]> git.sur5r.net Git - openldap/blob - libraries/liblutil/passwd.c
Sync with HEAD
[openldap] / libraries / liblutil / passwd.c
1 /* $OpenLDAP$ */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-2003 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16
17 /*
18  * int lutil_passwd(
19  *      const struct berval *passwd,
20  *      const struct berval *cred,
21  *      const char **schemes )
22  *
23  * Returns true if user supplied credentials (cred) matches
24  * the stored password (passwd). 
25  *
26  * Due to the use of the crypt(3) function 
27  * this routine is NOT thread-safe.
28  */
29
30 #include "portable.h"
31
32 #include <stdio.h>
33 #include <ac/stdlib.h>
34 #include <ac/string.h>
35 #include <ac/unistd.h>
36
37 #ifdef SLAPD_SPASSWD
38 #       ifdef HAVE_SASL_SASL_H
39 #               include <sasl/sasl.h>
40 #       else
41 #               include <sasl.h>
42 #       endif
43 #endif
44
45 #ifdef SLAPD_KPASSWD
46 #       include <ac/krb.h>
47 #       include <ac/krb5.h>
48 #endif
49
50 /* KPASSWD/krb.h brings in a conflicting des.h so don't use both.
51  * configure currently requires OpenSSL to enable LMHASH. Obviously
52  * this requirement can be fulfilled by the KRB DES library as well.
53  */
54 #if defined(SLAPD_LMHASH) && !defined(DES_ENCRYPT)
55 #       include <openssl/des.h>
56 #endif /* SLAPD_LMHASH */
57
58 #include <ac/param.h>
59
60 #ifdef SLAPD_CRYPT
61 # include <ac/crypt.h>
62
63 # if defined( HAVE_GETPWNAM ) && defined( HAVE_PW_PASSWD )
64 #  ifdef HAVE_SHADOW_H
65 #       include <shadow.h>
66 #  endif
67 #  ifdef HAVE_PWD_H
68 #       include <pwd.h>
69 #  endif
70 #  ifdef HAVE_AIX_SECURITY
71 #       include <userpw.h>
72 #  endif
73 # endif
74 #endif
75
76 #include <lber.h>
77
78 #include "ldap_pvt.h"
79 #include "lber_pvt.h"
80
81 #include "lutil_md5.h"
82 #include "lutil_sha1.h"
83 #include "lutil.h"
84
85 static const unsigned char crypt64[] =
86         "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890./";
87
88 #ifdef SLAPD_CRYPT
89 static char *salt_format = NULL;
90 #endif
91
92 struct pw_scheme {
93         struct berval name;
94         LUTIL_PASSWD_CHK_FUNC *chk_fn;
95         LUTIL_PASSWD_HASH_FUNC *hash_fn;
96 };
97
98 struct pw_slist {
99         struct pw_slist *next;
100         struct pw_scheme s;
101 };
102
103 /* password check routines */
104
105 static LUTIL_PASSWD_CHK_FUNC chk_md5;
106 static LUTIL_PASSWD_CHK_FUNC chk_smd5;
107 static LUTIL_PASSWD_HASH_FUNC hash_smd5;
108 static LUTIL_PASSWD_HASH_FUNC hash_md5;
109
110
111 #ifdef LUTIL_SHA1_BYTES
112 static LUTIL_PASSWD_CHK_FUNC chk_ssha1;
113 static LUTIL_PASSWD_CHK_FUNC chk_sha1;
114 static LUTIL_PASSWD_HASH_FUNC hash_sha1;
115 static LUTIL_PASSWD_HASH_FUNC hash_ssha1;
116 #endif
117
118 #ifdef SLAPD_LMHASH
119 static LUTIL_PASSWD_CHK_FUNC chk_lanman;
120 static LUTIL_PASSWD_HASH_FUNC hash_lanman;
121 #endif
122
123 #ifdef SLAPD_NS_MTA_MD5
124 static LUTIL_PASSWD_CHK_FUNC chk_ns_mta_md5;
125 #endif
126
127 #ifdef SLAPD_SPASSWD
128 static LUTIL_PASSWD_CHK_FUNC chk_sasl;
129 #endif
130
131 #ifdef SLAPD_KPASSWD
132 static LUTIL_PASSWD_CHK_FUNC chk_kerberos;
133 #endif
134
135 #ifdef SLAPD_CRYPT
136 static LUTIL_PASSWD_CHK_FUNC chk_crypt;
137 static LUTIL_PASSWD_HASH_FUNC hash_crypt;
138
139 #if defined( HAVE_GETPWNAM ) && defined( HAVE_PW_PASSWD )
140 static LUTIL_PASSWD_CHK_FUNC chk_unix;
141 #endif
142 #endif
143
144 /* password hash routines */
145
146 #ifdef SLAPD_CLEARTEXT
147 static LUTIL_PASSWD_HASH_FUNC hash_clear;
148 #endif
149
150 static struct pw_slist *pw_schemes;
151
152 static const struct pw_scheme pw_schemes_default[] =
153 {
154 #ifdef LUTIL_SHA1_BYTES
155         { BER_BVC("{SSHA}"),            chk_ssha1, hash_ssha1 },
156         { BER_BVC("{SHA}"),                     chk_sha1, hash_sha1 },
157 #endif
158
159         { BER_BVC("{SMD5}"),            chk_smd5, hash_smd5 },
160         { BER_BVC("{MD5}"),                     chk_md5, hash_md5 },
161
162 #ifdef SLAPD_LMHASH
163         { BER_BVC("{LANMAN}"),          chk_lanman, hash_lanman },
164 #endif /* SLAPD_LMHASH */
165
166 #ifdef SLAPD_NS_MTA_MD5
167         { BER_BVC("{NS-MTA-MD5}"),      chk_ns_mta_md5, NULL },
168 #endif /* SLAPD_NS_MTA_MD5 */
169
170 #ifdef SLAPD_SPASSWD
171         { BER_BVC("{SASL}"),            chk_sasl, NULL },
172 #endif
173
174 #ifdef SLAPD_KPASSWD
175         { BER_BVC("{KERBEROS}"),        chk_kerberos, NULL },
176 #endif
177
178 #ifdef SLAPD_CRYPT
179         { BER_BVC("{CRYPT}"),           chk_crypt, hash_crypt },
180 # if defined( HAVE_GETPWNAM ) && defined( HAVE_PW_PASSWD )
181         { BER_BVC("{UNIX}"),            chk_unix, NULL },
182 # endif
183 #endif
184
185 #ifdef SLAPD_CLEARTEXT
186         /* pseudo scheme */
187         { {0, "{CLEARTEXT}"},           NULL, hash_clear },
188 #endif
189
190         { BER_BVNULL, NULL, NULL }
191 };
192
193 int lutil_passwd_add(
194         struct berval *scheme,
195         LUTIL_PASSWD_CHK_FUNC *chk,
196         LUTIL_PASSWD_HASH_FUNC *hash )
197 {
198         struct pw_slist *ptr;
199
200         ptr = ber_memalloc( sizeof( struct pw_slist ));
201         if (!ptr) return -1;
202         ptr->next = pw_schemes;
203         ptr->s.name = *scheme;
204         ptr->s.chk_fn = chk;
205         ptr->s.hash_fn = hash;
206         pw_schemes = ptr;
207         return 0;
208 }
209
210 void lutil_passwd_init()
211 {
212         struct pw_slist *ptr;
213         struct pw_scheme *s;
214
215         for( s=(struct pw_scheme *)pw_schemes_default; s->name.bv_val; s++) {
216                 if ( lutil_passwd_add( &s->name, s->chk_fn, s->hash_fn )) break;
217         }
218 }
219
220 void lutil_passwd_destroy()
221 {
222         struct pw_slist *ptr, *next;
223
224         for( ptr=pw_schemes; ptr; ptr=next ) {
225                 next = ptr->next;
226                 ber_memfree( ptr );
227         }
228 }
229
230 static const struct pw_scheme *get_scheme(
231         const char* scheme )
232 {
233         struct pw_slist *pws;
234
235         if (!pw_schemes) lutil_passwd_init();
236
237         for( pws=pw_schemes; pws; pws=pws->next ) {
238                 if( strcasecmp(scheme, pws->s.name.bv_val ) == 0 ) {
239                         return &(pws->s);
240                 }
241         }
242
243         return NULL;
244 }
245
246 int lutil_passwd_scheme(
247         const char* scheme )
248 {
249         if( scheme == NULL ) {
250                 return 0;
251         }
252
253         return get_scheme(scheme) != NULL;
254 }
255
256
257 static int is_allowed_scheme( 
258         const char* scheme,
259         const char** schemes )
260 {
261         int i;
262
263         if( schemes == NULL ) return 1;
264
265         for( i=0; schemes[i] != NULL; i++ ) {
266                 if( strcasecmp( scheme, schemes[i] ) == 0 ) {
267                         return 1;
268                 }
269         }
270         return 0;
271 }
272
273 static struct berval *passwd_scheme(
274         const struct pw_scheme *scheme,
275         const struct berval * passwd,
276         struct berval *bv,
277         const char** allowed )
278 {
279         if( !is_allowed_scheme( scheme->name.bv_val, allowed ) ) {
280                 return NULL;
281         }
282
283         if( passwd->bv_len >= scheme->name.bv_len ) {
284                 if( strncasecmp( passwd->bv_val, scheme->name.bv_val, scheme->name.bv_len ) == 0 ) {
285                         bv->bv_val = &passwd->bv_val[scheme->name.bv_len];
286                         bv->bv_len = passwd->bv_len - scheme->name.bv_len;
287
288                         return bv;
289                 }
290         }
291
292         return NULL;
293 }
294
295 /*
296  * Return 0 if creds are good.
297  */
298 int
299 lutil_passwd(
300         const struct berval *passwd,    /* stored passwd */
301         const struct berval *cred,              /* user cred */
302         const char **schemes,
303         const char **text )
304 {
305         struct pw_slist *pws;
306
307         if ( text ) *text = NULL;
308
309         if (cred == NULL || cred->bv_len == 0 ||
310                 passwd == NULL || passwd->bv_len == 0 )
311         {
312                 return -1;
313         }
314
315         if (!pw_schemes) lutil_passwd_init();
316
317         for( pws=pw_schemes; pws; pws=pws->next ) {
318                 if( pws->s.chk_fn ) {
319                         struct berval x;
320                         struct berval *p = passwd_scheme( &(pws->s),
321                                 passwd, &x, schemes );
322
323                         if( p != NULL ) {
324                                 return (pws->s.chk_fn)( &(pws->s.name), p, cred, text );
325                         }
326                 }
327         }
328
329 #ifdef SLAPD_CLEARTEXT
330         if( is_allowed_scheme("{CLEARTEXT}", schemes ) ) {
331                 return (( passwd->bv_len == cred->bv_len ) &&
332                                 ( passwd->bv_val[0] != '{' /*'}'*/ ))
333                         ? memcmp( passwd->bv_val, cred->bv_val, passwd->bv_len )
334                         : 1;
335         }
336 #endif
337         return 1;
338 }
339
340 struct berval * lutil_passwd_generate( ber_len_t len )
341 {
342         struct berval *pw;
343
344         if( len < 1 ) return NULL;
345
346         pw = ber_memalloc( sizeof( struct berval ) );
347         if( pw == NULL ) return NULL;
348
349         pw->bv_len = len;
350         pw->bv_val = ber_memalloc( len + 1 );
351
352         if( pw->bv_val == NULL ) {
353                 ber_memfree( pw );
354                 return NULL;
355         }
356
357         if( lutil_entropy( (unsigned char *) pw->bv_val, pw->bv_len) < 0 ) {
358                 ber_bvfree( pw );
359                 return NULL; 
360         }
361
362         for( len = 0; len < pw->bv_len; len++ ) {
363                 pw->bv_val[len] = crypt64[
364                         pw->bv_val[len] % (sizeof(crypt64)-1) ];
365         }
366
367         pw->bv_val[len] = '\0';
368         
369         return pw;
370 }
371
372 struct berval * lutil_passwd_hash(
373         const struct berval * passwd,
374         const char * method,
375         const char **text )
376 {
377         const struct pw_scheme *sc = get_scheme( method );
378
379         if( text ) *text = NULL;
380         if( sc == NULL ) return NULL;
381         if( ! sc->hash_fn ) return NULL;
382
383         return (sc->hash_fn)( &sc->name, passwd, text );
384 }
385
386 /* pw_string is only called when SLAPD_LMHASH or SLAPD_CRYPT is defined */
387 #if defined(SLAPD_LMHASH) || defined(SLAPD_CRYPT)
388 static struct berval * pw_string(
389         const struct berval *sc,
390         const struct berval *passwd )
391 {
392         struct berval *pw = ber_memalloc( sizeof( struct berval ) );
393         if( pw == NULL ) return NULL;
394
395         pw->bv_len = sc->bv_len + passwd->bv_len;
396         pw->bv_val = ber_memalloc( pw->bv_len + 1 );
397
398         if( pw->bv_val == NULL ) {
399                 ber_memfree( pw );
400                 return NULL;
401         }
402
403         AC_MEMCPY( pw->bv_val, sc->bv_val, sc->bv_len );
404         AC_MEMCPY( &pw->bv_val[sc->bv_len], passwd->bv_val, passwd->bv_len );
405
406         pw->bv_val[pw->bv_len] = '\0';
407         return pw;
408 }
409 #endif /* SLAPD_LMHASH || SLAPD_CRYPT */
410
411 static struct berval * pw_string64(
412         const struct berval *sc,
413         const struct berval *hash,
414         const struct berval *salt )
415 {
416         int rc;
417         struct berval string;
418         struct berval *b64 = ber_memalloc( sizeof(struct berval) );
419         size_t b64len;
420
421         if( b64 == NULL ) return NULL;
422
423         if( salt ) {
424                 /* need to base64 combined string */
425                 string.bv_len = hash->bv_len + salt->bv_len;
426                 string.bv_val = ber_memalloc( string.bv_len + 1 );
427
428                 if( string.bv_val == NULL ) {
429                         ber_memfree( b64 );
430                         return NULL;
431                 }
432
433                 AC_MEMCPY( string.bv_val, hash->bv_val,
434                         hash->bv_len );
435                 AC_MEMCPY( &string.bv_val[hash->bv_len], salt->bv_val,
436                         salt->bv_len );
437                 string.bv_val[string.bv_len] = '\0';
438
439         } else {
440                 string = *hash;
441         }
442
443         b64len = LUTIL_BASE64_ENCODE_LEN( string.bv_len ) + 1;
444         b64->bv_len = b64len + sc->bv_len;
445         b64->bv_val = ber_memalloc( b64->bv_len + 1 );
446
447         if( b64->bv_val == NULL ) {
448                 if( salt ) ber_memfree( string.bv_val );
449                 ber_memfree( b64 );
450                 return NULL;
451         }
452
453         AC_MEMCPY(b64->bv_val, sc->bv_val, sc->bv_len);
454
455         rc = lutil_b64_ntop(
456                 (unsigned char *) string.bv_val, string.bv_len,
457                 &b64->bv_val[sc->bv_len], b64len );
458
459         if( salt ) ber_memfree( string.bv_val );
460         
461         if( rc < 0 ) {
462                 ber_bvfree( b64 );
463                 return NULL;
464         }
465
466         /* recompute length */
467         b64->bv_len = sc->bv_len + rc;
468         assert( strlen(b64->bv_val) == b64->bv_len );
469         return b64;
470 }
471
472 /* PASSWORD CHECK ROUTINES */
473
474 #ifdef LUTIL_SHA1_BYTES
475 static int chk_ssha1(
476         const struct berval *sc,
477         const struct berval * passwd,
478         const struct berval * cred,
479         const char **text )
480 {
481         lutil_SHA1_CTX SHA1context;
482         unsigned char SHA1digest[LUTIL_SHA1_BYTES];
483         int rc;
484         unsigned char *orig_pass = NULL;
485
486         /* safety check */
487         if (LUTIL_BASE64_DECODE_LEN(passwd->bv_len) <= sizeof(SHA1digest)) {
488                 return -1;
489         }
490
491         /* decode base64 password */
492         orig_pass = (unsigned char *) ber_memalloc( (size_t) (
493                 LUTIL_BASE64_DECODE_LEN(passwd->bv_len) + 1) );
494
495         if( orig_pass == NULL ) return -1;
496
497         rc = lutil_b64_pton(passwd->bv_val, orig_pass, passwd->bv_len);
498
499         if (rc < 0 || (unsigned)rc <= sizeof(SHA1digest)) {
500                 ber_memfree(orig_pass);
501                 return -1;
502         }
503  
504         /* hash credentials with salt */
505         lutil_SHA1Init(&SHA1context);
506         lutil_SHA1Update(&SHA1context,
507                 (const unsigned char *) cred->bv_val, cred->bv_len);
508         lutil_SHA1Update(&SHA1context,
509                 (const unsigned char *) &orig_pass[sizeof(SHA1digest)],
510                 rc - sizeof(SHA1digest));
511         lutil_SHA1Final(SHA1digest, &SHA1context);
512  
513         /* compare */
514         rc = memcmp((char *)orig_pass, (char *)SHA1digest, sizeof(SHA1digest));
515         ber_memfree(orig_pass);
516         return rc ? 1 : 0;
517 }
518
519 static int chk_sha1(
520         const struct berval *sc,
521         const struct berval * passwd,
522         const struct berval * cred,
523         const char **text )
524 {
525         lutil_SHA1_CTX SHA1context;
526         unsigned char SHA1digest[LUTIL_SHA1_BYTES];
527         int rc;
528         unsigned char *orig_pass = NULL;
529  
530         /* base64 un-encode password */
531         orig_pass = (unsigned char *) ber_memalloc( (size_t) (
532                 LUTIL_BASE64_DECODE_LEN(passwd->bv_len) + 1) );
533
534         if( orig_pass == NULL ) return -1;
535
536         rc = lutil_b64_pton(passwd->bv_val, orig_pass, passwd->bv_len);
537
538         if( rc != sizeof(SHA1digest) ) {
539                 ber_memfree(orig_pass);
540                 return -1;
541         }
542  
543         /* hash credentials with salt */
544         lutil_SHA1Init(&SHA1context);
545         lutil_SHA1Update(&SHA1context,
546                 (const unsigned char *) cred->bv_val, cred->bv_len);
547         lutil_SHA1Final(SHA1digest, &SHA1context);
548  
549         /* compare */
550         rc = memcmp((char *)orig_pass, (char *)SHA1digest, sizeof(SHA1digest));
551         ber_memfree(orig_pass);
552         return rc ? 1 : 0;
553 }
554 #endif
555
556 static int chk_smd5(
557         const struct berval *sc,
558         const struct berval * passwd,
559         const struct berval * cred,
560         const char **text )
561 {
562         lutil_MD5_CTX MD5context;
563         unsigned char MD5digest[LUTIL_MD5_BYTES];
564         int rc;
565         unsigned char *orig_pass = NULL;
566
567         /* safety check */
568         if (LUTIL_BASE64_DECODE_LEN(passwd->bv_len) <= sizeof(MD5digest)) {
569                 return -1;
570         }
571
572         /* base64 un-encode password */
573         orig_pass = (unsigned char *) ber_memalloc( (size_t) (
574                 LUTIL_BASE64_DECODE_LEN(passwd->bv_len) + 1) );
575
576         if( orig_pass == NULL ) return -1;
577
578         rc = lutil_b64_pton(passwd->bv_val, orig_pass, passwd->bv_len);
579
580         if (rc < 0 || (unsigned)rc <= sizeof(MD5digest)) {
581                 ber_memfree(orig_pass);
582                 return -1;
583         }
584
585         /* hash credentials with salt */
586         lutil_MD5Init(&MD5context);
587         lutil_MD5Update(&MD5context,
588                 (const unsigned char *) cred->bv_val,
589                 cred->bv_len );
590         lutil_MD5Update(&MD5context,
591                 &orig_pass[sizeof(MD5digest)],
592                 rc - sizeof(MD5digest));
593         lutil_MD5Final(MD5digest, &MD5context);
594
595         /* compare */
596         rc = memcmp((char *)orig_pass, (char *)MD5digest, sizeof(MD5digest));
597         ber_memfree(orig_pass);
598         return rc ? 1 : 0;
599 }
600
601 static int chk_md5(
602         const struct berval *sc,
603         const struct berval * passwd,
604         const struct berval * cred,
605         const char **text )
606 {
607         lutil_MD5_CTX MD5context;
608         unsigned char MD5digest[LUTIL_MD5_BYTES];
609         int rc;
610         unsigned char *orig_pass = NULL;
611
612         /* base64 un-encode password */
613         orig_pass = (unsigned char *) ber_memalloc( (size_t) (
614                 LUTIL_BASE64_DECODE_LEN(passwd->bv_len) + 1) );
615
616         if( orig_pass == NULL ) return -1;
617
618         rc = lutil_b64_pton(passwd->bv_val, orig_pass, passwd->bv_len);
619         if ( rc != sizeof(MD5digest) ) {
620                 ber_memfree(orig_pass);
621                 return -1;
622         }
623
624         /* hash credentials with salt */
625         lutil_MD5Init(&MD5context);
626         lutil_MD5Update(&MD5context,
627                 (const unsigned char *) cred->bv_val,
628                 cred->bv_len );
629         lutil_MD5Final(MD5digest, &MD5context);
630
631         /* compare */
632         rc = memcmp((char *)orig_pass, (char *)MD5digest, sizeof(MD5digest));
633         ber_memfree(orig_pass);
634         return rc ? 1 : 0;
635 }
636
637 #ifdef SLAPD_LMHASH
638 /* pseudocode from RFC2433
639  * A.2 LmPasswordHash()
640  * 
641  *    LmPasswordHash(
642  *    IN  0-to-14-oem-char Password,
643  *    OUT 16-octet         PasswordHash )
644  *    {
645  *       Set UcasePassword to the uppercased Password
646  *       Zero pad UcasePassword to 14 characters
647  * 
648  *       DesHash( 1st 7-octets of UcasePassword,
649  *                giving 1st 8-octets of PasswordHash )
650  * 
651  *       DesHash( 2nd 7-octets of UcasePassword,
652  *                giving 2nd 8-octets of PasswordHash )
653  *    }
654  * 
655  * 
656  * A.3 DesHash()
657  * 
658  *    DesHash(
659  *    IN  7-octet Clear,
660  *    OUT 8-octet Cypher )
661  *    {
662  *        *
663  *        * Make Cypher an irreversibly encrypted form of Clear by
664  *        * encrypting known text using Clear as the secret key.
665  *        * The known text consists of the string
666  *        *
667  *        *              KGS!@#$%
668  *        *
669  * 
670  *       Set StdText to "KGS!@#$%"
671  *       DesEncrypt( StdText, Clear, giving Cypher )
672  *    }
673  * 
674  * 
675  * A.4 DesEncrypt()
676  * 
677  *    DesEncrypt(
678  *    IN  8-octet Clear,
679  *    IN  7-octet Key,
680  *    OUT 8-octet Cypher )
681  *    {
682  *        *
683  *        * Use the DES encryption algorithm [4] in ECB mode [9]
684  *        * to encrypt Clear into Cypher such that Cypher can
685  *        * only be decrypted back to Clear by providing Key.
686  *        * Note that the DES algorithm takes as input a 64-bit
687  *        * stream where the 8th, 16th, 24th, etc.  bits are
688  *        * parity bits ignored by the encrypting algorithm.
689  *        * Unless you write your own DES to accept 56-bit input
690  *        * without parity, you will need to insert the parity bits
691  *        * yourself.
692  *        *
693  *    }
694  */
695
696 static void lmPasswd_to_key(
697         const unsigned char *lmPasswd,
698         des_cblock *key)
699 {
700         /* make room for parity bits */
701         ((char *)key)[0] = lmPasswd[0];
702         ((char *)key)[1] = ((lmPasswd[0]&0x01)<<7) | (lmPasswd[1]>>1);
703         ((char *)key)[2] = ((lmPasswd[1]&0x03)<<6) | (lmPasswd[2]>>2);
704         ((char *)key)[3] = ((lmPasswd[2]&0x07)<<5) | (lmPasswd[3]>>3);
705         ((char *)key)[4] = ((lmPasswd[3]&0x0F)<<4) | (lmPasswd[4]>>4);
706         ((char *)key)[5] = ((lmPasswd[4]&0x1F)<<3) | (lmPasswd[5]>>5);
707         ((char *)key)[6] = ((lmPasswd[5]&0x3F)<<2) | (lmPasswd[6]>>6);
708         ((char *)key)[7] = ((lmPasswd[6]&0x7F)<<1);
709                 
710         des_set_odd_parity( key );
711 }       
712
713 static int chk_lanman(
714         const struct berval *scheme,
715         const struct berval *passwd,
716         const struct berval *cred,
717         const char **text )
718 {
719         int i;
720         char UcasePassword[15];
721         des_cblock key;
722         des_key_schedule schedule;
723         des_cblock StdText = "KGS!@#$%";
724         des_cblock PasswordHash1, PasswordHash2;
725         char PasswordHash[33], storedPasswordHash[33];
726         
727         for( i=0; i<cred->bv_len; i++) {
728                 if(cred->bv_val[i] == '\0') {
729                         return -1;      /* NUL character in password */
730                 }
731         }
732         
733         if( cred->bv_val[i] != '\0' ) {
734                 return -1;      /* passwd must behave like a string */
735         }
736         
737         strncpy( UcasePassword, cred->bv_val, 14 );
738         UcasePassword[14] = '\0';
739         ldap_pvt_str2upper( UcasePassword );
740         
741         lmPasswd_to_key( UcasePassword, &key );
742         des_set_key_unchecked( &key, schedule );
743         des_ecb_encrypt( &StdText, &PasswordHash1, schedule , DES_ENCRYPT );
744         
745         lmPasswd_to_key( &UcasePassword[7], &key );
746         des_set_key_unchecked( &key, schedule );
747         des_ecb_encrypt( &StdText, &PasswordHash2, schedule , DES_ENCRYPT );
748         
749         sprintf( PasswordHash, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", 
750                 PasswordHash1[0],PasswordHash1[1],PasswordHash1[2],PasswordHash1[3],
751                 PasswordHash1[4],PasswordHash1[5],PasswordHash1[6],PasswordHash1[7],
752                 PasswordHash2[0],PasswordHash2[1],PasswordHash2[2],PasswordHash2[3],
753                 PasswordHash2[4],PasswordHash2[5],PasswordHash2[6],PasswordHash2[7] );
754         
755         /* as a precaution convert stored password hash to lower case */
756         strncpy( storedPasswordHash, passwd->bv_val, 32 );
757         storedPasswordHash[32] = '\0';
758         ldap_pvt_str2lower( storedPasswordHash );
759         
760         return memcmp( PasswordHash, storedPasswordHash, 32) ? 1 : 0;
761 }
762 #endif /* SLAPD_LMHASH */
763
764 #ifdef SLAPD_NS_MTA_MD5
765 static int chk_ns_mta_md5(
766         const struct berval *scheme,
767         const struct berval *passwd,
768         const struct berval *cred,
769         const char **text )
770 {
771         lutil_MD5_CTX MD5context;
772         unsigned char MD5digest[LUTIL_MD5_BYTES], c;
773         char buffer[LUTIL_MD5_BYTES*2];
774         int i;
775
776         if( passwd->bv_len != LUTIL_MD5_BYTES*2 ) {
777                 return 1;
778         }
779
780         /* hash credentials with salt */
781         lutil_MD5Init(&MD5context);
782         lutil_MD5Update(&MD5context,
783                 (const unsigned char *) &passwd->bv_val[32],
784                 32 );
785
786         c = 0x59;
787         lutil_MD5Update(&MD5context,
788                 (const unsigned char *) &c,
789                 1 );
790
791         lutil_MD5Update(&MD5context,
792                 (const unsigned char *) cred->bv_val,
793                 cred->bv_len );
794
795         c = 0xF7;
796         lutil_MD5Update(&MD5context,
797                 (const unsigned char *) &c,
798                 1 );
799
800         lutil_MD5Update(&MD5context,
801                 (const unsigned char *) &passwd->bv_val[32],
802                 32 );
803
804         lutil_MD5Final(MD5digest, &MD5context);
805
806         for( i=0; i < sizeof( MD5digest ); i++ ) {
807                 buffer[i+i]   = "0123456789abcdef"[(MD5digest[i]>>4) & 0x0F]; 
808                 buffer[i+i+1] = "0123456789abcdef"[ MD5digest[i] & 0x0F]; 
809         }
810
811         /* compare */
812         return memcmp((char *)passwd->bv_val,
813                 (char *)buffer, sizeof(buffer)) ? 1 : 0;
814 }
815 #endif
816
817 #ifdef SLAPD_SPASSWD
818 #ifdef HAVE_CYRUS_SASL
819 sasl_conn_t *lutil_passwd_sasl_conn = NULL;
820 #endif
821
822 static int chk_sasl(
823         const struct berval *sc,
824         const struct berval * passwd,
825         const struct berval * cred,
826         const char **text )
827 {
828         unsigned int i;
829         int rtn;
830
831         for( i=0; i<cred->bv_len; i++) {
832                 if(cred->bv_val[i] == '\0') {
833                         return 1;       /* NUL character in password */
834                 }
835         }
836
837         if( cred->bv_val[i] != '\0' ) {
838                 return 1;       /* cred must behave like a string */
839         }
840
841         for( i=0; i<passwd->bv_len; i++) {
842                 if(passwd->bv_val[i] == '\0') {
843                         return 1;       /* NUL character in password */
844                 }
845         }
846
847         if( passwd->bv_val[i] != '\0' ) {
848                 return 1;       /* passwd must behave like a string */
849         }
850
851         rtn = 1;
852
853 #ifdef HAVE_CYRUS_SASL
854         if( lutil_passwd_sasl_conn != NULL ) {
855                 int sc;
856 # if SASL_VERSION_MAJOR < 2
857                 sc = sasl_checkpass( lutil_passwd_sasl_conn,
858                         passwd->bv_val, passwd->bv_len,
859                         cred->bv_val, cred->bv_len,
860                         text );
861 # else
862                 sc = sasl_checkpass( lutil_passwd_sasl_conn,
863                         passwd->bv_val, passwd->bv_len,
864                         cred->bv_val, cred->bv_len );
865 # endif
866                 rtn = ( sc != SASL_OK );
867         }
868 #endif
869
870         return rtn;
871 }
872 #endif
873
874 #ifdef SLAPD_KPASSWD
875 static int chk_kerberos(
876         const struct berval *sc,
877         const struct berval * passwd,
878         const struct berval * cred,
879         const char **text )
880 {
881         unsigned int i;
882         int rtn;
883
884         for( i=0; i<cred->bv_len; i++) {
885                 if(cred->bv_val[i] == '\0') {
886                         return 1;       /* NUL character in password */
887                 }
888         }
889
890         if( cred->bv_val[i] != '\0' ) {
891                 return 1;       /* cred must behave like a string */
892         }
893
894         for( i=0; i<passwd->bv_len; i++) {
895                 if(passwd->bv_val[i] == '\0') {
896                         return 1;       /* NUL character in password */
897                 }
898         }
899
900         if( passwd->bv_val[i] != '\0' ) {
901                 return 1;       /* passwd must behave like a string */
902         }
903
904         rtn = 1;
905
906 #ifdef HAVE_KRB5 /* HAVE_HEIMDAL_KRB5 */
907         {
908 /* Portions:
909  * Copyright (c) 1997, 1998, 1999 Kungliga Tekniska H\xf6gskolan
910  * (Royal Institute of Technology, Stockholm, Sweden).
911  * All rights reserved.
912  *
913  * Redistribution and use in source and binary forms, with or without
914  * modification, are permitted provided that the following conditions
915  * are met:
916  *
917  * 1. Redistributions of source code must retain the above copyright
918  *    notice, this list of conditions and the following disclaimer.
919  *
920  * 2. Redistributions in binary form must reproduce the above copyright
921  *    notice, this list of conditions and the following disclaimer in the
922  *    documentation and/or other materials provided with the distribution.
923  *
924  * 3. Neither the name of the Institute nor the names of its contributors
925  *    may be used to endorse or promote products derived from this software
926  *    without specific prior written permission.
927  *
928  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
929  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
930  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
931  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
932  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
933  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
934  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
935  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
936  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
937  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
938  * SUCH DAMAGE.
939  */
940
941                 krb5_context context;
942                 krb5_error_code ret;
943                 krb5_creds creds;
944                 krb5_get_init_creds_opt get_options;
945                 krb5_verify_init_creds_opt verify_options;
946                 krb5_principal client, server;
947 #ifdef notdef
948                 krb5_preauthtype pre_auth_types[] = {KRB5_PADATA_ENC_TIMESTAMP};
949 #endif
950
951                 ret = krb5_init_context( &context );
952                 if (ret) {
953                         return 1;
954                 }
955
956 #ifdef notdef
957                 krb5_get_init_creds_opt_set_preauth_list(&get_options,
958                         pre_auth_types, 1);
959 #endif
960
961                 krb5_get_init_creds_opt_init( &get_options );
962
963                 krb5_verify_init_creds_opt_init( &verify_options );
964         
965                 ret = krb5_parse_name( context, passwd->bv_val, &client );
966
967                 if (ret) {
968                         krb5_free_context( context );
969                         return 1;
970                 }
971
972                 ret = krb5_get_init_creds_password( context,
973                         &creds, client, cred->bv_val, NULL,
974                         NULL, 0, NULL, &get_options );
975
976                 if (ret) {
977                         krb5_free_principal( context, client );
978                         krb5_free_context( context );
979                         return 1;
980                 }
981
982                 {
983                         char *host = ldap_pvt_get_fqdn( NULL );
984
985                         if( host == NULL ) {
986                                 krb5_free_principal( context, client );
987                                 krb5_free_context( context );
988                                 return 1;
989                         }
990
991                         ret = krb5_sname_to_principal( context,
992                                 host, "ldap", KRB5_NT_SRV_HST, &server );
993
994                         ber_memfree( host );
995                 }
996
997                 if (ret) {
998                         krb5_free_principal( context, client );
999                         krb5_free_context( context );
1000                         return 1;
1001                 }
1002
1003                 ret = krb5_verify_init_creds( context,
1004                         &creds, server, NULL, NULL, &verify_options );
1005
1006                 krb5_free_principal( context, client );
1007                 krb5_free_principal( context, server );
1008                 krb5_free_cred_contents( context, &creds );
1009                 krb5_free_context( context );
1010
1011                 rtn = !!ret;
1012         }
1013 #elif   defined(HAVE_KRB4)
1014         {
1015                 /* Borrowed from Heimdal kpopper */
1016 /* Portions:
1017  * Copyright (c) 1989 Regents of the University of California.
1018  * All rights reserved.  The Berkeley software License Agreement
1019  * specifies the terms and conditions for redistribution.
1020  */
1021
1022                 int status;
1023                 char lrealm[REALM_SZ];
1024                 char tkt[MAXHOSTNAMELEN];
1025
1026                 status = krb_get_lrealm(lrealm,1);
1027                 if (status == KFAILURE) {
1028                         return 1;
1029                 }
1030
1031                 snprintf(tkt, sizeof(tkt), "%s_slapd.%u",
1032                         TKT_ROOT, (unsigned)getpid());
1033                 krb_set_tkt_string (tkt);
1034
1035                 status = krb_verify_user( passwd->bv_val, "", lrealm,
1036                         cred->bv_val, 1, "ldap");
1037
1038                 dest_tkt(); /* no point in keeping the tickets */
1039
1040                 return status == KFAILURE;
1041         }
1042 #endif
1043
1044         return rtn;
1045 }
1046 #endif /* SLAPD_KPASSWD */
1047
1048 #ifdef SLAPD_CRYPT
1049 static int chk_crypt(
1050         const struct berval *sc,
1051         const struct berval * passwd,
1052         const struct berval * cred,
1053         const char **text )
1054 {
1055         char *cr;
1056         unsigned int i;
1057
1058         for( i=0; i<cred->bv_len; i++) {
1059                 if(cred->bv_val[i] == '\0') {
1060                         return 1;       /* NUL character in password */
1061                 }
1062         }
1063
1064         if( cred->bv_val[i] != '\0' ) {
1065                 return -1;      /* cred must behave like a string */
1066         }
1067
1068         if( passwd->bv_len < 2 ) {
1069                 return -1;      /* passwd must be at least two characters long */
1070         }
1071
1072         for( i=0; i<passwd->bv_len; i++) {
1073                 if(passwd->bv_val[i] == '\0') {
1074                         return -1;      /* NUL character in password */
1075                 }
1076         }
1077
1078         if( passwd->bv_val[i] != '\0' ) {
1079                 return -1;      /* passwd must behave like a string */
1080         }
1081
1082         cr = crypt( cred->bv_val, passwd->bv_val );
1083
1084         if( cr == NULL || cr[0] == '\0' ) {
1085                 /* salt must have been invalid */
1086                 return -1;
1087         }
1088
1089         return strcmp( passwd->bv_val, cr ) ? 1 : 0;
1090 }
1091
1092 # if defined( HAVE_GETPWNAM ) && defined( HAVE_PW_PASSWD )
1093 static int chk_unix(
1094         const struct berval *sc,
1095         const struct berval * passwd,
1096         const struct berval * cred,
1097         const char **text )
1098 {
1099         unsigned int i;
1100         char *pw,*cr;
1101
1102         for( i=0; i<cred->bv_len; i++) {
1103                 if(cred->bv_val[i] == '\0') {
1104                         return -1;      /* NUL character in password */
1105                 }
1106         }
1107         if( cred->bv_val[i] != '\0' ) {
1108                 return -1;      /* cred must behave like a string */
1109         }
1110
1111         for( i=0; i<passwd->bv_len; i++) {
1112                 if(passwd->bv_val[i] == '\0') {
1113                         return -1;      /* NUL character in password */
1114                 }
1115         }
1116
1117         if( passwd->bv_val[i] != '\0' ) {
1118                 return -1;      /* passwd must behave like a string */
1119         }
1120
1121         {
1122                 struct passwd *pwd = getpwnam(passwd->bv_val);
1123
1124                 if(pwd == NULL) {
1125                         return -1;      /* not found */
1126                 }
1127
1128                 pw = pwd->pw_passwd;
1129         }
1130 #  ifdef HAVE_GETSPNAM
1131         {
1132                 struct spwd *spwd = getspnam(passwd->bv_val);
1133
1134                 if(spwd != NULL) {
1135                         pw = spwd->sp_pwdp;
1136                 }
1137         }
1138 #  endif
1139 #  ifdef HAVE_AIX_SECURITY
1140         {
1141                 struct userpw *upw = getuserpw(passwd->bv_val);
1142
1143                 if (upw != NULL) {
1144                         pw = upw->upw_passwd;
1145                 }
1146         }
1147 #  endif
1148
1149         if( pw == NULL || pw[0] == '\0' || pw[1] == '\0' ) {
1150                 /* password must must be at least two characters long */
1151                 return -1;
1152         }
1153
1154         cr = crypt(cred->bv_val, pw);
1155
1156         if( cr == NULL || cr[0] == '\0' ) {
1157                 /* salt must have been invalid */
1158                 return -1;
1159         }
1160
1161         return strcmp(pw, cr) ? 1 : 0;
1162
1163 }
1164 # endif
1165 #endif
1166
1167 /* PASSWORD GENERATION ROUTINES */
1168
1169 #ifdef LUTIL_SHA1_BYTES
1170 static struct berval *hash_ssha1(
1171         const struct berval *scheme,
1172         const struct berval  *passwd,
1173         const char **text )
1174 {
1175         lutil_SHA1_CTX  SHA1context;
1176         unsigned char   SHA1digest[LUTIL_SHA1_BYTES];
1177         char            saltdata[4];
1178         struct berval digest;
1179         struct berval salt;
1180
1181         digest.bv_val = (char *) SHA1digest;
1182         digest.bv_len = sizeof(SHA1digest);
1183         salt.bv_val = saltdata;
1184         salt.bv_len = sizeof(saltdata);
1185
1186         if( lutil_entropy( (unsigned char *) salt.bv_val, salt.bv_len) < 0 ) {
1187                 return NULL; 
1188         }
1189
1190         lutil_SHA1Init( &SHA1context );
1191         lutil_SHA1Update( &SHA1context,
1192                 (const unsigned char *)passwd->bv_val, passwd->bv_len );
1193         lutil_SHA1Update( &SHA1context,
1194                 (const unsigned char *)salt.bv_val, salt.bv_len );
1195         lutil_SHA1Final( SHA1digest, &SHA1context );
1196
1197         return pw_string64( scheme, &digest, &salt);
1198 }
1199
1200 static struct berval *hash_sha1(
1201         const struct berval *scheme,
1202         const struct berval  *passwd,
1203         const char **text )
1204 {
1205         lutil_SHA1_CTX  SHA1context;
1206         unsigned char   SHA1digest[LUTIL_SHA1_BYTES];
1207         struct berval digest;
1208         digest.bv_val = (char *) SHA1digest;
1209         digest.bv_len = sizeof(SHA1digest);
1210      
1211         lutil_SHA1Init( &SHA1context );
1212         lutil_SHA1Update( &SHA1context,
1213                 (const unsigned char *)passwd->bv_val, passwd->bv_len );
1214         lutil_SHA1Final( SHA1digest, &SHA1context );
1215             
1216         return pw_string64( scheme, &digest, NULL);
1217 }
1218 #endif
1219
1220 static struct berval *hash_smd5(
1221         const struct berval *scheme,
1222         const struct berval  *passwd,
1223         const char **text )
1224 {
1225         lutil_MD5_CTX   MD5context;
1226         unsigned char   MD5digest[LUTIL_MD5_BYTES];
1227         char            saltdata[4];
1228         struct berval digest;
1229         struct berval salt;
1230
1231         digest.bv_val = (char *) MD5digest;
1232         digest.bv_len = sizeof(MD5digest);
1233         salt.bv_val = saltdata;
1234         salt.bv_len = sizeof(saltdata);
1235
1236         if( lutil_entropy( (unsigned char *) salt.bv_val, salt.bv_len) < 0 ) {
1237                 return NULL; 
1238         }
1239
1240         lutil_MD5Init( &MD5context );
1241         lutil_MD5Update( &MD5context,
1242                 (const unsigned char *) passwd->bv_val, passwd->bv_len );
1243         lutil_MD5Update( &MD5context,
1244                 (const unsigned char *) salt.bv_val, salt.bv_len );
1245         lutil_MD5Final( MD5digest, &MD5context );
1246
1247         return pw_string64( scheme, &digest, &salt );
1248 }
1249
1250 static struct berval *hash_md5(
1251         const struct berval *scheme,
1252         const struct berval  *passwd,
1253         const char **text )
1254 {
1255         lutil_MD5_CTX   MD5context;
1256         unsigned char   MD5digest[LUTIL_MD5_BYTES];
1257
1258         struct berval digest;
1259
1260         digest.bv_val = (char *) MD5digest;
1261         digest.bv_len = sizeof(MD5digest);
1262
1263         lutil_MD5Init( &MD5context );
1264         lutil_MD5Update( &MD5context,
1265                 (const unsigned char *) passwd->bv_val, passwd->bv_len );
1266         lutil_MD5Final( MD5digest, &MD5context );
1267
1268         return pw_string64( scheme, &digest, NULL );
1269 ;
1270 }
1271
1272 #ifdef SLAPD_LMHASH 
1273 static struct berval *hash_lanman(
1274         const struct berval *scheme,
1275         const struct berval *passwd,
1276         const char **text )
1277 {
1278
1279         int i;
1280         char UcasePassword[15];
1281         des_cblock key;
1282         des_key_schedule schedule;
1283         des_cblock StdText = "KGS!@#$%";
1284         des_cblock PasswordHash1, PasswordHash2;
1285         char PasswordHash[33];
1286         struct berval hash;
1287         
1288         for( i=0; i<passwd->bv_len; i++) {
1289                 if(passwd->bv_val[i] == '\0') {
1290                         return NULL;    /* NUL character in password */
1291                 }
1292         }
1293         
1294         if( passwd->bv_val[i] != '\0' ) {
1295                 return NULL;    /* passwd must behave like a string */
1296         }
1297         
1298         strncpy( UcasePassword, passwd->bv_val, 14 );
1299         UcasePassword[14] = '\0';
1300         ldap_pvt_str2upper( UcasePassword );
1301         
1302         lmPasswd_to_key( UcasePassword, &key );
1303         des_set_key_unchecked( &key, schedule );
1304         des_ecb_encrypt( &StdText, &PasswordHash1, schedule , DES_ENCRYPT );
1305         
1306         lmPasswd_to_key( &UcasePassword[7], &key );
1307         des_set_key_unchecked( &key, schedule );
1308         des_ecb_encrypt( &StdText, &PasswordHash2, schedule , DES_ENCRYPT );
1309         
1310         sprintf( PasswordHash, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", 
1311                 PasswordHash1[0],PasswordHash1[1],PasswordHash1[2],PasswordHash1[3],
1312                 PasswordHash1[4],PasswordHash1[5],PasswordHash1[6],PasswordHash1[7],
1313                 PasswordHash2[0],PasswordHash2[1],PasswordHash2[2],PasswordHash2[3],
1314                 PasswordHash2[4],PasswordHash2[5],PasswordHash2[6],PasswordHash2[7] );
1315         
1316         hash.bv_val = PasswordHash;
1317         hash.bv_len = 32;
1318         
1319         return pw_string( scheme, &hash );
1320 }
1321 #endif /* SLAPD_LMHASH */
1322
1323 #ifdef SLAPD_CRYPT
1324 static struct berval *hash_crypt(
1325         const struct berval *scheme,
1326         const struct berval *passwd,
1327         const char **text )
1328 {
1329         struct berval hash;
1330         unsigned char salt[32]; /* salt suitable for most anything */
1331         unsigned int i;
1332
1333         for( i=0; i<passwd->bv_len; i++) {
1334                 if(passwd->bv_val[i] == '\0') {
1335                         return NULL;    /* NUL character in password */
1336                 }
1337         }
1338
1339         if( passwd->bv_val[i] != '\0' ) {
1340                 return NULL;    /* passwd must behave like a string */
1341         }
1342
1343         if( lutil_entropy( salt, sizeof( salt ) ) < 0 ) {
1344                 return NULL; 
1345         }
1346
1347         for( i=0; i< ( sizeof(salt) - 1 ); i++ ) {
1348                 salt[i] = crypt64[ salt[i] % (sizeof(crypt64)-1) ];
1349         }
1350         salt[sizeof( salt ) - 1 ] = '\0';
1351
1352         if( salt_format != NULL ) {
1353                 /* copy the salt we made into entropy before snprintfing
1354                    it back into the salt */
1355                 char entropy[sizeof(salt)];
1356                 strcpy( entropy, (char *) salt );
1357                 snprintf( (char *) salt, sizeof(entropy), salt_format, entropy );
1358         }
1359
1360         hash.bv_val = crypt( passwd->bv_val, (char *) salt );
1361
1362         if( hash.bv_val == NULL ) return NULL;
1363
1364         hash.bv_len = strlen( hash.bv_val );
1365
1366         if( hash.bv_len == 0 ) {
1367                 return NULL;
1368         }
1369
1370         return pw_string( scheme, &hash );
1371 }
1372 #endif
1373
1374 int lutil_salt_format(const char *format)
1375 {
1376 #ifdef SLAPD_CRYPT
1377         free( salt_format );
1378
1379         salt_format = format != NULL ? strdup( format ) : NULL;
1380 #endif
1381
1382         return 0;
1383 }
1384
1385 #ifdef SLAPD_CLEARTEXT
1386 static struct berval *hash_clear(
1387         const struct berval *scheme,
1388         const struct berval  *passwd,
1389         const char **text )
1390 {
1391         return ber_bvdup( (struct berval *) passwd );
1392 }
1393 #endif
1394