diff options
Diffstat (limited to 'source3')
-rw-r--r-- | source3/Makefile.in | 1 | ||||
-rw-r--r-- | source3/winbindd/winbindd.c | 3 | ||||
-rw-r--r-- | source3/winbindd/winbindd_gid_to_sid.c | 87 | ||||
-rw-r--r-- | source3/winbindd/winbindd_proto.h | 6 | ||||
-rw-r--r-- | source3/winbindd/winbindd_sid.c | 58 |
5 files changed, 96 insertions, 59 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in index 4a872fe885..f7801d17a2 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -1163,6 +1163,7 @@ WINBINDD_OBJ1 = \ winbindd/winbindd_sid_to_uid.o \ winbindd/winbindd_sid_to_gid.o \ winbindd/winbindd_uid_to_sid.o \ + winbindd/winbindd_gid_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 9af63ff32e..4425517385 100644 --- a/source3/winbindd/winbindd.c +++ b/source3/winbindd/winbindd.c @@ -473,7 +473,6 @@ static struct winbindd_dispatch_table { /* Lookup related functions */ - { 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" }, { WINBINDD_SET_MAPPING, winbindd_set_mapping, "SET_MAPPING" }, @@ -530,6 +529,8 @@ static struct winbindd_async_dispatch_table async_nonpriv_table[] = { 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 }, + { WINBINDD_GID_TO_SID, "GID_TO_SID", + winbindd_gid_to_sid_send, winbindd_gid_to_sid_recv }, { 0, NULL, NULL, NULL } }; diff --git a/source3/winbindd/winbindd_gid_to_sid.c b/source3/winbindd/winbindd_gid_to_sid.c new file mode 100644 index 0000000000..b2cc3c2613 --- /dev/null +++ b/source3/winbindd/winbindd_gid_to_sid.c @@ -0,0 +1,87 @@ +/* + Unix SMB/CIFS implementation. + async implementation of WINBINDD_GID_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_gid_to_sid_state { + struct tevent_context *ev; + gid_t gid; + struct dom_sid sid; +}; + +static void winbindd_gid_to_sid_done(struct tevent_req *subreq); + +struct tevent_req *winbindd_gid_to_sid_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct winbindd_request *request) +{ + struct tevent_req *req, *subreq; + struct winbindd_gid_to_sid_state *state; + + req = tevent_req_create(mem_ctx, &state, + struct winbindd_gid_to_sid_state); + if (req == NULL) { + return NULL; + } + state->ev = ev; + + DEBUG(3, ("gid_to_sid %d\n", (int)request->data.gid)); + + subreq = wb_gid2sid_send(state, ev, request->data.gid); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, winbindd_gid_to_sid_done, req); + return req; +} + +static void winbindd_gid_to_sid_done(struct tevent_req *subreq) +{ + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct winbindd_gid_to_sid_state *state = tevent_req_data( + req, struct winbindd_gid_to_sid_state); + NTSTATUS status; + + status = wb_gid2sid_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_gid_to_sid_recv(struct tevent_req *req, + struct winbindd_response *response) +{ + struct winbindd_gid_to_sid_state *state = tevent_req_data( + req, struct winbindd_gid_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; +} diff --git a/source3/winbindd/winbindd_proto.h b/source3/winbindd/winbindd_proto.h index d8bd984590..38d5200aae 100644 --- a/source3/winbindd/winbindd_proto.h +++ b/source3/winbindd/winbindd_proto.h @@ -675,5 +675,11 @@ struct tevent_req *wb_gid2sid_send(TALLOC_CTX *mem_ctx, gid_t gid); NTSTATUS wb_gid2sid_recv(struct tevent_req *req, struct dom_sid *sid); +struct tevent_req *winbindd_gid_to_sid_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct winbindd_request *request); +NTSTATUS winbindd_gid_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 654f352ba3..db000682ae 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 gid to a sid */ - -static void gid2sid_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_sid2gid(&sid, state->request->data.gid); - request_error(state); - return; - } - DEBUG(10,("gid2sid: gid %lu has sid %s\n", - (unsigned long)(state->request->data.gid), sidstr)); - - idmap_cache_set_sid2gid(&sid, state->request->data.gid); - fstrcpy(state->response->data.sid.sid, sidstr); - state->response->data.sid.type = SID_NAME_DOM_GRP; - request_ok(state); - return; -} - - -void winbindd_gid_to_sid(struct winbindd_cli_state *state) -{ - struct dom_sid sid; - bool expired; - - DEBUG(3, ("[%5lu]: gid to sid %lu\n", (unsigned long)state->pid, - (unsigned long)state->request->data.gid)); - - if (idmap_cache_find_gid2sid(state->request->data.gid, &sid, - &expired)) { - DEBUG(10, ("idmap_cache_find_gid2sid found %d%s\n", - (int)state->request->data.gid, - 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 use async calls (may block) */ - backend: - winbindd_gid2sid_async(state->mem_ctx, state->request->data.gid, gid2sid_recv, state); -} - void winbindd_allocate_uid(struct winbindd_cli_state *state) { if ( !state->privileged ) { |