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 D_DEBUG("Filling domain '%s' and group '%s'.\n", dom_name
, gr_name
);
45 /* Basic whitespace replacement */
46 if (NT_STATUS_IS_OK(nt_status
)) {
47 full_group_name
= fill_domain_username_talloc(mem_ctx
, dom_name
,
50 /* Mapped to an alias */
51 else if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_FILE_RENAMED
)) {
52 full_group_name
= mapped_name
;
56 full_group_name
= fill_domain_username_talloc(mem_ctx
, dom_name
,
60 if (full_group_name
== NULL
) {
61 D_DEBUG("Returning false, since there is no full group name.\n");
65 gr
->gr_gid
= unix_gid
;
67 /* Group name and password */
69 strlcpy(gr
->gr_name
, full_group_name
, sizeof(gr
->gr_name
));
70 strlcpy(gr
->gr_passwd
, "x", sizeof(gr
->gr_passwd
));
72 D_DEBUG("Returning true. Full group name is '%s'.\n", gr_name
);
76 struct getgr_countmem
{
81 static int getgr_calc_memberlen(struct db_record
*rec
, void *private_data
)
83 struct getgr_countmem
*buf
= private_data
;
84 TDB_DATA data
= dbwrap_record_get_value(rec
);
89 len
= buf
->len
+ data
.dsize
;
97 struct getgr_stringmem
{
102 static int getgr_unparse_members(struct db_record
*rec
, void *private_data
)
104 struct getgr_stringmem
*buf
= private_data
;
105 TDB_DATA data
= dbwrap_record_get_value(rec
);
110 memcpy(buf
->buf
+ buf
->ofs
, data
.dptr
, len
);
112 buf
->buf
[buf
->ofs
] = ',';
117 NTSTATUS
winbindd_print_groupmembers(struct db_context
*members
,
119 int *num_members
, char **result
)
121 struct getgr_countmem c
;
122 struct getgr_stringmem m
;
129 status
= dbwrap_traverse(members
, getgr_calc_memberlen
, &c
, &count
);
130 if (!NT_STATUS_IS_OK(status
)) {
131 DBG_NOTICE("dbwrap_traverse failed: %s\n", nt_errstr(status
));
136 m
.buf
= talloc_array(mem_ctx
, char, c
.len
);
138 D_WARNING("talloc failed\n");
139 return NT_STATUS_NO_MEMORY
;
142 status
= dbwrap_traverse(members
, getgr_unparse_members
, &m
, &count
);
143 if (!NT_STATUS_IS_OK(status
)) {
145 DBG_NOTICE("dbwrap_traverse failed: %s\n", nt_errstr(status
));
149 m
.buf
[c
.len
- 1] = '\0';
152 *num_members
= c
.num
;
154 D_DEBUG("Returning %d member(s).\n", *num_members
);