Blame SOURCES/yp-tools-2.12-hash.patch

9a4c31
diff -up yp-tools-2.12/man/yppasswd.1.in.hash yp-tools-2.12/man/yppasswd.1.in
9a4c31
--- yp-tools-2.12/man/yppasswd.1.in.hash	2011-09-09 16:18:49.469037058 +0200
9a4c31
+++ yp-tools-2.12/man/yppasswd.1.in	2011-09-09 16:20:19.101030930 +0200
9a4c31
@@ -81,6 +81,12 @@ for authentication with the
9a4c31
 .BR yppasswdd (8)
9a4c31
 daemon. Subsequently, the
9a4c31
 program prompts for the updated information:
9a4c31
+.P
9a4c31
+If we use shadowing passwords using passwd.adjunct, SHA-512 will be 
9a4c31
+used for hashing a new password by default. If we want to use MD5, 
9a4c31
+SHA_256 or older DES, we need to set the environment variable 
9a4c31
+YP_PASSWD_HASH. Possible values are "DES", "MD5", "SHA-256" and 
9a4c31
+"SHA-512" (value is case-insensitive).
9a4c31
 .\"
9a4c31
 .\"
9a4c31
 .IP "\fByppasswd\fP or \fB-p\fP"
9a4c31
diff -up yp-tools-2.12/src/yppasswd.c.hash yp-tools-2.12/src/yppasswd.c
9a4c31
--- yp-tools-2.12/src/yppasswd.c.hash	2011-09-09 16:20:35.360029823 +0200
9a4c31
+++ yp-tools-2.12/src/yppasswd.c	2011-09-09 16:25:21.589010245 +0200
9a4c31
@@ -514,6 +514,32 @@ create_random_salt (char *salt, int num_
9a4c31
     close (fd);
9a4c31
 }
9a4c31
 
9a4c31
+
9a4c31
+/*
9a4c31
+ * Reads environment variable YP_PASSWD_HASH and returns hash id.
9a4c31
+ * Possible values are MD5, SHA-256, SHA-512 and DES.
9a4c31
+ * If other value is set or it is not set at all, SHA-512 is used.
9a4c31
+ */ 
9a4c31
+static int
9a4c31
+get_env_hash_id()
9a4c31
+{
9a4c31
+  const char *v = getenv("YP_PASSWD_HASH");
9a4c31
+  if (!v)
9a4c31
+    return SHA_512;
9a4c31
+
9a4c31
+  if (!strcasecmp(v, "DES"))
9a4c31
+    return DES;
9a4c31
+
9a4c31
+  if (!strcasecmp(v, "SHA-256"))
9a4c31
+    return SHA_256;
9a4c31
+
9a4c31
+  if (!strcasecmp(v, "MD5"))
9a4c31
+    return MD5;
9a4c31
+
9a4c31
+  return SHA_512;
9a4c31
+}
9a4c31
+
9a4c31
+
9a4c31
 int
9a4c31
 main (int argc, char **argv)
9a4c31
 {
9a4c31
@@ -723,6 +749,15 @@ main (int argc, char **argv)
9a4c31
 
9a4c31
       hash_id = get_hash_id (pwd->pw_passwd);
9a4c31
 
9a4c31
+      /* If we use passwd.adjunct, there is no magic value like $1$ in the 
9a4c31
+       * beginning of password, but ##username instead. Thus, SHA_512 will be 
9a4c31
+       * used for hashing a new password by default. If we want to use DES, 
9a4c31
+       * MD5 or SHA_256, we need to set the environment variable 
9a4c31
+       * YP_PASSWD_HASH (e.g. YP_PASSWD_HASH=DES).
9a4c31
+       */
9a4c31
+      if (strncmp(pwd->pw_passwd, "##", 2) == 0)
9a4c31
+        hash_id = get_env_hash_id();
9a4c31
+
9a4c31
       /* Preserve 'rounds=<N>$' (if present) in case of SHA-2 */
9a4c31
       if (hash_id == SHA_256 || hash_id == SHA_512)
9a4c31
 	{