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 AttributeDescription *ad_krb5ValidEnd;
63 static ObjectClass *oc_krb5KDCEntry;
67 #include <openssl/des.h>
68 #include <openssl/md4.h>
69 #include "ldap_utf8.h"
71 static AttributeDescription *ad_sambaLMPassword;
72 static AttributeDescription *ad_sambaNTPassword;
73 static AttributeDescription *ad_sambaPwdLastSet;
74 static AttributeDescription *ad_sambaPwdMustChange;
75 static AttributeDescription *ad_sambaPwdCanChange;
76 static ObjectClass *oc_sambaSamAccount;
79 /* Per-instance configuration information */
80 typedef struct smbk5pwd_t {
82 #define SMBK5PWD_F_KRB5 (0x1U)
83 #define SMBK5PWD_F_SAMBA (0x2U)
85 #define SMBK5PWD_DO_KRB5(pi) ((pi)->mode & SMBK5PWD_F_KRB5)
86 #define SMBK5PWD_DO_SAMBA(pi) ((pi)->mode & SMBK5PWD_F_SAMBA)
93 /* How many seconds before forcing a password change? */
94 time_t smb_must_change;
95 /* How many seconds after allowing a password change? */
96 time_t smb_can_change;
100 static const unsigned SMBK5PWD_F_ALL =
110 static int smbk5pwd_modules_init( smbk5pwd_t *pi );
113 static const char hex[] = "0123456789abcdef";
115 /* From liblutil/passwd.c... */
116 static void lmPasswd_to_key(
117 const char *lmPasswd,
120 const unsigned char *lpw = (const unsigned char *)lmPasswd;
121 unsigned char *k = (unsigned char *)key;
123 /* make room for parity bits */
125 k[1] = ((lpw[0]&0x01)<<7) | (lpw[1]>>1);
126 k[2] = ((lpw[1]&0x03)<<6) | (lpw[2]>>2);
127 k[3] = ((lpw[2]&0x07)<<5) | (lpw[3]>>3);
128 k[4] = ((lpw[3]&0x0F)<<4) | (lpw[4]>>4);
129 k[5] = ((lpw[4]&0x1F)<<3) | (lpw[5]>>5);
130 k[6] = ((lpw[5]&0x3F)<<2) | (lpw[6]>>6);
131 k[7] = ((lpw[6]&0x7F)<<1);
133 des_set_odd_parity( key );
136 #define MAX_PWLEN 256
140 const char in[HASHLEN],
148 out->bv_val = ch_malloc(HASHLEN*2 + 1);
149 out->bv_len = HASHLEN*2;
152 b = (unsigned char *)in;
153 for (i=0; i<HASHLEN; i++) {
155 *a++ = hex[*b++ & 0x0f];
161 struct berval *passwd,
165 char UcasePassword[15];
167 DES_key_schedule schedule;
168 DES_cblock StdText = "KGS!@#$%";
171 strncpy( UcasePassword, passwd->bv_val, 14 );
172 UcasePassword[14] = '\0';
173 ldap_pvt_str2upper( UcasePassword );
175 lmPasswd_to_key( UcasePassword, &key );
176 des_set_key_unchecked( &key, schedule );
177 des_ecb_encrypt( &StdText, &hbuf[0], schedule , DES_ENCRYPT );
179 lmPasswd_to_key( &UcasePassword[7], &key );
180 des_set_key_unchecked( &key, schedule );
181 des_ecb_encrypt( &StdText, &hbuf[1], schedule , DES_ENCRYPT );
183 hexify( (char *)hbuf, hash );
187 struct berval *passwd,
191 /* Windows currently only allows 14 character passwords, but
192 * may support up to 256 in the future. We assume this means
193 * 256 UCS2 characters, not 256 bytes...
198 if (passwd->bv_len > MAX_PWLEN*2)
199 passwd->bv_len = MAX_PWLEN*2;
202 MD4_Update( &ctx, passwd->bv_val, passwd->bv_len );
203 MD4_Final( (unsigned char *)hbuf, &ctx );
205 hexify( hbuf, hash );
207 #endif /* DO_SAMBA */
211 static int smbk5pwd_op_cleanup(
217 /* clear out the current key */
218 ldap_pvt_thread_pool_setkey( op->o_threadctx, smbk5pwd_op_cleanup,
219 NULL, 0, NULL, NULL );
221 /* free the callback */
223 op->o_callback = cb->sc_next;
224 op->o_tmpfree( cb, op->o_tmpmemctx );
228 static int smbk5pwd_op_bind(
232 /* If this is a simple Bind, stash the Op pointer so our chk
233 * function can find it. Set a cleanup callback to clear it
234 * out when the Bind completes.
236 if ( op->oq_bind.rb_method == LDAP_AUTH_SIMPLE ) {
238 ldap_pvt_thread_pool_setkey( op->o_threadctx,
239 smbk5pwd_op_cleanup, op, 0, NULL, NULL );
240 cb = op->o_tmpcalloc( 1, sizeof(slap_callback), op->o_tmpmemctx );
241 cb->sc_cleanup = smbk5pwd_op_cleanup;
242 cb->sc_next = op->o_callback;
245 return SLAP_CB_CONTINUE;
248 static LUTIL_PASSWD_CHK_FUNC k5key_chk;
249 static LUTIL_PASSWD_HASH_FUNC k5key_hash;
250 static const struct berval k5key_scheme = BER_BVC("{K5KEY}");
252 /* This password scheme stores no data in the userPassword attribute
253 * other than the scheme name. It assumes the invoking entry is a
254 * krb5KDCentry and compares the passed-in credentials against the
255 * krb5Key attribute. The krb5Key may be multi-valued, but they are
256 * simply multiple keytypes generated from the same input string, so
257 * only the first value needs to be compared here.
259 * Since the lutil_passwd API doesn't pass the Entry object in, we
260 * have to fetch it ourselves in order to get access to the other
261 * attributes. We accomplish this with the help of the overlay's Bind
262 * function, which stores the current Operation pointer in thread-specific
263 * storage so we can retrieve it here. The Operation provides all
264 * the necessary context for us to get Entry from the database.
266 static int k5key_chk(
267 const struct berval *sc,
268 const struct berval *passwd,
269 const struct berval *cred,
282 /* Find our thread context, find our Operation */
283 ctx = ldap_pvt_thread_pool_context();
285 if ( ldap_pvt_thread_pool_getkey( ctx, smbk5pwd_op_cleanup, &op_tmp, NULL )
287 return LUTIL_PASSWD_ERR;
290 rc = be_entry_get_rw( op, &op->o_req_ndn, NULL, NULL, 0, &e );
291 if ( rc != LDAP_SUCCESS ) return LUTIL_PASSWD_ERR;
293 rc = LUTIL_PASSWD_ERR;
298 a = attr_find( e->e_attrs, ad_krb5PrincipalName );
301 memset( &ent, 0, sizeof(ent) );
302 ret = krb5_parse_name(context, a->a_vals[0].bv_val, &ent.principal);
305 a = attr_find( e->e_attrs, ad_krb5ValidEnd );
308 struct lutil_timet tt;
309 if ( lutil_parsetime( a->a_vals[0].bv_val, &tm ) == 0 &&
310 lutil_tm2time( &tm, &tt ) == 0 && tt.tt_usec < op->o_time ) {
311 /* Account is expired */
312 rc = LUTIL_PASSWD_ERR;
317 krb5_get_pw_salt( context, ent.principal, &salt );
318 krb5_free_principal( context, ent.principal );
320 a = attr_find( e->e_attrs, ad_krb5Key );
324 ent.keys.val = &ekey;
325 decode_Key((unsigned char *) a->a_vals[0].bv_val,
326 (size_t) a->a_vals[0].bv_len, &ent.keys.val[0], &l);
327 if ( db->HDB_MASTER_KEY_SET )
328 hdb_unseal_keys( context, db, &ent );
330 krb5_string_to_key_salt( context, ekey.key.keytype, cred->bv_val,
333 krb5_free_salt( context, salt );
335 if ( memcmp( ekey.key.keyvalue.data, key.keyvalue.data,
336 key.keyvalue.length ) == 0 ) rc = LUTIL_PASSWD_OK;
338 krb5_free_keyblock_contents( context, &key );
339 krb5_free_keyblock_contents( context, &ekey.key );
342 be_entry_release_r( op, e );
346 static int k5key_hash(
347 const struct berval *scheme,
348 const struct berval *passwd,
352 ber_dupbv( hash, (struct berval *)&k5key_scheme );
353 return LUTIL_PASSWD_OK;
357 static int smbk5pwd_exop_passwd(
362 req_pwdexop_s *qpw = &op->oq_pwdexop;
365 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
366 smbk5pwd_t *pi = on->on_bi.bi_private;
369 /* Not the operation we expected, pass it on... */
370 if ( ber_bvcmp( &slap_EXOP_MODIFY_PASSWD, &op->ore_reqoid ) ) {
371 return SLAP_CB_CONTINUE;
374 op->o_bd->bd_info = (BackendInfo *)on->on_info;
375 rc = be_entry_get_rw( op, &op->o_req_ndn, NULL, NULL, 0, &e );
376 if ( rc != LDAP_SUCCESS ) return rc;
378 term = qpw->rs_new.bv_val[qpw->rs_new.bv_len];
379 qpw->rs_new.bv_val[qpw->rs_new.bv_len] = '\0';
390 if ( !SMBK5PWD_DO_KRB5( pi ) ) break;
392 if ( !is_entry_objectclass(e, oc_krb5KDCEntry, 0 ) ) break;
394 a = attr_find( e->e_attrs, ad_krb5PrincipalName );
397 memset( &ent, 0, sizeof(ent) );
398 ret = krb5_parse_name(context, a->a_vals[0].bv_val, &ent.principal);
401 a = attr_find( e->e_attrs, ad_krb5KeyVersionNumber );
404 if ( lutil_atoi( &kvno, a->a_vals[0].bv_val ) != 0 ) {
405 Debug( LDAP_DEBUG_ANY, "%s smbk5pwd EXOP: "
406 "dn=\"%s\" unable to parse krb5KeyVersionNumber=\"%s\"\n",
407 op->o_log_prefix, e->e_name.bv_val, a->a_vals[0].bv_val );
411 /* shouldn't happen, this is a required attr */
412 Debug( LDAP_DEBUG_ANY, "%s smbk5pwd EXOP: "
413 "dn=\"%s\" missing krb5KeyVersionNumber\n",
414 op->o_log_prefix, e->e_name.bv_val, 0 );
417 ret = _kadm5_set_keys(kadm_context, &ent, qpw->rs_new.bv_val);
418 hdb_seal_keys(context, db, &ent);
419 krb5_free_principal( context, ent.principal );
421 keys = ch_malloc( (ent.keys.len + 1) * sizeof(struct berval));
423 for (i = 0; i < ent.keys.len; i++) {
427 ASN1_MALLOC_ENCODE(Key, buf, len, &ent.keys.val[i], &len, ret);
431 keys[i].bv_val = (char *)buf;
432 keys[i].bv_len = len;
434 BER_BVZERO( &keys[i] );
436 _kadm5_free_keys(kadm_context, ent.keys.len, ent.keys.val);
438 if ( i != ent.keys.len ) {
439 ber_bvarray_free( keys );
443 ml = ch_malloc(sizeof(Modifications));
444 if (!qpw->rs_modtail) qpw->rs_modtail = &ml->sml_next;
445 ml->sml_next = qpw->rs_mods;
448 ml->sml_desc = ad_krb5Key;
449 ml->sml_op = LDAP_MOD_REPLACE;
450 #ifdef SLAP_MOD_INTERNAL
451 ml->sml_flags = SLAP_MOD_INTERNAL;
454 ml->sml_values = keys;
455 ml->sml_nvalues = NULL;
457 ml = ch_malloc(sizeof(Modifications));
458 ml->sml_next = qpw->rs_mods;
461 ml->sml_desc = ad_krb5KeyVersionNumber;
462 ml->sml_op = LDAP_MOD_REPLACE;
463 #ifdef SLAP_MOD_INTERNAL
464 ml->sml_flags = SLAP_MOD_INTERNAL;
467 ml->sml_values = ch_malloc( 2 * sizeof(struct berval));
468 ml->sml_values[0].bv_val = ch_malloc( 64 );
469 ml->sml_values[0].bv_len = sprintf(ml->sml_values[0].bv_val,
471 BER_BVZERO( &ml->sml_values[1] );
472 ml->sml_nvalues = NULL;
478 if ( SMBK5PWD_DO_SAMBA( pi ) && is_entry_objectclass(e, oc_sambaSamAccount, 0 ) ) {
485 /* Expand incoming UTF8 string to UCS4 */
486 l = ldap_utf8_chars(qpw->rs_new.bv_val);
487 wcs = ch_malloc((l+1) * sizeof(wchar_t));
489 ldap_x_utf8s_to_wcs( wcs, qpw->rs_new.bv_val, l );
491 /* Truncate UCS4 to UCS2 */
493 for (j=0; j<l; j++) {
496 *c++ = (wc >> 8) & 0xff;
499 pwd.bv_val = (char *)wcs;
502 ml = ch_malloc(sizeof(Modifications));
503 if (!qpw->rs_modtail) qpw->rs_modtail = &ml->sml_next;
504 ml->sml_next = qpw->rs_mods;
507 keys = ch_malloc( 2 * sizeof(struct berval) );
508 BER_BVZERO( &keys[1] );
509 nthash( &pwd, keys );
511 ml->sml_desc = ad_sambaNTPassword;
512 ml->sml_op = LDAP_MOD_REPLACE;
513 #ifdef SLAP_MOD_INTERNAL
514 ml->sml_flags = SLAP_MOD_INTERNAL;
517 ml->sml_values = keys;
518 ml->sml_nvalues = NULL;
520 /* Truncate UCS2 to 8-bit ASCII */
523 for (j=1; j<l; j++) {
528 pwd.bv_val[pwd.bv_len] = '\0';
530 ml = ch_malloc(sizeof(Modifications));
531 ml->sml_next = qpw->rs_mods;
534 keys = ch_malloc( 2 * sizeof(struct berval) );
535 BER_BVZERO( &keys[1] );
536 lmhash( &pwd, keys );
538 ml->sml_desc = ad_sambaLMPassword;
539 ml->sml_op = LDAP_MOD_REPLACE;
540 #ifdef SLAP_MOD_INTERNAL
541 ml->sml_flags = SLAP_MOD_INTERNAL;
544 ml->sml_values = keys;
545 ml->sml_nvalues = NULL;
549 ml = ch_malloc(sizeof(Modifications));
550 ml->sml_next = qpw->rs_mods;
553 keys = ch_malloc( 2 * sizeof(struct berval) );
554 keys[0].bv_val = ch_malloc( LDAP_PVT_INTTYPE_CHARS(long) );
555 keys[0].bv_len = snprintf(keys[0].bv_val,
556 LDAP_PVT_INTTYPE_CHARS(long),
557 "%ld", slap_get_time());
558 BER_BVZERO( &keys[1] );
560 ml->sml_desc = ad_sambaPwdLastSet;
561 ml->sml_op = LDAP_MOD_REPLACE;
562 #ifdef SLAP_MOD_INTERNAL
563 ml->sml_flags = SLAP_MOD_INTERNAL;
566 ml->sml_values = keys;
567 ml->sml_nvalues = NULL;
569 if (pi->smb_must_change)
571 ml = ch_malloc(sizeof(Modifications));
572 ml->sml_next = qpw->rs_mods;
575 keys = ch_malloc( 2 * sizeof(struct berval) );
576 keys[0].bv_val = ch_malloc( LDAP_PVT_INTTYPE_CHARS(long) );
577 keys[0].bv_len = snprintf(keys[0].bv_val,
578 LDAP_PVT_INTTYPE_CHARS(long),
579 "%ld", slap_get_time() + pi->smb_must_change);
580 BER_BVZERO( &keys[1] );
582 ml->sml_desc = ad_sambaPwdMustChange;
583 ml->sml_op = LDAP_MOD_REPLACE;
584 #ifdef SLAP_MOD_INTERNAL
585 ml->sml_flags = SLAP_MOD_INTERNAL;
588 ml->sml_values = keys;
589 ml->sml_nvalues = NULL;
592 if (pi->smb_can_change)
594 ml = ch_malloc(sizeof(Modifications));
595 ml->sml_next = qpw->rs_mods;
598 keys = ch_malloc( 2 * sizeof(struct berval) );
599 keys[0].bv_val = ch_malloc( LDAP_PVT_INTTYPE_CHARS(long) );
600 keys[0].bv_len = snprintf(keys[0].bv_val,
601 LDAP_PVT_INTTYPE_CHARS(long),
602 "%ld", slap_get_time() + pi->smb_can_change);
603 BER_BVZERO( &keys[1] );
605 ml->sml_desc = ad_sambaPwdCanChange;
606 ml->sml_op = LDAP_MOD_REPLACE;
607 #ifdef SLAP_MOD_INTERNAL
608 ml->sml_flags = SLAP_MOD_INTERNAL;
611 ml->sml_values = keys;
612 ml->sml_nvalues = NULL;
615 #endif /* DO_SAMBA */
616 be_entry_release_r( op, e );
617 qpw->rs_new.bv_val[qpw->rs_new.bv_len] = term;
619 return SLAP_CB_CONTINUE;
622 static slap_overinst smbk5pwd;
624 /* back-config stuff */
626 PC_SMB_MUST_CHANGE = 1,
631 static ConfigDriver smbk5pwd_cf_func;
634 * NOTE: uses OID arcs OLcfgCtAt:1 and OLcfgCtOc:1
637 static ConfigTable smbk5pwd_cfats[] = {
638 { "smbk5pwd-enable", "arg",
639 2, 0, 0, ARG_MAGIC|PC_SMB_ENABLE, smbk5pwd_cf_func,
640 "( OLcfgCtAt:1.1 NAME 'olcSmbK5PwdEnable' "
641 "DESC 'Modules to be enabled' "
642 "SYNTAX OMsDirectoryString )", NULL, NULL },
643 { "smbk5pwd-must-change", "time",
644 2, 2, 0, ARG_MAGIC|ARG_INT|PC_SMB_MUST_CHANGE, smbk5pwd_cf_func,
645 "( OLcfgCtAt:1.2 NAME 'olcSmbK5PwdMustChange' "
646 "DESC 'Credentials validity interval' "
647 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
648 { "smbk5pwd-can-change", "time",
649 2, 2, 0, ARG_MAGIC|ARG_INT|PC_SMB_CAN_CHANGE, smbk5pwd_cf_func,
650 "( OLcfgCtAt:1.3 NAME 'olcSmbK5PwdCanChange' "
651 "DESC 'Credentials minimum validity interval' "
652 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
654 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
657 static ConfigOCs smbk5pwd_cfocs[] = {
659 "NAME 'olcSmbK5PwdConfig' "
660 "DESC 'smbk5pwd overlay configuration' "
661 "SUP olcOverlayConfig "
664 "$ olcSmbK5PwdMustChange "
665 "$ olcSmbK5PwdCanChange "
666 ") )", Cft_Overlay, smbk5pwd_cfats },
672 * add here other functionalities; handle their initialization
673 * as appropriate in smbk5pwd_modules_init().
675 static slap_verbmasks smbk5pwd_modules[] = {
676 { BER_BVC( "krb5" ), SMBK5PWD_F_KRB5 },
677 { BER_BVC( "samba" ), SMBK5PWD_F_SAMBA },
682 smbk5pwd_cf_func( ConfigArgs *c )
684 slap_overinst *on = (slap_overinst *)c->bi;
687 smbk5pwd_t *pi = on->on_bi.bi_private;
689 if ( c->op == SLAP_CONFIG_EMIT ) {
691 case PC_SMB_MUST_CHANGE:
693 c->value_int = pi->smb_must_change;
694 #else /* ! DO_SAMBA */
696 #endif /* ! DO_SAMBA */
699 case PC_SMB_CAN_CHANGE:
701 c->value_int = pi->smb_can_change;
702 #else /* ! DO_SAMBA */
704 #endif /* ! DO_SAMBA */
708 c->rvalue_vals = NULL;
710 mask_to_verbs( smbk5pwd_modules, pi->mode, &c->rvalue_vals );
711 if ( c->rvalue_vals == NULL ) {
723 } else if ( c->op == LDAP_MOD_DELETE ) {
725 case PC_SMB_MUST_CHANGE:
728 case PC_SMB_CAN_CHANGE:
738 m = verb_to_mask( c->line, smbk5pwd_modules );
751 case PC_SMB_MUST_CHANGE:
753 if ( c->value_int < 0 ) {
754 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
755 "<%s> invalid negative value \"%d\".",
756 c->log, c->argv[ 0 ], 0 );
759 pi->smb_must_change = c->value_int;
760 #else /* ! DO_SAMBA */
761 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
762 "<%s> only meaningful "
763 "when compiled with -DDO_SAMBA.\n",
764 c->log, c->argv[ 0 ], 0 );
766 #endif /* ! DO_SAMBA */
769 case PC_SMB_CAN_CHANGE:
771 if ( c->value_int < 0 ) {
772 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
773 "<%s> invalid negative value \"%d\".",
774 c->log, c->argv[ 0 ], 0 );
777 pi->smb_can_change = c->value_int;
778 #else /* ! DO_SAMBA */
779 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
780 "<%s> only meaningful "
781 "when compiled with -DDO_SAMBA.\n",
782 c->log, c->argv[ 0 ], 0 );
784 #endif /* ! DO_SAMBA */
787 case PC_SMB_ENABLE: {
788 slap_mask_t mode = pi->mode, m;
790 rc = verbs_to_mask( c->argc, c->argv, smbk5pwd_modules, &m );
792 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
793 "<%s> unknown module \"%s\".\n",
794 c->log, c->argv[ 0 ], c->argv[ rc ] );
798 /* we can hijack the smbk5pwd_t structure because
799 * from within the configuration, this is the only
804 if ( SMBK5PWD_DO_KRB5( pi ) ) {
805 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
806 "<%s> module \"%s\" only allowed when compiled with -DDO_KRB5.\n",
807 c->log, c->argv[ 0 ], c->argv[ rc ] );
811 #endif /* ! DO_KRB5 */
814 if ( SMBK5PWD_DO_SAMBA( pi ) ) {
815 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
816 "<%s> module \"%s\" only allowed when compiled with -DDO_SAMBA.\n",
817 c->log, c->argv[ 0 ], c->argv[ rc ] );
821 #endif /* ! DO_SAMBA */
824 BackendDB db = *c->be;
826 /* Re-initialize the module, because
827 * the configuration might have changed */
828 db.bd_info = (BackendInfo *)on;
829 rc = smbk5pwd_modules_init( pi );
846 smbk5pwd_modules_init( smbk5pwd_t *pi )
850 AttributeDescription **adp;
854 { "krb5Key", &ad_krb5Key },
855 { "krb5KeyVersionNumber", &ad_krb5KeyVersionNumber },
856 { "krb5PrincipalName", &ad_krb5PrincipalName },
857 { "krb5ValidEnd", &ad_krb5ValidEnd },
863 { "sambaLMPassword", &ad_sambaLMPassword },
864 { "sambaNTPassword", &ad_sambaNTPassword },
865 { "sambaPwdLastSet", &ad_sambaPwdLastSet },
866 { "sambaPwdMustChange", &ad_sambaPwdMustChange },
867 { "sambaPwdCanChange", &ad_sambaPwdCanChange },
870 #endif /* DO_SAMBA */
873 /* this is to silence the unused var warning */
874 dummy_ad.name = NULL;
877 if ( SMBK5PWD_DO_KRB5( pi ) && oc_krb5KDCEntry == NULL ) {
879 extern HDB *_kadm5_s_get_db(void *);
883 /* Make sure all of our necessary schema items are loaded */
884 oc_krb5KDCEntry = oc_find( "krb5KDCEntry" );
885 if ( !oc_krb5KDCEntry ) {
886 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
887 "unable to find \"krb5KDCEntry\" objectClass.\n",
892 for ( i = 0; krb5_ad[ i ].name != NULL; i++ ) {
895 *(krb5_ad[ i ].adp) = NULL;
897 rc = slap_str2ad( krb5_ad[ i ].name, krb5_ad[ i ].adp, &text );
898 if ( rc != LDAP_SUCCESS ) {
899 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
900 "unable to find \"%s\" attributeType: %s (%d).\n",
901 krb5_ad[ i ].name, text, rc );
902 oc_krb5KDCEntry = NULL;
907 /* Initialize Kerberos context */
908 ret = krb5_init_context(&context);
910 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
911 "unable to initialize krb5 context (%d).\n",
913 oc_krb5KDCEntry = NULL;
917 ret = kadm5_s_init_with_password_ctx( context,
921 &conf, 0, 0, &kadm_context );
923 char *err_str, *err_msg = "<unknown error>";
924 err_str = krb5_get_error_string( context );
926 err_msg = (char *)krb5_get_err_text( context, ret );
927 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
928 "unable to initialize krb5 admin context: %s (%d).\n",
929 err_str ? err_str : err_msg, ret, 0 );
931 krb5_free_error_string( context, err_str );
932 krb5_free_context( context );
933 oc_krb5KDCEntry = NULL;
937 db = _kadm5_s_get_db( kadm_context );
942 if ( SMBK5PWD_DO_SAMBA( pi ) && oc_sambaSamAccount == NULL ) {
945 oc_sambaSamAccount = oc_find( "sambaSamAccount" );
946 if ( !oc_sambaSamAccount ) {
947 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
948 "unable to find \"sambaSamAccount\" objectClass.\n",
953 for ( i = 0; samba_ad[ i ].name != NULL; i++ ) {
956 *(samba_ad[ i ].adp) = NULL;
958 rc = slap_str2ad( samba_ad[ i ].name, samba_ad[ i ].adp, &text );
959 if ( rc != LDAP_SUCCESS ) {
960 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
961 "unable to find \"%s\" attributeType: %s (%d).\n",
962 samba_ad[ i ].name, text, rc );
963 oc_sambaSamAccount = NULL;
968 #endif /* DO_SAMBA */
974 smbk5pwd_db_init(BackendDB *be, ConfigReply *cr)
976 slap_overinst *on = (slap_overinst *)be->bd_info;
979 pi = ch_calloc( 1, sizeof( smbk5pwd_t ) );
983 on->on_bi.bi_private = (void *)pi;
989 smbk5pwd_db_open(BackendDB *be, ConfigReply *cr)
991 slap_overinst *on = (slap_overinst *)be->bd_info;
992 smbk5pwd_t *pi = (smbk5pwd_t *)on->on_bi.bi_private;
996 if ( pi->mode == 0 ) {
997 pi->mode = SMBK5PWD_F_ALL;
1000 rc = smbk5pwd_modules_init( pi );
1009 smbk5pwd_db_destroy(BackendDB *be, ConfigReply *cr)
1011 slap_overinst *on = (slap_overinst *)be->bd_info;
1012 smbk5pwd_t *pi = (smbk5pwd_t *)on->on_bi.bi_private;
1022 smbk5pwd_initialize(void)
1026 smbk5pwd.on_bi.bi_type = "smbk5pwd";
1028 smbk5pwd.on_bi.bi_db_init = smbk5pwd_db_init;
1029 smbk5pwd.on_bi.bi_db_open = smbk5pwd_db_open;
1030 smbk5pwd.on_bi.bi_db_destroy = smbk5pwd_db_destroy;
1032 smbk5pwd.on_bi.bi_extended = smbk5pwd_exop_passwd;
1035 smbk5pwd.on_bi.bi_op_bind = smbk5pwd_op_bind;
1037 lutil_passwd_add( (struct berval *)&k5key_scheme, k5key_chk, k5key_hash );
1040 smbk5pwd.on_bi.bi_cf_ocs = smbk5pwd_cfocs;
1042 rc = config_register_schema( smbk5pwd_cfats, smbk5pwd_cfocs );
1047 return overlay_register( &smbk5pwd );
1050 #if SLAPD_OVER_SMBK5PWD == SLAPD_MOD_DYNAMIC
1051 int init_module(int argc, char *argv[]) {
1052 return smbk5pwd_initialize();
1056 #endif /* defined(SLAPD_OVER_SMBK5PWD) */