/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 2004-2005 The OpenLDAP Foundation.
+ * Copyright 2004-2008 The OpenLDAP Foundation.
* Portions Copyright 2004-2005 Howard Chu, Symas Corporation.
* Portions Copyright 2004 Hewlett-Packard Company.
* All rights reserved.
#include <ldap.h>
#include "lutil.h"
#include "slap.h"
-#if SLAPD_MODULES
+#ifdef SLAPD_MODULES
#define LIBLTDL_DLL_IMPORT /* Win32: don't re-export libltdl's symbols */
#include <ltdl.h>
#endif
#include <ac/time.h>
#include <ac/string.h>
#include <ac/ctype.h>
+#include "config.h"
#ifndef MODULE_NAME_SZ
#define MODULE_NAME_SZ 256
* used by all instances
*/
typedef struct pw_conn {
- int restricted; /* TRUE if connection is restricted */
+ struct berval dn; /* DN of restricted user */
} pw_conn;
static pw_conn *pwcons;
static int ppolicy_cid;
+static int ov_count;
typedef struct pass_policy {
AttributeDescription *ad; /* attribute to which the policy applies */
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
"SINGLE-VALUE "
#if 0
- /* Not until MANAGEDIT control is released */
+ /* Not until Relax control is released */
"NO-USER-MODIFICATION "
#endif
"USAGE directoryOperation )",
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
"SINGLE-VALUE "
#if 0
- /* Not until MANAGEDIT control is released */
+ /* Not until Relax control is released */
"NO-USER-MODIFICATION "
#endif
"USAGE directoryOperation )",
static ldap_pvt_thread_mutex_t chk_syntax_mutex;
+enum {
+ PPOLICY_DEFAULT = 1,
+ PPOLICY_HASH_CLEARTEXT,
+ PPOLICY_USE_LOCKOUT
+};
+
+static ConfigDriver ppolicy_cf_default;
+
+static ConfigTable ppolicycfg[] = {
+ { "ppolicy_default", "policyDN", 2, 2, 0,
+ ARG_DN|ARG_QUOTE|ARG_MAGIC|PPOLICY_DEFAULT, ppolicy_cf_default,
+ "( OLcfgOvAt:12.1 NAME 'olcPPolicyDefault' "
+ "DESC 'DN of a pwdPolicy object for uncustomized objects' "
+ "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
+ { "ppolicy_hash_cleartext", "on|off", 1, 2, 0,
+ ARG_ON_OFF|ARG_OFFSET|PPOLICY_HASH_CLEARTEXT,
+ (void *)offsetof(pp_info,hash_passwords),
+ "( OLcfgOvAt:12.2 NAME 'olcPPolicyHashCleartext' "
+ "DESC 'Hash passwords on add or modify' "
+ "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
+ { "ppolicy_use_lockout", "on|off", 1, 2, 0,
+ ARG_ON_OFF|ARG_OFFSET|PPOLICY_USE_LOCKOUT,
+ (void *)offsetof(pp_info,use_lockout),
+ "( OLcfgOvAt:12.3 NAME 'olcPPolicyUseLockout' "
+ "DESC 'Warn clients with AccountLocked' "
+ "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
+ { NULL, NULL, 0, 0, 0, ARG_IGNORED }
+};
+
+static ConfigOCs ppolicyocs[] = {
+ { "( OLcfgOvOc:12.1 "
+ "NAME 'olcPPolicyConfig' "
+ "DESC 'Password Policy configuration' "
+ "SUP olcOverlayConfig "
+ "MAY ( olcPPolicyDefault $ olcPPolicyHashCleartext $ "
+ "olcPPolicyUseLockout ) )",
+ Cft_Overlay, ppolicycfg },
+ { NULL, 0, NULL }
+};
+
+static int
+ppolicy_cf_default( ConfigArgs *c )
+{
+ slap_overinst *on = (slap_overinst *)c->bi;
+ pp_info *pi = (pp_info *)on->on_bi.bi_private;
+ int rc = ARG_BAD_CONF;
+
+ assert ( c->type == PPOLICY_DEFAULT );
+ Debug(LDAP_DEBUG_TRACE, "==> ppolicy_cf_default\n", 0, 0, 0);
+
+ switch ( c->op ) {
+ case SLAP_CONFIG_EMIT:
+ Debug(LDAP_DEBUG_TRACE, "==> ppolicy_cf_default emit\n", 0, 0, 0);
+ rc = 0;
+ if ( !BER_BVISEMPTY( &pi->def_policy )) {
+ rc = value_add_one( &c->rvalue_vals,
+ &pi->def_policy );
+ if ( rc ) return rc;
+ rc = value_add_one( &c->rvalue_nvals,
+ &pi->def_policy );
+ }
+ break;
+ case LDAP_MOD_DELETE:
+ Debug(LDAP_DEBUG_TRACE, "==> ppolicy_cf_default delete\n", 0, 0, 0);
+ if ( pi->def_policy.bv_val ) {
+ ber_memfree ( pi->def_policy.bv_val );
+ pi->def_policy.bv_val = NULL;
+ }
+ pi->def_policy.bv_len = 0;
+ rc = 0;
+ break;
+ case SLAP_CONFIG_ADD:
+ /* fallthrough to LDAP_MOD_ADD */
+ case LDAP_MOD_ADD:
+ Debug(LDAP_DEBUG_TRACE, "==> ppolicy_cf_default add\n", 0, 0, 0);
+ if ( pi->def_policy.bv_val ) {
+ ber_memfree ( pi->def_policy.bv_val );
+ }
+ pi->def_policy = c->value_ndn;
+ ber_memfree( c->value_dn.bv_val );
+ BER_BVZERO( &c->value_dn );
+ BER_BVZERO( &c->value_ndn );
+ rc = 0;
+ break;
+ default:
+ abort ();
+ }
+
+ return rc;
+}
+
static time_t
parse_time( char *atm )
{
return 0;
}
-#define PPOLICY_WARNING 0xa0L
-#define PPOLICY_ERROR 0xa1L
+/* IMPLICIT TAGS, all context-specific */
+#define PPOLICY_WARNING 0xa0L /* constructed + 0 */
+#define PPOLICY_ERROR 0x81L /* primitive + 1 */
-#define PPOLICY_EXPIRE 0xa0L
-#define PPOLICY_GRACE 0xa1L
+#define PPOLICY_EXPIRE 0x80L /* primitive + 0 */
+#define PPOLICY_GRACE 0x81L /* primitive + 1 */
+
+static const char ppolicy_ctrl_oid[] = LDAP_CONTROL_PASSWORDPOLICYRESPONSE;
static LDAPControl *
-create_passcontrol( int exptime, int grace, LDAPPasswordPolicyError err )
+create_passcontrol( Operation *op, int exptime, int grace, LDAPPasswordPolicyError err )
{
char berbuf[LBER_ELEMENT_SIZEOF], bb2[LBER_ELEMENT_SIZEOF];
BerElement *ber = (BerElement *)berbuf, *b2 = (BerElement *)bb2;
- LDAPControl *c;
+ LDAPControl c = { 0 }, *cp;
struct berval bv;
- if ((c = ch_calloc( sizeof( LDAPControl ), 1 )) == NULL) return NULL;
- c->ldctl_oid = LDAP_CONTROL_PASSWORDPOLICYRESPONSE;
- c->ldctl_iscritical = 0;
- c->ldctl_value.bv_val = NULL;
- c->ldctl_value.bv_len = 0;
+ BER_BVZERO( &c.ldctl_value );
ber_init2( ber, NULL, LBER_USE_DER );
- ber_printf(ber, "{" /*}*/ );
+ ber_printf( ber, "{" /*}*/ );
- if (exptime >= 0) {
+ if ( exptime >= 0 ) {
ber_init2( b2, NULL, LBER_USE_DER );
ber_printf( b2, "ti", PPOLICY_EXPIRE, exptime );
ber_flatten2( b2, &bv, 1 );
+ (void)ber_free_buf(b2);
ber_printf( ber, "tO", PPOLICY_WARNING, &bv );
ch_free( bv.bv_val );
- } else if (grace > 0) {
+ } else if ( grace > 0 ) {
ber_init2( b2, NULL, LBER_USE_DER );
ber_printf( b2, "ti", PPOLICY_GRACE, grace );
ber_flatten2( b2, &bv, 1 );
+ (void)ber_free_buf(b2);
ber_printf( ber, "tO", PPOLICY_WARNING, &bv );
ch_free( bv.bv_val );
}
}
ber_printf( ber, /*{*/ "N}" );
- if (ber_flatten2( ber, &(c->ldctl_value), 1 ) == LBER_DEFAULT) {
- ch_free(c);
- (void)ber_free_buf(ber);
+ if (ber_flatten2( ber, &c.ldctl_value, 0 ) == -1) {
return NULL;
}
+ cp = op->o_tmpalloc( sizeof( LDAPControl ) + c.ldctl_value.bv_len, op->o_tmpmemctx );
+ cp->ldctl_oid = (char *)ppolicy_ctrl_oid;
+ cp->ldctl_iscritical = 0;
+ cp->ldctl_value.bv_val = (char *)&cp[1];
+ cp->ldctl_value.bv_len = c.ldctl_value.bv_len;
+ AC_MEMCPY( cp->ldctl_value.bv_val, c.ldctl_value.bv_val, c.ldctl_value.bv_len );
(void)ber_free_buf(ber);
- return c;
+
+ return cp;
+}
+
+static LDAPControl **
+add_passcontrol( Operation *op, SlapReply *rs, LDAPControl *ctrl )
+{
+ LDAPControl **ctrls, **oldctrls = rs->sr_ctrls;
+ int n;
+
+ n = 0;
+ if ( oldctrls ) {
+ for ( ; oldctrls[n]; n++ )
+ ;
+ }
+ n += 2;
+
+ ctrls = op->o_tmpcalloc( sizeof( LDAPControl * ), n, op->o_tmpmemctx );
+
+ n = 0;
+ if ( oldctrls ) {
+ for ( ; oldctrls[n]; n++ ) {
+ ctrls[n] = oldctrls[n];
+ }
+ }
+ ctrls[n] = ctrl;
+ ctrls[n+1] = NULL;
+
+ rs->sr_ctrls = ctrls;
+
+ return oldctrls;
}
static void
memset( pp, 0, sizeof(PassPolicy) );
+ pp->ad = slap_schema.si_ad_userPassword;
+
/* Users can change their own password by default */
pp->pwdAllowUserChange = 1;
#if 0 /* Only worry about userPassword for now */
if ((a = attr_find( pe->e_attrs, ad_pwdAttribute )))
slap_bv2ad( &a->a_vals[0], &pp->ad, &text );
-#else
- pp->ad = slap_schema.si_ad_userPassword;
#endif
if ( ( a = attr_find( pe->e_attrs, ad_pwdMinAge ) )
}
if ((a = attr_find( pe->e_attrs, ad_pwdLockout )))
- pp->pwdLockout = !strcmp( a->a_nvals[0].bv_val, "TRUE" );
+ pp->pwdLockout = bvmatch( &a->a_nvals[0], &slap_true_bv );
if ((a = attr_find( pe->e_attrs, ad_pwdMustChange )))
- pp->pwdMustChange = !strcmp( a->a_nvals[0].bv_val, "TRUE" );
+ pp->pwdMustChange = bvmatch( &a->a_nvals[0], &slap_true_bv );
if ((a = attr_find( pe->e_attrs, ad_pwdAllowUserChange )))
- pp->pwdAllowUserChange = !strcmp( a->a_nvals[0].bv_val, "TRUE" );
+ pp->pwdAllowUserChange = bvmatch( &a->a_nvals[0], &slap_true_bv );
if ((a = attr_find( pe->e_attrs, ad_pwdSafeModify )))
- pp->pwdSafeModify = !strcmp( a->a_nvals[0].bv_val, "TRUE" );
+ pp->pwdSafeModify = bvmatch( &a->a_nvals[0], &slap_true_bv );
op->o_bd->bd_info = (BackendInfo *)on->on_info;
be_entry_release_r( op, pe );
return;
defaultpol:
- Debug( LDAP_DEBUG_ANY,
+ Debug( LDAP_DEBUG_TRACE,
"ppolicy_get: using default policy\n", 0, 0, 0 );
return;
}
if (cred->bv_val[e]) {
int rc;
rc = lutil_passwd_scheme( cred->bv_val );
- if (rc && sch) {
- sch->bv_val = cred->bv_val;
- sch->bv_len = e;
+ if (rc) {
+ if (sch) {
+ sch->bv_val = cred->bv_val;
+ sch->bv_len = e;
+ }
return LDAP_SUCCESS;
}
}
rc = LDAP_SUCCESS;
if (pp->pwdCheckModule[0]) {
-#if SLAPD_MODULES
+#ifdef SLAPD_MODULES
lt_dlhandle mod;
const char *err;
ldap_pvt_thread_mutex_lock( &chk_syntax_mutex );
ok = prog( cred->bv_val, &txt, e );
ldap_pvt_thread_mutex_unlock( &chk_syntax_mutex );
- if (txt) {
+ if (ok != LDAP_SUCCESS) {
Debug(LDAP_DEBUG_ANY,
"check_password_quality: module error: (%s) %s.[%d]\n",
- pp->pwdCheckModule, txt, ok );
+ pp->pwdCheckModule, txt ? txt : "", ok );
free(txt);
- } else
- ok = LDAP_SUCCESS;
+ }
}
lt_dlclose( mod );
{
char *ptr;
struct berval nv, npw;
- int i, j;
+ ber_len_t i, j;
assert (bv && (bv->bv_len > 0) && (bv->bv_val) && oldtime && oldpw );
- if ( oid ) *oid = 0;
+ if ( oid ) {
+ *oid = 0;
+ }
*oldtime = (time_t)-1;
- oldpw->bv_val = NULL;
- oldpw->bv_len = 0;
+ BER_BVZERO( oldpw );
ber_dupbv( &nv, bv );
/* first get the time field */
- for(i=0; (i < nv.bv_len) && (nv.bv_val[i] != '#'); i++);
- if ( i == nv.bv_len) goto exit_failure; /* couldn't locate the '#' separator */
+ for ( i = 0; (i < nv.bv_len) && (nv.bv_val[i] != '#'); i++ )
+ ;
+ if ( i == nv.bv_len ) {
+ goto exit_failure; /* couldn't locate the '#' separator */
+ }
nv.bv_val[i++] = '\0'; /* terminate the string & move to next field */
ptr = nv.bv_val;
*oldtime = parse_time( ptr );
- if (*oldtime == (time_t)-1) goto exit_failure;
+ if (*oldtime == (time_t)-1) {
+ goto exit_failure;
+ }
/* get the OID field */
- for(ptr = &(nv.bv_val[i]);(i < nv.bv_len) && (nv.bv_val[i] != '#'); i++);
- if ( i == nv.bv_len) goto exit_failure; /* couldn't locate the '#' separator */
+ for (ptr = &(nv.bv_val[i]); (i < nv.bv_len) && (nv.bv_val[i] != '#'); i++ )
+ ;
+ if ( i == nv.bv_len ) {
+ goto exit_failure; /* couldn't locate the '#' separator */
+ }
nv.bv_val[i++] = '\0'; /* terminate the string & move to next field */
- if ( oid ) *oid = ber_strdup( ptr );
+ if ( oid ) {
+ *oid = ber_strdup( ptr );
+ }
/* get the length field */
- for(ptr = &(nv.bv_val[i]);(i < nv.bv_len) && (nv.bv_val[i] != '#'); i++);
- if ( i == nv.bv_len) goto exit_failure; /* couldn't locate the '#' separator */
+ for ( ptr = &(nv.bv_val[i]); (i < nv.bv_len) && (nv.bv_val[i] != '#'); i++ )
+ ;
+ if ( i == nv.bv_len ) {
+ goto exit_failure; /* couldn't locate the '#' separator */
+ }
nv.bv_val[i++] = '\0'; /* terminate the string & move to next field */
oldpw->bv_len = strtol( ptr, NULL, 10 );
- if (errno == ERANGE) goto exit_failure;
+ if (errno == ERANGE) {
+ goto exit_failure;
+ }
/* lastly, get the octets of the string */
- for(j=i, ptr = &(nv.bv_val[i]);i < nv.bv_len; i++);
- if (i-j != oldpw->bv_len) goto exit_failure; /* length is wrong */
+ for ( j = i, ptr = &(nv.bv_val[i]); i < nv.bv_len; i++ )
+ ;
+ if ( i - j != oldpw->bv_len) {
+ goto exit_failure; /* length is wrong */
+ }
npw.bv_val = ptr;
npw.bv_len = oldpw->bv_len;
ber_dupbv( oldpw, &npw );
+ ber_memfree( nv.bv_val );
return LDAP_SUCCESS;
-exit_failure:
- if (oid && *oid) { ber_memfree(*oid); *oid = NULL; }
- if (oldpw->bv_val) {
- ber_memfree( oldpw->bv_val); oldpw->bv_val = NULL;
- oldpw->bv_len = 0;
+
+exit_failure:;
+ if ( oid && *oid ) {
+ ber_memfree(*oid);
+ *oid = NULL;
}
- ber_memfree(nv.bv_val);
+ if ( oldpw->bv_val ) {
+ ber_memfree( oldpw->bv_val);
+ BER_BVZERO( oldpw );
+ }
+ ber_memfree( nv.bv_val );
+
return LDAP_OTHER;
}
typedef struct ppbind {
slap_overinst *on;
int send_ctrl;
+ LDAPControl **oldctrls;
Modifications *mod;
LDAPPasswordPolicyError pErr;
PassPolicy pp;
} ppbind;
+static void
+ctrls_cleanup( Operation *op, SlapReply *rs, LDAPControl **oldctrls )
+{
+ int n;
+
+ assert( rs->sr_ctrls != NULL );
+ assert( rs->sr_ctrls[0] != NULL );
+
+ for ( n = 0; rs->sr_ctrls[n]; n++ ) {
+ if ( rs->sr_ctrls[n]->ldctl_oid == ppolicy_ctrl_oid ) {
+ op->o_tmpfree( rs->sr_ctrls[n], op->o_tmpmemctx );
+ rs->sr_ctrls[n] = (LDAPControl *)(-1);
+ break;
+ }
+ }
+
+ if ( rs->sr_ctrls[n] == NULL ) {
+ /* missed? */
+ }
+
+ op->o_tmpfree( rs->sr_ctrls, op->o_tmpmemctx );
+
+ rs->sr_ctrls = oldctrls;
+}
+
static int
-ppolicy_bind_resp( Operation *op, SlapReply *rs )
+ppolicy_ctrls_cleanup( Operation *op, SlapReply *rs )
+{
+ ppbind *ppb = op->o_callback->sc_private;
+ if ( ppb->send_ctrl ) {
+ ctrls_cleanup( op, rs, ppb->oldctrls );
+ }
+ return SLAP_CB_CONTINUE;
+}
+
+static int
+ppolicy_bind_response( Operation *op, SlapReply *rs )
{
ppbind *ppb = op->o_callback->sc_private;
slap_overinst *on = ppb->on;
m->sml_flags = 0;
m->sml_type = ad_pwdFailureTime->ad_cname;
m->sml_desc = ad_pwdFailureTime;
+ m->sml_numvals = 1;
m->sml_values = ch_calloc( sizeof(struct berval), 2 );
+ m->sml_nvalues = ch_calloc( sizeof(struct berval), 2 );
ber_dupbv( &m->sml_values[0], ×tamp );
+ ber_dupbv( &m->sml_nvalues[0], ×tamp );
m->sml_next = mod;
mod = m;
m->sml_flags = 0;
m->sml_type = ad_pwdAccountLockedTime->ad_cname;
m->sml_desc = ad_pwdAccountLockedTime;
+ m->sml_numvals = 1;
m->sml_values = ch_calloc( sizeof(struct berval), 2 );
+ m->sml_nvalues = ch_calloc( sizeof(struct berval), 2 );
ber_dupbv( &m->sml_values[0], ×tamp );
+ ber_dupbv( &m->sml_nvalues[0], ×tamp );
m->sml_next = mod;
mod = m;
}
*/
if ( ppb->pp.pwdMustChange &&
(a = attr_find( e->e_attrs, ad_pwdReset )) &&
- !strcmp( a->a_nvals[0].bv_val, "TRUE" ) ) {
+ bvmatch( &a->a_nvals[0], &slap_true_bv ) )
+ {
/*
* need to inject client controls here to give
* more information. For the moment, we ensure
* that we are disallowed from doing anything
* other than change password.
*/
- pwcons[op->o_conn->c_conn_idx].restricted = 1;
+ ber_dupbv( &pwcons[op->o_conn->c_conn_idx].dn,
+ &op->o_conn->c_ndn );
ppb->pErr = PP_changeAfterReset;
* we now check whether the password has expired.
*
* We can skip this bit if passwords don't age in
- * the policy.
+ * the policy. Also, if there was no pwdChangedTime
+ * attribute in the entry, the password never expires.
*/
if (ppb->pp.pwdMaxAge == 0) goto grace;
- if (pwtime == (time_t)-1) {
- /*
- * Hmm. No password changed time on the
- * entry. This is odd - it should have
- * been provided when the attribute was added.
- *
- * However, it's possible that it could be
- * missing if the DIT was established via
- * an import process.
- */
- Debug( LDAP_DEBUG_ANY,
- "ppolicy_bind: Entry %s does not have valid pwdChangedTime attribute - assuming password expired\n",
- e->e_name.bv_val, 0, 0);
-
- pwExpired = 1;
- } else {
+ if (pwtime != (time_t)-1) {
/*
* Check: was the last change time of
* the password older than the maximum age
m->sml_flags = 0;
m->sml_type = ad_pwdGraceUseTime->ad_cname;
m->sml_desc = ad_pwdGraceUseTime;
+ m->sml_numvals = 1;
m->sml_values = ch_calloc( sizeof(struct berval), 2 );
+ m->sml_nvalues = ch_calloc( sizeof(struct berval), 2 );
ber_dupbv( &m->sml_values[0], ×tamp );
+ ber_dupbv( &m->sml_nvalues[0], ×tamp );
m->sml_next = mod;
mod = m;
}
if ( ppb->send_ctrl ) {
- LDAPControl **ctrls = NULL;
+ LDAPControl *ctrl = NULL;
pp_info *pi = on->on_bi.bi_private;
/* Do we really want to tell that the account is locked? */
if ( ppb->pErr == PP_accountLocked && !pi->use_lockout ) {
ppb->pErr = PP_noError;
}
- ctrls = ch_calloc( sizeof( LDAPControl *) , 2 );
- ctrls[0] = create_passcontrol( warn, ngut, ppb->pErr );
- ctrls[1] = NULL;
- rs->sr_ctrls = ctrls;
+ ctrl = create_passcontrol( op, warn, ngut, ppb->pErr );
+ ppb->oldctrls = add_passcontrol( op, rs, ctrl );
+ op->o_callback->sc_cleanup = ppolicy_ctrls_cleanup;
}
op->o_bd->bd_info = bi;
return SLAP_CB_CONTINUE;
slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
/* Reset lockout status on all Bind requests */
- pwcons[op->o_conn->c_conn_idx].restricted = 0;
+ if ( !BER_BVISEMPTY( &pwcons[op->o_conn->c_conn_idx].dn )) {
+ ch_free( pwcons[op->o_conn->c_conn_idx].dn.bv_val );
+ BER_BVZERO( &pwcons[op->o_conn->c_conn_idx].dn );
+ }
/* Root bypasses policy */
if ( !be_isroot_dn( op->o_bd, &op->o_req_ndn )) {
/* Setup a callback so we can munge the result */
- cb->sc_response = ppolicy_bind_resp;
+ cb->sc_response = ppolicy_bind_response;
cb->sc_next = op->o_callback->sc_next;
cb->sc_private = ppb;
op->o_callback->sc_next = cb;
return SLAP_CB_CONTINUE;
}
-/* Reset the restricted flag for the next session on this connection */
+/* Reset the restricted info for the next session on this connection */
static int
ppolicy_connection_destroy( BackendDB *bd, Connection *conn )
{
- pwcons[conn->c_conn_idx].restricted = 0;
+ if ( !BER_BVISEMPTY( &pwcons[conn->c_conn_idx].dn )) {
+ ch_free( pwcons[conn->c_conn_idx].dn.bv_val );
+ BER_BVZERO( &pwcons[conn->c_conn_idx].dn );
+ }
return SLAP_CB_CONTINUE;
}
send_ctrl = 1;
}
- if ( op->o_conn && pwcons[op->o_conn->c_conn_idx].restricted ) {
+ if ( op->o_conn && !BER_BVISEMPTY( &pwcons[op->o_conn->c_conn_idx].dn )) {
+ LDAPControl **oldctrls;
+ /* if the current authcDN doesn't match the one we recorded,
+ * then an intervening Bind has succeeded and the restriction
+ * no longer applies. (ITS#4516)
+ */
+ if ( !dn_match( &op->o_conn->c_ndn,
+ &pwcons[op->o_conn->c_conn_idx].dn )) {
+ ch_free( pwcons[op->o_conn->c_conn_idx].dn.bv_val );
+ BER_BVZERO( &pwcons[op->o_conn->c_conn_idx].dn );
+ return SLAP_CB_CONTINUE;
+ }
+
Debug( LDAP_DEBUG_TRACE,
"connection restricted to password changing only\n", 0, 0, 0);
if ( send_ctrl ) {
- LDAPControl **ctrls = NULL;
-
- ctrls = ch_calloc( sizeof( LDAPControl *) , 2 );
- ctrls[0] = create_passcontrol( -1, -1, PP_changeAfterReset );
- ctrls[1] = NULL;
- rs->sr_ctrls = ctrls;
+ LDAPControl *ctrl = NULL;
+ ctrl = create_passcontrol( op, -1, -1, PP_changeAfterReset );
+ oldctrls = add_passcontrol( op, rs, ctrl );
}
op->o_bd->bd_info = (BackendInfo *)on->on_info;
send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
"Operations are restricted to bind/unbind/abandon/StartTLS/modify password" );
+ if ( send_ctrl ) {
+ ctrls_cleanup( op, rs, oldctrls );
+ }
return rs->sr_err;
}
if ((pa = attr_find( op->oq_add.rs_e->e_attrs,
slap_schema.si_ad_userPassword )))
{
+ assert( pa->a_vals != NULL );
+ assert( !BER_BVISNULL( &pa->a_vals[ 0 ] ) );
+
+ if ( !BER_BVISNULL( &pa->a_vals[ 1 ] ) ) {
+ send_ldap_error( op, rs, LDAP_CONSTRAINT_VIOLATION, "Password policy only allows one password value" );
+ return rs->sr_err;
+ }
+
/*
* new entry contains a password - if we're not the root user
* then we need to check that the password fits in with the
}
rc = check_password_quality( bv, &pp, &pErr, op->ora_e );
if (rc != LDAP_SUCCESS) {
+ LDAPControl **oldctrls = NULL;
op->o_bd->bd_info = (BackendInfo *)on->on_info;
if ( send_ctrl ) {
- LDAPControl **ctrls = NULL;
-
- ctrls = ch_calloc( sizeof( LDAPControl *) , 2 );
- ctrls[0] = create_passcontrol( -1, -1, pErr );
- ctrls[1] = NULL;
- rs->sr_ctrls = ctrls;
+ LDAPControl *ctrl = NULL;
+ ctrl = create_passcontrol( op, -1, -1, pErr );
+ oldctrls = add_passcontrol( op, rs, ctrl );
}
send_ldap_error( op, rs, rc, "Password fails quality checking policy" );
+ if ( send_ctrl ) {
+ ctrls_cleanup( op, rs, oldctrls );
+ }
return rs->sr_err;
}
}
timestamp.bv_len = sizeof(timebuf);
slap_timestamp( &now, ×tamp );
- attr_merge_one( op->ora_e, ad_pwdChangedTime, ×tamp, NULL );
+ attr_merge_one( op->ora_e, ad_pwdChangedTime, ×tamp, ×tamp );
}
}
return SLAP_CB_CONTINUE;
}
+static int
+ppolicy_mod_cb( Operation *op, SlapReply *rs )
+{
+ slap_callback *sc = op->o_callback;
+ op->o_callback = sc->sc_next;
+ if ( rs->sr_err == LDAP_SUCCESS ) {
+ ch_free( pwcons[op->o_conn->c_conn_idx].dn.bv_val );
+ BER_BVZERO( &pwcons[op->o_conn->c_conn_idx].dn );
+ }
+ op->o_tmpfree( sc, op->o_tmpmemctx );
+ return SLAP_CB_CONTINUE;
+}
+
static int
ppolicy_modify( Operation *op, SlapReply *rs )
{
struct berval newpw = BER_BVNULL, oldpw = BER_BVNULL,
*bv, cr[2];
LDAPPasswordPolicyError pErr = PP_noError;
+ LDAPControl *ctrl = NULL;
+ LDAPControl **oldctrls = NULL;
+ int is_pwdexop = 0;
op->o_bd->bd_info = (BackendInfo *)on->on_info;
rc = be_entry_get_rw( op, &op->o_req_ndn, NULL, NULL, 0, &e );
a_lock = attr_find( e->e_attrs, ad_pwdAccountLockedTime );
a_fail = attr_find( e->e_attrs, ad_pwdFailureTime );
- for( prev = &op->oq_modify.rs_modlist, ml = *prev; ml; ml = *prev ) {
+ for( prev = &op->orm_modlist, ml = *prev; ml; ml = *prev ) {
if ( ml->sml_desc == slap_schema.si_ad_userPassword )
got_pw = 1;
ml->sml_flags = SLAP_MOD_INTERNAL;
ml->sml_type.bv_val = NULL;
ml->sml_desc = ad_pwdGraceUseTime;
+ ml->sml_numvals = 0;
ml->sml_values = NULL;
ml->sml_nvalues = NULL;
ml->sml_next = NULL;
ml->sml_flags = SLAP_MOD_INTERNAL;
ml->sml_type.bv_val = NULL;
ml->sml_desc = ad_pwdAccountLockedTime;
+ ml->sml_numvals = 0;
ml->sml_values = NULL;
ml->sml_nvalues = NULL;
ml->sml_next = NULL;
ml->sml_flags = SLAP_MOD_INTERNAL;
ml->sml_type.bv_val = NULL;
ml->sml_desc = ad_pwdFailureTime;
+ ml->sml_numvals = 0;
ml->sml_values = NULL;
ml->sml_nvalues = NULL;
ml->sml_next = NULL;
slap_callback *sc;
for ( sc = op->o_callback; sc; sc=sc->sc_next ) {
- if ( sc->sc_response == slap_replog_cb &&
+ if ( sc->sc_response == slap_null_cb &&
sc->sc_private ) {
req_pwdexop_s *qpw = sc->sc_private;
newpw = qpw->rs_new;
oldpw = qpw->rs_old;
+ is_pwdexop = 1;
break;
}
}
ppolicy_get( op, e, &pp );
- for ( ml = op->oq_modify.rs_modlist,
+ for ( ml = op->orm_modlist,
pwmod = 0, mod_pw_only = 1,
deladd = 0, delmod = NULL,
addmod = NULL,
pwmod = 1;
pwmop = ml->sml_op;
if ((deladd == 0) && (ml->sml_op == LDAP_MOD_DELETE) &&
- (ml->sml_values) && (ml->sml_values[0].bv_val != NULL)) {
+ (ml->sml_values) && !BER_BVISNULL( &ml->sml_values[0] ))
+ {
deladd = 1;
delmod = ml;
}
- if ((deladd == 1) && ((ml->sml_op == LDAP_MOD_ADD) ||
- (ml->sml_op == LDAP_MOD_REPLACE)))
- deladd = 2;
-
if ((ml->sml_op == LDAP_MOD_ADD) ||
(ml->sml_op == LDAP_MOD_REPLACE))
- addmod = ml;
- } else if (! is_at_operational( ml->sml_desc->ad_type )) {
+ {
+ if ( ml->sml_values && !BER_BVISNULL( &ml->sml_values[0] )) {
+ if ( deladd == 1 )
+ deladd = 2;
+
+ /* FIXME: there's no easy way to ensure
+ * that add does not cause multiple
+ * userPassword values; one way (that
+ * would be consistent with the single
+ * password constraint) would be to turn
+ * add into replace); another would be
+ * to disallow add.
+ *
+ * Let's check at least that a single value
+ * is being added
+ */
+ if ( addmod || !BER_BVISNULL( &ml->sml_values[ 1 ] ) ) {
+ rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
+ rs->sr_text = "Password policy only allows one password value";
+ goto return_results;
+ }
+
+ addmod = ml;
+ } else {
+ /* replace can have no values, add cannot */
+ assert( ml->sml_op == LDAP_MOD_REPLACE );
+ }
+ }
+
+ } else if ( !(ml->sml_flags & SLAP_MOD_INTERNAL) && !is_at_operational( ml->sml_desc->ad_type ) ) {
mod_pw_only = 0;
/* modifying something other than password */
}
}
}
- if (pwcons[op->o_conn->c_conn_idx].restricted && !mod_pw_only) {
- Debug( LDAP_DEBUG_TRACE,
- "connection restricted to password changing only\n", 0, 0, 0 );
- rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
- rs->sr_text = "Operations are restricted to bind/unbind/abandon/StartTLS/modify password";
- pErr = PP_changeAfterReset;
- goto return_results;
+ if (!BER_BVISEMPTY( &pwcons[op->o_conn->c_conn_idx].dn ) && !mod_pw_only ) {
+ if ( dn_match( &op->o_conn->c_ndn,
+ &pwcons[op->o_conn->c_conn_idx].dn )) {
+ Debug( LDAP_DEBUG_TRACE,
+ "connection restricted to password changing only\n", 0, 0, 0 );
+ rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
+ rs->sr_text = "Operations are restricted to bind/unbind/abandon/StartTLS/modify password";
+ pErr = PP_changeAfterReset;
+ goto return_results;
+ } else {
+ ch_free( pwcons[op->o_conn->c_conn_idx].dn.bv_val );
+ BER_BVZERO( &pwcons[op->o_conn->c_conn_idx].dn );
+ }
}
/*
* if we have a "safe password modify policy", then we need to check if we're doing
* a delete (with the old password), followed by an add (with the new password).
*
- * If we don't have this, then we fail with an error. We also skip all the checks if
+ * If we got just a delete with nothing else, just let it go. We also skip all the checks if
* the root user is bound. Root can do anything, including avoid the policies.
*/
if (!pwmod) goto do_modify;
- /*
- * Did we get a valid add mod?
- */
-
- if (!addmod) {
- rs->sr_err = LDAP_OTHER;
- rs->sr_text = "Internal Error";
- Debug( LDAP_DEBUG_TRACE,
- "cannot locate modification supplying new password\n", 0, 0, 0 );
- goto return_results;
- }
-
/*
* Build the password history list in ascending time order
* We need this, even if the user is root, in order to maintain
* the pwdHistory operational attributes properly.
*/
- if (pp.pwdInHistory > 0 && (ha = attr_find( e->e_attrs, ad_pwdHistory ))) {
+ if (addmod && pp.pwdInHistory > 0 && (ha = attr_find( e->e_attrs, ad_pwdHistory ))) {
struct berval oldpw;
time_t oldtime;
if (be_isroot( op )) goto do_modify;
+ if (!pp.pwdAllowUserChange) {
+ rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
+ rs->sr_text = "User alteration of password is not allowed";
+ pErr = PP_passwordModNotAllowed;
+ goto return_results;
+ }
+
+ /* Just deleting? */
+ if (!addmod) {
+ /* skip everything else */
+ pwmod = 0;
+ goto do_modify;
+ }
+
/* This is a pwdModify exop that provided the old pw.
* We need to create a Delete mod for this old pw and
* let the matching value get found later
*/
if (pp.pwdSafeModify && oldpw.bv_val ) {
- ml = (Modifications *) ch_malloc( sizeof( Modifications ) );
+ ml = (Modifications *)ch_calloc( sizeof( Modifications ), 1 );
ml->sml_op = LDAP_MOD_DELETE;
ml->sml_flags = SLAP_MOD_INTERNAL;
ml->sml_desc = pp.ad;
ml->sml_type = pp.ad->ad_cname;
+ ml->sml_numvals = 1;
ml->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
ber_dupbv( &ml->sml_values[0], &oldpw );
- ml->sml_values[1].bv_len = 0;
- ml->sml_values[1].bv_val = NULL;
- ml->sml_nvalues = NULL;
+ BER_BVZERO( &ml->sml_values[1] );
ml->sml_next = op->orm_modlist;
op->orm_modlist = ml;
delmod = ml;
goto return_results;
}
- if (!pp.pwdAllowUserChange) {
- rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
- rs->sr_text = "User alteration of password is not allowed";
- pErr = PP_passwordModNotAllowed;
- goto return_results;
- }
-
- if (pp.pwdMinAge > 0) {
+ /* Check age, but only if pwdReset is not TRUE */
+ pa = attr_find( e->e_attrs, ad_pwdReset );
+ if ((!pa || !bvmatch( &pa->a_nvals[0], &slap_true_bv )) &&
+ pp.pwdMinAge > 0) {
time_t pwtime = (time_t)-1, now;
int age;
* replace the delete value with the (possibly hashed)
* value which is currently in the password.
*/
- for(i=0; delmod->sml_values[i].bv_val; i++) {
- free(delmod->sml_values[i].bv_val);
- delmod->sml_values[i].bv_len = 0;
+ for ( i = 0; !BER_BVISNULL( &delmod->sml_values[i] ); i++ ) {
+ free( delmod->sml_values[i].bv_val );
+ BER_BVZERO( &delmod->sml_values[i] );
}
- free(delmod->sml_values);
+ free( delmod->sml_values );
delmod->sml_values = ch_calloc( sizeof(struct berval), 2 );
- delmod->sml_values[1].bv_len = 0;
- delmod->sml_values[1].bv_val = NULL;
- ber_dupbv(&(delmod->sml_values[0]), &(pa->a_nvals[0]));
+ BER_BVZERO( &delmod->sml_values[1] );
+ ber_dupbv( &(delmod->sml_values[0]), &(pa->a_nvals[0]) );
}
}
- bv = newpw.bv_val ? &newpw : addmod->sml_values;
+ bv = newpw.bv_val ? &newpw : &addmod->sml_values[0];
if (pp.pwdCheckQuality > 0) {
rc = check_password_quality( bv, &pp, &pErr, e );
}
}
- if (pa) {
+ /* If pwdInHistory is zero, passwords may be reused */
+ if (pa && pp.pwdInHistory > 0) {
/*
* Last check - the password history.
*/
goto return_results;
}
- if (pp.pwdInHistory < 1) goto do_modify;
-
/*
* Iterate through the password history, and fail on any
* password matches.
struct berval timestamp;
char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
time_t now = slap_get_time();
-
+
+ /* If the conn is restricted, set a callback to clear it
+ * if the pwmod succeeds
+ */
+ if (!BER_BVISEMPTY( &pwcons[op->o_conn->c_conn_idx].dn )) {
+ slap_callback *sc = op->o_tmpcalloc( 1, sizeof( slap_callback ),
+ op->o_tmpmemctx );
+ sc->sc_next = op->o_callback;
+ /* Must use sc_response to insure we reset on success, before
+ * the client sees the response. Must use sc_cleanup to insure
+ * that it gets cleaned up if sc_response is not called.
+ */
+ sc->sc_response = ppolicy_mod_cb;
+ sc->sc_cleanup = ppolicy_mod_cb;
+ op->o_callback = sc;
+ }
+
/*
* keep the necessary pwd.. operational attributes
* up to date.
timestamp.bv_len = sizeof(timebuf);
slap_timestamp( &now, ×tamp );
- mods = (Modifications *) ch_malloc( sizeof( Modifications ) );
- mods->sml_type.bv_val = NULL;
+ mods = (Modifications *) ch_calloc( sizeof( Modifications ), 1 );
mods->sml_desc = ad_pwdChangedTime;
if (pwmop != LDAP_MOD_DELETE) {
mods->sml_op = LDAP_MOD_REPLACE;
+ mods->sml_numvals = 1;
mods->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
ber_dupbv( &mods->sml_values[0], ×tamp );
- mods->sml_values[1].bv_len = 0;
- mods->sml_values[1].bv_val = NULL;
- assert( mods->sml_values[0].bv_val != NULL );
+ BER_BVZERO( &mods->sml_values[1] );
+ assert( !BER_BVISNULL( &mods->sml_values[0] ) );
+
} else {
mods->sml_op = LDAP_MOD_DELETE;
- mods->sml_values = NULL;
}
mods->sml_flags = SLAP_MOD_INTERNAL;
- mods->sml_nvalues = NULL;
mods->sml_next = NULL;
modtail->sml_next = mods;
modtail = mods;
if (attr_find(e->e_attrs, ad_pwdGraceUseTime )) {
- mods = (Modifications *) ch_malloc( sizeof( Modifications ) );
+ mods = (Modifications *) ch_calloc( sizeof( Modifications ), 1 );
mods->sml_op = LDAP_MOD_DELETE;
- mods->sml_flags = SLAP_MOD_INTERNAL;
- mods->sml_type.bv_val = NULL;
mods->sml_desc = ad_pwdGraceUseTime;
- mods->sml_values = NULL;
- mods->sml_nvalues = NULL;
+ mods->sml_flags = SLAP_MOD_INTERNAL;
mods->sml_next = NULL;
modtail->sml_next = mods;
modtail = mods;
}
if (attr_find(e->e_attrs, ad_pwdAccountLockedTime )) {
- mods = (Modifications *) ch_malloc( sizeof( Modifications ) );
+ mods = (Modifications *) ch_calloc( sizeof( Modifications ), 1 );
mods->sml_op = LDAP_MOD_DELETE;
- mods->sml_flags = SLAP_MOD_INTERNAL;
- mods->sml_type.bv_val = NULL;
mods->sml_desc = ad_pwdAccountLockedTime;
- mods->sml_values = NULL;
- mods->sml_nvalues = NULL;
+ mods->sml_flags = SLAP_MOD_INTERNAL;
mods->sml_next = NULL;
modtail->sml_next = mods;
modtail = mods;
}
if (attr_find(e->e_attrs, ad_pwdFailureTime )) {
- mods = (Modifications *) ch_malloc( sizeof( Modifications ) );
+ mods = (Modifications *) ch_calloc( sizeof( Modifications ), 1 );
mods->sml_op = LDAP_MOD_DELETE;
- mods->sml_flags = SLAP_MOD_INTERNAL;
- mods->sml_type.bv_val = NULL;
mods->sml_desc = ad_pwdFailureTime;
- mods->sml_values = NULL;
- mods->sml_nvalues = NULL;
+ mods->sml_flags = SLAP_MOD_INTERNAL;
mods->sml_next = NULL;
modtail->sml_next = mods;
modtail = mods;
/* Delete the pwdReset attribute, since it's being reset */
if ((zapReset) && (attr_find(e->e_attrs, ad_pwdReset ))) {
- mods = (Modifications *) ch_malloc( sizeof( Modifications ) );
+ mods = (Modifications *) ch_calloc( sizeof( Modifications ), 1 );
mods->sml_op = LDAP_MOD_DELETE;
- mods->sml_flags = SLAP_MOD_INTERNAL;
- mods->sml_type.bv_val = NULL;
mods->sml_desc = ad_pwdReset;
- mods->sml_values = NULL;
- mods->sml_nvalues = NULL;
+ mods->sml_flags = SLAP_MOD_INTERNAL;
mods->sml_next = NULL;
modtail->sml_next = mods;
modtail = mods;
* This is easily evaluated, since the linked list is
* created in ascending time order.
*/
- mods = (Modifications *) ch_malloc( sizeof( Modifications ) );
+ mods = (Modifications *) ch_calloc( sizeof( Modifications ), 1 );
mods->sml_op = LDAP_MOD_DELETE;
mods->sml_flags = SLAP_MOD_INTERNAL;
- mods->sml_type.bv_val = NULL;
mods->sml_desc = ad_pwdHistory;
- mods->sml_nvalues = NULL;
+ mods->sml_numvals = hsize - pp.pwdInHistory + 1;
mods->sml_values = ch_calloc( sizeof( struct berval ),
- hsize - pp.pwdInHistory + 2 );
- mods->sml_values[ hsize - pp.pwdInHistory + 1 ].bv_val = NULL;
- mods->sml_values[ hsize - pp.pwdInHistory + 1 ].bv_len = 0;
+ hsize - pp.pwdInHistory + 2 );
+ BER_BVZERO( &mods->sml_values[ hsize - pp.pwdInHistory + 1 ] );
for(i=0,p=tl; i < (hsize - pp.pwdInHistory + 1); i++, p=p->next) {
- mods->sml_values[i].bv_val = NULL;
- mods->sml_values[i].bv_len = 0;
+ BER_BVZERO( &mods->sml_values[i] );
ber_dupbv( &(mods->sml_values[i]), &p->bv );
}
mods->sml_next = NULL;
mods->sml_type.bv_val = NULL;
mods->sml_desc = ad_pwdHistory;
mods->sml_nvalues = NULL;
+ mods->sml_numvals = 1;
mods->sml_values = ch_calloc( sizeof( struct berval ), 2 );
mods->sml_values[ 1 ].bv_val = NULL;
mods->sml_values[ 1 ].bv_len = 0;
mods->sml_next = NULL;
modtail->sml_next = mods;
modtail = mods;
+
} else {
Debug( LDAP_DEBUG_TRACE,
"ppolicy_modify: password attr lookup failed\n", 0, 0, 0 );
*/
if ((pi->hash_passwords) && (addmod) && !newpw.bv_val &&
- (password_scheme( &(addmod->sml_values[0]), NULL ) != LDAP_SUCCESS)) {
+ (password_scheme( &(addmod->sml_values[0]), NULL ) != LDAP_SUCCESS))
+ {
struct berval hpw, bv;
slap_passwd_hash( &(addmod->sml_values[0]), &hpw, &txt );
rs->sr_text = txt;
goto return_results;
}
- bv.bv_val = addmod->sml_values[0].bv_val;
- bv.bv_len = addmod->sml_values[0].bv_len;
+ bv = addmod->sml_values[0];
/* clear and discard the clear password */
memset(bv.bv_val, 0, bv.bv_len);
ber_memfree(bv.bv_val);
- addmod->sml_values[0].bv_val = hpw.bv_val;
- addmod->sml_values[0].bv_len = hpw.bv_len;
+ addmod->sml_values[0] = hpw;
}
}
op->o_bd->bd_info = (BackendInfo *)on->on_info;
op->o_bd->bd_info = (BackendInfo *)on->on_info;
be_entry_release_r( op, e );
if ( send_ctrl ) {
- LDAPControl **ctrls = NULL;
-
- ctrls = ch_calloc( sizeof( LDAPControl *) , 2 );
- ctrls[0] = create_passcontrol( -1, -1, pErr );
- ctrls[1] = NULL;
- rs->sr_ctrls = ctrls;
+ ctrl = create_passcontrol( op, -1, -1, pErr );
+ oldctrls = add_passcontrol( op, rs, ctrl );
}
send_ldap_result( op, rs );
+ if ( send_ctrl ) {
+ if ( is_pwdexop ) {
+ if ( rs->sr_flags & REP_CTRLS_MUSTBEFREED ) {
+ op->o_tmpfree( oldctrls, op->o_tmpmemctx );
+ }
+ oldctrls = NULL;
+ rs->sr_flags |= REP_CTRLS_MUSTBEFREED;
+
+ } else {
+ ctrls_cleanup( op, rs, oldctrls );
+ }
+ }
return rs->sr_err;
}
SlapReply *rs,
LDAPControl *ctrl )
{
- if ( ctrl->ldctl_value.bv_len ) {
- rs->sr_text = "passwordPolicyRequest control value not empty";
+ if ( !BER_BVISNULL( &ctrl->ldctl_value ) ) {
+ rs->sr_text = "passwordPolicyRequest control value not absent";
return LDAP_PROTOCOL_ERROR;
}
- if ( ctrl->ldctl_iscritical ) {
- rs->sr_text = "passwordPolicyRequest control invalid criticality";
- return LDAP_PROTOCOL_ERROR;
- }
- op->o_ctrlflag[ppolicy_cid] = SLAP_CONTROL_NONCRITICAL;
+ op->o_ctrlflag[ppolicy_cid] = ctrl->ldctl_iscritical
+ ? SLAP_CONTROL_CRITICAL
+ : SLAP_CONTROL_NONCRITICAL;
return LDAP_SUCCESS;
}
static int
ppolicy_db_init(
- BackendDB *be
+ BackendDB *be,
+ ConfigReply *cr
)
{
slap_overinst *on = (slap_overinst *) be->bd_info;
for (i=0; pwd_UsSchema[i].def; i++) {
code = slap_str2ad( pwd_UsSchema[i].def, pwd_UsSchema[i].ad, &err );
if ( code ) {
- fprintf( stderr, "User Schema Load failed %d: %s\n", code, err );
+ if ( cr ){
+ snprintf( cr->msg, sizeof(cr->msg),
+ "User Schema load failed for attribute \"%s\". Error code %d: %s",
+ pwd_UsSchema[i].def, code, err );
+ fprintf( stderr, "%s\n", cr->msg );
+ }
return code;
}
}
on->on_bi.bi_private = ch_calloc( sizeof(pp_info), 1 );
- if ( dtblsize && !pwcons )
- pwcons = ch_calloc(sizeof(pw_conn), dtblsize );
+ if ( dtblsize && !pwcons ) {
+ /* accommodate for c_conn_idx == -1 */
+ pwcons = ch_calloc( sizeof(pw_conn), dtblsize + 1 );
+ pwcons++;
+ }
return 0;
}
static int
ppolicy_db_open(
- BackendDB *be
+ BackendDB *be,
+ ConfigReply *cr
)
{
+ ov_count++;
return overlay_register_control( be, LDAP_CONTROL_PASSWORDPOLICYREQUEST );
}
static int
ppolicy_close(
- BackendDB *be
+ BackendDB *be,
+ ConfigReply *cr
)
{
slap_overinst *on = (slap_overinst *) be->bd_info;
pp_info *pi = on->on_bi.bi_private;
-
- free( pwcons );
+
+ /* Perhaps backover should provide bi_destroy hooks... */
+ ov_count--;
+ if ( ov_count <=0 && pwcons ) {
+ pwcons--;
+ free( pwcons );
+ pwcons = NULL;
+ }
free( pi->def_policy.bv_val );
free( pi );
return 0;
}
-static int
-ppolicy_config(
- BackendDB *be,
- const char *fname,
- int lineno,
- int argc,
- char **argv
-)
-{
- slap_overinst *on = (slap_overinst *) be->bd_info;
- pp_info *pi = on->on_bi.bi_private;
- struct berval dn;
-
-
- if ( strcasecmp( argv[0], "ppolicy_default" ) == 0 ) {
- if ( argc != 2 ) {
- fprintf( stderr, "%s: line %d: invalid arguments in \"ppolicy_default"
- " <policyDN>\n", fname, lineno );
- return ( 1 );
- }
- ber_str2bv( argv[1], 0, 0, &dn );
- if ( dnNormalize( 0, NULL, NULL, &dn, &pi->def_policy, NULL ) ) {
- fprintf( stderr, "%s: line %d: policyDN is invalid\n",
- fname, lineno );
- return 1;
- }
- return 0;
-
- } else if ( strcasecmp( argv[0], "ppolicy_use_lockout" ) == 0 ) {
- if ( argc != 1 ) {
- fprintf( stderr, "%s: line %d: ppolicy_use_lockout "
- "takes no arguments\n", fname, lineno );
- return ( 1 );
- }
- pi->use_lockout = 1;
- return 0;
- } else if ( strcasecmp( argv[0], "ppolicy_hash_cleartext" ) == 0 ) {
- if ( argc != 1 ) {
- fprintf( stderr, "%s: line %d: ppolicy_hash_cleartext "
- "takes no arguments\n", fname, lineno );
- return ( 1 );
- }
- pi->hash_passwords = 1;
- return 0;
- }
- return SLAP_CONF_UNKNOWN;
-}
-
static char *extops[] = {
LDAP_EXOP_MODIFY_PASSWD,
NULL
static slap_overinst ppolicy;
-int ppolicy_init()
+int ppolicy_initialize()
{
- LDAPAttributeType *at;
- const char *err;
int i, code;
for (i=0; pwd_OpSchema[i].def; i++) {
- at = ldap_str2attributetype( pwd_OpSchema[i].def, &code, &err,
- LDAP_SCHEMA_ALLOW_ALL );
- if ( !at ) {
- fprintf( stderr, "AttributeType Load failed %s %s\n",
- ldap_scherr2str(code), err );
- return code;
- }
- code = at_add( at, 0, NULL, &err );
- if ( !code ) {
- slap_str2ad( at->at_names[0], pwd_OpSchema[i].ad, &err );
- }
- ldap_memfree( at );
+ code = register_at( pwd_OpSchema[i].def, pwd_OpSchema[i].ad, 0 );
if ( code ) {
- fprintf( stderr, "AttributeType Load failed %s %s\n",
- scherr2str(code), err );
+ Debug( LDAP_DEBUG_ANY,
+ "ppolicy_initialize: register_at failed\n", 0, 0, 0 );
return code;
}
/* Allow Manager to set these as needed */
ppolicy.on_bi.bi_type = "ppolicy";
ppolicy.on_bi.bi_db_init = ppolicy_db_init;
ppolicy.on_bi.bi_db_open = ppolicy_db_open;
- ppolicy.on_bi.bi_db_config = ppolicy_config;
ppolicy.on_bi.bi_db_close = ppolicy_close;
ppolicy.on_bi.bi_op_add = ppolicy_add;
ppolicy.on_bi.bi_op_search = ppolicy_restrict;
ppolicy.on_bi.bi_connection_destroy = ppolicy_connection_destroy;
+ ppolicy.on_bi.bi_cf_ocs = ppolicyocs;
+ code = config_register_schema( ppolicycfg, ppolicyocs );
+ if ( code ) return code;
+
return overlay_register( &ppolicy );
}
#if SLAPD_OVER_PPOLICY == SLAPD_MOD_DYNAMIC
int init_module(int argc, char *argv[]) {
- return ppolicy_init();
+ return ppolicy_initialize();
}
#endif