]> git.sur5r.net Git - openldap/commitdiff
Ensure normalized root DN is available to internal SLAPI operations for
authorLuke Howard <lukeh@openldap.org>
Sun, 2 Feb 2003 11:00:52 +0000 (11:00 +0000)
committerLuke Howard <lukeh@openldap.org>
Sun, 2 Feb 2003 11:00:52 +0000 (11:00 +0000)
authorization to work.

Do not crash when forming Modification list from LDAPMod array.

servers/slapd/slapi/slapi_ops.c

index 86477da646c363e91badb950ac12230a5217cd68..6855267351393c280de28cb82c9c127a7263cd1e 100644 (file)
@@ -240,59 +240,61 @@ fakeConnection(
        return pConn;\r
 }\r
 \r
-/* \r
- * Function : ValuestoBValues \r
- * Convert an array of char ptrs to an array of berval ptrs.\r
- * return value : LDAP_SUCCESS\r
- *                LDAP_NO_MEMORY\r
- *                LDAP_OTHER\r
-*/\r
-\r
-static int \r
-ValuesToBValues(\r
-       char **ppValue, \r
-       struct berval ***pppBV )\r
+/*\r
+ * Function : values2obj\r
+ * Convert an array of strings into a BerVarray.\r
+ * the strings.\r
+ */\r
+static int\r
+values2obj(\r
+       char **ppValue,\r
+       BerVarray *bvobj)\r
 {\r
-       int  rc = LDAP_SUCCESS;\r
-       int  i;\r
-       struct berval *pTmpBV;\r
-       struct berval **ppNewBV;\r
-\r
-       /* count the number of char ptrs. */\r
-       for ( i = 0; ppValue != NULL && ppValue[i] != NULL; i++ ) {\r
-               ;       /* NULL */\r
+       int rc = LDAP_SUCCESS;\r
+       int i;\r
+       BerVarray tmpberval;\r
+\r
+       if ( ppValue == NULL ) {\r
+               *bvobj = NULL;\r
+               return LDAP_SUCCESS;\r
        }\r
 \r
-       if ( i == 0 ) {\r
-               rc = LDAP_OTHER;\r
-       } else {\r
-               *pppBV = ppNewBV = (struct berval **)slapi_ch_malloc( (i+1)*(sizeof(struct berval *)) );\r
-               if ( *pppBV == NULL ) {\r
-                       rc = LDAP_NO_MEMORY;\r
-               } else {\r
-                       while ( ppValue != NULL && *ppValue != NULL && rc == LDAP_SUCCESS ) {\r
-                               pTmpBV = (struct berval *)slapi_ch_malloc(sizeof(struct berval));\r
-                               if ( pTmpBV == NULL) {\r
-                                       rc = LDAP_NO_MEMORY;\r
-                               } else {\r
-                                       pTmpBV->bv_val = slapi_ch_strdup(*ppValue);\r
-                                       if ( pTmpBV->bv_val == NULL ) {\r
-                                               rc = LDAP_NO_MEMORY;\r
-                                       } else {\r
-                                               pTmpBV->bv_len = strlen(*ppValue);\r
-                                               *ppNewBV = pTmpBV;\r
-                                               ppNewBV++;\r
-                                       }\r
-                                       ppValue++;\r
-                               }\r
-                       }\r
-                       /* null terminate the array of berval ptrs */\r
-                       *ppNewBV = NULL;\r
-               }\r
+       for ( i = 0; ppValue[i] != NULL; i++ )\r
+               ;\r
+\r
+       tmpberval = (BerVarray)slapi_ch_malloc( (i+1) * (sizeof(struct berval)) );\r
+       if ( tmpberval == NULL ) {\r
+               return LDAP_NO_MEMORY;\r
        }\r
-       return( rc );\r
+       for ( i = 0; ppValue[i] != NULL; i++ ) {\r
+               tmpberval[i].bv_val = ppValue[i];\r
+               tmpberval[i].bv_len = strlen( ppValue[i] );\r
+       }\r
+       tmpberval[i].bv_val = NULL;\r
+       tmpberval[i].bv_len = 0;\r
+\r
+       *bvobj = tmpberval;\r
+\r
+       return LDAP_SUCCESS;\r
 }\r
 \r
+static void\r
+freeMods( Modifications *ml )\r
+{\r
+       /*\r
+        * Free a modification list whose values have been \r
+        * set with bvptr2obj() or values2obj() (ie. they\r
+        * do not own the pointer to the underlying values)\r
+        */\r
+       Modifications *next;\r
+\r
+       for ( ; ml != NULL; ml = next ) {\r
+               next = ml->sml_next;\r
+\r
+               slapi_ch_free( (void **)&ml->sml_bvalues );\r
+               slapi_ch_free( (void **)&ml );\r
+       }\r
+}\r
 \r
 /*\r
  * Function : LDAPModToEntry \r
@@ -311,7 +313,6 @@ LDAPModToEntry(
        Entry                   *pEntry=NULL;\r
        LDAPMod                 *pMod;\r
        struct berval           *bv;\r
-       struct berval           **ppBV;\r
        Backend                 *be;\r
        Operation               *op;\r
 \r
@@ -352,8 +353,8 @@ LDAPModToEntry(
                                /* convert an array of pointers to bervals to an array of bervals */\r
                                rc = bvptr2obj(pMod->mod_bvalues, &bv);\r
                                if (rc != LDAP_SUCCESS) goto cleanup;\r
-                               tmp.sml_type.bv_val = slapi_ch_strdup(pMod->mod_type);\r
-                               tmp.sml_type.bv_len = slapi_ch_stlen(pMod->mod_type);\r
+                               tmp.sml_type.bv_val = pMod->mod_type;\r
+                               tmp.sml_type.bv_len = strlen( pMod->mod_type );\r
                                tmp.sml_bvalues = bv;\r
                \r
                                mod  = (Modifications *) ch_malloc( sizeof(Modifications) );\r
@@ -373,12 +374,10 @@ LDAPModToEntry(
                                if ( pMod->mod_values == NULL ) {\r
                                        rc = LDAP_OTHER;\r
                                } else {\r
-                                       rc = ValuesToBValues( pMod->mod_values, &ppBV );\r
+                                       rc = values2obj( pMod->mod_values, &bv );\r
                                        if (rc != LDAP_SUCCESS) goto cleanup;\r
-                                       rc = bvptr2obj(ppBV, &bv);\r
-                                       if (rc != LDAP_SUCCESS) goto cleanup;\r
-                                       tmp.sml_type.bv_val = slapi_ch_strdup(pMod->mod_type);\r
-                                       tmp.sml_type.bv_len = slapi_ch_stlen(pMod->mod_type);\r
+                                       tmp.sml_type.bv_val = pMod->mod_type;\r
+                                       tmp.sml_type.bv_len = strlen( pMod->mod_type );\r
                                        tmp.sml_bvalues = bv;\r
                \r
                                        mod  = (Modifications *) ch_malloc( sizeof(Modifications) );\r
@@ -391,10 +390,6 @@ LDAPModToEntry(
 \r
                                        *modtail = mod;\r
                                        modtail = &mod->sml_next;\r
-\r
-                                       if ( ppBV != NULL ) {\r
-                                               ber_bvecfree( ppBV );\r
-                                       }\r
                                }\r
                        }\r
                } /* for each LDAPMod */\r
@@ -449,7 +444,7 @@ cleanup:
 \r
        if ( dn.bv_val ) slapi_ch_free( (void **)&dn.bv_val );\r
        if ( op ) slapi_ch_free( (void **)&op );\r
-       if ( modlist != NULL ) slap_mods_free( modlist );\r
+       if ( modlist != NULL ) freeMods( modlist );\r
        if ( rc != LDAP_SUCCESS ) {\r
                if ( pEntry != NULL ) {\r
                        slapi_entry_free( pEntry );\r
@@ -496,7 +491,7 @@ slapi_delete_internal(
                goto cleanup;\r
        }\r
 \r
-       pConn = fakeConnection( NULL,  LDAP_REQ_DELETE );\r
+       pConn = fakeConnection( NULL, LDAP_REQ_DELETE );\r
        if (pConn == NULL) {\r
                rc = LDAP_NO_MEMORY;\r
                goto cleanup;\r
@@ -522,10 +517,8 @@ slapi_delete_internal(
                goto cleanup;\r
        }\r
 \r
-       op->o_ndn.bv_val = slapi_ch_strdup(be->be_rootdn.bv_val);\r
-       op->o_ndn.bv_len = be->be_rootdn.bv_len;\r
-       pConn->c_dn.bv_val = slapi_ch_strdup(be->be_rootdn.bv_val);\r
-       pConn->c_dn.bv_len = be->be_rootdn.bv_len;\r
+       op->o_dn = pConn->c_dn = be->be_rootdn;\r
+       op->o_ndn = pConn->c_ndn = be->be_rootndn;\r
 \r
        suffix_alias( be, &ndn );\r
 \r
@@ -558,8 +551,6 @@ cleanup:
 \r
        if ( pConn != NULL ) {\r
                if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );\r
-               if ( pConn->c_dn.bv_val ) slapi_ch_free( (void **)&pConn->c_dn.bv_val );\r
-               if ( op->o_dn.bv_val ) slapi_ch_free( (void **)&op->o_dn.bv_val );\r
                if ( op ) slapi_ch_free( (void **)&op );\r
                pSavePB = pPB;\r
                free( pConn );\r
@@ -612,10 +603,8 @@ slapi_add_entry_internal(
                goto cleanup;\r
        }\r
 \r
-       op->o_ndn.bv_val = slapi_ch_strdup( be->be_rootdn.bv_val );\r
-       op->o_ndn.bv_len = be->be_rootdn.bv_len;\r
-       pConn->c_dn.bv_val = slapi_ch_strdup( be->be_rootdn.bv_val );\r
-       pConn->c_dn.bv_len = be->be_rootdn.bv_len;\r
+       op->o_dn = pConn->c_dn = be->be_rootdn;\r
+       op->o_ndn = pConn->c_ndn = be->be_rootndn;\r
 \r
        if ( be->be_add ) {\r
                int repl_user = be_isupdate( be, &op->o_ndn );\r
@@ -642,13 +631,7 @@ cleanup:
 \r
        if ( pConn != NULL ) {\r
                if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );\r
-               if ( pConn->c_dn.bv_val ) slapi_ch_free( (void **)&pConn->c_dn.bv_val );\r
-               if ( op ) {\r
-                       if ( op->o_ndn.bv_val ) {\r
-                               slapi_ch_free( (void **)&op->o_ndn.bv_val );\r
-                       }\r
-                       free(op);\r
-               }\r
+               if ( op != NULL ) slapi_ch_free( (void **)&op );\r
                pSavePB = pPB;\r
                free( pConn );\r
        }\r
@@ -807,10 +790,8 @@ slapi_modrdn_internal(
                goto cleanup;\r
        }\r
 \r
-       op->o_ndn.bv_val = slapi_ch_strdup( be->be_rootdn.bv_val );\r
-       op->o_ndn.bv_len = be->be_rootdn.bv_len;\r
-       pConn->c_dn.bv_val = slapi_ch_strdup( be->be_rootdn.bv_val );\r
-       pConn->c_dn.bv_len = be->be_rootdn.bv_len;\r
+       op->o_dn = pConn->c_dn = be->be_rootdn;\r
+       op->o_ndn = pConn->c_ndn = be->be_rootndn;\r
 \r
        suffix_alias( be, &ndn );\r
 \r
@@ -858,11 +839,7 @@ cleanup:
 \r
        if ( pConn != NULL ) {\r
                if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );\r
-               if ( pConn->c_dn.bv_val ) slapi_ch_free( (void **)&pConn->c_dn.bv_val );\r
-               if ( op ) {\r
-                       if ( op->o_dn.bv_val ) slapi_ch_free( (void **)&op->o_dn.bv_val );\r
-                       slapi_ch_free( (void **)&op );\r
-               }\r
+               if ( op != NULL ) slapi_ch_free( (void **)&op );\r
                pSavePB = pPB;\r
                free( pConn );\r
        }\r
@@ -905,7 +882,6 @@ slapi_modify_internal(
        int                     isCritical;\r
        Backend                 *be;\r
        struct berval           *bv;\r
-       struct berval           **ppBV;\r
        LDAPMod                 *pMod;\r
 \r
        Modifications           *modlist = NULL;\r
@@ -943,10 +919,8 @@ slapi_modify_internal(
                goto cleanup;\r
        }\r
 \r
-       op->o_ndn.bv_val = slapi_ch_strdup( be->be_rootdn.bv_val );\r
-       op->o_ndn.bv_len = be->be_rootdn.bv_len;\r
-       pConn->c_dn.bv_val = slapi_ch_strdup( be->be_rootdn.bv_val );\r
-       pConn->c_dn.bv_len = be->be_rootdn.bv_len;\r
+       op->o_dn = pConn->c_dn = be->be_rootdn;\r
+       op->o_ndn = pConn->c_ndn = be->be_rootndn;\r
 \r
        suffix_alias( be, &ndn );\r
 \r
@@ -961,8 +935,8 @@ slapi_modify_internal(
                         */\r
                        rc = bvptr2obj( pMod->mod_bvalues, &bv );\r
                        if ( rc != LDAP_SUCCESS ) goto cleanup;\r
-                       tmp.sml_type.bv_val = slapi_ch_strdup( pMod->mod_type );\r
-                       tmp.sml_type.bv_len = slapi_ch_stlen( pMod->mod_type );\r
+                       tmp.sml_type.bv_val = pMod->mod_type;\r
+                       tmp.sml_type.bv_len = strlen( pMod->mod_type );\r
                        tmp.sml_bvalues = bv;\r
 \r
                        mod  = (Modifications *)ch_malloc( sizeof(Modifications) );\r
@@ -973,12 +947,10 @@ slapi_modify_internal(
                        mod->sml_type = tmp.sml_type;\r
                        mod->sml_bvalues = tmp.sml_bvalues;\r
                } else { \r
-                       rc = ValuesToBValues( pMod->mod_values, &ppBV );\r
-                       if ( rc != LDAP_SUCCESS ) goto cleanup;\r
-                       rc = bvptr2obj( ppBV, &bv );\r
+                       rc = values2obj( pMod->mod_values, &bv );\r
                        if ( rc != LDAP_SUCCESS ) goto cleanup;\r
-                       tmp.sml_type.bv_val = slapi_ch_strdup( pMod->mod_type );\r
-                       tmp.sml_type.bv_len = slapi_ch_stlen( pMod->mod_type );\r
+                       tmp.sml_type.bv_val = pMod->mod_type;\r
+                       tmp.sml_type.bv_len = strlen( pMod->mod_type );\r
                        tmp.sml_bvalues = bv;\r
 \r
                        mod  = (Modifications *) ch_malloc( sizeof(Modifications) );\r
@@ -988,10 +960,6 @@ slapi_modify_internal(
                        mod->sml_desc = NULL;\r
                        mod->sml_type = tmp.sml_type;\r
                        mod->sml_bvalues = tmp.sml_bvalues;\r
-\r
-                       if ( ppBV != NULL ) {\r
-                               ber_bvecfree( ppBV );\r
-                       }\r
                }\r
                *modtail = mod;\r
                modtail = &mod->sml_next;\r
@@ -1068,15 +1036,11 @@ cleanup:
        if ( pdn.bv_val ) ch_free( pdn.bv_val );\r
        if ( ndn.bv_val ) ch_free( ndn.bv_val );\r
 \r
-       if ( modlist != NULL ) slap_mods_free( modlist );\r
+       if ( modlist != NULL ) freeMods( modlist );\r
 \r
        if ( pConn != NULL ) {\r
                if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );\r
-               if ( pConn->c_dn.bv_val ) slapi_ch_free( (void **)&pConn->c_dn.bv_val );\r
-               if ( op ) {\r
-                       if ( op->o_dn.bv_val ) slapi_ch_free( (void **)&op->o_dn.bv_val );\r
-                       slapi_ch_free( (void **)&op );\r
-               }\r
+               if ( op != NULL ) slapi_ch_free( (void **)&op );\r
                pSavePB = pPB;\r
                free( pConn );\r
        }\r
@@ -1217,10 +1181,8 @@ slapi_search_internal_bind(
                goto cleanup;\r
        } \r
 \r
-       op->o_ndn.bv_val = slapi_ch_strdup( be->be_rootdn.bv_val );\r
-       op->o_ndn.bv_len = be->be_rootdn.bv_len;\r
-       c->c_dn.bv_val = slapi_ch_strdup( be->be_rootdn.bv_val );\r
-       c->c_dn.bv_len = be->be_rootdn.bv_len;\r
+       op->o_dn = c->c_dn = be->be_rootdn;\r
+       op->o_ndn = c->c_ndn = be->be_rootndn;\r
 \r
        if ( be->be_search ) {\r
                rc = (*be->be_search)( be, c, op, &pdn, &ndn,\r
@@ -1251,11 +1213,7 @@ cleanup:
 \r
        if ( c != NULL ) {\r
                if ( c->c_sb != NULL ) ber_sockbuf_free( c->c_sb );\r
-               if ( c->c_dn.bv_val ) slapi_ch_free( (void **)&c->c_dn.bv_val );\r
-               if ( op ) {\r
-                       if ( op->o_ndn.bv_val ) slapi_ch_free( (void **)&op->o_ndn.bv_val );\r
-                       free( op );\r
-               }\r
+               if ( op != NULL ) slapi_ch_free( (void **)&op );\r
                pSavePB = ptr;\r
                free( c );\r
        }\r