s3-winbind: Added a common rpc_name_to_sid function.
authorAndreas Schneider <asn@samba.org>
Thu, 17 Jun 2010 14:06:34 +0000 (16:06 +0200)
committerAndreas Schneider <asn@samba.org>
Mon, 5 Jul 2010 13:59:10 +0000 (15:59 +0200)
source3/winbindd/winbindd_rpc.c
source3/winbindd/winbindd_rpc.h

index eddd1882d4055736fee9af93051927aa79d7a454..a699fc2e143a345eda392f6306b9ac58a82f3b5b 100644 (file)
@@ -247,3 +247,66 @@ NTSTATUS rpc_enum_local_groups(TALLOC_CTX *mem_ctx,
 
        return NT_STATUS_OK;
 }
+
+/* convert a single name to a sid in a domain */
+NTSTATUS rpc_name_to_sid(TALLOC_CTX *mem_ctx,
+                        struct rpc_pipe_client *lsa_pipe,
+                        struct policy_handle *lsa_policy,
+                        const char *domain_name,
+                        const char *name,
+                        uint32_t flags,
+                        struct dom_sid *sid,
+                        enum lsa_SidType *type)
+{
+       enum lsa_SidType *types = NULL;
+       struct dom_sid *sids = NULL;
+       char *full_name = NULL;
+       char *mapped_name = NULL;
+       NTSTATUS status;
+
+       if (name == NULL || name[0] == '\0') {
+               full_name = talloc_asprintf(mem_ctx, "%s", domain_name);
+       } else if (domain_name == NULL || domain_name[0] == '\0') {
+               full_name = talloc_asprintf(mem_ctx, "%s", name);
+       } else {
+               full_name = talloc_asprintf(mem_ctx, "%s\\%s", domain_name, name);
+       }
+
+       if (full_name == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       status = normalize_name_unmap(mem_ctx, full_name, &mapped_name);
+       /* Reset the full_name pointer if we mapped anything */
+       if (NT_STATUS_IS_OK(status) ||
+           NT_STATUS_EQUAL(status, NT_STATUS_FILE_RENAMED)) {
+               full_name = mapped_name;
+       }
+
+       DEBUG(3,("name_to_sid: %s for domain %s\n",
+                full_name ? full_name : "", domain_name ));
+
+       /*
+        * We don't run into deadlocks here, cause winbind_off() is
+        * called in the main function.
+        */
+       status = rpccli_lsa_lookup_names(lsa_pipe,
+                                        mem_ctx,
+                                        lsa_policy,
+                                        1, /* num_names */
+                                        (const char **) &full_name,
+                                        NULL, /* domains */
+                                        1, /* level */
+                                        &sids,
+                                        &types);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(2,("name_to_sid: failed to lookup name: %s\n",
+                       nt_errstr(status)));
+               return status;
+       }
+
+       sid_copy(sid, &sids[0]);
+       *type = types[0];
+
+       return NT_STATUS_OK;
+}
index 5ba5bf4ce5558b0b0ec0f9c22b5ef2d35542861d..99006d465532f7811ad4e7f00bb38e1208a33a0e 100644 (file)
@@ -47,4 +47,14 @@ NTSTATUS rpc_enum_local_groups(TALLOC_CTX *mem_ctx,
                               uint32_t *pnum_info,
                               struct acct_info **pinfo);
 
+/* Convert a single name to a sid in a domain */
+NTSTATUS rpc_name_to_sid(TALLOC_CTX *mem_ctx,
+                        struct rpc_pipe_client *lsa_pipe,
+                        struct policy_handle *lsa_policy,
+                        const char *domain_name,
+                        const char *name,
+                        uint32_t flags,
+                        struct dom_sid *psid,
+                        enum lsa_SidType *ptype);
+
 #endif /* _WINBINDD_RPC_H_ */