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
;
39 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
41 domain
= find_domain_from_name_noinit(dom_name
);
43 DEBUG(0, ("Failed to find domain '%s'. "
44 "Check connection to trusted domains!\n",
49 nt_status
= normalize_name_map(mem_ctx
, domain
, gr_name
,
52 /* Basic whitespace replacement */
53 if (NT_STATUS_IS_OK(nt_status
)) {
54 fill_domain_username(full_group_name
, dom_name
,
57 /* Mapped to an aliase */
58 else if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_FILE_RENAMED
)) {
59 fstrcpy(full_group_name
, mapped_name
);
63 fill_domain_username( full_group_name
, dom_name
,
67 gr
->gr_gid
= unix_gid
;
69 /* Group name and password */
71 strlcpy(gr
->gr_name
, full_group_name
, sizeof(gr
->gr_name
));
72 strlcpy(gr
->gr_passwd
, "x", sizeof(gr
->gr_passwd
));
77 struct getgr_countmem
{
82 static int getgr_calc_memberlen(DATA_BLOB key
, void *data
, void *priv
)
84 struct wbint_Principal
*m
= talloc_get_type_abort(
85 data
, struct wbint_Principal
);
86 struct getgr_countmem
*buf
= (struct getgr_countmem
*)priv
;
89 buf
->len
+= strlen(m
->name
) + 1;
93 struct getgr_stringmem
{
98 static int getgr_unparse_members(DATA_BLOB key
, void *data
, void *priv
)
100 struct wbint_Principal
*m
= talloc_get_type_abort(
101 data
, struct wbint_Principal
);
102 struct getgr_stringmem
*buf
= (struct getgr_stringmem
*)priv
;
105 len
= strlen(m
->name
);
107 memcpy(buf
->buf
+ buf
->ofs
, m
->name
, len
);
109 buf
->buf
[buf
->ofs
] = ',';
114 NTSTATUS
winbindd_print_groupmembers(struct talloc_dict
*members
,
116 int *num_members
, char **result
)
118 struct getgr_countmem c
;
119 struct getgr_stringmem m
;
125 res
= talloc_dict_traverse(members
, getgr_calc_memberlen
, &c
);
127 DEBUG(5, ("talloc_dict_traverse failed\n"));
128 return NT_STATUS_INTERNAL_ERROR
;
132 m
.buf
= talloc_array(mem_ctx
, char, c
.len
);
134 DEBUG(5, ("talloc failed\n"));
135 return NT_STATUS_NO_MEMORY
;
138 res
= talloc_dict_traverse(members
, getgr_unparse_members
, &m
);
140 DEBUG(5, ("talloc_dict_traverse failed\n"));
142 return NT_STATUS_INTERNAL_ERROR
;
144 m
.buf
[c
.len
-1] = '\0';
146 *num_members
= c
.num
;