r14076: When the backends trusted_domains call comes back with no trusts the
[Samba/gbeck.git] / source3 / sam / idmap_util.c
blob7233cb48cd1ef34fd5a94bc101af3e24634d5b72
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 /*****************************************************************
26 Returns SID pointer.
27 *****************************************************************/
29 NTSTATUS idmap_uid_to_sid(DOM_SID *sid, uid_t uid, int flags)
31 unid_t id;
33 DEBUG(10,("idmap_uid_to_sid: uid = [%lu]\n", (unsigned long)uid));
35 flags |= ID_USERID;
36 id.uid = uid;
38 return idmap_get_sid_from_id(sid, id, flags);
41 /*****************************************************************
42 Group mapping is used for gids that maps to Wellknown SIDs
43 Returns SID pointer.
44 *****************************************************************/
46 NTSTATUS idmap_gid_to_sid(DOM_SID *sid, gid_t gid, int flags)
48 unid_t id;
50 DEBUG(10,("idmap_gid_to_sid: gid = [%lu]\n", (unsigned long)gid));
52 flags |= ID_GROUPID;
53 id.gid = gid;
55 return idmap_get_sid_from_id(sid, id, flags);
58 /*****************************************************************
59 if it is a foreign sid or it is in idmap rid range check idmap,
60 otherwise falls back to the legacy algorithmic mapping.
61 Returns True if this name is a user sid and the conversion
62 was done correctly, False if not.
63 *****************************************************************/
65 NTSTATUS idmap_sid_to_uid(const DOM_SID *sid, uid_t *uid, uint32 flags)
67 NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
68 unid_t id;
70 DEBUG(10,("idmap_sid_to_uid: sid = [%s]\n", sid_string_static(sid)));
72 flags |= ID_USERID;
74 ret = idmap_get_id_from_sid(&id, (int *)&flags, sid);
76 if ( NT_STATUS_IS_OK(ret) ) {
77 DEBUG(10,("idmap_sid_to_uid: uid = [%lu]\n", (unsigned long)id.uid));
78 *uid = id.uid;
81 return ret;
85 /*****************************************************************
86 *THE CANONICAL* convert SID to gid function.
87 if it is a foreign sid or it is in idmap rid range check idmap,
88 otherwise falls back to the legacy algorithmic mapping.
89 Group mapping is used for gids that maps to Wellknown SIDs
90 Returns True if this name is a user sid and the conversion
91 was done correctly, False if not.
92 *****************************************************************/
94 NTSTATUS idmap_sid_to_gid(const DOM_SID *sid, gid_t *gid, uint32 flags)
96 NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
97 unid_t id;
99 DEBUG(10,("sid_to_gid: sid = [%s]\n", sid_string_static(sid)));
101 flags |= ID_GROUPID;
103 ret = idmap_get_id_from_sid(&id, (int *)&flags, sid);
105 if ( NT_STATUS_IS_OK(ret) )
107 DEBUG(10,("idmap_sid_to_gid: gid = [%lu]\n", (unsigned long)id.gid));
108 *gid = id.gid;
111 return ret;
114 /* placeholder for checking lp_winbind_nss_info() */
115 BOOL use_nss_info(const char *info)
117 int i;
118 const char **list = lp_winbind_nss_info();
120 for (i=0; list[i]; i++) {
121 if (strequal(list[i], info))
122 return True;
125 return False;