2 Unix SMB/CIFS implementation.
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.*/
24 #define DBGC_CLASS DBGC_IDMAP
26 /*****************************************************************
27 Returns the SID mapped to the given UID.
28 If mapping is not possible returns an error.
29 *****************************************************************/
31 NTSTATUS idmap_uid_to_sid(DOM_SID *sid, uid_t uid)
35 struct id_map *maps[2];
37 DEBUG(10,("uid = [%lu]\n", (unsigned long)uid));
40 map.xid.type = ID_TYPE_UID;
46 ret = idmap_unixids_to_sids(maps);
47 if ( ! NT_STATUS_IS_OK(ret)) {
48 DEBUG(10, ("error mapping uid [%lu]\n", (unsigned long)uid));
53 DEBUG(10, ("uid [%lu] not mapped\n", (unsigned long)uid));
54 return NT_STATUS_NONE_MAPPED;
60 /*****************************************************************
61 Returns SID mapped to the given GID.
62 If mapping is not possible returns an error.
63 *****************************************************************/
65 NTSTATUS idmap_gid_to_sid(DOM_SID *sid, gid_t gid)
69 struct id_map *maps[2];
71 DEBUG(10,("gid = [%lu]\n", (unsigned long)gid));
74 map.xid.type = ID_TYPE_GID;
80 ret = idmap_unixids_to_sids(maps);
81 if ( ! NT_STATUS_IS_OK(ret)) {
82 DEBUG(10, ("error mapping gid [%lu]\n", (unsigned long)gid));
87 DEBUG(10, ("gid [%lu] not mapped\n", (unsigned long)gid));
88 return NT_STATUS_NONE_MAPPED;
94 /*****************************************************************
95 Returns the UID mapped to the given SID.
96 If mapping is not possible or SID maps to a GID returns an error.
97 *****************************************************************/
99 NTSTATUS idmap_sid_to_uid(DOM_SID *sid, uid_t *uid)
103 struct id_map *maps[2];
105 DEBUG(10,("idmap_sid_to_uid: sid = [%s]\n", sid_string_static(sid)));
112 ret = idmap_sids_to_unixids(maps);
113 if ( ! NT_STATUS_IS_OK(ret)) {
114 DEBUG(10, ("error mapping sid [%s] to uid\n", sid_string_static(sid)));
118 if (( ! map.mapped) || (map.xid.type != ID_TYPE_UID)) {
119 DEBUG(10, ("sid [%s] not mapped to an uid [%u,%u,%u]\n", sid_string_static(sid), map.mapped, map.xid.type, map.xid.id));
120 return NT_STATUS_NONE_MAPPED;
128 /*****************************************************************
129 Returns the GID mapped to the given SID.
130 If mapping is not possible or SID maps to a UID returns an error.
131 *****************************************************************/
133 NTSTATUS idmap_sid_to_gid(DOM_SID *sid, gid_t *gid)
137 struct id_map *maps[2];
139 DEBUG(10,("idmap_sid_to_gid: sid = [%s]\n", sid_string_static(sid)));
146 ret = idmap_sids_to_unixids(maps);
147 if ( ! NT_STATUS_IS_OK(ret)) {
148 DEBUG(10, ("error mapping sid [%s] to gid\n", sid_string_static(sid)));
152 if (( ! map.mapped) || (map.xid.type != ID_TYPE_GID)) {
153 DEBUG(10, ("sid [%s] not mapped to an gid [%u,%u,%u]\n", sid_string_static(sid), map.mapped, map.xid.type, map.xid.id));
154 return NT_STATUS_NONE_MAPPED;