1998-05-07 22:19:05 +04:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
1998-05-07 22:19:05 +04:00
Password and authentication handling
2001-09-26 00:21:21 +04:00
Copyright ( C ) Jeremy Allison 1996 - 2001
2000-11-14 02:03:34 +03:00
Copyright ( C ) Luke Kenneth Casson Leighton 1996 - 1998
2006-02-21 17:34:11 +03:00
Copyright ( C ) Gerald ( Jerry ) Carter 2000 - 2006
2002-01-12 04:55:09 +03:00
Copyright ( C ) Andrew Bartlett 2001 - 2002
2003-05-12 22:12:31 +04:00
Copyright ( C ) Simo Sorce 2003
2006-02-13 20:08:25 +03:00
Copyright ( C ) Volker Lendecke 2006
1998-05-19 01:30:57 +04:00
1998-05-07 22:19:05 +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"
2002-07-15 14:35:28 +04:00
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_PASSDB
2003-07-01 08:11:42 +04:00
/******************************************************************
get the default domain / netbios name to be used when
testing authentication . For example , if you connect
to a Windows member server using a bogus domain name , the
Windows box will map the BOGUS \ user to DOMAIN \ user . A
standalone box will map to WKS \ user .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-02-21 17:34:11 +03:00
const char * my_sam_name ( void )
2003-05-07 12:21:06 +04:00
{
2003-07-01 00:45:14 +04:00
/* standalone servers can only use the local netbios name */
if ( lp_server_role ( ) = = ROLE_STANDALONE )
return global_myname ( ) ;
2003-07-01 08:11:42 +04:00
/* Windows domain members default to the DOMAIN
2003-07-01 00:45:14 +04:00
name when not specified */
return lp_workgroup ( ) ;
2003-05-07 12:21:06 +04:00
}
1999-12-13 16:27:58 +03:00
2006-02-25 00:36:40 +03:00
/**********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static int samu_destroy ( void * p )
{
struct samu * user = p ;
data_blob_clear_free ( & user - > lm_pw ) ;
data_blob_clear_free ( & user - > nt_pw ) ;
if ( user - > plaintext_pw )
memset ( user - > plaintext_pw , 0x0 , strlen ( user - > plaintext_pw ) ) ;
return 0 ;
}
2001-09-27 13:13:26 +04:00
2006-02-25 00:36:40 +03:00
/**********************************************************************
generate a new struct samuser
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
struct samu * samu_new ( TALLOC_CTX * ctx )
2001-09-27 13:13:26 +04:00
{
2006-02-25 00:36:40 +03:00
struct samu * user ;
if ( ! ( user = TALLOC_ZERO_P ( ctx , struct samu ) ) ) {
DEBUG ( 0 , ( " samuser_new: Talloc failed! \n " ) ) ;
return NULL ;
}
talloc_set_destructor ( user , samu_destroy ) ;
2002-11-07 10:19:10 +03:00
/* no initial methods */
2006-02-25 00:36:40 +03:00
2002-11-07 10:19:10 +03:00
user - > methods = NULL ;
2001-10-04 03:08:10 +04:00
/* Don't change these timestamp settings without a good reason.
They are important for NT member server compatibility . */
2006-02-20 23:09:36 +03:00
user - > logon_time = ( time_t ) 0 ;
user - > pass_last_set_time = ( time_t ) 0 ;
user - > pass_can_change_time = ( time_t ) 0 ;
2006-02-21 17:34:11 +03:00
user - > logoff_time = get_time_t_max ( ) ;
user - > kickoff_time = get_time_t_max ( ) ;
2006-02-20 23:09:36 +03:00
user - > pass_must_change_time = get_time_t_max ( ) ;
user - > fields_present = 0x00ffffff ;
user - > logon_divs = 168 ; /* hours per week */
user - > hours_len = 21 ; /* 21 times 8 bits = 168 */
memset ( user - > hours , 0xff , user - > hours_len ) ; /* available at all hours */
user - > bad_password_count = 0 ;
user - > logon_count = 0 ;
user - > unknown_6 = 0x000004ec ; /* don't know */
2002-01-15 04:14:58 +03:00
/* Some parts of samba strlen their pdb_get...() returns,
so this keeps the interface unchanged for now . */
2006-02-20 23:09:36 +03:00
user - > username = " " ;
user - > domain = " " ;
user - > nt_username = " " ;
user - > full_name = " " ;
user - > home_dir = " " ;
user - > logon_script = " " ;
user - > profile_path = " " ;
user - > acct_desc = " " ;
user - > workstations = " " ;
user - > unknown_str = " " ;
user - > munged_dial = " " ;
user - > plaintext_pw = NULL ;
2002-09-25 19:19:00 +04:00
2006-02-25 00:36:40 +03:00
/* Unless we know otherwise have a Account Control Bit
2003-10-10 16:57:44 +04:00
value of ' normal user ' . This helps User Manager , which
2006-02-25 00:36:40 +03:00
asks for a filtered list of users . */
2003-10-10 16:57:44 +04:00
2006-02-20 23:09:36 +03:00
user - > acct_ctrl = ACB_NORMAL ;
return user ;
}
2001-09-27 13:13:26 +04:00
2006-02-21 19:46:21 +03:00
/*********************************************************************
Initialize a struct samu from a struct passwd including the user
2006-02-25 00:36:40 +03:00
and group SIDs . The * user structure is filled out with the Unix
attributes and a user SID .
2006-02-21 19:46:21 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-02-12 18:20:40 +03:00
2006-02-25 00:36:40 +03:00
static NTSTATUS samu_set_unix_internal ( struct samu * user , const struct passwd * pwd , BOOL create )
2004-02-12 18:20:40 +03:00
{
const char * guest_account = lp_guestaccount ( ) ;
2006-02-25 00:36:40 +03:00
const char * domain = global_myname ( ) ;
uint32 urid ;
2006-02-21 19:46:21 +03:00
if ( ! pwd ) {
return NT_STATUS_NO_SUCH_USER ;
2004-02-12 18:20:40 +03:00
}
2006-02-21 22:22:49 +03:00
/* Basic properties based upon the Unix account information */
2006-02-25 00:36:40 +03:00
2006-02-21 19:46:21 +03:00
pdb_set_username ( user , pwd - > pw_name , PDB_SET ) ;
pdb_set_fullname ( user , pwd - > pw_gecos , PDB_SET ) ;
pdb_set_domain ( user , get_global_sam_name ( ) , PDB_DEFAULT ) ;
2006-02-25 00:36:40 +03:00
2006-02-21 22:22:49 +03:00
/* save the password structure for later use */
2006-02-25 00:36:40 +03:00
2006-02-21 22:22:49 +03:00
user - > unix_pw = tcopy_passwd ( user , pwd ) ;
2006-02-25 00:36:40 +03:00
/* Special case for the guest account which must have a RID of 501 */
2006-02-21 19:46:21 +03:00
2006-02-25 00:36:40 +03:00
if ( strequal ( pwd - > pw_name , guest_account ) ) {
2006-02-21 19:46:21 +03:00
if ( ! pdb_set_user_sid_from_rid ( user , DOMAIN_USER_RID_GUEST , PDB_DEFAULT ) ) {
return NT_STATUS_NO_SUCH_USER ;
}
return NT_STATUS_OK ;
2004-02-12 18:20:40 +03:00
}
2006-02-21 19:46:21 +03:00
2006-02-25 00:36:40 +03:00
/* Non-guest accounts...Check for a workstation or user account */
2006-02-21 19:46:21 +03:00
if ( pwd - > pw_name [ strlen ( pwd - > pw_name ) - 1 ] = = ' $ ' ) {
/* workstation */
2006-02-17 22:07:58 +03:00
2006-02-21 19:46:21 +03:00
if ( ! pdb_set_acct_ctrl ( user , ACB_WSTRUST , PDB_DEFAULT ) ) {
DEBUG ( 1 , ( " Failed to set 'workstation account' flags for user %s. \n " ,
pwd - > pw_name ) ) ;
return NT_STATUS_INVALID_COMPUTER_NAME ;
2006-02-25 00:36:40 +03:00
}
2004-02-12 18:20:40 +03:00
}
2006-02-21 19:46:21 +03:00
else {
/* user */
2006-02-17 22:07:58 +03:00
2006-02-21 19:46:21 +03:00
if ( ! pdb_set_acct_ctrl ( user , ACB_NORMAL , PDB_DEFAULT ) ) {
DEBUG ( 1 , ( " Failed to set 'normal account' flags for user %s. \n " ,
pwd - > pw_name ) ) ;
return NT_STATUS_INVALID_ACCOUNT_NAME ;
}
2002-07-15 14:35:28 +04:00
2006-02-25 00:36:40 +03:00
/* set some basic attributes */
2003-07-11 09:33:40 +04:00
2006-02-25 00:36:40 +03:00
pdb_set_profile_path ( user , talloc_sub_specified ( user ,
lp_logon_path ( ) , pwd - > pw_name , domain , pwd - > pw_uid , pwd - > pw_gid ) ,
PDB_DEFAULT ) ;
pdb_set_homedir ( user , talloc_sub_specified ( user ,
lp_logon_home ( ) , pwd - > pw_name , domain , pwd - > pw_uid , pwd - > pw_gid ) ,
PDB_DEFAULT ) ;
pdb_set_dir_drive ( user , talloc_sub_specified ( user ,
lp_logon_drive ( ) , pwd - > pw_name , domain , pwd - > pw_uid , pwd - > pw_gid ) ,
PDB_DEFAULT ) ;
pdb_set_logon_script ( user , talloc_sub_specified ( user ,
lp_logon_script ( ) , pwd - > pw_name , domain , pwd - > pw_uid , pwd - > pw_gid ) ,
PDB_DEFAULT ) ;
2006-02-21 17:34:11 +03:00
}
2006-02-25 00:36:40 +03:00
/* Now deal with the user SID. If we have a backend that can generate
RIDs , then do so . But sometimes the caller just wanted a structure
initialized and will fill in these fields later ( such as from a
NET_USER_INFO_3 structure ) */
2006-02-21 17:34:11 +03:00
2006-02-25 00:36:40 +03:00
if ( create & & ! pdb_rid_algorithm ( ) ) {
uint32 user_rid ;
DOM_SID user_sid ;
2006-02-04 01:19:41 +03:00
2006-02-25 00:36:40 +03:00
if ( ! pdb_new_rid ( & user_rid ) ) {
DEBUG ( 3 , ( " Could not allocate a new RID \n " ) ) ;
return NT_STATUS_ACCESS_DENIED ;
2006-02-04 01:19:41 +03:00
}
2006-02-25 00:36:40 +03:00
sid_copy ( & user_sid , get_global_sam_sid ( ) ) ;
sid_append_rid ( & user_sid , user_rid ) ;
2006-02-04 01:19:41 +03:00
2006-02-25 00:36:40 +03:00
if ( ! pdb_set_user_sid ( user , & user_sid , PDB_SET ) ) {
DEBUG ( 3 , ( " pdb_set_user_sid failed \n " ) ) ;
return NT_STATUS_INTERNAL_ERROR ;
2006-02-04 01:19:41 +03:00
}
2006-02-25 00:36:40 +03:00
return NT_STATUS_OK ;
2006-02-04 01:19:41 +03:00
}
2006-03-01 23:47:36 +03:00
/* generate a SID for the user with the RID algorithm */
2006-02-25 00:36:40 +03:00
urid = algorithmic_pdb_uid_to_user_rid ( user - > unix_pw - > pw_uid ) ;
if ( ! pdb_set_user_sid_from_rid ( user , urid , PDB_SET ) ) {
return NT_STATUS_INTERNAL_ERROR ;
2006-02-04 01:19:41 +03:00
}
2006-02-25 00:36:40 +03:00
return NT_STATUS_OK ;
}
2006-02-04 01:19:41 +03:00
2006-02-25 00:36:40 +03:00
/********************************************************************
Set the Unix user attributes
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-02-04 01:19:41 +03:00
2006-02-25 00:36:40 +03:00
NTSTATUS samu_set_unix ( struct samu * user , const struct passwd * pwd )
{
return samu_set_unix_internal ( user , pwd , False ) ;
2003-04-29 13:43:17 +04:00
}
2006-02-25 00:36:40 +03:00
NTSTATUS samu_alloc_rid_unix ( struct samu * user , const struct passwd * pwd )
{
return samu_set_unix_internal ( user , pwd , True ) ;
}
2003-04-29 13:43:17 +04:00
2001-09-26 00:21:21 +04:00
/**********************************************************
Encode the account control bits into a string .
length = length of string to encode into ( including terminating
null ) . length * MUST BE MORE THAN 2 * !
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-02-27 13:32:45 +03:00
char * pdb_encode_acct_ctrl ( uint32 acct_ctrl , size_t length )
2001-09-26 00:21:21 +04:00
{
static fstring acct_str ;
2004-02-08 14:02:11 +03:00
2001-09-26 00:21:21 +04:00
size_t i = 0 ;
2004-02-09 18:21:42 +03:00
SMB_ASSERT ( length < = sizeof ( acct_str ) ) ;
2001-09-26 00:21:21 +04:00
acct_str [ i + + ] = ' [ ' ;
if ( acct_ctrl & ACB_PWNOTREQ ) acct_str [ i + + ] = ' N ' ;
if ( acct_ctrl & ACB_DISABLED ) acct_str [ i + + ] = ' D ' ;
if ( acct_ctrl & ACB_HOMDIRREQ ) acct_str [ i + + ] = ' H ' ;
if ( acct_ctrl & ACB_TEMPDUP ) acct_str [ i + + ] = ' T ' ;
if ( acct_ctrl & ACB_NORMAL ) acct_str [ i + + ] = ' U ' ;
if ( acct_ctrl & ACB_MNS ) acct_str [ i + + ] = ' M ' ;
if ( acct_ctrl & ACB_WSTRUST ) acct_str [ i + + ] = ' W ' ;
if ( acct_ctrl & ACB_SVRTRUST ) acct_str [ i + + ] = ' S ' ;
if ( acct_ctrl & ACB_AUTOLOCK ) acct_str [ i + + ] = ' L ' ;
if ( acct_ctrl & ACB_PWNOEXP ) acct_str [ i + + ] = ' X ' ;
if ( acct_ctrl & ACB_DOMTRUST ) acct_str [ i + + ] = ' I ' ;
for ( ; i < length - 2 ; i + + )
acct_str [ i ] = ' ' ;
i = length - 2 ;
acct_str [ i + + ] = ' ] ' ;
acct_str [ i + + ] = ' \0 ' ;
return acct_str ;
}
/**********************************************************
Decode the account control bits from a string .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-02-27 13:32:45 +03:00
uint32 pdb_decode_acct_ctrl ( const char * p )
2001-09-26 00:21:21 +04:00
{
2006-02-27 13:32:45 +03:00
uint32 acct_ctrl = 0 ;
2001-09-26 00:21:21 +04:00
BOOL finished = False ;
/*
* Check if the account type bits have been encoded after the
* NT password ( in the form [ NDHTUWSLXI ] ) .
*/
if ( * p ! = ' [ ' )
return 0 ;
for ( p + + ; * p & & ! finished ; p + + ) {
switch ( * p ) {
case ' N ' : { acct_ctrl | = ACB_PWNOTREQ ; break ; /* 'N'o password. */ }
case ' D ' : { acct_ctrl | = ACB_DISABLED ; break ; /* 'D'isabled. */ }
case ' H ' : { acct_ctrl | = ACB_HOMDIRREQ ; break ; /* 'H'omedir required. */ }
case ' T ' : { acct_ctrl | = ACB_TEMPDUP ; break ; /* 'T'emp account. */ }
case ' U ' : { acct_ctrl | = ACB_NORMAL ; break ; /* 'U'ser account (normal). */ }
case ' M ' : { acct_ctrl | = ACB_MNS ; break ; /* 'M'NS logon user account. What is this ? */ }
case ' W ' : { acct_ctrl | = ACB_WSTRUST ; break ; /* 'W'orkstation account. */ }
case ' S ' : { acct_ctrl | = ACB_SVRTRUST ; break ; /* 'S'erver account. */ }
case ' L ' : { acct_ctrl | = ACB_AUTOLOCK ; break ; /* 'L'ocked account. */ }
case ' X ' : { acct_ctrl | = ACB_PWNOEXP ; break ; /* No 'X'piry on password */ }
case ' I ' : { acct_ctrl | = ACB_DOMTRUST ; break ; /* 'I'nterdomain trust account. */ }
case ' ' : { break ; }
case ' : ' :
case ' \n ' :
case ' \0 ' :
case ' ] ' :
default : { finished = True ; }
}
}
return acct_ctrl ;
}
/*************************************************************
Routine to set 32 hex password characters from a 16 byte array .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-02-27 13:32:45 +03:00
void pdb_sethexpwd ( char * p , const unsigned char * pwd , uint32 acct_ctrl )
2001-09-26 00:21:21 +04:00
{
if ( pwd ! = NULL ) {
int i ;
for ( i = 0 ; i < 16 ; i + + )
slprintf ( & p [ i * 2 ] , 3 , " %02X " , pwd [ i ] ) ;
} else {
if ( acct_ctrl & ACB_PWNOTREQ )
safe_strcpy ( p , " NO PASSWORDXXXXXXXXXXXXXXXXXXXXX " , 33 ) ;
else
safe_strcpy ( p , " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX " , 33 ) ;
}
}
/*************************************************************
Routine to get the 32 hex characters and turn them
into a 16 byte array .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
This commit is number 4 of 4.
In particular this commit focuses on:
Actually adding the 'const' to the passdb interface, and the flow-on changes.
Also kill off the 'disp_info' stuff, as its no longer used.
While these changes have been mildly tested, and are pretty small, any
assistance in this is appreciated.
----
These changes introduces a large dose of 'const' to the Samba tree.
There are a number of good reasons to do this:
- I want to allow the SAM_ACCOUNT structure to move from wasteful
pstrings and fstrings to allocated strings. We can't do that if
people are modifying these outputs, as they may well make
assumptions about getting pstrings and fstrings
- I want --with-pam_smbpass to compile with a slightly sane
volume of warnings, currently its pretty bad, even in 2.2
where is compiles at all.
- Tridge assures me that he no longer opposes 'const religion'
based on the ability to #define const the problem away.
- Changed Get_Pwnam(x,y) into two variants (so that the const
parameter can work correctly): - Get_Pwnam(const x) and
Get_Pwnam_Modify(x).
- Reworked smbd/chgpasswd.c to work with these mods, passing
around a 'struct passwd' rather than the modified username
---
This finishes this line of commits off, your tree should now compile again :-)
Andrew Bartlett
(This used to be commit c95f5aeb9327347674589ae313b75bee3bf8e317)
2001-10-29 10:35:11 +03:00
BOOL pdb_gethexpwd ( const char * p , unsigned char * pwd )
2001-09-26 00:21:21 +04:00
{
int i ;
unsigned char lonybble , hinybble ;
2003-01-03 11:28:12 +03:00
const char * hexchars = " 0123456789ABCDEF " ;
2001-09-26 00:21:21 +04:00
char * p1 , * p2 ;
if ( ! p )
return ( False ) ;
for ( i = 0 ; i < 32 ; i + = 2 ) {
2005-12-27 23:52:36 +03:00
hinybble = toupper_ascii ( p [ i ] ) ;
lonybble = toupper_ascii ( p [ i + 1 ] ) ;
2001-09-26 00:21:21 +04:00
p1 = strchr ( hexchars , hinybble ) ;
p2 = strchr ( hexchars , lonybble ) ;
if ( ! p1 | | ! p2 )
return ( False ) ;
hinybble = PTR_DIFF ( p1 , hexchars ) ;
lonybble = PTR_DIFF ( p2 , hexchars ) ;
pwd [ i / 2 ] = ( hinybble < < 4 ) | lonybble ;
}
return ( True ) ;
}
2004-08-13 22:02:58 +04:00
/*************************************************************
Routine to set 42 hex hours characters from a 21 byte array .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void pdb_sethexhours ( char * p , const unsigned char * hours )
{
if ( hours ! = NULL ) {
int i ;
for ( i = 0 ; i < 21 ; i + + ) {
slprintf ( & p [ i * 2 ] , 3 , " %02X " , hours [ i ] ) ;
}
} else {
safe_strcpy ( p , " FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF " , 43 ) ;
}
}
/*************************************************************
Routine to get the 42 hex characters and turn them
into a 21 byte array .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
BOOL pdb_gethexhours ( const char * p , unsigned char * hours )
{
int i ;
unsigned char lonybble , hinybble ;
const char * hexchars = " 0123456789ABCDEF " ;
char * p1 , * p2 ;
if ( ! p ) {
return ( False ) ;
}
for ( i = 0 ; i < 42 ; i + = 2 ) {
2005-12-27 23:52:36 +03:00
hinybble = toupper_ascii ( p [ i ] ) ;
lonybble = toupper_ascii ( p [ i + 1 ] ) ;
2004-08-13 22:02:58 +04:00
p1 = strchr ( hexchars , hinybble ) ;
p2 = strchr ( hexchars , lonybble ) ;
if ( ! p1 | | ! p2 ) {
return ( False ) ;
}
hinybble = PTR_DIFF ( p1 , hexchars ) ;
lonybble = PTR_DIFF ( p2 , hexchars ) ;
hours [ i / 2 ] = ( hinybble < < 4 ) | lonybble ;
}
return ( True ) ;
}
2006-02-25 00:36:40 +03:00
/********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
This patch cleans up some of our ldap code, for better behaviour:
We now always read the Domain SID out of LDAP. If the local secrets.tdb
is ever different to LDAP, it is overwritten out of LDAP. We also
store the 'algorithmic rid base' into LDAP, and assert if it changes.
(This ensures cross-host synchronisation, and allows for possible
integration with idmap). If we fail to read/add the domain entry, we just
fallback to the old behaviour.
We always use an existing DN when adding IDMAP entries to LDAP, unless
no suitable entry is available. This means that a user's posixAccount
will have a SID added to it, or a user's sambaSamAccount will have a UID
added. Where we cannot us an existing DN, we use
'sambaSid=S-x-y-z,....' as the DN.
The code now allows modifications to the ID mapping in many cases.
Likewise, we now check more carefully when adding new user entires to LDAP,
to not duplicate SIDs (for users, at this stage), and to add the sambaSamAccount
onto the idmap entry for that user, if it is already established (ensuring
we do not duplicate sambaSid entries in the directory).
The allocated UID code has been expanded to take into account the space
between '1000 - algorithmic rid base'. This much better fits into what
an NT4 does - allocating in the bottom part of the RID range.
On the code cleanup side of things, we now share as much code as
possible between idmap_ldap and pdb_ldap.
We also no longer use the race-prone 'enumerate all users' method for
finding the next RID to allocate. Instead, we just start at the bottom
of the range, and increment again if the user already exists. The first
time this is run, it may well take a long time, but next time will just
be able to use the next Rid.
Thanks to metze and AB for double-checking parts of this.
Andrew Bartlett
(This used to be commit 9c595c8c2327b92a86901d84c3f2c284dabd597e)
2003-07-04 17:29:42 +04:00
int algorithmic_rid_base ( void )
2002-11-05 10:20:27 +03:00
{
static int rid_offset = 0 ;
if ( rid_offset ! = 0 )
return rid_offset ;
rid_offset = lp_algorithmic_rid_base ( ) ;
if ( rid_offset < BASE_RID ) {
/* Try to prevent admin foot-shooting, we can't put algorithmic
rids below 1000 , that ' s the ' well known RIDs ' on NT */
DEBUG ( 0 , ( " 'algorithmic rid base' must be equal to or above %ld \n " , BASE_RID ) ) ;
rid_offset = BASE_RID ;
}
if ( rid_offset & 1 ) {
DEBUG ( 0 , ( " algorithmic rid base must be even \n " ) ) ;
rid_offset + = 1 ;
}
return rid_offset ;
}
2003-05-12 22:12:31 +04:00
/*******************************************************************
Converts NT user RID to a UNIX uid .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-05 10:20:27 +03:00
2004-08-17 23:59:22 +04:00
uid_t algorithmic_pdb_user_rid_to_uid ( uint32 user_rid )
1999-12-13 16:27:58 +03:00
{
2002-11-05 10:20:27 +03:00
int rid_offset = algorithmic_rid_base ( ) ;
2003-05-12 22:12:31 +04:00
return ( uid_t ) ( ( ( user_rid & ( ~ USER_RID_TYPE ) ) - rid_offset ) / RID_MULTIPLIER ) ;
1999-12-13 16:27:58 +03:00
}
2006-02-04 01:19:41 +03:00
uid_t max_algorithmic_uid ( void )
{
return algorithmic_pdb_user_rid_to_uid ( 0xfffffffe ) ;
}
This commit is number 4 of 4.
In particular this commit focuses on:
Actually adding the 'const' to the passdb interface, and the flow-on changes.
Also kill off the 'disp_info' stuff, as its no longer used.
While these changes have been mildly tested, and are pretty small, any
assistance in this is appreciated.
----
These changes introduces a large dose of 'const' to the Samba tree.
There are a number of good reasons to do this:
- I want to allow the SAM_ACCOUNT structure to move from wasteful
pstrings and fstrings to allocated strings. We can't do that if
people are modifying these outputs, as they may well make
assumptions about getting pstrings and fstrings
- I want --with-pam_smbpass to compile with a slightly sane
volume of warnings, currently its pretty bad, even in 2.2
where is compiles at all.
- Tridge assures me that he no longer opposes 'const religion'
based on the ability to #define const the problem away.
- Changed Get_Pwnam(x,y) into two variants (so that the const
parameter can work correctly): - Get_Pwnam(const x) and
Get_Pwnam_Modify(x).
- Reworked smbd/chgpasswd.c to work with these mods, passing
around a 'struct passwd' rather than the modified username
---
This finishes this line of commits off, your tree should now compile again :-)
Andrew Bartlett
(This used to be commit c95f5aeb9327347674589ae313b75bee3bf8e317)
2001-10-29 10:35:11 +03:00
/*******************************************************************
2002-03-18 14:35:53 +03:00
converts UNIX uid to an NT User RID .
This commit is number 4 of 4.
In particular this commit focuses on:
Actually adding the 'const' to the passdb interface, and the flow-on changes.
Also kill off the 'disp_info' stuff, as its no longer used.
While these changes have been mildly tested, and are pretty small, any
assistance in this is appreciated.
----
These changes introduces a large dose of 'const' to the Samba tree.
There are a number of good reasons to do this:
- I want to allow the SAM_ACCOUNT structure to move from wasteful
pstrings and fstrings to allocated strings. We can't do that if
people are modifying these outputs, as they may well make
assumptions about getting pstrings and fstrings
- I want --with-pam_smbpass to compile with a slightly sane
volume of warnings, currently its pretty bad, even in 2.2
where is compiles at all.
- Tridge assures me that he no longer opposes 'const religion'
based on the ability to #define const the problem away.
- Changed Get_Pwnam(x,y) into two variants (so that the const
parameter can work correctly): - Get_Pwnam(const x) and
Get_Pwnam_Modify(x).
- Reworked smbd/chgpasswd.c to work with these mods, passing
around a 'struct passwd' rather than the modified username
---
This finishes this line of commits off, your tree should now compile again :-)
Andrew Bartlett
(This used to be commit c95f5aeb9327347674589ae313b75bee3bf8e317)
2001-10-29 10:35:11 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-08-17 23:59:22 +04:00
uint32 algorithmic_pdb_uid_to_user_rid ( uid_t uid )
This commit is number 4 of 4.
In particular this commit focuses on:
Actually adding the 'const' to the passdb interface, and the flow-on changes.
Also kill off the 'disp_info' stuff, as its no longer used.
While these changes have been mildly tested, and are pretty small, any
assistance in this is appreciated.
----
These changes introduces a large dose of 'const' to the Samba tree.
There are a number of good reasons to do this:
- I want to allow the SAM_ACCOUNT structure to move from wasteful
pstrings and fstrings to allocated strings. We can't do that if
people are modifying these outputs, as they may well make
assumptions about getting pstrings and fstrings
- I want --with-pam_smbpass to compile with a slightly sane
volume of warnings, currently its pretty bad, even in 2.2
where is compiles at all.
- Tridge assures me that he no longer opposes 'const religion'
based on the ability to #define const the problem away.
- Changed Get_Pwnam(x,y) into two variants (so that the const
parameter can work correctly): - Get_Pwnam(const x) and
Get_Pwnam_Modify(x).
- Reworked smbd/chgpasswd.c to work with these mods, passing
around a 'struct passwd' rather than the modified username
---
This finishes this line of commits off, your tree should now compile again :-)
Andrew Bartlett
(This used to be commit c95f5aeb9327347674589ae313b75bee3bf8e317)
2001-10-29 10:35:11 +03:00
{
2002-11-05 10:20:27 +03:00
int rid_offset = algorithmic_rid_base ( ) ;
2002-07-15 14:35:28 +04:00
return ( ( ( ( ( uint32 ) uid ) * RID_MULTIPLIER ) + rid_offset ) | USER_RID_TYPE ) ;
This commit is number 4 of 4.
In particular this commit focuses on:
Actually adding the 'const' to the passdb interface, and the flow-on changes.
Also kill off the 'disp_info' stuff, as its no longer used.
While these changes have been mildly tested, and are pretty small, any
assistance in this is appreciated.
----
These changes introduces a large dose of 'const' to the Samba tree.
There are a number of good reasons to do this:
- I want to allow the SAM_ACCOUNT structure to move from wasteful
pstrings and fstrings to allocated strings. We can't do that if
people are modifying these outputs, as they may well make
assumptions about getting pstrings and fstrings
- I want --with-pam_smbpass to compile with a slightly sane
volume of warnings, currently its pretty bad, even in 2.2
where is compiles at all.
- Tridge assures me that he no longer opposes 'const religion'
based on the ability to #define const the problem away.
- Changed Get_Pwnam(x,y) into two variants (so that the const
parameter can work correctly): - Get_Pwnam(const x) and
Get_Pwnam_Modify(x).
- Reworked smbd/chgpasswd.c to work with these mods, passing
around a 'struct passwd' rather than the modified username
---
This finishes this line of commits off, your tree should now compile again :-)
Andrew Bartlett
(This used to be commit c95f5aeb9327347674589ae313b75bee3bf8e317)
2001-10-29 10:35:11 +03:00
}
2000-11-14 02:03:34 +03:00
/*******************************************************************
2002-03-18 14:35:53 +03:00
Converts NT group RID to a UNIX gid .
2000-11-14 02:03:34 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2002-03-18 14:35:53 +03:00
gid_t pdb_group_rid_to_gid ( uint32 group_rid )
1999-12-13 16:27:58 +03:00
{
2002-11-05 10:20:27 +03:00
int rid_offset = algorithmic_rid_base ( ) ;
2002-07-15 14:35:28 +04:00
return ( gid_t ) ( ( ( group_rid & ( ~ GROUP_RID_TYPE ) ) - rid_offset ) / RID_MULTIPLIER ) ;
1999-12-13 16:27:58 +03:00
}
2006-02-04 01:19:41 +03:00
gid_t max_algorithmic_gid ( void )
{
return pdb_group_rid_to_gid ( 0xffffffff ) ;
}
2000-11-14 02:03:34 +03:00
/*******************************************************************
converts NT Group RID to a UNIX uid .
2001-12-02 03:03:35 +03:00
warning : you must not call that function only
you must do a call to the group mapping first .
there is not anymore a direct link between the gid and the rid .
2000-11-14 02:03:34 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2000-10-07 19:56:36 +04:00
2000-11-14 02:03:34 +03:00
uint32 pdb_gid_to_group_rid ( gid_t gid )
2000-10-07 19:56:36 +04:00
{
2002-11-05 10:20:27 +03:00
int rid_offset = algorithmic_rid_base ( ) ;
2002-07-15 14:35:28 +04:00
return ( ( ( ( ( uint32 ) gid ) * RID_MULTIPLIER ) + rid_offset ) | GROUP_RID_TYPE ) ;
2000-10-07 19:56:36 +04:00
}
2000-11-14 02:03:34 +03:00
/*******************************************************************
Decides if a RID is a well known RID .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-02-25 00:36:40 +03:00
static BOOL rid_is_well_known ( uint32 rid )
2000-10-07 19:56:36 +04:00
{
2003-05-14 04:46:43 +04:00
/* Not using rid_offset here, because this is the actual
2002-07-15 14:35:28 +04:00
NT fixed value ( 1000 ) */
return ( rid < BASE_RID ) ;
2000-10-07 19:56:36 +04:00
}
1999-12-13 16:27:58 +03:00
2000-11-14 02:03:34 +03:00
/*******************************************************************
Decides if a RID is a user or group RID .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-09-26 00:21:21 +04:00
2004-08-17 23:59:22 +04:00
BOOL algorithmic_pdb_rid_is_user ( uint32 rid )
2000-11-14 02:03:34 +03:00
{
2006-02-25 00:36:40 +03:00
if ( rid_is_well_known ( rid ) ) {
2004-08-17 23:59:22 +04:00
/*
* The only well known user RIDs are DOMAIN_USER_RID_ADMIN
* and DOMAIN_USER_RID_GUEST .
*/
if ( rid = = DOMAIN_USER_RID_ADMIN | | rid = = DOMAIN_USER_RID_GUEST )
return True ;
} else if ( ( rid & RID_TYPE_MASK ) = = USER_RID_TYPE ) {
return True ;
}
return False ;
2000-11-14 02:03:34 +03:00
}
/*******************************************************************
Convert a name into a SID . Used in the lookup name rpc .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2006-02-13 20:08:25 +03:00
BOOL lookup_global_sam_name ( const char * user , int flags , uint32_t * rid ,
2006-02-04 01:19:41 +03:00
enum SID_NAME_USE * type )
1998-05-18 18:43:06 +04:00
{
2002-07-15 14:35:28 +04:00
GROUP_MAP map ;
2006-02-13 20:08:25 +03:00
BOOL ret ;
2006-02-04 01:19:41 +03:00
/* LOOKUP_NAME_GROUP is a hack to allow valid users = @foo to work
* correctly in the case where foo also exists as a user . If the flag
* is set , don ' t look for users at all . */
2006-02-13 20:08:25 +03:00
if ( ( flags & LOOKUP_NAME_GROUP ) = = 0 ) {
2006-02-20 23:09:36 +03:00
struct samu * sam_account = NULL ;
2006-02-13 20:08:25 +03:00
DOM_SID user_sid ;
2005-12-03 21:34:13 +03:00
2006-02-21 17:34:11 +03:00
if ( ! ( sam_account = samu_new ( NULL ) ) ) {
2005-12-03 21:34:13 +03:00
return False ;
}
2006-02-13 20:08:25 +03:00
become_root ( ) ;
ret = pdb_getsampwnam ( sam_account , user ) ;
unbecome_root ( ) ;
2005-12-03 21:34:13 +03:00
2006-02-13 20:08:25 +03:00
if ( ret ) {
sid_copy ( & user_sid , pdb_get_user_sid ( sam_account ) ) ;
}
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( sam_account ) ;
2002-01-26 15:24:18 +03:00
2006-02-13 20:08:25 +03:00
if ( ret ) {
if ( ! sid_check_is_in_our_domain ( & user_sid ) ) {
DEBUG ( 0 , ( " User %s with invalid SID %s in passdb \n " ,
user , sid_string_static ( & user_sid ) ) ) ;
return False ;
}
2005-12-03 21:34:13 +03:00
2006-02-13 20:08:25 +03:00
sid_peek_rid ( & user_sid , rid ) ;
* type = SID_NAME_USER ;
return True ;
2003-11-24 20:31:38 +03:00
}
2005-12-03 21:34:13 +03:00
}
2006-02-13 20:08:25 +03:00
/*
* Maybe it is a group ?
*/
become_root ( ) ;
ret = pdb_getgrnam ( & map , user ) ;
unbecome_root ( ) ;
2006-02-04 01:19:41 +03:00
2006-02-13 20:08:25 +03:00
if ( ! ret ) {
2005-12-03 21:34:13 +03:00
return False ;
}
2006-02-13 20:08:25 +03:00
/* BUILTIN groups are looked up elsewhere */
if ( ! sid_check_is_in_our_domain ( & map . sid ) ) {
DEBUG ( 10 , ( " Found group %s (%s) not in our domain -- "
" ignoring. " , user ,
sid_string_static ( & map . sid ) ) ) ;
2005-12-03 21:34:13 +03:00
return False ;
2000-11-14 02:03:34 +03:00
}
2006-02-13 20:08:25 +03:00
/* yes it's a mapped group */
sid_peek_rid ( & map . sid , rid ) ;
* type = map . sid_name_use ;
2000-11-14 02:03:34 +03:00
return True ;
1998-05-18 18:43:06 +04:00
}
2000-11-14 02:03:34 +03:00
/*************************************************************
2001-09-26 00:21:21 +04:00
Change a password entry in the local smbpasswd file .
2000-11-14 02:03:34 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2006-02-04 01:19:41 +03:00
NTSTATUS local_password_change ( const char * user_name , int local_flags ,
This commit is number 4 of 4.
In particular this commit focuses on:
Actually adding the 'const' to the passdb interface, and the flow-on changes.
Also kill off the 'disp_info' stuff, as its no longer used.
While these changes have been mildly tested, and are pretty small, any
assistance in this is appreciated.
----
These changes introduces a large dose of 'const' to the Samba tree.
There are a number of good reasons to do this:
- I want to allow the SAM_ACCOUNT structure to move from wasteful
pstrings and fstrings to allocated strings. We can't do that if
people are modifying these outputs, as they may well make
assumptions about getting pstrings and fstrings
- I want --with-pam_smbpass to compile with a slightly sane
volume of warnings, currently its pretty bad, even in 2.2
where is compiles at all.
- Tridge assures me that he no longer opposes 'const religion'
based on the ability to #define const the problem away.
- Changed Get_Pwnam(x,y) into two variants (so that the const
parameter can work correctly): - Get_Pwnam(const x) and
Get_Pwnam_Modify(x).
- Reworked smbd/chgpasswd.c to work with these mods, passing
around a 'struct passwd' rather than the modified username
---
This finishes this line of commits off, your tree should now compile again :-)
Andrew Bartlett
(This used to be commit c95f5aeb9327347674589ae313b75bee3bf8e317)
2001-10-29 10:35:11 +03:00
const char * new_passwd ,
2000-11-14 02:03:34 +03:00
char * err_str , size_t err_str_len ,
char * msg_str , size_t msg_str_len )
{
2006-02-20 23:09:36 +03:00
struct samu * sam_pass = NULL ;
2006-02-27 13:32:45 +03:00
uint32 other_acb ;
2006-02-04 01:19:41 +03:00
NTSTATUS result ;
1999-12-13 16:27:58 +03:00
2000-11-14 02:03:34 +03:00
* err_str = ' \0 ' ;
* msg_str = ' \0 ' ;
1999-12-13 16:27:58 +03:00
2000-11-14 02:03:34 +03:00
/* Get the smb passwd entry for this user */
2006-02-21 17:34:11 +03:00
if ( ! ( sam_pass = samu_new ( NULL ) ) ) {
return NT_STATUS_NO_MEMORY ;
}
2003-07-09 04:20:43 +04:00
become_root ( ) ;
2001-09-26 00:21:21 +04:00
if ( ! pdb_getsampwnam ( sam_pass , user_name ) ) {
2003-07-09 04:20:43 +04:00
unbecome_root ( ) ;
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( sam_pass ) ;
2001-05-07 18:04:46 +04:00
2003-04-29 13:43:17 +04:00
if ( ( local_flags & LOCAL_ADD_USER ) | | ( local_flags & LOCAL_DELETE_USER ) ) {
2006-02-04 01:19:41 +03:00
int tmp_debug = DEBUGLEVEL ;
2006-02-25 00:36:40 +03:00
struct passwd * pwd ;
2006-02-04 01:19:41 +03:00
/* Might not exist in /etc/passwd. */
if ( tmp_debug < 1 ) {
DEBUGLEVEL = 1 ;
}
2006-02-25 00:36:40 +03:00
if ( ! ( pwd = getpwnam_alloc ( NULL , user_name ) ) ) {
return NT_STATUS_NO_SUCH_USER ;
}
/* create the struct samu and initialize the basic Unix properties */
if ( ! ( sam_pass = samu_new ( NULL ) ) ) {
return NT_STATUS_NO_MEMORY ;
}
result = samu_set_unix ( sam_pass , pwd ) ;
2006-02-04 01:19:41 +03:00
DEBUGLEVEL = tmp_debug ;
2006-02-25 00:36:40 +03:00
TALLOC_FREE ( pwd ) ;
2006-02-21 17:34:11 +03:00
if ( NT_STATUS_EQUAL ( result , NT_STATUS_INVALID_PRIMARY_GROUP ) ) {
2006-02-04 01:19:41 +03:00
return result ;
}
if ( ! NT_STATUS_IS_OK ( result ) ) {
2006-02-25 00:36:40 +03:00
slprintf ( err_str , err_str_len - 1 , " Failed to " " initialize account for user %s: %s \n " ,
user_name , nt_errstr ( result ) ) ;
2006-02-04 01:19:41 +03:00
return result ;
This is another *BIG* change...
Samba now features a pluggable passdb interface, along the same lines as the
one in use in the auth subsystem. In this case, only one backend may be active
at a time by the 'normal' interface, and only one backend per passdb_context is
permitted outside that.
This pluggable interface is designed to allow any number of passdb backends to
be compiled in, with the selection at runtime. The 'passdb backend' paramater
has been created (and documented!) to support this.
As such, configure has been modfied to allow (for example) --with-ldap and the
old smbpasswd to be selected at the same time.
This patch also introduces two new backends: smbpasswd_nua and tdbsam_nua.
These two backends accept 'non unix accounts', where the user does *not* exist
in /etc/passwd. These accounts' don't have UIDs in the unix sense, but to
avoid conflicts in the algroitmic mapping of RIDs, they use the values
specified in the 'non unix account range' paramter - in the same way as the
winbind ranges are specifed.
While I was at it, I cleaned up some of the code in pdb_tdb (code copied
directly from smbpasswd and not really considered properly). Most of this was
to do with % macro expansion on stored data. It isn't easy to get the macros
into the tdb, and the first password change will 'expand' them. tdbsam needs
to use a similar system to pdb_ldap in this regard.
This patch only makes minor adjustments to pdb_nisplus and pdb_ldap, becouse I
don't have the test facilities for these. I plan to incoroprate at least
pdb_ldap into this scheme after consultation with Jerry.
Each (converted) passdb module now no longer has any 'static' variables, and
only exports 1 init function outside its .c file.
The non-unix-account support in this patch has been proven! It is now possible
to join a win2k machine to a Samba PDC without an account in /etc/passwd!
Other changes:
Minor interface adjustments:
pdb_delete_sam_account() now takes a SAM_ACCOUNT, not a char*.
pdb_update_sam_account() no longer takes the 'override' argument that was being
ignored so often (every other passdb backend). Extra checks have been added in
some places.
Minor code changes:
smbpasswd no longer attempts to initialise the passdb at startup, this is
now done on first use.
pdbedit has lost some of its 'machine account' logic, as this behaviour is now
controlled by the passdb subsystem directly.
The samr subsystem no longer calls 'local password change', but does the pdb
interactions directly. This allow the ACB_ flags specifed to be transferred
direct to the backend, without interference.
Doco:
I've updated the doco to reflect some of the changes, and removed some paramters
no longer applicable to HEAD.
(This used to be commit ff354c99c585068af6dc1ff35a1f109a806b326b)
2002-01-20 17:30:58 +03:00
}
} else {
2003-04-29 13:43:17 +04:00
slprintf ( err_str , err_str_len - 1 , " Failed to find entry for user %s. \n " , user_name ) ;
2006-02-04 01:19:41 +03:00
return NT_STATUS_NO_SUCH_USER ;
2001-09-27 13:13:26 +04:00
}
2001-05-04 19:44:27 +04:00
} else {
2003-07-09 04:20:43 +04:00
unbecome_root ( ) ;
2000-11-14 02:03:34 +03:00
/* the entry already existed */
local_flags & = ~ LOCAL_ADD_USER ;
}
1999-12-13 16:27:58 +03:00
2002-09-25 19:19:00 +04:00
/* the 'other' acb bits not being changed here */
other_acb = ( pdb_get_acct_ctrl ( sam_pass ) & ( ! ( ACB_WSTRUST | ACB_DOMTRUST | ACB_SVRTRUST | ACB_NORMAL ) ) ) ;
if ( local_flags & LOCAL_TRUST_ACCOUNT ) {
2002-11-02 06:47:48 +03:00
if ( ! pdb_set_acct_ctrl ( sam_pass , ACB_WSTRUST | other_acb , PDB_CHANGED ) ) {
2002-09-25 19:19:00 +04:00
slprintf ( err_str , err_str_len - 1 , " Failed to set 'trusted workstation account' flags for user %s. \n " , user_name ) ;
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( sam_pass ) ;
2006-02-04 01:19:41 +03:00
return NT_STATUS_UNSUCCESSFUL ;
2002-09-25 19:19:00 +04:00
}
} else if ( local_flags & LOCAL_INTERDOM_ACCOUNT ) {
2002-11-02 06:47:48 +03:00
if ( ! pdb_set_acct_ctrl ( sam_pass , ACB_DOMTRUST | other_acb , PDB_CHANGED ) ) {
2002-09-25 19:19:00 +04:00
slprintf ( err_str , err_str_len - 1 , " Failed to set 'domain trust account' flags for user %s. \n " , user_name ) ;
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( sam_pass ) ;
2006-02-04 01:19:41 +03:00
return NT_STATUS_UNSUCCESSFUL ;
2002-09-25 19:19:00 +04:00
}
} else {
2002-11-02 06:47:48 +03:00
if ( ! pdb_set_acct_ctrl ( sam_pass , ACB_NORMAL | other_acb , PDB_CHANGED ) ) {
2002-09-25 19:19:00 +04:00
slprintf ( err_str , err_str_len - 1 , " Failed to set 'normal account' flags for user %s. \n " , user_name ) ;
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( sam_pass ) ;
2006-02-04 01:19:41 +03:00
return NT_STATUS_UNSUCCESSFUL ;
2002-09-25 19:19:00 +04:00
}
}
1999-12-13 16:27:58 +03:00
/*
2000-11-14 02:03:34 +03:00
* We are root - just write the new password
* and the valid last change time .
1999-12-13 16:27:58 +03:00
*/
2001-09-29 17:14:19 +04:00
if ( local_flags & LOCAL_DISABLE_USER ) {
2002-11-02 06:47:48 +03:00
if ( ! pdb_set_acct_ctrl ( sam_pass , pdb_get_acct_ctrl ( sam_pass ) | ACB_DISABLED , PDB_CHANGED ) ) {
2001-09-29 17:14:19 +04:00
slprintf ( err_str , err_str_len - 1 , " Failed to set 'disabled' flag for user %s. \n " , user_name ) ;
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( sam_pass ) ;
2006-02-04 01:19:41 +03:00
return NT_STATUS_UNSUCCESSFUL ;
2001-09-29 17:14:19 +04:00
}
2001-09-26 00:21:21 +04:00
} else if ( local_flags & LOCAL_ENABLE_USER ) {
2002-11-02 06:47:48 +03:00
if ( ! pdb_set_acct_ctrl ( sam_pass , pdb_get_acct_ctrl ( sam_pass ) & ( ~ ACB_DISABLED ) , PDB_CHANGED ) ) {
2001-09-29 17:14:19 +04:00
slprintf ( err_str , err_str_len - 1 , " Failed to unset 'disabled' flag for user %s. \n " , user_name ) ;
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( sam_pass ) ;
2006-02-04 01:19:41 +03:00
return NT_STATUS_UNSUCCESSFUL ;
2001-09-29 17:14:19 +04:00
}
}
if ( local_flags & LOCAL_SET_NO_PASSWORD ) {
2002-11-02 06:47:48 +03:00
if ( ! pdb_set_acct_ctrl ( sam_pass , pdb_get_acct_ctrl ( sam_pass ) | ACB_PWNOTREQ , PDB_CHANGED ) ) {
2001-09-29 17:14:19 +04:00
slprintf ( err_str , err_str_len - 1 , " Failed to set 'no password required' flag for user %s. \n " , user_name ) ;
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( sam_pass ) ;
2006-02-04 01:19:41 +03:00
return NT_STATUS_UNSUCCESSFUL ;
1999-12-13 16:27:58 +03:00
}
2001-10-30 08:21:16 +03:00
} else if ( local_flags & LOCAL_SET_PASSWORD ) {
1999-12-13 16:27:58 +03:00
/*
2000-11-14 02:03:34 +03:00
* If we ' re dealing with setting a completely empty user account
* ie . One with a password of ' XXXX ' , but not set disabled ( like
* an account created from scratch ) then if the old password was
* ' XX ' s then getsmbpwent will have set the ACB_DISABLED flag .
* We remove that as we ' re giving this user their first password
* and the decision hasn ' t really been made to disable them ( ie .
* don ' t create them disabled ) . JRA .
1999-12-13 16:27:58 +03:00
*/
2001-09-29 17:14:19 +04:00
if ( ( pdb_get_lanman_passwd ( sam_pass ) = = NULL ) & & ( pdb_get_acct_ctrl ( sam_pass ) & ACB_DISABLED ) ) {
2002-11-02 06:47:48 +03:00
if ( ! pdb_set_acct_ctrl ( sam_pass , pdb_get_acct_ctrl ( sam_pass ) & ( ~ ACB_DISABLED ) , PDB_CHANGED ) ) {
2001-09-29 17:14:19 +04:00
slprintf ( err_str , err_str_len - 1 , " Failed to unset 'disabled' flag for user %s. \n " , user_name ) ;
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( sam_pass ) ;
2006-02-04 01:19:41 +03:00
return NT_STATUS_UNSUCCESSFUL ;
2001-09-29 17:14:19 +04:00
}
}
2002-11-02 06:47:48 +03:00
if ( ! pdb_set_acct_ctrl ( sam_pass , pdb_get_acct_ctrl ( sam_pass ) & ( ~ ACB_PWNOTREQ ) , PDB_CHANGED ) ) {
2001-09-29 17:14:19 +04:00
slprintf ( err_str , err_str_len - 1 , " Failed to unset 'no password required' flag for user %s. \n " , user_name ) ;
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( sam_pass ) ;
2006-02-04 01:19:41 +03:00
return NT_STATUS_UNSUCCESSFUL ;
2001-09-29 17:14:19 +04:00
}
if ( ! pdb_set_plaintext_passwd ( sam_pass , new_passwd ) ) {
slprintf ( err_str , err_str_len - 1 , " Failed to set password for user %s. \n " , user_name ) ;
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( sam_pass ) ;
2006-02-04 01:19:41 +03:00
return NT_STATUS_UNSUCCESSFUL ;
2001-09-29 17:14:19 +04:00
}
}
if ( local_flags & LOCAL_ADD_USER ) {
2006-02-13 20:08:25 +03:00
if ( NT_STATUS_IS_OK ( pdb_add_sam_account ( sam_pass ) ) ) {
2001-09-29 17:14:19 +04:00
slprintf ( msg_str , msg_str_len - 1 , " Added user %s. \n " , user_name ) ;
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( sam_pass ) ;
2006-02-04 01:19:41 +03:00
return NT_STATUS_OK ;
2001-09-29 17:14:19 +04:00
} else {
slprintf ( err_str , err_str_len - 1 , " Failed to add entry for user %s. \n " , user_name ) ;
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( sam_pass ) ;
2006-02-04 01:19:41 +03:00
return NT_STATUS_UNSUCCESSFUL ;
2001-09-29 17:14:19 +04:00
}
2002-01-30 15:06:22 +03:00
} else if ( local_flags & LOCAL_DELETE_USER ) {
2006-02-13 20:08:25 +03:00
if ( ! NT_STATUS_IS_OK ( pdb_delete_sam_account ( sam_pass ) ) ) {
2002-01-30 15:06:22 +03:00
slprintf ( err_str , err_str_len - 1 , " Failed to delete entry for user %s. \n " , user_name ) ;
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( sam_pass ) ;
2006-02-04 01:19:41 +03:00
return NT_STATUS_UNSUCCESSFUL ;
2002-01-30 15:06:22 +03:00
}
slprintf ( msg_str , msg_str_len - 1 , " Deleted user %s. \n " , user_name ) ;
2001-09-26 00:21:21 +04:00
} else {
2006-02-04 01:19:41 +03:00
result = pdb_update_sam_account ( sam_pass ) ;
if ( ! NT_STATUS_IS_OK ( result ) ) {
2000-11-14 02:03:34 +03:00
slprintf ( err_str , err_str_len - 1 , " Failed to modify entry for user %s. \n " , user_name ) ;
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( sam_pass ) ;
2006-02-04 01:19:41 +03:00
return result ;
2000-11-14 02:03:34 +03:00
}
if ( local_flags & LOCAL_DISABLE_USER )
slprintf ( msg_str , msg_str_len - 1 , " Disabled user %s. \n " , user_name ) ;
else if ( local_flags & LOCAL_ENABLE_USER )
slprintf ( msg_str , msg_str_len - 1 , " Enabled user %s. \n " , user_name ) ;
else if ( local_flags & LOCAL_SET_NO_PASSWORD )
slprintf ( msg_str , msg_str_len - 1 , " User %s password set to none. \n " , user_name ) ;
1999-03-03 23:48:48 +03:00
}
2000-11-14 02:03:34 +03:00
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( sam_pass ) ;
2006-02-04 01:19:41 +03:00
return NT_STATUS_OK ;
2003-07-07 09:11:10 +04:00
}
2003-07-09 01:58:29 +04:00
/**********************************************************************
2006-02-20 23:09:36 +03:00
Marshall / unmarshall struct samu structs .
2003-07-09 01:58:29 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-02-27 13:32:45 +03:00
# define TDB_FORMAT_STRING_V3 "dddddddBBBBBBBBBBBBddBBBdwdBwwd"
2003-07-09 01:58:29 +04:00
2006-02-21 22:02:22 +03:00
/*********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-02-13 17:48:20 +03:00
2006-02-27 13:32:45 +03:00
BOOL init_sam_from_buffer_v3 ( struct samu * sampass , uint8 * buf , uint32 buflen )
2004-02-13 17:48:20 +03:00
{
/* times are stored as 32bit integer
take care on system with 64 bit wide time_t
- - SSS */
uint32 logon_time ,
logoff_time ,
kickoff_time ,
bad_password_time ,
pass_last_set_time ,
pass_can_change_time ,
pass_must_change_time ;
2005-02-11 17:58:33 +03:00
char * username = NULL ;
char * domain = NULL ;
char * nt_username = NULL ;
char * dir_drive = NULL ;
char * unknown_str = NULL ;
char * munged_dial = NULL ;
char * fullname = NULL ;
char * homedir = NULL ;
char * logon_script = NULL ;
char * profile_path = NULL ;
char * acct_desc = NULL ;
char * workstations = NULL ;
2004-02-13 17:48:20 +03:00
uint32 username_len , domain_len , nt_username_len ,
dir_drive_len , unknown_str_len , munged_dial_len ,
fullname_len , homedir_len , logon_script_len ,
profile_path_len , acct_desc_len , workstations_len ;
2006-02-27 13:32:45 +03:00
uint32 user_rid , group_rid , hours_len , unknown_6 , acct_ctrl ;
uint16 logon_divs ;
2004-02-13 17:48:20 +03:00
uint16 bad_password_count , logon_count ;
2005-02-11 17:58:33 +03:00
uint8 * hours = NULL ;
uint8 * lm_pw_ptr = NULL , * nt_pw_ptr = NULL , * nt_pw_hist_ptr = NULL ;
2004-02-13 17:48:20 +03:00
uint32 len = 0 ;
2004-07-08 10:39:22 +04:00
uint32 lm_pw_len , nt_pw_len , nt_pw_hist_len , hourslen ;
uint32 pwHistLen = 0 ;
2004-02-13 17:48:20 +03:00
BOOL ret = True ;
2005-01-20 01:50:27 +03:00
fstring tmpstring ;
2005-12-01 17:46:56 +03:00
BOOL expand_explicit = lp_passdb_expand_explicit ( ) ;
2004-02-13 17:48:20 +03:00
if ( sampass = = NULL | | buf = = NULL ) {
2006-02-27 13:32:45 +03:00
DEBUG ( 0 , ( " init_sam_from_buffer_v3: NULL parameters found! \n " ) ) ;
2004-02-13 17:48:20 +03:00
return False ;
}
2006-02-27 13:32:45 +03:00
/* TDB_FORMAT_STRING_V3 "dddddddBBBBBBBBBBBBddBBBdwdBwwd" */
2004-07-08 10:39:22 +04:00
2004-02-13 17:48:20 +03:00
/* unpack the buffer into variables */
2006-02-27 13:32:45 +03:00
len = tdb_unpack ( ( char * ) buf , buflen , TDB_FORMAT_STRING_V3 ,
2004-07-08 10:39:22 +04:00
& logon_time , /* d */
& logoff_time , /* d */
& kickoff_time , /* d */
& bad_password_time , /* d */
& pass_last_set_time , /* d */
& pass_can_change_time , /* d */
& pass_must_change_time , /* d */
& username_len , & username , /* B */
& domain_len , & domain , /* B */
& nt_username_len , & nt_username , /* B */
& fullname_len , & fullname , /* B */
& homedir_len , & homedir , /* B */
& dir_drive_len , & dir_drive , /* B */
& logon_script_len , & logon_script , /* B */
& profile_path_len , & profile_path , /* B */
& acct_desc_len , & acct_desc , /* B */
& workstations_len , & workstations , /* B */
& unknown_str_len , & unknown_str , /* B */
& munged_dial_len , & munged_dial , /* B */
& user_rid , /* d */
& group_rid , /* d */
& lm_pw_len , & lm_pw_ptr , /* B */
& nt_pw_len , & nt_pw_ptr , /* B */
/* Change from V1 is addition of password history field. */
& nt_pw_hist_len , & nt_pw_hist_ptr , /* B */
2006-02-27 13:32:45 +03:00
/* Change from V2 is the uint32 acb_mask */
& acct_ctrl , /* d */
2004-07-08 10:39:22 +04:00
/* Also "remove_me" field was removed. */
& logon_divs , /* w */
& hours_len , /* d */
& hourslen , & hours , /* B */
& bad_password_count , /* w */
& logon_count , /* w */
& unknown_6 ) ; /* d */
2004-02-13 17:48:20 +03:00
2004-02-19 21:35:43 +03:00
if ( len = = ( uint32 ) - 1 ) {
2004-02-13 17:48:20 +03:00
ret = False ;
goto done ;
}
pdb_set_logon_time ( sampass , logon_time , PDB_SET ) ;
pdb_set_logoff_time ( sampass , logoff_time , PDB_SET ) ;
pdb_set_kickoff_time ( sampass , kickoff_time , PDB_SET ) ;
2004-02-19 18:59:35 +03:00
pdb_set_bad_password_time ( sampass , bad_password_time , PDB_SET ) ;
2004-02-13 17:48:20 +03:00
pdb_set_pass_can_change_time ( sampass , pass_can_change_time , PDB_SET ) ;
pdb_set_pass_must_change_time ( sampass , pass_must_change_time , PDB_SET ) ;
pdb_set_pass_last_set_time ( sampass , pass_last_set_time , PDB_SET ) ;
pdb_set_username ( sampass , username , PDB_SET ) ;
pdb_set_domain ( sampass , domain , PDB_SET ) ;
pdb_set_nt_username ( sampass , nt_username , PDB_SET ) ;
pdb_set_fullname ( sampass , fullname , PDB_SET ) ;
if ( homedir ) {
2005-01-20 01:50:27 +03:00
fstrcpy ( tmpstring , homedir ) ;
2005-12-01 17:46:56 +03:00
if ( expand_explicit ) {
standard_sub_basic ( username , tmpstring ,
sizeof ( tmpstring ) ) ;
}
2005-01-20 01:50:27 +03:00
pdb_set_homedir ( sampass , tmpstring , PDB_SET ) ;
2004-02-13 17:48:20 +03:00
}
else {
pdb_set_homedir ( sampass ,
2006-02-20 23:09:36 +03:00
talloc_sub_basic ( sampass , username , lp_logon_home ( ) ) ,
2004-02-13 17:48:20 +03:00
PDB_DEFAULT ) ;
}
if ( dir_drive )
pdb_set_dir_drive ( sampass , dir_drive , PDB_SET ) ;
2005-01-20 01:50:27 +03:00
else
pdb_set_dir_drive ( sampass , lp_logon_drive ( ) , PDB_DEFAULT ) ;
2004-02-13 17:48:20 +03:00
2005-01-20 01:50:27 +03:00
if ( logon_script ) {
fstrcpy ( tmpstring , logon_script ) ;
2005-12-01 17:46:56 +03:00
if ( expand_explicit ) {
standard_sub_basic ( username , tmpstring ,
sizeof ( tmpstring ) ) ;
}
2005-01-20 01:50:27 +03:00
pdb_set_logon_script ( sampass , tmpstring , PDB_SET ) ;
}
2004-02-13 17:48:20 +03:00
else {
pdb_set_logon_script ( sampass ,
2006-02-20 23:09:36 +03:00
talloc_sub_basic ( sampass , username , lp_logon_script ( ) ) ,
2004-02-13 17:48:20 +03:00
PDB_DEFAULT ) ;
}
if ( profile_path ) {
2005-01-20 01:50:27 +03:00
fstrcpy ( tmpstring , profile_path ) ;
2005-12-01 17:46:56 +03:00
if ( expand_explicit ) {
standard_sub_basic ( username , tmpstring ,
sizeof ( tmpstring ) ) ;
}
2005-01-20 01:50:27 +03:00
pdb_set_profile_path ( sampass , tmpstring , PDB_SET ) ;
}
else {
2004-02-13 17:48:20 +03:00
pdb_set_profile_path ( sampass ,
2006-02-20 23:09:36 +03:00
talloc_sub_basic ( sampass , username , lp_logon_path ( ) ) ,
2004-02-13 17:48:20 +03:00
PDB_DEFAULT ) ;
}
pdb_set_acct_desc ( sampass , acct_desc , PDB_SET ) ;
pdb_set_workstations ( sampass , workstations , PDB_SET ) ;
pdb_set_munged_dial ( sampass , munged_dial , PDB_SET ) ;
if ( lm_pw_ptr & & lm_pw_len = = LM_HASH_LEN ) {
if ( ! pdb_set_lanman_passwd ( sampass , lm_pw_ptr , PDB_SET ) ) {
ret = False ;
goto done ;
}
}
if ( nt_pw_ptr & & nt_pw_len = = NT_HASH_LEN ) {
if ( ! pdb_set_nt_passwd ( sampass , nt_pw_ptr , PDB_SET ) ) {
ret = False ;
goto done ;
}
}
2005-09-30 21:13:37 +04:00
pdb_get_account_policy ( AP_PASSWORD_HISTORY , & pwHistLen ) ;
2004-07-09 01:01:30 +04:00
if ( pwHistLen ) {
2005-03-22 18:03:17 +03:00
uint8 * pw_hist = SMB_MALLOC ( pwHistLen * PW_HISTORY_ENTRY_LEN ) ;
2004-07-09 01:01:30 +04:00
if ( ! pw_hist ) {
ret = False ;
goto done ;
}
2004-08-05 23:57:41 +04:00
memset ( pw_hist , ' \0 ' , pwHistLen * PW_HISTORY_ENTRY_LEN ) ;
2004-07-09 01:01:30 +04:00
if ( nt_pw_hist_ptr & & nt_pw_hist_len ) {
int i ;
2004-08-05 23:57:41 +04:00
SMB_ASSERT ( ( nt_pw_hist_len % PW_HISTORY_ENTRY_LEN ) = = 0 ) ;
nt_pw_hist_len / = PW_HISTORY_ENTRY_LEN ;
2004-07-09 01:01:30 +04:00
for ( i = 0 ; ( i < pwHistLen ) & & ( i < nt_pw_hist_len ) ; i + + ) {
2004-08-05 23:57:41 +04:00
memcpy ( & pw_hist [ i * PW_HISTORY_ENTRY_LEN ] ,
& nt_pw_hist_ptr [ i * PW_HISTORY_ENTRY_LEN ] ,
PW_HISTORY_ENTRY_LEN ) ;
2004-07-09 01:01:30 +04:00
}
}
if ( ! pdb_set_pw_history ( sampass , pw_hist , pwHistLen , PDB_SET ) ) {
SAFE_FREE ( pw_hist ) ;
2004-07-08 10:39:22 +04:00
ret = False ;
goto done ;
}
2004-07-09 01:01:30 +04:00
SAFE_FREE ( pw_hist ) ;
2004-07-08 10:39:22 +04:00
} else {
pdb_set_pw_history ( sampass , NULL , 0 , PDB_SET ) ;
}
2004-02-13 17:48:20 +03:00
pdb_set_user_sid_from_rid ( sampass , user_rid , PDB_SET ) ;
pdb_set_hours_len ( sampass , hours_len , PDB_SET ) ;
pdb_set_bad_password_count ( sampass , bad_password_count , PDB_SET ) ;
pdb_set_logon_count ( sampass , logon_count , PDB_SET ) ;
pdb_set_unknown_6 ( sampass , unknown_6 , PDB_SET ) ;
2006-02-27 13:32:45 +03:00
/* Change from V2 is the uint32 acct_ctrl */
2004-02-13 17:48:20 +03:00
pdb_set_acct_ctrl ( sampass , acct_ctrl , PDB_SET ) ;
pdb_set_logon_divs ( sampass , logon_divs , PDB_SET ) ;
pdb_set_hours ( sampass , hours , PDB_SET ) ;
done :
SAFE_FREE ( username ) ;
SAFE_FREE ( domain ) ;
SAFE_FREE ( nt_username ) ;
SAFE_FREE ( fullname ) ;
SAFE_FREE ( homedir ) ;
SAFE_FREE ( dir_drive ) ;
SAFE_FREE ( logon_script ) ;
SAFE_FREE ( profile_path ) ;
SAFE_FREE ( acct_desc ) ;
SAFE_FREE ( workstations ) ;
SAFE_FREE ( munged_dial ) ;
SAFE_FREE ( unknown_str ) ;
2004-07-08 10:39:22 +04:00
SAFE_FREE ( lm_pw_ptr ) ;
SAFE_FREE ( nt_pw_ptr ) ;
SAFE_FREE ( nt_pw_hist_ptr ) ;
2004-02-13 17:48:20 +03:00
SAFE_FREE ( hours ) ;
return ret ;
}
2006-02-21 22:02:22 +03:00
/*********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-02-27 13:32:45 +03:00
uint32 init_buffer_from_sam_v3 ( uint8 * * buf , struct samu * sampass , BOOL size_only )
2004-02-13 17:48:20 +03:00
{
size_t len , buflen ;
/* times are stored as 32bit integer
take care on system with 64 bit wide time_t
- - SSS */
uint32 logon_time ,
logoff_time ,
kickoff_time ,
bad_password_time ,
pass_last_set_time ,
pass_can_change_time ,
pass_must_change_time ;
uint32 user_rid , group_rid ;
const char * username ;
const char * domain ;
const char * nt_username ;
const char * dir_drive ;
const char * unknown_str ;
const char * munged_dial ;
const char * fullname ;
const char * homedir ;
const char * logon_script ;
const char * profile_path ;
const char * acct_desc ;
const char * workstations ;
uint32 username_len , domain_len , nt_username_len ,
dir_drive_len , unknown_str_len , munged_dial_len ,
fullname_len , homedir_len , logon_script_len ,
profile_path_len , acct_desc_len , workstations_len ;
const uint8 * lm_pw ;
const uint8 * nt_pw ;
2004-07-08 10:39:22 +04:00
const uint8 * nt_pw_hist ;
2004-02-13 17:48:20 +03:00
uint32 lm_pw_len = 16 ;
uint32 nt_pw_len = 16 ;
2004-07-08 10:39:22 +04:00
uint32 nt_pw_hist_len ;
uint32 pwHistLen = 0 ;
2004-02-13 17:48:20 +03:00
2006-02-20 23:09:36 +03:00
/* do we have a valid struct samu pointer? */
2004-02-13 17:48:20 +03:00
if ( sampass = = NULL ) {
2006-02-20 23:09:36 +03:00
DEBUG ( 0 , ( " init_buffer_from_sam: struct samu is NULL! \n " ) ) ;
2004-02-13 17:48:20 +03:00
return - 1 ;
}
* buf = NULL ;
buflen = 0 ;
logon_time = ( uint32 ) pdb_get_logon_time ( sampass ) ;
logoff_time = ( uint32 ) pdb_get_logoff_time ( sampass ) ;
kickoff_time = ( uint32 ) pdb_get_kickoff_time ( sampass ) ;
2004-02-19 18:59:35 +03:00
bad_password_time = ( uint32 ) pdb_get_bad_password_time ( sampass ) ;
2004-02-13 17:48:20 +03:00
pass_can_change_time = ( uint32 ) pdb_get_pass_can_change_time ( sampass ) ;
pass_must_change_time = ( uint32 ) pdb_get_pass_must_change_time ( sampass ) ;
pass_last_set_time = ( uint32 ) pdb_get_pass_last_set_time ( sampass ) ;
user_rid = pdb_get_user_rid ( sampass ) ;
group_rid = pdb_get_group_rid ( sampass ) ;
username = pdb_get_username ( sampass ) ;
2004-07-08 10:39:22 +04:00
if ( username ) {
2004-02-13 17:48:20 +03:00
username_len = strlen ( username ) + 1 ;
2004-07-08 10:39:22 +04:00
} else {
2004-02-13 17:48:20 +03:00
username_len = 0 ;
2004-07-08 10:39:22 +04:00
}
2004-02-13 17:48:20 +03:00
domain = pdb_get_domain ( sampass ) ;
2004-07-08 10:39:22 +04:00
if ( domain ) {
2004-02-13 17:48:20 +03:00
domain_len = strlen ( domain ) + 1 ;
2004-07-08 10:39:22 +04:00
} else {
2004-02-13 17:48:20 +03:00
domain_len = 0 ;
2004-07-08 10:39:22 +04:00
}
2004-02-13 17:48:20 +03:00
nt_username = pdb_get_nt_username ( sampass ) ;
2004-07-08 10:39:22 +04:00
if ( nt_username ) {
2004-02-13 17:48:20 +03:00
nt_username_len = strlen ( nt_username ) + 1 ;
2004-07-08 10:39:22 +04:00
} else {
2004-02-13 17:48:20 +03:00
nt_username_len = 0 ;
2004-07-08 10:39:22 +04:00
}
2004-02-13 17:48:20 +03:00
fullname = pdb_get_fullname ( sampass ) ;
2004-07-08 10:39:22 +04:00
if ( fullname ) {
2004-02-13 17:48:20 +03:00
fullname_len = strlen ( fullname ) + 1 ;
2004-07-08 10:39:22 +04:00
} else {
2004-02-13 17:48:20 +03:00
fullname_len = 0 ;
2004-07-08 10:39:22 +04:00
}
2004-02-13 17:48:20 +03:00
/*
* Only updates fields which have been set ( not defaults from smb . conf )
*/
2004-07-08 10:39:22 +04:00
if ( ! IS_SAM_DEFAULT ( sampass , PDB_DRIVE ) ) {
2004-02-13 17:48:20 +03:00
dir_drive = pdb_get_dir_drive ( sampass ) ;
2004-07-08 10:39:22 +04:00
} else {
2004-02-13 17:48:20 +03:00
dir_drive = NULL ;
2004-07-08 10:39:22 +04:00
}
if ( dir_drive ) {
2004-02-13 17:48:20 +03:00
dir_drive_len = strlen ( dir_drive ) + 1 ;
2004-07-08 10:39:22 +04:00
} else {
2004-02-13 17:48:20 +03:00
dir_drive_len = 0 ;
2004-07-08 10:39:22 +04:00
}
2004-02-13 17:48:20 +03:00
2004-07-08 10:39:22 +04:00
if ( ! IS_SAM_DEFAULT ( sampass , PDB_SMBHOME ) ) {
2004-02-13 17:48:20 +03:00
homedir = pdb_get_homedir ( sampass ) ;
2004-07-08 10:39:22 +04:00
} else {
2004-02-13 17:48:20 +03:00
homedir = NULL ;
2004-07-08 10:39:22 +04:00
}
if ( homedir ) {
2004-02-13 17:48:20 +03:00
homedir_len = strlen ( homedir ) + 1 ;
2004-07-08 10:39:22 +04:00
} else {
2004-02-13 17:48:20 +03:00
homedir_len = 0 ;
2004-07-08 10:39:22 +04:00
}
2004-02-13 17:48:20 +03:00
2004-07-08 10:39:22 +04:00
if ( ! IS_SAM_DEFAULT ( sampass , PDB_LOGONSCRIPT ) ) {
2004-02-13 17:48:20 +03:00
logon_script = pdb_get_logon_script ( sampass ) ;
2004-07-08 10:39:22 +04:00
} else {
2004-02-13 17:48:20 +03:00
logon_script = NULL ;
2004-07-08 10:39:22 +04:00
}
if ( logon_script ) {
2004-02-13 17:48:20 +03:00
logon_script_len = strlen ( logon_script ) + 1 ;
2004-07-08 10:39:22 +04:00
} else {
2004-02-13 17:48:20 +03:00
logon_script_len = 0 ;
2004-07-08 10:39:22 +04:00
}
2004-02-13 17:48:20 +03:00
2004-07-08 10:39:22 +04:00
if ( ! IS_SAM_DEFAULT ( sampass , PDB_PROFILE ) ) {
2004-02-13 17:48:20 +03:00
profile_path = pdb_get_profile_path ( sampass ) ;
2004-07-08 10:39:22 +04:00
} else {
2004-02-13 17:48:20 +03:00
profile_path = NULL ;
2004-07-08 10:39:22 +04:00
}
if ( profile_path ) {
2004-02-13 17:48:20 +03:00
profile_path_len = strlen ( profile_path ) + 1 ;
2004-07-08 10:39:22 +04:00
} else {
2004-02-13 17:48:20 +03:00
profile_path_len = 0 ;
2004-07-08 10:39:22 +04:00
}
2004-02-13 17:48:20 +03:00
lm_pw = pdb_get_lanman_passwd ( sampass ) ;
2004-07-08 10:39:22 +04:00
if ( ! lm_pw ) {
2004-02-13 17:48:20 +03:00
lm_pw_len = 0 ;
2004-07-08 10:39:22 +04:00
}
2004-02-13 17:48:20 +03:00
nt_pw = pdb_get_nt_passwd ( sampass ) ;
2004-07-08 10:39:22 +04:00
if ( ! nt_pw ) {
2004-02-13 17:48:20 +03:00
nt_pw_len = 0 ;
2004-07-08 10:39:22 +04:00
}
2005-09-30 21:13:37 +04:00
pdb_get_account_policy ( AP_PASSWORD_HISTORY , & pwHistLen ) ;
2004-07-08 10:39:22 +04:00
nt_pw_hist = pdb_get_pw_history ( sampass , & nt_pw_hist_len ) ;
if ( pwHistLen & & nt_pw_hist & & nt_pw_hist_len ) {
2004-08-05 23:57:41 +04:00
nt_pw_hist_len * = PW_HISTORY_ENTRY_LEN ;
2004-07-08 10:39:22 +04:00
} else {
nt_pw_hist_len = 0 ;
}
2004-02-13 17:48:20 +03:00
acct_desc = pdb_get_acct_desc ( sampass ) ;
2004-07-08 10:39:22 +04:00
if ( acct_desc ) {
2004-02-13 17:48:20 +03:00
acct_desc_len = strlen ( acct_desc ) + 1 ;
2004-07-08 10:39:22 +04:00
} else {
2004-02-13 17:48:20 +03:00
acct_desc_len = 0 ;
2004-07-08 10:39:22 +04:00
}
2004-02-13 17:48:20 +03:00
workstations = pdb_get_workstations ( sampass ) ;
2004-07-08 10:39:22 +04:00
if ( workstations ) {
2004-02-13 17:48:20 +03:00
workstations_len = strlen ( workstations ) + 1 ;
2004-07-08 10:39:22 +04:00
} else {
2004-02-13 17:48:20 +03:00
workstations_len = 0 ;
2004-07-08 10:39:22 +04:00
}
2004-02-13 17:48:20 +03:00
unknown_str = NULL ;
unknown_str_len = 0 ;
munged_dial = pdb_get_munged_dial ( sampass ) ;
2004-07-08 10:39:22 +04:00
if ( munged_dial ) {
2004-02-13 17:48:20 +03:00
munged_dial_len = strlen ( munged_dial ) + 1 ;
2004-07-08 10:39:22 +04:00
} else {
2004-02-13 17:48:20 +03:00
munged_dial_len = 0 ;
2004-07-08 10:39:22 +04:00
}
2006-02-27 13:32:45 +03:00
/* TDB_FORMAT_STRING_V3 "dddddddBBBBBBBBBBBBddBBBdwdBwwd" */
2004-07-08 10:39:22 +04:00
2004-02-13 17:48:20 +03:00
/* one time to get the size needed */
2006-02-27 13:32:45 +03:00
len = tdb_pack ( NULL , 0 , TDB_FORMAT_STRING_V3 ,
2004-07-08 10:39:22 +04:00
logon_time , /* d */
logoff_time , /* d */
kickoff_time , /* d */
bad_password_time , /* d */
pass_last_set_time , /* d */
pass_can_change_time , /* d */
pass_must_change_time , /* d */
username_len , username , /* B */
domain_len , domain , /* B */
nt_username_len , nt_username , /* B */
fullname_len , fullname , /* B */
homedir_len , homedir , /* B */
dir_drive_len , dir_drive , /* B */
logon_script_len , logon_script , /* B */
profile_path_len , profile_path , /* B */
acct_desc_len , acct_desc , /* B */
workstations_len , workstations , /* B */
unknown_str_len , unknown_str , /* B */
munged_dial_len , munged_dial , /* B */
user_rid , /* d */
group_rid , /* d */
lm_pw_len , lm_pw , /* B */
nt_pw_len , nt_pw , /* B */
nt_pw_hist_len , nt_pw_hist , /* B */
2006-02-27 13:32:45 +03:00
pdb_get_acct_ctrl ( sampass ) , /* d */
2004-07-08 10:39:22 +04:00
pdb_get_logon_divs ( sampass ) , /* w */
pdb_get_hours_len ( sampass ) , /* d */
MAX_HOURS_LEN , pdb_get_hours ( sampass ) , /* B */
pdb_get_bad_password_count ( sampass ) , /* w */
pdb_get_logon_count ( sampass ) , /* w */
pdb_get_unknown_6 ( sampass ) ) ; /* d */
if ( size_only ) {
2004-02-13 17:48:20 +03:00
return buflen ;
2004-07-08 10:39:22 +04:00
}
2004-02-13 17:48:20 +03:00
/* malloc the space needed */
2004-12-07 21:25:53 +03:00
if ( ( * buf = ( uint8 * ) SMB_MALLOC ( len ) ) = = NULL ) {
2006-02-27 13:32:45 +03:00
DEBUG ( 0 , ( " init_buffer_from_sam_v3: Unable to malloc() memory for buffer! \n " ) ) ;
2004-02-13 17:48:20 +03:00
return ( - 1 ) ;
}
/* now for the real call to tdb_pack() */
2006-02-27 13:32:45 +03:00
buflen = tdb_pack ( ( char * ) * buf , len , TDB_FORMAT_STRING_V3 ,
2004-07-08 10:39:22 +04:00
logon_time , /* d */
logoff_time , /* d */
kickoff_time , /* d */
bad_password_time , /* d */
pass_last_set_time , /* d */
pass_can_change_time , /* d */
pass_must_change_time , /* d */
username_len , username , /* B */
domain_len , domain , /* B */
nt_username_len , nt_username , /* B */
fullname_len , fullname , /* B */
homedir_len , homedir , /* B */
dir_drive_len , dir_drive , /* B */
logon_script_len , logon_script , /* B */
profile_path_len , profile_path , /* B */
acct_desc_len , acct_desc , /* B */
workstations_len , workstations , /* B */
unknown_str_len , unknown_str , /* B */
munged_dial_len , munged_dial , /* B */
user_rid , /* d */
group_rid , /* d */
lm_pw_len , lm_pw , /* B */
nt_pw_len , nt_pw , /* B */
nt_pw_hist_len , nt_pw_hist , /* B */
2006-02-27 13:32:45 +03:00
pdb_get_acct_ctrl ( sampass ) , /* d */
2004-07-08 10:39:22 +04:00
pdb_get_logon_divs ( sampass ) , /* w */
pdb_get_hours_len ( sampass ) , /* d */
MAX_HOURS_LEN , pdb_get_hours ( sampass ) , /* B */
pdb_get_bad_password_count ( sampass ) , /* w */
pdb_get_logon_count ( sampass ) , /* w */
pdb_get_unknown_6 ( sampass ) ) ; /* d */
2003-07-09 01:58:29 +04:00
/* check to make sure we got it correct */
if ( buflen ! = len ) {
2006-02-27 13:32:45 +03:00
DEBUG ( 0 , ( " init_buffer_from_sam_v3: somthing odd is going on here: bufflen (%lu) != len (%lu) in tdb_pack operations! \n " ,
2003-07-25 08:24:40 +04:00
( unsigned long ) buflen , ( unsigned long ) len ) ) ;
2003-07-09 01:58:29 +04:00
/* error */
SAFE_FREE ( * buf ) ;
return ( - 1 ) ;
}
return ( buflen ) ;
}
2003-08-13 04:08:28 +04:00
2006-02-21 22:02:22 +03:00
/*********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-02-25 00:36:40 +03:00
BOOL pdb_copy_sam_account ( struct samu * dst , struct samu * src )
2004-11-06 01:53:35 +03:00
{
BOOL result ;
uint8 * buf ;
int len ;
2006-02-25 00:36:40 +03:00
if ( ! dst )
2004-11-06 01:53:35 +03:00
return False ;
2006-02-27 13:32:45 +03:00
len = init_buffer_from_sam_v3 ( & buf , src , False ) ;
2004-11-06 01:53:35 +03:00
if ( len = = - 1 )
return False ;
2006-02-27 13:32:45 +03:00
result = init_sam_from_buffer_v3 ( dst , buf , len ) ;
2006-02-25 00:36:40 +03:00
dst - > methods = src - > methods ;
if ( src - > unix_pw )
dst - > unix_pw = tcopy_passwd ( dst , src - > unix_pw ) ;
2004-11-06 01:53:35 +03:00
free ( buf ) ;
return result ;
}
2004-02-19 21:35:43 +03:00
/*********************************************************************
Update the bad password count checking the AP_RESET_COUNT_TIME
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-02-20 23:09:36 +03:00
BOOL pdb_update_bad_password_count ( struct samu * sampass , BOOL * updated )
2004-02-19 21:35:43 +03:00
{
time_t LastBadPassword ;
uint16 BadPasswordCount ;
uint32 resettime ;
2004-02-20 00:37:24 +03:00
if ( ! sampass ) return False ;
2004-02-19 21:35:43 +03:00
BadPasswordCount = pdb_get_bad_password_count ( sampass ) ;
2004-02-20 00:37:24 +03:00
if ( ! BadPasswordCount ) {
DEBUG ( 9 , ( " No bad password attempts. \n " ) ) ;
return True ;
}
2005-09-30 21:13:37 +04:00
if ( ! pdb_get_account_policy ( AP_RESET_COUNT_TIME , & resettime ) ) {
DEBUG ( 0 , ( " pdb_update_bad_password_count: pdb_get_account_policy failed. \n " ) ) ;
2004-02-20 00:37:24 +03:00
return False ;
}
/* First, check if there is a reset time to compare */
2004-02-20 19:00:25 +03:00
if ( ( resettime = = ( uint32 ) - 1 ) | | ( resettime = = 0 ) ) {
DEBUG ( 9 , ( " No reset time, can't reset bad pw count \n " ) ) ;
2004-02-20 00:37:24 +03:00
return True ;
}
LastBadPassword = pdb_get_bad_password_time ( sampass ) ;
DEBUG ( 7 , ( " LastBadPassword=%d, resettime=%d, current time=%d. \n " ,
( uint32 ) LastBadPassword , resettime , ( uint32 ) time ( NULL ) ) ) ;
if ( time ( NULL ) > ( LastBadPassword + ( time_t ) resettime * 60 ) ) {
pdb_set_bad_password_count ( sampass , 0 , PDB_CHANGED ) ;
pdb_set_bad_password_time ( sampass , 0 , PDB_CHANGED ) ;
2004-07-17 05:37:04 +04:00
if ( updated ) {
* updated = True ;
}
2004-02-19 21:35:43 +03:00
}
2004-02-20 00:37:24 +03:00
2004-02-19 21:35:43 +03:00
return True ;
}
/*********************************************************************
Update the ACB_AUTOLOCK flag checking the AP_LOCK_ACCOUNT_DURATION
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-02-20 23:09:36 +03:00
BOOL pdb_update_autolock_flag ( struct samu * sampass , BOOL * updated )
2004-02-19 21:35:43 +03:00
{
uint32 duration ;
time_t LastBadPassword ;
2004-02-20 00:37:24 +03:00
if ( ! sampass ) return False ;
2004-02-19 21:35:43 +03:00
2004-02-20 00:37:24 +03:00
if ( ! ( pdb_get_acct_ctrl ( sampass ) & ACB_AUTOLOCK ) ) {
2004-07-17 05:37:04 +04:00
DEBUG ( 9 , ( " pdb_update_autolock_flag: Account %s not autolocked, no check needed \n " ,
pdb_get_username ( sampass ) ) ) ;
2004-02-20 00:37:24 +03:00
return True ;
2004-02-19 21:35:43 +03:00
}
2005-09-30 21:13:37 +04:00
if ( ! pdb_get_account_policy ( AP_LOCK_ACCOUNT_DURATION , & duration ) ) {
DEBUG ( 0 , ( " pdb_update_autolock_flag: pdb_get_account_policy failed. \n " ) ) ;
2004-02-20 00:37:24 +03:00
return False ;
}
/* First, check if there is a duration to compare */
2004-02-20 19:00:25 +03:00
if ( ( duration = = ( uint32 ) - 1 ) | | ( duration = = 0 ) ) {
2004-07-17 05:37:04 +04:00
DEBUG ( 9 , ( " pdb_update_autolock_flag: No reset duration, can't reset autolock \n " ) ) ;
2004-02-20 00:37:24 +03:00
return True ;
}
LastBadPassword = pdb_get_bad_password_time ( sampass ) ;
2004-07-17 05:37:04 +04:00
DEBUG ( 7 , ( " pdb_update_autolock_flag: Account %s, LastBadPassword=%d, duration=%d, current time =%d. \n " ,
pdb_get_username ( sampass ) , ( uint32 ) LastBadPassword , duration * 60 , ( uint32 ) time ( NULL ) ) ) ;
if ( LastBadPassword = = ( time_t ) 0 ) {
DEBUG ( 1 , ( " pdb_update_autolock_flag: Account %s administratively locked out with no \
bad password time . Leaving locked out . \ n " ,
pdb_get_username ( sampass ) ) ) ;
return True ;
}
2004-02-20 00:37:24 +03:00
if ( ( time ( NULL ) > ( LastBadPassword + ( time_t ) duration * 60 ) ) ) {
pdb_set_acct_ctrl ( sampass ,
pdb_get_acct_ctrl ( sampass ) & ~ ACB_AUTOLOCK ,
PDB_CHANGED ) ;
pdb_set_bad_password_count ( sampass , 0 , PDB_CHANGED ) ;
pdb_set_bad_password_time ( sampass , 0 , PDB_CHANGED ) ;
2004-07-17 05:37:04 +04:00
if ( updated ) {
* updated = True ;
}
2004-02-20 00:37:24 +03:00
}
2004-02-19 21:35:43 +03:00
return True ;
}
/*********************************************************************
Increment the bad_password_count
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-02-20 23:09:36 +03:00
BOOL pdb_increment_bad_password_count ( struct samu * sampass )
2004-02-19 21:35:43 +03:00
{
uint32 account_policy_lockout ;
2004-02-20 00:37:24 +03:00
BOOL autolock_updated = False , badpw_updated = False ;
2006-01-13 22:38:09 +03:00
BOOL ret ;
2004-02-19 21:35:43 +03:00
if ( ! sampass )
return False ;
2004-02-20 00:37:24 +03:00
/* Retrieve the account lockout policy */
2006-01-13 22:38:09 +03:00
become_root ( ) ;
ret = pdb_get_account_policy ( AP_BAD_ATTEMPT_LOCKOUT , & account_policy_lockout ) ;
unbecome_root ( ) ;
if ( ! ret ) {
2005-09-30 21:13:37 +04:00
DEBUG ( 0 , ( " pdb_increment_bad_password_count: pdb_get_account_policy failed. \n " ) ) ;
2004-02-19 21:35:43 +03:00
return False ;
2004-02-20 00:37:24 +03:00
}
2004-02-19 21:35:43 +03:00
2004-02-20 00:37:24 +03:00
/* If there is no policy, we don't need to continue checking */
if ( ! account_policy_lockout ) {
DEBUG ( 9 , ( " No lockout policy, don't track bad passwords \n " ) ) ;
2004-02-19 21:35:43 +03:00
return True ;
}
2004-02-20 00:37:24 +03:00
/* Check if the autolock needs to be cleared */
if ( ! pdb_update_autolock_flag ( sampass , & autolock_updated ) )
return False ;
/* Check if the badpw count needs to be reset */
if ( ! pdb_update_bad_password_count ( sampass , & badpw_updated ) )
return False ;
/*
Ok , now we can assume that any resetting that needs to be
done has been done , and just get on with incrementing
and autolocking if necessary
*/
pdb_set_bad_password_count ( sampass ,
pdb_get_bad_password_count ( sampass ) + 1 ,
PDB_CHANGED ) ;
pdb_set_bad_password_time ( sampass , time ( NULL ) , PDB_CHANGED ) ;
if ( pdb_get_bad_password_count ( sampass ) < account_policy_lockout )
return True ;
if ( ! pdb_set_acct_ctrl ( sampass ,
pdb_get_acct_ctrl ( sampass ) | ACB_AUTOLOCK ,
PDB_CHANGED ) ) {
DEBUG ( 1 , ( " pdb_increment_bad_password_count:failed to set 'autolock' flag. \n " ) ) ;
return False ;
}
return True ;
2004-02-19 21:35:43 +03:00
}