[SCM] Samba Shared Repository - branch master updated
Kai Blin
kai at samba.org
Thu Feb 11 16:06:30 MST 2010
The branch, master has been updated
via 4ff7f6e... s3 test: Make the netbios name test pass again
via ea055e8... s4: Switch to S3-style id mapping data types.
via 86d70ae... s4 idmap: Make the sid_to_xid and xid_to_sid calls static.
via 5d84805... libwbclient: Test wbcLookupName async functions
via cf96837... libwbclient: Implement wbcLookupName_send/recv
via 145f2c7... libwbclient: Implement wbcAuthenticateUserEx_send/recv
via 749fb03... libwbclient: Implement wbcLookupSid_send/recv
via 5788672... libwbclient: Implement wbcGidToSid_send/recv
via ada6e26... libwbclient: Implement wbcSidToGid_send/recv
via 446b4aa... libwbclient: Implement wbcUidToSid_send/recv
via 4ff1906... libwbclient: Implement wbcSidToUid_send/recv
via 33bbe1c... libwbclient: Add wbcInterfaceDetails_send/recv
via 861ef36... libwbclient: Add wbcDomainInfo_send/recv calls
via 99c0f56... libwbclient: Add wbcDomainName_send/recv call
via 7cb070f... libwbclient: Add wbcNetbiosName_send/recv calls
via fd6b145... libwbclient: Add async wbcInfo_send()/wbcInfo_recv() calls
via a089522... libwbclient: add wbcInterfaceVersion send/recv calls
via 1ca7274... libwbclient: torture-test wbcPing async functions.
via 3204113... libwbclient: Add async wbcPing_send/_recv
via f9d041c... libwbclient: Zero out context on initialization
from 02a5078... Final part of jumbo patch for bug #7104 - "wide links" and "unix extensions" are incompatible.
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 4ff7f6ed3634f9a45b1ebdc965152bbada72b49d
Author: Kai Blin <kai at samba.org>
Date: Tue Feb 2 15:18:01 2010 +0100
s3 test: Make the netbios name test pass again
commit ea055e8c7905ec5d229fd5b50ca9ec8f60073b53
Author: Kai Blin <kai at samba.org>
Date: Thu Apr 23 16:37:11 2009 +0200
s4: Switch to S3-style id mapping data types.
commit 86d70ae94425c34fcb7cc7791a6e54b1a47f21cc
Author: Kai Blin <kai at samba.org>
Date: Wed Apr 22 18:10:12 2009 +0200
s4 idmap: Make the sid_to_xid and xid_to_sid calls static.
Looking at the winbind interface, we should only be using the bulk conversion calls.
commit 5d848053a7f62519beed6b5ac7fb0076ae8fa9e3
Author: Kai Blin <kai at samba.org>
Date: Fri Jan 29 12:09:18 2010 +0100
libwbclient: Test wbcLookupName async functions
commit cf968371ef207719424d2eb58dbddcf0d0c7952d
Author: Kai Blin <kai at samba.org>
Date: Thu May 28 00:57:32 2009 +0200
libwbclient: Implement wbcLookupName_send/recv
commit 145f2c751b5de2864a472363cb478596c5040ee4
Author: Kai Blin <kai at samba.org>
Date: Thu May 28 00:55:57 2009 +0200
libwbclient: Implement wbcAuthenticateUserEx_send/recv
commit 749fb039719e60d82c496a2e1587bfa32d0360b8
Author: Kai Blin <kai at samba.org>
Date: Fri Apr 24 16:24:56 2009 +0200
libwbclient: Implement wbcLookupSid_send/recv
commit 57886720bb1a0e93d8903a0fa677f3820fa3cb07
Author: Kai Blin <kai at samba.org>
Date: Thu Apr 2 09:45:39 2009 +0200
libwbclient: Implement wbcGidToSid_send/recv
commit ada6e26d5e6bacaacbe9cdebdabe41c383e5f8c8
Author: Kai Blin <kai at samba.org>
Date: Thu Apr 2 09:22:43 2009 +0200
libwbclient: Implement wbcSidToGid_send/recv
commit 446b4aa17c03993a0fa0c77bd7e8bdec938be991
Author: Kai Blin <kai at samba.org>
Date: Thu Apr 2 09:57:40 2009 +0200
libwbclient: Implement wbcUidToSid_send/recv
commit 4ff1906357659a040aa90bcd51dd1974ec405001
Author: Kai Blin <kai at samba.org>
Date: Tue Mar 31 23:10:48 2009 +0200
libwbclient: Implement wbcSidToUid_send/recv
commit 33bbe1cafda93d493509f5dabfdb0ed7bbe69a71
Author: Kai Blin <kai at samba.org>
Date: Sun Feb 15 11:01:44 2009 +0100
libwbclient: Add wbcInterfaceDetails_send/recv
commit 861ef367c839d44b185ae3dd9191e849a5e33027
Author: Kai Blin <kai at samba.org>
Date: Sat Feb 14 10:06:05 2009 +0100
libwbclient: Add wbcDomainInfo_send/recv calls
commit 99c0f569f9a62b63e1d26418a777302b03c3fc7f
Author: Kai Blin <kai at samba.org>
Date: Fri Feb 13 22:51:52 2009 +0100
libwbclient: Add wbcDomainName_send/recv call
commit 7cb070f2b346ed486ee24926965290890f72786f
Author: Kai Blin <kai at samba.org>
Date: Fri Feb 13 22:37:56 2009 +0100
libwbclient: Add wbcNetbiosName_send/recv calls
commit fd6b1457935e3d6e156a85cce27aae43b3475723
Author: Kai Blin <kai at samba.org>
Date: Wed Mar 25 10:08:10 2009 +0100
libwbclient: Add async wbcInfo_send()/wbcInfo_recv() calls
commit a0895222be4e0227f26a625474c89fdf5aa9875c
Author: Kai Blin <kai at samba.org>
Date: Thu Feb 12 00:11:45 2009 +0100
libwbclient: add wbcInterfaceVersion send/recv calls
commit 1ca727420a0d2f3d0f4a14b06c1a8d1ea6c40339
Author: Kai Blin <kai at samba.org>
Date: Fri Jan 29 11:22:14 2010 +0100
libwbclient: torture-test wbcPing async functions.
commit 3204113efe0eccbb502914699cb5a4ddcf4efdfa
Author: Kai Blin <kai at samba.org>
Date: Tue Mar 24 22:51:11 2009 +0100
libwbclient: Add async wbcPing_send/_recv
commit f9d041ccd358f6e91a44369c70eebcbf605de2cd
Author: Kai Blin <kai at samba.org>
Date: Fri Jan 29 11:54:33 2010 +0100
libwbclient: Zero out context on initialization
This prevents a segfault when using wbcDebug without prior call to wbcSetDebug
-----------------------------------------------------------------------
Summary of changes:
nsswitch/libwbclient/tests/wbclient.c | 99 +++
nsswitch/libwbclient/wbc_async.c | 2 +-
nsswitch/libwbclient/wbc_async.h | 105 ++++
nsswitch/libwbclient/wbc_idmap.c | 422 +++++++++++++
nsswitch/libwbclient/wbc_pam.c | 270 ++++++++
nsswitch/libwbclient/wbc_sid.c | 258 ++++++++
nsswitch/libwbclient/wbc_util.c | 826 ++++++++++++++++++++++++-
nsswitch/libwbclient/wbclient.h | 11 +-
source3/selftest/tests.sh | 2 +
source4/libcli/wbclient/wbclient.c | 10 +-
source4/libcli/wbclient/wbclient.h | 8 +-
source4/librpc/idl/winbind.idl | 13 +-
source4/ntvfs/posix/pvfs_acl.c | 18 +-
source4/ntvfs/posix/pvfs_acl_nfs4.c | 16 +-
source4/ntvfs/unixuid/vfs_unixuid.c | 10 +-
source4/rpc_server/unixinfo/dcesrv_unixinfo.c | 24 +-
source4/winbind/idmap.c | 40 +-
source4/winbind/wb_gid2sid.c | 10 +-
source4/winbind/wb_sid2gid.c | 10 +-
source4/winbind/wb_sid2uid.c | 10 +-
source4/winbind/wb_sids2xids.c | 6 +-
source4/winbind/wb_uid2sid.c | 10 +-
source4/winbind/wb_xids2sids.c | 6 +-
23 files changed, 2092 insertions(+), 94 deletions(-)
Changeset truncated at 500 lines:
diff --git a/nsswitch/libwbclient/tests/wbclient.c b/nsswitch/libwbclient/tests/wbclient.c
index 9e4c348..6d4ea86 100644
--- a/nsswitch/libwbclient/tests/wbclient.c
+++ b/nsswitch/libwbclient/tests/wbclient.c
@@ -19,6 +19,7 @@
#include "includes.h"
#include "nsswitch/libwbclient/wbclient.h"
+#include "nsswitch/libwbclient/wbc_async.h"
#include "torture/smbtorture.h"
#include "torture/winbind/proto.h"
@@ -35,6 +36,17 @@
#define torture_assert_wbc_ok(torture_ctx,expr,cmt) \
torture_assert_wbc_equal(torture_ctx,expr,WBC_ERR_SUCCESS,cmt)
+
+static void wbc_debug_torture(void *private_data, enum wbcDebugLevel level,
+ const char *fmt, va_list ap) PRINTF_ATTRIBUTE(3,0);
+static void wbc_debug_torture(void *private_data, enum wbcDebugLevel level,
+ const char *fmt, va_list ap)
+{
+ struct torture_context *tctx = talloc_get_type_abort(private_data,
+ struct torture_context);
+ torture_comment(tctx, "%s", talloc_vasprintf(tctx, fmt, ap));
+}
+
static bool test_wbc_ping(struct torture_context *tctx)
{
torture_assert_wbc_ok(tctx, wbcPing(),
@@ -43,6 +55,24 @@ static bool test_wbc_ping(struct torture_context *tctx)
return true;
}
+static bool test_wbc_ping_async(struct torture_context *tctx)
+{
+ struct wb_context *wb_ctx;
+ struct tevent_req *req;
+
+ wb_ctx = wb_context_init(tctx, NULL);
+
+ req = wbcPing_send(tctx, tctx->ev, wb_ctx);
+ torture_assert(tctx, req, "wbcPing_send failed");
+
+ if(!tevent_req_poll(req, tctx->ev)) {
+ return false;
+ }
+ torture_assert_wbc_ok(tctx, wbcPing_recv(req), "wbcPing_recv failed");
+ return true;
+}
+
+
static bool test_wbc_pingdc(struct torture_context *tctx)
{
torture_assert_wbc_equal(tctx, wbcPingDc("random_string", NULL), WBC_ERR_NOT_IMPLEMENTED,
@@ -202,6 +232,73 @@ static bool test_wbc_users(struct torture_context *tctx)
return true;
}
+static bool test_wbc_users_async(struct torture_context *tctx)
+{
+ struct wb_context *wb_ctx;
+ struct tevent_req *req;
+ const char *domain_name = NULL;
+ uint32_t num_users;
+ const char **users;
+ int i;
+ struct wbcInterfaceDetails *details;
+
+ wb_ctx = wb_context_init(tctx, NULL);
+ wbcSetDebug(wb_ctx, wbc_debug_torture, tctx);
+
+ req = wbcInterfaceDetails_send(tctx, tctx->ev, wb_ctx);
+ torture_assert(tctx, req, "wbcInterfaceDetails_send failed");
+
+ if(!tevent_req_poll(req, tctx->ev)) {
+ return false;
+ }
+ torture_assert_wbc_ok(tctx,
+ wbcInterfaceDetails_recv(req, tctx, &details),
+ "wbcInterfaceDetails_recv failed");
+
+ domain_name = talloc_strdup(tctx, details->netbios_domain);
+ wbcFreeMemory(details);
+
+ /* No async implementation of this yet. */
+ torture_assert_wbc_ok(tctx, wbcListUsers(domain_name, &num_users, &users),
+ "wbcListUsers failed");
+ torture_assert(tctx, !(num_users > 0 && !users),
+ "wbcListUsers returned invalid results");
+
+ for (i=0; i < MIN(num_users,100); i++) {
+
+ struct wbcDomainSid sid, *sids;
+ enum wbcSidType name_type;
+ char *domain;
+ char *name;
+ uint32_t num_sids;
+
+ req = wbcLookupName_send(tctx, tctx->ev, wb_ctx, domain_name,
+ users[i]);
+ torture_assert(tctx, req, "wbcLookupName_send failed");
+
+ if(!tevent_req_poll(req, tctx->ev)) {
+ return false;
+ }
+
+ torture_assert_wbc_ok(tctx,
+ wbcLookupName_recv(req, &sid, &name_type),
+ "wbcLookupName_recv failed");
+
+ torture_assert_int_equal(tctx, name_type, WBC_SID_NAME_USER,
+ "wbcLookupName expected WBC_SID_NAME_USER");
+ torture_assert_wbc_ok(tctx, wbcLookupSid(&sid, &domain, &name, &name_type),
+ "wbcLookupSid failed");
+ torture_assert_int_equal(tctx, name_type, WBC_SID_NAME_USER,
+ "wbcLookupSid expected WBC_SID_NAME_USER");
+ torture_assert(tctx, name,
+ "wbcLookupSid returned no name");
+ torture_assert_wbc_ok(tctx, wbcLookupUserSids(&sid, true, &num_sids, &sids),
+ "wbcLookupUserSids failed");
+ }
+
+ return true;
+}
+
static bool test_wbc_groups(struct torture_context *tctx)
{
const char *domain_name = NULL;
@@ -353,6 +450,7 @@ struct torture_suite *torture_wbclient(void)
struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "WBCLIENT");
torture_suite_add_simple_test(suite, "wbcPing", test_wbc_ping);
+ torture_suite_add_simple_test(suite, "wbcPing_async", test_wbc_ping_async);
torture_suite_add_simple_test(suite, "wbcPingDc", test_wbc_pingdc);
torture_suite_add_simple_test(suite, "wbcLibraryDetails", test_wbc_library_details);
torture_suite_add_simple_test(suite, "wbcInterfaceDetails", test_wbc_interface_details);
@@ -361,6 +459,7 @@ struct torture_suite *torture_wbclient(void)
torture_suite_add_simple_test(suite, "wbcGuidToString", test_wbc_guidtostring);
torture_suite_add_simple_test(suite, "wbcDomainInfo", test_wbc_domain_info);
torture_suite_add_simple_test(suite, "wbcListUsers", test_wbc_users);
+ torture_suite_add_simple_test(suite, "wbcListUsers_async", test_wbc_users_async);
torture_suite_add_simple_test(suite, "wbcListGroups", test_wbc_groups);
torture_suite_add_simple_test(suite, "wbcListTrusts", test_wbc_trusts);
torture_suite_add_simple_test(suite, "wbcLookupDomainController", test_wbc_lookupdc);
diff --git a/nsswitch/libwbclient/wbc_async.c b/nsswitch/libwbclient/wbc_async.c
index 181d546..d1dd76d 100644
--- a/nsswitch/libwbclient/wbc_async.c
+++ b/nsswitch/libwbclient/wbc_async.c
@@ -192,7 +192,7 @@ struct wb_context *wb_context_init(TALLOC_CTX *mem_ctx, const char* dir)
{
struct wb_context *result;
- result = talloc(mem_ctx, struct wb_context);
+ result = talloc_zero(mem_ctx, struct wb_context);
if (result == NULL) {
return NULL;
}
diff --git a/nsswitch/libwbclient/wbc_async.h b/nsswitch/libwbclient/wbc_async.h
index 76e02ca..c918ccb 100644
--- a/nsswitch/libwbclient/wbc_async.h
+++ b/nsswitch/libwbclient/wbc_async.h
@@ -92,4 +92,109 @@ struct tevent_req *wb_simple_trans_send(TALLOC_CTX *mem_ctx,
int wb_simple_trans_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
struct winbindd_response **presponse, int *err);
+/* Async functions from wbc_idmap.c */
+
+struct tevent_req *wbcSidToUid_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct wb_context *wb_ctx,
+ const struct wbcDomainSid *sid);
+wbcErr wbcSidToUid_recv(struct tevent_req *req, uid_t *puid);
+
+struct tevent_req *wbcUidToSid_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct wb_context *wb_ctx,
+ uid_t uid);
+wbcErr wbcUidToSid_recv(struct tevent_req *req, struct wbcDomainSid *psid);
+
+struct tevent_req *wbcSidToGid_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct wb_context *wb_ctx,
+ const struct wbcDomainSid *sid);
+wbcErr wbcSidToGid_recv(struct tevent_req *req, gid_t *pgid);
+
+struct tevent_req *wbcGidToSid_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct wb_context *wb_ctx,
+ gid_t gid);
+wbcErr wbcGidToSid_recv(struct tevent_req *req, struct wbcDomainSid *psid);
+
+/* Async functions from wbc_pam.c */
+struct tevent_req *wbcAuthenticateUserEx_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct wb_context *wb_ctx,
+ const struct wbcAuthUserParams *params);
+wbcErr wbcAuthenticateUserEx_recv(struct tevent_req *req,
+ TALLOC_CTX *mem_ctx,
+ struct wbcAuthUserInfo **info,
+ struct wbcAuthErrorInfo **error);
+
+/* Async functions from wbc_sid.c */
+struct tevent_req *wbcLookupName_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct wb_context *wb_ctx,
+ const char *domain,
+ const char *name);
+wbcErr wbcLookupName_recv(struct tevent_req *req,
+ struct wbcDomainSid *sid,
+ enum wbcSidType *name_type);
+struct tevent_req *wbcLookupSid_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct wb_context *wb_ctx,
+ const struct wbcDomainSid *sid);
+wbcErr wbcLookupSid_recv(struct tevent_req *req,
+ TALLOC_CTX *mem_ctx,
+ char **pdomain,
+ char **pname,
+ enum wbcSidType *pname_type);
+
+/* Async functions from wbc_util.c */
+
+struct tevent_req *wbcPing_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct wb_context *wb_ctx);
+wbcErr wbcPing_recv(struct tevent_req *req);
+
+struct tevent_req *wbcInterfaceVersion_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct wb_context *wb_ctx);
+wbcErr wbcInterfaceVersion_recv(struct tevent_req *req,
+ uint32_t *interface_version);
+
+struct tevent_req *wbcInfo_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct wb_context *wb_ctx);
+wbcErr wbcInfo_recv(struct tevent_req *req,
+ TALLOC_CTX *mem_ctx,
+ char *winbind_separator,
+ char **version_string);
+
+struct tevent_req *wbcNetbiosName_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct wb_context *wb_ctx);
+wbcErr wbcNetbiosName_recv(struct tevent_req *req,
+ TALLOC_CTX *mem_ctx,
+ char **netbios_name);
+
+struct tevent_req *wbcDomainName_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct wb_context *wb_ctx);
+wbcErr wbcDomainName_recv(struct tevent_req *req,
+ TALLOC_CTX *mem_ctx,
+ char **netbios_name);
+
+struct tevent_req *wbcInterfaceDetails_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct wb_context *wb_ctx);
+wbcErr wbcInterfaceDetails_recv(struct tevent_req *req,
+ TALLOC_CTX *mem_ctx,
+ struct wbcInterfaceDetails **details);
+
+struct tevent_req *wbcDomainInfo_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct wb_context *wb_ctx,
+ const char *domain);
+wbcErr wbcDomainInfo_recv(struct tevent_req *req,
+ TALLOC_CTX *mem_ctx,
+ struct wbcDomainInfo **dinfo);
+
#endif /*_WBC_ASYNC_H_*/
diff --git a/nsswitch/libwbclient/wbc_idmap.c b/nsswitch/libwbclient/wbc_idmap.c
index 10a02fd..e1bb6f2 100644
--- a/nsswitch/libwbclient/wbc_idmap.c
+++ b/nsswitch/libwbclient/wbc_idmap.c
@@ -4,6 +4,7 @@
Winbind client API
Copyright (C) Gerald (Jerry) Carter 2007
+ Copyright (C) Kai Blin 2009
This library is free software; you can redistribute it and/or
@@ -25,6 +26,105 @@
#include "replace.h"
#include "libwbclient.h"
+struct wbc_sid_to_uid_state {
+ struct winbindd_request req;
+ uid_t uid;
+};
+
+static void wbcSidToUid_done(struct tevent_req *subreq);
+
+/**
+ * @brief Convert a Windows SID to a Unix uid, allocating an uid if needed
+ *
+ * @param mem_ctx talloc context to allocate the request from
+ * @param ev tevent context to use for async operation
+ * @param wb_ctx winbind context to use
+ * @param *sid pointer to the domain SID to be resolved
+ *
+ * @return tevent_req on success, NULL on error
+ */
+
+struct tevent_req *wbcSidToUid_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct wb_context *wb_ctx,
+ const struct wbcDomainSid *sid)
+{
+ struct tevent_req *req, *subreq;
+ struct wbc_sid_to_uid_state *state;
+ char *sid_string;
+ wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+
+ req = tevent_req_create(mem_ctx, &state, struct wbc_sid_to_uid_state);
+ if (req == NULL) {
+ return NULL;
+ }
+
+ ZERO_STRUCT(state->req);
+
+ state->req.cmd = WINBINDD_SID_TO_UID;
+ wbc_status = wbcSidToString(sid, &sid_string);
+ if (!WBC_ERROR_IS_OK(wbc_status)) {
+ return tevent_req_post(req, ev);
+ }
+ strncpy(state->req.data.sid, sid_string, sizeof(state->req.data.sid)-1);
+ wbcFreeMemory(sid_string);
+
+ subreq = wb_trans_send(state, ev, wb_ctx, false, &state->req);
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
+ }
+
+ tevent_req_set_callback(subreq, wbcSidToUid_done, req);
+ return req;
+}
+
+static void wbcSidToUid_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct wbc_sid_to_uid_state *state = tevent_req_data(
+ req, struct wbc_sid_to_uid_state);
+ struct winbindd_response *resp;
+ wbcErr wbc_status;
+
+ wbc_status = wb_trans_recv(subreq, state, &resp);
+ TALLOC_FREE(subreq);
+ if (!WBC_ERROR_IS_OK(wbc_status)) {
+ tevent_req_error(req, wbc_status);
+ return;
+ }
+ state->uid = resp->data.uid;
+ TALLOC_FREE(resp);
+
+ tevent_req_done(req);
+}
+
+/**
+ * @brief Receive a Unix uid mapped to a Windows SID
+ *
+ * @param req tevent_req containing the request
+ * @param *puid pointer to hold the resolved uid_t value
+ *
+ * @return #wbcErr
+ */
+
+wbcErr wbcSidToUid_recv(struct tevent_req *req, uid_t *puid)
+{
+ struct wbc_sid_to_uid_state *state = tevent_req_data(
+ req, struct wbc_sid_to_uid_state);
+ wbcErr wbc_status;
+
+ if (tevent_req_is_wbcerr(req, &wbc_status)) {
+ tevent_req_received(req);
+ return wbc_status;
+ }
+
+ *puid = state->uid;
+
+ tevent_req_received(req);
+ return WBC_ERR_SUCCESS;
+}
+
/* Convert a Windows SID to a Unix uid, allocating an uid if needed */
wbcErr wbcSidToUid(const struct wbcDomainSid *sid, uid_t *puid)
{
@@ -71,6 +171,116 @@ wbcErr wbcQuerySidToUid(const struct wbcDomainSid *sid,
return WBC_ERR_NOT_IMPLEMENTED;
}
+struct wbc_uid_to_sid_state {
+ struct winbindd_request req;
+ struct wbcDomainSid *sid;
+};
+
+static void wbcUidToSid_done(struct tevent_req *subreq);
+
+/**
+ * @brief Request a Windows SID for an Unix uid, allocating an SID if needed
+ *
+ * @param mem_ctx talloc context to allocate the request from
+ * @param ev tevent context to use for async operation
+ * @param wb_ctx winbind context to use
+ * @param uid uid to be resolved to a SID
+ *
+ * @return tevent_req on success, NULL on error
+ */
+
+struct tevent_req *wbcUidToSid_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct wb_context *wb_ctx,
+ uid_t uid)
+{
+ struct tevent_req *req, *subreq;
+ struct wbc_uid_to_sid_state *state;
+
+ req = tevent_req_create(mem_ctx, &state, struct wbc_uid_to_sid_state);
+ if (req == NULL) {
+ return NULL;
+ }
+
+ ZERO_STRUCT(state->req);
+
+ state->req.cmd = WINBINDD_UID_TO_SID;
+ state->req.data.uid = uid;
+
+ subreq = wb_trans_send(state, ev, wb_ctx, false, &state->req);
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
+ }
+
+ tevent_req_set_callback(subreq, wbcUidToSid_done, req);
+ return req;
+}
+
+static void wbcUidToSid_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct wbc_uid_to_sid_state *state = tevent_req_data(
+ req, struct wbc_uid_to_sid_state);
+ struct winbindd_response *resp;
+ wbcErr wbc_status;
+
+ wbc_status = wb_trans_recv(subreq, state, &resp);
+ TALLOC_FREE(subreq);
+ if (!WBC_ERROR_IS_OK(wbc_status)) {
+ tevent_req_error(req, wbc_status);
+ return;
+ }
+
+ state->sid = talloc(state, struct wbcDomainSid);
+ if (state->sid == NULL) {
+ TALLOC_FREE(resp);
+ tevent_req_error(req, WBC_ERR_NO_MEMORY);
+ return;
+ }
+
+ wbc_status = wbcStringToSid(resp->data.sid.sid, state->sid);
+ TALLOC_FREE(resp);
+
+ if (!WBC_ERROR_IS_OK(wbc_status)) {
+ tevent_req_error(req, wbc_status);
+ return;
+ }
+
+ tevent_req_done(req);
+}
+
+/**
+ * @brief Receive a Unix uid mapped to a Windows SID
+ *
+ * @param req tevent_req containing the request
+ * @param *psid pointer to hold the resolved SID
+ *
+ * @return #wbcErr
+ */
+
+wbcErr wbcUidToSid_recv(struct tevent_req *req, struct wbcDomainSid *psid)
+{
+ struct wbc_uid_to_sid_state *state = tevent_req_data(
+ req, struct wbc_uid_to_sid_state);
+ wbcErr wbc_status;
+
+ if (psid == NULL) {
+ tevent_req_received(req);
+ return WBC_ERR_INVALID_PARAM;
+ }
+
+ if (tevent_req_is_wbcerr(req, &wbc_status)) {
+ tevent_req_received(req);
+ return wbc_status;
+ }
+
+ memcpy(psid, state->sid, sizeof(struct wbcDomainSid));
+
--
Samba Shared Repository
More information about the samba-cvs
mailing list