1 /* smbk5pwd.c - Overlay for managing Samba and Heimdal passwords */
4 * Copyright 2004-2005 by Howard Chu, Symas Corp.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
16 * Support for table-driven configuration added by Pierangelo Masarati.
17 * Support for sambaPwdMustChange and sambaPwdCanChange added by Marco D'Ettorre.
19 * The conditions of the OpenLDAP Public License apply.
24 #ifndef SLAPD_OVER_SMBK5PWD
25 #define SLAPD_OVER_SMBK5PWD SLAPD_MOD_DYNAMIC
28 #ifdef SLAPD_OVER_SMBK5PWD
32 #include <ac/string.h>
41 /* make ASN1_MALLOC_ENCODE use our allocator */
42 #define malloc ch_malloc
45 #include <kadm5/admin.h>
48 #ifndef HDB_INTERFACE_VERSION
49 #define HDB_MASTER_KEY_SET master_key_set
51 #define HDB_MASTER_KEY_SET hdb_master_key_set
54 static krb5_context context;
55 static void *kadm_context;
56 static kadm5_config_params conf;
59 static AttributeDescription *ad_krb5Key;
60 static AttributeDescription *ad_krb5KeyVersionNumber;
61 static AttributeDescription *ad_krb5PrincipalName;
62 static ObjectClass *oc_krb5KDCEntry;
66 #include <openssl/des.h>
67 #include <openssl/md4.h>
68 #include "ldap_utf8.h"
70 static AttributeDescription *ad_sambaLMPassword;
71 static AttributeDescription *ad_sambaNTPassword;
72 static AttributeDescription *ad_sambaPwdLastSet;
73 static AttributeDescription *ad_sambaPwdMustChange;
74 static AttributeDescription *ad_sambaPwdCanChange;
75 static ObjectClass *oc_sambaSamAccount;
78 /* Per-instance configuration information */
79 typedef struct smbk5pwd_t {
81 #define SMBK5PWD_F_KRB5 (0x1U)
82 #define SMBK5PWD_F_SAMBA (0x2U)
84 #define SMBK5PWD_DO_KRB5(pi) ((pi)->mode & SMBK5PWD_F_KRB5)
85 #define SMBK5PWD_DO_SAMBA(pi) ((pi)->mode & SMBK5PWD_F_SAMBA)
92 /* How many seconds before forcing a password change? */
93 time_t smb_must_change;
94 /* How many seconds after allowing a password change? */
95 time_t smb_can_change;
99 static const unsigned SMBK5PWD_F_ALL =
109 static int smbk5pwd_modules_init( smbk5pwd_t *pi );
112 static const char hex[] = "0123456789abcdef";
114 /* From liblutil/passwd.c... */
115 static void lmPasswd_to_key(
116 const char *lmPasswd,
119 const unsigned char *lpw = (const unsigned char *)lmPasswd;
120 unsigned char *k = (unsigned char *)key;
122 /* make room for parity bits */
124 k[1] = ((lpw[0]&0x01)<<7) | (lpw[1]>>1);
125 k[2] = ((lpw[1]&0x03)<<6) | (lpw[2]>>2);
126 k[3] = ((lpw[2]&0x07)<<5) | (lpw[3]>>3);
127 k[4] = ((lpw[3]&0x0F)<<4) | (lpw[4]>>4);
128 k[5] = ((lpw[4]&0x1F)<<3) | (lpw[5]>>5);
129 k[6] = ((lpw[5]&0x3F)<<2) | (lpw[6]>>6);
130 k[7] = ((lpw[6]&0x7F)<<1);
132 des_set_odd_parity( key );
135 #define MAX_PWLEN 256
139 const char in[HASHLEN],
147 out->bv_val = ch_malloc(HASHLEN*2 + 1);
148 out->bv_len = HASHLEN*2;
151 b = (unsigned char *)in;
152 for (i=0; i<HASHLEN; i++) {
154 *a++ = hex[*b++ & 0x0f];
160 struct berval *passwd,
164 char UcasePassword[15];
166 des_key_schedule schedule;
167 des_cblock StdText = "KGS!@#$%";
170 strncpy( UcasePassword, passwd->bv_val, 14 );
171 UcasePassword[14] = '\0';
172 ldap_pvt_str2upper( UcasePassword );
174 lmPasswd_to_key( UcasePassword, &key );
175 des_set_key_unchecked( &key, schedule );
176 des_ecb_encrypt( &StdText, &hbuf[0], schedule , DES_ENCRYPT );
178 lmPasswd_to_key( &UcasePassword[7], &key );
179 des_set_key_unchecked( &key, schedule );
180 des_ecb_encrypt( &StdText, &hbuf[1], schedule , DES_ENCRYPT );
182 hexify( (char *)hbuf, hash );
186 struct berval *passwd,
190 /* Windows currently only allows 14 character passwords, but
191 * may support up to 256 in the future. We assume this means
192 * 256 UCS2 characters, not 256 bytes...
197 if (passwd->bv_len > MAX_PWLEN*2)
198 passwd->bv_len = MAX_PWLEN*2;
201 MD4_Update( &ctx, passwd->bv_val, passwd->bv_len );
202 MD4_Final( (unsigned char *)hbuf, &ctx );
204 hexify( hbuf, hash );
206 #endif /* DO_SAMBA */
210 static int smbk5pwd_op_cleanup(
216 /* clear out the current key */
217 ldap_pvt_thread_pool_setkey( op->o_threadctx, smbk5pwd_op_cleanup,
218 NULL, 0, NULL, NULL );
220 /* free the callback */
222 op->o_callback = cb->sc_next;
223 op->o_tmpfree( cb, op->o_tmpmemctx );
227 static int smbk5pwd_op_bind(
231 /* If this is a simple Bind, stash the Op pointer so our chk
232 * function can find it. Set a cleanup callback to clear it
233 * out when the Bind completes.
235 if ( op->oq_bind.rb_method == LDAP_AUTH_SIMPLE ) {
237 ldap_pvt_thread_pool_setkey( op->o_threadctx,
238 smbk5pwd_op_cleanup, op, 0, NULL, NULL );
239 cb = op->o_tmpcalloc( 1, sizeof(slap_callback), op->o_tmpmemctx );
240 cb->sc_cleanup = smbk5pwd_op_cleanup;
241 cb->sc_next = op->o_callback;
244 return SLAP_CB_CONTINUE;
247 static LUTIL_PASSWD_CHK_FUNC k5key_chk;
248 static LUTIL_PASSWD_HASH_FUNC k5key_hash;
249 static const struct berval k5key_scheme = BER_BVC("{K5KEY}");
251 /* This password scheme stores no data in the userPassword attribute
252 * other than the scheme name. It assumes the invoking entry is a
253 * krb5KDCentry and compares the passed-in credentials against the
254 * krb5Key attribute. The krb5Key may be multi-valued, but they are
255 * simply multiple keytypes generated from the same input string, so
256 * only the first value needs to be compared here.
258 * Since the lutil_passwd API doesn't pass the Entry object in, we
259 * have to fetch it ourselves in order to get access to the other
260 * attributes. We accomplish this with the help of the overlay's Bind
261 * function, which stores the current Operation pointer in thread-specific
262 * storage so we can retrieve it here. The Operation provides all
263 * the necessary context for us to get Entry from the database.
265 static int k5key_chk(
266 const struct berval *sc,
267 const struct berval *passwd,
268 const struct berval *cred,
281 /* Find our thread context, find our Operation */
282 ctx = ldap_pvt_thread_pool_context();
284 if ( ldap_pvt_thread_pool_getkey( ctx, smbk5pwd_op_cleanup, &op_tmp, NULL )
286 return LUTIL_PASSWD_ERR;
289 rc = be_entry_get_rw( op, &op->o_req_ndn, NULL, NULL, 0, &e );
290 if ( rc != LDAP_SUCCESS ) return LUTIL_PASSWD_ERR;
292 rc = LUTIL_PASSWD_ERR;
297 a = attr_find( e->e_attrs, ad_krb5PrincipalName );
300 memset( &ent, 0, sizeof(ent) );
301 ret = krb5_parse_name(context, a->a_vals[0].bv_val, &ent.principal);
303 krb5_get_pw_salt( context, ent.principal, &salt );
304 krb5_free_principal( context, ent.principal );
306 a = attr_find( e->e_attrs, ad_krb5Key );
310 ent.keys.val = &ekey;
311 decode_Key((unsigned char *) a->a_vals[0].bv_val,
312 (size_t) a->a_vals[0].bv_len, &ent.keys.val[0], &l);
313 if ( db->HDB_MASTER_KEY_SET )
314 hdb_unseal_keys( context, db, &ent );
316 krb5_string_to_key_salt( context, ekey.key.keytype, cred->bv_val,
319 krb5_free_salt( context, salt );
321 if ( memcmp( ekey.key.keyvalue.data, key.keyvalue.data,
322 key.keyvalue.length ) == 0 ) rc = LUTIL_PASSWD_OK;
324 krb5_free_keyblock_contents( context, &key );
325 krb5_free_keyblock_contents( context, &ekey.key );
328 be_entry_release_r( op, e );
332 static int k5key_hash(
333 const struct berval *scheme,
334 const struct berval *passwd,
338 ber_dupbv( hash, (struct berval *)&k5key_scheme );
339 return LUTIL_PASSWD_OK;
343 static int smbk5pwd_exop_passwd(
348 req_pwdexop_s *qpw = &op->oq_pwdexop;
351 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
352 smbk5pwd_t *pi = on->on_bi.bi_private;
354 /* Not the operation we expected, pass it on... */
355 if ( ber_bvcmp( &slap_EXOP_MODIFY_PASSWD, &op->ore_reqoid ) ) {
356 return SLAP_CB_CONTINUE;
359 op->o_bd->bd_info = (BackendInfo *)on->on_info;
360 rc = be_entry_get_rw( op, &op->o_req_ndn, NULL, NULL, 0, &e );
361 if ( rc != LDAP_SUCCESS ) return rc;
372 if ( !SMBK5PWD_DO_KRB5( pi ) ) break;
374 if ( !is_entry_objectclass(e, oc_krb5KDCEntry, 0 ) ) break;
376 a = attr_find( e->e_attrs, ad_krb5PrincipalName );
379 memset( &ent, 0, sizeof(ent) );
380 ret = krb5_parse_name(context, a->a_vals[0].bv_val, &ent.principal);
383 a = attr_find( e->e_attrs, ad_krb5KeyVersionNumber );
386 if ( lutil_atoi( &kvno, a->a_vals[0].bv_val ) != 0 ) {
387 Debug( LDAP_DEBUG_ANY, "%s smbk5pwd EXOP: "
388 "dn=\"%s\" unable to parse krb5KeyVersionNumber=\"%s\"\n",
389 op->o_log_prefix, e->e_name.bv_val, a->a_vals[0].bv_val );
393 /* shouldn't happen, this is a required attr */
394 Debug( LDAP_DEBUG_ANY, "%s smbk5pwd EXOP: "
395 "dn=\"%s\" missing krb5KeyVersionNumber\n",
396 op->o_log_prefix, e->e_name.bv_val, 0 );
399 ret = _kadm5_set_keys(kadm_context, &ent, qpw->rs_new.bv_val);
400 hdb_seal_keys(context, db, &ent);
401 krb5_free_principal( context, ent.principal );
403 keys = ch_malloc( (ent.keys.len + 1) * sizeof(struct berval));
405 for (i = 0; i < ent.keys.len; i++) {
409 ASN1_MALLOC_ENCODE(Key, buf, len, &ent.keys.val[i], &len, ret);
413 keys[i].bv_val = (char *)buf;
414 keys[i].bv_len = len;
416 BER_BVZERO( &keys[i] );
418 _kadm5_free_keys(kadm_context, ent.keys.len, ent.keys.val);
420 if ( i != ent.keys.len ) {
421 ber_bvarray_free( keys );
425 ml = ch_malloc(sizeof(Modifications));
426 if (!qpw->rs_modtail) qpw->rs_modtail = &ml->sml_next;
427 ml->sml_next = qpw->rs_mods;
430 ml->sml_desc = ad_krb5Key;
431 ml->sml_op = LDAP_MOD_REPLACE;
432 #ifdef SLAP_MOD_INTERNAL
433 ml->sml_flags = SLAP_MOD_INTERNAL;
436 ml->sml_values = keys;
437 ml->sml_nvalues = NULL;
439 ml = ch_malloc(sizeof(Modifications));
440 ml->sml_next = qpw->rs_mods;
443 ml->sml_desc = ad_krb5KeyVersionNumber;
444 ml->sml_op = LDAP_MOD_REPLACE;
445 #ifdef SLAP_MOD_INTERNAL
446 ml->sml_flags = SLAP_MOD_INTERNAL;
449 ml->sml_values = ch_malloc( 2 * sizeof(struct berval));
450 ml->sml_values[0].bv_val = ch_malloc( 64 );
451 ml->sml_values[0].bv_len = sprintf(ml->sml_values[0].bv_val,
453 BER_BVZERO( &ml->sml_values[1] );
454 ml->sml_nvalues = NULL;
460 if ( SMBK5PWD_DO_SAMBA( pi ) && is_entry_objectclass(e, oc_sambaSamAccount, 0 ) ) {
467 /* Expand incoming UTF8 string to UCS4 */
468 l = ldap_utf8_chars(qpw->rs_new.bv_val);
469 wcs = ch_malloc((l+1) * sizeof(wchar_t));
471 ldap_x_utf8s_to_wcs( wcs, qpw->rs_new.bv_val, l );
473 /* Truncate UCS4 to UCS2 */
475 for (j=0; j<l; j++) {
478 *c++ = (wc >> 8) & 0xff;
481 pwd.bv_val = (char *)wcs;
484 ml = ch_malloc(sizeof(Modifications));
485 if (!qpw->rs_modtail) qpw->rs_modtail = &ml->sml_next;
486 ml->sml_next = qpw->rs_mods;
489 keys = ch_malloc( 2 * sizeof(struct berval) );
490 BER_BVZERO( &keys[1] );
491 nthash( &pwd, keys );
493 ml->sml_desc = ad_sambaNTPassword;
494 ml->sml_op = LDAP_MOD_REPLACE;
495 #ifdef SLAP_MOD_INTERNAL
496 ml->sml_flags = SLAP_MOD_INTERNAL;
499 ml->sml_values = keys;
500 ml->sml_nvalues = NULL;
502 /* Truncate UCS2 to 8-bit ASCII */
505 for (j=1; j<l; j++) {
510 pwd.bv_val[pwd.bv_len] = '\0';
512 ml = ch_malloc(sizeof(Modifications));
513 ml->sml_next = qpw->rs_mods;
516 keys = ch_malloc( 2 * sizeof(struct berval) );
517 BER_BVZERO( &keys[1] );
518 lmhash( &pwd, keys );
520 ml->sml_desc = ad_sambaLMPassword;
521 ml->sml_op = LDAP_MOD_REPLACE;
522 #ifdef SLAP_MOD_INTERNAL
523 ml->sml_flags = SLAP_MOD_INTERNAL;
526 ml->sml_values = keys;
527 ml->sml_nvalues = NULL;
531 ml = ch_malloc(sizeof(Modifications));
532 ml->sml_next = qpw->rs_mods;
535 keys = ch_malloc( 2 * sizeof(struct berval) );
536 keys[0].bv_val = ch_malloc( LDAP_PVT_INTTYPE_CHARS(long) );
537 keys[0].bv_len = snprintf(keys[0].bv_val,
538 LDAP_PVT_INTTYPE_CHARS(long),
539 "%ld", slap_get_time());
540 BER_BVZERO( &keys[1] );
542 ml->sml_desc = ad_sambaPwdLastSet;
543 ml->sml_op = LDAP_MOD_REPLACE;
544 #ifdef SLAP_MOD_INTERNAL
545 ml->sml_flags = SLAP_MOD_INTERNAL;
548 ml->sml_values = keys;
549 ml->sml_nvalues = NULL;
551 if (pi->smb_must_change)
553 ml = ch_malloc(sizeof(Modifications));
554 ml->sml_next = qpw->rs_mods;
557 keys = ch_malloc( 2 * sizeof(struct berval) );
558 keys[0].bv_val = ch_malloc( LDAP_PVT_INTTYPE_CHARS(long) );
559 keys[0].bv_len = snprintf(keys[0].bv_val,
560 LDAP_PVT_INTTYPE_CHARS(long),
561 "%ld", slap_get_time() + pi->smb_must_change);
562 BER_BVZERO( &keys[1] );
564 ml->sml_desc = ad_sambaPwdMustChange;
565 ml->sml_op = LDAP_MOD_REPLACE;
566 #ifdef SLAP_MOD_INTERNAL
567 ml->sml_flags = SLAP_MOD_INTERNAL;
570 ml->sml_values = keys;
571 ml->sml_nvalues = NULL;
574 if (pi->smb_can_change)
576 ml = ch_malloc(sizeof(Modifications));
577 ml->sml_next = qpw->rs_mods;
580 keys = ch_malloc( 2 * sizeof(struct berval) );
581 keys[0].bv_val = ch_malloc( LDAP_PVT_INTTYPE_CHARS(long) );
582 keys[0].bv_len = snprintf(keys[0].bv_val,
583 LDAP_PVT_INTTYPE_CHARS(long),
584 "%ld", slap_get_time() + pi->smb_can_change);
585 BER_BVZERO( &keys[1] );
587 ml->sml_desc = ad_sambaPwdCanChange;
588 ml->sml_op = LDAP_MOD_REPLACE;
589 #ifdef SLAP_MOD_INTERNAL
590 ml->sml_flags = SLAP_MOD_INTERNAL;
593 ml->sml_values = keys;
594 ml->sml_nvalues = NULL;
597 #endif /* DO_SAMBA */
598 be_entry_release_r( op, e );
600 return SLAP_CB_CONTINUE;
603 static slap_overinst smbk5pwd;
605 /* back-config stuff */
607 PC_SMB_MUST_CHANGE = 1,
612 static ConfigDriver smbk5pwd_cf_func;
615 * NOTE: uses OID arcs OLcfgCtAt:1 and OLcfgCtOc:1
618 static ConfigTable smbk5pwd_cfats[] = {
619 { "smbk5pwd-enable", "arg",
620 2, 0, 0, ARG_MAGIC|PC_SMB_ENABLE, smbk5pwd_cf_func,
621 "( OLcfgCtAt:1.1 NAME 'olcSmbK5PwdEnable' "
622 "DESC 'Modules to be enabled' "
623 "SYNTAX OMsDirectoryString )", NULL, NULL },
624 { "smbk5pwd-must-change", "time",
625 2, 2, 0, ARG_MAGIC|ARG_INT|PC_SMB_MUST_CHANGE, smbk5pwd_cf_func,
626 "( OLcfgCtAt:1.2 NAME 'olcSmbK5PwdMustChange' "
627 "DESC 'Credentials validity interval' "
628 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
629 { "smbk5pwd-can-change", "time",
630 2, 2, 0, ARG_MAGIC|ARG_INT|PC_SMB_CAN_CHANGE, smbk5pwd_cf_func,
631 "( OLcfgCtAt:1.3 NAME 'olcSmbK5PwdCanChange' "
632 "DESC 'Credentials minimum validity interval' "
633 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
635 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
638 static ConfigOCs smbk5pwd_cfocs[] = {
640 "NAME 'olcSmbK5PwdConfig' "
641 "DESC 'smbk5pwd overlay configuration' "
642 "SUP olcOverlayConfig "
645 "$ olcSmbK5PwdMustChange "
646 "$ olcSmbK5PwdCanChange "
647 ") )", Cft_Overlay, smbk5pwd_cfats },
653 * add here other functionalities; handle their initialization
654 * as appropriate in smbk5pwd_modules_init().
656 static slap_verbmasks smbk5pwd_modules[] = {
657 { BER_BVC( "krb5" ), SMBK5PWD_F_KRB5 },
658 { BER_BVC( "samba" ), SMBK5PWD_F_SAMBA },
663 smbk5pwd_cf_func( ConfigArgs *c )
665 slap_overinst *on = (slap_overinst *)c->bi;
668 smbk5pwd_t *pi = on->on_bi.bi_private;
670 if ( c->op == SLAP_CONFIG_EMIT ) {
672 case PC_SMB_MUST_CHANGE:
674 c->value_int = pi->smb_must_change;
675 #else /* ! DO_SAMBA */
677 #endif /* ! DO_SAMBA */
680 case PC_SMB_CAN_CHANGE:
682 c->value_int = pi->smb_can_change;
683 #else /* ! DO_SAMBA */
685 #endif /* ! DO_SAMBA */
689 c->rvalue_vals = NULL;
691 mask_to_verbs( smbk5pwd_modules, pi->mode, &c->rvalue_vals );
692 if ( c->rvalue_vals == NULL ) {
704 } else if ( c->op == LDAP_MOD_DELETE ) {
706 case PC_SMB_MUST_CHANGE:
709 case PC_SMB_CAN_CHANGE:
719 m = verb_to_mask( c->line, smbk5pwd_modules );
732 case PC_SMB_MUST_CHANGE:
734 if ( c->value_int < 0 ) {
735 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
736 "<%s> invalid negative value \"%d\".",
737 c->log, c->argv[ 0 ], 0 );
740 pi->smb_must_change = c->value_int;
741 #else /* ! DO_SAMBA */
742 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
743 "<%s> only meaningful "
744 "when compiled with -DDO_SAMBA.\n",
745 c->log, c->argv[ 0 ], 0 );
747 #endif /* ! DO_SAMBA */
750 case PC_SMB_CAN_CHANGE:
752 if ( c->value_int < 0 ) {
753 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
754 "<%s> invalid negative value \"%d\".",
755 c->log, c->argv[ 0 ], 0 );
758 pi->smb_can_change = c->value_int;
759 #else /* ! DO_SAMBA */
760 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
761 "<%s> only meaningful "
762 "when compiled with -DDO_SAMBA.\n",
763 c->log, c->argv[ 0 ], 0 );
765 #endif /* ! DO_SAMBA */
768 case PC_SMB_ENABLE: {
769 slap_mask_t mode = pi->mode, m;
771 rc = verbs_to_mask( c->argc, c->argv, smbk5pwd_modules, &m );
773 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
774 "<%s> unknown module \"%s\".\n",
775 c->log, c->argv[ 0 ], c->argv[ rc ] );
779 /* we can hijack the smbk5pwd_t structure because
780 * from within the configuration, this is the only
785 if ( SMBK5PWD_DO_KRB5( pi ) ) {
786 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
787 "<%s> module \"%s\" only allowed when compiled with -DDO_KRB5.\n",
788 c->log, c->argv[ 0 ], c->argv[ rc ] );
792 #endif /* ! DO_KRB5 */
795 if ( SMBK5PWD_DO_SAMBA( pi ) ) {
796 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
797 "<%s> module \"%s\" only allowed when compiled with -DDO_SAMBA.\n",
798 c->log, c->argv[ 0 ], c->argv[ rc ] );
802 #endif /* ! DO_SAMBA */
805 BackendDB db = *c->be;
807 /* Re-initialize the module, because
808 * the configuration might have changed */
809 db.bd_info = (BackendInfo *)on;
810 rc = smbk5pwd_modules_init( pi );
827 smbk5pwd_modules_init( smbk5pwd_t *pi )
831 AttributeDescription **adp;
835 { "krb5Key", &ad_krb5Key },
836 { "krb5KeyVersionNumber", &ad_krb5KeyVersionNumber },
837 { "krb5PrincipalName", &ad_krb5PrincipalName },
843 { "sambaLMPassword", &ad_sambaLMPassword },
844 { "sambaNTPassword", &ad_sambaNTPassword },
845 { "sambaPwdLastSet", &ad_sambaPwdLastSet },
846 { "sambaPwdMustChange", &ad_sambaPwdMustChange },
847 { "sambaPwdCanChange", &ad_sambaPwdCanChange },
850 #endif /* DO_SAMBA */
853 /* this is to silence the unused var warning */
854 dummy_ad.name = NULL;
857 if ( SMBK5PWD_DO_KRB5( pi ) && oc_krb5KDCEntry == NULL ) {
859 extern HDB *_kadm5_s_get_db(void *);
863 /* Make sure all of our necessary schema items are loaded */
864 oc_krb5KDCEntry = oc_find( "krb5KDCEntry" );
865 if ( !oc_krb5KDCEntry ) {
866 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
867 "unable to find \"krb5KDCEntry\" objectClass.\n",
872 for ( i = 0; krb5_ad[ i ].name != NULL; i++ ) {
875 *(krb5_ad[ i ].adp) = NULL;
877 rc = slap_str2ad( krb5_ad[ i ].name, krb5_ad[ i ].adp, &text );
878 if ( rc != LDAP_SUCCESS ) {
879 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
880 "unable to find \"%s\" attributeType: %s (%d).\n",
881 krb5_ad[ i ].name, text, rc );
882 oc_krb5KDCEntry = NULL;
887 /* Initialize Kerberos context */
888 ret = krb5_init_context(&context);
890 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
891 "unable to initialize krb5 context (%d).\n",
893 oc_krb5KDCEntry = NULL;
897 ret = kadm5_s_init_with_password_ctx( context,
901 &conf, 0, 0, &kadm_context );
903 char *err_str, *err_msg = "<unknown error>";
904 err_str = krb5_get_error_string( context );
906 err_msg = krb5_get_err_text( context, ret );
907 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
908 "unable to initialize krb5 admin context: %s (%d).\n",
909 err_str ? err_str : err_msg, ret, 0 );
911 krb5_free_error_string( context, err_str );
912 krb5_free_context( context );
913 oc_krb5KDCEntry = NULL;
917 db = _kadm5_s_get_db( kadm_context );
922 if ( SMBK5PWD_DO_SAMBA( pi ) && oc_sambaSamAccount == NULL ) {
925 oc_sambaSamAccount = oc_find( "sambaSamAccount" );
926 if ( !oc_sambaSamAccount ) {
927 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
928 "unable to find \"sambaSamAccount\" objectClass.\n",
933 for ( i = 0; samba_ad[ i ].name != NULL; i++ ) {
936 *(samba_ad[ i ].adp) = NULL;
938 rc = slap_str2ad( samba_ad[ i ].name, samba_ad[ i ].adp, &text );
939 if ( rc != LDAP_SUCCESS ) {
940 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
941 "unable to find \"%s\" attributeType: %s (%d).\n",
942 samba_ad[ i ].name, text, rc );
943 oc_sambaSamAccount = NULL;
948 #endif /* DO_SAMBA */
954 smbk5pwd_db_init(BackendDB *be, ConfigReply *cr)
956 slap_overinst *on = (slap_overinst *)be->bd_info;
959 pi = ch_calloc( 1, sizeof( smbk5pwd_t ) );
963 on->on_bi.bi_private = (void *)pi;
969 smbk5pwd_db_open(BackendDB *be, ConfigReply *cr)
971 slap_overinst *on = (slap_overinst *)be->bd_info;
972 smbk5pwd_t *pi = (smbk5pwd_t *)on->on_bi.bi_private;
976 if ( pi->mode == 0 ) {
977 pi->mode = SMBK5PWD_F_ALL;
980 rc = smbk5pwd_modules_init( pi );
989 smbk5pwd_db_destroy(BackendDB *be, ConfigReply *cr)
991 slap_overinst *on = (slap_overinst *)be->bd_info;
992 smbk5pwd_t *pi = (smbk5pwd_t *)on->on_bi.bi_private;
1002 smbk5pwd_initialize(void)
1006 smbk5pwd.on_bi.bi_type = "smbk5pwd";
1008 smbk5pwd.on_bi.bi_db_init = smbk5pwd_db_init;
1009 smbk5pwd.on_bi.bi_db_open = smbk5pwd_db_open;
1010 smbk5pwd.on_bi.bi_db_destroy = smbk5pwd_db_destroy;
1012 smbk5pwd.on_bi.bi_extended = smbk5pwd_exop_passwd;
1015 smbk5pwd.on_bi.bi_op_bind = smbk5pwd_op_bind;
1017 lutil_passwd_add( (struct berval *)&k5key_scheme, k5key_chk, k5key_hash );
1020 smbk5pwd.on_bi.bi_cf_ocs = smbk5pwd_cfocs;
1022 rc = config_register_schema( smbk5pwd_cfats, smbk5pwd_cfocs );
1027 return overlay_register( &smbk5pwd );
1030 #if SLAPD_OVER_SMBK5PWD == SLAPD_MOD_DYNAMIC
1031 int init_module(int argc, char *argv[]) {
1032 return smbk5pwd_initialize();
1036 #endif /* defined(SLAPD_OVER_SMBK5PWD) */