s3: Remove unused get_sam_group_entries
[Samba.git] / source3 / winbindd / winbindd_group.c
bloba985fa254fedbc7bb608765fccf27afbc00ca9c0
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 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,
42 &mapped_name);
44 /* Basic whitespace replacement */
45 if (NT_STATUS_IS_OK(nt_status)) {
46 fill_domain_username(full_group_name, dom_name,
47 mapped_name, true);
49 /* Mapped to an aliase */
50 else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_FILE_RENAMED)) {
51 fstrcpy(full_group_name, mapped_name);
53 /* no change */
54 else {
55 fill_domain_username( full_group_name, dom_name,
56 gr_name, True );
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);
66 return True;
69 struct getgr_countmem {
70 int num;
71 size_t len;
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;
80 buf->num += 1;
81 buf->len += strlen(m->name) + 1;
82 return 0;
85 struct getgr_stringmem {
86 size_t ofs;
87 char *buf;
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;
95 int len;
97 len = strlen(m->name);
99 memcpy(buf->buf + buf->ofs, m->name, len);
100 buf->ofs += len;
101 buf->buf[buf->ofs] = ',';
102 buf->ofs += 1;
103 return 0;
106 NTSTATUS winbindd_print_groupmembers(struct talloc_dict *members,
107 TALLOC_CTX *mem_ctx,
108 int *num_members, char **result)
110 struct getgr_countmem c;
111 struct getgr_stringmem m;
112 int res;
114 c.num = 0;
115 c.len = 0;
117 res = talloc_dict_traverse(members, getgr_calc_memberlen, &c);
118 if (res != 0) {
119 DEBUG(5, ("talloc_dict_traverse failed\n"));
120 return NT_STATUS_INTERNAL_ERROR;
123 m.ofs = 0;
124 m.buf = talloc_array(mem_ctx, char, c.len);
125 if (m.buf == NULL) {
126 DEBUG(5, ("talloc failed\n"));
127 return NT_STATUS_NO_MEMORY;
130 res = talloc_dict_traverse(members, getgr_unparse_members, &m);
131 if (res != 0) {
132 DEBUG(5, ("talloc_dict_traverse failed\n"));
133 TALLOC_FREE(m.buf);
134 return NT_STATUS_INTERNAL_ERROR;
136 m.buf[c.len-1] = '\0';
138 *num_members = c.num;
139 *result = m.buf;
140 return NT_STATUS_OK;