浏览代码

HADOOP-3098. Allow more characters in user and group names while
using -chown and -chgrp commands. (rangadi)


git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/branches/branch-0.16@642304 13f79535-47bb-0310-9956-ffa450edef68

Raghu Angadi 17 年之前
父节点
当前提交
ea3c256dff

+ 3 - 0
CHANGES.txt

@@ -83,6 +83,9 @@ Release 0.16.1 - 2008-03-13
 
 
     HADOOP-2911. Make the information printed by the HOD allocate and
     HADOOP-2911. Make the information printed by the HOD allocate and
     info commands less verbose and clearer. (Vinod Kumar via nigel)
     info commands less verbose and clearer. (Vinod Kumar via nigel)
+
+    HADOOP-3098. Allow more characters in user and group names while
+    using -chown and -chgrp commands. (rangadi)
     
     
   BUG FIXES
   BUG FIXES
 
 

+ 8 - 2
src/java/org/apache/hadoop/fs/FsShell.java

@@ -1272,8 +1272,14 @@ public class FsShell extends Configured implements Tool {
       "\t-R\tmodifies the files recursively. This is the only option\n" +
       "\t-R\tmodifies the files recursively. This is the only option\n" +
       "\t\tcurrently supported.\n\n" +
       "\t\tcurrently supported.\n\n" +
       "\t\tIf only owner or group is specified then only owner or\n" +
       "\t\tIf only owner or group is specified then only owner or\n" +
-      "\t\tgroup is modified. The owner and group names can only\n" + 
-      "\t\tcontain digits and alphabet. These names are case sensitive.\n";
+      "\t\tgroup is modified.\n\n" +
+      "\t\tThe owner and group names may only cosists of digits, alphabet,\n"+
+      "\t\tand any of '-_.@/' i.e. [-_.@/a-zA-Z0-9]. The names are case\n" +
+      "\t\tsensitive.\n\n" +
+      "\t\tWARNING: Avoid using '.' to separate user name and group though\n" +
+      "\t\tLinux allows it. If user names have dots in them and you are\n" +
+      "\t\tusing local file system, you might see surprising results since\n" +
+      "\t\tshell command 'chown' is used for local files.\n";
     
     
     String chgrp = FsShellPermissions.CHGRP_USAGE + "\n" +
     String chgrp = FsShellPermissions.CHGRP_USAGE + "\n" +
       "\t\tThis is equivalent to -chown ... :GROUP ...\n";
       "\t\tThis is equivalent to -chown ... :GROUP ...\n";

+ 5 - 3
src/java/org/apache/hadoop/fs/FsShellPermissions.java

@@ -190,11 +190,13 @@ class FsShellPermissions {
 
 
   /*========== chown ==========*/
   /*========== chown ==========*/
   
   
-  ///allows only alpha-numberic names for owner group
+  static private String allowedChars = "[-_./@a-zA-Z0-9]";
+  ///allows only "allowedChars" above in names for owner and group
   static private Pattern chownPattern = 
   static private Pattern chownPattern = 
-         Pattern.compile("^\\s*(\\p{Alnum}+)?([:.](\\p{Alnum}*))?\\s*$");
+         Pattern.compile("^\\s*(" + allowedChars + "+)?" +
+                          "([:](" + allowedChars + "*))?\\s*$");
   static private Pattern chgrpPattern = 
   static private Pattern chgrpPattern = 
-         Pattern.compile("^\\s*(\\p{Alnum}+)\\s*$");
+         Pattern.compile("^\\s*(" + allowedChars + "+)\\s*$");
   
   
   static String CHOWN_USAGE = "-chown [-R] [OWNER][:[GROUP]] PATH...";
   static String CHOWN_USAGE = "-chown [-R] [OWNER][:[GROUP]] PATH...";
   static String CHGRP_USAGE = "-chgrp [-R] GROUP PATH...";  
   static String CHGRP_USAGE = "-chgrp [-R] GROUP PATH...";  

+ 15 - 1
src/test/org/apache/hadoop/dfs/TestDFSShell.java

@@ -385,7 +385,7 @@ public class TestDFSShell extends TestCase {
   public void testFilePermissions() throws IOException {
   public void testFilePermissions() throws IOException {
     Configuration conf = new Configuration();
     Configuration conf = new Configuration();
     
     
-    //test chnmod on local fs
+    //test chmod on local fs
     FileSystem fs = FileSystem.getLocal(conf);
     FileSystem fs = FileSystem.getLocal(conf);
     testChmod(conf, fs, 
     testChmod(conf, fs, 
               (new File(TEST_ROOT_DIR, "chmodTest")).getAbsolutePath());
               (new File(TEST_ROOT_DIR, "chmodTest")).getAbsolutePath());
@@ -428,6 +428,20 @@ public class TestDFSShell extends TestCase {
     runCmd(shell, "-chown", "-R", "hadoop:toys", "unknownFile", "/");
     runCmd(shell, "-chown", "-R", "hadoop:toys", "unknownFile", "/");
     confirmOwner("hadoop", "toys", fs, root, parent, path);
     confirmOwner("hadoop", "toys", fs, root, parent, path);
     
     
+    // Test different characters in names
+
+    runCmd(shell, "-chown", "hdfs.user", file);
+    confirmOwner("hdfs.user", null, fs, path);
+    
+    runCmd(shell, "-chown", "_Hdfs.User-10:_hadoop.users--", file);
+    confirmOwner("_Hdfs.User-10", "_hadoop.users--", fs, path);
+    
+    runCmd(shell, "-chown", "hdfs/hadoop-core@apache.org:asf-projects", file);
+    confirmOwner("hdfs/hadoop-core@apache.org", "asf-projects", fs, path);
+    
+    runCmd(shell, "-chgrp", "hadoop-core@apache.org/100", file);
+    confirmOwner(null, "hadoop-core@apache.org/100", fs, path);
+    
     cluster.shutdown();
     cluster.shutdown();
   }
   }
   /**
   /**