Skip to content

Commit db23420

Browse files
author
Pradeep Nayak
committed
HADOOP-12345: Compute the correct credential length
1 parent 42d53e8 commit db23420

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/security/CredentialsSys.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public int[] getAuxGIDs() {
6363
return mAuxGIDs;
6464
}
6565

66+
public int getStamp() {
67+
return mStamp;
68+
}
69+
6670
public void setGID(int gid) {
6771
this.mGID = gid;
6872
}
@@ -93,8 +97,15 @@ public void read(XDR xdr) {
9397

9498
@Override
9599
public void write(XDR xdr) {
100+
int padding = 0;
101+
// we do not need compute padding if the hostname is already a multiple of 4
102+
if (mHostName.getBytes(Charsets.UTF_8).length != 0) {
103+
padding = 4 - (mHostName.getBytes(Charsets.UTF_8).length % 4);
104+
}
96105
// mStamp + mHostName.length + mHostName + mUID + mGID + mAuxGIDs.count
97106
mCredentialsLength = 20 + mHostName.getBytes(Charsets.UTF_8).length;
107+
// add the extra padding to the credential length where hostname is not a multiple of 4
108+
mCredentialsLength = mCredentialsLength + padding;
98109
// mAuxGIDs
99110
if (mAuxGIDs != null && mAuxGIDs.length > 0) {
100111
mCredentialsLength += mAuxGIDs.length * 4;

hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/security/TestCredentialsSys.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public void testReadWrite() {
3333
CredentialsSys credential = new CredentialsSys();
3434
credential.setUID(0);
3535
credential.setGID(1);
36+
credential.setStamp(1234);
3637

3738
XDR xdr = new XDR();
3839
credential.write(xdr);
@@ -42,5 +43,6 @@ public void testReadWrite() {
4243

4344
assertEquals(0, newCredential.getUID());
4445
assertEquals(1, newCredential.getGID());
46+
assertEquals(1234, newCredential.getStamp());
4547
}
4648
}

0 commit comments

Comments
 (0)