s3:winbindd: factor add_wbint_Principal_to_dict() out of wb_group_members_done()
authorMichael Adam <obnox@samba.org>
Thu, 6 Dec 2012 17:06:49 +0000 (18:06 +0100)
committerStefan Metzmacher <metze@samba.org>
Tue, 29 Jan 2013 20:48:01 +0000 (21:48 +0100)
for later reuse

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/winbindd/wb_group_members.c
source3/winbindd/winbindd_proto.h

index e4b4c0ac33930afee46faa5979a684b63623b49f..ecd07cf655710823f49ed9131320e09a780cebef 100644 (file)
@@ -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:
index 33b0f01f3de9e71de70c96c1123f3661735f4269..00b7c321949bbe1c5a239c90f3d7e5f372d45616 100644 (file)
@@ -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,