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 3 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, see <http://www.gnu.org/licenses/>.
26 #define DBGC_CLASS DBGC_IDMAP
28 /*****************************
29 Initialise idmap database.
30 *****************************/
32 static NTSTATUS
idmap_nss_int_init(struct idmap_domain
*dom
)
34 dom
->initialized
= True
;
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 if (! dom
->initialized
) {
48 return NT_STATUS_UNSUCCESSFUL
;
51 ctx
= talloc_new(dom
);
53 DEBUG(0, ("Out of memory!\n"));
54 return NT_STATUS_NO_MEMORY
;
57 for (i
= 0; ids
[i
]; i
++) {
61 enum lsa_SidType type
;
64 switch (ids
[i
]->xid
.type
) {
66 pw
= getpwuid((uid_t
)ids
[i
]->xid
.id
);
69 ids
[i
]->status
= ID_UNMAPPED
;
75 gr
= getgrgid((gid_t
)ids
[i
]->xid
.id
);
78 ids
[i
]->status
= ID_UNMAPPED
;
84 ids
[i
]->status
= ID_UNKNOWN
;
88 /* by default calls to winbindd are disabled
89 the following call will not recurse so this is safe */
91 /* Lookup name from PDC using lsa_lookup_names() */
92 ret
= winbind_lookup_name(dom
->name
, name
, ids
[i
]->sid
, &type
);
96 /* TODO: how do we know if the name is really not mapped,
97 * or something just failed ? */
98 ids
[i
]->status
= ID_UNMAPPED
;
104 if (ids
[i
]->xid
.type
== ID_TYPE_UID
) {
105 ids
[i
]->status
= ID_MAPPED
;
109 case SID_NAME_DOM_GRP
:
111 case SID_NAME_WKN_GRP
:
112 if (ids
[i
]->xid
.type
== ID_TYPE_GID
) {
113 ids
[i
]->status
= ID_MAPPED
;
118 ids
[i
]->status
= ID_UNKNOWN
;
128 /**********************************
129 lookup a set of sids.
130 **********************************/
132 static NTSTATUS
idmap_nss_sids_to_unixids(struct idmap_domain
*dom
, struct id_map
**ids
)
137 if (! dom
->initialized
) {
138 return NT_STATUS_UNSUCCESSFUL
;
141 ctx
= talloc_new(dom
);
143 DEBUG(0, ("Out of memory!\n"));
144 return NT_STATUS_NO_MEMORY
;
147 for (i
= 0; ids
[i
]; i
++) {
149 enum lsa_SidType type
;
150 const char *dom_name
= NULL
;
151 const char *name
= NULL
;
154 /* by default calls to winbindd are disabled
155 the following call will not recurse so this is safe */
157 ret
= winbind_lookup_sid(ctx
, ids
[i
]->sid
, &dom_name
, &name
, &type
);
161 /* TODO: how do we know if the name is really not mapped,
162 * or something just failed ? */
163 ids
[i
]->status
= ID_UNMAPPED
;
168 case SID_NAME_USER
: {
171 /* this will find also all lower case name and use username level */
173 pw
= Get_Pwnam_alloc(talloc_tos(), name
);
175 ids
[i
]->xid
.id
= pw
->pw_uid
;
176 ids
[i
]->xid
.type
= ID_TYPE_UID
;
177 ids
[i
]->status
= ID_MAPPED
;
183 case SID_NAME_DOM_GRP
:
185 case SID_NAME_WKN_GRP
:
189 ids
[i
]->xid
.id
= gr
->gr_gid
;
190 ids
[i
]->xid
.type
= ID_TYPE_GID
;
191 ids
[i
]->status
= ID_MAPPED
;
196 ids
[i
]->status
= ID_UNKNOWN
;
205 /**********************************
206 Close the idmap tdb instance
207 **********************************/
209 static NTSTATUS
idmap_nss_close(struct idmap_domain
*dom
)
214 static struct idmap_methods nss_methods
= {
216 .init
= idmap_nss_int_init
,
217 .unixids_to_sids
= idmap_nss_unixids_to_sids
,
218 .sids_to_unixids
= idmap_nss_sids_to_unixids
,
219 .close_fn
= idmap_nss_close
222 NTSTATUS
idmap_nss_init(void)
224 return smb_register_idmap(SMB_IDMAP_INTERFACE_VERSION
, "nss", &nss_methods
);