HADOOP-12581. ShellBasedIdMapping needs suport for Solaris (Alan Burlison via aw)

This commit is contained in:
Allen Wittenauer 2016-05-12 14:42:04 -07:00
parent 013000fbc2
commit 0f3d6bc65e
1 changed files with 11 additions and 10 deletions

View File

@ -179,7 +179,7 @@ public class ShellBasedIdMapping implements IdMappingServiceProvider {
+ "The host system with duplicated user/group name or id might work fine most of the time by itself.\n" + "The host system with duplicated user/group name or id might work fine most of the time by itself.\n"
+ "However when NFS gateway talks to HDFS, HDFS accepts only user and group name.\n" + "However when NFS gateway talks to HDFS, HDFS accepts only user and group name.\n"
+ "Therefore, same name means the same user or same group. To find the duplicated names/ids, one can do:\n" + "Therefore, same name means the same user or same group. To find the duplicated names/ids, one can do:\n"
+ "<getent passwd | cut -d: -f1,3> and <getent group | cut -d: -f1,3> on Linux systems,\n" + "<getent passwd | cut -d: -f1,3> and <getent group | cut -d: -f1,3> on Linux, BSD and Solaris systems,\n"
+ "<dscl . -list /Users UniqueID> and <dscl . -list /Groups PrimaryGroupID> on MacOS."; + "<dscl . -list /Users UniqueID> and <dscl . -list /Groups PrimaryGroupID> on MacOS.";
private static void reportDuplicateEntry(final String header, private static void reportDuplicateEntry(final String header,
@ -273,7 +273,8 @@ public class ShellBasedIdMapping implements IdMappingServiceProvider {
} }
private boolean checkSupportedPlatform() { private boolean checkSupportedPlatform() {
if (!OS.startsWith("Linux") && !OS.startsWith("Mac")) { if (!OS.startsWith("Linux") && !OS.startsWith("Mac")
&& !OS.equals("SunOS") && !OS.contains("BSD")) {
LOG.error("Platform is not supported:" + OS LOG.error("Platform is not supported:" + OS
+ ". Can't update user map and group map and" + ". Can't update user map and group map and"
+ " 'nobody' will be used for any user and group."); + " 'nobody' will be used for any user and group.");
@ -385,7 +386,7 @@ public class ShellBasedIdMapping implements IdMappingServiceProvider {
// OR // OR
// id -u <name> | awk '{print "<name>:"$1 }' // id -u <name> | awk '{print "<name>:"$1 }'
// //
private String getName2IdCmdLinux(final String name, final boolean isGrp) { private String getName2IdCmdNIX(final String name, final boolean isGrp) {
String cmd; String cmd;
if (isGrp) { if (isGrp) {
cmd = "getent group " + name + " | cut -d: -f1,3"; cmd = "getent group " + name + " | cut -d: -f1,3";
@ -396,7 +397,7 @@ public class ShellBasedIdMapping implements IdMappingServiceProvider {
} }
// search for name with given id, return "<name>:<id>" // search for name with given id, return "<name>:<id>"
private String getId2NameCmdLinux(final int id, final boolean isGrp) { private String getId2NameCmdNIX(final int id, final boolean isGrp) {
String cmd = "getent "; String cmd = "getent ";
cmd += isGrp? "group " : "passwd "; cmd += isGrp? "group " : "passwd ";
cmd += String.valueOf(id) + " | cut -d: -f1,3"; cmd += String.valueOf(id) + " | cut -d: -f1,3";
@ -466,14 +467,14 @@ public class ShellBasedIdMapping implements IdMappingServiceProvider {
boolean updated = false; boolean updated = false;
updateStaticMapping(); updateStaticMapping();
if (OS.startsWith("Linux")) { if (OS.startsWith("Linux") || OS.equals("SunOS") || OS.contains("BSD")) {
if (isGrp) { if (isGrp) {
updated = updateMapInternal(gidNameMap, "group", updated = updateMapInternal(gidNameMap, "group",
getName2IdCmdLinux(name, true), ":", getName2IdCmdNIX(name, true), ":",
staticMapping.gidMapping); staticMapping.gidMapping);
} else { } else {
updated = updateMapInternal(uidNameMap, "user", updated = updateMapInternal(uidNameMap, "user",
getName2IdCmdLinux(name, false), ":", getName2IdCmdNIX(name, false), ":",
staticMapping.uidMapping); staticMapping.uidMapping);
} }
} else { } else {
@ -502,14 +503,14 @@ public class ShellBasedIdMapping implements IdMappingServiceProvider {
boolean updated = false; boolean updated = false;
updateStaticMapping(); updateStaticMapping();
if (OS.startsWith("Linux")) { if (OS.startsWith("Linux") || OS.equals("SunOS") || OS.contains("BSD")) {
if (isGrp) { if (isGrp) {
updated = updateMapInternal(gidNameMap, "group", updated = updateMapInternal(gidNameMap, "group",
getId2NameCmdLinux(id, true), ":", getId2NameCmdNIX(id, true), ":",
staticMapping.gidMapping); staticMapping.gidMapping);
} else { } else {
updated = updateMapInternal(uidNameMap, "user", updated = updateMapInternal(uidNameMap, "user",
getId2NameCmdLinux(id, false), ":", getId2NameCmdNIX(id, false), ":",
staticMapping.uidMapping); staticMapping.uidMapping);
} }
} else { } else {