2 Unix SMB/CIFS implementation.
4 Copyright (C) Simo Sorce 2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*/
23 #define DBGC_CLASS DBGC_IDMAP
27 /**********************************************************************
28 Get the free RID base if idmap is configured, otherwise return 0
29 **********************************************************************/
31 uint32
idmap_get_free_rid_base(void)
34 if (idmap_get_free_rid_range(&low
, &high
)) {
40 /**********************************************************************
41 **********************************************************************/
43 BOOL
idmap_check_ugid_is_in_free_range(uint32 id
)
47 if (!idmap_get_free_ugid_range(&low
, &high
)) {
50 if (id
< low
|| id
> high
) {
56 /**********************************************************************
57 **********************************************************************/
59 BOOL
idmap_check_rid_is_in_free_range(uint32 rid
)
63 if (!idmap_get_free_rid_range(&low
, &high
)) {
66 if (rid
< algorithmic_rid_base()) {
70 if (rid
< low
|| rid
> high
) {
77 /**********************************************************************
78 if it is a foreign SID or if the SID is in the free range, return true
79 **********************************************************************/
81 BOOL
idmap_check_sid_is_in_free_range(const DOM_SID
*sid
)
83 if (sid_compare_domain(get_global_sam_sid(), sid
) == 0) {
87 if (sid_peek_rid(sid
, &rid
)) {
88 return idmap_check_rid_is_in_free_range(rid
);
99 /*****************************************************************
101 *****************************************************************/
103 NTSTATUS
idmap_uid_to_sid(DOM_SID
*sid
, uid_t uid
, int flags
)
107 DEBUG(10,("idmap_uid_to_sid: uid = [%lu]\n", (unsigned long)uid
));
112 return idmap_get_sid_from_id(sid
, id
, flags
);
115 /*****************************************************************
116 Group mapping is used for gids that maps to Wellknown SIDs
118 *****************************************************************/
120 NTSTATUS
idmap_gid_to_sid(DOM_SID
*sid
, gid_t gid
, int flags
)
124 DEBUG(10,("idmap_gid_to_sid: gid = [%lu]\n", (unsigned long)gid
));
129 return idmap_get_sid_from_id(sid
, id
, flags
);
132 /*****************************************************************
133 if it is a foreign sid or it is in idmap rid range check idmap,
134 otherwise falls back to the legacy algorithmic mapping.
135 Returns True if this name is a user sid and the conversion
136 was done correctly, False if not.
137 *****************************************************************/
139 NTSTATUS
idmap_sid_to_uid(const DOM_SID
*sid
, uid_t
*uid
, uint32 flags
)
141 NTSTATUS ret
= NT_STATUS_UNSUCCESSFUL
;
144 DEBUG(10,("idmap_sid_to_uid: sid = [%s]\n", sid_string_static(sid
)));
148 ret
= idmap_get_id_from_sid(&id
, (int *)&flags
, sid
);
150 if ( NT_STATUS_IS_OK(ret
) ) {
151 DEBUG(10,("idmap_sid_to_uid: uid = [%lu]\n", (unsigned long)id
.uid
));
159 /*****************************************************************
160 *THE CANONICAL* convert SID to gid function.
161 if it is a foreign sid or it is in idmap rid range check idmap,
162 otherwise falls back to the legacy algorithmic mapping.
163 Group mapping is used for gids that maps to Wellknown SIDs
164 Returns True if this name is a user sid and the conversion
165 was done correctly, False if not.
166 *****************************************************************/
168 NTSTATUS
idmap_sid_to_gid(const DOM_SID
*sid
, gid_t
*gid
, uint32 flags
)
170 NTSTATUS ret
= NT_STATUS_UNSUCCESSFUL
;
173 DEBUG(10,("sid_to_gid: sid = [%s]\n", sid_string_static(sid
)));
177 ret
= idmap_get_id_from_sid(&id
, (int *)&flags
, sid
);
179 if ( NT_STATUS_IS_OK(ret
) )
181 DEBUG(10,("idmap_sid_to_gid: gid = [%lu]\n", (unsigned long)id
.gid
));
188 /* placeholder for checking lp_winbind_nss_info() */
189 BOOL
use_nss_info(const char *info
)
192 const char **list
= lp_winbind_nss_info();
194 for (i
=0; list
[i
]; i
++) {
195 if (strequal(list
[i
], info
))