2006-12-12 17:52:13 +03:00
/*
* idmap_rid : static map between Active Directory / NT RIDs and RFC 2307 accounts
* Copyright ( C ) Guenther Deschner , 2004
* Copyright ( C ) Sumit Bose , 2004
*
* 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 .
*
* 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 .
*
* You should have received a copy of the GNU General Public License
2007-07-10 09:23:25 +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"
2006-12-12 18:16:26 +03:00
# include "winbindd.h"
2010-08-18 20:13:42 +04:00
# include "idmap.h"
2010-10-15 15:32:08 +04:00
# include "../libcli/security/dom_sid.h"
2006-12-12 17:52:13 +03:00
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_IDMAP
struct idmap_rid_context {
uint32_t base_rid ;
} ;
2007-01-22 19:54:02 +03:00
/******************************************************************************
compat params can ' t be used because of the completely different way
we support multiple domains in the new idmap
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2011-03-03 01:00:58 +03:00
static NTSTATUS idmap_rid_initialize ( struct idmap_domain * dom )
2006-12-12 17:52:13 +03:00
{
struct idmap_rid_context * ctx ;
2011-06-07 05:44:43 +04:00
ctx = talloc_zero ( dom , struct idmap_rid_context ) ;
2010-06-21 19:28:37 +04:00
if ( ctx = = NULL ) {
2006-12-12 17:52:13 +03:00
DEBUG ( 0 , ( " Out of memory! \n " ) ) ;
return NT_STATUS_NO_MEMORY ;
}
2017-03-18 21:05:10 +03:00
ctx - > base_rid = idmap_config_int ( dom - > name , " base_rid " , 0 ) ;
2010-06-22 14:44:22 +04:00
2006-12-12 17:52:13 +03:00
dom - > private_data = ctx ;
return NT_STATUS_OK ;
}
2010-06-22 14:38:19 +04:00
static NTSTATUS idmap_rid_id_to_sid ( struct idmap_domain * dom , struct id_map * map )
2006-12-12 17:52:13 +03:00
{
2010-06-22 14:38:19 +04:00
struct idmap_rid_context * ctx ;
ctx = talloc_get_type ( dom - > private_data , struct idmap_rid_context ) ;
2006-12-12 17:52:13 +03:00
/* apply filters before checking */
2010-06-22 14:38:19 +04:00
if ( ! idmap_unix_id_is_in_range ( map - > xid . id , dom ) ) {
2006-12-12 17:52:13 +03:00
DEBUG ( 5 , ( " Requested id (%u) out of range (%u - %u). Filtered! \n " ,
2010-06-22 14:38:19 +04:00
map - > xid . id , dom - > low_id , dom - > high_id ) ) ;
2006-12-12 17:52:13 +03:00
return NT_STATUS_NONE_MAPPED ;
}
2017-09-25 16:42:08 +03:00
if ( is_null_sid ( & dom - > dom_sid ) ) {
DBG_INFO ( " idmap domain '%s' without SID \n " , dom - > name ) ;
2017-10-09 14:29:05 +03:00
return NT_STATUS_NONE_MAPPED ;
2007-01-22 19:54:02 +03:00
}
2010-06-22 14:38:19 +04:00
2017-09-25 16:42:08 +03:00
sid_compose ( map - > sid , & dom - > dom_sid ,
map - > xid . id - dom - > low_id + ctx - > base_rid ) ;
2006-12-12 17:52:13 +03:00
2007-01-14 20:58:24 +03:00
map - > status = ID_MAPPED ;
2012-10-15 18:32:25 +04:00
map - > xid . type = ID_TYPE_BOTH ;
2006-12-12 17:52:13 +03:00
return NT_STATUS_OK ;
}
/**********************************
2015-12-27 21:55:40 +03:00
Single sid to id lookup function .
2006-12-12 17:52:13 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-06-22 14:42:06 +04:00
static NTSTATUS idmap_rid_sid_to_id ( struct idmap_domain * dom , struct id_map * map )
2006-12-12 17:52:13 +03:00
{
uint32_t rid ;
2010-06-22 14:42:06 +04:00
struct idmap_rid_context * ctx ;
ctx = talloc_get_type ( dom - > private_data , struct idmap_rid_context ) ;
2006-12-12 17:52:13 +03:00
sid_peek_rid ( map - > sid , & rid ) ;
2010-06-22 14:42:06 +04:00
map - > xid . id = rid - ctx - > base_rid + dom - > low_id ;
2012-10-15 18:32:25 +04:00
map - > xid . type = ID_TYPE_BOTH ;
2006-12-12 17:52:13 +03:00
/* apply filters before returning result */
2007-04-20 02:26:09 +04:00
2010-06-22 14:42:06 +04:00
if ( ! idmap_unix_id_is_in_range ( map - > xid . id , dom ) ) {
2006-12-12 17:52:13 +03:00
DEBUG ( 5 , ( " Requested id (%u) out of range (%u - %u). Filtered! \n " ,
2010-06-22 14:42:06 +04:00
map - > xid . id , dom - > low_id , dom - > high_id ) ) ;
2007-01-14 20:58:24 +03:00
map - > status = ID_UNMAPPED ;
2006-12-12 17:52:13 +03:00
return NT_STATUS_NONE_MAPPED ;
}
2007-01-14 20:58:24 +03:00
map - > status = ID_MAPPED ;
2006-12-12 17:52:13 +03:00
return NT_STATUS_OK ;
}
/**********************************
2015-12-27 21:55:40 +03:00
lookup a set of unix ids .
2006-12-12 17:52:13 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS idmap_rid_unixids_to_sids ( struct idmap_domain * dom , struct id_map * * ids )
{
NTSTATUS ret ;
int i ;
2023-07-18 12:45:25 +03:00
/* initialize the status to avoid surprise */
2009-03-02 09:19:50 +03:00
for ( i = 0 ; ids [ i ] ; i + + ) {
ids [ i ] - > status = ID_UNKNOWN ;
}
2006-12-13 19:39:50 +03:00
2006-12-12 17:52:13 +03:00
for ( i = 0 ; ids [ i ] ; i + + ) {
2010-06-22 14:38:19 +04:00
ret = idmap_rid_id_to_sid ( dom , ids [ i ] ) ;
2006-12-12 17:52:13 +03:00
if ( ( ! NT_STATUS_IS_OK ( ret ) ) & &
( ! NT_STATUS_EQUAL ( ret , NT_STATUS_NONE_MAPPED ) ) ) {
/* some fatal error occurred, log it */
2016-12-11 21:57:20 +03:00
DBG_NOTICE ( " Unexpected error resolving an ID "
" (%d): %s \n " , ids [ i ] - > xid . id ,
nt_errstr ( ret ) ) ;
2006-12-12 17:52:13 +03:00
}
}
return NT_STATUS_OK ;
}
/**********************************
2015-12-27 21:55:40 +03:00
lookup a set of sids .
2006-12-12 17:52:13 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS idmap_rid_sids_to_unixids ( struct idmap_domain * dom , struct id_map * * ids )
{
NTSTATUS ret ;
int i ;
2023-07-18 12:45:25 +03:00
/* initialize the status to avoid surprise */
2009-03-02 09:19:50 +03:00
for ( i = 0 ; ids [ i ] ; i + + ) {
ids [ i ] - > status = ID_UNKNOWN ;
}
2006-12-13 19:39:50 +03:00
2006-12-12 17:52:13 +03:00
for ( i = 0 ; ids [ i ] ; i + + ) {
2010-06-22 14:42:06 +04:00
ret = idmap_rid_sid_to_id ( dom , ids [ i ] ) ;
2006-12-12 17:52:13 +03:00
if ( ( ! NT_STATUS_IS_OK ( ret ) ) & &
( ! NT_STATUS_EQUAL ( ret , NT_STATUS_NONE_MAPPED ) ) ) {
2018-12-14 23:09:51 +03:00
struct dom_sid_buf buf ;
2006-12-12 17:52:13 +03:00
/* some fatal error occurred, log it */
DEBUG ( 3 , ( " Unexpected error resolving a SID (%s) \n " ,
2018-12-14 23:09:51 +03:00
dom_sid_str_buf ( ids [ i ] - > sid , & buf ) ) ) ;
2006-12-12 17:52:13 +03:00
}
}
return NT_STATUS_OK ;
}
2019-03-21 14:30:37 +03:00
static const struct idmap_methods rid_methods = {
2006-12-12 17:52:13 +03:00
. init = idmap_rid_initialize ,
. unixids_to_sids = idmap_rid_unixids_to_sids ,
. sids_to_unixids = idmap_rid_sids_to_unixids ,
} ;
2015-08-13 19:16:20 +03:00
static_decl_idmap ;
2017-04-20 22:24:43 +03:00
NTSTATUS idmap_rid_init ( TALLOC_CTX * ctx )
2006-12-12 17:52:13 +03:00
{
return smb_register_idmap ( SMB_IDMAP_INTERFACE_VERSION , " rid " , & rid_methods ) ;
}