summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/winbindd/winbindd_rpc.c63
-rw-r--r--source3/winbindd/winbindd_rpc.h10
2 files changed, 73 insertions, 0 deletions
diff --git a/source3/winbindd/winbindd_rpc.c b/source3/winbindd/winbindd_rpc.c
index eddd1882d4..a699fc2e14 100644
--- a/source3/winbindd/winbindd_rpc.c
+++ b/source3/winbindd/winbindd_rpc.c
@@ -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;
+}
diff --git a/source3/winbindd/winbindd_rpc.h b/source3/winbindd/winbindd_rpc.h
index 5ba5bf4ce5..99006d4655 100644
--- a/source3/winbindd/winbindd_rpc.h
+++ b/source3/winbindd/winbindd_rpc.h
@@ -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_ */