2006-12-12 17:52:13 +03:00
/*
Unix SMB / CIFS implementation .
idmap PASSDB backend
Copyright ( C ) Simo Sorce 2006
2008-07-11 19:45:16 +04:00
2006-12-12 17:52:13 +03:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
2006-12-12 17:52:13 +03:00
( at your option ) any later version .
2008-07-11 19:45:16 +04:00
2006-12-12 17:52:13 +03:00
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
2008-07-11 19:45:16 +04:00
2006-12-12 17:52:13 +03:00
You should have received a copy of the GNU General Public License
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2006-12-12 17:52:13 +03:00
*/
# include "includes.h"
2010-08-18 20:13:42 +04:00
# include "idmap.h"
2006-12-12 17:52:13 +03:00
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_IDMAP
/*****************************
Initialise idmap database .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-07-13 14:07:40 +04:00
static NTSTATUS idmap_pdb_init ( struct idmap_domain * dom , const char * params )
2006-12-12 17:52:13 +03:00
{
return NT_STATUS_OK ;
}
/**********************************
lookup a set of unix ids .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS idmap_pdb_unixids_to_sids ( struct idmap_domain * dom , struct id_map * * ids )
{
int i ;
for ( i = 0 ; ids [ i ] ; i + + ) {
2007-01-14 20:58:24 +03:00
/* unmapped by default */
ids [ i ] - > status = ID_UNMAPPED ;
2006-12-12 17:52:13 +03:00
switch ( ids [ i ] - > xid . type ) {
case ID_TYPE_UID :
2007-01-14 20:58:24 +03:00
if ( pdb_uid_to_sid ( ( uid_t ) ids [ i ] - > xid . id , ids [ i ] - > sid ) ) {
ids [ i ] - > status = ID_MAPPED ;
}
2006-12-12 17:52:13 +03:00
break ;
case ID_TYPE_GID :
2007-01-14 20:58:24 +03:00
if ( pdb_gid_to_sid ( ( gid_t ) ids [ i ] - > xid . id , ids [ i ] - > sid ) ) {
ids [ i ] - > status = ID_MAPPED ;
}
2006-12-12 17:52:13 +03:00
break ;
default : /* ?? */
2007-01-14 20:58:24 +03:00
ids [ i ] - > status = ID_UNKNOWN ;
2006-12-12 17:52:13 +03:00
}
}
return NT_STATUS_OK ;
}
/**********************************
lookup a set of sids .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS idmap_pdb_sids_to_unixids ( struct idmap_domain * dom , struct id_map * * ids )
{
int i ;
for ( i = 0 ; ids [ i ] ; i + + ) {
enum lsa_SidType type ;
union unid_t id ;
2008-07-11 19:45:16 +04:00
2006-12-12 17:52:13 +03:00
if ( pdb_sid_to_id ( ids [ i ] - > sid , & id , & type ) ) {
switch ( type ) {
case SID_NAME_USER :
ids [ i ] - > xid . id = id . uid ;
ids [ i ] - > xid . type = ID_TYPE_UID ;
2007-01-14 20:58:24 +03:00
ids [ i ] - > status = ID_MAPPED ;
2006-12-12 17:52:13 +03:00
break ;
case SID_NAME_DOM_GRP :
case SID_NAME_ALIAS :
case SID_NAME_WKN_GRP :
ids [ i ] - > xid . id = id . gid ;
ids [ i ] - > xid . type = ID_TYPE_GID ;
2007-01-14 20:58:24 +03:00
ids [ i ] - > status = ID_MAPPED ;
2006-12-12 17:52:13 +03:00
break ;
default : /* ?? */
/* make sure it is marked as unmapped */
2007-01-14 20:58:24 +03:00
ids [ i ] - > status = ID_UNKNOWN ;
2006-12-12 17:52:13 +03:00
break ;
}
} else {
/* Query Failed */
2007-01-14 20:58:24 +03:00
ids [ i ] - > status = ID_UNMAPPED ;
2006-12-12 17:52:13 +03:00
}
}
return NT_STATUS_OK ;
}
/**********************************
Close the idmap tdb instance
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS idmap_pdb_close ( struct idmap_domain * dom )
{
return NT_STATUS_OK ;
}
static struct idmap_methods passdb_methods = {
. init = idmap_pdb_init ,
. unixids_to_sids = idmap_pdb_unixids_to_sids ,
. sids_to_unixids = idmap_pdb_sids_to_unixids ,
. close_fn = idmap_pdb_close
} ;
NTSTATUS idmap_passdb_init ( void )
{
return smb_register_idmap ( SMB_IDMAP_INTERFACE_VERSION , " passdb " , & passdb_methods ) ;
}