diff options
author | Michael Adam <obnox@samba.org> | 2012-12-06 18:06:49 +0100 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2013-01-29 21:48:01 +0100 |
commit | 729e2c36301620ccc61b1d97205fb3f482efbe15 (patch) | |
tree | 533c811b867a5c5884644bc19461a3cf6ee594df /source3 | |
parent | 3680cc4a11ef5476457b580f8422d0ab82451173 (diff) | |
download | samba-729e2c36301620ccc61b1d97205fb3f482efbe15.tar.gz samba-729e2c36301620ccc61b1d97205fb3f482efbe15.tar.bz2 samba-729e2c36301620ccc61b1d97205fb3f482efbe15.zip |
s3:winbindd: factor add_wbint_Principal_to_dict() out of wb_group_members_done()
for later reuse
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Diffstat (limited to 'source3')
-rw-r--r-- | source3/winbindd/wb_group_members.c | 59 | ||||
-rw-r--r-- | source3/winbindd/winbindd_proto.h | 5 |
2 files changed, 47 insertions, 17 deletions
diff --git a/source3/winbindd/wb_group_members.c b/source3/winbindd/wb_group_members.c index e4b4c0ac33..ecd07cf655 100644 --- a/source3/winbindd/wb_group_members.c +++ b/source3/winbindd/wb_group_members.c @@ -349,6 +349,42 @@ static NTSTATUS wb_group_members_next_subreq( return NT_STATUS_OK; } + +/** + * compose a wbint_Principal and add it to talloc_dict + * + * NOTE: this has a side effect: *name needs to be talloc'd + * and it is talloc_move'd to mem_ctx. + */ +NTSTATUS add_wbint_Principal_to_dict(TALLOC_CTX *mem_ctx, + struct dom_sid *sid, + const char **name, + enum lsa_SidType type, + struct talloc_dict *dict) +{ + struct wbint_Principal *m; + DATA_BLOB key; + bool ok; + + m = talloc(mem_ctx, struct wbint_Principal); + if (m == NULL) { + return NT_STATUS_NO_MEMORY; + } + + sid_copy(&m->sid, sid); + m->name = talloc_move(m, name); + m->type = type; + + key = data_blob_const(&m->sid, sizeof(m->sid)); + + ok = talloc_dict_set(dict, key, &m); + if (!ok) { + return NT_STATUS_NO_MEMORY; + } + + return NT_STATUS_OK; +} + static void wb_group_members_done(struct tevent_req *subreq) { struct tevent_req *req = tevent_req_callback_data( @@ -397,26 +433,15 @@ static void wb_group_members_done(struct tevent_req *subreq) /* * Add a copy of members[i] to state->users */ - struct wbint_Principal *m; - struct dom_sid *sid; - DATA_BLOB key; - - m = talloc(talloc_tos(), struct wbint_Principal); - if (tevent_req_nomem(m, req)) { + status = add_wbint_Principal_to_dict(talloc_tos(), + &members[i].sid, + &members[i].name, + members[i].type, + state->users); + if (tevent_req_nterror(req, status)) { return; } - sid_copy(&m->sid, &members[i].sid); - m->name = talloc_move(m, &members[i].name); - m->type = members[i].type; - - sid = &members[i].sid; - key = data_blob_const( - sid, ndr_size_dom_sid(sid, 0)); - if (!talloc_dict_set(state->users, key, &m)) { - tevent_req_nterror(req, NT_STATUS_NO_MEMORY); - return; - } break; } case SID_NAME_DOM_GRP: diff --git a/source3/winbindd/winbindd_proto.h b/source3/winbindd/winbindd_proto.h index 33b0f01f3d..00b7c32194 100644 --- a/source3/winbindd/winbindd_proto.h +++ b/source3/winbindd/winbindd_proto.h @@ -643,6 +643,11 @@ struct tevent_req *wb_group_members_send(TALLOC_CTX *mem_ctx, int max_depth); NTSTATUS wb_group_members_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, struct talloc_dict **members); +NTSTATUS add_wbint_Principal_to_dict(TALLOC_CTX *mem_ctx, + struct dom_sid *sid, + const char **name, + enum lsa_SidType type, + struct talloc_dict *dict); struct tevent_req *wb_getgrsid_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, |