]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/passwd.c
Switch to openldap-data directory
[openldap] / servers / slapd / back-bdb / passwd.c
index e7d7b02a12cd83ec4c6ada2c5d778de28493fadb..bec86197894430933f815cbd5ff677c2b8bbcab5 100644 (file)
@@ -1,7 +1,7 @@
 /* passwd.c - bdb backend password routines */
 /* $OpenLDAP$ */
 /*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 
@@ -24,70 +24,74 @@ bdb_exop_passwd(
        struct berval   **rspdata,
        LDAPControl             *** rspctrls,
        const char              **text,
-       struct berval   *** refs )
+       BerVarray *refs )
 {
        struct bdb_info *bdb = (struct bdb_info *) be->be_private;
        int rc;
        Entry *e = NULL;
-       struct berval *hash = NULL;
+       struct berval hash = { 0, NULL };
        DB_TXN *ltid = NULL;
        struct bdb_op_info opinfo;
        char textbuf[SLAP_TEXT_BUFLEN];
        size_t textlen = sizeof textbuf;
 
-       struct berval *id = NULL;
-       struct berval *new = NULL;
+       struct berval id = { 0, NULL };
+       struct berval new = { 0, NULL };
 
-       char *dn;
+       struct berval *dn;
 
        assert( reqoid != NULL );
-       assert( strcmp( LDAP_EXOP_X_MODIFY_PASSWD, reqoid ) == 0 );
+       assert( strcmp( LDAP_EXOP_MODIFY_PASSWD, reqoid ) == 0 );
 
        rc = slap_passwd_parse( reqdata,
                &id, NULL, &new, text );
 
        Debug( LDAP_DEBUG_ARGS, "==> bdb_exop_passwd: \"%s\"\n",
-               id ? id->bv_val : "", 0, 0 );
+               id.bv_val ? id.bv_val : "", 0, 0 );
 
        if( rc != LDAP_SUCCESS ) {
                goto done;
        }
 
-       if( new == NULL || new->bv_len == 0 ) {
-               new = slap_passwd_generate();
+       if( new.bv_len == 0 ) {
+               slap_passwd_generate(&new);
 
-               if( new == NULL || new->bv_len == 0 ) {
+               if( new.bv_len == 0 ) {
                        *text = "password generation failed.";
                        rc = LDAP_OTHER;
                        goto done;
                }
                
-               *rspdata = slap_passwd_return( new );
+               *rspdata = slap_passwd_return( &new );
        }
 
-       hash = slap_passwd_hash( new );
+       slap_passwd_hash( &new, &hash );
 
-       if( hash == NULL || hash->bv_len == 0 ) {
+       if( hash.bv_len == 0 ) {
                *text = "password hash failed";
                rc = LDAP_OTHER;
                goto done;
        }
 
-       dn = id ? id->bv_val : op->o_dn;
+       dn = id.bv_val ? &id : &op->o_dn;
 
        Debug( LDAP_DEBUG_TRACE, "bdb_exop_passwd: \"%s\"%s\n",
-               dn, id ? " (proxy)" : "", 0 );
+               dn->bv_val, id.bv_val ? " (proxy)" : "", 0 );
 
-       if( dn == NULL || dn[0] == '\0' ) {
+       if( dn->bv_len == 0 ) {
                *text = "No password is associated with the Root DSE";
                rc = LDAP_OPERATIONS_ERROR;
                goto done;
        }
 
-       if (0) {
+       if( 0 ) {
 retry: /* transaction retry */
+               if ( e != NULL ) {
+                       bdb_cache_delete_entry(&bdb->bi_cache, e);
+                       bdb_cache_return_entry_w(&bdb->bi_cache, e);
+               }
                Debug( LDAP_DEBUG_TRACE, "bdb_exop_passwd: retrying...\n", 0, 0, 0 );
-               rc = txn_abort( ltid );
+               rc = TXN_ABORT( ltid );
                ltid = NULL;
                op->o_private = NULL;
                if( rc != 0 ) {
@@ -95,10 +99,12 @@ retry:      /* transaction retry */
                        *text = "internal error";
                        goto done;
                }
+               ldap_pvt_thread_yield();
        }
 
        /* begin transaction */
-       rc = txn_begin( bdb->bi_dbenv, NULL, &ltid, 0 );
+       rc = TXN_BEGIN( bdb->bi_dbenv, NULL, &ltid, 
+               bdb->bi_db_opflags );
        *text = NULL;
        if( rc != 0 ) {
                Debug( LDAP_DEBUG_TRACE,
@@ -115,7 +121,7 @@ retry:      /* transaction retry */
        op->o_private = &opinfo;
 
        /* get entry */
-       rc = bdb_dn2entry( be, ltid, dn, &e, NULL, 0 );
+       rc = bdb_dn2entry_w( be, ltid, dn, &e, NULL, 0 );
 
        switch(rc) {
        case DB_LOCK_DEADLOCK:
@@ -136,27 +142,36 @@ retry:    /* transaction retry */
                goto done;
        }
 
+#ifdef BDB_SUBENTRIES
+       if( is_entry_subentries( e ) ) {
+               /* entry is an alias, don't allow operation */
+               *text = "authorization entry is subentry";
+               rc = LDAP_OTHER;
+               goto done;
+       }
+#endif
+#ifdef BDB_ALIASES
        if( is_entry_alias( e ) ) {
                /* entry is an alias, don't allow operation */
                *text = "authorization entry is alias";
                rc = LDAP_ALIAS_PROBLEM;
                goto done;
        }
-
+#endif
 
        if( is_entry_referral( e ) ) {
                /* entry is an referral, don't allow operation */
                *text = "authorization entry is referral";
-               rc = LDAP_OPERATIONS_ERROR;
+               rc = LDAP_OTHER;
                goto done;
        }
 
        {
                Modifications ml;
-               struct berval *vals[2];
+               struct berval vals[2];
 
                vals[0] = hash;
-               vals[1] = NULL;
+               vals[1].bv_val = NULL;
 
                ml.sml_desc = slap_schema.si_ad_userPassword;
                ml.sml_bvalues = vals;
@@ -170,8 +185,6 @@ retry:      /* transaction retry */
                case DB_LOCK_DEADLOCK:
                case DB_LOCK_NOTGRANTED:
                        *text = NULL;
-                       bdb_entry_return( be, e );
-                       e = NULL;
                        goto retry;
                case 0:
                        break;
@@ -181,48 +194,44 @@ retry:    /* transaction retry */
                        goto done;
                }
 
-       }
+               /* change the entry itself */
+               rc = bdb_id2entry_update( be, ltid, e );
+               if( rc != 0 ) {
+                       switch(rc) {
+                       case DB_LOCK_DEADLOCK:
+                       case DB_LOCK_NOTGRANTED:
+                               goto retry;
+                       }
+                       *text = "entry update failed";
+                       rc = LDAP_OTHER;
+               }
 
-       /* change the entry itself */
-       rc = bdb_id2entry_update( be, ltid, e );
-       if( rc != 0 ) {
-               switch(rc) {
-               case DB_LOCK_DEADLOCK:
-               case DB_LOCK_NOTGRANTED:
-                       bdb_entry_return( be, e );
-                       e = NULL;
-                       goto retry;
+               if( rc == 0 ) {
+                       if( op->o_noop ) {
+                               rc = TXN_ABORT( ltid );
+                       } else {
+                               rc = TXN_COMMIT( ltid, 0 );
+                       }
+                       ltid = NULL;
                }
-               *text = "entry update failed";
-               rc = LDAP_OTHER;
-       } else
-       {
-               rc = txn_commit( ltid, 0 );
-               ltid = NULL;
                op->o_private = NULL;
-               if (rc)
-                       *text = "commit failed";
+
+               if( rc == LDAP_SUCCESS ) {
+                       replog( be, op, &e->e_name, &e->e_nname, &ml );
+               }
        }
 
 done:
        if( e != NULL ) {
-               bdb_entry_return( be, e );
-       }
-
-       if( id != NULL ) {
-               ber_bvfree( id );
+               bdb_cache_return_entry_w( &bdb->bi_cache, e );
        }
-
-       if( new != NULL ) {
-               ber_bvfree( new );
-       }
-
-       if( hash != NULL ) {
-               ber_bvfree( hash );
+               
+       if( hash.bv_val != NULL ) {
+               free( hash.bv_val );
        }
 
        if( ltid != NULL ) {
-               txn_abort( ltid );
+               TXN_ABORT( ltid );
                op->o_private = NULL;
        }