s3-winbindd: add and use winbindd_lookup_sids().
authorGünther Deschner <gd@samba.org>
Thu, 17 Sep 2009 05:59:25 +0000 (07:59 +0200)
committerKarolin Seeger <kseeger@samba.org>
Thu, 8 Oct 2009 07:39:30 +0000 (09:39 +0200)
Guenther
(cherry picked from commit f0b52b8c3133e3696db361d9d0e7d1fff0fab991)

source3/winbindd/winbindd_ads.c
source3/winbindd/winbindd_proto.h
source3/winbindd/winbindd_rpc.c

index 7828b4510bd494d1860a26276fa79d532509ce7e..227c967c931c84112238318983b2d7ac17c0c0a9 100644 (file)
@@ -977,8 +977,6 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
        int i;
        size_t num_members = 0;
        ads_control args;
-        struct rpc_pipe_client *cli;
-        struct policy_handle lsa_policy;
        DOM_SID *sid_mem_nocache = NULL;
        char **names_nocache = NULL;
        enum lsa_SidType *name_types_nocache = NULL;
@@ -1122,31 +1120,14 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
 
        /* handle sids not resolved from cache by lsa_lookup_sids */
        if (num_nocache > 0) {
-               unsigned int orig_timeout;
 
-               status = cm_connect_lsa(domain, tmp_ctx, &cli, &lsa_policy);
-
-               if (!NT_STATUS_IS_OK(status)) {
-                       goto done;
-               }
-
-               /*
-                * This call can take a long time
-                * allow the server to time out.
-                * 35 seconds should do it.
-                */
-               orig_timeout = rpccli_set_timeout(cli, 35000);
-
-               status = rpccli_lsa_lookup_sids(cli, tmp_ctx,
-                                               &lsa_policy,
-                                               num_nocache,
-                                               sid_mem_nocache,
-                                               &domains_nocache,
-                                               &names_nocache,
-                                               &name_types_nocache);
-
-               /* And restore our original timeout. */
-               rpccli_set_timeout(cli, orig_timeout);
+               status = winbindd_lookup_sids(tmp_ctx,
+                                             domain,
+                                             num_nocache,
+                                             sid_mem_nocache,
+                                             &domains_nocache,
+                                             &names_nocache,
+                                             &name_types_nocache);
 
                if (!(NT_STATUS_IS_OK(status) ||
                      NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED) ||
@@ -1155,30 +1136,13 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
                        DEBUG(1, ("lsa_lookupsids call failed with %s "
                                  "- retrying...\n", nt_errstr(status)));
 
-                       status = cm_connect_lsa(domain, tmp_ctx, &cli,
-                                               &lsa_policy);
-
-                       if (!NT_STATUS_IS_OK(status)) {
-                               goto done;
-                       }
-
-                       /*
-                        * This call can take a long time
-                        * allow the server to time out.
-                        * 35 seconds should do it.
-                        */
-                       orig_timeout = rpccli_set_timeout(cli, 35000);
-
-                       status = rpccli_lsa_lookup_sids(cli, tmp_ctx,
-                                                       &lsa_policy,
-                                                       num_nocache,
-                                                       sid_mem_nocache,
-                                                       &domains_nocache,
-                                                       &names_nocache,
-                                                       &name_types_nocache);
-
-                       /* And restore our original timeout. */
-                       rpccli_set_timeout(cli, orig_timeout);
+                       status = winbindd_lookup_sids(tmp_ctx,
+                                                     domain,
+                                                     num_nocache,
+                                                     sid_mem_nocache,
+                                                     &domains_nocache,
+                                                     &names_nocache,
+                                                     &name_types_nocache);
                }
 
                if (NT_STATUS_IS_OK(status) ||
index 384395f89648b06fc8da5fb69a1c304bec1566ed..ad8018253c54b87355e594dab7c8fca495fae598 100644 (file)
@@ -71,6 +71,15 @@ int main(int argc, char **argv, char **envp);
 
 /* The following definitions come from winbindd/winbindd_ads.c  */
 
+/* The following definitions come from winbindd/winbindd_rpc.c  */
+
+NTSTATUS winbindd_lookup_sids(TALLOC_CTX *mem_ctx,
+                             struct winbindd_domain *domain,
+                             uint32_t num_sids,
+                             const struct dom_sid *sids,
+                             char ***domains,
+                             char ***names,
+                             enum lsa_SidType **types);
 
 /* The following definitions come from winbindd/winbindd_async.c  */
 
index 38b20d847940c9c5f863fcc75890a6bb9c1df2bb..255db612b29477aec6fd8b5d99f3a334fa49b928 100644 (file)
@@ -353,42 +353,26 @@ static NTSTATUS msrpc_sid_to_name(struct winbindd_domain *domain,
        char **names;
        enum lsa_SidType *types = NULL;
        NTSTATUS result;
-       struct rpc_pipe_client *cli;
-       struct policy_handle lsa_policy;
        NTSTATUS name_map_status = NT_STATUS_UNSUCCESSFUL;
        char *mapped_name = NULL;
-       unsigned int orig_timeout;
 
        DEBUG(3,("sid_to_name [rpc] %s for domain %s\n", sid_string_dbg(sid),
                 domain->name ));
 
-       result = cm_connect_lsa(domain, mem_ctx, &cli, &lsa_policy);
+       result = winbindd_lookup_sids(mem_ctx,
+                                     domain,
+                                     1,
+                                     sid,
+                                     &domains,
+                                     &names,
+                                     &types);
        if (!NT_STATUS_IS_OK(result)) {
-               DEBUG(2,("msrpc_sid_to_name: cm_connect_lsa() failed (%s)\n",
-                        nt_errstr(result)));           
+               DEBUG(2,("msrpc_sid_to_name: failed to lookup sids: %s\n",
+                       nt_errstr(result)));
                return result;
        }
        
 
-       /*
-        * This call can take a long time
-        * allow the server to time out.
-        * 35 seconds should do it.
-        */
-       orig_timeout = rpccli_set_timeout(cli, 35000);
-
-       result = rpccli_lsa_lookup_sids(cli, mem_ctx, &lsa_policy,
-                                       1, sid, &domains, &names, &types);
-
-       /* And restore our original timeout. */
-       rpccli_set_timeout(cli, orig_timeout);
-
-       if (!NT_STATUS_IS_OK(result)) {         
-               DEBUG(2,("msrpc_sid_to_name: rpccli_lsa_lookup_sids()  failed (%s)\n",
-                        nt_errstr(result)));           
-               return result;
-       }
-
        *type = (enum lsa_SidType)types[0];
        *domain_name = domains[0];
        *name = names[0];
@@ -418,12 +402,9 @@ static NTSTATUS msrpc_rids_to_names(struct winbindd_domain *domain,
 {
        char **domains;
        NTSTATUS result;
-       struct rpc_pipe_client *cli;
-       struct policy_handle lsa_policy;
        DOM_SID *sids;
        size_t i;
        char **ret_names;
-       unsigned int orig_timeout;
 
        DEBUG(3, ("rids_to_names [rpc] for domain %s\n", domain->name ));
 
@@ -442,24 +423,13 @@ static NTSTATUS msrpc_rids_to_names(struct winbindd_domain *domain,
                }
        }
 
-       result = cm_connect_lsa(domain, mem_ctx, &cli, &lsa_policy);
-       if (!NT_STATUS_IS_OK(result)) {
-               return result;
-       }
-
-       /*
-        * This call can take a long time
-        * allow the server to time out.
-        * 35 seconds should do it.
-        */
-       orig_timeout = rpccli_set_timeout(cli, 35000);
-
-       result = rpccli_lsa_lookup_sids(cli, mem_ctx, &lsa_policy,
-                                       num_rids, sids, &domains,
-                                       names, types);
-
-       /* And restore our original timeout. */
-       rpccli_set_timeout(cli, orig_timeout);
+       result = winbindd_lookup_sids(mem_ctx,
+                                     domain,
+                                     num_rids,
+                                     sids,
+                                     &domains,
+                                     names,
+                                     types);
 
        if (!NT_STATUS_IS_OK(result) &&
            !NT_STATUS_EQUAL(result, STATUS_SOME_UNMAPPED)) {
@@ -1222,6 +1192,45 @@ static NTSTATUS msrpc_password_policy(struct winbindd_domain *domain,
        return result;
 }
 
+NTSTATUS winbindd_lookup_sids(TALLOC_CTX *mem_ctx,
+                             struct winbindd_domain *domain,
+                             uint32_t num_sids,
+                             const struct dom_sid *sids,
+                             char ***domains,
+                             char ***names,
+                             enum lsa_SidType **types)
+{
+       NTSTATUS status;
+       struct rpc_pipe_client *cli = NULL;
+       struct policy_handle lsa_policy;
+       unsigned int orig_timeout;
+
+       status = cm_connect_lsa(domain, mem_ctx, &cli, &lsa_policy);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       /*
+        * This call can take a long time
+        * allow the server to time out.
+        * 35 seconds should do it.
+        */
+       orig_timeout = rpccli_set_timeout(cli, 35000);
+
+       status = rpccli_lsa_lookup_sids(cli, mem_ctx, &lsa_policy,
+                                       num_sids, sids, domains,
+                                       names, types);
+
+       /* And restore our original timeout. */
+       rpccli_set_timeout(cli, orig_timeout);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       return status;
+}
+
 
 /* the rpc backend methods are exposed via this structure */
 struct winbindd_methods msrpc_methods = {