summaryrefslogtreecommitdiff
path: root/source3/winbindd
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2009-08-27 17:11:24 +0200
committerVolker Lendecke <vl@samba.org>2009-08-29 19:42:26 +0200
commit50d9fb42fc771e07326f3f47103676f2ef88107e (patch)
tree67239f96f1154386cf5ca874bdec731fa48ac58b /source3/winbindd
parent425239caeeb22cb0a221a38b70f2f2dc8b64bdcc (diff)
downloadsamba-50d9fb42fc771e07326f3f47103676f2ef88107e.tar.gz
samba-50d9fb42fc771e07326f3f47103676f2ef88107e.tar.bz2
samba-50d9fb42fc771e07326f3f47103676f2ef88107e.zip
w3:winbind: Convert WINBINDD_LOOKUPRIDS to the new API
Diffstat (limited to 'source3/winbindd')
-rw-r--r--source3/winbindd/winbindd.c6
-rw-r--r--source3/winbindd/winbindd_async.c58
-rw-r--r--source3/winbindd/winbindd_domain.c4
-rw-r--r--source3/winbindd/winbindd_dual_srv.c40
-rw-r--r--source3/winbindd/winbindd_lookuprids.c197
-rw-r--r--source3/winbindd/winbindd_proto.h9
-rw-r--r--source3/winbindd/winbindd_sid.c30
7 files changed, 246 insertions, 98 deletions
diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c
index a57412ab14..10538d3f21 100644
--- a/source3/winbindd/winbindd.c
+++ b/source3/winbindd/winbindd.c
@@ -447,10 +447,6 @@ static struct winbindd_dispatch_table {
{ WINBINDD_LIST_TRUSTDOM, winbindd_list_trusted_domains,
"LIST_TRUSTDOM" },
- /* SID related functions */
-
- { WINBINDD_LOOKUPRIDS, winbindd_lookuprids, "LOOKUPRIDS" },
-
/* Lookup related functions */
{ WINBINDD_ALLOCATE_UID, winbindd_allocate_uid, "ALLOCATE_UID" },
@@ -530,6 +526,8 @@ static struct winbindd_async_dispatch_table async_nonpriv_table[] = {
winbindd_getgrnam_send, winbindd_getgrnam_recv },
{ WINBINDD_GETUSERSIDS, "GETUSERSIDS",
winbindd_getusersids_send, winbindd_getusersids_recv },
+ { WINBINDD_LOOKUPRIDS, "LOOKUPRIDS",
+ winbindd_lookuprids_send, winbindd_lookuprids_recv },
{ WINBINDD_SETPWENT, "SETPWENT",
winbindd_setpwent_send, winbindd_setpwent_recv },
{ WINBINDD_GETPWENT, "GETPWENT",
diff --git a/source3/winbindd/winbindd_async.c b/source3/winbindd/winbindd_async.c
index d16a1f8288..1e63ed1fec 100644
--- a/source3/winbindd/winbindd_async.c
+++ b/source3/winbindd/winbindd_async.c
@@ -694,64 +694,6 @@ static bool parse_ridlist(TALLOC_CTX *mem_ctx, char *ridstr,
return True;
}
-enum winbindd_result winbindd_dual_lookuprids(struct winbindd_domain *domain,
- struct winbindd_cli_state *state)
-{
- uint32 *rids = NULL;
- size_t i, buflen, num_rids = 0;
- ssize_t len;
- DOM_SID domain_sid;
- char *domain_name;
- char **names;
- enum lsa_SidType *types;
- NTSTATUS status;
- char *result;
-
- DEBUG(10, ("Looking up RIDs for domain %s (%s)\n",
- state->request->domain_name,
- state->request->data.sid));
-
- if (!parse_ridlist(state->mem_ctx, state->request->extra_data.data,
- &rids, &num_rids)) {
- DEBUG(5, ("Could not parse ridlist\n"));
- return WINBINDD_ERROR;
- }
-
- if (!string_to_sid(&domain_sid, state->request->data.sid)) {
- DEBUG(5, ("Could not parse domain sid %s\n",
- state->request->data.sid));
- return WINBINDD_ERROR;
- }
-
- status = domain->methods->rids_to_names(domain, state->mem_ctx,
- &domain_sid, rids, num_rids,
- &domain_name,
- &names, &types);
-
- if (!NT_STATUS_IS_OK(status) &&
- !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
- return WINBINDD_ERROR;
- }
-
- len = 0;
- buflen = 0;
- result = NULL;
-
- for (i=0; i<num_rids; i++) {
- sprintf_append(state->mem_ctx, &result, &len, &buflen,
- "%d %s\n", types[i], names[i]);
- }
-
- fstrcpy(state->response->data.domain_name, domain_name);
-
- if (result != NULL) {
- state->response->extra_data.data = result;
- state->response->length += len+1;
- }
-
- return WINBINDD_OK;
-}
-
static void getsidaliases_recv(TALLOC_CTX *mem_ctx, bool success,
struct winbindd_response *response,
void *c, void *private_data)
diff --git a/source3/winbindd/winbindd_domain.c b/source3/winbindd/winbindd_domain.c
index eb4e131259..14376c62bf 100644
--- a/source3/winbindd/winbindd_domain.c
+++ b/source3/winbindd/winbindd_domain.c
@@ -50,10 +50,6 @@ static const struct winbindd_child_dispatch_table domain_dispatch_table[] = {
.struct_cmd = WINBINDD_LOOKUPNAME,
.struct_fn = winbindd_dual_lookupname,
},{
- .name = "LOOKUPRIDS",
- .struct_cmd = WINBINDD_LOOKUPRIDS,
- .struct_fn = winbindd_dual_lookuprids,
- },{
.name = "LIST_USERS",
.struct_cmd = WINBINDD_LIST_USERS,
.struct_fn = winbindd_dual_list_users,
diff --git a/source3/winbindd/winbindd_dual_srv.c b/source3/winbindd/winbindd_dual_srv.c
index 6b1a4b3615..b46b3d511e 100644
--- a/source3/winbindd/winbindd_dual_srv.c
+++ b/source3/winbindd/winbindd_dual_srv.c
@@ -289,3 +289,43 @@ done:
return status;
}
+
+NTSTATUS _wbint_LookupRids(pipes_struct *p, struct wbint_LookupRids *r)
+{
+ struct winbindd_domain *domain = wb_child_domain();
+ char *domain_name;
+ char **names;
+ enum lsa_SidType *types;
+ struct wbint_Principal *result;
+ NTSTATUS status;
+ int i;
+
+ if (domain == NULL) {
+ return NT_STATUS_REQUEST_NOT_ACCEPTED;
+ }
+
+ status = domain->methods->rids_to_names(
+ domain, talloc_tos(), &domain->sid, r->in.rids->rids,
+ r->in.rids->num_rids, &domain_name, &names, &types);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+
+ result = talloc_array(p->mem_ctx, struct wbint_Principal,
+ r->in.rids->num_rids);
+ if (result == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ for (i=0; i<r->in.rids->num_rids; i++) {
+ sid_compose(&result[i].sid, &domain->sid, r->in.rids->rids[i]);
+ result[i].type = types[i];
+ result[i].name = talloc_move(result, &names[i]);
+ }
+ TALLOC_FREE(types);
+ TALLOC_FREE(names);
+
+ r->out.names->num_principals = r->in.rids->num_rids;
+ r->out.names->principals = result;
+ return NT_STATUS_OK;
+}
diff --git a/source3/winbindd/winbindd_lookuprids.c b/source3/winbindd/winbindd_lookuprids.c
new file mode 100644
index 0000000000..f2cb8793eb
--- /dev/null
+++ b/source3/winbindd/winbindd_lookuprids.c
@@ -0,0 +1,197 @@
+/*
+ Unix SMB/CIFS implementation.
+ async implementation of WINBINDD_LOOKUPRIDS
+ 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"
+#include "librpc/gen_ndr/cli_wbint.h"
+
+struct winbindd_lookuprids_state {
+ struct tevent_context *ev;
+ const char *domain_name;
+ struct wbint_RidArray rids;
+ struct wbint_Principals names;
+};
+
+static bool parse_ridlist(TALLOC_CTX *mem_ctx, char *ridstr,
+ uint32_t **prids, uint32_t *pnum_rids);
+
+static void winbindd_lookuprids_done(struct tevent_req *subreq);
+
+struct tevent_req *winbindd_lookuprids_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct winbindd_cli_state *cli,
+ struct winbindd_request *request)
+{
+ struct tevent_req *req, *subreq;
+ struct winbindd_lookuprids_state *state;
+ struct winbindd_domain *domain;
+ struct dom_sid sid;
+
+ req = tevent_req_create(mem_ctx, &state,
+ struct winbindd_lookuprids_state);
+ if (req == NULL) {
+ return NULL;
+ }
+ state->ev = ev;
+
+ /* Ensure null termination */
+ request->data.sid[sizeof(request->data.sid)-1]='\0';
+
+ DEBUG(3, ("lookuprids (%s)\n", request->data.sid));
+
+ if (!string_to_sid(&sid, request->data.sid)) {
+ DEBUG(5, ("%s not a SID\n", request->data.sid));
+ tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
+ return tevent_req_post(req, ev);
+ }
+
+ domain = find_domain_from_sid_noinit(&sid);
+ if (domain == NULL) {
+ DEBUG(5, ("Domain for sid %s not found\n",
+ sid_string_dbg(&sid)));
+ tevent_req_nterror(req, NT_STATUS_NO_SUCH_DOMAIN);
+ return tevent_req_post(req, ev);
+ }
+
+ if (request->extra_data.data[request->extra_len-1] != '\0') {
+ DEBUG(5, ("extra_data not 0-terminated\n"));
+ tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
+ return tevent_req_post(req, ev);
+ }
+
+ if (!parse_ridlist(state, request->extra_data.data,
+ &state->rids.rids, &state->rids.num_rids)) {
+ DEBUG(5, ("parse_ridlist failed\n"));
+ tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
+ return tevent_req_post(req, ev);
+ }
+
+ subreq = rpccli_wbint_LookupRids_send(
+ state, ev, domain->child.rpccli, &state->rids, &state->names);
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
+ }
+ tevent_req_set_callback(subreq, winbindd_lookuprids_done, req);
+ return req;
+}
+
+static void winbindd_lookuprids_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct winbindd_lookuprids_state *state = tevent_req_data(
+ req, struct winbindd_lookuprids_state);
+ NTSTATUS status, result;
+
+ status = rpccli_wbint_LookupRids_recv(subreq, state, &result);
+ TALLOC_FREE(subreq);
+ if (!NT_STATUS_IS_OK(status)) {
+ tevent_req_nterror(req, status);
+ return;
+ }
+ if (!NT_STATUS_IS_OK(result)) {
+ tevent_req_nterror(req, result);
+ return;
+ }
+ tevent_req_done(req);
+}
+
+NTSTATUS winbindd_lookuprids_recv(struct tevent_req *req,
+ struct winbindd_response *response)
+{
+ struct winbindd_lookuprids_state *state = tevent_req_data(
+ req, struct winbindd_lookuprids_state);
+ NTSTATUS status;
+ char *result;
+ int i;
+
+ if (tevent_req_is_nterror(req, &status)) {
+ DEBUG(5, ("Lookuprids failed: %s\n",nt_errstr(status)));
+ return status;
+ }
+
+ result = talloc_strdup(response, "");
+ if (result == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ for (i=0; i<state->names.num_principals; i++) {
+ struct wbint_Principal *p = &state->names.principals[i];
+
+ result = talloc_asprintf_append_buffer(
+ result, "%d %s\n", (int)p->type, p->name);
+ if (result == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+ }
+
+ fstrcpy(response->data.domain_name, state->domain_name);
+ response->extra_data.data = result;
+ response->length += talloc_get_size(result);
+ return NT_STATUS_OK;
+}
+
+static bool parse_ridlist(TALLOC_CTX *mem_ctx, char *ridstr,
+ uint32_t **prids, uint32_t *pnum_rids)
+{
+ uint32_t i, num_rids;
+ uint32_t *rids;
+ char *p;
+
+ if (ridstr == NULL) {
+ return false;
+ }
+
+ p = ridstr;
+ num_rids = 0;
+
+ /* count rids */
+
+ while ((p = strchr(p, '\n')) != NULL) {
+ p += 1;
+ num_rids += 1;
+ }
+
+ if (num_rids == 0) {
+ *pnum_rids = 0;
+ *prids = NULL;
+ return true;
+ }
+
+ rids = talloc_array(mem_ctx, uint32_t, num_rids);
+ if (rids == NULL) {
+ return false;
+ }
+
+ p = ridstr;
+
+ for (i=0; i<num_rids; i++) {
+ char *q;
+ rids[i] = strtoul(p, &q, 10);
+ if (*q != '\n') {
+ DEBUG(0, ("Got invalid ridstr: %s\n", p));
+ return false;
+ }
+ p = q+1;
+ }
+
+ *pnum_rids = num_rids;
+ *prids = rids;
+ return true;
+}
diff --git a/source3/winbindd/winbindd_proto.h b/source3/winbindd/winbindd_proto.h
index 930d48b458..bebfc9d9e4 100644
--- a/source3/winbindd/winbindd_proto.h
+++ b/source3/winbindd/winbindd_proto.h
@@ -102,8 +102,6 @@ bool print_sidlist(TALLOC_CTX *mem_ctx, const DOM_SID *sids,
size_t num_sids, char **result, ssize_t *len);
bool parse_sidlist(TALLOC_CTX *mem_ctx, const char *sidstr,
DOM_SID **sids, size_t *num_sids);
-enum winbindd_result winbindd_dual_lookuprids(struct winbindd_domain *domain,
- struct winbindd_cli_state *state);
void winbindd_getsidaliases_async(struct winbindd_domain *domain,
TALLOC_CTX *mem_ctx,
const DOM_SID *sids, size_t num_sids,
@@ -848,6 +846,13 @@ struct tevent_req *winbindd_getusersids_send(TALLOC_CTX *mem_ctx,
NTSTATUS winbindd_getusersids_recv(struct tevent_req *req,
struct winbindd_response *response);
+struct tevent_req *winbindd_lookuprids_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct winbindd_cli_state *cli,
+ struct winbindd_request *request);
+NTSTATUS winbindd_lookuprids_recv(struct tevent_req *req,
+ struct winbindd_response *response);
+
struct tevent_req *wb_query_user_list_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct winbindd_domain *domain);
diff --git a/source3/winbindd/winbindd_sid.c b/source3/winbindd/winbindd_sid.c
index db000682ae..8f09d5f7eb 100644
--- a/source3/winbindd/winbindd_sid.c
+++ b/source3/winbindd/winbindd_sid.c
@@ -25,36 +25,6 @@
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_WINBIND
-/* Convert a string */
-
-void winbindd_lookuprids(struct winbindd_cli_state *state)
-{
- struct winbindd_domain *domain;
- DOM_SID domain_sid;
-
- /* Ensure null termination */
- state->request->data.sid[sizeof(state->request->data.sid)-1]='\0';
-
- DEBUG(10, ("lookup_rids: %s\n", state->request->data.sid));
-
- if (!string_to_sid(&domain_sid, state->request->data.sid)) {
- DEBUG(5, ("Could not convert %s to SID\n",
- state->request->data.sid));
- request_error(state);
- return;
- }
-
- domain = find_lookup_domain_from_sid(&domain_sid);
- if (domain == NULL) {
- DEBUG(10, ("Could not find domain for name %s\n",
- state->request->domain_name));
- request_error(state);
- return;
- }
-
- sendto_domain(state, domain);
-}
-
static void set_mapping_recv(void *private_data, bool success)
{
struct winbindd_cli_state *state =