smbXcli: Add "force_channel_sequence"
[Samba.git] / source3 / winbindd / winbindd_group.c
blobec95bf404a2abe45cb05e18e315c4df544b25e5f
1 /*
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/>.
25 #include "includes.h"
26 #include "winbindd.h"
28 #undef DBGC_CLASS
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 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
40 nt_status = normalize_name_map(mem_ctx, dom_name, gr_name,
41 &mapped_name);
43 /* Basic whitespace replacement */
44 if (NT_STATUS_IS_OK(nt_status)) {
45 fill_domain_username(full_group_name, dom_name,
46 mapped_name, true);
48 /* Mapped to an aliase */
49 else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_FILE_RENAMED)) {
50 fstrcpy(full_group_name, mapped_name);
52 /* no change */
53 else {
54 fill_domain_username( full_group_name, dom_name,
55 gr_name, True );
58 gr->gr_gid = unix_gid;
60 /* Group name and password */
62 strlcpy(gr->gr_name, full_group_name, sizeof(gr->gr_name));
63 strlcpy(gr->gr_passwd, "x", sizeof(gr->gr_passwd));
65 return True;
68 struct getgr_countmem {
69 int num;
70 size_t len;
73 static int getgr_calc_memberlen(DATA_BLOB key, void *data, void *priv)
75 struct wbint_Principal *m = talloc_get_type_abort(
76 data, struct wbint_Principal);
77 struct getgr_countmem *buf = (struct getgr_countmem *)priv;
79 buf->num += 1;
80 buf->len += strlen(m->name) + 1;
81 return 0;
84 struct getgr_stringmem {
85 size_t ofs;
86 char *buf;
89 static int getgr_unparse_members(DATA_BLOB key, void *data, void *priv)
91 struct wbint_Principal *m = talloc_get_type_abort(
92 data, struct wbint_Principal);
93 struct getgr_stringmem *buf = (struct getgr_stringmem *)priv;
94 int len;
96 len = strlen(m->name);
98 memcpy(buf->buf + buf->ofs, m->name, len);
99 buf->ofs += len;
100 buf->buf[buf->ofs] = ',';
101 buf->ofs += 1;
102 return 0;
105 NTSTATUS winbindd_print_groupmembers(struct talloc_dict *members,
106 TALLOC_CTX *mem_ctx,
107 int *num_members, char **result)
109 struct getgr_countmem c;
110 struct getgr_stringmem m;
111 int res;
113 c.num = 0;
114 c.len = 0;
116 res = talloc_dict_traverse(members, getgr_calc_memberlen, &c);
117 if (res == -1) {
118 DEBUG(5, ("talloc_dict_traverse failed\n"));
119 return NT_STATUS_INTERNAL_ERROR;
122 m.ofs = 0;
123 m.buf = talloc_array(mem_ctx, char, c.len);
124 if (m.buf == NULL) {
125 DEBUG(5, ("talloc failed\n"));
126 return NT_STATUS_NO_MEMORY;
129 res = talloc_dict_traverse(members, getgr_unparse_members, &m);
130 if (res == -1) {
131 DEBUG(5, ("talloc_dict_traverse failed\n"));
132 TALLOC_FREE(m.buf);
133 return NT_STATUS_INTERNAL_ERROR;
135 m.buf[c.len-1] = '\0';
137 *num_members = c.num;
138 *result = m.buf;
139 return NT_STATUS_OK;