winbindd: let normalize_name_map() call find_domain_from_name_noinit()
authorRalph Boehme <slow@samba.org>
Mon, 27 Nov 2017 11:42:44 +0000 (12:42 +0100)
committerRalph Boehme <slow@samba.org>
Wed, 29 Nov 2017 15:59:15 +0000 (16:59 +0100)
Let normalize_name_map fetch the domain itself with
find_domain_from_name_noinit().

This removes two calls to find_domain_from_name_noinit() in the default
configuration of "winbind normalize names = no". The domain is only need
in normalize_name_map if "winbind normalize names" is enabled.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/winbindd/wb_getpwsid.c
source3/winbindd/winbindd_group.c
source3/winbindd/winbindd_msrpc.c
source3/winbindd/winbindd_proto.h
source3/winbindd/winbindd_rpc.c
source3/winbindd/winbindd_util.c

index dcb249287d9e9bcb86fbddda06765c6c9801b177..01c2f9cebfbaf119f73207da63b1d020753f56ce 100644 (file)
@@ -69,7 +69,6 @@ static void wb_getpwsid_queryuser_done(struct tevent_req *subreq)
                req, struct wb_getpwsid_state);
        struct winbindd_pw *pw = state->pw;
        struct wbint_userinfo *info;
-       struct winbindd_domain *domain = NULL;
        fstring acct_name, output_username;
        char *mapped_name = NULL;
        char *tmp;
@@ -91,11 +90,6 @@ static void wb_getpwsid_queryuser_done(struct tevent_req *subreq)
                return;
        }
 
-       domain = find_domain_from_name_noinit(info->domain_name);
-       if (tevent_req_nomem(domain, req)) {
-               return;
-       }
-
        /*
         * TODO:
         * This function should be called in 'idmap winbind child'. It shouldn't
@@ -103,7 +97,7 @@ static void wb_getpwsid_queryuser_done(struct tevent_req *subreq)
         * winbind.idl. This is a fix which can be backported for now.
         */
        status = normalize_name_map(state,
-                                   domain,
+                                   info->domain_name,
                                    acct_name,
                                    &mapped_name);
        if (NT_STATUS_IS_OK(status)) {
index b5c9d3cf94eaac203b0aed87a4bc7c6e2fba74d6..417565ecbf0ce91aa61cda45bf78bb0f0c58799d 100644 (file)
@@ -36,18 +36,9 @@ bool fill_grent(TALLOC_CTX *mem_ctx, struct winbindd_gr *gr,
 {
        fstring full_group_name;
        char *mapped_name = NULL;
-       struct winbindd_domain *domain;
        NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
 
-       domain = find_domain_from_name_noinit(dom_name);
-       if (domain == NULL) {
-               DEBUG(0, ("Failed to find domain '%s'. "
-                         "Check connection to trusted domains!\n",
-                         dom_name));
-               return false;
-       }
-
-       nt_status = normalize_name_map(mem_ctx, domain, gr_name,
+       nt_status = normalize_name_map(mem_ctx, dom_name, gr_name,
                                       &mapped_name);
 
        /* Basic whitespace replacement */
index c56537662bad016f7b5e470030dc68bb38800dfc..9bf4354f4e39ff8d4766fdea8b07f36da19b1b52 100644 (file)
@@ -313,7 +313,7 @@ static NTSTATUS msrpc_sid_to_name(struct winbindd_domain *domain,
 
        DEBUG(5,("Mapped sid to [%s]\\[%s]\n", domains[0], *name));
 
-       name_map_status = normalize_name_map(mem_ctx, domain, *name,
+       name_map_status = normalize_name_map(mem_ctx, domain->name, *name,
                                             &mapped_name);
        if (NT_STATUS_IS_OK(name_map_status) ||
            NT_STATUS_EQUAL(name_map_status, NT_STATUS_FILE_RENAMED))
@@ -377,7 +377,7 @@ static NTSTATUS msrpc_rids_to_names(struct winbindd_domain *domain,
 
                if ((*types)[i] != SID_NAME_UNKNOWN) {
                        name_map_status = normalize_name_map(mem_ctx,
-                                                            domain,
+                                                            domain->name,
                                                             ret_names[i],
                                                             &mapped_name);
                        if (NT_STATUS_IS_OK(name_map_status) ||
index 83136996dd2049c4a0520d8b2f399135e6ff6cce..cf01337aaad78126f98e71b5dba03e94fe364878 100644 (file)
@@ -471,7 +471,7 @@ NTSTATUS lookup_usergroups_cached(TALLOC_CTX *mem_ctx,
                                  uint32_t *p_num_groups, struct dom_sid **user_sids);
 
 NTSTATUS normalize_name_map(TALLOC_CTX *mem_ctx,
-                            struct winbindd_domain *domain,
+                            const char *domain_name,
                             const char *name,
                             char **normalized);
 NTSTATUS normalize_name_unmap(TALLOC_CTX *mem_ctx,
index 2c76e1abd6cd95e05644768ad85b51d92795bde9..f50fb8fa5dba23bcc50bdfca05baa9ae17df6606 100644 (file)
@@ -332,7 +332,7 @@ NTSTATUS rpc_sid_to_name(TALLOC_CTX *mem_ctx,
        *ptype = (enum lsa_SidType) types[0];
 
        map_status = normalize_name_map(mem_ctx,
-                                       domain,
+                                       domain->name,
                                        names[0],
                                        &mapped_name);
        if (NT_STATUS_IS_OK(map_status) ||
@@ -410,7 +410,7 @@ NTSTATUS rpc_rids_to_names(TALLOC_CTX *mem_ctx,
 
                if (types[i] != SID_NAME_UNKNOWN) {
                        map_status = normalize_name_map(mem_ctx,
-                                                       domain,
+                                                       domain->name,
                                                        names[i],
                                                        &mapped_name);
                        if (NT_STATUS_IS_OK(map_status) ||
index 7b443c79fa5973efe23bba9cb3845b9ccdef1265..34f38e5fbbb574d6cf69b071fb7e04ce3c1cad4e 100644 (file)
@@ -1339,10 +1339,11 @@ NTSTATUS lookup_usergroups_cached(TALLOC_CTX *mem_ctx,
 ********************************************************************/
 
 NTSTATUS normalize_name_map(TALLOC_CTX *mem_ctx,
-                            struct winbindd_domain *domain,
+                            const char *domain_name,
                             const char *name,
                             char **normalized)
 {
+       struct winbindd_domain *domain = NULL;
        NTSTATUS nt_status;
 
        if (!name || !normalized) {
@@ -1353,6 +1354,12 @@ NTSTATUS normalize_name_map(TALLOC_CTX *mem_ctx,
                return NT_STATUS_PROCEDURE_NOT_FOUND;
        }
 
+       domain = find_domain_from_name_noinit(domain_name);
+       if (domain == NULL) {
+               DBG_ERR("Failed to find domain '%s'\n", domain_name);
+               return NT_STATUS_NO_SUCH_DOMAIN;
+       }
+
        /* Alias support and whitespace replacement are mutually
           exclusive */