2 Unix SMB/CIFS implementation.
4 Winbind daemon for ntdom nss module
6 Copyright (C) Tim Potter 2000
7 Copyright (C) Jeremy Allison 2001.
8 Copyright (C) Gerald (Jerry) Carter 2003.
9 Copyright (C) Volker Lendecke 2005
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include "lib/dbwrap/dbwrap.h"
30 #define DBGC_CLASS DBGC_WINBIND
32 /* Fill a grent structure from various other information */
34 bool fill_grent(TALLOC_CTX *mem_ctx, struct winbindd_gr *gr,
35 const char *dom_name, const char *gr_name, gid_t unix_gid)
37 const char *full_group_name;
38 char *mapped_name = NULL;
39 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
41 nt_status = normalize_name_map(mem_ctx, dom_name, gr_name,
44 /* Basic whitespace replacement */
45 if (NT_STATUS_IS_OK(nt_status)) {
46 full_group_name = fill_domain_username_talloc(mem_ctx, dom_name,
49 /* Mapped to an aliase */
50 else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_FILE_RENAMED)) {
51 full_group_name = mapped_name;
55 full_group_name = fill_domain_username_talloc(mem_ctx, dom_name,
59 if (full_group_name == NULL) {
63 gr->gr_gid = unix_gid;
65 /* Group name and password */
67 strlcpy(gr->gr_name, full_group_name, sizeof(gr->gr_name));
68 strlcpy(gr->gr_passwd, "x", sizeof(gr->gr_passwd));
73 struct getgr_countmem {
78 static int getgr_calc_memberlen(struct db_record *rec, void *private_data)
80 struct getgr_countmem *buf = private_data;
81 TDB_DATA data = dbwrap_record_get_value(rec);
86 len = buf->len + data.dsize;
94 struct getgr_stringmem {
99 static int getgr_unparse_members(struct db_record *rec, void *private_data)
101 struct getgr_stringmem *buf = private_data;
102 TDB_DATA data = dbwrap_record_get_value(rec);
107 memcpy(buf->buf + buf->ofs, data.dptr, len);
109 buf->buf[buf->ofs] = ',';
114 NTSTATUS winbindd_print_groupmembers(struct db_context *members,
116 int *num_members, char **result)
118 struct getgr_countmem c;
119 struct getgr_stringmem m;
126 status = dbwrap_traverse(members, getgr_calc_memberlen, &c, &count);
127 if (!NT_STATUS_IS_OK(status)) {
128 DBG_NOTICE("dbwrap_traverse failed: %s\n", nt_errstr(status));
133 m.buf = talloc_array(mem_ctx, char, c.len);
135 DEBUG(5, ("talloc failed\n"));
136 return NT_STATUS_NO_MEMORY;
139 status = dbwrap_traverse(members, getgr_unparse_members, &m, &count);
140 if (!NT_STATUS_IS_OK(status)) {
142 DBG_NOTICE("dbwrap_traverse failed: %s\n", nt_errstr(status));
145 m.buf[c.len-1] = '\0';
147 *num_members = c.num;