r9654: introduce the samdb_search_dn call
authorSimo Sorce <idra@samba.org>
Fri, 26 Aug 2005 16:12:25 +0000 (16:12 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:34:38 +0000 (13:34 -0500)
source/dsdb/samdb/samdb.c
source/libnet/libnet_samsync_ldb.c
source/rpc_server/lsa/dcesrv_lsa.c
source/rpc_server/samr/dcesrv_samr.c
source/rpc_server/samr/samr_password.c

index 9cb9a9344606552699b39513b0ac39706bcc52b6..aed47d1ed2725c5ad3fa96e12eb47ab0570c41b7 100644 (file)
@@ -127,6 +127,28 @@ const char *samdb_search_string(struct ldb_context *sam_ldb,
        return str;
 }
 
+struct ldb_dn *samdb_search_dn(struct ldb_context *sam_ldb,
+                              TALLOC_CTX *mem_ctx,
+                              const struct ldb_dn *basedn,
+                              const char *format, ...) _PRINTF_ATTRIBUTE(4,5)
+{
+       va_list ap;
+       struct ldb_dn *ret;
+       struct ldb_message **res = NULL;
+       int count;
+
+       va_start(ap, format);
+       count = gendb_search_v(sam_ldb, mem_ctx, basedn, &res, NULL, format, ap);
+       va_end(ap);
+
+       if (count != 1) return NULL;
+
+       ret = talloc_steal(mem_ctx, res[0]->dn);
+       talloc_free(res);
+
+       return ret;
+}
+
 /*
   search the sam for a dom_sid attribute in exactly 1 record
 */
index f595880e8e7e75101c12f8f36ebc605d80f71a8d..837170afac660972433a4cdf09145dfe0306cc0c 100644 (file)
@@ -58,11 +58,9 @@ static NTSTATUS samsync_ldb_add_foreignSecurityPrincipal(TALLOC_CTX *mem_ctx,
 {
        const char *sidstr = dom_sid_string(mem_ctx, sid);
        /* We assume that ForeignSecurityPrincipals are under the BASEDN of the main domain */
-       struct ldb_dn *basedn = ldb_dn_explode(mem_ctx,
-                                               samdb_search_string(state->sam_ldb, mem_ctx,
-                                                                       state->base_dn[SAM_DATABASE_DOMAIN],
-                                                                       "dn", "(&(objectClass=container)"
-                                                                               "(cn=ForeignSecurityPrincipals))"));
+       struct ldb_dn *basedn = samdb_search_dn(state->sam_ldb, mem_ctx,
+                                               state->base_dn[SAM_DATABASE_DOMAIN],
+                                               "(&(objectClass=container)(cn=ForeignSecurityPrincipals))");
        struct ldb_message *msg;
        int ret;
 
index bac25fcc241ff20969663f84396ee2da87b42796..c81eb99a0efed8c8ef4b19a970ea27dda5c05f43 100644 (file)
@@ -261,18 +261,15 @@ static NTSTATUS lsa_get_policy_state(struct dcesrv_call_state *dce_call, TALLOC_
 
        /* work out the builtin_dn - useful for so many calls its worth
           fetching here */
-       state->builtin_dn = ldb_dn_explode(state, 
-                                        samdb_search_string(state->sam_ldb, mem_ctx, NULL,
-                                                            "dn", "objectClass=builtinDomain"));
+       state->builtin_dn = samdb_search_dn(state->sam_ldb, mem_ctx, NULL, "objectClass=builtinDomain");
        if (!state->builtin_dn) {
                return NT_STATUS_NO_SUCH_DOMAIN;                
        }
 
        /* work out the system_dn - useful for so many calls its worth
           fetching here */
-       state->system_dn = ldb_dn_explode(state, 
-                                       samdb_search_string(state->sam_ldb, mem_ctx, state->domain_dn,
-                                                           "dn", "(&(objectClass=container)(cn=System))"));
+       state->system_dn = samdb_search_dn(state->sam_ldb, mem_ctx,
+                                          state->domain_dn, "(&(objectClass=container)(cn=System))");
        if (!state->system_dn) {
                return NT_STATUS_NO_SUCH_DOMAIN;                
        }
@@ -1304,13 +1301,9 @@ static NTSTATUS lsa_OpenAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *
        }
        
        /* check it really exists */
-       astate->account_dn = 
-               ldb_dn_explode(mem_ctx,
-                               samdb_search_string(state->sam_ldb, astate,
-                                                   NULL, "dn", 
-                                                   "(&(objectSid=%s)(objectClass=group))", 
-                                                   ldap_encode_ndr_dom_sid(mem_ctx,
-                                                                           astate->account_sid)));
+       astate->account_dn = samdb_search_string(state->sam_ldb, astate,
+                                                NULL, "(&(objectSid=%s)(objectClass=group))", 
+                                                ldap_encode_ndr_dom_sid(mem_ctx, astate->account_sid));
        if (astate->account_dn == NULL) {
                talloc_free(astate);
                return NT_STATUS_NO_SUCH_USER;
@@ -1466,8 +1459,7 @@ static NTSTATUS lsa_AddRemoveAccountRights(struct dcesrv_call_state *dce_call,
                return NT_STATUS_NO_MEMORY;
        }
 
-       dn = samdb_search_string(state->sam_ldb, mem_ctx, NULL, "dn", 
-                                "objectSid=%s", sidstr);
+       dn = samdb_search_dn(state->sam_ldb, mem_ctx, NULL, "objectSid=%s", sidstr);
        if (dn == NULL) {
                return NT_STATUS_NO_SUCH_USER;
        }
index ff15eb43bb5e803893999fa4b1903f8381140664..aeea3a120c17173e4afad62920f402fc31ac4f07 100644 (file)
@@ -2117,11 +2117,8 @@ static NTSTATUS samr_AddAliasMember(struct dcesrv_call_state *dce_call, TALLOC_C
                 * cn=For...,cn=Builtin,dc={BASEDN}.  -- vl
                 */
 
-               basedn = ldb_dn_explode(mem_ctx,
-                                       samdb_search_string(d_state->sam_ctx,
-                                                           mem_ctx, NULL, "dn",
-                                                           "(&(objectClass=container)"
-                                                           "(cn=ForeignSecurityPrincipals))"));
+               basedn = samdb_search_dn(d_state->sam_ctx, mem_ctx, NULL,
+                                        "(&(objectClass=container)(cn=ForeignSecurityPrincipals))");
 
                if (basedn == NULL) {
                        DEBUG(0, ("Failed to find DN for "
index c86276310132c2043ef708dd51d74dfd2bff09da..ab99b6945874b979d0d86bfc3171f4a702176530 100644 (file)
@@ -210,10 +210,9 @@ NTSTATUS samr_OemChangePasswordUser2(struct dcesrv_call_state *dce_call, TALLOC_
                return NT_STATUS_NO_SUCH_USER;
        }
 
-       domain_dn = ldb_dn_explode(mem_ctx,
-                                  samdb_search_string(sam_ctx, mem_ctx, NULL, "dn",
-                                                       "(objectSid=%s)", 
-                                                       ldap_encode_ndr_dom_sid(mem_ctx, domain_sid)));
+       domain_dn = samdb_search_dn(sam_ctx, mem_ctx, NULL,
+                                   "(objectSid=%s)", 
+                                   ldap_encode_ndr_dom_sid(mem_ctx, domain_sid));
        if (!domain_dn) {
                return NT_STATUS_INTERNAL_DB_CORRUPTION;
        }
@@ -361,10 +360,9 @@ NTSTATUS samr_ChangePasswordUser3(struct dcesrv_call_state *dce_call,
                goto failed;
        }
 
-       domain_dn = ldb_dn_explode(mem_ctx,
-                                  samdb_search_string(sam_ctx, mem_ctx, NULL, "dn",
-                                                       "(objectSid=%s)", 
-                                                       ldap_encode_ndr_dom_sid(mem_ctx, domain_sid)));
+       domain_dn = samdb_search_dn(sam_ctx, mem_ctx, NULL,
+                                   "(objectSid=%s)", 
+                                   ldap_encode_ndr_dom_sid(mem_ctx, domain_sid));
        if (!domain_dn) {
                status = NT_STATUS_INTERNAL_DB_CORRUPTION;
                goto failed;