static const unsigned char crypt64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890./";
+#ifdef SLAPD_CRYPT
+static const char *salt_format = NULL;
+#endif
+
struct pw_scheme;
typedef int (*PASSWD_CHK_FUNC)(
const struct berval *passwd )
{
struct berval hash;
- unsigned char salt[9]; /* salt suitable for anything */
+ unsigned char salt[32]; /* salt suitable for most anything */
int i;
for( i=0; i<passwd->bv_len; i++) {
return NULL; /* passwd must behave like a string */
}
- if( lutil_entropy( salt, 8) < 0 ) {
+ if( lutil_entropy( salt, sizeof( salt ) ) < 0 ) {
return NULL;
}
- for( i=0; i<8; i++ ) {
+ for( i=0; i< ( sizeof(salt) - 1 ); i++ ) {
salt[i] = crypt64[ salt[i] % (sizeof(crypt64)-1) ];
}
- salt[8] = '\0';
+ salt[sizeof( salt ) - 1 ] = '\0';
+
+ if( salt_format != NULL ) {
+ /* copy the salt we made into entropy before snprintfing
+ it back into the salt */
+ char entropy[sizeof(salt)];
+ strcpy( entropy, salt );
+ snprintf( salt, sizeof(entropy), salt_format, entropy );
+ }
hash.bv_val = crypt( passwd->bv_val, salt );
return pw_string( scheme, &hash );
}
#endif
+
+int lutil_salt_format(const char *format)
+{
+#ifdef SLAPD_CRYPT
+ if (format) {
+ if (salt_format)
+ free(salt_format);
+ salt_format = strdup(format);
+ } else { // unset if they pass in NULL
+ if (salt_format)
+ free(salt_format);
+ salt_format = NULL;
+ }
+#endif
+
+ return 0;
+}
default_passwd_hash = ch_strdup( cargv[1] );
}
+ } else if ( strcasecmp( cargv[0], "password-crypt-salt-format" ) == 0 )
+ {
+ if ( cargc < 2 ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
+ "%s: line %d: missing format in "
+ "\"password-crypt-salt-format <format>\" line\n",
+ fname, lineno ));
+#else
+ Debug( LDAP_DEBUG_ANY, "%s: line %d: missing format in "
+ "\"password-crypt-salt-format <format>\" line\n",
+ fname, lineno, 0 );
+#endif
+
+ return 1;
+ }
+
+ lutil_salt_format( cargv[1] );
+
/* set SASL host */
} else if ( strcasecmp( cargv[0], "sasl-host" ) == 0 ) {
if ( cargc < 2 ) {