hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject hadoop git commit: HADOOP-12345. Pad hostname correctly in CredentialsSys.java. Contributed by Pradeep Nayak Udupi Kadbet.
Date Thu, 30 Jun 2016 00:32:56 GMT
Repository: hadoop
Updated Branches:
  refs/heads/trunk 5c07c573d -> 846ada2de


HADOOP-12345. Pad hostname correctly in CredentialsSys.java. Contributed by Pradeep Nayak
Udupi Kadbet.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/846ada2d
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/846ada2d
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/846ada2d

Branch: refs/heads/trunk
Commit: 846ada2de33f9840d6e60fd7339ecc2d71f277c7
Parents: 5c07c57
Author: Andrew Wang <wang@apache.org>
Authored: Wed Jun 29 17:32:35 2016 -0700
Committer: Andrew Wang <wang@apache.org>
Committed: Wed Jun 29 17:32:35 2016 -0700

----------------------------------------------------------------------
 .../hadoop/oncrpc/security/Credentials.java     |  6 +++
 .../hadoop/oncrpc/security/CredentialsSys.java  | 17 ++++++++
 .../oncrpc/security/TestCredentialsSys.java     | 42 ++++++++++++++++++++
 3 files changed, 65 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/846ada2d/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/security/Credentials.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/security/Credentials.java
b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/security/Credentials.java
index 29c706b..639a1e5 100644
--- a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/security/Credentials.java
+++ b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/security/Credentials.java
@@ -17,6 +17,7 @@
  */
 package org.apache.hadoop.oncrpc.security;
 
+import com.google.common.annotations.VisibleForTesting;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.oncrpc.XDR;
@@ -66,4 +67,9 @@ public abstract class Credentials extends RpcAuthInfo {
   protected Credentials(AuthFlavor flavor) {
     super(flavor);
   }
+
+  @VisibleForTesting
+  int getCredentialLength() {
+    return mCredentialsLength;
+  }
 }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/846ada2d/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/security/CredentialsSys.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/security/CredentialsSys.java
b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/security/CredentialsSys.java
index d13c361..4d39de3 100644
--- a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/security/CredentialsSys.java
+++ b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/security/CredentialsSys.java
@@ -20,6 +20,7 @@ package org.apache.hadoop.oncrpc.security;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 
+import com.google.common.annotations.VisibleForTesting;
 import org.apache.commons.io.Charsets;
 import org.apache.hadoop.oncrpc.XDR;
 
@@ -63,6 +64,11 @@ public class CredentialsSys extends Credentials {
     return mAuxGIDs;
   }
 
+  @VisibleForTesting
+  int getStamp() {
+    return mStamp;
+  }
+
   public void setGID(int gid) {
     this.mGID = gid;
   }
@@ -75,6 +81,11 @@ public class CredentialsSys extends Credentials {
     this.mStamp = stamp;
   }
 
+  @VisibleForTesting
+  void setHostName(String hostname) {
+    this.mHostName = hostname;
+  }
+
   @Override
   public void read(XDR xdr) {
     mCredentialsLength = xdr.readInt();
@@ -93,8 +104,14 @@ public class CredentialsSys extends Credentials {
 
   @Override
   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
     mCredentialsLength = 20 + mHostName.getBytes(Charsets.UTF_8).length;
+    mCredentialsLength = mCredentialsLength + padding;
     // mAuxGIDs
     if (mAuxGIDs != null && mAuxGIDs.length > 0) {
       mCredentialsLength += mAuxGIDs.length * 4;

http://git-wip-us.apache.org/repos/asf/hadoop/blob/846ada2d/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/security/TestCredentialsSys.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/security/TestCredentialsSys.java
b/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/security/TestCredentialsSys.java
index 2b9e339..745ac5c 100644
--- a/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/security/TestCredentialsSys.java
+++ b/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/security/TestCredentialsSys.java
@@ -33,6 +33,7 @@ public class TestCredentialsSys {
     CredentialsSys credential = new CredentialsSys();
     credential.setUID(0);
     credential.setGID(1);
+    credential.setStamp(1234);
     
     XDR xdr = new XDR();
     credential.write(xdr);
@@ -42,5 +43,46 @@ public class TestCredentialsSys {
     
     assertEquals(0, newCredential.getUID());
     assertEquals(1, newCredential.getGID());
+    assertEquals(1234, newCredential.getStamp());
+  }
+
+  @Test
+  public void testHostNameNotMultipleOf4() {
+    CredentialsSys credential = new CredentialsSys();
+    credential.setUID(0);
+    credential.setGID(1);
+    credential.setStamp(1234);
+    credential.setHostName("hadoop-nfs");
+
+    XDR xdr = new XDR();
+    credential.write(xdr);
+
+    CredentialsSys newCredential = new CredentialsSys();
+    newCredential.read(xdr.asReadOnlyWrap());
+
+    assertEquals(0, newCredential.getUID());
+    assertEquals(1, newCredential.getGID());
+    assertEquals(1234, newCredential.getStamp());
+    assertEquals(32, newCredential.getCredentialLength());
+  }
+
+  @Test
+  public void testHostNameMultipleOf4() {
+    CredentialsSys credential = new CredentialsSys();
+    credential.setUID(0);
+    credential.setGID(1);
+    credential.setStamp(1234);
+    credential.setHostName("apachehadoop");
+
+    XDR xdr = new XDR();
+    credential.write(xdr);
+
+    CredentialsSys newCredential = new CredentialsSys();
+    newCredential.read(xdr.asReadOnlyWrap());
+
+    assertEquals(0, newCredential.getUID());
+    assertEquals(1, newCredential.getGID());
+    assertEquals(1234, newCredential.getStamp());
+    assertEquals(32, newCredential.getCredentialLength());
   }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message