|
@@ -20,6 +20,7 @@ package org.apache.hadoop.oncrpc.security;
|
|
import java.net.InetAddress;
|
|
import java.net.InetAddress;
|
|
import java.net.UnknownHostException;
|
|
import java.net.UnknownHostException;
|
|
|
|
|
|
|
|
+import com.google.common.annotations.VisibleForTesting;
|
|
import org.apache.commons.io.Charsets;
|
|
import org.apache.commons.io.Charsets;
|
|
import org.apache.hadoop.oncrpc.XDR;
|
|
import org.apache.hadoop.oncrpc.XDR;
|
|
|
|
|
|
@@ -63,6 +64,11 @@ public class CredentialsSys extends Credentials {
|
|
return mAuxGIDs;
|
|
return mAuxGIDs;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @VisibleForTesting
|
|
|
|
+ int getStamp() {
|
|
|
|
+ return mStamp;
|
|
|
|
+ }
|
|
|
|
+
|
|
public void setGID(int gid) {
|
|
public void setGID(int gid) {
|
|
this.mGID = gid;
|
|
this.mGID = gid;
|
|
}
|
|
}
|
|
@@ -75,6 +81,11 @@ public class CredentialsSys extends Credentials {
|
|
this.mStamp = stamp;
|
|
this.mStamp = stamp;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @VisibleForTesting
|
|
|
|
+ void setHostName(String hostname) {
|
|
|
|
+ this.mHostName = hostname;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void read(XDR xdr) {
|
|
public void read(XDR xdr) {
|
|
mCredentialsLength = xdr.readInt();
|
|
mCredentialsLength = xdr.readInt();
|
|
@@ -93,8 +104,14 @@ public class CredentialsSys extends Credentials {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void write(XDR xdr) {
|
|
public void write(XDR xdr) {
|
|
|
|
+ int padding = 0;
|
|
|
|
+ // Ensure there are padding bytes if hostname is not a multiple of 4.
|
|
|
|
+ padding = 4 - (mHostName.getBytes(Charsets.UTF_8).length % 4);
|
|
|
|
+ // padding bytes is zero if hostname is already a multiple of 4.
|
|
|
|
+ padding = padding % 4;
|
|
// mStamp + mHostName.length + mHostName + mUID + mGID + mAuxGIDs.count
|
|
// mStamp + mHostName.length + mHostName + mUID + mGID + mAuxGIDs.count
|
|
mCredentialsLength = 20 + mHostName.getBytes(Charsets.UTF_8).length;
|
|
mCredentialsLength = 20 + mHostName.getBytes(Charsets.UTF_8).length;
|
|
|
|
+ mCredentialsLength = mCredentialsLength + padding;
|
|
// mAuxGIDs
|
|
// mAuxGIDs
|
|
if (mAuxGIDs != null && mAuxGIDs.length > 0) {
|
|
if (mAuxGIDs != null && mAuxGIDs.length > 0) {
|
|
mCredentialsLength += mAuxGIDs.length * 4;
|
|
mCredentialsLength += mAuxGIDs.length * 4;
|