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-2012 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;
70 typedef unsigned char DES_cblock[8];
72 #include <openssl/des.h>
73 #include <openssl/md4.h>
75 #include "ldap_utf8.h"
77 static AttributeDescription *ad_sambaLMPassword;
78 static AttributeDescription *ad_sambaNTPassword;
79 static AttributeDescription *ad_sambaPwdLastSet;
80 static AttributeDescription *ad_sambaPwdMustChange;
81 static AttributeDescription *ad_sambaPwdCanChange;
82 static ObjectClass *oc_sambaSamAccount;
86 static AttributeDescription *ad_shadowLastChange;
87 static ObjectClass *oc_shadowAccount;
90 /* Per-instance configuration information */
91 typedef struct smbk5pwd_t {
93 #define SMBK5PWD_F_KRB5 (0x1U)
94 #define SMBK5PWD_F_SAMBA (0x2U)
95 #define SMBK5PWD_F_SHADOW (0x4U)
97 #define SMBK5PWD_DO_KRB5(pi) ((pi)->mode & SMBK5PWD_F_KRB5)
98 #define SMBK5PWD_DO_SAMBA(pi) ((pi)->mode & SMBK5PWD_F_SAMBA)
99 #define SMBK5PWD_DO_SHADOW(pi) ((pi)->mode & SMBK5PWD_F_SHADOW)
106 /* How many seconds before forcing a password change? */
107 time_t smb_must_change;
108 /* How many seconds after allowing a password change? */
109 time_t smb_can_change;
117 static const unsigned SMBK5PWD_F_ALL =
130 static int smbk5pwd_modules_init( smbk5pwd_t *pi );
133 static const char hex[] = "0123456789abcdef";
135 /* From liblutil/passwd.c... */
136 static void lmPasswd_to_key(
137 const char *lmPasswd,
140 const unsigned char *lpw = (const unsigned char *)lmPasswd;
141 unsigned char *k = (unsigned char *)key;
143 /* make room for parity bits */
145 k[1] = ((lpw[0]&0x01)<<7) | (lpw[1]>>1);
146 k[2] = ((lpw[1]&0x03)<<6) | (lpw[2]>>2);
147 k[3] = ((lpw[2]&0x07)<<5) | (lpw[3]>>3);
148 k[4] = ((lpw[3]&0x0F)<<4) | (lpw[4]>>4);
149 k[5] = ((lpw[4]&0x1F)<<3) | (lpw[5]>>5);
150 k[6] = ((lpw[5]&0x3F)<<2) | (lpw[6]>>6);
151 k[7] = ((lpw[6]&0x7F)<<1);
154 des_set_odd_parity( key );
158 #define MAX_PWLEN 256
162 const char in[HASHLEN],
170 out->bv_val = ch_malloc(HASHLEN*2 + 1);
171 out->bv_len = HASHLEN*2;
174 b = (unsigned char *)in;
175 for (i=0; i<HASHLEN; i++) {
177 *a++ = hex[*b++ & 0x0f];
183 struct berval *passwd,
187 char UcasePassword[15];
189 DES_cblock StdText = "KGS!@#$%";
192 DES_key_schedule schedule;
193 #elif defined(HAVE_GNUTLS)
194 gcry_cipher_hd_t h = NULL;
197 err = gcry_cipher_open( &h, GCRY_CIPHER_DES, GCRY_CIPHER_MODE_CBC, 0 );
201 strncpy( UcasePassword, passwd->bv_val, 14 );
202 UcasePassword[14] = '\0';
203 ldap_pvt_str2upper( UcasePassword );
205 lmPasswd_to_key( UcasePassword, &key );
207 err = gcry_cipher_setkey( h, &key, sizeof(key) );
209 err = gcry_cipher_encrypt( h, &hbuf[0], sizeof(key), &StdText, sizeof(key) );
211 gcry_cipher_reset( h );
212 lmPasswd_to_key( &UcasePassword[7], &key );
213 err = gcry_cipher_setkey( h, &key, sizeof(key) );
215 err = gcry_cipher_encrypt( h, &hbuf[1], sizeof(key), &StdText, sizeof(key) );
218 gcry_cipher_close( h );
220 #elif defined(HAVE_OPENSSL)
221 des_set_key_unchecked( &key, schedule );
222 des_ecb_encrypt( &StdText, &hbuf[0], schedule , DES_ENCRYPT );
224 lmPasswd_to_key( &UcasePassword[7], &key );
225 des_set_key_unchecked( &key, schedule );
226 des_ecb_encrypt( &StdText, &hbuf[1], schedule , DES_ENCRYPT );
229 hexify( (char *)hbuf, hash );
233 struct berval *passwd,
237 /* Windows currently only allows 14 character passwords, but
238 * may support up to 256 in the future. We assume this means
239 * 256 UCS2 characters, not 256 bytes...
246 if (passwd->bv_len > MAX_PWLEN*2)
247 passwd->bv_len = MAX_PWLEN*2;
251 MD4_Update( &ctx, passwd->bv_val, passwd->bv_len );
252 MD4_Final( (unsigned char *)hbuf, &ctx );
253 #elif defined(HAVE_GNUTLS)
254 gcry_md_hash_buffer(GCRY_MD_MD4, hbuf, passwd->bv_val, passwd->bv_len );
257 hexify( hbuf, hash );
259 #endif /* DO_SAMBA */
263 static int smbk5pwd_op_cleanup(
269 /* clear out the current key */
270 ldap_pvt_thread_pool_setkey( op->o_threadctx, smbk5pwd_op_cleanup,
271 NULL, 0, NULL, NULL );
273 /* free the callback */
275 op->o_callback = cb->sc_next;
276 op->o_tmpfree( cb, op->o_tmpmemctx );
280 static int smbk5pwd_op_bind(
284 /* If this is a simple Bind, stash the Op pointer so our chk
285 * function can find it. Set a cleanup callback to clear it
286 * out when the Bind completes.
288 if ( op->oq_bind.rb_method == LDAP_AUTH_SIMPLE ) {
290 ldap_pvt_thread_pool_setkey( op->o_threadctx,
291 smbk5pwd_op_cleanup, op, 0, NULL, NULL );
292 cb = op->o_tmpcalloc( 1, sizeof(slap_callback), op->o_tmpmemctx );
293 cb->sc_cleanup = smbk5pwd_op_cleanup;
294 cb->sc_next = op->o_callback;
297 return SLAP_CB_CONTINUE;
300 static LUTIL_PASSWD_CHK_FUNC k5key_chk;
301 static LUTIL_PASSWD_HASH_FUNC k5key_hash;
302 static const struct berval k5key_scheme = BER_BVC("{K5KEY}");
304 /* This password scheme stores no data in the userPassword attribute
305 * other than the scheme name. It assumes the invoking entry is a
306 * krb5KDCentry and compares the passed-in credentials against the
307 * krb5Key attribute. The krb5Key may be multi-valued, but they are
308 * simply multiple keytypes generated from the same input string, so
309 * only the first value needs to be compared here.
311 * Since the lutil_passwd API doesn't pass the Entry object in, we
312 * have to fetch it ourselves in order to get access to the other
313 * attributes. We accomplish this with the help of the overlay's Bind
314 * function, which stores the current Operation pointer in thread-specific
315 * storage so we can retrieve it here. The Operation provides all
316 * the necessary context for us to get Entry from the database.
318 static int k5key_chk(
319 const struct berval *sc,
320 const struct berval *passwd,
321 const struct berval *cred,
334 /* Find our thread context, find our Operation */
335 ctx = ldap_pvt_thread_pool_context();
337 if ( ldap_pvt_thread_pool_getkey( ctx, smbk5pwd_op_cleanup, &op_tmp, NULL )
339 return LUTIL_PASSWD_ERR;
342 rc = be_entry_get_rw( op, &op->o_req_ndn, NULL, NULL, 0, &e );
343 if ( rc != LDAP_SUCCESS ) return LUTIL_PASSWD_ERR;
345 rc = LUTIL_PASSWD_ERR;
350 a = attr_find( e->e_attrs, ad_krb5PrincipalName );
353 memset( &ent, 0, sizeof(ent) );
354 ret = krb5_parse_name(context, a->a_vals[0].bv_val, &ent.principal);
357 a = attr_find( e->e_attrs, ad_krb5ValidEnd );
360 struct lutil_timet tt;
361 if ( lutil_parsetime( a->a_vals[0].bv_val, &tm ) == 0 &&
362 lutil_tm2time( &tm, &tt ) == 0 && tt.tt_usec < op->o_time ) {
363 /* Account is expired */
364 rc = LUTIL_PASSWD_ERR;
369 krb5_get_pw_salt( context, ent.principal, &salt );
370 krb5_free_principal( context, ent.principal );
372 a = attr_find( e->e_attrs, ad_krb5Key );
376 ent.keys.val = &ekey;
377 decode_Key((unsigned char *) a->a_vals[0].bv_val,
378 (size_t) a->a_vals[0].bv_len, &ent.keys.val[0], &l);
379 if ( db->HDB_MASTER_KEY_SET )
380 hdb_unseal_keys( context, db, &ent );
382 krb5_string_to_key_salt( context, ekey.key.keytype, cred->bv_val,
385 krb5_free_salt( context, salt );
387 if ( memcmp( ekey.key.keyvalue.data, key.keyvalue.data,
388 key.keyvalue.length ) == 0 ) rc = LUTIL_PASSWD_OK;
390 krb5_free_keyblock_contents( context, &key );
391 krb5_free_keyblock_contents( context, &ekey.key );
394 be_entry_release_r( op, e );
398 static int k5key_hash(
399 const struct berval *scheme,
400 const struct berval *passwd,
404 ber_dupbv( hash, (struct berval *)&k5key_scheme );
405 return LUTIL_PASSWD_OK;
409 static int smbk5pwd_exop_passwd(
414 req_pwdexop_s *qpw = &op->oq_pwdexop;
417 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
418 smbk5pwd_t *pi = on->on_bi.bi_private;
421 /* Not the operation we expected, pass it on... */
422 if ( ber_bvcmp( &slap_EXOP_MODIFY_PASSWD, &op->ore_reqoid ) ) {
423 return SLAP_CB_CONTINUE;
426 op->o_bd->bd_info = (BackendInfo *)on->on_info;
427 rc = be_entry_get_rw( op, &op->o_req_ndn, NULL, NULL, 0, &e );
428 if ( rc != LDAP_SUCCESS ) return rc;
430 term = qpw->rs_new.bv_val[qpw->rs_new.bv_len];
431 qpw->rs_new.bv_val[qpw->rs_new.bv_len] = '\0';
443 if ( !SMBK5PWD_DO_KRB5( pi ) ) break;
445 if ( !is_entry_objectclass(e, oc_krb5KDCEntry, 0 ) ) break;
447 a = attr_find( e->e_attrs, ad_krb5PrincipalName );
450 memset( &ent, 0, sizeof(ent) );
451 ret = krb5_parse_name(context, a->a_vals[0].bv_val, &ent.principal);
454 a = attr_find( e->e_attrs, ad_krb5KeyVersionNumber );
457 if ( lutil_atoi( &kvno, a->a_vals[0].bv_val ) != 0 ) {
458 Debug( LDAP_DEBUG_ANY, "%s smbk5pwd EXOP: "
459 "dn=\"%s\" unable to parse krb5KeyVersionNumber=\"%s\"\n",
460 op->o_log_prefix, e->e_name.bv_val, a->a_vals[0].bv_val );
464 /* shouldn't happen, this is a required attr */
465 Debug( LDAP_DEBUG_ANY, "%s smbk5pwd EXOP: "
466 "dn=\"%s\" missing krb5KeyVersionNumber\n",
467 op->o_log_prefix, e->e_name.bv_val, 0 );
470 ret = hdb_generate_key_set_password(context, ent.principal,
471 qpw->rs_new.bv_val, &ent.keys.val, &nkeys);
472 ent.keys.len = nkeys;
473 hdb_seal_keys(context, db, &ent);
474 krb5_free_principal( context, ent.principal );
476 keys = ch_malloc( (ent.keys.len + 1) * sizeof(struct berval));
478 for (i = 0; i < ent.keys.len; i++) {
482 ASN1_MALLOC_ENCODE(Key, buf, len, &ent.keys.val[i], &len, ret);
486 keys[i].bv_val = (char *)buf;
487 keys[i].bv_len = len;
489 BER_BVZERO( &keys[i] );
491 hdb_free_keys(context, ent.keys.len, ent.keys.val);
493 if ( i != ent.keys.len ) {
494 ber_bvarray_free( keys );
498 ml = ch_malloc(sizeof(Modifications));
499 if (!qpw->rs_modtail) qpw->rs_modtail = &ml->sml_next;
500 ml->sml_next = qpw->rs_mods;
503 ml->sml_desc = ad_krb5Key;
504 ml->sml_op = LDAP_MOD_REPLACE;
505 #ifdef SLAP_MOD_INTERNAL
506 ml->sml_flags = SLAP_MOD_INTERNAL;
509 ml->sml_values = keys;
510 ml->sml_nvalues = NULL;
512 ml = ch_malloc(sizeof(Modifications));
513 ml->sml_next = qpw->rs_mods;
516 ml->sml_desc = ad_krb5KeyVersionNumber;
517 ml->sml_op = LDAP_MOD_REPLACE;
518 #ifdef SLAP_MOD_INTERNAL
519 ml->sml_flags = SLAP_MOD_INTERNAL;
522 ml->sml_values = ch_malloc( 2 * sizeof(struct berval));
523 ml->sml_values[0].bv_val = ch_malloc( 64 );
524 ml->sml_values[0].bv_len = sprintf(ml->sml_values[0].bv_val,
526 BER_BVZERO( &ml->sml_values[1] );
527 ml->sml_nvalues = NULL;
533 if ( SMBK5PWD_DO_SAMBA( pi ) && is_entry_objectclass(e, oc_sambaSamAccount, 0 ) ) {
540 /* Expand incoming UTF8 string to UCS4 */
541 l = ldap_utf8_chars(qpw->rs_new.bv_val);
542 wcs = ch_malloc((l+1) * sizeof(wchar_t));
544 ldap_x_utf8s_to_wcs( wcs, qpw->rs_new.bv_val, l );
546 /* Truncate UCS4 to UCS2 */
548 for (j=0; j<l; j++) {
551 *c++ = (wc >> 8) & 0xff;
554 pwd.bv_val = (char *)wcs;
557 ml = ch_malloc(sizeof(Modifications));
558 if (!qpw->rs_modtail) qpw->rs_modtail = &ml->sml_next;
559 ml->sml_next = qpw->rs_mods;
562 keys = ch_malloc( 2 * sizeof(struct berval) );
563 BER_BVZERO( &keys[1] );
564 nthash( &pwd, keys );
566 ml->sml_desc = ad_sambaNTPassword;
567 ml->sml_op = LDAP_MOD_REPLACE;
568 #ifdef SLAP_MOD_INTERNAL
569 ml->sml_flags = SLAP_MOD_INTERNAL;
572 ml->sml_values = keys;
573 ml->sml_nvalues = NULL;
575 /* Truncate UCS2 to 8-bit ASCII */
578 for (j=1; j<l; j++) {
583 pwd.bv_val[pwd.bv_len] = '\0';
585 ml = ch_malloc(sizeof(Modifications));
586 ml->sml_next = qpw->rs_mods;
589 keys = ch_malloc( 2 * sizeof(struct berval) );
590 BER_BVZERO( &keys[1] );
591 lmhash( &pwd, keys );
593 ml->sml_desc = ad_sambaLMPassword;
594 ml->sml_op = LDAP_MOD_REPLACE;
595 #ifdef SLAP_MOD_INTERNAL
596 ml->sml_flags = SLAP_MOD_INTERNAL;
599 ml->sml_values = keys;
600 ml->sml_nvalues = NULL;
604 ml = ch_malloc(sizeof(Modifications));
605 ml->sml_next = qpw->rs_mods;
608 keys = ch_malloc( 2 * sizeof(struct berval) );
609 keys[0].bv_val = ch_malloc( LDAP_PVT_INTTYPE_CHARS(long) );
610 keys[0].bv_len = snprintf(keys[0].bv_val,
611 LDAP_PVT_INTTYPE_CHARS(long),
612 "%ld", slap_get_time());
613 BER_BVZERO( &keys[1] );
615 ml->sml_desc = ad_sambaPwdLastSet;
616 ml->sml_op = LDAP_MOD_REPLACE;
617 #ifdef SLAP_MOD_INTERNAL
618 ml->sml_flags = SLAP_MOD_INTERNAL;
621 ml->sml_values = keys;
622 ml->sml_nvalues = NULL;
624 if (pi->smb_must_change)
626 ml = ch_malloc(sizeof(Modifications));
627 ml->sml_next = qpw->rs_mods;
630 keys = ch_malloc( 2 * sizeof(struct berval) );
631 keys[0].bv_val = ch_malloc( LDAP_PVT_INTTYPE_CHARS(long) );
632 keys[0].bv_len = snprintf(keys[0].bv_val,
633 LDAP_PVT_INTTYPE_CHARS(long),
634 "%ld", slap_get_time() + pi->smb_must_change);
635 BER_BVZERO( &keys[1] );
637 ml->sml_desc = ad_sambaPwdMustChange;
638 ml->sml_op = LDAP_MOD_REPLACE;
639 #ifdef SLAP_MOD_INTERNAL
640 ml->sml_flags = SLAP_MOD_INTERNAL;
643 ml->sml_values = keys;
644 ml->sml_nvalues = NULL;
647 if (pi->smb_can_change)
649 ml = ch_malloc(sizeof(Modifications));
650 ml->sml_next = qpw->rs_mods;
653 keys = ch_malloc( 2 * sizeof(struct berval) );
654 keys[0].bv_val = ch_malloc( LDAP_PVT_INTTYPE_CHARS(long) );
655 keys[0].bv_len = snprintf(keys[0].bv_val,
656 LDAP_PVT_INTTYPE_CHARS(long),
657 "%ld", slap_get_time() + pi->smb_can_change);
658 BER_BVZERO( &keys[1] );
660 ml->sml_desc = ad_sambaPwdCanChange;
661 ml->sml_op = LDAP_MOD_REPLACE;
662 #ifdef SLAP_MOD_INTERNAL
663 ml->sml_flags = SLAP_MOD_INTERNAL;
666 ml->sml_values = keys;
667 ml->sml_nvalues = NULL;
670 #endif /* DO_SAMBA */
674 if ( SMBK5PWD_DO_SHADOW( pi ) && is_entry_objectclass(e, oc_shadowAccount, 0 ) ) {
677 ml = ch_malloc(sizeof(Modifications));
678 if (!qpw->rs_modtail) qpw->rs_modtail = &ml->sml_next;
679 ml->sml_next = qpw->rs_mods;
682 keys = ch_malloc( sizeof(struct berval) * 2);
683 BER_BVZERO( &keys[1] );
684 keys[0].bv_val = ch_malloc( LDAP_PVT_INTTYPE_CHARS(long) );
685 keys[0].bv_len = snprintf(keys[0].bv_val,
686 LDAP_PVT_INTTYPE_CHARS(long),
687 "%ld", (long)(slap_get_time() / (60 * 60 * 24)));
689 ml->sml_desc = ad_shadowLastChange;
690 ml->sml_op = LDAP_MOD_REPLACE;
691 #ifdef SLAP_MOD_INTERNAL
692 ml->sml_flags = SLAP_MOD_INTERNAL;
695 ml->sml_values = keys;
696 ml->sml_nvalues = NULL;
698 #endif /* DO_SHADOW */
700 be_entry_release_r( op, e );
701 qpw->rs_new.bv_val[qpw->rs_new.bv_len] = term;
703 return SLAP_CB_CONTINUE;
706 static slap_overinst smbk5pwd;
708 /* back-config stuff */
710 PC_SMB_MUST_CHANGE = 1,
715 static ConfigDriver smbk5pwd_cf_func;
718 * NOTE: uses OID arcs OLcfgCtAt:1 and OLcfgCtOc:1
721 static ConfigTable smbk5pwd_cfats[] = {
722 { "smbk5pwd-enable", "arg",
723 2, 0, 0, ARG_MAGIC|PC_SMB_ENABLE, smbk5pwd_cf_func,
724 "( OLcfgCtAt:1.1 NAME 'olcSmbK5PwdEnable' "
725 "DESC 'Modules to be enabled' "
726 "SYNTAX OMsDirectoryString )", NULL, NULL },
727 { "smbk5pwd-must-change", "time",
728 2, 2, 0, ARG_MAGIC|ARG_INT|PC_SMB_MUST_CHANGE, smbk5pwd_cf_func,
729 "( OLcfgCtAt:1.2 NAME 'olcSmbK5PwdMustChange' "
730 "DESC 'Credentials validity interval' "
731 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
732 { "smbk5pwd-can-change", "time",
733 2, 2, 0, ARG_MAGIC|ARG_INT|PC_SMB_CAN_CHANGE, smbk5pwd_cf_func,
734 "( OLcfgCtAt:1.3 NAME 'olcSmbK5PwdCanChange' "
735 "DESC 'Credentials minimum validity interval' "
736 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
738 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
741 static ConfigOCs smbk5pwd_cfocs[] = {
743 "NAME 'olcSmbK5PwdConfig' "
744 "DESC 'smbk5pwd overlay configuration' "
745 "SUP olcOverlayConfig "
748 "$ olcSmbK5PwdMustChange "
749 "$ olcSmbK5PwdCanChange "
750 ") )", Cft_Overlay, smbk5pwd_cfats },
756 * add here other functionalities; handle their initialization
757 * as appropriate in smbk5pwd_modules_init().
759 static slap_verbmasks smbk5pwd_modules[] = {
760 { BER_BVC( "krb5" ), SMBK5PWD_F_KRB5 },
761 { BER_BVC( "samba" ), SMBK5PWD_F_SAMBA },
762 { BER_BVC( "shadow" ), SMBK5PWD_F_SHADOW },
767 smbk5pwd_cf_func( ConfigArgs *c )
769 slap_overinst *on = (slap_overinst *)c->bi;
772 smbk5pwd_t *pi = on->on_bi.bi_private;
774 if ( c->op == SLAP_CONFIG_EMIT ) {
776 case PC_SMB_MUST_CHANGE:
778 c->value_int = pi->smb_must_change;
779 #else /* ! DO_SAMBA */
781 #endif /* ! DO_SAMBA */
784 case PC_SMB_CAN_CHANGE:
786 c->value_int = pi->smb_can_change;
787 #else /* ! DO_SAMBA */
789 #endif /* ! DO_SAMBA */
793 c->rvalue_vals = NULL;
795 mask_to_verbs( smbk5pwd_modules, pi->mode, &c->rvalue_vals );
796 if ( c->rvalue_vals == NULL ) {
808 } else if ( c->op == LDAP_MOD_DELETE ) {
810 case PC_SMB_MUST_CHANGE:
813 case PC_SMB_CAN_CHANGE:
823 i = verb_to_mask( c->line, smbk5pwd_modules );
824 pi->mode &= ~smbk5pwd_modules[i].mask;
836 case PC_SMB_MUST_CHANGE:
838 if ( c->value_int < 0 ) {
839 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
840 "<%s> invalid negative value \"%d\".",
841 c->log, c->argv[ 0 ], 0 );
844 pi->smb_must_change = c->value_int;
845 #else /* ! DO_SAMBA */
846 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
847 "<%s> only meaningful "
848 "when compiled with -DDO_SAMBA.\n",
849 c->log, c->argv[ 0 ], 0 );
851 #endif /* ! DO_SAMBA */
854 case PC_SMB_CAN_CHANGE:
856 if ( c->value_int < 0 ) {
857 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
858 "<%s> invalid negative value \"%d\".",
859 c->log, c->argv[ 0 ], 0 );
862 pi->smb_can_change = c->value_int;
863 #else /* ! DO_SAMBA */
864 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
865 "<%s> only meaningful "
866 "when compiled with -DDO_SAMBA.\n",
867 c->log, c->argv[ 0 ], 0 );
869 #endif /* ! DO_SAMBA */
872 case PC_SMB_ENABLE: {
873 slap_mask_t mode = pi->mode, m = 0;
875 rc = verbs_to_mask( c->argc, c->argv, smbk5pwd_modules, &m );
877 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
878 "<%s> unknown module \"%s\".\n",
879 c->log, c->argv[ 0 ], c->argv[ rc ] );
883 /* we can hijack the smbk5pwd_t structure because
884 * from within the configuration, this is the only
889 if ( SMBK5PWD_DO_KRB5( pi ) ) {
890 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
891 "<%s> module \"%s\" only allowed when compiled with -DDO_KRB5.\n",
892 c->log, c->argv[ 0 ], c->argv[ rc ] );
896 #endif /* ! DO_KRB5 */
899 if ( SMBK5PWD_DO_SAMBA( pi ) ) {
900 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
901 "<%s> module \"%s\" only allowed when compiled with -DDO_SAMBA.\n",
902 c->log, c->argv[ 0 ], c->argv[ rc ] );
906 #endif /* ! DO_SAMBA */
909 if ( SMBK5PWD_DO_SHADOW( pi ) ) {
910 Debug( LDAP_DEBUG_ANY, "%s: smbk5pwd: "
911 "<%s> module \"%s\" only allowed when compiled with -DDO_SHADOW.\n",
912 c->log, c->argv[ 0 ], c->argv[ rc ] );
916 #endif /* ! DO_SHADOW */
919 BackendDB db = *c->be;
921 /* Re-initialize the module, because
922 * the configuration might have changed */
923 db.bd_info = (BackendInfo *)on;
924 rc = smbk5pwd_modules_init( pi );
941 smbk5pwd_modules_init( smbk5pwd_t *pi )
945 AttributeDescription **adp;
949 { "krb5Key", &ad_krb5Key },
950 { "krb5KeyVersionNumber", &ad_krb5KeyVersionNumber },
951 { "krb5PrincipalName", &ad_krb5PrincipalName },
952 { "krb5ValidEnd", &ad_krb5ValidEnd },
958 { "sambaLMPassword", &ad_sambaLMPassword },
959 { "sambaNTPassword", &ad_sambaNTPassword },
960 { "sambaPwdLastSet", &ad_sambaPwdLastSet },
961 { "sambaPwdMustChange", &ad_sambaPwdMustChange },
962 { "sambaPwdCanChange", &ad_sambaPwdCanChange },
965 #endif /* DO_SAMBA */
968 { "shadowLastChange", &ad_shadowLastChange },
971 #endif /* DO_SHADOW */
974 /* this is to silence the unused var warning */
975 dummy_ad.name = NULL;
978 if ( SMBK5PWD_DO_KRB5( pi ) && oc_krb5KDCEntry == NULL ) {
980 extern HDB *_kadm5_s_get_db(void *);
984 /* Make sure all of our necessary schema items are loaded */
985 oc_krb5KDCEntry = oc_find( "krb5KDCEntry" );
986 if ( !oc_krb5KDCEntry ) {
987 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
988 "unable to find \"krb5KDCEntry\" objectClass.\n",
993 for ( i = 0; krb5_ad[ i ].name != NULL; i++ ) {
996 *(krb5_ad[ i ].adp) = NULL;
998 rc = slap_str2ad( krb5_ad[ i ].name, krb5_ad[ i ].adp, &text );
999 if ( rc != LDAP_SUCCESS ) {
1000 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
1001 "unable to find \"%s\" attributeType: %s (%d).\n",
1002 krb5_ad[ i ].name, text, rc );
1003 oc_krb5KDCEntry = NULL;
1008 /* Initialize Kerberos context */
1009 ret = krb5_init_context(&context);
1011 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
1012 "unable to initialize krb5 context (%d).\n",
1014 oc_krb5KDCEntry = NULL;
1018 ret = kadm5_s_init_with_password_ctx( context,
1019 KADM5_ADMIN_SERVICE,
1021 KADM5_ADMIN_SERVICE,
1022 &conf, 0, 0, &kadm_context );
1024 char *err_str, *err_msg = "<unknown error>";
1025 err_str = krb5_get_error_string( context );
1027 err_msg = (char *)krb5_get_err_text( context, ret );
1028 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
1029 "unable to initialize krb5 admin context: %s (%d).\n",
1030 err_str ? err_str : err_msg, ret, 0 );
1032 krb5_free_error_string( context, err_str );
1033 krb5_free_context( context );
1034 oc_krb5KDCEntry = NULL;
1038 db = _kadm5_s_get_db( kadm_context );
1040 #endif /* DO_KRB5 */
1043 if ( SMBK5PWD_DO_SAMBA( pi ) && oc_sambaSamAccount == NULL ) {
1046 oc_sambaSamAccount = oc_find( "sambaSamAccount" );
1047 if ( !oc_sambaSamAccount ) {
1048 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
1049 "unable to find \"sambaSamAccount\" objectClass.\n",
1054 for ( i = 0; samba_ad[ i ].name != NULL; i++ ) {
1057 *(samba_ad[ i ].adp) = NULL;
1059 rc = slap_str2ad( samba_ad[ i ].name, samba_ad[ i ].adp, &text );
1060 if ( rc != LDAP_SUCCESS ) {
1061 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
1062 "unable to find \"%s\" attributeType: %s (%d).\n",
1063 samba_ad[ i ].name, text, rc );
1064 oc_sambaSamAccount = NULL;
1069 #endif /* DO_SAMBA */
1072 if ( SMBK5PWD_DO_SHADOW( pi ) && oc_shadowAccount == NULL ) {
1075 oc_shadowAccount = oc_find( "shadowAccount" );
1076 if ( !oc_shadowAccount ) {
1077 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
1078 "unable to find \"shadowAccount\" objectClass.\n",
1083 for ( i = 0; shadow_ad[ i ].name != NULL; i++ ) {
1086 *(shadow_ad[ i ].adp) = NULL;
1088 rc = slap_str2ad( shadow_ad[ i ].name, shadow_ad[ i ].adp, &text );
1089 if ( rc != LDAP_SUCCESS ) {
1090 Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
1091 "unable to find \"%s\" attributeType: %s (%d).\n",
1092 shadow_ad[ i ].name, text, rc );
1093 oc_shadowAccount = NULL;
1098 #endif /* DO_SHADOW */
1104 smbk5pwd_db_init(BackendDB *be, ConfigReply *cr)
1106 slap_overinst *on = (slap_overinst *)be->bd_info;
1109 pi = ch_calloc( 1, sizeof( smbk5pwd_t ) );
1113 on->on_bi.bi_private = (void *)pi;
1119 smbk5pwd_db_open(BackendDB *be, ConfigReply *cr)
1121 slap_overinst *on = (slap_overinst *)be->bd_info;
1122 smbk5pwd_t *pi = (smbk5pwd_t *)on->on_bi.bi_private;
1126 if ( pi->mode == 0 ) {
1127 pi->mode = SMBK5PWD_F_ALL;
1130 rc = smbk5pwd_modules_init( pi );
1139 smbk5pwd_db_destroy(BackendDB *be, ConfigReply *cr)
1141 slap_overinst *on = (slap_overinst *)be->bd_info;
1142 smbk5pwd_t *pi = (smbk5pwd_t *)on->on_bi.bi_private;
1152 smbk5pwd_initialize(void)
1156 smbk5pwd.on_bi.bi_type = "smbk5pwd";
1158 smbk5pwd.on_bi.bi_db_init = smbk5pwd_db_init;
1159 smbk5pwd.on_bi.bi_db_open = smbk5pwd_db_open;
1160 smbk5pwd.on_bi.bi_db_destroy = smbk5pwd_db_destroy;
1162 smbk5pwd.on_bi.bi_extended = smbk5pwd_exop_passwd;
1165 smbk5pwd.on_bi.bi_op_bind = smbk5pwd_op_bind;
1167 lutil_passwd_add( (struct berval *)&k5key_scheme, k5key_chk, k5key_hash );
1170 smbk5pwd.on_bi.bi_cf_ocs = smbk5pwd_cfocs;
1172 rc = config_register_schema( smbk5pwd_cfats, smbk5pwd_cfocs );
1177 return overlay_register( &smbk5pwd );
1180 #if SLAPD_OVER_SMBK5PWD == SLAPD_MOD_DYNAMIC
1181 int init_module(int argc, char *argv[]) {
1182 return smbk5pwd_initialize();
1186 #endif /* defined(SLAPD_OVER_SMBK5PWD) */