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/>.
29 #define DBGC_CLASS DBGC_WINBIND
31 /* Fill a grent structure from various other information */
33 bool fill_grent(TALLOC_CTX
*mem_ctx
, struct winbindd_gr
*gr
,
34 const char *dom_name
, const char *gr_name
, gid_t unix_gid
)
36 fstring full_group_name
;
37 char *mapped_name
= NULL
;
38 struct winbindd_domain
*domain
= find_domain_from_name_noinit(dom_name
);
39 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
41 nt_status
= normalize_name_map(mem_ctx
, domain
, gr_name
,
44 /* Basic whitespace replacement */
45 if (NT_STATUS_IS_OK(nt_status
)) {
46 fill_domain_username(full_group_name
, dom_name
,
49 /* Mapped to an aliase */
50 else if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_FILE_RENAMED
)) {
51 fstrcpy(full_group_name
, mapped_name
);
55 fill_domain_username( full_group_name
, dom_name
,
59 gr
->gr_gid
= unix_gid
;
61 /* Group name and password */
63 safe_strcpy(gr
->gr_name
, full_group_name
, sizeof(gr
->gr_name
) - 1);
64 safe_strcpy(gr
->gr_passwd
, "x", sizeof(gr
->gr_passwd
) - 1);
69 struct getgr_countmem
{
74 static int getgr_calc_memberlen(DATA_BLOB key
, void *data
, void *priv
)
76 struct wbint_Principal
*m
= talloc_get_type_abort(
77 data
, struct wbint_Principal
);
78 struct getgr_countmem
*buf
= (struct getgr_countmem
*)priv
;
81 buf
->len
+= strlen(m
->name
) + 1;
85 struct getgr_stringmem
{
90 static int getgr_unparse_members(DATA_BLOB key
, void *data
, void *priv
)
92 struct wbint_Principal
*m
= talloc_get_type_abort(
93 data
, struct wbint_Principal
);
94 struct getgr_stringmem
*buf
= (struct getgr_stringmem
*)priv
;
97 len
= strlen(m
->name
);
99 memcpy(buf
->buf
+ buf
->ofs
, m
->name
, len
);
101 buf
->buf
[buf
->ofs
] = ',';
106 NTSTATUS
winbindd_print_groupmembers(struct talloc_dict
*members
,
108 int *num_members
, char **result
)
110 struct getgr_countmem c
;
111 struct getgr_stringmem m
;
117 res
= talloc_dict_traverse(members
, getgr_calc_memberlen
, &c
);
119 DEBUG(5, ("talloc_dict_traverse failed\n"));
120 return NT_STATUS_INTERNAL_ERROR
;
124 m
.buf
= talloc_array(mem_ctx
, char, c
.len
);
126 DEBUG(5, ("talloc failed\n"));
127 return NT_STATUS_NO_MEMORY
;
130 res
= talloc_dict_traverse(members
, getgr_unparse_members
, &m
);
132 DEBUG(5, ("talloc_dict_traverse failed\n"));
134 return NT_STATUS_INTERNAL_ERROR
;
136 m
.buf
[c
.len
-1] = '\0';
138 *num_members
= c
.num
;