1 /* smbk5pwd.c - Overlay for managing Samba and Heimdal passwords */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2004-2015 The OpenLDAP Foundation.
6 * Portions Copyright 2004-2005 by Howard Chu, Symas Corp.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * Support for table-driven configuration added by Pierangelo Masarati.
19 * Support for sambaPwdMustChange and sambaPwdCanChange added by Marco D'Ettorre.
20 * Support for shadowLastChange added by SATOH Fumiyasu @ OSS Technology, Inc.
25 #ifndef SLAPD_OVER_SMBK5PWD
26 #define SLAPD_OVER_SMBK5PWD SLAPD_MOD_DYNAMIC
29 #ifdef SLAPD_OVER_SMBK5PWD
33 #include <ac/string.h>
42 /* make ASN1_MALLOC_ENCODE use our allocator */
43 #define malloc ch_malloc
46 #include <kadm5/admin.h>
49 #ifndef HDB_INTERFACE_VERSION
50 #define HDB_MASTER_KEY_SET master_key_set
52 #define HDB_MASTER_KEY_SET hdb_master_key_set
55 static krb5_context context;
56 static void *kadm_context;
57 static kadm5_config_params conf;
60 static AttributeDescription *ad_krb5Key;
61 static AttributeDescription *ad_krb5KeyVersionNumber;
62 static AttributeDescription *ad_krb5PrincipalName;
63 static AttributeDescription *ad_krb5ValidEnd;
64 static ObjectClass *oc_krb5KDCEntry;
69 #include <nettle/des.h>
70 #include <nettle/md4.h>
71 typedef unsigned char DES_cblock[8];
73 #include <openssl/des.h>
74 #include <openssl/md4.h>
76 #error Unsupported crypto backend.
78 #include "ldap_utf8.h"
80 static AttributeDescription *ad_sambaLMPassword;
81 static AttributeDescription *ad_sambaNTPassword;
82 static AttributeDescription *ad_sambaPwdLastSet;
83 static AttributeDescription *ad_sambaPwdMustChange;
84 static AttributeDescription *ad_sambaPwdCanChange;
85 static ObjectClass *oc_sambaSamAccount;
89 static AttributeDescription *ad_shadowLastChange;
90 static ObjectClass *oc_shadowAccount;
93 /* Per-instance configuration information */
94 typedef struct smbk5pwd_t {
96 #define SMBK5PWD_F_KRB5 (0x1U)
97 #define SMBK5PWD_F_SAMBA (0x2U)
98 #define SMBK5PWD_F_SHADOW (0x4U)
100 #define SMBK5PWD_DO_KRB5(pi) ((pi)->mode & SMBK5PWD_F_KRB5)
101 #define SMBK5PWD_DO_SAMBA(pi) ((pi)->mode & SMBK5PWD_F_SAMBA)
102 #define SMBK5PWD_DO_SHADOW(pi) ((pi)->mode & SMBK5PWD_F_SHADOW)
109 /* How many seconds before forcing a password change? */
110 time_t smb_must_change;
111 /* How many seconds after allowing a password change? */
112 time_t smb_can_change;
120 static const unsigned SMBK5PWD_F_ALL =
133 static int smbk5pwd_modules_init( smbk5pwd_t *pi );
136 static const char hex[] = "0123456789abcdef";
138 /* From liblutil/passwd.c... */
139 static void lmPasswd_to_key(
140 const char *lmPasswd,
143 const unsigned char *lpw = (const unsigned char *)lmPasswd;
144 unsigned char *k = (unsigned char *)key;
146 /* make room for parity bits */
148 k[1] = ((lpw[0]&0x01)<<7) | (lpw[1]>>1);
149 k[2] = ((lpw[1]&0x03)<<6) | (lpw[2]>>2);
150 k[3] = ((lpw[2]&0x07)<<5) | (lpw[3]>>3);
151 k[4] = ((lpw[3]&0x0F)<<4) | (lpw[4]>>4);
152 k[5] = ((lpw[4]&0x1F)<<3) | (lpw[5]>>5);
153 k[6] = ((lpw[5]&0x3F)<<2) | (lpw[6]>>6);
154 k[7] = ((lpw[6]&0x7F)<<1);
157 des_set_odd_parity( key );
161 #define MAX_PWLEN 256
165 const char in[HASHLEN],
173 out->bv_val = ch_malloc(HASHLEN*2 + 1);
174 out->bv_len = HASHLEN*2;
177 b = (unsigned char *)in;
178 for (i=0; i<HASHLEN; i++) {
180 *a++ = hex[*b++ & 0x0f];
186 struct berval *passwd,
190 char UcasePassword[15];
192 DES_cblock StdText = "KGS!@#$%";
195 DES_key_schedule schedule;
196 #elif defined(HAVE_GNUTLS)
200 strncpy( UcasePassword, passwd->bv_val, 14 );
201 UcasePassword[14] = '\0';
202 ldap_pvt_str2upper( UcasePassword );
204 lmPasswd_to_key( UcasePassword, &key );
206 des_set_key( &ctx, key );
207 des_encrypt( &ctx, sizeof(key), hbuf[0], StdText );
209 lmPasswd_to_key( &UcasePassword[7], &key );
210 des_set_key( &ctx, key );
211 des_encrypt( &ctx, sizeof(key), hbuf[1], StdText );
212 #elif defined(HAVE_OPENSSL)
213 des_set_key_unchecked( &key, schedule );
214 des_ecb_encrypt( &StdText, &hbuf[0], schedule , DES_ENCRYPT );
216 lmPasswd_to_key( &UcasePassword[7], &key );
217 des_set_key_unchecked( &key, schedule );
218 des_ecb_encrypt( &StdText, &hbuf[1], schedule , DES_ENCRYPT );
221 hexify( (char *)hbuf, hash );
225 struct berval *passwd,
229 /* Windows currently only allows 14 character passwords, but
230 * may support up to 256 in the future. We assume this means
231 * 256 UCS2 characters, not 256 bytes...
236 #elif defined(HAVE_GNUTLS)
240 if (passwd->bv_len > MAX_PWLEN*2)
241 passwd->bv_len = MAX_PWLEN*2;
245 MD4_Update( &ctx, passwd->bv_val, passwd->bv_len );
246 MD4_Final( (unsigned char *)hbuf, &ctx );
247 #elif defined(HAVE_GNUTLS)
249 md4_update( &ctx, passwd->bv_len, (unsigned char *)passwd->bv_val );
250 md4_digest( &ctx, sizeof(hbuf), (unsigned char *)hbuf );
253 hexify( hbuf, hash );
255 #endif /* DO_SAMBA */
259 static int smbk5pwd_op_cleanup(
265 /* clear out the current key */
266 ldap_pvt_thread_pool_setkey( op->o_threadctx, smbk5pwd_op_cleanup,
267 NULL, 0, NULL, NULL );
269 /* free the callback */
271 op->o_callback = cb->sc_next;
272 op->o_tmpfree( cb, op->o_tmpmemctx );
276 static int smbk5pwd_op_bind(
280 /* If this is a simple Bind, stash the Op pointer so our chk
281 * function can find it. Set a cleanup callback to clear it
282 * out when the Bind completes.
284 if ( op->oq_bind.rb_method == LDAP_AUTH_SIMPLE ) {
286 ldap_pvt_thread_pool_setkey( op->o_threadctx,
287 smbk5pwd_op_cleanup, op, 0, NULL, NULL );
288 cb = op->o_tmpcalloc( 1, sizeof(slap_callback), op->o_tmpmemctx );
289 cb->sc_cleanup = smbk5pwd_op_cleanup;
290 cb->sc_next = op->o_callback;
293 return SLAP_CB_CONTINUE;
296 static LUTIL_PASSWD_CHK_FUNC k5key_chk;
297 static LUTIL_PASSWD_HASH_FUNC k5key_hash;
298 static const struct berval k5key_scheme = BER_BVC("{K5KEY}");
300 /* This password scheme stores no data in the userPassword attribute
301 * other than the scheme name. It assumes the invoking entry is a
302 * krb5KDCentry and compares the passed-in credentials against the
303 * krb5Key attribute. The krb5Key may be multi-valued, but they are
304 * simply multiple keytypes generated from the same input string, so
305 * only the first value needs to be compared here.
307 * Since the lutil_passwd API doesn't pass the Entry object in, we
308 * have to fetch it ourselves in order to get access to the other
309 * attributes. We accomplish this with the help of the overlay's Bind
310 * function, which stores the current Operation pointer in thread-specific
311 * storage so we can retrieve it here. The Operation provides all
312 * the necessary context for us to get Entry from the database.
314 static int k5key_chk(
315 const struct berval *sc,
316 const struct berval *passwd,
317 const struct berval *cred,
330 /* Find our thread context, find our Operation */
331 ctx = ldap_pvt_thread_pool_context();
333 if ( ldap_pvt_thread_pool_getkey( ctx, smbk5pwd_op_cleanup, &op_tmp, NULL )
335 return LUTIL_PASSWD_ERR;
338 rc = be_entry_get_rw( op, &op->o_req_ndn, NULL, NULL, 0, &e );
339 if ( rc != LDAP_SUCCESS ) return LUTIL_PASSWD_ERR;
341 rc = LUTIL_PASSWD_ERR;
346 a = attr_find( e->e_attrs, ad_krb5PrincipalName );
349 memset( &ent, 0, sizeof(ent) );
350 ret = krb5_parse_name(context, a->a_vals[0].bv_val, &ent.principal);
353 a = attr_find( e->e_attrs, ad_krb5ValidEnd );
356 struct lutil_timet tt;
357 if ( lutil_parsetime( a->a_vals[0].bv_val, &tm ) == 0 &&
358 lutil_tm2time( &tm, &tt ) == 0 && tt.tt_usec < op->o_time ) {
359 /* Account is expired */
360 rc = LUTIL_PASSWD_ERR;
365 krb5_get_pw_salt( context, ent.principal, &salt );
366 krb5_free_principal( context, ent.principal );
368 a = attr_find( e->e_attrs, ad_krb5Key );
372 ent.keys.val = &ekey;
373 decode_Key((unsigned char *) a->a_vals[0].bv_val,
374 (size_t) a->a_vals[0].bv_len, &ent.keys.val[0], &l);
375 if ( db->HDB_MASTER_KEY_SET )
376 hdb_unseal_keys( context, db, &ent );
378 krb5_string_to_key_salt( context, ekey.key.keytype, cred->bv_val,
381 krb5_free_salt( context, salt );
383 if ( memcmp( ekey.key.keyvalue.data, key.keyvalue.data,
384 key.keyvalue.length ) == 0 ) rc = LUTIL_PASSWD_OK;
386 krb5_free_keyblock_contents( context, &key );
387 krb5_free_keyblock_contents( context, &ekey.key );
390 be_entry_release_r( op, e );
394 static int k5key_hash(
395 const struct berval *scheme,
396 const struct berval *passwd,
400 ber_dupbv( hash, (struct berval *)&k5key_scheme );
401 return LUTIL_PASSWD_OK;
405 static int smbk5pwd_exop_passwd(
410 req_pwdexop_s *qpw = &op->oq_pwdexop;
413 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
414 smbk5pwd_t *pi = on->on_bi.bi_private;
417 /* Not the operation we expected, pass it on... */
418 if ( ber_bvcmp( &slap_EXOP_MODIFY_PASSWD, &op->ore_reqoid ) ) {
419 return SLAP_CB_CONTINUE;
422 op->o_bd->bd_info = (BackendInfo *)on->on_info;
423 rc = be_entry_get_rw( op, &op->o_req_ndn, NULL, NULL, 0, &e );
424 if ( rc != LDAP_SUCCESS ) return rc;
426 term = qpw->rs_new.bv_val[qpw->rs_new.bv_len];
427 qpw->rs_new.bv_val[qpw->rs_new.bv_len] = '\0';
439 if ( !SMBK5PWD_DO_KRB5( pi ) ) break;
441 if ( !is_entry_objectclass(e, oc_krb5KDCEntry, 0 ) ) break;
443 a = attr_find( e->e_attrs, ad_krb5PrincipalName );
446 memset( &ent, 0, sizeof(ent) );
447 ret = krb5_parse_name(context, a->a_vals[0].bv_val, &ent.principal);
450 a = attr_find( e->e_attrs, ad_krb5KeyVersionNumber );
453 if ( lutil_atoi( &kvno, a->a_vals[0].bv_val ) != 0 ) {
454 Debug( LDAP_DEBUG_ANY, "%s smbk5pwd EXOP: "
455 "dn=\"%s\" unable to parse krb5KeyVersionNumber=\"%s\"\n",
456 op->o_log_prefix, e->e_name.bv_val, a->a_vals[0].bv_val );
460 /* shouldn't happen, this is a required attr */
461 Debug( LDAP_DEBUG_ANY, "%s smbk5pwd EXOP: "
462 "dn=\"%s\" missing krb5KeyVersionNumber\n",
463 op->o_log_prefix, e->e_name.bv_val, 0 );
466 ret = hdb_generate_key_set_password(context, ent.principal,
467 qpw->rs_new.bv_val, &ent.keys.val, &nkeys);
468 ent.keys.len = nkeys;
469 hdb_seal_keys(context, db, &ent);
470 krb5_free_principal( context, ent.principal );
472 keys = ch_malloc( (ent.keys.len + 1) * sizeof(struct berval));
474 for (i = 0; i < ent.keys.len; i++) {
478 ASN1_MALLOC_ENCODE(Key, buf, len, &ent.keys.val[i], &len, ret);
482 keys[i].bv_val = (char *)buf;
483 keys[i].bv_len = len;
485 BER_BVZERO( &keys[i] );
487 hdb_free_keys(context, ent.keys.len, ent.keys.val);
489 if ( i != ent.keys.len ) {
490 ber_bvarray_free( keys );
494 ml = ch_malloc(sizeof(Modifications));
495 if (!qpw->rs_modtail) qpw->rs_modtail = &ml->sml_next;
496 ml->sml_next = qpw->rs_mods;
499 ml->sml_desc = ad_krb5Key;
500 ml->sml_op = LDAP_MOD_REPLACE;
501 #ifdef SLAP_MOD_INTERNAL
502 ml->sml_flags = SLAP_MOD_INTERNAL;
505 ml->sml_values = keys;
506 ml->sml_nvalues = NULL;
508 ml = ch_malloc(sizeof(Modifications));
509 ml->sml_next = qpw->rs_mods;
512 ml->sml_desc = ad_krb5KeyVersionNumber;
513 ml->sml_op = LDAP_MOD_REPLACE;
514 #ifdef SLAP_MOD_INTERNAL
515 ml->sml_flags = SLAP_MOD_INTERNAL;
518 ml->sml_values = ch_malloc( 2 * sizeof(struct berval));
519 ml->sml_values[0].bv_val = ch_malloc( 64 );
520 ml->sml_values[0].bv_len = sprintf(ml->sml_values[0].bv_val,
522 BER_BVZERO( &ml->sml_values[1] );
523 ml->sml_nvalues = NULL;
529 if ( SMBK5PWD_DO_SAMBA( pi ) && is_entry_objectclass(e, oc_sambaSamAccount, 0 ) ) {
536 /* Expand incoming UTF8 string to UCS4 */
537 l = ldap_utf8_chars(qpw->rs_new.bv_val);
538 wcs = ch_malloc((l+1) * sizeof(wchar_t));
540 ldap_x_utf8s_to_wcs( wcs, qpw->rs_new.bv_val, l );
542 /* Truncate UCS4 to UCS2 */
544 for (j=0; j<l; j++) {
547 *c++ = (wc >> 8) & 0xff;
550 pwd.bv_val = (char *)wcs;
553 ml = ch_malloc(sizeof(Modifications));
554 if (!qpw->rs_modtail) qpw->rs_modtail = &ml->sml_next;
555 ml->sml_next = qpw->rs_mods;
558 keys = ch_malloc( 2 * sizeof(struct berval) );
559 BER_BVZERO( &keys[1] );
560 nthash( &pwd, keys );
562 ml->sml_desc = ad_sambaNTPassword;
563 ml->sml_op = LDAP_MOD_REPLACE;
564 #ifdef SLAP_MOD_INTERNAL
565 ml->sml_flags = SLAP_MOD_INTERNAL;
568 ml->sml_values = keys;
569 ml->sml_nvalues = NULL;
571 /* Truncate UCS2 to 8-bit ASCII */
574 for (j=1; j<l; j++) {
579 pwd.bv_val[pwd.bv_len] = '\0';
581 ml = ch_malloc(sizeof(Modifications));
582 ml->sml_next = qpw->rs_mods;
585 keys = ch_malloc( 2 * sizeof(struct berval) );
586 BER_BVZERO( &keys[1] );
587 lmhash( &pwd, keys );
589 ml->sml_desc = ad_sambaLMPassword;
590 ml->sml_op = LDAP_MOD_REPLACE;
591 #ifdef SLAP_MOD_INTERNAL
592 ml->sml_flags = SLAP_MOD_INTERNAL;
595 ml->sml_values = keys;
596 ml->sml_nvalues = NULL;
600 ml = ch_malloc(sizeof(Modifications));
601 ml->sml_next = qpw->rs_mods;
604 keys = ch_malloc( 2 * sizeof(struct berval) );
605 keys[0].bv_val = ch_malloc( LDAP_PVT_INTTYPE_CHARS(long) );
606 keys[0].bv_len = snprintf(keys[0].bv_val,
607 LDAP_PVT_INTTYPE_CHARS(long),
608 "%ld", slap_get_time());
609 BER_BVZERO( &keys[1] );
611 ml->sml_desc = ad_sambaPwdLastSet;
612 ml->sml_op = LDAP_MOD_REPLACE;
613 #ifdef SLAP_MOD_INTERNAL
614 ml->sml_flags = SLAP_MOD_INTERNAL;
617 ml->sml_values = keys;
618 ml->sml_nvalues = NULL;
620 if (pi->smb_must_change)
622 ml = ch_malloc(sizeof(Modifications));
623 ml->sml_next = qpw->rs_mods;
626 keys = ch_malloc( 2 * sizeof(struct berval) );
627 keys[0].bv_val = ch_malloc( LDAP_PVT_INTTYPE_CHARS(long) );
628 keys[0].bv_len = snprintf(keys[0].bv_val,
629 LDAP_PVT_INTTYPE_CHARS(long),
630 "%ld", slap_get_time() + pi->smb_must_change);
631 BER_BVZERO( &keys[1] );
633 ml->sml_desc = ad_sambaPwdMustChange;
634 ml->sml_op = LDAP_MOD_REPLACE;
635 #ifdef SLAP_MOD_INTERNAL
636 ml->sml_flags = SLAP_MOD_INTERNAL;
639 ml->sml_values = keys;
640 ml->sml_nvalues = NULL;
643 if (pi->smb_can_change)
645 ml = ch_malloc(sizeof(Modifications));
646 ml->sml_next = qpw->rs_mods;
649 keys = ch_malloc( 2 * sizeof(struct berval) );
650 keys[0].bv_val = ch_malloc( LDAP_PVT_INTTYPE_CHARS(long) );
651 keys[0].bv_len = snprintf(keys[0].bv_val,
652 LDAP_PVT_INTTYPE_CHARS(long),
653 "%ld", slap_get_time() + pi->smb_can_change);
654 BER_BVZERO( &keys[1] );
656 ml->sml_desc = ad_sambaPwdCanChange;
657 ml->sml_op = LDAP_MOD_REPLACE;
658 #ifdef SLAP_MOD_INTERNAL
659 ml->sml_flags = SLAP_MOD_INTERNAL;
662 ml->sml_values = keys;
663 ml->sml_nvalues = NULL;
666 #endif /* DO_SAMBA */
670 if ( SMBK5PWD_DO_SHADOW( pi ) && is_entry_objectclass(e, oc_shadowAccount, 0 ) ) {
673 ml = ch_malloc(sizeof(Modifications));
674 if (!qpw->rs_modtail) qpw->rs_modtail = &ml->sml_next;
675 ml->sml_next = qpw->rs_mods;
678 keys = ch_malloc( sizeof(struct berval) * 2);
679 BER_BVZERO( &keys[1] );
680 keys[0].bv_val = ch_malloc( LDAP_PVT_INTTYPE_CHARS(long) );
681 keys[0].bv_len = snprintf(keys[0].bv_val,
682 LDAP_PVT_INTTYPE_CHARS(long),
683 "%ld", (long)(slap_get_time() / (60 * 60 * 24)));
685 ml->sml_desc = ad_shadowLastChange;
686 ml->sml_op = LDAP_MOD_REPLACE;
687 #ifdef SLAP_MOD_INTERNAL
688 ml->sml_flags = SLAP_MOD_INTERNAL;
691 ml->sml_values = keys;
692 ml->sml_nvalues = NULL;
694 #endif /* DO_SHADOW */
696 be_entry_release_r( op, e );
697 qpw->rs_new.bv_val[qpw->rs_new.bv_len] = term;
699 return SLAP_CB_CONTINUE;
702 static slap_overinst smbk5pwd;
704 /* back-config stuff */
706 PC_SMB_MUST_CHANGE = 1,
711 static ConfigDriver smbk5pwd_cf_func;
714 * NOTE: uses OID arcs OLcfgCtAt:1 and OLcfgCtOc:1
717 static ConfigTable smbk5pwd_cfats[] = {
718 { "smbk5pwd-enable", "arg",
719 2, 0, 0, ARG_MAGIC|PC_SMB_ENABLE, smbk5pwd_cf_func,
720 "( OLcfgCtAt:1.1 NAME 'olcSmbK5PwdEnable' "
721 "DESC 'Modules to be enabled' "
722 "SYNTAX OMsDirectoryString )", NULL, NULL },
723 { "smbk5pwd-must-change", "time",
724 2, 2, 0, ARG_MAGIC|ARG_INT|PC_SMB_MUST_CHANGE, smbk5pwd_cf_func,
725 "( OLcfgCtAt:1.2 NAME 'olcSmbK5PwdMustChange' "
726 "DESC 'Credentials validity interval' "
727 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
728 { "smbk5pwd-can-change", "time",
729 2, 2, 0, ARG_MAGIC|ARG_INT|PC_SMB_CAN_CHANGE, smbk5pwd_cf_func,
730 "( OLcfgCtAt:1.3 NAME 'olcSmbK5PwdCanChange' "
731 "DESC 'Credentials minimum validity interval' "
732 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
734 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
737 static ConfigOCs smbk5pwd_cfocs[] = {
739 "NAME 'olcSmbK5PwdConfig' "
740 "DESC 'smbk5pwd overlay configuration' "
741 "SUP olcOverlayConfig "
744 "$ olcSmbK5PwdMustChange "
745 "$ olcSmbK5PwdCanChange "
746 ") )", Cft_Overlay, smbk5pwd_cfats },
752 * add here other functionalities; handle their initialization
753 * as appropriate in smbk5pwd_modules_init().
755 static slap_verbmasks smbk5pwd_modules[] = {
756 { BER_BVC( "krb5" ), SMBK5PWD_F_KRB5 },
757 { BER_BVC( "samba" ), SMBK5PWD_F_SAMBA },
758 { BER_BVC( "shadow" ), SMBK5PWD_F_SHADOW },
763 smbk5pwd_cf_func( ConfigArgs *c )
765 slap_overinst *on = (slap_overinst *)c->bi;
768 smbk5pwd_t *pi = on->on_bi.bi_private;
770 if ( c->op == SLAP_CONFIG_EMIT ) {
772 case PC_SMB_MUST_CHANGE:
774 c->value_int = pi->smb_must_change;
775 #else /* ! DO_SAMBA */
777 #endif /* ! DO_SAMBA */
780 case PC_SMB_CAN_CHANGE:
782 c->value_int = pi->smb_can_change;
783 #else /* ! DO_SAMBA */
785 #endif /* ! DO_SAMBA */
789 c->rvalue_vals = NULL;
791 mask_to_verbs( smbk5pwd_modules, pi->mode, &c->rvalue_vals );
792 if ( c->rvalue_vals == NULL ) {
804 } else if ( c->op == LDAP_MOD_DELETE ) {
806 case PC_SMB_MUST_CHANGE:
809 case PC_SMB_CAN_CHANGE:
819 i = verb_to_mask( c->line, smbk5pwd_modules );
820 pi->mode &= ~smbk5pwd_modules[i].mask;
832 case PC_SMB_MUST_CHANGE:
834 if ( c->value_int < 0 ) {
835 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
836 "<%s> invalid negative value \"%d\".",
837 c->log, c->argv[ 0 ], 0 );
840 pi->smb_must_change = c->value_int;
841 #else /* ! DO_SAMBA */
842 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
843 "<%s> only meaningful "
844 "when compiled with -DDO_SAMBA.\n",
845 c->log, c->argv[ 0 ], 0 );
847 #endif /* ! DO_SAMBA */
850 case PC_SMB_CAN_CHANGE:
852 if ( c->value_int < 0 ) {
853 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
854 "<%s> invalid negative value \"%d\".",
855 c->log, c->argv[ 0 ], 0 );
858 pi->smb_can_change = c->value_int;
859 #else /* ! DO_SAMBA */
860 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
861 "<%s> only meaningful "
862 "when compiled with -DDO_SAMBA.\n",
863 c->log, c->argv[ 0 ], 0 );
865 #endif /* ! DO_SAMBA */
868 case PC_SMB_ENABLE: {
869 slap_mask_t mode = pi->mode, m = 0;
871 rc = verbs_to_mask( c->argc, c->argv, smbk5pwd_modules, &m );
873 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
874 "<%s> unknown module \"%s\".\n",
875 c->log, c->argv[ 0 ], c->argv[ rc ] );
879 /* we can hijack the smbk5pwd_t structure because
880 * from within the configuration, this is the only
885 if ( SMBK5PWD_DO_KRB5( pi ) ) {
886 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
887 "<%s> module \"%s\" only allowed when compiled with -DDO_KRB5.\n",
888 c->log, c->argv[ 0 ], c->argv[ rc ] );
892 #endif /* ! DO_KRB5 */
895 if ( SMBK5PWD_DO_SAMBA( pi ) ) {
896 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
897 "<%s> module \"%s\" only allowed when compiled with -DDO_SAMBA.\n",
898 c->log, c->argv[ 0 ], c->argv[ rc ] );
902 #endif /* ! DO_SAMBA */
905 if ( SMBK5PWD_DO_SHADOW( pi ) ) {
906 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
907 "<%s> module \"%s\" only allowed when compiled with -DDO_SHADOW.\n",
908 c->log, c->argv[ 0 ], c->argv[ rc ] );
912 #endif /* ! DO_SHADOW */
914 /* Re-initialize the module, because
915 * the configuration might have changed */
916 rc = smbk5pwd_modules_init( pi );
932 smbk5pwd_modules_init( smbk5pwd_t *pi )
936 AttributeDescription **adp;
940 { "krb5Key", &ad_krb5Key },
941 { "krb5KeyVersionNumber", &ad_krb5KeyVersionNumber },
942 { "krb5PrincipalName", &ad_krb5PrincipalName },
943 { "krb5ValidEnd", &ad_krb5ValidEnd },
949 { "sambaLMPassword", &ad_sambaLMPassword },
950 { "sambaNTPassword", &ad_sambaNTPassword },
951 { "sambaPwdLastSet", &ad_sambaPwdLastSet },
952 { "sambaPwdMustChange", &ad_sambaPwdMustChange },
953 { "sambaPwdCanChange", &ad_sambaPwdCanChange },
956 #endif /* DO_SAMBA */
959 { "shadowLastChange", &ad_shadowLastChange },
962 #endif /* DO_SHADOW */
965 /* this is to silence the unused var warning */
969 if ( SMBK5PWD_DO_KRB5( pi ) && oc_krb5KDCEntry == NULL ) {
971 extern HDB *_kadm5_s_get_db(void *);
975 /* Make sure all of our necessary schema items are loaded */
976 oc_krb5KDCEntry = oc_find( "krb5KDCEntry" );
977 if ( !oc_krb5KDCEntry ) {
978 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
979 "unable to find \"krb5KDCEntry\" objectClass.\n",
984 for ( i = 0; krb5_ad[ i ].name != NULL; i++ ) {
987 *(krb5_ad[ i ].adp) = NULL;
989 rc = slap_str2ad( krb5_ad[ i ].name, krb5_ad[ i ].adp, &text );
990 if ( rc != LDAP_SUCCESS ) {
991 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
992 "unable to find \"%s\" attributeType: %s (%d).\n",
993 krb5_ad[ i ].name, text, rc );
994 oc_krb5KDCEntry = NULL;
999 /* Initialize Kerberos context */
1000 ret = krb5_init_context(&context);
1002 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
1003 "unable to initialize krb5 context (%d).\n",
1005 oc_krb5KDCEntry = NULL;
1009 ret = kadm5_s_init_with_password_ctx( context,
1010 KADM5_ADMIN_SERVICE,
1012 KADM5_ADMIN_SERVICE,
1013 &conf, 0, 0, &kadm_context );
1015 char *err_str, *err_msg = "<unknown error>";
1016 err_str = krb5_get_error_string( context );
1018 err_msg = (char *)krb5_get_err_text( context, ret );
1019 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
1020 "unable to initialize krb5 admin context: %s (%d).\n",
1021 err_str ? err_str : err_msg, ret, 0 );
1023 krb5_free_error_string( context, err_str );
1024 krb5_free_context( context );
1025 oc_krb5KDCEntry = NULL;
1029 db = _kadm5_s_get_db( kadm_context );
1031 #endif /* DO_KRB5 */
1034 if ( SMBK5PWD_DO_SAMBA( pi ) && oc_sambaSamAccount == NULL ) {
1037 oc_sambaSamAccount = oc_find( "sambaSamAccount" );
1038 if ( !oc_sambaSamAccount ) {
1039 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
1040 "unable to find \"sambaSamAccount\" objectClass.\n",
1045 for ( i = 0; samba_ad[ i ].name != NULL; i++ ) {
1048 *(samba_ad[ i ].adp) = NULL;
1050 rc = slap_str2ad( samba_ad[ i ].name, samba_ad[ i ].adp, &text );
1051 if ( rc != LDAP_SUCCESS ) {
1052 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
1053 "unable to find \"%s\" attributeType: %s (%d).\n",
1054 samba_ad[ i ].name, text, rc );
1055 oc_sambaSamAccount = NULL;
1060 #endif /* DO_SAMBA */
1063 if ( SMBK5PWD_DO_SHADOW( pi ) && oc_shadowAccount == NULL ) {
1066 oc_shadowAccount = oc_find( "shadowAccount" );
1067 if ( !oc_shadowAccount ) {
1068 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
1069 "unable to find \"shadowAccount\" objectClass.\n",
1074 for ( i = 0; shadow_ad[ i ].name != NULL; i++ ) {
1077 *(shadow_ad[ i ].adp) = NULL;
1079 rc = slap_str2ad( shadow_ad[ i ].name, shadow_ad[ i ].adp, &text );
1080 if ( rc != LDAP_SUCCESS ) {
1081 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
1082 "unable to find \"%s\" attributeType: %s (%d).\n",
1083 shadow_ad[ i ].name, text, rc );
1084 oc_shadowAccount = NULL;
1089 #endif /* DO_SHADOW */
1095 smbk5pwd_db_init(BackendDB *be, ConfigReply *cr)
1097 slap_overinst *on = (slap_overinst *)be->bd_info;
1100 pi = ch_calloc( 1, sizeof( smbk5pwd_t ) );
1104 on->on_bi.bi_private = (void *)pi;
1110 smbk5pwd_db_open(BackendDB *be, ConfigReply *cr)
1112 slap_overinst *on = (slap_overinst *)be->bd_info;
1113 smbk5pwd_t *pi = (smbk5pwd_t *)on->on_bi.bi_private;
1117 if ( pi->mode == 0 ) {
1118 pi->mode = SMBK5PWD_F_ALL;
1121 rc = smbk5pwd_modules_init( pi );
1130 smbk5pwd_db_destroy(BackendDB *be, ConfigReply *cr)
1132 slap_overinst *on = (slap_overinst *)be->bd_info;
1133 smbk5pwd_t *pi = (smbk5pwd_t *)on->on_bi.bi_private;
1143 smbk5pwd_initialize(void)
1147 smbk5pwd.on_bi.bi_type = "smbk5pwd";
1149 smbk5pwd.on_bi.bi_db_init = smbk5pwd_db_init;
1150 smbk5pwd.on_bi.bi_db_open = smbk5pwd_db_open;
1151 smbk5pwd.on_bi.bi_db_destroy = smbk5pwd_db_destroy;
1153 smbk5pwd.on_bi.bi_extended = smbk5pwd_exop_passwd;
1156 smbk5pwd.on_bi.bi_op_bind = smbk5pwd_op_bind;
1158 lutil_passwd_add( (struct berval *)&k5key_scheme, k5key_chk, k5key_hash );
1161 smbk5pwd.on_bi.bi_cf_ocs = smbk5pwd_cfocs;
1163 rc = config_register_schema( smbk5pwd_cfats, smbk5pwd_cfocs );
1168 return overlay_register( &smbk5pwd );
1171 #if SLAPD_OVER_SMBK5PWD == SLAPD_MOD_DYNAMIC
1172 int init_module(int argc, char *argv[]) {
1173 return smbk5pwd_initialize();
1177 #endif /* defined(SLAPD_OVER_SMBK5PWD) */