summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2009-08-04 14:07:44 -0400
committerVolker Lendecke <vl@samba.org>2009-08-05 03:21:22 -0400
commit9b369ffcf0f113871b00de4229432a74fe436834 (patch)
tree23a447f5396ecd190f7628815362eb95746ee8c1
parent3eff8e93e283828afdb3413aec2dae5c01b101b3 (diff)
downloadsamba-9b369ffcf0f113871b00de4229432a74fe436834.tar.gz
samba-9b369ffcf0f113871b00de4229432a74fe436834.tar.bz2
samba-9b369ffcf0f113871b00de4229432a74fe436834.zip
s3:winbind: Convert WINBINDD_UID_TO_SID the new API
-rw-r--r--source3/Makefile.in1
-rw-r--r--source3/winbindd/winbindd.c3
-rw-r--r--source3/winbindd/winbindd_proto.h6
-rw-r--r--source3/winbindd/winbindd_sid.c58
-rw-r--r--source3/winbindd/winbindd_uid_to_sid.c87
5 files changed, 96 insertions, 59 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in
index 50e9ebf56d..48f6a9ad2e 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -1161,6 +1161,7 @@ WINBINDD_OBJ1 = \
winbindd/winbindd_lookupname.o \
winbindd/winbindd_sid_to_uid.o \
winbindd/winbindd_sid_to_gid.o \
+ winbindd/winbindd_uid_to_sid.o \
auth/token_util.o \
../nsswitch/libwbclient/wb_reqtrans.o \
smbd/connection.o
diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c
index 0f320850d2..9af63ff32e 100644
--- a/source3/winbindd/winbindd.c
+++ b/source3/winbindd/winbindd.c
@@ -473,7 +473,6 @@ static struct winbindd_dispatch_table {
/* Lookup related functions */
- { WINBINDD_UID_TO_SID, winbindd_uid_to_sid, "UID_TO_SID" },
{ WINBINDD_GID_TO_SID, winbindd_gid_to_sid, "GID_TO_SID" },
{ WINBINDD_ALLOCATE_UID, winbindd_allocate_uid, "ALLOCATE_UID" },
{ WINBINDD_ALLOCATE_GID, winbindd_allocate_gid, "ALLOCATE_GID" },
@@ -529,6 +528,8 @@ static struct winbindd_async_dispatch_table async_nonpriv_table[] = {
winbindd_sid_to_uid_send, winbindd_sid_to_uid_recv },
{ WINBINDD_SID_TO_GID, "SID_TO_GID",
winbindd_sid_to_gid_send, winbindd_sid_to_gid_recv },
+ { WINBINDD_UID_TO_SID, "UID_TO_SID",
+ winbindd_uid_to_sid_send, winbindd_uid_to_sid_recv },
{ 0, NULL, NULL, NULL }
};
diff --git a/source3/winbindd/winbindd_proto.h b/source3/winbindd/winbindd_proto.h
index e0a43f5094..f1fb7e0a87 100644
--- a/source3/winbindd/winbindd_proto.h
+++ b/source3/winbindd/winbindd_proto.h
@@ -664,5 +664,11 @@ struct tevent_req *wb_uid2sid_send(TALLOC_CTX *mem_ctx,
uid_t uid);
NTSTATUS wb_uid2sid_recv(struct tevent_req *req, struct dom_sid *sid);
+struct tevent_req *winbindd_uid_to_sid_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct winbindd_request *request);
+NTSTATUS winbindd_uid_to_sid_recv(struct tevent_req *req,
+ struct winbindd_response *response);
+
#endif /* _WINBINDD_PROTO_H_ */
diff --git a/source3/winbindd/winbindd_sid.c b/source3/winbindd/winbindd_sid.c
index 718345b5e3..654f352ba3 100644
--- a/source3/winbindd/winbindd_sid.c
+++ b/source3/winbindd/winbindd_sid.c
@@ -171,64 +171,6 @@ void winbindd_set_hwm(struct winbindd_cli_state *state)
winbindd_set_hwm_async(state->mem_ctx, &xid, set_hwm_recv, state);
}
-/* Convert a uid to a sid */
-
-static void uid2sid_recv(void *private_data, bool success, const char *sidstr)
-{
- struct winbindd_cli_state *state =
- (struct winbindd_cli_state *)private_data;
- struct dom_sid sid;
-
- if (!success || !string_to_sid(&sid, sidstr)) {
- ZERO_STRUCT(sid);
- idmap_cache_set_sid2uid(&sid, state->request->data.uid);
- request_error(state);
- return;
- }
-
- DEBUG(10,("uid2sid: uid %lu has sid %s\n",
- (unsigned long)(state->request->data.uid), sidstr));
-
- idmap_cache_set_sid2uid(&sid, state->request->data.uid);
- fstrcpy(state->response->data.sid.sid, sidstr);
- state->response->data.sid.type = SID_NAME_USER;
- request_ok(state);
- return;
-}
-
-void winbindd_uid_to_sid(struct winbindd_cli_state *state)
-{
- struct dom_sid sid;
- bool expired;
-
- DEBUG(3, ("[%5lu]: uid to sid %lu\n", (unsigned long)state->pid,
- (unsigned long)state->request->data.uid));
-
- if (idmap_cache_find_uid2sid(state->request->data.uid, &sid,
- &expired)) {
- DEBUG(10, ("idmap_cache_find_uid2sid found %d%s\n",
- (int)state->request->data.uid,
- expired ? " (expired)": ""));
- if (expired && IS_DOMAIN_ONLINE(find_our_domain())) {
- DEBUG(10, ("revalidating expired entry\n"));
- goto backend;
- }
- if (is_null_sid(&sid)) {
- DEBUG(10, ("Returning negative cache entry\n"));
- request_error(state);
- return;
- }
- DEBUG(10, ("Returning positive cache entry\n"));
- sid_to_fstring(state->response->data.sid.sid, &sid);
- request_ok(state);
- return;
- }
-
- /* always go via the async interface (may block) */
- backend:
- winbindd_uid2sid_async(state->mem_ctx, state->request->data.uid, uid2sid_recv, state);
-}
-
/* Convert a gid to a sid */
static void gid2sid_recv(void *private_data, bool success, const char *sidstr)
diff --git a/source3/winbindd/winbindd_uid_to_sid.c b/source3/winbindd/winbindd_uid_to_sid.c
new file mode 100644
index 0000000000..151fffd296
--- /dev/null
+++ b/source3/winbindd/winbindd_uid_to_sid.c
@@ -0,0 +1,87 @@
+/*
+ Unix SMB/CIFS implementation.
+ async implementation of WINBINDD_UID_TO_SID
+ Copyright (C) Volker Lendecke 2009
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "winbindd.h"
+
+struct winbindd_uid_to_sid_state {
+ struct tevent_context *ev;
+ uid_t uid;
+ struct dom_sid sid;
+};
+
+static void winbindd_uid_to_sid_done(struct tevent_req *subreq);
+
+struct tevent_req *winbindd_uid_to_sid_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct winbindd_request *request)
+{
+ struct tevent_req *req, *subreq;
+ struct winbindd_uid_to_sid_state *state;
+
+ req = tevent_req_create(mem_ctx, &state,
+ struct winbindd_uid_to_sid_state);
+ if (req == NULL) {
+ return NULL;
+ }
+ state->ev = ev;
+
+ DEBUG(3, ("uid_to_sid %d\n", (int)request->data.uid));
+
+ subreq = wb_uid2sid_send(state, ev, request->data.uid);
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
+ }
+ tevent_req_set_callback(subreq, winbindd_uid_to_sid_done, req);
+ return req;
+}
+
+static void winbindd_uid_to_sid_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct winbindd_uid_to_sid_state *state = tevent_req_data(
+ req, struct winbindd_uid_to_sid_state);
+ NTSTATUS status;
+
+ status = wb_uid2sid_recv(subreq, &state->sid);
+ TALLOC_FREE(subreq);
+ if (!NT_STATUS_IS_OK(status)) {
+ tevent_req_nterror(req, status);
+ return;
+ }
+ tevent_req_done(req);
+}
+
+NTSTATUS winbindd_uid_to_sid_recv(struct tevent_req *req,
+ struct winbindd_response *response)
+{
+ struct winbindd_uid_to_sid_state *state = tevent_req_data(
+ req, struct winbindd_uid_to_sid_state);
+ NTSTATUS status;
+
+ if (tevent_req_is_nterror(req, &status)) {
+ DEBUG(5, ("Could not convert sid %s: %s\n",
+ sid_string_dbg(&state->sid), nt_errstr(status)));
+ return status;
+ }
+ sid_to_fstring(response->data.sid.sid, &state->sid);
+ response->data.sid.type = SID_NAME_USER;
+ return NT_STATUS_OK;
+}