nsswitch/idmap_util.c

説明を見る。
00001 /* 
00002    Unix SMB/CIFS implementation.
00003    ID Mapping
00004    Copyright (C) Simo Sorce 2003
00005    Copyright (C) Jeremy Allison 2006
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program; if not, write to the Free Software
00019    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*/
00020 
00021 #include "includes.h"
00022 
00023 #undef DBGC_CLASS
00024 #define DBGC_CLASS DBGC_IDMAP
00025 
00026 /*****************************************************************
00027  Returns the SID mapped to the given UID.
00028  If mapping is not possible returns an error.
00029 *****************************************************************/  
00030 
00031 NTSTATUS idmap_uid_to_sid(DOM_SID *sid, uid_t uid)
00032 {
00033         NTSTATUS ret;
00034         struct id_map map;
00035         struct id_map *maps[2];
00036 
00037         DEBUG(10,("uid = [%lu]\n", (unsigned long)uid));
00038 
00039         map.sid = sid;
00040         map.xid.type = ID_TYPE_UID;
00041         map.xid.id = uid;
00042 
00043         maps[0] = ↦
00044         maps[1] = NULL;
00045         
00046         ret = idmap_unixids_to_sids(maps);
00047         if ( ! NT_STATUS_IS_OK(ret)) {
00048                 DEBUG(10, ("error mapping uid [%lu]\n", (unsigned long)uid));
00049                 return ret;
00050         }
00051 
00052         if (map.status != ID_MAPPED) {
00053                 DEBUG(10, ("uid [%lu] not mapped\n", (unsigned long)uid));
00054                 return NT_STATUS_NONE_MAPPED;
00055         }
00056 
00057         return NT_STATUS_OK;
00058 }
00059 
00060 /*****************************************************************
00061  Returns SID mapped to the given GID.
00062  If mapping is not possible returns an error.
00063 *****************************************************************/  
00064 
00065 NTSTATUS idmap_gid_to_sid(DOM_SID *sid, gid_t gid)
00066 {
00067         NTSTATUS ret;
00068         struct id_map map;
00069         struct id_map *maps[2];
00070 
00071         DEBUG(10,("gid = [%lu]\n", (unsigned long)gid));
00072 
00073         map.sid = sid;
00074         map.xid.type = ID_TYPE_GID;
00075         map.xid.id = gid;
00076 
00077         maps[0] = ↦
00078         maps[1] = NULL;
00079         
00080         ret = idmap_unixids_to_sids(maps);
00081         if ( ! NT_STATUS_IS_OK(ret)) {
00082                 DEBUG(10, ("error mapping gid [%lu]\n", (unsigned long)gid));
00083                 return ret;
00084         }
00085 
00086         if (map.status != ID_MAPPED) {
00087                 DEBUG(10, ("gid [%lu] not mapped\n", (unsigned long)gid));
00088                 return NT_STATUS_NONE_MAPPED;
00089         }
00090 
00091         return NT_STATUS_OK;
00092 }
00093 
00094 /*****************************************************************
00095  Returns the UID mapped to the given SID.
00096  If mapping is not possible or SID maps to a GID returns an error.
00097 *****************************************************************/  
00098 
00099 NTSTATUS idmap_sid_to_uid(DOM_SID *sid, uid_t *uid)
00100 {
00101         NTSTATUS ret;
00102         struct id_map map;
00103         struct id_map *maps[2];
00104 
00105         DEBUG(10,("idmap_sid_to_uid: sid = [%s]\n", sid_string_static(sid)));
00106 
00107         map.sid = sid;
00108         map.xid.type = ID_TYPE_UID;     
00109         
00110         maps[0] = ↦
00111         maps[1] = NULL;
00112         
00113         ret = idmap_sids_to_unixids(maps);
00114         if ( ! NT_STATUS_IS_OK(ret)) {
00115                 DEBUG(10, ("error mapping sid [%s] to uid\n", 
00116                            sid_string_static(sid)));
00117                 return ret;
00118         }
00119 
00120         if ((map.status != ID_MAPPED) || (map.xid.type != ID_TYPE_UID)) {
00121                 DEBUG(10, ("sid [%s] not mapped to an uid [%u,%u,%u]\n", 
00122                            sid_string_static(sid), 
00123                            map.status, 
00124                            map.xid.type, 
00125                            map.xid.id));
00126                 return NT_STATUS_NONE_MAPPED;
00127         }
00128 
00129         *uid = map.xid.id;
00130 
00131         return NT_STATUS_OK;
00132 }
00133 
00134 /*****************************************************************
00135  Returns the GID mapped to the given SID.
00136  If mapping is not possible or SID maps to a UID returns an error.
00137 *****************************************************************/  
00138 
00139 NTSTATUS idmap_sid_to_gid(DOM_SID *sid, gid_t *gid)
00140 {
00141         NTSTATUS ret;
00142         struct id_map map;
00143         struct id_map *maps[2];
00144 
00145         DEBUG(10,("idmap_sid_to_gid: sid = [%s]\n", sid_string_static(sid)));
00146 
00147         map.sid = sid;
00148         map.xid.type = ID_TYPE_GID;
00149         
00150         maps[0] = ↦
00151         maps[1] = NULL;
00152         
00153         ret = idmap_sids_to_unixids(maps);
00154         if ( ! NT_STATUS_IS_OK(ret)) {
00155                 DEBUG(10, ("error mapping sid [%s] to gid\n", 
00156                            sid_string_static(sid)));
00157                 return ret;
00158         }
00159 
00160         if ((map.status != ID_MAPPED) || (map.xid.type != ID_TYPE_GID)) {
00161                 DEBUG(10, ("sid [%s] not mapped to an gid [%u,%u]\n", 
00162                            sid_string_static(sid), 
00163                            map.status, 
00164                            map.xid.type));
00165                 return NT_STATUS_NONE_MAPPED;
00166         }
00167 
00168         *gid = map.xid.id;
00169 
00170         return NT_STATUS_OK;
00171 }

Sambaに対してSat Aug 29 21:23:09 2009に生成されました。  doxygen 1.4.7