2008-02-07 16:40:39 +03:00
/*
2002-07-03 11:37:54 +04:00
Unix SMB / CIFS implementation .
SAMR Pipe utility functions .
2008-02-07 16:40:39 +03:00
2002-07-03 11:37:54 +04:00
Copyright ( C ) Luke Kenneth Casson Leighton 1996 - 1998
Copyright ( C ) Gerald ( Jerry ) Carter 2000 - 2001
Copyright ( C ) Andrew Bartlett 2001 - 2002
2002-09-26 22:37:55 +04:00
Copyright ( C ) Stefan ( metze ) Metzmacher 2002
2008-02-27 21:38:48 +03:00
Copyright ( C ) Guenther Deschner 2008
2008-02-07 16:40:39 +03:00
2002-07-03 11:37:54 +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
2007-07-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
2002-07-03 11:37:54 +04:00
( at your option ) any later version .
2008-02-07 16:40:39 +03:00
2002-07-03 11:37:54 +04:00
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
2008-02-07 16:40:39 +03:00
2002-07-03 11:37:54 +04:00
You should have received a copy of the GNU General Public License
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2002-07-03 11:37:54 +04:00
*/
# include "includes.h"
2010-08-03 00:52:00 +04:00
# include "../librpc/gen_ndr/samr.h"
2010-05-18 01:27:30 +04:00
# include "rpc_server/srv_samr_util.h"
2002-07-03 11:37:54 +04:00
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_RPC_SRV
2002-09-26 22:37:55 +04:00
# define STRING_CHANGED (old_string && !new_string) ||\
( ! old_string & & new_string ) | | \
( old_string & & new_string & & ( strcmp ( old_string , new_string ) ! = 0 ) )
2003-11-07 21:32:23 +03:00
# define STRING_CHANGED_NC(s1,s2) ((s1) && !(s2)) ||\
( ! ( s1 ) & & ( s2 ) ) | | \
( ( s1 ) & & ( s2 ) & & ( strcmp ( ( s1 ) , ( s2 ) ) ! = 0 ) )
2009-05-07 19:06:26 +04:00
/*************************************************************
Copies a struct samr_UserInfo2 to a struct samu
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void copy_id2_to_sam_passwd ( struct samu * to ,
struct samr_UserInfo2 * from )
{
struct samr_UserInfo21 i ;
if ( from = = NULL | | to = = NULL ) {
return ;
}
ZERO_STRUCT ( i ) ;
i . fields_present = SAMR_FIELD_COMMENT |
SAMR_FIELD_COUNTRY_CODE |
SAMR_FIELD_CODE_PAGE ;
i . comment = from - > comment ;
i . country_code = from - > country_code ;
i . code_page = from - > code_page ;
copy_id21_to_sam_passwd ( " INFO_2 " , to , & i ) ;
}
/*************************************************************
Copies a struct samr_UserInfo4 to a struct samu
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void copy_id4_to_sam_passwd ( struct samu * to ,
struct samr_UserInfo4 * from )
{
struct samr_UserInfo21 i ;
if ( from = = NULL | | to = = NULL ) {
return ;
}
ZERO_STRUCT ( i ) ;
i . fields_present = SAMR_FIELD_LOGON_HOURS ;
i . logon_hours = from - > logon_hours ;
copy_id21_to_sam_passwd ( " INFO_4 " , to , & i ) ;
}
/*************************************************************
Copies a struct samr_UserInfo6 to a struct samu
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void copy_id6_to_sam_passwd ( struct samu * to ,
struct samr_UserInfo6 * from )
{
struct samr_UserInfo21 i ;
if ( from = = NULL | | to = = NULL ) {
return ;
}
ZERO_STRUCT ( i ) ;
i . fields_present = SAMR_FIELD_ACCOUNT_NAME |
SAMR_FIELD_FULL_NAME ;
i . account_name = from - > account_name ;
i . full_name = from - > full_name ;
copy_id21_to_sam_passwd ( " INFO_6 " , to , & i ) ;
}
/*************************************************************
Copies a struct samr_UserInfo8 to a struct samu
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void copy_id8_to_sam_passwd ( struct samu * to ,
struct samr_UserInfo8 * from )
{
struct samr_UserInfo21 i ;
if ( from = = NULL | | to = = NULL ) {
return ;
}
ZERO_STRUCT ( i ) ;
i . fields_present = SAMR_FIELD_FULL_NAME ;
i . full_name = from - > full_name ;
copy_id21_to_sam_passwd ( " INFO_8 " , to , & i ) ;
}
/*************************************************************
Copies a struct samr_UserInfo10 to a struct samu
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void copy_id10_to_sam_passwd ( struct samu * to ,
struct samr_UserInfo10 * from )
{
struct samr_UserInfo21 i ;
if ( from = = NULL | | to = = NULL ) {
return ;
}
ZERO_STRUCT ( i ) ;
i . fields_present = SAMR_FIELD_HOME_DIRECTORY |
SAMR_FIELD_HOME_DRIVE ;
i . home_directory = from - > home_directory ;
i . home_drive = from - > home_drive ;
copy_id21_to_sam_passwd ( " INFO_10 " , to , & i ) ;
}
/*************************************************************
Copies a struct samr_UserInfo11 to a struct samu
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void copy_id11_to_sam_passwd ( struct samu * to ,
struct samr_UserInfo11 * from )
{
struct samr_UserInfo21 i ;
if ( from = = NULL | | to = = NULL ) {
return ;
}
ZERO_STRUCT ( i ) ;
i . fields_present = SAMR_FIELD_LOGON_SCRIPT ;
i . logon_script = from - > logon_script ;
copy_id21_to_sam_passwd ( " INFO_11 " , to , & i ) ;
}
/*************************************************************
Copies a struct samr_UserInfo12 to a struct samu
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void copy_id12_to_sam_passwd ( struct samu * to ,
struct samr_UserInfo12 * from )
{
struct samr_UserInfo21 i ;
if ( from = = NULL | | to = = NULL ) {
return ;
}
ZERO_STRUCT ( i ) ;
i . fields_present = SAMR_FIELD_PROFILE_PATH ;
i . profile_path = from - > profile_path ;
copy_id21_to_sam_passwd ( " INFO_12 " , to , & i ) ;
}
/*************************************************************
Copies a struct samr_UserInfo13 to a struct samu
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void copy_id13_to_sam_passwd ( struct samu * to ,
struct samr_UserInfo13 * from )
{
struct samr_UserInfo21 i ;
if ( from = = NULL | | to = = NULL ) {
return ;
}
ZERO_STRUCT ( i ) ;
i . fields_present = SAMR_FIELD_DESCRIPTION ;
i . description = from - > description ;
copy_id21_to_sam_passwd ( " INFO_13 " , to , & i ) ;
}
/*************************************************************
Copies a struct samr_UserInfo14 to a struct samu
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void copy_id14_to_sam_passwd ( struct samu * to ,
struct samr_UserInfo14 * from )
{
struct samr_UserInfo21 i ;
if ( from = = NULL | | to = = NULL ) {
return ;
}
ZERO_STRUCT ( i ) ;
i . fields_present = SAMR_FIELD_WORKSTATIONS ;
i . workstations = from - > workstations ;
copy_id21_to_sam_passwd ( " INFO_14 " , to , & i ) ;
}
2009-05-07 23:45:51 +04:00
/*************************************************************
Copies a struct samr_UserInfo16 to a struct samu
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void copy_id16_to_sam_passwd ( struct samu * to ,
struct samr_UserInfo16 * from )
{
struct samr_UserInfo21 i ;
if ( from = = NULL | | to = = NULL ) {
return ;
}
ZERO_STRUCT ( i ) ;
i . fields_present = SAMR_FIELD_ACCT_FLAGS ;
i . acct_flags = from - > acct_flags ;
copy_id21_to_sam_passwd ( " INFO_16 " , to , & i ) ;
}
2009-05-07 19:06:26 +04:00
/*************************************************************
Copies a struct samr_UserInfo17 to a struct samu
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void copy_id17_to_sam_passwd ( struct samu * to ,
struct samr_UserInfo17 * from )
{
struct samr_UserInfo21 i ;
if ( from = = NULL | | to = = NULL ) {
return ;
}
ZERO_STRUCT ( i ) ;
i . fields_present = SAMR_FIELD_ACCT_EXPIRY ;
i . acct_expiry = from - > acct_expiry ;
copy_id21_to_sam_passwd ( " INFO_17 " , to , & i ) ;
}
2008-11-27 19:49:25 +03:00
/*************************************************************
Copies a struct samr_UserInfo18 to a struct samu
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void copy_id18_to_sam_passwd ( struct samu * to ,
struct samr_UserInfo18 * from )
{
struct samr_UserInfo21 i ;
if ( from = = NULL | | to = = NULL ) {
return ;
}
ZERO_STRUCT ( i ) ;
i . fields_present = SAMR_FIELD_EXPIRED_FLAG ;
i . password_expired = from - > password_expired ;
copy_id21_to_sam_passwd ( " INFO_18 " , to , & i ) ;
}
2003-11-07 21:32:23 +03:00
/*************************************************************
2008-02-11 23:09:21 +03:00
Copies a struct samr_UserInfo20 to a struct samu
2003-11-07 21:32:23 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-11 23:09:21 +03:00
void copy_id20_to_sam_passwd ( struct samu * to ,
struct samr_UserInfo20 * from )
2003-11-07 21:32:23 +03:00
{
const char * old_string ;
char * new_string ;
DATA_BLOB mung ;
2008-02-12 01:28:01 +03:00
if ( from = = NULL | | to = = NULL ) {
2003-11-07 21:32:23 +03:00
return ;
2008-02-12 01:28:01 +03:00
}
2008-01-19 04:12:35 +03:00
2008-03-31 22:43:18 +04:00
if ( from - > parameters . array ) {
2003-11-07 21:32:23 +03:00
old_string = pdb_get_munged_dial ( to ) ;
2008-03-31 22:43:18 +04:00
mung = data_blob_const ( from - > parameters . array ,
from - > parameters . length ) ;
2004-05-07 12:42:13 +04:00
new_string = ( mung . length = = 0 ) ?
2008-01-19 04:12:35 +03:00
NULL : base64_encode_data_blob ( talloc_tos ( ) , mung ) ;
2008-02-13 01:30:44 +03:00
DEBUG ( 10 , ( " INFO_20 PARAMETERS: %s -> %s \n " ,
old_string , new_string ) ) ;
if ( STRING_CHANGED_NC ( old_string , new_string ) ) {
pdb_set_munged_dial ( to , new_string , PDB_CHANGED ) ;
}
2003-11-07 21:32:23 +03:00
2007-10-28 21:15:08 +03:00
TALLOC_FREE ( new_string ) ;
2003-11-07 21:32:23 +03:00
}
}
2002-07-03 11:37:54 +04:00
/*************************************************************
2008-02-11 23:09:21 +03:00
Copies a struct samr_UserInfo21 to a struct samu
2002-09-26 22:37:55 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-07-03 11:37:54 +04:00
2008-02-12 00:47:49 +03:00
void copy_id21_to_sam_passwd ( const char * log_prefix ,
struct samu * to ,
2008-02-11 23:09:21 +03:00
struct samr_UserInfo21 * from )
2002-07-03 11:37:54 +04:00
{
2002-09-26 22:37:55 +04:00
time_t unix_time , stored_time ;
const char * old_string , * new_string ;
2008-02-12 00:47:49 +03:00
const char * l ;
2002-07-03 11:37:54 +04:00
2008-02-12 00:47:49 +03:00
if ( from = = NULL | | to = = NULL ) {
2002-07-03 11:37:54 +04:00
return ;
2008-02-12 00:47:49 +03:00
}
if ( log_prefix ) {
l = log_prefix ;
} else {
l = " INFO_21 " ;
}
2004-03-03 00:02:09 +03:00
2008-02-12 01:06:05 +03:00
if ( from - > fields_present & SAMR_FIELD_LAST_LOGON ) {
2008-02-13 01:30:44 +03:00
unix_time = nt_time_to_unix ( from - > last_logon ) ;
2002-09-26 22:37:55 +04:00
stored_time = pdb_get_logon_time ( to ) ;
2008-02-13 01:30:44 +03:00
DEBUG ( 10 , ( " %s SAMR_FIELD_LAST_LOGON: %lu -> %lu \n " , l ,
( long unsigned int ) stored_time ,
( long unsigned int ) unix_time ) ) ;
if ( stored_time ! = unix_time ) {
2002-11-02 06:47:48 +03:00
pdb_set_logon_time ( to , unix_time , PDB_CHANGED ) ;
2008-02-13 01:30:44 +03:00
}
2004-03-03 00:02:09 +03:00
}
2008-02-12 01:06:05 +03:00
if ( from - > fields_present & SAMR_FIELD_LAST_LOGOFF ) {
2008-02-13 01:30:44 +03:00
unix_time = nt_time_to_unix ( from - > last_logoff ) ;
2002-09-26 22:37:55 +04:00
stored_time = pdb_get_logoff_time ( to ) ;
2008-02-13 01:30:44 +03:00
DEBUG ( 10 , ( " %s SAMR_FIELD_LAST_LOGOFF: %lu -> %lu \n " , l ,
( long unsigned int ) stored_time ,
( long unsigned int ) unix_time ) ) ;
if ( stored_time ! = unix_time ) {
2002-11-02 06:47:48 +03:00
pdb_set_logoff_time ( to , unix_time , PDB_CHANGED ) ;
2008-02-13 01:30:44 +03:00
}
2002-09-26 22:37:55 +04:00
}
2004-03-03 00:02:09 +03:00
2008-02-12 01:06:05 +03:00
if ( from - > fields_present & SAMR_FIELD_ACCT_EXPIRY ) {
2008-02-13 01:30:44 +03:00
unix_time = nt_time_to_unix ( from - > acct_expiry ) ;
2002-09-26 22:37:55 +04:00
stored_time = pdb_get_kickoff_time ( to ) ;
2008-02-13 01:30:44 +03:00
DEBUG ( 10 , ( " %s SAMR_FIELD_ACCT_EXPIRY: %lu -> %lu \n " , l ,
( long unsigned int ) stored_time ,
( long unsigned int ) unix_time ) ) ;
if ( stored_time ! = unix_time ) {
2002-11-02 06:47:48 +03:00
pdb_set_kickoff_time ( to , unix_time , PDB_CHANGED ) ;
2008-02-13 01:30:44 +03:00
}
2008-02-07 16:40:39 +03:00
}
2002-07-03 11:37:54 +04:00
2008-02-12 01:06:05 +03:00
if ( from - > fields_present & SAMR_FIELD_LAST_PWD_CHANGE ) {
2008-02-13 01:30:44 +03:00
unix_time = nt_time_to_unix ( from - > last_password_change ) ;
2002-09-26 22:37:55 +04:00
stored_time = pdb_get_pass_last_set_time ( to ) ;
2008-02-13 01:30:44 +03:00
DEBUG ( 10 , ( " %s SAMR_FIELD_LAST_PWD_CHANGE: %lu -> %lu \n " , l ,
( long unsigned int ) stored_time ,
( long unsigned int ) unix_time ) ) ;
if ( stored_time ! = unix_time ) {
2002-11-02 06:47:48 +03:00
pdb_set_pass_last_set_time ( to , unix_time , PDB_CHANGED ) ;
2008-02-13 01:30:44 +03:00
}
2002-09-26 22:37:55 +04:00
}
2008-02-12 01:06:05 +03:00
if ( ( from - > fields_present & SAMR_FIELD_ACCOUNT_NAME ) & &
2008-02-11 23:09:21 +03:00
( from - > account_name . string ) ) {
2002-09-26 22:37:55 +04:00
old_string = pdb_get_username ( to ) ;
2008-02-11 23:09:21 +03:00
new_string = from - > account_name . string ;
2008-02-13 01:30:44 +03:00
DEBUG ( 10 , ( " %s SAMR_FIELD_ACCOUNT_NAME: %s -> %s \n " , l ,
old_string , new_string ) ) ;
if ( STRING_CHANGED ) {
pdb_set_username ( to , new_string , PDB_CHANGED ) ;
}
2002-09-26 22:37:55 +04:00
}
2008-02-12 01:06:05 +03:00
if ( ( from - > fields_present & SAMR_FIELD_FULL_NAME ) & &
2008-02-11 23:09:21 +03:00
( from - > full_name . string ) ) {
2002-09-26 22:37:55 +04:00
old_string = pdb_get_fullname ( to ) ;
2008-02-11 23:09:21 +03:00
new_string = from - > full_name . string ;
2008-02-13 01:30:44 +03:00
DEBUG ( 10 , ( " %s SAMR_FIELD_FULL_NAME: %s -> %s \n " , l ,
old_string , new_string ) ) ;
if ( STRING_CHANGED ) {
pdb_set_fullname ( to , new_string , PDB_CHANGED ) ;
}
2002-09-26 22:37:55 +04:00
}
2008-02-07 16:40:39 +03:00
2008-02-12 01:06:05 +03:00
if ( ( from - > fields_present & SAMR_FIELD_HOME_DIRECTORY ) & &
2008-02-11 23:09:21 +03:00
( from - > home_directory . string ) ) {
2002-09-26 22:37:55 +04:00
old_string = pdb_get_homedir ( to ) ;
2008-02-11 23:09:21 +03:00
new_string = from - > home_directory . string ;
2008-02-13 01:30:44 +03:00
DEBUG ( 10 , ( " %s SAMR_FIELD_HOME_DIRECTORY: %s -> %s \n " , l ,
old_string , new_string ) ) ;
if ( STRING_CHANGED ) {
pdb_set_homedir ( to , new_string , PDB_CHANGED ) ;
}
2002-09-26 22:37:55 +04:00
}
2008-02-12 01:06:05 +03:00
if ( ( from - > fields_present & SAMR_FIELD_HOME_DRIVE ) & &
2008-02-11 23:09:21 +03:00
( from - > home_drive . string ) ) {
2002-09-26 22:37:55 +04:00
old_string = pdb_get_dir_drive ( to ) ;
2008-02-11 23:09:21 +03:00
new_string = from - > home_drive . string ;
2008-02-13 01:30:44 +03:00
DEBUG ( 10 , ( " %s SAMR_FIELD_HOME_DRIVE: %s -> %s \n " , l ,
old_string , new_string ) ) ;
if ( STRING_CHANGED ) {
pdb_set_dir_drive ( to , new_string , PDB_CHANGED ) ;
}
2002-09-26 22:37:55 +04:00
}
2002-07-03 11:37:54 +04:00
2008-02-12 01:06:05 +03:00
if ( ( from - > fields_present & SAMR_FIELD_LOGON_SCRIPT ) & &
2008-02-11 23:09:21 +03:00
( from - > logon_script . string ) ) {
2002-09-26 22:37:55 +04:00
old_string = pdb_get_logon_script ( to ) ;
2008-02-11 23:09:21 +03:00
new_string = from - > logon_script . string ;
2008-02-13 01:30:44 +03:00
DEBUG ( 10 , ( " %s SAMR_FIELD_LOGON_SCRIPT: %s -> %s \n " , l ,
old_string , new_string ) ) ;
if ( STRING_CHANGED ) {
2002-11-02 06:47:48 +03:00
pdb_set_logon_script ( to , new_string , PDB_CHANGED ) ;
2008-02-13 01:30:44 +03:00
}
2002-09-26 22:37:55 +04:00
}
2008-02-12 01:06:05 +03:00
if ( ( from - > fields_present & SAMR_FIELD_PROFILE_PATH ) & &
2008-02-11 23:09:21 +03:00
( from - > profile_path . string ) ) {
2002-09-26 22:37:55 +04:00
old_string = pdb_get_profile_path ( to ) ;
2008-02-11 23:09:21 +03:00
new_string = from - > profile_path . string ;
2008-02-13 01:30:44 +03:00
DEBUG ( 10 , ( " %s SAMR_FIELD_PROFILE_PATH: %s -> %s \n " , l ,
old_string , new_string ) ) ;
if ( STRING_CHANGED ) {
2002-11-02 06:47:48 +03:00
pdb_set_profile_path ( to , new_string , PDB_CHANGED ) ;
2008-02-13 01:30:44 +03:00
}
2002-09-26 22:37:55 +04:00
}
2008-02-07 16:40:39 +03:00
2008-02-12 01:06:05 +03:00
if ( ( from - > fields_present & SAMR_FIELD_DESCRIPTION ) & &
2008-02-11 23:09:21 +03:00
( from - > description . string ) ) {
2002-09-26 22:37:55 +04:00
old_string = pdb_get_acct_desc ( to ) ;
2008-02-11 23:09:21 +03:00
new_string = from - > description . string ;
2008-02-13 01:30:44 +03:00
DEBUG ( 10 , ( " %s SAMR_FIELD_DESCRIPTION: %s -> %s \n " , l ,
old_string , new_string ) ) ;
if ( STRING_CHANGED ) {
pdb_set_acct_desc ( to , new_string , PDB_CHANGED ) ;
}
2002-09-26 22:37:55 +04:00
}
2008-02-07 16:40:39 +03:00
2008-02-12 01:06:05 +03:00
if ( ( from - > fields_present & SAMR_FIELD_WORKSTATIONS ) & &
2008-02-11 23:09:21 +03:00
( from - > workstations . string ) ) {
2002-09-26 22:37:55 +04:00
old_string = pdb_get_workstations ( to ) ;
2008-02-11 23:09:21 +03:00
new_string = from - > workstations . string ;
2008-02-13 01:30:44 +03:00
DEBUG ( 10 , ( " %s SAMR_FIELD_WORKSTATIONS: %s -> %s \n " , l ,
old_string , new_string ) ) ;
if ( STRING_CHANGED ) {
2002-11-02 06:47:48 +03:00
pdb_set_workstations ( to , new_string , PDB_CHANGED ) ;
2008-02-13 01:30:44 +03:00
}
2002-09-26 22:37:55 +04:00
}
2008-02-12 01:06:05 +03:00
if ( ( from - > fields_present & SAMR_FIELD_COMMENT ) & &
2008-02-11 23:09:21 +03:00
( from - > comment . string ) ) {
2006-07-11 22:01:26 +04:00
old_string = pdb_get_comment ( to ) ;
2008-02-11 23:09:21 +03:00
new_string = from - > comment . string ;
2008-02-13 01:30:44 +03:00
DEBUG ( 10 , ( " %s SAMR_FIELD_COMMENT: %s -> %s \n " , l ,
old_string , new_string ) ) ;
if ( STRING_CHANGED ) {
2006-07-11 22:01:26 +04:00
pdb_set_comment ( to , new_string , PDB_CHANGED ) ;
2008-02-13 01:30:44 +03:00
}
2002-09-26 22:37:55 +04:00
}
2008-02-12 01:28:01 +03:00
2008-02-12 01:06:05 +03:00
if ( ( from - > fields_present & SAMR_FIELD_PARAMETERS ) & &
2008-03-31 22:43:18 +04:00
( from - > parameters . array ) ) {
2003-11-07 21:32:23 +03:00
char * newstr ;
2008-03-31 22:43:18 +04:00
DATA_BLOB mung ;
2002-09-26 22:37:55 +04:00
old_string = pdb_get_munged_dial ( to ) ;
2008-03-31 22:43:18 +04:00
mung = data_blob_const ( from - > parameters . array ,
from - > parameters . length ) ;
2004-05-07 12:42:13 +04:00
newstr = ( mung . length = = 0 ) ?
2008-01-19 04:12:35 +03:00
NULL : base64_encode_data_blob ( talloc_tos ( ) , mung ) ;
2008-02-13 01:30:44 +03:00
DEBUG ( 10 , ( " %s SAMR_FIELD_PARAMETERS: %s -> %s \n " , l ,
old_string , newstr ) ) ;
if ( STRING_CHANGED_NC ( old_string , newstr ) ) {
pdb_set_munged_dial ( to , newstr , PDB_CHANGED ) ;
}
2003-11-07 21:32:23 +03:00
2007-10-28 21:15:08 +03:00
TALLOC_FREE ( newstr ) ;
2002-09-26 22:37:55 +04:00
}
2008-02-12 01:28:01 +03:00
2008-02-12 01:06:05 +03:00
if ( from - > fields_present & SAMR_FIELD_RID ) {
2008-02-11 23:09:21 +03:00
if ( from - > rid = = 0 ) {
2008-02-13 01:30:44 +03:00
DEBUG ( 10 , ( " %s: Asked to set User RID to 0 !? Skipping change! \n " , l ) ) ;
2008-02-11 23:09:21 +03:00
} else if ( from - > rid ! = pdb_get_user_rid ( to ) ) {
2008-02-13 01:30:44 +03:00
DEBUG ( 10 , ( " %s SAMR_FIELD_RID: %u -> %u NOT UPDATED! \n " , l ,
pdb_get_user_rid ( to ) , from - > rid ) ) ;
2004-03-03 00:02:09 +03:00
}
2002-09-26 22:37:55 +04:00
}
2008-02-07 16:40:39 +03:00
2008-02-12 01:06:05 +03:00
if ( from - > fields_present & SAMR_FIELD_PRIMARY_GID ) {
2008-02-11 23:09:21 +03:00
if ( from - > primary_gid = = 0 ) {
2008-02-13 01:30:44 +03:00
DEBUG ( 10 , ( " %s: Asked to set Group RID to 0 !? Skipping change! \n " , l ) ) ;
2008-02-11 23:09:21 +03:00
} else if ( from - > primary_gid ! = pdb_get_group_rid ( to ) ) {
2008-02-13 01:30:44 +03:00
DEBUG ( 10 , ( " %s SAMR_FIELD_PRIMARY_GID: %u -> %u \n " , l ,
pdb_get_group_rid ( to ) , from - > primary_gid ) ) ;
pdb_set_group_sid_from_rid ( to ,
from - > primary_gid , PDB_CHANGED ) ;
2004-03-03 00:02:09 +03:00
}
2002-09-26 22:37:55 +04:00
}
2008-02-07 16:40:39 +03:00
2008-02-12 01:06:05 +03:00
if ( from - > fields_present & SAMR_FIELD_ACCT_FLAGS ) {
2008-02-13 01:30:44 +03:00
DEBUG ( 10 , ( " %s SAMR_FIELD_ACCT_FLAGS: %08X -> %08X \n " , l ,
pdb_get_acct_ctrl ( to ) , from - > acct_flags ) ) ;
2008-02-11 23:09:21 +03:00
if ( from - > acct_flags ! = pdb_get_acct_ctrl ( to ) ) {
2009-05-09 02:03:50 +04:00
/* You cannot autolock an unlocked account via
* setuserinfo calls , so make sure to remove the
* ACB_AUTOLOCK bit here - gd */
if ( ( from - > acct_flags & ACB_AUTOLOCK ) & &
! ( pdb_get_acct_ctrl ( to ) & ACB_AUTOLOCK ) ) {
from - > acct_flags & = ~ ACB_AUTOLOCK ;
}
2008-02-13 01:30:44 +03:00
if ( ! ( from - > acct_flags & ACB_AUTOLOCK ) & &
( pdb_get_acct_ctrl ( to ) & ACB_AUTOLOCK ) ) {
2004-06-16 22:05:47 +04:00
/* We're unlocking a previously locked user. Reset bad password counts.
Patch from Jianliang Lu . < Jianliang . Lu @ getronics . com > */
pdb_set_bad_password_count ( to , 0 , PDB_CHANGED ) ;
pdb_set_bad_password_time ( to , 0 , PDB_CHANGED ) ;
}
2008-02-11 23:09:21 +03:00
pdb_set_acct_ctrl ( to , from - > acct_flags , PDB_CHANGED ) ;
2004-03-03 00:02:09 +03:00
}
2002-11-02 06:47:48 +03:00
}
2008-02-12 01:17:45 +03:00
if ( from - > fields_present & SAMR_FIELD_LOGON_HOURS ) {
2007-11-27 22:22:58 +03:00
char oldstr [ 44 ] ; /* hours strings are 42 bytes. */
char newstr [ 44 ] ;
2008-02-13 01:30:44 +03:00
DEBUG ( 15 , ( " %s SAMR_FIELD_LOGON_HOURS (units_per_week): %08X -> %08X \n " , l ,
pdb_get_logon_divs ( to ) , from - > logon_hours . units_per_week ) ) ;
2008-02-12 01:17:45 +03:00
if ( from - > logon_hours . units_per_week ! = pdb_get_logon_divs ( to ) ) {
2008-02-13 01:30:44 +03:00
pdb_set_logon_divs ( to ,
from - > logon_hours . units_per_week , PDB_CHANGED ) ;
2004-03-03 00:02:09 +03:00
}
2002-07-03 11:37:54 +04:00
2008-02-13 01:30:44 +03:00
DEBUG ( 15 , ( " %s SAMR_FIELD_LOGON_HOURS (units_per_week/8): %08X -> %08X \n " , l ,
pdb_get_hours_len ( to ) ,
from - > logon_hours . units_per_week / 8 ) ) ;
2008-02-12 01:17:45 +03:00
if ( from - > logon_hours . units_per_week / 8 ! = pdb_get_hours_len ( to ) ) {
2008-02-13 01:30:44 +03:00
pdb_set_hours_len ( to ,
from - > logon_hours . units_per_week / 8 , PDB_CHANGED ) ;
2004-03-03 00:02:09 +03:00
}
2002-09-26 22:37:55 +04:00
2008-02-13 01:30:44 +03:00
DEBUG ( 15 , ( " %s SAMR_FIELD_LOGON_HOURS (bits): %s -> %s \n " , l ,
pdb_get_hours ( to ) , from - > logon_hours . bits ) ) ;
2005-06-25 00:25:18 +04:00
pdb_sethexhours ( oldstr , pdb_get_hours ( to ) ) ;
2008-02-12 01:17:45 +03:00
pdb_sethexhours ( newstr , from - > logon_hours . bits ) ;
2005-06-25 00:25:18 +04:00
if ( ! strequal ( oldstr , newstr ) ) {
2008-02-12 01:17:45 +03:00
pdb_set_hours ( to , from - > logon_hours . bits , PDB_CHANGED ) ;
2004-12-24 03:08:15 +03:00
}
2002-11-02 06:47:48 +03:00
}
2008-02-12 01:17:45 +03:00
2008-02-12 01:06:05 +03:00
if ( from - > fields_present & SAMR_FIELD_BAD_PWD_COUNT ) {
2008-02-13 01:30:44 +03:00
DEBUG ( 10 , ( " %s SAMR_FIELD_BAD_PWD_COUNT: %08X -> %08X \n " , l ,
pdb_get_bad_password_count ( to ) , from - > bad_password_count ) ) ;
2004-03-03 00:02:09 +03:00
if ( from - > bad_password_count ! = pdb_get_bad_password_count ( to ) ) {
2008-02-13 01:30:44 +03:00
pdb_set_bad_password_count ( to ,
from - > bad_password_count , PDB_CHANGED ) ;
2004-03-03 00:02:09 +03:00
}
2002-11-02 06:47:48 +03:00
}
2002-09-26 22:37:55 +04:00
2008-02-12 01:06:05 +03:00
if ( from - > fields_present & SAMR_FIELD_NUM_LOGONS ) {
2008-02-13 01:30:44 +03:00
DEBUG ( 10 , ( " %s SAMR_FIELD_NUM_LOGONS: %08X -> %08X \n " , l ,
pdb_get_logon_count ( to ) , from - > logon_count ) ) ;
2004-03-03 00:02:09 +03:00
if ( from - > logon_count ! = pdb_get_logon_count ( to ) ) {
pdb_set_logon_count ( to , from - > logon_count , PDB_CHANGED ) ;
}
2003-09-19 03:53:48 +04:00
}
2006-09-20 21:25:46 +04:00
/* If the must change flag is set, the last set time goes to zero.
2008-02-07 16:40:39 +03:00
the must change and can change fields also do , but they are
2006-09-20 21:25:46 +04:00
calculated from policy , not set from the wire */
2008-02-12 01:06:05 +03:00
if ( from - > fields_present & SAMR_FIELD_EXPIRED_FLAG ) {
2008-02-13 01:30:44 +03:00
DEBUG ( 10 , ( " %s SAMR_FIELD_EXPIRED_FLAG: %02X \n " , l ,
from - > password_expired ) ) ;
2008-11-27 19:49:25 +03:00
if ( from - > password_expired ! = 0 ) {
2008-02-07 16:40:39 +03:00
pdb_set_pass_last_set_time ( to , 0 , PDB_CHANGED ) ;
2006-09-20 21:25:46 +04:00
} else {
2008-06-09 19:45:39 +04:00
/* A subtlety here: some windows commands will
clear the expired flag even though it ' s not
set , and we don ' t want to reset the time
in these caess . " net user /dom <user> /active:y "
for example , to clear an autolocked acct .
We must check to see if it ' s expired first . jmcd */
2008-11-27 19:49:25 +03:00
uint32_t pwd_max_age = 0 ;
time_t now = time ( NULL ) ;
2009-07-14 01:53:49 +04:00
pdb_get_account_policy ( PDB_POLICY_MAX_PASSWORD_AGE , & pwd_max_age ) ;
2008-11-27 19:49:25 +03:00
if ( pwd_max_age = = ( uint32_t ) - 1 | | pwd_max_age = = 0 ) {
pwd_max_age = get_time_t_max ( ) ;
}
2008-06-09 19:45:39 +04:00
stored_time = pdb_get_pass_last_set_time ( to ) ;
2008-11-27 19:49:25 +03:00
/* we will only *set* a pwdlastset date when
a ) the last pwdlastset time was 0 ( user was forced to
change password ) .
b ) the users password has not expired . gd . */
if ( ( stored_time = = 0 ) | |
( ( now - stored_time ) > pwd_max_age ) ) {
pdb_set_pass_last_set_time ( to , now , PDB_CHANGED ) ;
}
2005-08-10 20:02:32 +04:00
}
2002-09-26 22:37:55 +04:00
}
2002-07-03 11:37:54 +04:00
}
/*************************************************************
2008-02-11 23:09:21 +03:00
Copies a struct samr_UserInfo23 to a struct samu
2002-09-26 22:37:55 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-07-03 11:37:54 +04:00
2008-02-11 23:09:21 +03:00
void copy_id23_to_sam_passwd ( struct samu * to ,
struct samr_UserInfo23 * from )
2002-07-03 11:37:54 +04:00
{
2008-02-13 01:30:44 +03:00
if ( from = = NULL | | to = = NULL ) {
2002-07-03 11:37:54 +04:00
return ;
2008-02-13 01:30:44 +03:00
}
2004-03-03 00:02:09 +03:00
2008-02-12 00:47:49 +03:00
copy_id21_to_sam_passwd ( " INFO 23 " , to , & from - > info ) ;
2002-07-03 11:37:54 +04:00
}
2006-06-06 18:18:12 +04:00
2008-11-27 19:49:25 +03:00
/*************************************************************
Copies a struct samr_UserInfo24 to a struct samu
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void copy_id24_to_sam_passwd ( struct samu * to ,
struct samr_UserInfo24 * from )
{
struct samr_UserInfo21 i ;
if ( from = = NULL | | to = = NULL ) {
return ;
}
ZERO_STRUCT ( i ) ;
i . fields_present = SAMR_FIELD_EXPIRED_FLAG ;
i . password_expired = from - > password_expired ;
copy_id21_to_sam_passwd ( " INFO_24 " , to , & i ) ;
}
2006-06-06 18:18:12 +04:00
/*************************************************************
2008-02-11 23:09:21 +03:00
Copies a struct samr_UserInfo25 to a struct samu
2006-06-06 18:18:12 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-11 23:09:21 +03:00
void copy_id25_to_sam_passwd ( struct samu * to ,
struct samr_UserInfo25 * from )
2006-06-06 18:18:12 +04:00
{
2008-02-12 00:47:49 +03:00
if ( from = = NULL | | to = = NULL ) {
2006-06-06 18:18:12 +04:00
return ;
2008-02-12 00:47:49 +03:00
}
2006-06-06 18:18:12 +04:00
2008-02-12 00:47:49 +03:00
copy_id21_to_sam_passwd ( " INFO_25 " , to , & from - > info ) ;
2006-06-06 18:18:12 +04:00
}
2008-11-27 19:49:25 +03:00
/*************************************************************
Copies a struct samr_UserInfo26 to a struct samu
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void copy_id26_to_sam_passwd ( struct samu * to ,
struct samr_UserInfo26 * from )
{
struct samr_UserInfo21 i ;
if ( from = = NULL | | to = = NULL ) {
return ;
}
ZERO_STRUCT ( i ) ;
i . fields_present = SAMR_FIELD_EXPIRED_FLAG ;
i . password_expired = from - > password_expired ;
copy_id21_to_sam_passwd ( " INFO_26 " , to , & i ) ;
}