diff options
author | Andreas Schneider <asn@samba.org> | 2010-06-17 16:06:34 +0200 |
---|---|---|
committer | Andreas Schneider <asn@samba.org> | 2010-07-05 15:59:10 +0200 |
commit | 37dbfaebc7a31a6c44d51003770945cb4dab8848 (patch) | |
tree | 18dd0f779c3f2e38a340c77930d0ab3311ec49dc /source3/winbindd | |
parent | 01730e4b471b7ccf699f9435b87a997980156c37 (diff) | |
download | samba-37dbfaebc7a31a6c44d51003770945cb4dab8848.tar.gz samba-37dbfaebc7a31a6c44d51003770945cb4dab8848.tar.bz2 samba-37dbfaebc7a31a6c44d51003770945cb4dab8848.zip |
s3-winbind: Added a common rpc_name_to_sid function.
Diffstat (limited to 'source3/winbindd')
-rw-r--r-- | source3/winbindd/winbindd_rpc.c | 63 | ||||
-rw-r--r-- | source3/winbindd/winbindd_rpc.h | 10 |
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_ */ |