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

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