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 3 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, see <http://www.gnu.org/licenses/>.*/
23 #define DBGC_CLASS DBGC_IDMAP
25 /*****************************************************************
26 Returns the SID mapped to the given UID.
27 If mapping is not possible returns an error.
28 *****************************************************************/
30 NTSTATUS idmap_uid_to_sid(DOM_SID *sid, uid_t uid)
34 struct id_map *maps[2];
36 DEBUG(10,("uid = [%lu]\n", (unsigned long)uid));
39 map.xid.type = ID_TYPE_UID;
45 ret = idmap_unixids_to_sids(maps);
46 if ( ! NT_STATUS_IS_OK(ret)) {
47 DEBUG(10, ("error mapping uid [%lu]\n", (unsigned long)uid));
51 if (map.status != ID_MAPPED) {
52 DEBUG(10, ("uid [%lu] not mapped\n", (unsigned long)uid));
53 return NT_STATUS_NONE_MAPPED;
59 /*****************************************************************
60 Returns SID mapped to the given GID.
61 If mapping is not possible returns an error.
62 *****************************************************************/
64 NTSTATUS idmap_gid_to_sid(DOM_SID *sid, gid_t gid)
68 struct id_map *maps[2];
70 DEBUG(10,("gid = [%lu]\n", (unsigned long)gid));
73 map.xid.type = ID_TYPE_GID;
79 ret = idmap_unixids_to_sids(maps);
80 if ( ! NT_STATUS_IS_OK(ret)) {
81 DEBUG(10, ("error mapping gid [%lu]\n", (unsigned long)gid));
85 if (map.status != ID_MAPPED) {
86 DEBUG(10, ("gid [%lu] not mapped\n", (unsigned long)gid));
87 return NT_STATUS_NONE_MAPPED;
93 /*****************************************************************
94 Returns the UID mapped to the given SID.
95 If mapping is not possible or SID maps to a GID returns an error.
96 *****************************************************************/
98 NTSTATUS idmap_sid_to_uid(DOM_SID *sid, uid_t *uid)
102 struct id_map *maps[2];
104 DEBUG(10,("idmap_sid_to_uid: sid = [%s]\n", sid_string_static(sid)));
107 map.xid.type = ID_TYPE_UID;
112 ret = idmap_sids_to_unixids(maps);
113 if ( ! NT_STATUS_IS_OK(ret)) {
114 DEBUG(10, ("error mapping sid [%s] to uid\n",
115 sid_string_static(sid)));
119 if ((map.status != ID_MAPPED) || (map.xid.type != ID_TYPE_UID)) {
120 DEBUG(10, ("sid [%s] not mapped to an uid [%u,%u,%u]\n",
121 sid_string_static(sid),
125 return NT_STATUS_NONE_MAPPED;
133 /*****************************************************************
134 Returns the GID mapped to the given SID.
135 If mapping is not possible or SID maps to a UID returns an error.
136 *****************************************************************/
138 NTSTATUS idmap_sid_to_gid(DOM_SID *sid, gid_t *gid)
142 struct id_map *maps[2];
144 DEBUG(10,("idmap_sid_to_gid: sid = [%s]\n", sid_string_static(sid)));
147 map.xid.type = ID_TYPE_GID;
152 ret = idmap_sids_to_unixids(maps);
153 if ( ! NT_STATUS_IS_OK(ret)) {
154 DEBUG(10, ("error mapping sid [%s] to gid\n",
155 sid_string_static(sid)));
159 if ((map.status != ID_MAPPED) || (map.xid.type != ID_TYPE_GID)) {
160 DEBUG(10, ("sid [%s] not mapped to a gid [%u,%u,%u]\n",
161 sid_string_static(sid),
165 return NT_STATUS_NONE_MAPPED;