r19787: get winbindd compiling
[Samba.git] / source / sam / idmap_util.c
blob8320b294f8fdb4bd9f12dc63eb64d1111330cabe
1 /*
2 Unix SMB/CIFS implementation.
3 ID Mapping
4 Copyright (C) Simo Sorce 2003
5 Copyright (C) Jeremy Allison 2006
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*/
21 #include "includes.h"
23 #undef DBGC_CLASS
24 #define DBGC_CLASS DBGC_IDMAP
26 /*****************************************************************
27 Returns SID pointer.
28 *****************************************************************/
30 NTSTATUS idmap_uid_to_sid(DOM_SID *sid, uid_t uid, int flags)
32 unid_t id;
34 DEBUG(10,("idmap_uid_to_sid: uid = [%lu]\n", (unsigned long)uid));
36 id.uid = uid;
38 return idmap_get_sid_from_id(sid, id, ID_USERID, 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 id.gid = gid;
54 return idmap_get_sid_from_id(sid, id, ID_GROUPID, flags);
57 /*****************************************************************
58 if it is a foreign sid or it is in idmap rid range check idmap,
59 otherwise falls back to the legacy algorithmic mapping.
60 Returns True if this name is a user sid and the conversion
61 was done correctly, False if not.
62 *****************************************************************/
64 NTSTATUS idmap_sid_to_uid(const DOM_SID *sid, uid_t *uid, int flags)
66 NTSTATUS ret;
67 enum idmap_type id_type;
68 unid_t id;
70 DEBUG(10,("idmap_sid_to_uid: sid = [%s]\n", sid_string_static(sid)));
72 /* For the LDAP and tdb backends we must *KNOW* what we're looking for.
73 This interface design *SUCKS* ! JRA. */
75 id_type = ID_USERID;
76 ret = idmap_get_id_from_sid(&id, &id_type, sid, flags);
78 if (!NT_STATUS_IS_OK(ret)) {
79 return ret;
82 if (id_type != ID_USERID) {
83 return NT_STATUS_NONE_MAPPED;
86 DEBUG(10,("idmap_sid_to_uid: uid = [%lu]\n", (unsigned long)id.uid));
87 *uid = id.uid;
89 return NT_STATUS_OK;
92 /*****************************************************************
93 *THE CANONICAL* convert SID to gid function.
94 if it is a foreign sid or it is in idmap rid range check idmap,
95 otherwise falls back to the legacy algorithmic mapping.
96 Group mapping is used for gids that maps to Wellknown SIDs
97 Returns True if this name is a user sid and the conversion
98 was done correctly, False if not.
99 *****************************************************************/
101 NTSTATUS idmap_sid_to_gid(const DOM_SID *sid, gid_t *gid, int flags)
103 NTSTATUS ret;
104 enum idmap_type id_type;
105 unid_t id;
107 DEBUG(10,("sid_to_gid: sid = [%s]\n", sid_string_static(sid)));
109 /* For the LDAP and tdb backends we must *KNOW* what we're looking for.
110 This interface design *SUCKS* ! JRA. */
112 id_type = ID_GROUPID;
113 ret = idmap_get_id_from_sid(&id, &id_type, sid, flags);
115 if (!NT_STATUS_IS_OK(ret)) {
116 return ret;
119 if (id_type != ID_GROUPID) {
120 return NT_STATUS_NONE_MAPPED;
123 DEBUG(10,("idmap_sid_to_gid: gid = [%lu]\n", (unsigned long)id.gid));
124 *gid = id.gid;
126 return NT_STATUS_OK;