svn commit: samba r5604 - in trunk/source/nsswitch: .
vlendec at samba.org
vlendec at samba.org
Tue Mar 1 16:37:30 GMT 2005
Author: vlendec
Date: 2005-03-01 16:37:29 +0000 (Tue, 01 Mar 2005)
New Revision: 5604
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=5604
Log:
Make winbindd_allocate_rid and winbindd_gid_to_sid async.
Volker
Modified:
trunk/source/nsswitch/winbindd.c
trunk/source/nsswitch/winbindd_dual.c
trunk/source/nsswitch/winbindd_sid.c
Changeset:
Modified: trunk/source/nsswitch/winbindd.c
===================================================================
--- trunk/source/nsswitch/winbindd.c 2005-03-01 16:08:36 UTC (rev 5603)
+++ trunk/source/nsswitch/winbindd.c 2005-03-01 16:37:29 UTC (rev 5604)
@@ -271,8 +271,8 @@
{ WINBINDD_SID_TO_UID, winbindd_sid_to_uid_async, "SID_TO_UID" },
{ WINBINDD_SID_TO_GID, winbindd_sid_to_gid_async, "SID_TO_GID" },
{ WINBINDD_UID_TO_SID, winbindd_uid_to_sid_async, "UID_TO_SID" },
- { WINBINDD_GID_TO_SID, winbindd_gid_to_sid, "GID_TO_SID" },
- { WINBINDD_ALLOCATE_RID, winbindd_allocate_rid, "ALLOCATE_RID" },
+ { WINBINDD_GID_TO_SID, winbindd_gid_to_sid_async, "GID_TO_SID" },
+ { WINBINDD_ALLOCATE_RID, winbindd_allocate_rid_async, "ALLOCATE_RID" },
{ WINBINDD_ALLOCATE_RID_AND_GID, winbindd_allocate_rid_and_gid_async,
"ALLOCATE_RID_AND_GID" },
Modified: trunk/source/nsswitch/winbindd_dual.c
===================================================================
--- trunk/source/nsswitch/winbindd_dual.c 2005-03-01 16:08:36 UTC (rev 5603)
+++ trunk/source/nsswitch/winbindd_dual.c 2005-03-01 16:37:29 UTC (rev 5604)
@@ -433,6 +433,7 @@
{ WINBINDD_DUAL_UID2NAME, winbindd_dual_uid2name, "DUAL_UID2NAME" },
{ WINBINDD_DUAL_GID2NAME, winbindd_dual_gid2name, "DUAL_GID2NAME" },
{ WINBINDD_DUAL_IDMAPSET, winbindd_dual_idmapset, "DUAL_IDMAPSET" },
+ { WINBINDD_ALLOCATE_RID, winbindd_allocate_rid, "ALLOCATE_RID" },
{ WINBINDD_ALLOCATE_RID_AND_GID, winbindd_allocate_rid_and_gid,
"ALLOCATE_RID_AND_GID" },
/* End of list */
Modified: trunk/source/nsswitch/winbindd_sid.c
===================================================================
--- trunk/source/nsswitch/winbindd_sid.c 2005-03-01 16:08:36 UTC (rev 5603)
+++ trunk/source/nsswitch/winbindd_sid.c 2005-03-01 16:37:29 UTC (rev 5604)
@@ -505,8 +505,9 @@
static void uid2sid_uid2name_recv(void *private, BOOL success,
const char *username);
-static void uid2sid_lookupsid_recv(void *private, BOOL success,
- const DOM_SID *sid, enum SID_NAME_USE type);
+static void uid2sid_lookupname_recv(void *private, BOOL success,
+ const DOM_SID *sid,
+ enum SID_NAME_USE type);
static void uid2sid_idmap_set_mapping_recv(void *private, BOOL success);
enum winbindd_result winbindd_uid_to_sid_async(struct winbindd_cli_state *state)
@@ -577,11 +578,11 @@
winbindd_lookup_name_async(state->cli_state->mem_ctx,
domain->name, username,
- uid2sid_lookupsid_recv, state);
+ uid2sid_lookupname_recv, state);
}
-static void uid2sid_lookupsid_recv(void *private, BOOL success,
- const DOM_SID *sid, enum SID_NAME_USE type)
+static void uid2sid_lookupname_recv(void *private, BOOL success,
+ const DOM_SID *sid, enum SID_NAME_USE type)
{
struct uid2sid_state *state = private;
unid_t id;
@@ -592,12 +593,6 @@
return;
}
- if (type != SID_NAME_USER) {
- state->cli_state->response.result = WINBINDD_ERROR;
- request_finished(state->cli_state);
- return;
- }
-
state->sid = *sid;
state->type = type;
@@ -619,23 +614,37 @@
}
/* Convert a gid to a sid */
-enum winbindd_result winbindd_gid_to_sid(struct winbindd_cli_state *state)
+
+struct gid2sid_state {
+ struct winbindd_cli_state *cli_state;
+ gid_t gid;
+ fstring name;
+ DOM_SID sid;
+ enum SID_NAME_USE type;
+};
+
+static void gid2sid_gid2name_recv(void *private, BOOL success,
+ const char *groupname);
+static void gid2sid_lookupname_recv(void *private, BOOL success,
+ const DOM_SID *sid,
+ enum SID_NAME_USE type);
+static void gid2sid_idmap_set_mapping_recv(void *private, BOOL success);
+
+enum winbindd_result winbindd_gid_to_sid_async(struct winbindd_cli_state *state)
{
DOM_SID sid;
NTSTATUS status;
- struct group *grp = NULL;
- enum SID_NAME_USE type;
- unid_t id;
- struct winbindd_domain *domain;
+ struct gid2sid_state *gid2sid_state;
DEBUG(3, ("[%5lu]: gid to sid %lu\n", (unsigned long)state->pid,
(unsigned long)state->request.data.gid));
- status = idmap_gid_to_sid(&sid, state->request.data.gid, 0);
+ status = idmap_gid_to_sid(&sid, state->request.data.gid,
+ ID_QUERY_ONLY | ID_CACHE_ONLY);
if (NT_STATUS_IS_OK(status)) {
sid_to_string(state->response.data.sid.sid, &sid);
- state->response.data.sid.type = SID_NAME_DOM_GRP;
+ state->response.data.sid.type = SID_NAME_USER;
return WINBINDD_OK;
}
@@ -646,42 +655,86 @@
}
/* The only chance that this is correct is that winbind trusted
- * domains only = yes, and the group exists in nss and the domain. */
+ * domains only = yes, and the user exists in nss and the domain. */
if (!lp_winbind_trusted_domains_only()) {
return WINBINDD_ERROR;
}
- grp = getgrgid(state->request.data.gid);
- if (grp == NULL)
+ /* The only chance that this is correct is that winbind trusted
+ * domains only = yes, and the user exists in nss and the domain. */
+
+ gid2sid_state = TALLOC_ZERO_P(state->mem_ctx, struct gid2sid_state);
+ if (gid2sid_state == NULL) {
+ DEBUG(0, ("talloc failed\n"));
return WINBINDD_ERROR;
+ }
+ gid2sid_state->cli_state = state;
+ gid2sid_state->gid = state->request.data.gid;
+
+ return winbindd_gid2name_async(state->mem_ctx, state->request.data.gid,
+ gid2sid_gid2name_recv, gid2sid_state);
+}
+
+static void gid2sid_gid2name_recv(void *private, BOOL success,
+ const char *username)
+{
+ struct gid2sid_state *state = private;
+ struct winbindd_domain *domain;
+
+ DEBUG(10, ("gid2sid: gid %lu has name %s\n",
+ (unsigned long)state->gid, username));
+
+ fstrcpy(state->name, username);
+
domain = find_our_domain();
- if (domain == NULL) {
- DEBUG(0,("winbindd_gid_to_sid: can't find my own domain!\n"));
- return WINBINDD_ERROR;
+
+ if ((!success) || (domain == NULL)) {
+ state->cli_state->response.result = WINBINDD_ERROR;
+ request_finished(state->cli_state);
+ return;
}
- if ( !winbindd_lookup_sid_by_name(state->mem_ctx, domain,
- domain->name, grp->gr_name,
- &sid, &type) )
- return WINBINDD_ERROR;
+ winbindd_lookup_name_async(state->cli_state->mem_ctx,
+ domain->name, username,
+ gid2sid_lookupname_recv, state);
+}
- if ( type!=SID_NAME_DOM_GRP && type!=SID_NAME_ALIAS )
- return WINBINDD_ERROR;
+static void gid2sid_lookupname_recv(void *private, BOOL success,
+ const DOM_SID *sid, enum SID_NAME_USE type)
+{
+ struct gid2sid_state *state = private;
+ unid_t id;
- /* don't fail if we can't store it */
+ if ((!success) ||
+ ((type != SID_NAME_DOM_GRP) && (type!=SID_NAME_ALIAS))) {
+ state->cli_state->response.result = WINBINDD_ERROR;
+ request_finished(state->cli_state);
+ return;
+ }
- id.gid = grp->gr_gid;
- idmap_set_mapping( &sid, id, ID_GROUPID );
+ state->sid = *sid;
+ state->type = type;
- sid_to_string(state->response.data.sid.sid, &sid);
- state->response.data.sid.type = SID_NAME_DOM_GRP;
+ id.gid = state->gid;
+ idmap_set_mapping_async(state->cli_state->mem_ctx, sid, id, ID_GROUPID,
+ gid2sid_idmap_set_mapping_recv, state );
+}
- return WINBINDD_OK;
+static void gid2sid_idmap_set_mapping_recv(void *private, BOOL success)
+{
+ struct gid2sid_state *state = private;
+
+ /* don't fail if we can't store it */
+
+ sid_to_string(state->cli_state->response.data.sid.sid, &state->sid);
+ state->cli_state->response.data.sid.type = state->type;
+ state->cli_state->response.result = WINBINDD_OK;
+ request_finished(state->cli_state);
}
-enum winbindd_result winbindd_allocate_rid(struct winbindd_cli_state *state)
+enum winbindd_result winbindd_allocate_rid_async(struct winbindd_cli_state *state)
{
if ( !state->privileged ) {
DEBUG(2, ("winbindd_allocate_rid: non-privileged access "
@@ -689,6 +742,13 @@
return WINBINDD_ERROR;
}
+ return async_request(state->mem_ctx, idmap_child(),
+ &state->request, &state->response,
+ request_finished_cont, state);
+}
+
+enum winbindd_result winbindd_allocate_rid(struct winbindd_cli_state *state)
+{
/* We tell idmap to always allocate a user RID. There might be a good
* reason to keep RID allocation for users to even and groups to
* odd. This needs discussion I think. For now only allocate user
More information about the samba-cvs
mailing list