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)
36 DEBUG(10,("uid = [%lu]\n", (unsigned long)uid));
39 map.xid.type = ID_TYPE_UID;
43 ret = idmap_unixids_to_sids(&maps, 1);
44 if ( ! NT_STATUS_IS_OK(ret)) {
45 DEBUG(10, ("error mapping uid [%lu]\n", (unsigned long)uid));
49 if (map.status != ID_MAPPED) {
50 DEBUG(10, ("uid [%lu] not mapped\n", (unsigned long)uid));
51 return NT_STATUS_NONE_MAPPED;
57 /*****************************************************************
58 Returns SID mapped to the given GID.
59 If mapping is not possible returns an error.
60 *****************************************************************/
62 NTSTATUS idmap_gid_to_sid(DOM_SID *sid, gid_t gid)
68 DEBUG(10,("gid = [%lu]\n", (unsigned long)gid));
71 map.xid.type = ID_TYPE_GID;
75 ret = idmap_unixids_to_sids(&maps, 1);
76 if ( ! NT_STATUS_IS_OK(ret)) {
77 DEBUG(10, ("error mapping gid [%lu]\n", (unsigned long)gid));
81 if (map.status != ID_MAPPED) {
82 DEBUG(10, ("gid [%lu] not mapped\n", (unsigned long)gid));
83 return NT_STATUS_NONE_MAPPED;
89 /*****************************************************************
90 Returns the UID mapped to the given SID.
91 If mapping is not possible or SID maps to a GID returns an error.
92 *****************************************************************/
94 NTSTATUS idmap_sid_to_uid(DOM_SID *sid, uid_t *uid)
100 DEBUG(10,("idmap_sid_to_uid: sid = [%s]\n", sid_string_dbg(sid)));
103 map.xid.type = ID_TYPE_UID;
106 ret = idmap_sids_to_unixids(&maps, 1);
107 if ( ! NT_STATUS_IS_OK(ret)) {
108 DEBUG(10, ("error mapping sid [%s] to uid\n",
109 sid_string_dbg(sid)));
113 if ((map.status != ID_MAPPED) || (map.xid.type != ID_TYPE_UID)) {
114 DEBUG(10, ("sid [%s] not mapped to an uid [%u,%u,%u]\n",
119 return NT_STATUS_NONE_MAPPED;
127 /*****************************************************************
128 Returns the GID mapped to the given SID.
129 If mapping is not possible or SID maps to a UID returns an error.
130 *****************************************************************/
132 NTSTATUS idmap_sid_to_gid(DOM_SID *sid, gid_t *gid)
138 DEBUG(10,("idmap_sid_to_gid: sid = [%s]\n", sid_string_dbg(sid)));
141 map.xid.type = ID_TYPE_GID;
144 ret = idmap_sids_to_unixids(&maps, 1);
145 if ( ! NT_STATUS_IS_OK(ret)) {
146 DEBUG(10, ("error mapping sid [%s] to gid\n",
147 sid_string_dbg(sid)));
151 if ((map.status != ID_MAPPED) || (map.xid.type != ID_TYPE_GID)) {
152 DEBUG(10, ("sid [%s] not mapped to a gid [%u,%u]\n",
156 return NT_STATUS_NONE_MAPPED;