s3-winbind: Added a common rpc_rids_to_names function.
authorAndreas Schneider <asn@samba.org>
Thu, 17 Jun 2010 17:31:51 +0000 (19:31 +0200)
committerAndreas Schneider <asn@samba.org>
Mon, 5 Jul 2010 13:59:11 +0000 (15:59 +0200)
source3/winbindd/winbindd_rpc.c
source3/winbindd/winbindd_rpc.h

index 7dc67b8398ae5b99648a660680a3effffe7b3fe3..cfc9d996c9ccd491aa7530ad7b0274a73f6c43e6 100644 (file)
@@ -366,3 +366,82 @@ NTSTATUS rpc_sid_to_name(TALLOC_CTX *mem_ctx,
 
        return NT_STATUS_OK;
 }
+
+/* Convert a bunch of rids to user or group names */
+NTSTATUS rpc_rids_to_names(TALLOC_CTX *mem_ctx,
+                          struct rpc_pipe_client *lsa_pipe,
+                          struct policy_handle *lsa_policy,
+                          struct winbindd_domain *domain,
+                          const struct dom_sid *sid,
+                          uint32_t *rids,
+                          size_t num_rids,
+                          char **pdomain_name,
+                          char ***pnames,
+                          enum lsa_SidType **ptypes)
+{
+       enum lsa_SidType *types = NULL;
+       char *domain_name = NULL;
+       char **domains = NULL;
+       char **names = NULL;
+       struct dom_sid *sids;
+       size_t i;
+       NTSTATUS status;
+
+       if (num_rids > 0) {
+               sids = TALLOC_ARRAY(mem_ctx, struct dom_sid, num_rids);
+               if (sids == NULL) {
+                       return NT_STATUS_NO_MEMORY;
+               }
+       } else {
+               sids = NULL;
+       }
+
+       for (i = 0; i < num_rids; i++) {
+               if (!sid_compose(&sids[i], sid, rids[i])) {
+                       return NT_STATUS_INTERNAL_ERROR;
+               }
+       }
+
+       status = rpccli_lsa_lookup_sids(lsa_pipe,
+                                       mem_ctx,
+                                       lsa_policy,
+                                       num_rids,
+                                       sids,
+                                       &domains,
+                                       &names,
+                                       &types);
+       if (!NT_STATUS_IS_OK(status) &&
+           !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
+               DEBUG(2,("rids_to_names: failed to lookup sids: %s\n",
+                       nt_errstr(status)));
+               return status;
+       }
+
+       for (i = 0; i < num_rids; i++) {
+               char *mapped_name = NULL;
+               NTSTATUS map_status;
+
+               if (types[i] != SID_NAME_UNKNOWN) {
+                       map_status = normalize_name_map(mem_ctx,
+                                                       domain,
+                                                       names[i],
+                                                       &mapped_name);
+                       if (NT_STATUS_IS_OK(map_status) ||
+                           NT_STATUS_EQUAL(map_status, NT_STATUS_FILE_RENAMED)) {
+                               TALLOC_FREE(names[i]);
+                               names[i] = talloc_strdup(names, mapped_name);
+                               if (names[i] == NULL) {
+                                       return NT_STATUS_NO_MEMORY;
+                               }
+                       }
+
+                       domain_name = domains[i];
+               }
+       }
+
+       *pdomain_name = domain_name;
+       *ptypes = types;
+       *pnames = names;
+
+       return NT_STATUS_OK;
+}
index e0658a350589f0e032afc6436d92f53ca5209745..15ad6dab8939704c390bd0c146b61bc1aeb1d2a9 100644 (file)
@@ -67,4 +67,16 @@ NTSTATUS rpc_sid_to_name(TALLOC_CTX *mem_ctx,
                         char **pname,
                         enum lsa_SidType *ptype);
 
+/* Convert a bunch of rids to user or group names */
+NTSTATUS rpc_rids_to_names(TALLOC_CTX *mem_ctx,
+                          struct rpc_pipe_client *lsa_pipe,
+                          struct policy_handle *lsa_policy,
+                          struct winbindd_domain *domain,
+                          const struct dom_sid *sid,
+                          uint32_t *rids,
+                          size_t num_rids,
+                          char **pdomain_name,
+                          char ***pnames,
+                          enum lsa_SidType **ptypes);
+
 #endif /* _WINBINDD_RPC_H_ */