+static void lmPasswd_to_key(
+ const char *lmPasswd,
+ des_cblock *key)
+{
+ const unsigned char *lpw = (const unsigned char *) lmPasswd;
+ unsigned char *k = (unsigned char *) key;
+
+ /* make room for parity bits */
+ k[0] = lpw[0];
+ k[1] = ((lpw[0] & 0x01) << 7) | (lpw[1] >> 1);
+ k[2] = ((lpw[1] & 0x03) << 6) | (lpw[2] >> 2);
+ k[3] = ((lpw[2] & 0x07) << 5) | (lpw[3] >> 3);
+ k[4] = ((lpw[3] & 0x0F) << 4) | (lpw[4] >> 4);
+ k[5] = ((lpw[4] & 0x1F) << 3) | (lpw[5] >> 5);
+ k[6] = ((lpw[5] & 0x3F) << 2) | (lpw[6] >> 6);
+ k[7] = ((lpw[6] & 0x7F) << 1);
+
+ des_set_odd_parity( key );
+}
+
+static int chk_lanman(
+ const struct berval *scheme,
+ const struct berval *passwd,
+ const struct berval *cred,
+ const char **text )
+{
+ int i;
+ char UcasePassword[15];
+ des_cblock key;
+ des_key_schedule schedule;
+ des_cblock StdText = "KGS!@#$%";
+ des_cblock PasswordHash1, PasswordHash2;
+ char PasswordHash[33], storedPasswordHash[33];
+
+ for( i=0; i<cred->bv_len; i++) {
+ if(cred->bv_val[i] == '\0') {
+ return LUTIL_PASSWD_ERR; /* NUL character in password */
+ }
+ }
+
+ if( cred->bv_val[i] != '\0' ) {
+ return LUTIL_PASSWD_ERR; /* passwd must behave like a string */
+ }
+
+ strncpy( UcasePassword, cred->bv_val, 14 );
+ UcasePassword[14] = '\0';
+ ldap_pvt_str2upper( UcasePassword );
+
+ lmPasswd_to_key( UcasePassword, &key );
+ des_set_key_unchecked( &key, schedule );
+ des_ecb_encrypt( &StdText, &PasswordHash1, schedule , DES_ENCRYPT );
+
+ lmPasswd_to_key( &UcasePassword[7], &key );
+ des_set_key_unchecked( &key, schedule );
+ des_ecb_encrypt( &StdText, &PasswordHash2, schedule , DES_ENCRYPT );
+
+ sprintf( PasswordHash, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
+ PasswordHash1[0],PasswordHash1[1],PasswordHash1[2],PasswordHash1[3],
+ PasswordHash1[4],PasswordHash1[5],PasswordHash1[6],PasswordHash1[7],
+ PasswordHash2[0],PasswordHash2[1],PasswordHash2[2],PasswordHash2[3],
+ PasswordHash2[4],PasswordHash2[5],PasswordHash2[6],PasswordHash2[7] );
+
+ /* as a precaution convert stored password hash to lower case */
+ strncpy( storedPasswordHash, passwd->bv_val, 32 );
+ storedPasswordHash[32] = '\0';
+ ldap_pvt_str2lower( storedPasswordHash );
+
+ return memcmp( PasswordHash, storedPasswordHash, 32) ? LUTIL_PASSWD_ERR : LUTIL_PASSWD_OK;