r11161: another regression from merge; make sure to build vfs_full_audit modulebranch...
[Samba.git] / source / sam / idmap_util.c
blobcac8934f7b65743387af719741863abca356f544
1 /*
2 Unix SMB/CIFS implementation.
3 ID Mapping
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.*/
20 #include "includes.h"
22 #undef DBGC_CLASS
23 #define DBGC_CLASS DBGC_IDMAP
25 #if 0 /* NOT USED */
27 /**********************************************************************
28 Get the free RID base if idmap is configured, otherwise return 0
29 **********************************************************************/
31 uint32 idmap_get_free_rid_base(void)
33 uint32 low, high;
34 if (idmap_get_free_rid_range(&low, &high)) {
35 return low;
37 return 0;
40 /**********************************************************************
41 **********************************************************************/
43 BOOL idmap_check_ugid_is_in_free_range(uint32 id)
45 uint32 low, high;
47 if (!idmap_get_free_ugid_range(&low, &high)) {
48 return False;
50 if (id < low || id > high) {
51 return False;
53 return True;
56 /**********************************************************************
57 **********************************************************************/
59 BOOL idmap_check_rid_is_in_free_range(uint32 rid)
61 uint32 low, high;
63 if (!idmap_get_free_rid_range(&low, &high)) {
64 return False;
66 if (rid < algorithmic_rid_base()) {
67 return True;
70 if (rid < low || rid > high) {
71 return False;
74 return True;
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) {
85 uint32 rid;
87 if (sid_peek_rid(sid, &rid)) {
88 return idmap_check_rid_is_in_free_range(rid);
91 return False;
94 return True;
97 #endif /* NOT USED */
99 /*****************************************************************
100 Returns SID pointer.
101 *****************************************************************/
103 NTSTATUS idmap_uid_to_sid(DOM_SID *sid, uid_t uid, int flags)
105 unid_t id;
107 DEBUG(10,("idmap_uid_to_sid: uid = [%lu]\n", (unsigned long)uid));
109 flags |= ID_USERID;
110 id.uid = uid;
112 return idmap_get_sid_from_id(sid, id, flags);
115 /*****************************************************************
116 Group mapping is used for gids that maps to Wellknown SIDs
117 Returns SID pointer.
118 *****************************************************************/
120 NTSTATUS idmap_gid_to_sid(DOM_SID *sid, gid_t gid, int flags)
122 unid_t id;
124 DEBUG(10,("idmap_gid_to_sid: gid = [%lu]\n", (unsigned long)gid));
126 flags |= ID_GROUPID;
127 id.gid = 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;
142 unid_t id;
144 DEBUG(10,("idmap_sid_to_uid: sid = [%s]\n", sid_string_static(sid)));
146 flags |= ID_USERID;
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));
152 *uid = id.uid;
155 return ret;
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;
171 unid_t id;
173 DEBUG(10,("sid_to_gid: sid = [%s]\n", sid_string_static(sid)));
175 flags |= ID_GROUPID;
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));
182 *gid = id.gid;
185 return ret;
188 /* placeholder for checking lp_winbind_nss_info() */
189 BOOL use_nss_info(const char *info)
191 int i;
192 const char **list = lp_winbind_nss_info();
194 for (i=0; list[i]; i++) {
195 if (strequal(list[i], info))
196 return True;
199 return False;