#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;
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);
return;
}
- state->members = talloc_dict_init(state);
+ state->members = db_open_rbt(state);
if (tevent_req_nomem(state->members, req)) {
return;
}
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;
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);
#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:
/*
* 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;
};
}
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);
}
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)
/*
* 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;
}
}
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);
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);
}
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);
#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
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);
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);
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);
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);
#include "includes.h"
#include "winbindd.h"
+#include "lib/dbwrap/dbwrap.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_WINBIND
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;
}
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;
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';
/* 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);
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,
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,
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,