From bfc67663e341981d94e796bfadd191135458152d Wed Oct 24 19:27:52 2012
From: Michael Gliwinski <michael.gliwinski@henderson-group.com>
Date: Wed, 24 Oct 2012 19:28:20 BST
Subject: [PATCH 1/1] Fixed sshKeyDistribution technique to make it work with network users.

Two changes required to make the technique work with network users:

 * do not assume users are in /etc/passwd, instead use `getent passwd` to obtain user information
 * do not assume user's primary group is named the same as the username, instead use primary group gid when setting ownership of .ssh directory and authorized_keys file

---
diff --git a/techniques/systemSettings/remoteAccess/sshKeyDistribution/1.0/sshKeyDistribution.st b/techniques/systemSettings/remoteAccess/sshKeyDistribution/1.0/sshKeyDistribution.st
index fb4b7c7..510122e 100644
--- a/techniques/systemSettings/remoteAccess/sshKeyDistribution/1.0/sshKeyDistribution.st
+++ b/techniques/systemSettings/remoteAccess/sshKeyDistribution/1.0/sshKeyDistribution.st
@@ -41,33 +41,41 @@
 }&
                 "sshkey_distribution_index" slist => getindices("sshkey_distribution_name");
 
-		"no_$(sshkey_distribution_index)" int => getfields("$(sshkey_distribution_name[$(sshkey_distribution_index)]):.*","/etc/passwd",":","userdata_$(sshkey_distribution_index)");
+		"userdata_$(sshkey_distribution_index)" string => execresult("/usr/bin/getent passwd $(sshkey_distribution_name[$(sshkey_distribution_index)])", "noshell");
+		"no_$(sshkey_distribution_index)" int => parsestringarray(
+			"userarray_$(sshkey_distribution_index)",
+			"$(userdata_$(sshkey_distribution_index))",
+			"",
+			":",
+			"1000",
+			"200000"
+			);
 
 files:
 
 	linux.!SuSE::
 
-		"$(userdata_$(sshkey_distribution_index)[6])/.ssh/."
+		"$(userarray_$(sshkey_distribution_index)[$(sshkey_distribution_name[$(sshkey_distribution_index)])][5])/.ssh/."
 			create => "true",
 			ifvarclass => canonify("index_$(sshkey_distribution_index)_exists"),
-			perms  => mog("700", "$(sshkey_distribution_name[$(sshkey_distribution_index)])", "$(sshkey_distribution_name[$(sshkey_distribution_index)])");
+			perms  => mog("700", "$(sshkey_distribution_name[$(sshkey_distribution_index)])", "$(userarray_$(sshkey_distribution_index)[$(sshkey_distribution_name[$(sshkey_distribution_index)])][3])");
 
-		"$(userdata_$(sshkey_distribution_index)[6])/.ssh/authorized_keys"
+		"$(userarray_$(sshkey_distribution_index)[$(sshkey_distribution_name[$(sshkey_distribution_index)])][5])/.ssh/authorized_keys"
 			create => "true",
 			edit_defaults => rudder_empty_select("$(sshkey_distribution_edit_type[$(sshkey_distribution_index)])"),
-			perms  => mog("600", "$(sshkey_distribution_name[$(sshkey_distribution_index)])", "$(sshkey_distribution_name[$(sshkey_distribution_index)])"),
+			perms  => mog("600", "$(sshkey_distribution_name[$(sshkey_distribution_index)])", "$(userarray_$(sshkey_distribution_index)[$(sshkey_distribution_name[$(sshkey_distribution_index)])][3])"),
 			edit_line => insert_lines("$(sshkey_distribution_key[$(sshkey_distribution_index)])"),
 			ifvarclass => canonify("index_$(sshkey_distribution_index)_exists"),
 			classes => kept_if_else("line_$(sshkey_distribution_index)_ok","line_$(sshkey_distribution_index)_added","line_$(sshkey_distribution_index)_failed");
 
 	SuSE::
 
-		"$(userdata_$(sshkey_distribution_index)[6])/.ssh/."
+		"$(userarray_$(sshkey_distribution_index)[$(sshkey_distribution_name[$(sshkey_distribution_index)])][5])/.ssh/."
 			create => "true",
 			ifvarclass => canonify("index_$(sshkey_distribution_index)_exists"),
 			perms  => mog("700", "$(sshkey_distribution_name[$(sshkey_distribution_index)])", "users");
 
-		"$(userdata_$(sshkey_distribution_index)[6])/.ssh/authorized_keys"
+		"$(userarray_$(sshkey_distribution_index)[$(sshkey_distribution_name[$(sshkey_distribution_index)])][5])/.ssh/authorized_keys"
 			create => "true",
 			edit_defaults => rudder_empty_select("$(sshkey_distribution_edit_type[$(sshkey_distribution_index)])"),
 			perms  => mog("600", "$(sshkey_distribution_name[$(sshkey_distribution_index)])", "users"),
-- 
bzr 2.6b2, bzr-git 0.6.9, dulwich 0.8.5
