2002-01-12 04:55:09 +03:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
2002-01-12 04:55:09 +03:00
SAM_ACCOUNT access routines
Copyright ( C ) Jeremy Allison 1996 - 2001
Copyright ( C ) Luke Kenneth Casson Leighton 1996 - 1998
Copyright ( C ) Gerald ( Jerry ) Carter 2000 - 2001
Copyright ( C ) Andrew Bartlett 2001 - 2002
2002-07-15 14:35:28 +04:00
Copyright ( C ) Stefan ( metze ) Metzmacher 2002
2002-01-12 04:55:09 +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
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
2002-01-15 04:02:13 +03:00
/**
2003-05-14 04:46:43 +04:00
* @ todo Redefine this to NULL , but this changes the API because
2002-01-15 04:02:13 +03:00
* much of samba assumes that the pdb_get . . . ( ) funtions
* return pstrings . ( ie not null - pointers ) .
2002-01-15 04:14:58 +03:00
* See also pdb_fill_default_sam ( ) .
2002-01-15 04:02:13 +03:00
*/
# define PDB_NOT_QUITE_NULL ""
2002-01-12 04:55:09 +03:00
/*********************************************************************
2002-11-02 06:47:48 +03:00
Collection of get . . . ( ) functions for SAM_ACCOUNT .
2002-01-12 04:55:09 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
uint16 pdb_get_acct_ctrl ( const SAM_ACCOUNT * sampass )
{
if ( sampass )
return ( sampass - > private . acct_ctrl ) ;
else
return ( ACB_DISABLED ) ;
}
time_t pdb_get_logon_time ( const SAM_ACCOUNT * sampass )
{
if ( sampass )
return ( sampass - > private . logon_time ) ;
else
return ( 0 ) ;
}
time_t pdb_get_logoff_time ( const SAM_ACCOUNT * sampass )
{
if ( sampass )
return ( sampass - > private . logoff_time ) ;
else
return ( - 1 ) ;
}
time_t pdb_get_kickoff_time ( const SAM_ACCOUNT * sampass )
{
if ( sampass )
return ( sampass - > private . kickoff_time ) ;
else
return ( - 1 ) ;
}
time_t pdb_get_pass_last_set_time ( const SAM_ACCOUNT * sampass )
{
if ( sampass )
return ( sampass - > private . pass_last_set_time ) ;
else
return ( - 1 ) ;
}
time_t pdb_get_pass_can_change_time ( const SAM_ACCOUNT * sampass )
{
if ( sampass )
return ( sampass - > private . pass_can_change_time ) ;
else
return ( - 1 ) ;
}
time_t pdb_get_pass_must_change_time ( const SAM_ACCOUNT * sampass )
{
if ( sampass )
return ( sampass - > private . pass_must_change_time ) ;
else
return ( - 1 ) ;
}
uint16 pdb_get_logon_divs ( const SAM_ACCOUNT * sampass )
{
if ( sampass )
return ( sampass - > private . logon_divs ) ;
else
return ( - 1 ) ;
}
uint32 pdb_get_hours_len ( const SAM_ACCOUNT * sampass )
{
if ( sampass )
return ( sampass - > private . hours_len ) ;
else
return ( - 1 ) ;
}
const uint8 * pdb_get_hours ( const SAM_ACCOUNT * sampass )
{
if ( sampass )
return ( sampass - > private . hours ) ;
else
return ( NULL ) ;
}
const uint8 * pdb_get_nt_passwd ( const SAM_ACCOUNT * sampass )
{
if ( sampass ) {
SMB_ASSERT ( ( ! sampass - > private . nt_pw . data )
| | sampass - > private . nt_pw . length = = NT_HASH_LEN ) ;
return ( ( uint8 * ) sampass - > private . nt_pw . data ) ;
}
else
return ( NULL ) ;
}
const uint8 * pdb_get_lanman_passwd ( const SAM_ACCOUNT * sampass )
{
if ( sampass ) {
SMB_ASSERT ( ( ! sampass - > private . lm_pw . data )
| | sampass - > private . lm_pw . length = = LM_HASH_LEN ) ;
return ( ( uint8 * ) sampass - > private . lm_pw . data ) ;
}
else
return ( NULL ) ;
}
2002-07-15 14:35:28 +04:00
/* Return the plaintext password if known. Most of the time
it isn ' t , so don ' t assume anything magic about this function .
Used to pass the plaintext to passdb backends that might
want to store more than just the NTLM hashes .
*/
const char * pdb_get_plaintext_passwd ( const SAM_ACCOUNT * sampass )
2002-01-12 04:55:09 +03:00
{
2002-07-15 14:35:28 +04:00
if ( sampass ) {
2002-09-25 19:19:00 +04:00
return ( sampass - > private . plaintext_pw ) ;
2002-07-15 14:35:28 +04:00
}
2002-01-12 04:55:09 +03:00
else
2002-07-15 14:35:28 +04:00
return ( NULL ) ;
2002-01-12 04:55:09 +03:00
}
2002-07-15 14:35:28 +04:00
const DOM_SID * pdb_get_user_sid ( const SAM_ACCOUNT * sampass )
2002-01-12 04:55:09 +03:00
{
2002-07-15 14:35:28 +04:00
if ( sampass )
return & sampass - > private . user_sid ;
2002-01-12 04:55:09 +03:00
else
2002-07-15 14:35:28 +04:00
return ( NULL ) ;
2002-01-12 04:55:09 +03:00
}
2002-07-15 14:35:28 +04:00
const DOM_SID * pdb_get_group_sid ( const SAM_ACCOUNT * sampass )
{
if ( sampass )
return & sampass - > private . group_sid ;
else
return ( NULL ) ;
}
2002-01-12 04:55:09 +03:00
/**
* Get flags showing what is initalised in the SAM_ACCOUNT
* @ param sampass the SAM_ACCOUNT in question
* @ return the flags indicating the members initialised in the struct .
* */
2002-11-02 06:47:48 +03:00
enum pdb_value_state pdb_get_init_flags ( const SAM_ACCOUNT * sampass , enum pdb_elements element )
2002-01-12 04:55:09 +03:00
{
2002-11-02 06:47:48 +03:00
enum pdb_value_state ret = PDB_DEFAULT ;
if ( ! sampass | | ! sampass - > private . change_flags | | ! sampass - > private . set_flags )
return ret ;
if ( bitmap_query ( sampass - > private . set_flags , element ) ) {
2003-03-20 15:52:56 +03:00
DEBUG ( 11 , ( " element %d: SET \n " , element ) ) ;
2002-11-02 06:47:48 +03:00
ret = PDB_SET ;
}
if ( bitmap_query ( sampass - > private . change_flags , element ) ) {
2003-03-20 15:52:56 +03:00
DEBUG ( 11 , ( " element %d: CHANGED \n " , element ) ) ;
2002-11-02 06:47:48 +03:00
ret = PDB_CHANGED ;
}
if ( ret = = PDB_DEFAULT ) {
2003-03-20 15:52:56 +03:00
DEBUG ( 11 , ( " element %d: DEFAULT \n " , element ) ) ;
2002-11-02 06:47:48 +03:00
}
return ret ;
2002-01-12 04:55:09 +03:00
}
const char * pdb_get_username ( const SAM_ACCOUNT * sampass )
{
if ( sampass )
return ( sampass - > private . username ) ;
else
return ( NULL ) ;
}
const char * pdb_get_domain ( const SAM_ACCOUNT * sampass )
{
if ( sampass )
return ( sampass - > private . domain ) ;
else
return ( NULL ) ;
}
const char * pdb_get_nt_username ( const SAM_ACCOUNT * sampass )
{
if ( sampass )
return ( sampass - > private . nt_username ) ;
else
return ( NULL ) ;
}
const char * pdb_get_fullname ( const SAM_ACCOUNT * sampass )
{
if ( sampass )
return ( sampass - > private . full_name ) ;
else
return ( NULL ) ;
}
const char * pdb_get_homedir ( const SAM_ACCOUNT * sampass )
{
if ( sampass )
return ( sampass - > private . home_dir ) ;
else
return ( NULL ) ;
}
2002-07-15 14:35:28 +04:00
const char * pdb_get_unix_homedir ( const SAM_ACCOUNT * sampass )
{
if ( sampass )
return ( sampass - > private . unix_home_dir ) ;
else
return ( NULL ) ;
}
2002-08-17 21:00:51 +04:00
const char * pdb_get_dir_drive ( const SAM_ACCOUNT * sampass )
2002-01-12 04:55:09 +03:00
{
if ( sampass )
return ( sampass - > private . dir_drive ) ;
else
return ( NULL ) ;
}
const char * pdb_get_logon_script ( const SAM_ACCOUNT * sampass )
{
if ( sampass )
return ( sampass - > private . logon_script ) ;
else
return ( NULL ) ;
}
const char * pdb_get_profile_path ( const SAM_ACCOUNT * sampass )
{
if ( sampass )
return ( sampass - > private . profile_path ) ;
else
return ( NULL ) ;
}
const char * pdb_get_acct_desc ( const SAM_ACCOUNT * sampass )
{
if ( sampass )
return ( sampass - > private . acct_desc ) ;
else
return ( NULL ) ;
}
const char * pdb_get_workstations ( const SAM_ACCOUNT * sampass )
{
if ( sampass )
return ( sampass - > private . workstations ) ;
else
return ( NULL ) ;
}
const char * pdb_get_unknown_str ( const SAM_ACCOUNT * sampass )
{
if ( sampass )
return ( sampass - > private . unknown_str ) ;
else
return ( NULL ) ;
}
const char * pdb_get_munged_dial ( const SAM_ACCOUNT * sampass )
{
if ( sampass )
return ( sampass - > private . munged_dial ) ;
else
return ( NULL ) ;
}
2002-11-02 06:47:48 +03:00
uint32 pdb_get_unknown_3 ( const SAM_ACCOUNT * sampass )
2002-01-12 04:55:09 +03:00
{
if ( sampass )
return ( sampass - > private . unknown_3 ) ;
else
return ( - 1 ) ;
}
2003-09-19 03:53:48 +04:00
uint16 pdb_get_bad_password_count ( const SAM_ACCOUNT * sampass )
2002-01-12 04:55:09 +03:00
{
if ( sampass )
2003-09-19 03:53:48 +04:00
return ( sampass - > private . bad_password_count ) ;
2002-01-12 04:55:09 +03:00
else
2003-09-19 03:53:48 +04:00
return 0 ;
}
uint16 pdb_get_logon_count ( const SAM_ACCOUNT * sampass )
{
if ( sampass )
return ( sampass - > private . logon_count ) ;
else
return 0 ;
2002-01-12 04:55:09 +03:00
}
2002-11-02 06:47:48 +03:00
uint32 pdb_get_unknown_6 ( const SAM_ACCOUNT * sampass )
2002-01-12 04:55:09 +03:00
{
if ( sampass )
return ( sampass - > private . unknown_6 ) ;
else
return ( - 1 ) ;
}
2003-07-05 13:46:12 +04:00
void * pdb_get_backend_private_data ( const SAM_ACCOUNT * sampass , const struct pdb_methods * my_methods )
{
2003-07-05 14:39:41 +04:00
if ( sampass & & my_methods = = sampass - > private . backend_private_methods )
2003-07-05 13:46:12 +04:00
return sampass - > private . backend_private_data ;
else
return NULL ;
}
2002-01-12 04:55:09 +03:00
/*********************************************************************
2002-11-02 06:47:48 +03:00
Collection of set . . . ( ) functions for SAM_ACCOUNT .
2002-01-12 04:55:09 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-02 06:47:48 +03:00
BOOL pdb_set_acct_ctrl ( SAM_ACCOUNT * sampass , uint16 acct_ctrl , enum pdb_value_state flag )
2002-01-12 04:55:09 +03:00
{
if ( ! sampass )
return False ;
2002-11-02 06:47:48 +03:00
sampass - > private . acct_ctrl = acct_ctrl ;
return pdb_set_init_flags ( sampass , PDB_ACCTCTRL , flag ) ;
2002-01-12 04:55:09 +03:00
}
2002-11-02 06:47:48 +03:00
BOOL pdb_set_logon_time ( SAM_ACCOUNT * sampass , time_t mytime , enum pdb_value_state flag )
2002-01-12 04:55:09 +03:00
{
if ( ! sampass )
return False ;
sampass - > private . logon_time = mytime ;
2002-03-02 13:16:28 +03:00
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_LOGONTIME , flag ) ;
2002-01-12 04:55:09 +03:00
}
2002-11-02 06:47:48 +03:00
BOOL pdb_set_logoff_time ( SAM_ACCOUNT * sampass , time_t mytime , enum pdb_value_state flag )
2002-01-12 04:55:09 +03:00
{
if ( ! sampass )
return False ;
sampass - > private . logoff_time = mytime ;
2002-03-02 13:16:28 +03:00
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_LOGOFFTIME , flag ) ;
2002-01-12 04:55:09 +03:00
}
2002-11-02 06:47:48 +03:00
BOOL pdb_set_kickoff_time ( SAM_ACCOUNT * sampass , time_t mytime , enum pdb_value_state flag )
2002-01-12 04:55:09 +03:00
{
if ( ! sampass )
return False ;
sampass - > private . kickoff_time = mytime ;
2002-03-02 13:16:28 +03:00
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_KICKOFFTIME , flag ) ;
2002-01-12 04:55:09 +03:00
}
2002-11-02 06:47:48 +03:00
BOOL pdb_set_pass_can_change_time ( SAM_ACCOUNT * sampass , time_t mytime , enum pdb_value_state flag )
2002-01-12 04:55:09 +03:00
{
if ( ! sampass )
return False ;
sampass - > private . pass_can_change_time = mytime ;
2002-03-02 13:16:28 +03:00
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_CANCHANGETIME , flag ) ;
2002-01-12 04:55:09 +03:00
}
2002-11-02 06:47:48 +03:00
BOOL pdb_set_pass_must_change_time ( SAM_ACCOUNT * sampass , time_t mytime , enum pdb_value_state flag )
2002-01-12 04:55:09 +03:00
{
if ( ! sampass )
return False ;
sampass - > private . pass_must_change_time = mytime ;
2002-03-02 13:16:28 +03:00
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_MUSTCHANGETIME , flag ) ;
2002-01-12 04:55:09 +03:00
}
2002-11-02 06:47:48 +03:00
BOOL pdb_set_pass_last_set_time ( SAM_ACCOUNT * sampass , time_t mytime , enum pdb_value_state flag )
2002-01-12 04:55:09 +03:00
{
if ( ! sampass )
return False ;
sampass - > private . pass_last_set_time = mytime ;
2002-03-02 13:16:28 +03:00
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_PASSLASTSET , flag ) ;
2002-01-12 04:55:09 +03:00
}
2002-11-02 06:47:48 +03:00
BOOL pdb_set_hours_len ( SAM_ACCOUNT * sampass , uint32 len , enum pdb_value_state flag )
2002-01-12 04:55:09 +03:00
{
if ( ! sampass )
return False ;
sampass - > private . hours_len = len ;
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_HOURSLEN , flag ) ;
2002-01-12 04:55:09 +03:00
}
2002-11-02 06:47:48 +03:00
BOOL pdb_set_logon_divs ( SAM_ACCOUNT * sampass , uint16 hours , enum pdb_value_state flag )
2002-01-12 04:55:09 +03:00
{
if ( ! sampass )
return False ;
sampass - > private . logon_divs = hours ;
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_LOGONDIVS , flag ) ;
2002-01-12 04:55:09 +03:00
}
/**
* Set flags showing what is initalised in the SAM_ACCOUNT
* @ param sampass the SAM_ACCOUNT in question
* @ param flag The * new * flag to be set . Old flags preserved
* this flag is only added .
* */
2002-11-02 06:47:48 +03:00
BOOL pdb_set_init_flags ( SAM_ACCOUNT * sampass , enum pdb_elements element , enum pdb_value_state value_flag )
2002-01-12 04:55:09 +03:00
{
2002-11-02 06:47:48 +03:00
if ( ! sampass | | ! sampass - > mem_ctx )
2002-01-12 04:55:09 +03:00
return False ;
2002-11-02 06:47:48 +03:00
if ( ! sampass - > private . set_flags ) {
if ( ( sampass - > private . set_flags =
bitmap_talloc ( sampass - > mem_ctx ,
PDB_COUNT ) ) = = NULL ) {
DEBUG ( 0 , ( " bitmap_talloc failed \n " ) ) ;
return False ;
}
}
if ( ! sampass - > private . change_flags ) {
if ( ( sampass - > private . change_flags =
bitmap_talloc ( sampass - > mem_ctx ,
PDB_COUNT ) ) = = NULL ) {
DEBUG ( 0 , ( " bitmap_talloc failed \n " ) ) ;
return False ;
}
}
switch ( value_flag ) {
case PDB_CHANGED :
if ( ! bitmap_set ( sampass - > private . change_flags , element ) ) {
DEBUG ( 0 , ( " Can't set flag: %d in change_flags. \n " , element ) ) ;
return False ;
}
if ( ! bitmap_set ( sampass - > private . set_flags , element ) ) {
2003-03-20 15:52:56 +03:00
DEBUG ( 0 , ( " Can't set flag: %d in set_flags. \n " , element ) ) ;
2002-11-02 06:47:48 +03:00
return False ;
}
2003-03-20 15:52:56 +03:00
DEBUG ( 11 , ( " element %d -> now CHANGED \n " , element ) ) ;
2002-11-02 06:47:48 +03:00
break ;
case PDB_SET :
if ( ! bitmap_clear ( sampass - > private . change_flags , element ) ) {
DEBUG ( 0 , ( " Can't set flag: %d in change_flags. \n " , element ) ) ;
return False ;
}
if ( ! bitmap_set ( sampass - > private . set_flags , element ) ) {
2003-03-20 15:52:56 +03:00
DEBUG ( 0 , ( " Can't set flag: %d in set_flags. \n " , element ) ) ;
2002-11-02 06:47:48 +03:00
return False ;
}
2003-04-28 09:26:59 +04:00
DEBUG ( 10 , ( " element %d -> now SET \n " , element ) ) ;
2002-11-02 06:47:48 +03:00
break ;
case PDB_DEFAULT :
default :
if ( ! bitmap_clear ( sampass - > private . change_flags , element ) ) {
DEBUG ( 0 , ( " Can't set flag: %d in change_flags. \n " , element ) ) ;
return False ;
}
if ( ! bitmap_clear ( sampass - > private . set_flags , element ) ) {
2003-03-20 15:52:56 +03:00
DEBUG ( 0 , ( " Can't set flag: %d in set_flags. \n " , element ) ) ;
2002-11-02 06:47:48 +03:00
return False ;
}
2003-04-28 09:26:59 +04:00
DEBUG ( 11 , ( " element %d -> now DEFAULT \n " , element ) ) ;
2002-11-02 06:47:48 +03:00
break ;
}
2002-01-12 04:55:09 +03:00
return True ;
}
2003-10-06 05:38:46 +04:00
BOOL pdb_set_user_sid ( SAM_ACCOUNT * sampass , const DOM_SID * u_sid , enum pdb_value_state flag )
2002-01-12 04:55:09 +03:00
{
2002-07-15 14:35:28 +04:00
if ( ! sampass | | ! u_sid )
2002-01-12 04:55:09 +03:00
return False ;
2002-07-15 14:35:28 +04:00
sid_copy ( & sampass - > private . user_sid , u_sid ) ;
2002-01-12 04:55:09 +03:00
2002-07-15 14:35:28 +04:00
DEBUG ( 10 , ( " pdb_set_user_sid: setting user sid %s \n " ,
sid_string_static ( & sampass - > private . user_sid ) ) ) ;
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_USERSID , flag ) ;
2002-01-12 04:55:09 +03:00
}
2002-11-02 06:47:48 +03:00
BOOL pdb_set_user_sid_from_string ( SAM_ACCOUNT * sampass , fstring u_sid , enum pdb_value_state flag )
2002-01-12 04:55:09 +03:00
{
2002-07-15 14:35:28 +04:00
DOM_SID new_sid ;
2002-11-02 06:47:48 +03:00
2002-07-15 14:35:28 +04:00
if ( ! sampass | | ! u_sid )
2002-01-12 04:55:09 +03:00
return False ;
2002-07-15 14:35:28 +04:00
DEBUG ( 10 , ( " pdb_set_user_sid_from_string: setting user sid %s \n " ,
u_sid ) ) ;
if ( ! string_to_sid ( & new_sid , u_sid ) ) {
DEBUG ( 1 , ( " pdb_set_user_sid_from_string: %s isn't a valid SID! \n " , u_sid ) ) ;
return False ;
}
2002-11-02 06:47:48 +03:00
if ( ! pdb_set_user_sid ( sampass , & new_sid , flag ) ) {
2002-07-15 14:35:28 +04:00
DEBUG ( 1 , ( " pdb_set_user_sid_from_string: could not set sid %s on SAM_ACCOUNT! \n " , u_sid ) ) ;
return False ;
}
return True ;
}
2003-10-06 05:38:46 +04:00
BOOL pdb_set_group_sid ( SAM_ACCOUNT * sampass , const DOM_SID * g_sid , enum pdb_value_state flag )
2002-07-15 14:35:28 +04:00
{
if ( ! sampass | | ! g_sid )
return False ;
sid_copy ( & sampass - > private . group_sid , g_sid ) ;
DEBUG ( 10 , ( " pdb_set_group_sid: setting group sid %s \n " ,
sid_string_static ( & sampass - > private . group_sid ) ) ) ;
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_GROUPSID , flag ) ;
2002-07-15 14:35:28 +04:00
}
2002-11-02 06:47:48 +03:00
BOOL pdb_set_group_sid_from_string ( SAM_ACCOUNT * sampass , fstring g_sid , enum pdb_value_state flag )
2002-07-15 14:35:28 +04:00
{
DOM_SID new_sid ;
if ( ! sampass | | ! g_sid )
return False ;
DEBUG ( 10 , ( " pdb_set_group_sid_from_string: setting group sid %s \n " ,
g_sid ) ) ;
if ( ! string_to_sid ( & new_sid , g_sid ) ) {
DEBUG ( 1 , ( " pdb_set_group_sid_from_string: %s isn't a valid SID! \n " , g_sid ) ) ;
return False ;
}
2002-11-02 06:47:48 +03:00
if ( ! pdb_set_group_sid ( sampass , & new_sid , flag ) ) {
2002-07-15 14:35:28 +04:00
DEBUG ( 1 , ( " pdb_set_group_sid_from_string: could not set sid %s on SAM_ACCOUNT! \n " , g_sid ) ) ;
return False ;
}
2002-01-12 04:55:09 +03:00
return True ;
}
/*********************************************************************
Set the user ' s UNIX name .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-02 06:47:48 +03:00
BOOL pdb_set_username ( SAM_ACCOUNT * sampass , const char * username , enum pdb_value_state flag )
{
2002-01-12 04:55:09 +03:00
if ( ! sampass )
return False ;
2002-01-15 04:02:13 +03:00
if ( username ) {
2002-03-19 02:57:14 +03:00
DEBUG ( 10 , ( " pdb_set_username: setting username %s, was %s \n " , username ,
( sampass - > private . username ) ? ( sampass - > private . username ) : " NULL " ) ) ;
2002-01-15 04:02:13 +03:00
sampass - > private . username = talloc_strdup ( sampass - > mem_ctx , username ) ;
2002-01-15 08:15:22 +03:00
if ( ! sampass - > private . username ) {
DEBUG ( 0 , ( " pdb_set_username: talloc_strdup() failed! \n " ) ) ;
return False ;
}
2002-01-15 04:02:13 +03:00
} else {
sampass - > private . username = PDB_NOT_QUITE_NULL ;
}
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_USERNAME , flag ) ;
2002-01-12 04:55:09 +03:00
}
/*********************************************************************
Set the domain name .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-02 06:47:48 +03:00
BOOL pdb_set_domain ( SAM_ACCOUNT * sampass , const char * domain , enum pdb_value_state flag )
{
2002-01-12 04:55:09 +03:00
if ( ! sampass )
return False ;
2002-01-15 04:02:13 +03:00
if ( domain ) {
2002-03-19 02:57:14 +03:00
DEBUG ( 10 , ( " pdb_set_domain: setting domain %s, was %s \n " , domain ,
( sampass - > private . domain ) ? ( sampass - > private . domain ) : " NULL " ) ) ;
2002-01-15 04:02:13 +03:00
sampass - > private . domain = talloc_strdup ( sampass - > mem_ctx , domain ) ;
2002-01-15 08:15:22 +03:00
if ( ! sampass - > private . domain ) {
DEBUG ( 0 , ( " pdb_set_domain: talloc_strdup() failed! \n " ) ) ;
return False ;
}
2002-01-15 04:02:13 +03:00
} else {
sampass - > private . domain = PDB_NOT_QUITE_NULL ;
}
2002-01-12 04:55:09 +03:00
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_DOMAIN , flag ) ;
2002-01-12 04:55:09 +03:00
}
/*********************************************************************
Set the user ' s NT name .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-02 06:47:48 +03:00
BOOL pdb_set_nt_username ( SAM_ACCOUNT * sampass , const char * nt_username , enum pdb_value_state flag )
2002-01-12 04:55:09 +03:00
{
if ( ! sampass )
return False ;
2002-01-15 04:02:13 +03:00
if ( nt_username ) {
2002-03-19 02:57:14 +03:00
DEBUG ( 10 , ( " pdb_set_nt_username: setting nt username %s, was %s \n " , nt_username ,
( sampass - > private . nt_username ) ? ( sampass - > private . nt_username ) : " NULL " ) ) ;
2002-01-15 04:02:13 +03:00
sampass - > private . nt_username = talloc_strdup ( sampass - > mem_ctx , nt_username ) ;
2002-01-15 08:15:22 +03:00
if ( ! sampass - > private . nt_username ) {
DEBUG ( 0 , ( " pdb_set_nt_username: talloc_strdup() failed! \n " ) ) ;
return False ;
}
2002-01-15 04:02:13 +03:00
} else {
sampass - > private . nt_username = PDB_NOT_QUITE_NULL ;
}
2002-01-12 04:55:09 +03:00
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_NTUSERNAME , flag ) ;
2002-01-12 04:55:09 +03:00
}
/*********************************************************************
Set the user ' s full name .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-02 06:47:48 +03:00
BOOL pdb_set_fullname ( SAM_ACCOUNT * sampass , const char * full_name , enum pdb_value_state flag )
2002-01-12 04:55:09 +03:00
{
if ( ! sampass )
return False ;
2002-01-15 04:02:13 +03:00
if ( full_name ) {
2002-03-19 02:57:14 +03:00
DEBUG ( 10 , ( " pdb_set_full_name: setting full name %s, was %s \n " , full_name ,
( sampass - > private . full_name ) ? ( sampass - > private . full_name ) : " NULL " ) ) ;
2002-01-15 04:02:13 +03:00
sampass - > private . full_name = talloc_strdup ( sampass - > mem_ctx , full_name ) ;
2002-01-15 08:15:22 +03:00
if ( ! sampass - > private . full_name ) {
DEBUG ( 0 , ( " pdb_set_fullname: talloc_strdup() failed! \n " ) ) ;
return False ;
}
2002-01-15 04:02:13 +03:00
} else {
sampass - > private . full_name = PDB_NOT_QUITE_NULL ;
}
2002-01-12 04:55:09 +03:00
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_FULLNAME , flag ) ;
2002-01-12 04:55:09 +03:00
}
/*********************************************************************
Set the user ' s logon script .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-02 06:47:48 +03:00
BOOL pdb_set_logon_script ( SAM_ACCOUNT * sampass , const char * logon_script , enum pdb_value_state flag )
2002-01-12 04:55:09 +03:00
{
if ( ! sampass )
return False ;
2002-01-15 04:02:13 +03:00
if ( logon_script ) {
2002-03-19 02:57:14 +03:00
DEBUG ( 10 , ( " pdb_set_logon_script: setting logon script %s, was %s \n " , logon_script ,
( sampass - > private . logon_script ) ? ( sampass - > private . logon_script ) : " NULL " ) ) ;
2002-01-15 04:02:13 +03:00
sampass - > private . logon_script = talloc_strdup ( sampass - > mem_ctx , logon_script ) ;
2002-01-15 08:15:22 +03:00
if ( ! sampass - > private . logon_script ) {
DEBUG ( 0 , ( " pdb_set_logon_script: talloc_strdup() failed! \n " ) ) ;
return False ;
}
2002-01-15 04:02:13 +03:00
} else {
sampass - > private . logon_script = PDB_NOT_QUITE_NULL ;
}
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_LOGONSCRIPT , flag ) ;
2002-01-12 04:55:09 +03:00
}
/*********************************************************************
Set the user ' s profile path .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-02 06:47:48 +03:00
BOOL pdb_set_profile_path ( SAM_ACCOUNT * sampass , const char * profile_path , enum pdb_value_state flag )
2002-01-12 04:55:09 +03:00
{
if ( ! sampass )
return False ;
2002-01-15 04:02:13 +03:00
if ( profile_path ) {
2002-03-19 02:57:14 +03:00
DEBUG ( 10 , ( " pdb_set_profile_path: setting profile path %s, was %s \n " , profile_path ,
( sampass - > private . profile_path ) ? ( sampass - > private . profile_path ) : " NULL " ) ) ;
2002-01-15 04:02:13 +03:00
sampass - > private . profile_path = talloc_strdup ( sampass - > mem_ctx , profile_path ) ;
2002-01-15 08:15:22 +03:00
if ( ! sampass - > private . profile_path ) {
DEBUG ( 0 , ( " pdb_set_profile_path: talloc_strdup() failed! \n " ) ) ;
return False ;
}
2002-01-15 04:02:13 +03:00
} else {
sampass - > private . profile_path = PDB_NOT_QUITE_NULL ;
}
2002-01-12 04:55:09 +03:00
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_PROFILE , flag ) ;
2002-01-12 04:55:09 +03:00
}
/*********************************************************************
Set the user ' s directory drive .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-02 06:47:48 +03:00
BOOL pdb_set_dir_drive ( SAM_ACCOUNT * sampass , const char * dir_drive , enum pdb_value_state flag )
2002-01-12 04:55:09 +03:00
{
if ( ! sampass )
return False ;
2002-01-15 04:02:13 +03:00
if ( dir_drive ) {
2002-03-19 02:57:14 +03:00
DEBUG ( 10 , ( " pdb_set_dir_drive: setting dir drive %s, was %s \n " , dir_drive ,
( sampass - > private . dir_drive ) ? ( sampass - > private . dir_drive ) : " NULL " ) ) ;
2002-01-15 04:02:13 +03:00
sampass - > private . dir_drive = talloc_strdup ( sampass - > mem_ctx , dir_drive ) ;
2002-01-15 08:15:22 +03:00
if ( ! sampass - > private . dir_drive ) {
DEBUG ( 0 , ( " pdb_set_dir_drive: talloc_strdup() failed! \n " ) ) ;
return False ;
}
2002-01-15 04:02:13 +03:00
} else {
sampass - > private . dir_drive = PDB_NOT_QUITE_NULL ;
}
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_DRIVE , flag ) ;
2002-01-12 04:55:09 +03:00
}
/*********************************************************************
Set the user ' s home directory .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-02 06:47:48 +03:00
BOOL pdb_set_homedir ( SAM_ACCOUNT * sampass , const char * home_dir , enum pdb_value_state flag )
2002-01-12 04:55:09 +03:00
{
if ( ! sampass )
return False ;
2002-01-15 04:02:13 +03:00
if ( home_dir ) {
2002-03-19 02:57:14 +03:00
DEBUG ( 10 , ( " pdb_set_homedir: setting home dir %s, was %s \n " , home_dir ,
( sampass - > private . home_dir ) ? ( sampass - > private . home_dir ) : " NULL " ) ) ;
2002-01-15 04:02:13 +03:00
sampass - > private . home_dir = talloc_strdup ( sampass - > mem_ctx , home_dir ) ;
2002-01-15 08:15:22 +03:00
if ( ! sampass - > private . home_dir ) {
DEBUG ( 0 , ( " pdb_set_home_dir: talloc_strdup() failed! \n " ) ) ;
return False ;
}
2002-01-15 04:02:13 +03:00
} else {
sampass - > private . home_dir = PDB_NOT_QUITE_NULL ;
}
2002-01-12 04:55:09 +03:00
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_SMBHOME , flag ) ;
2002-01-12 04:55:09 +03:00
}
2002-07-15 14:35:28 +04:00
/*********************************************************************
Set the user ' s unix home directory .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-02 06:47:48 +03:00
BOOL pdb_set_unix_homedir ( SAM_ACCOUNT * sampass , const char * unix_home_dir , enum pdb_value_state flag )
2002-07-15 14:35:28 +04:00
{
if ( ! sampass )
return False ;
if ( unix_home_dir ) {
DEBUG ( 10 , ( " pdb_set_unix_homedir: setting home dir %s, was %s \n " , unix_home_dir ,
( sampass - > private . unix_home_dir ) ? ( sampass - > private . unix_home_dir ) : " NULL " ) ) ;
sampass - > private . unix_home_dir = talloc_strdup ( sampass - > mem_ctx ,
unix_home_dir ) ;
if ( ! sampass - > private . unix_home_dir ) {
DEBUG ( 0 , ( " pdb_set_unix_home_dir: talloc_strdup() failed! \n " ) ) ;
return False ;
}
} else {
sampass - > private . unix_home_dir = PDB_NOT_QUITE_NULL ;
}
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_UNIXHOMEDIR , flag ) ;
2002-07-15 14:35:28 +04:00
}
2002-01-12 04:55:09 +03:00
/*********************************************************************
Set the user ' s account description .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-02 06:47:48 +03:00
BOOL pdb_set_acct_desc ( SAM_ACCOUNT * sampass , const char * acct_desc , enum pdb_value_state flag )
2002-01-12 04:55:09 +03:00
{
if ( ! sampass )
return False ;
2002-01-15 04:02:13 +03:00
if ( acct_desc ) {
sampass - > private . acct_desc = talloc_strdup ( sampass - > mem_ctx , acct_desc ) ;
2002-01-15 08:15:22 +03:00
if ( ! sampass - > private . acct_desc ) {
DEBUG ( 0 , ( " pdb_set_acct_desc: talloc_strdup() failed! \n " ) ) ;
return False ;
}
2002-01-15 04:02:13 +03:00
} else {
sampass - > private . acct_desc = PDB_NOT_QUITE_NULL ;
}
2002-01-12 04:55:09 +03:00
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_ACCTDESC , flag ) ;
2002-01-12 04:55:09 +03:00
}
/*********************************************************************
Set the user ' s workstation allowed list .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-02 06:47:48 +03:00
BOOL pdb_set_workstations ( SAM_ACCOUNT * sampass , const char * workstations , enum pdb_value_state flag )
2002-01-12 04:55:09 +03:00
{
if ( ! sampass )
return False ;
2002-01-15 04:02:13 +03:00
if ( workstations ) {
2002-03-19 02:57:14 +03:00
DEBUG ( 10 , ( " pdb_set_workstations: setting workstations %s, was %s \n " , workstations ,
( sampass - > private . workstations ) ? ( sampass - > private . workstations ) : " NULL " ) ) ;
2002-01-15 04:02:13 +03:00
sampass - > private . workstations = talloc_strdup ( sampass - > mem_ctx , workstations ) ;
2002-01-15 08:15:22 +03:00
if ( ! sampass - > private . workstations ) {
DEBUG ( 0 , ( " pdb_set_workstations: talloc_strdup() failed! \n " ) ) ;
return False ;
}
2002-01-15 04:02:13 +03:00
} else {
sampass - > private . workstations = PDB_NOT_QUITE_NULL ;
}
2002-01-12 04:55:09 +03:00
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_WORKSTATIONS , flag ) ;
2002-01-12 04:55:09 +03:00
}
/*********************************************************************
Set the user ' s ' unknown_str ' , whatever the heck this actually is . . .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-02 06:47:48 +03:00
BOOL pdb_set_unknown_str ( SAM_ACCOUNT * sampass , const char * unknown_str , enum pdb_value_state flag )
2002-01-12 04:55:09 +03:00
{
if ( ! sampass )
return False ;
2002-01-15 04:02:13 +03:00
if ( unknown_str ) {
sampass - > private . unknown_str = talloc_strdup ( sampass - > mem_ctx , unknown_str ) ;
2002-01-15 08:15:22 +03:00
if ( ! sampass - > private . unknown_str ) {
DEBUG ( 0 , ( " pdb_set_unknown_str: talloc_strdup() failed! \n " ) ) ;
return False ;
}
2002-01-15 04:02:13 +03:00
} else {
sampass - > private . unknown_str = PDB_NOT_QUITE_NULL ;
}
2002-01-12 04:55:09 +03:00
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_UNKNOWNSTR , flag ) ;
2002-01-12 04:55:09 +03:00
}
/*********************************************************************
Set the user ' s dial string .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-02 06:47:48 +03:00
BOOL pdb_set_munged_dial ( SAM_ACCOUNT * sampass , const char * munged_dial , enum pdb_value_state flag )
2002-01-12 04:55:09 +03:00
{
if ( ! sampass )
return False ;
2002-03-19 02:57:14 +03:00
2002-01-15 04:02:13 +03:00
if ( munged_dial ) {
sampass - > private . munged_dial = talloc_strdup ( sampass - > mem_ctx , munged_dial ) ;
2002-01-15 08:15:22 +03:00
if ( ! sampass - > private . munged_dial ) {
DEBUG ( 0 , ( " pdb_set_munged_dial: talloc_strdup() failed! \n " ) ) ;
return False ;
}
2002-01-15 04:02:13 +03:00
} else {
sampass - > private . munged_dial = PDB_NOT_QUITE_NULL ;
}
2002-01-12 04:55:09 +03:00
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_MUNGEDDIAL , flag ) ;
2002-01-12 04:55:09 +03:00
}
/*********************************************************************
Set the user ' s NT hash .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-02 06:47:48 +03:00
BOOL pdb_set_nt_passwd ( SAM_ACCOUNT * sampass , const uint8 pwd [ NT_HASH_LEN ] , enum pdb_value_state flag )
2002-01-12 04:55:09 +03:00
{
if ( ! sampass )
return False ;
data_blob_clear_free ( & sampass - > private . nt_pw ) ;
2004-01-29 23:14:50 +03:00
if ( pwd ) {
sampass - > private . nt_pw = data_blob ( pwd , NT_HASH_LEN ) ;
} else {
sampass - > private . nt_pw = data_blob ( NULL , 0 ) ;
}
2002-01-12 04:55:09 +03:00
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_NTPASSWD , flag ) ;
2002-01-12 04:55:09 +03:00
}
/*********************************************************************
Set the user ' s LM hash .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-02 06:47:48 +03:00
BOOL pdb_set_lanman_passwd ( SAM_ACCOUNT * sampass , const uint8 pwd [ LM_HASH_LEN ] , enum pdb_value_state flag )
2002-01-12 04:55:09 +03:00
{
if ( ! sampass )
return False ;
data_blob_clear_free ( & sampass - > private . lm_pw ) ;
2004-01-29 23:14:50 +03:00
if ( pwd ) {
sampass - > private . lm_pw = data_blob ( pwd , LM_HASH_LEN ) ;
} else {
sampass - > private . lm_pw = data_blob ( NULL , 0 ) ;
}
2002-01-12 04:55:09 +03:00
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_LMPASSWD , flag ) ;
2002-01-12 04:55:09 +03:00
}
2002-07-15 14:35:28 +04:00
/*********************************************************************
Set the user ' s plaintext password only ( base procedure , see helper
below )
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-02 06:47:48 +03:00
BOOL pdb_set_plaintext_pw_only ( SAM_ACCOUNT * sampass , const char * password , enum pdb_value_state flag )
2002-07-15 14:35:28 +04:00
{
if ( ! sampass )
return False ;
2002-09-25 19:19:00 +04:00
if ( password ) {
if ( sampass - > private . plaintext_pw ! = NULL )
memset ( sampass - > private . plaintext_pw , ' \0 ' , strlen ( sampass - > private . plaintext_pw ) + 1 ) ;
2002-09-26 22:58:34 +04:00
2002-09-25 19:19:00 +04:00
sampass - > private . plaintext_pw = talloc_strdup ( sampass - > mem_ctx , password ) ;
if ( ! sampass - > private . plaintext_pw ) {
DEBUG ( 0 , ( " pdb_set_unknown_str: talloc_strdup() failed! \n " ) ) ;
return False ;
}
} else {
sampass - > private . plaintext_pw = NULL ;
}
2002-07-15 14:35:28 +04:00
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_PLAINTEXT_PW , flag ) ;
2002-07-15 14:35:28 +04:00
}
2002-11-02 06:47:48 +03:00
BOOL pdb_set_unknown_3 ( SAM_ACCOUNT * sampass , uint32 unkn , enum pdb_value_state flag )
2002-01-12 04:55:09 +03:00
{
if ( ! sampass )
return False ;
sampass - > private . unknown_3 = unkn ;
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_UNKNOWN3 , flag ) ;
2002-01-12 04:55:09 +03:00
}
2003-09-19 03:53:48 +04:00
BOOL pdb_set_bad_password_count ( SAM_ACCOUNT * sampass , uint16 bad_password_count , enum pdb_value_state flag )
{
if ( ! sampass )
return False ;
sampass - > private . bad_password_count = bad_password_count ;
return pdb_set_init_flags ( sampass , PDB_BAD_PASSWORD_COUNT , flag ) ;
}
BOOL pdb_set_logon_count ( SAM_ACCOUNT * sampass , uint16 logon_count , enum pdb_value_state flag )
2002-01-12 04:55:09 +03:00
{
if ( ! sampass )
return False ;
2003-09-19 03:53:48 +04:00
sampass - > private . logon_count = logon_count ;
2002-11-02 06:47:48 +03:00
2003-09-19 03:53:48 +04:00
return pdb_set_init_flags ( sampass , PDB_LOGON_COUNT , flag ) ;
2002-01-12 04:55:09 +03:00
}
2002-11-02 06:47:48 +03:00
BOOL pdb_set_unknown_6 ( SAM_ACCOUNT * sampass , uint32 unkn , enum pdb_value_state flag )
2002-01-12 04:55:09 +03:00
{
if ( ! sampass )
return False ;
sampass - > private . unknown_6 = unkn ;
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_UNKNOWN6 , flag ) ;
2002-01-12 04:55:09 +03:00
}
2002-11-02 06:47:48 +03:00
BOOL pdb_set_hours ( SAM_ACCOUNT * sampass , const uint8 * hours , enum pdb_value_state flag )
2002-01-12 04:55:09 +03:00
{
if ( ! sampass )
return False ;
if ( ! hours ) {
memset ( ( char * ) sampass - > private . hours , 0 , MAX_HOURS_LEN ) ;
return True ;
}
memcpy ( sampass - > private . hours , hours , MAX_HOURS_LEN ) ;
2002-11-02 06:47:48 +03:00
return pdb_set_init_flags ( sampass , PDB_HOURS , flag ) ;
2002-01-12 04:55:09 +03:00
}
2003-07-05 13:46:12 +04:00
BOOL pdb_set_backend_private_data ( SAM_ACCOUNT * sampass , void * private_data ,
void ( * free_fn ) ( void * * ) ,
const struct pdb_methods * my_methods ,
enum pdb_value_state flag )
{
if ( ! sampass )
return False ;
if ( sampass - > private . backend_private_data & & sampass - > private . backend_private_data_free_fn ) {
sampass - > private . backend_private_data_free_fn ( & sampass - > private . backend_private_data ) ;
}
sampass - > private . backend_private_data = private_data ;
sampass - > private . backend_private_data_free_fn = free_fn ;
2003-07-05 14:39:41 +04:00
sampass - > private . backend_private_methods = my_methods ;
2003-07-05 13:46:12 +04:00
return pdb_set_init_flags ( sampass , PDB_BACKEND_PRIVATE_DATA , flag ) ;
}
2002-01-12 04:55:09 +03:00
/* Helpful interfaces to the above */
/*********************************************************************
Sets the last changed times and must change times for a normal
password change .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
BOOL pdb_set_pass_changed_now ( SAM_ACCOUNT * sampass )
{
uint32 expire ;
2003-03-22 11:09:22 +03:00
uint32 min_age ;
2002-01-12 04:55:09 +03:00
if ( ! sampass )
return False ;
2002-11-02 06:47:48 +03:00
if ( ! pdb_set_pass_last_set_time ( sampass , time ( NULL ) , PDB_CHANGED ) )
2002-01-12 04:55:09 +03:00
return False ;
2002-08-17 21:00:51 +04:00
if ( ! account_policy_get ( AP_MAX_PASSWORD_AGE , & expire )
| | ( expire = = ( uint32 ) - 1 ) ) {
2002-11-02 06:47:48 +03:00
if ( ! pdb_set_pass_must_change_time ( sampass , get_time_t_max ( ) , PDB_CHANGED ) )
2002-01-12 04:55:09 +03:00
return False ;
} else {
if ( ! pdb_set_pass_must_change_time ( sampass ,
2002-08-17 21:00:51 +04:00
pdb_get_pass_last_set_time ( sampass )
2002-11-02 06:47:48 +03:00
+ expire , PDB_CHANGED ) )
2002-01-12 04:55:09 +03:00
return False ;
}
2003-03-22 11:09:22 +03:00
if ( ! account_policy_get ( AP_MIN_PASSWORD_AGE , & min_age )
| | ( min_age = = ( uint32 ) - 1 ) ) {
if ( ! pdb_set_pass_can_change_time ( sampass , 0 , PDB_CHANGED ) )
return False ;
} else {
if ( ! pdb_set_pass_can_change_time ( sampass ,
pdb_get_pass_last_set_time ( sampass )
+ min_age , PDB_CHANGED ) )
return False ;
}
2002-01-12 04:55:09 +03:00
return True ;
}
/*********************************************************************
Set the user ' s PLAINTEXT password . Used as an interface to the above .
Also sets the last change time to NOW .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
BOOL pdb_set_plaintext_passwd ( SAM_ACCOUNT * sampass , const char * plaintext )
{
uchar new_lanman_p16 [ 16 ] ;
uchar new_nt_p16 [ 16 ] ;
if ( ! sampass | | ! plaintext )
return False ;
2004-02-08 11:38:42 +03:00
/* Calculate the MD4 hash (NT compatible) of the password */
E_md4hash ( plaintext , new_nt_p16 ) ;
2002-01-12 04:55:09 +03:00
2002-11-02 06:47:48 +03:00
if ( ! pdb_set_nt_passwd ( sampass , new_nt_p16 , PDB_CHANGED ) )
2002-01-12 04:55:09 +03:00
return False ;
2004-02-08 11:38:42 +03:00
if ( ! E_deshash ( plaintext , new_lanman_p16 ) ) {
/* E_deshash returns false for 'long' passwords (> 14
DOS chars ) . This allows us to match Win2k , which
does not store a LM hash for these passwords ( which
would reduce the effective password length to 14 */
if ( ! pdb_set_lanman_passwd ( sampass , NULL , PDB_CHANGED ) )
return False ;
} else {
if ( ! pdb_set_lanman_passwd ( sampass , new_lanman_p16 , PDB_CHANGED ) )
return False ;
}
2002-09-25 19:19:00 +04:00
2002-11-02 06:47:48 +03:00
if ( ! pdb_set_plaintext_pw_only ( sampass , plaintext , PDB_CHANGED ) )
2002-09-25 19:19:00 +04:00
return False ;
2002-01-12 04:55:09 +03:00
if ( ! pdb_set_pass_changed_now ( sampass ) )
return False ;
return True ;
}