From: Volker Lendecke Date: Sun, 6 Aug 2017 13:49:01 +0000 (+0200) Subject: winbind: Remove the use of "talloc_dict" X-Git-Tag: tevent-0.9.34~282 X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=762fba44d71d194c1f3799a8d5b671c1366da142;p=samba.git winbind: Remove the use of "talloc_dict" As members we only collect names, indexed by sids. This is served well by just a simple dbwrap_rbt. Signed-off-by: Volker Lendecke Reviewed-by: Ralph Boehme --- diff --git a/source3/winbindd/wb_getgrsid.c b/source3/winbindd/wb_getgrsid.c index 8e0eac7de93..b210645ea5a 100644 --- a/source3/winbindd/wb_getgrsid.c +++ b/source3/winbindd/wb_getgrsid.c @@ -21,6 +21,7 @@ #include "winbindd.h" #include "librpc/gen_ndr/ndr_winbind_c.h" #include "../libcli/security/security.h" +#include "lib/dbwrap/dbwrap_rbt.h" struct wb_getgrsid_state { struct tevent_context *ev; @@ -30,7 +31,7 @@ struct wb_getgrsid_state { const char *name; enum lsa_SidType type; gid_t gid; - struct talloc_dict *members; + struct db_context *members; }; static void wb_getgrsid_lookupsid_done(struct tevent_req *subreq); @@ -156,7 +157,7 @@ static void wb_getgrsid_sid2gid_done(struct tevent_req *subreq) return; } - state->members = talloc_dict_init(state); + state->members = db_open_rbt(state); if (tevent_req_nomem(state->members, req)) { return; } @@ -169,11 +170,7 @@ static void wb_getgrsid_sid2gid_done(struct tevent_req *subreq) return; } - status = add_wbint_Principal_to_dict(talloc_tos(), - &state->sid, - &name, - state->type, - state->members); + status = add_member_to_db(state->members, &state->sid, name); if (!NT_STATUS_IS_OK(status)) { tevent_req_nterror(req, status); return; @@ -213,7 +210,7 @@ static void wb_getgrsid_got_members(struct tevent_req *subreq) NTSTATUS wb_getgrsid_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, const char **domname, const char **name, gid_t *gid, - struct talloc_dict **members) + struct db_context **members) { struct wb_getgrsid_state *state = tevent_req_data( req, struct wb_getgrsid_state); diff --git a/source3/winbindd/wb_group_members.c b/source3/winbindd/wb_group_members.c index 5a20d87514c..7978b188143 100644 --- a/source3/winbindd/wb_group_members.c +++ b/source3/winbindd/wb_group_members.c @@ -22,6 +22,9 @@ #include "librpc/gen_ndr/ndr_winbind_c.h" #include "../librpc/gen_ndr/ndr_security.h" #include "../libcli/security/security.h" +#include "lib/util/util_tdb.h" +#include "lib/dbwrap/dbwrap.h" +#include "lib/dbwrap/dbwrap_rbt.h" /* * We have 3 sets of routines here: @@ -268,14 +271,14 @@ static NTSTATUS wb_groups_members_recv(struct tevent_req *req, /* * This is the routine expanding a list of groups up to a certain level. We - * collect the users in a talloc_dict: We have to add them without duplicates, - * and talloc_dict is an indexed (here indexed by SID) data structure. + * collect the users in a rbt database: We have to add them without duplicates, + * and the db is indexed by SID. */ struct wb_group_members_state { struct tevent_context *ev; int depth; - struct talloc_dict *users; + struct db_context *users; struct wbint_Principal *groups; }; @@ -301,7 +304,7 @@ struct tevent_req *wb_group_members_send(TALLOC_CTX *mem_ctx, } state->ev = ev; state->depth = max_depth; - state->users = talloc_dict_init(state); + state->users = db_open_rbt(state); if (tevent_req_nomem(state->users, req)) { return tevent_req_post(req, ev); } @@ -349,40 +352,18 @@ 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) +NTSTATUS add_member_to_db(struct db_context *db, struct dom_sid *sid, + const char *name) { - 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)); + size_t len = ndr_size_dom_sid(sid, 0); + uint8_t sidbuf[len]; + TDB_DATA key = { .dptr = sidbuf, .dsize = sizeof(sidbuf) }; + NTSTATUS status; - ok = talloc_dict_set(dict, key, &m); - if (!ok) { - return NT_STATUS_NO_MEMORY; - } + sid_linearize(sidbuf, sizeof(sidbuf), sid); - return NT_STATUS_OK; + status = dbwrap_store(db, key, string_term_tdb_data(name), 0); + return status; } static void wb_group_members_done(struct tevent_req *subreq) @@ -433,11 +414,8 @@ static void wb_group_members_done(struct tevent_req *subreq) /* * Add a copy of members[i] to state->users */ - status = add_wbint_Principal_to_dict(talloc_tos(), - &members[i].sid, - &members[i].name, - members[i].type, - state->users); + status = add_member_to_db(state->users, &members[i].sid, + members[i].name); if (tevent_req_nterror(req, status)) { return; } @@ -476,7 +454,7 @@ static void wb_group_members_done(struct tevent_req *subreq) } NTSTATUS wb_group_members_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, - struct talloc_dict **members) + struct db_context **members) { struct wb_group_members_state *state = tevent_req_data( req, struct wb_group_members_state); diff --git a/source3/winbindd/wb_next_grent.c b/source3/winbindd/wb_next_grent.c index fd925b609e5..d249287cc40 100644 --- a/source3/winbindd/wb_next_grent.c +++ b/source3/winbindd/wb_next_grent.c @@ -27,7 +27,7 @@ struct wb_next_grent_state { int max_nesting; struct getgrent_state *gstate; struct winbindd_gr *gr; - struct talloc_dict *members; + struct db_context *members; }; static void wb_next_grent_fetch_done(struct tevent_req *subreq); @@ -150,7 +150,7 @@ static void wb_next_grent_getgrsid_done(struct tevent_req *subreq) } NTSTATUS wb_next_grent_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, - struct talloc_dict **members) + struct db_context **members) { struct wb_next_grent_state *state = tevent_req_data( req, struct wb_next_grent_state); diff --git a/source3/winbindd/winbindd.h b/source3/winbindd/winbindd.h index 6951112629d..396f7f7946e 100644 --- a/source3/winbindd/winbindd.h +++ b/source3/winbindd/winbindd.h @@ -28,8 +28,6 @@ #include "librpc/gen_ndr/dcerpc.h" #include "librpc/gen_ndr/winbind.h" -#include "talloc_dict.h" - #include "../lib/util/tevent_ntstatus.h" #ifdef HAVE_LIBNSCD diff --git a/source3/winbindd/winbindd_getgrent.c b/source3/winbindd/winbindd_getgrent.c index 21da75b4c52..2c8cbac083a 100644 --- a/source3/winbindd/winbindd_getgrent.c +++ b/source3/winbindd/winbindd_getgrent.c @@ -26,7 +26,7 @@ struct winbindd_getgrent_state { int max_groups; int num_groups; struct winbindd_gr *groups; - struct talloc_dict **members; + struct db_context **members; }; static void winbindd_getgrent_done(struct tevent_req *subreq); @@ -72,7 +72,7 @@ struct tevent_req *winbindd_getgrent_send(TALLOC_CTX *mem_ctx, return tevent_req_post(req, ev); } - state->members = talloc_array(state, struct talloc_dict *, + state->members = talloc_array(state, struct db_context *, state->max_groups); if (tevent_req_nomem(state->members, req)) { TALLOC_FREE(state->groups); diff --git a/source3/winbindd/winbindd_getgrgid.c b/source3/winbindd/winbindd_getgrgid.c index 8e8bdeea86a..640ebfa4969 100644 --- a/source3/winbindd/winbindd_getgrgid.c +++ b/source3/winbindd/winbindd_getgrgid.c @@ -28,7 +28,7 @@ struct winbindd_getgrgid_state { const char *domname; const char *name; gid_t gid; - struct talloc_dict *members; + struct db_context *members; }; static void winbindd_getgrgid_gid2sid_done(struct tevent_req *subreq); diff --git a/source3/winbindd/winbindd_getgrnam.c b/source3/winbindd/winbindd_getgrnam.c index 12b16513caa..02d9abc28a2 100644 --- a/source3/winbindd/winbindd_getgrnam.c +++ b/source3/winbindd/winbindd_getgrnam.c @@ -27,7 +27,7 @@ struct winbindd_getgrnam_state { const char *domname; const char *name; gid_t gid; - struct talloc_dict *members; + struct db_context *members; }; static void winbindd_getgrnam_lookupname_done(struct tevent_req *subreq); diff --git a/source3/winbindd/winbindd_group.c b/source3/winbindd/winbindd_group.c index ae461bf3748..b5c9d3cf94e 100644 --- a/source3/winbindd/winbindd_group.c +++ b/source3/winbindd/winbindd_group.c @@ -24,6 +24,7 @@ #include "includes.h" #include "winbindd.h" +#include "lib/dbwrap/dbwrap.h" #undef DBGC_CLASS #define DBGC_CLASS DBGC_WINBIND @@ -79,14 +80,19 @@ struct getgr_countmem { size_t len; }; -static int getgr_calc_memberlen(DATA_BLOB key, void *data, void *priv) +static int getgr_calc_memberlen(struct db_record *rec, void *private_data) { - struct wbint_Principal *m = talloc_get_type_abort( - data, struct wbint_Principal); - struct getgr_countmem *buf = (struct getgr_countmem *)priv; + struct getgr_countmem *buf = private_data; + TDB_DATA data = dbwrap_record_get_value(rec); + size_t len; buf->num += 1; - buf->len += strlen(m->name) + 1; + + len = buf->len + data.dsize; + if (len < buf->len) { + return 0; + } + buf->len = len; return 0; } @@ -95,37 +101,37 @@ struct getgr_stringmem { char *buf; }; -static int getgr_unparse_members(DATA_BLOB key, void *data, void *priv) +static int getgr_unparse_members(struct db_record *rec, void *private_data) { - struct wbint_Principal *m = talloc_get_type_abort( - data, struct wbint_Principal); - struct getgr_stringmem *buf = (struct getgr_stringmem *)priv; + struct getgr_stringmem *buf = private_data; + TDB_DATA data = dbwrap_record_get_value(rec); int len; - len = strlen(m->name); + len = data.dsize-1; - memcpy(buf->buf + buf->ofs, m->name, len); + memcpy(buf->buf + buf->ofs, data.dptr, len); buf->ofs += len; buf->buf[buf->ofs] = ','; buf->ofs += 1; return 0; } -NTSTATUS winbindd_print_groupmembers(struct talloc_dict *members, +NTSTATUS winbindd_print_groupmembers(struct db_context *members, TALLOC_CTX *mem_ctx, int *num_members, char **result) { struct getgr_countmem c; struct getgr_stringmem m; - int res; + int count; + NTSTATUS status; c.num = 0; c.len = 0; - res = talloc_dict_traverse(members, getgr_calc_memberlen, &c); - if (res == -1) { - DEBUG(5, ("talloc_dict_traverse failed\n")); - return NT_STATUS_INTERNAL_ERROR; + status = dbwrap_traverse(members, getgr_calc_memberlen, &c, &count); + if (!NT_STATUS_IS_OK(status)) { + DBG_NOTICE("dbwrap_traverse failed: %s\n", nt_errstr(status)); + return status; } m.ofs = 0; @@ -135,11 +141,11 @@ NTSTATUS winbindd_print_groupmembers(struct talloc_dict *members, return NT_STATUS_NO_MEMORY; } - res = talloc_dict_traverse(members, getgr_unparse_members, &m); - if (res == -1) { - DEBUG(5, ("talloc_dict_traverse failed\n")); + status = dbwrap_traverse(members, getgr_unparse_members, &m, &count); + if (!NT_STATUS_IS_OK(status)) { TALLOC_FREE(m.buf); - return NT_STATUS_INTERNAL_ERROR; + DBG_NOTICE("dbwrap_traverse failed: %s\n", nt_errstr(status)); + return status; } m.buf[c.len-1] = '\0'; diff --git a/source3/winbindd/winbindd_proto.h b/source3/winbindd/winbindd_proto.h index 7560fc53bae..46e6530105a 100644 --- a/source3/winbindd/winbindd_proto.h +++ b/source3/winbindd/winbindd_proto.h @@ -339,7 +339,9 @@ struct winbindd_domain *wb_child_domain(void); /* The following definitions come from winbindd/winbindd_group.c */ bool fill_grent(TALLOC_CTX *mem_ctx, struct winbindd_gr *gr, const char *dom_name, const char *gr_name, gid_t unix_gid); -NTSTATUS winbindd_print_groupmembers(struct talloc_dict *members, + +struct db_context; +NTSTATUS winbindd_print_groupmembers(struct db_context *members, TALLOC_CTX *mem_ctx, int *num_members, char **result); @@ -661,12 +663,9 @@ struct tevent_req *wb_group_members_send(TALLOC_CTX *mem_ctx, enum lsa_SidType type, 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 db_context **members); +NTSTATUS add_member_to_db(struct db_context *db, struct dom_sid *sid, + const char *name); struct tevent_req *wb_getgrsid_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, @@ -674,7 +673,7 @@ struct tevent_req *wb_getgrsid_send(TALLOC_CTX *mem_ctx, int max_nesting); NTSTATUS wb_getgrsid_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, const char **domname, const char **name, gid_t *gid, - struct talloc_dict **members); + struct db_context **members); struct tevent_req *winbindd_getgrgid_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, @@ -778,7 +777,7 @@ struct tevent_req *wb_next_grent_send(TALLOC_CTX *mem_ctx, struct getgrent_state *gstate, struct winbindd_gr *gr); NTSTATUS wb_next_grent_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, - struct talloc_dict **members); + struct db_context **members); struct tevent_req *winbindd_setgrent_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,