2 Unix SMB/CIFS implementation.
6 Copyright (C) Simo Sorce 2006
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #define DBGC_CLASS DBGC_IDMAP
29 /*****************************
30 Initialise idmap database.
31 *****************************/
33 static NTSTATUS idmap_nss_int_init(struct idmap_domain *dom, const char *compat_params)
38 /**********************************
39 lookup a set of unix ids.
40 **********************************/
42 static NTSTATUS idmap_nss_unixids_to_sids(struct idmap_domain *dom, struct id_map **ids)
47 ctx = talloc_new(dom);
49 DEBUG(0, ("Out of memory!\n"));
50 return NT_STATUS_NO_MEMORY;
53 for (i = 0; ids[i]; i++) {
57 enum lsa_SidType type;
60 switch (ids[i]->xid.type) {
62 pw = getpwuid((uid_t)ids[i]->xid.id);
65 ids[i]->mapped = False;
71 gr = getgrgid((gid_t)ids[i]->xid.id);
74 ids[i]->mapped = False;
80 ids[i]->mapped = False;
84 /* by default calls to winbindd are disabled
85 the following call will not recurse so this is safe */
87 /* Lookup name from PDC using lsa_lookup_names() */
88 ret = winbind_lookup_name(dom->name, name, ids[i]->sid, &type);
92 ids[i]->mapped = False;
96 /* make sure it is marked as unmapped if types do not match */
97 ids[i]->mapped = False;
101 if (ids[i]->xid.type == ID_TYPE_UID) {
102 ids[i]->mapped = True;
106 case SID_NAME_DOM_GRP:
108 case SID_NAME_WKN_GRP:
109 if (ids[i]->xid.type == ID_TYPE_GID) {
110 ids[i]->mapped = True;
124 /**********************************
125 lookup a set of sids.
126 **********************************/
128 static NTSTATUS idmap_nss_sids_to_unixids(struct idmap_domain *dom, struct id_map **ids)
133 ctx = talloc_new(dom);
135 DEBUG(0, ("Out of memory!\n"));
136 return NT_STATUS_NO_MEMORY;
139 for (i = 0; ids[i]; i++) {
142 enum lsa_SidType type;
143 const char *dom_name = NULL;
144 const char *name = NULL;
147 /* by default calls to winbindd are disabled
148 the following call will not recurse so this is safe */
150 ret = winbind_lookup_sid(ctx, ids[i]->sid, &dom_name, &name, &type);
154 ids[i]->mapped = False;
158 /* make sure it is marked as unmapped if types do not match */
159 ids[i]->mapped = False;
164 /* this will find also all lower case name and use username level */
166 pw = Get_Pwnam(name);
168 ids[i]->xid.id = pw->pw_uid;
169 ids[i]->xid.type = ID_TYPE_UID;
170 ids[i]->mapped = True;
174 case SID_NAME_DOM_GRP:
176 case SID_NAME_WKN_GRP:
180 ids[i]->xid.id = gr->gr_gid;
181 ids[i]->xid.type = ID_TYPE_GID;
182 ids[i]->mapped = True;
187 ids[i]->mapped = False;
196 /**********************************
197 Close the idmap tdb instance
198 **********************************/
200 static NTSTATUS idmap_nss_close(struct idmap_domain *dom)
205 static struct idmap_methods nss_methods = {
207 .init = idmap_nss_int_init,
208 .unixids_to_sids = idmap_nss_unixids_to_sids,
209 .sids_to_unixids = idmap_nss_sids_to_unixids,
210 .close_fn = idmap_nss_close
213 NTSTATUS idmap_nss_init(void)
215 return smb_register_idmap(SMB_IDMAP_INTERFACE_VERSION, "nss", &nss_methods);