]> git.sur5r.net Git - openldap/blobdiff - libraries/liblutil/passwd.c
fix test when slapo-memberof(5) built as module (ITS#5132)
[openldap] / libraries / liblutil / passwd.c
index 7512dff6d02bc56e93807610742ad0f38cb96dca..2ccad563b2047984233644c87cd6821118eb1b29 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2005 The OpenLDAP Foundation.
+ * Copyright 1998-2007 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -42,7 +42,7 @@
 #ifdef SLAPD_CRYPT
 # include <ac/crypt.h>
 
-# if defined( HAVE_GETPWNAM ) && defined( HAVE_PW_PASSWD )
+# if defined( HAVE_GETPWNAM ) && defined( HAVE_STRUCT_PASSWD_PW_PASSWD )
 #  ifdef HAVE_SHADOW_H
 #      include <shadow.h>
 #  endif
@@ -73,6 +73,10 @@ static lutil_cryptfunc lutil_crypt;
 lutil_cryptfunc *lutil_cryptptr = lutil_crypt;
 #endif
 
+/* KLUDGE:
+ *  chk_fn is NULL iff name is {CLEARTEXT}
+ *     otherwise, things will break
+ */
 struct pw_scheme {
        struct berval name;
        LUTIL_PASSWD_CHK_FUNC *chk_fn;
@@ -110,7 +114,7 @@ static LUTIL_PASSWD_HASH_FUNC hash_lanman;
 static LUTIL_PASSWD_CHK_FUNC chk_crypt;
 static LUTIL_PASSWD_HASH_FUNC hash_crypt;
 
-#if defined( HAVE_GETPWNAM ) && defined( HAVE_PW_PASSWD )
+#if defined( HAVE_GETPWNAM ) && defined( HAVE_STRUCT_PASSWD_PW_PASSWD )
 static LUTIL_PASSWD_CHK_FUNC chk_unix;
 #endif
 #endif
@@ -140,14 +144,14 @@ static const struct pw_scheme pw_schemes_default[] =
 
 #ifdef SLAPD_CRYPT
        { BER_BVC("{CRYPT}"),           chk_crypt, hash_crypt },
-# if defined( HAVE_GETPWNAM ) && defined( HAVE_PW_PASSWD )
+# if defined( HAVE_GETPWNAM ) && defined( HAVE_STRUCT_PASSWD_PW_PASSWD )
        { BER_BVC("{UNIX}"),            chk_unix, NULL },
 # endif
 #endif
 
 #ifdef SLAPD_CLEARTEXT
        /* pseudo scheme */
-       { {0, "{CLEARTEXT}"},           NULL, hash_clear },
+       { BER_BVC("{CLEARTEXT}"),       NULL, hash_clear },
 #endif
 
        { BER_BVNULL, NULL, NULL }
@@ -206,12 +210,10 @@ static const struct pw_scheme *get_scheme(
                return NULL;
 
        bv.bv_len = bv.bv_val - scheme + 1;
-       bv.bv_val = scheme;
+       bv.bv_val = (char *) scheme;
 
        for( pws=pw_schemes; pws; pws=pws->next ) {
-               if( bv.bv_len != pws->s.name.bv_len )
-                       continue;
-               if( strncasecmp(bv.bv_val, pws->s.name.bv_val, bv.bv_len ) == 0 ) {
+               if ( ber_bvstrcasecmp(&bv, &pws->s.name ) == 0 ) {
                        return &(pws->s);
                }
        }
@@ -303,10 +305,17 @@ lutil_passwd(
        }
 
 #ifdef SLAPD_CLEARTEXT
+       /* Do we think there is a scheme specifier here that we
+        * didn't recognize? Assume a scheme name is at least 1 character.
+        */
+       if (( passwd->bv_val[0] == '{' ) &&
+               ( ber_bvchr( passwd, '}' ) > passwd->bv_val+1 ))
+       {
+               return 1;
+       }
        if( is_allowed_scheme("{CLEARTEXT}", schemes ) ) {
-               return (( passwd->bv_len == cred->bv_len ) &&
-                               ( passwd->bv_val[0] != '{' /*'}'*/ ))
-                       ? memcmp( passwd->bv_val, cred->bv_val, passwd->bv_len )
+               return ( passwd->bv_len == cred->bv_len ) ?
+                       memcmp( passwd->bv_val, cred->bv_val, passwd->bv_len )
                        : 1;
        }
 #endif
@@ -682,18 +691,21 @@ static int chk_md5(
  */
 
 static void lmPasswd_to_key(
-       const unsigned char *lmPasswd,
+       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 */
-       ((char *)key)[0] = lmPasswd[0];
-       ((char *)key)[1] = ((lmPasswd[0]&0x01)<<7) | (lmPasswd[1]>>1);
-       ((char *)key)[2] = ((lmPasswd[1]&0x03)<<6) | (lmPasswd[2]>>2);
-       ((char *)key)[3] = ((lmPasswd[2]&0x07)<<5) | (lmPasswd[3]>>3);
-       ((char *)key)[4] = ((lmPasswd[3]&0x0F)<<4) | (lmPasswd[4]>>4);
-       ((char *)key)[5] = ((lmPasswd[4]&0x1F)<<3) | (lmPasswd[5]>>5);
-       ((char *)key)[6] = ((lmPasswd[5]&0x3F)<<2) | (lmPasswd[6]>>6);
-       ((char *)key)[7] = ((lmPasswd[6]&0x7F)<<1);
+       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 );
 }      
@@ -778,9 +790,7 @@ static int chk_crypt(
        const struct berval * cred,
        const char **text )
 {
-       char *cr;
        unsigned int i;
-       int rc;
 
        for( i=0; i<cred->bv_len; i++) {
                if(cred->bv_val[i] == '\0') {
@@ -809,7 +819,7 @@ static int chk_crypt(
        return lutil_cryptptr( cred->bv_val, passwd->bv_val, NULL );
 }
 
-# if defined( HAVE_GETPWNAM ) && defined( HAVE_PW_PASSWD )
+# if defined( HAVE_GETPWNAM ) && defined( HAVE_STRUCT_PASSWD_PW_PASSWD )
 static int chk_unix(
        const struct berval *sc,
        const struct berval * passwd,
@@ -817,7 +827,7 @@ static int chk_unix(
        const char **text )
 {
        unsigned int i;
-       char *pw,*cr;
+       char *pw;
 
        for( i=0; i<cred->bv_len; i++) {
                if(cred->bv_val[i] == '\0') {