Submitted By:            Randy McMurchy <randy_at_linuxfromscratch_dot_org>
Date:                    2007-10-16
Initial Package Version: 0.7 (original patch adapted from an 0.6.1 version patch)
Upstream Status:         Pending submission
Origin:                  Randy McMurchy, DJ Lucas and Heimdal sample source code
Description:             Enables kpasswd and kadmin to use the cracklib library.
                         CrackLib must be installed using BLFS instructions. See:
                         http://www.linuxfromscratch.org/blfs/view/svn/postlfs/cracklib.html


diff -Naur heimdal-0.8.1-orig/lib/kadm5/Makefile.in heimdal-0.8.1/lib/kadm5/Makefile.in
--- heimdal-0.8.1-orig/lib/kadm5/Makefile.in	2007-04-23 16:26:05.000000000 +0000
+++ heimdal-0.8.1/lib/kadm5/Makefile.in	2007-07-05 20:36:47.000000000 +0000
@@ -299,7 +299,7 @@
 LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@
 LIBADD_roken = @LIBADD_roken@
 LIBOBJS = @LIBOBJS@
-LIBS = @LIBS@
+LIBS = @LIBS@ -lcrack_heimdal
 LIBTOOL = @LIBTOOL@
 LIB_AUTH_SUBDIRS = @LIB_AUTH_SUBDIRS@
 LIB_NDBM = @LIB_NDBM@

diff -Naur heimdal-0.8.1-orig/lib/kadm5/password_quality.c heimdal-0.8.1/lib/kadm5/password_quality.c
--- heimdal-0.8.1-orig/lib/kadm5/password_quality.c	2007-04-23 16:23:50.000000000 +0000
+++ heimdal-0.8.1/lib/kadm5/password_quality.c	2007-07-05 20:36:47.000000000 +0000
@@ -33,6 +33,7 @@
 
 #include "kadm5_locl.h"
 #include "kadm5-pwcheck.h"
+#include <crack_heimdal.h>
 
 RCSID("$Id: password_quality.c 17595 2006-05-30 21:51:55Z lha $");
 
@@ -63,7 +64,39 @@
 	return 0;
 }
 
+/* The following function was inserted to utilize the CrackLib library to 
+   ensure strong passwords.  The cracklib library must be patched before 
+   this function will work. For more information, see:
+   http://www.linuxfromscratch.org/blfs/view/svn/postlfs/cracklib.html
+*/
+
+#if defined(CRACKLIB_HEIMDAL_H) && defined(CRACKLIB_DICTPATH)
+
 static const char *
+
+min_length_passwd_quality_v0 (krb5_context context,
+                              krb5_principal principal,
+                              krb5_data *password)
+{
+    char *s = malloc(password->length + 1);
+    char *msg;
+    char *strings[2];
+    if(s == NULL)
+        return NULL; /* XXX */
+    strings[0] = principal->name.name_string.val[0]; /* XXX */
+    strings[1] = NULL;
+    memcpy(s, password->data, password->length);
+    s[password->length] = '\0';
+    msg = FascistCheck(s, CRACKLIB_DICTPATH, strings);
+    memset(s, 0, password->length);
+    free(s);
+    return msg;
+}
+
+#else /* Not using CrackLib */
+
+static const char *
+
 min_length_passwd_quality_v0 (krb5_context context,
 			      krb5_principal principal,
 			      krb5_data *pwd)
@@ -80,6 +113,7 @@
     return NULL;
 }
 
+#endif /* CRACKLIB_HEIMDAL_H && CRACKLIB_DICTPATH */
 
 static int
 char_class_passwd_quality (krb5_context context,
