2003-08-13 05:53:07 +04:00
/*
Unix SMB / CIFS implementation .
2004-05-15 11:51:38 +04:00
helper mapping functions for the SAMDB server
2003-08-13 05:53:07 +04:00
Copyright ( C ) Stefan ( metze ) Metzmacher 2002
2004-05-15 11:51:38 +04:00
Copyright ( C ) Andrew Tridgell 2004
2003-08-13 05:53:07 +04: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
the Free Software Foundation ; either version 2 of the License , or
( 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
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
2004-11-01 13:30:34 +03:00
# include "librpc/gen_ndr/ndr_samr.h"
2005-02-10 10:43:39 +03:00
# include "ads.h"
2003-08-13 05:53:07 +04:00
/*
translated the ACB_CTRL Flags to UserFlags ( userAccountControl )
*/
2004-05-15 11:51:38 +04:00
/* mapping between ADS userAccountControl and SAMR acct_flags */
static const struct {
2004-05-25 20:24:13 +04:00
uint32_t uf ;
2006-03-15 14:56:58 +03:00
uint32_t acb ;
2004-05-15 11:51:38 +04:00
} acct_flags_map [ ] = {
{ UF_ACCOUNTDISABLE , ACB_DISABLED } ,
{ UF_HOMEDIR_REQUIRED , ACB_HOMDIRREQ } ,
{ UF_PASSWD_NOTREQD , ACB_PWNOTREQ } ,
{ UF_TEMP_DUPLICATE_ACCOUNT , ACB_TEMPDUP } ,
{ UF_NORMAL_ACCOUNT , ACB_NORMAL } ,
{ UF_MNS_LOGON_ACCOUNT , ACB_MNS } ,
{ UF_INTERDOMAIN_TRUST_ACCOUNT , ACB_DOMTRUST } ,
{ UF_WORKSTATION_TRUST_ACCOUNT , ACB_WSTRUST } ,
{ UF_SERVER_TRUST_ACCOUNT , ACB_SVRTRUST } ,
{ UF_DONT_EXPIRE_PASSWD , ACB_PWNOEXP } ,
{ UF_LOCKOUT , ACB_AUTOLOCK }
} ;
2003-08-13 05:53:07 +04:00
2006-03-15 14:56:58 +03:00
uint32_t samdb_acb2uf ( uint32_t acb )
2004-05-15 11:51:38 +04:00
{
2004-05-25 20:24:13 +04:00
uint32_t i , ret = 0 ;
2004-05-15 11:51:38 +04:00
for ( i = 0 ; i < ARRAY_SIZE ( acct_flags_map ) ; i + + ) {
if ( acct_flags_map [ i ] . acb & acb ) {
ret | = acct_flags_map [ i ] . uf ;
}
}
return ret ;
2003-08-13 05:53:07 +04:00
}
/*
translated the UserFlags ( userAccountControl ) to ACB_CTRL Flags
*/
2006-03-15 14:56:58 +03:00
uint32_t samdb_uf2acb ( uint32_t uf )
2003-08-13 05:53:07 +04:00
{
2004-05-25 20:24:13 +04:00
uint32_t i ;
2006-03-15 14:56:58 +03:00
uint32_t ret = 0 ;
2004-05-15 11:51:38 +04:00
for ( i = 0 ; i < ARRAY_SIZE ( acct_flags_map ) ; i + + ) {
if ( acct_flags_map [ i ] . uf & uf ) {
ret | = acct_flags_map [ i ] . acb ;
}
2003-08-13 05:53:07 +04:00
}
2004-05-15 11:51:38 +04:00
return ret ;
2003-08-13 05:53:07 +04:00
}
/*
get the accountType from the UserFlags
*/
2004-05-25 20:24:13 +04:00
uint32_t samdb_uf2atype ( uint32_t uf )
2003-08-13 05:53:07 +04:00
{
2004-05-25 20:24:13 +04:00
uint32_t atype = 0x00000000 ;
2003-08-13 05:53:07 +04:00
if ( uf & UF_NORMAL_ACCOUNT ) atype = ATYPE_NORMAL_ACCOUNT ;
else if ( uf & UF_TEMP_DUPLICATE_ACCOUNT ) atype = ATYPE_NORMAL_ACCOUNT ;
else if ( uf & UF_SERVER_TRUST_ACCOUNT ) atype = ATYPE_WORKSTATION_TRUST ;
else if ( uf & UF_WORKSTATION_TRUST_ACCOUNT ) atype = ATYPE_WORKSTATION_TRUST ;
else if ( uf & UF_INTERDOMAIN_TRUST_ACCOUNT ) atype = ATYPE_INTERDOMAIN_TRUST ;
return atype ;
}
/*
get the accountType from the groupType
*/
2004-05-25 20:24:13 +04:00
uint32_t samdb_gtype2atype ( uint32_t gtype )
2003-08-13 05:53:07 +04:00
{
2004-05-25 20:24:13 +04:00
uint32_t atype = 0x00000000 ;
2003-08-13 05:53:07 +04:00
switch ( gtype ) {
case GTYPE_SECURITY_BUILTIN_LOCAL_GROUP :
atype = ATYPE_SECURITY_LOCAL_GROUP ;
break ;
case GTYPE_SECURITY_DOMAIN_LOCAL_GROUP :
atype = ATYPE_SECURITY_LOCAL_GROUP ;
break ;
case GTYPE_SECURITY_GLOBAL_GROUP :
atype = ATYPE_SECURITY_GLOBAL_GROUP ;
break ;
case GTYPE_DISTRIBUTION_GLOBAL_GROUP :
atype = ATYPE_DISTRIBUTION_GLOBAL_GROUP ;
break ;
case GTYPE_DISTRIBUTION_DOMAIN_LOCAL_GROUP :
atype = ATYPE_DISTRIBUTION_UNIVERSAL_GROUP ;
break ;
case GTYPE_DISTRIBUTION_UNIVERSAL_GROUP :
atype = ATYPE_DISTRIBUTION_LOCAL_GROUP ;
break ;
}
return atype ;
}
/* turn a sAMAccountType into a SID_NAME_USE */
2005-01-06 16:34:18 +03:00
enum lsa_SidType samdb_atype_map ( uint32_t atype )
2003-08-13 05:53:07 +04:00
{
switch ( atype & 0xF0000000 ) {
case ATYPE_GLOBAL_GROUP :
return SID_NAME_DOM_GRP ;
2004-02-01 14:26:25 +03:00
case ATYPE_SECURITY_LOCAL_GROUP :
return SID_NAME_ALIAS ;
2003-08-13 05:53:07 +04:00
case ATYPE_ACCOUNT :
return SID_NAME_USER ;
default :
DEBUG ( 1 , ( " hmm, need to map account type 0x%x \n " , atype ) ) ;
}
return SID_NAME_UNKNOWN ;
}