summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2010-06-17 16:25:07 +0200
committerAndreas Schneider <asn@samba.org>2010-07-05 15:59:11 +0200
commit506dc899b26eea7b3115748b6311e8a07fb16909 (patch)
treee7c3e65fa8a1373d2fc509bcaf63eb08d15668a3 /source3
parent22c9ced11952bc61c0f074103b5ca9a312f53c70 (diff)
downloadsamba-506dc899b26eea7b3115748b6311e8a07fb16909.tar.gz
samba-506dc899b26eea7b3115748b6311e8a07fb16909.tar.bz2
samba-506dc899b26eea7b3115748b6311e8a07fb16909.zip
s3-winbind: Added a common rpc_sid_to_name function.
Diffstat (limited to 'source3')
-rw-r--r--source3/winbindd/winbindd_rpc.c56
-rw-r--r--source3/winbindd/winbindd_rpc.h10
2 files changed, 66 insertions, 0 deletions
diff --git a/source3/winbindd/winbindd_rpc.c b/source3/winbindd/winbindd_rpc.c
index a699fc2e14..7dc67b8398 100644
--- a/source3/winbindd/winbindd_rpc.c
+++ b/source3/winbindd/winbindd_rpc.c
@@ -310,3 +310,59 @@ NTSTATUS rpc_name_to_sid(TALLOC_CTX *mem_ctx,
return NT_STATUS_OK;
}
+
+/* Convert a domain SID to a user or group name */
+NTSTATUS rpc_sid_to_name(TALLOC_CTX *mem_ctx,
+ struct rpc_pipe_client *lsa_pipe,
+ struct policy_handle *lsa_policy,
+ struct winbindd_domain *domain,
+ const struct dom_sid *sid,
+ char **pdomain_name,
+ char **pname,
+ enum lsa_SidType *ptype)
+{
+ char *mapped_name = NULL;
+ char **domains = NULL;
+ char **names = NULL;
+ enum lsa_SidType *types = NULL;
+ NTSTATUS map_status;
+ NTSTATUS status;
+
+ status = rpccli_lsa_lookup_sids(lsa_pipe,
+ mem_ctx,
+ lsa_policy,
+ 1, /* num_sids */
+ sid,
+ &domains,
+ &names,
+ &types);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(2,("sid_to_name: failed to lookup sids: %s\n",
+ nt_errstr(status)));
+ return status;
+ }
+
+ *ptype = (enum lsa_SidType) types[0];
+
+ map_status = normalize_name_map(mem_ctx,
+ domain,
+ *pname,
+ &mapped_name);
+ if (NT_STATUS_IS_OK(map_status) ||
+ NT_STATUS_EQUAL(map_status, NT_STATUS_FILE_RENAMED)) {
+ *pname = talloc_strdup(mem_ctx, mapped_name);
+ DEBUG(5,("returning mapped name -- %s\n", *pname));
+ } else {
+ *pname = talloc_strdup(mem_ctx, names[0]);
+ }
+ if (*pname == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ *pdomain_name = talloc_strdup(mem_ctx, domains[0]);
+ if (*pdomain_name == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ return NT_STATUS_OK;
+}
diff --git a/source3/winbindd/winbindd_rpc.h b/source3/winbindd/winbindd_rpc.h
index 99006d4655..e0658a3505 100644
--- a/source3/winbindd/winbindd_rpc.h
+++ b/source3/winbindd/winbindd_rpc.h
@@ -57,4 +57,14 @@ NTSTATUS rpc_name_to_sid(TALLOC_CTX *mem_ctx,
struct dom_sid *psid,
enum lsa_SidType *ptype);
+/* Convert a domain SID to a user or group name */
+NTSTATUS rpc_sid_to_name(TALLOC_CTX *mem_ctx,
+ struct rpc_pipe_client *lsa_pipe,
+ struct policy_handle *lsa_policy,
+ struct winbindd_domain *domain,
+ const struct dom_sid *sid,
+ char **pdomain_name,
+ char **pname,
+ enum lsa_SidType *ptype);
+
#endif /* _WINBINDD_RPC_H_ */