diff options
-rw-r--r-- | source3/include/proto.h | 4 | ||||
-rw-r--r-- | source3/include/smb.h | 4 | ||||
-rw-r--r-- | source3/passdb/passdb.c | 551 | ||||
-rw-r--r-- | source3/passdb/pdb_smbpasswd.c | 103 | ||||
-rw-r--r-- | source3/rpc_server/srv_samr_nt.c | 4 |
5 files changed, 329 insertions, 337 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h index b18efe0cc2..2d2ea90bdf 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -1618,9 +1618,6 @@ void close_sock(void); int write_sock(void *buffer, int count); int read_reply(struct winbindd_response *response); void free_response(struct winbindd_response *response); -enum nss_status winbindd_request(int req_type, - struct winbindd_request *request, - struct winbindd_response *response); /*The following definitions come from param/loadparm.c */ @@ -1992,7 +1989,6 @@ char* pdb_get_munged_dial (SAM_ACCOUNT *sampass); uint32 pdb_get_unknown3 (SAM_ACCOUNT *sampass); uint32 pdb_get_unknown5 (SAM_ACCOUNT *sampass); uint32 pdb_get_unknown6 (SAM_ACCOUNT *sampass); -void pdb_set_mem_ownership (SAM_ACCOUNT *sampass, BOOL flag); BOOL pdb_set_acct_ctrl (SAM_ACCOUNT *sampass, uint16 flags); BOOL pdb_set_logon_time (SAM_ACCOUNT *sampass, time_t mytime); BOOL pdb_set_logoff_time (SAM_ACCOUNT *sampass, time_t mytime); diff --git a/source3/include/smb.h b/source3/include/smb.h index aa1356d821..c53f0d21e3 100644 --- a/source3/include/smb.h +++ b/source3/include/smb.h @@ -644,8 +644,8 @@ typedef struct typedef struct sam_passwd { - BOOL own_memory; /* do we own the memory allocated for the - pointers in this struct? */ + TALLOC_CTX *mem_ctx; /* used for all dynamically allocated + memory in this struct*/ time_t logon_time; /* logon time */ time_t logoff_time; /* logoff time */ diff --git a/source3/passdb/passdb.c b/source3/passdb/passdb.c index a0b9726a63..6636285b6f 100644 --- a/source3/passdb/passdb.c +++ b/source3/passdb/passdb.c @@ -4,7 +4,7 @@ Password and authentication handling Copyright (C) Jeremy Allison 1996-1998 Copyright (C) Luke Kenneth Casson Leighton 1996-1998 - Copyright (C) Gerald (Jerry) Carter 2000 + Copyright (C) Gerald (Jerry) Carter 2000-2001 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 @@ -21,7 +21,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include <dlfcn.h> #include "includes.h" extern int DEBUGLEVEL; @@ -46,6 +45,9 @@ BOOL initialize_password_db(BOOL reload) char* modulename = lp_passdb_module_path(); + /* This function is unfinished right now, so just + ignore the details and always return True. It is here + only as a placeholder --jerry */ return True; /* load another module? */ @@ -104,7 +106,10 @@ void pdb_init_sam(SAM_ACCOUNT *user) return; ZERO_STRUCTP(user); - + + user->mem_ctx = talloc_init(); + DEBUG(10, ("pdb_init_sam: obtained a talloc context of 0x%x\n", user->mem_ctx)); + user->logon_time = (time_t)0; user->logoff_time = (time_t)-1; user->kickoff_time = (time_t)-1; @@ -125,31 +130,13 @@ void pdb_init_sam(SAM_ACCOUNT *user) ***********************************************************/ void pdb_clear_sam(SAM_ACCOUNT *user) { - /* do we have a SAM_CCOUTN struct to work with? */ if (user == NULL) return; + + /* free upany memory used */ + DEBUG(10, ("pdb_clear_sam: releasing memory. talloc context is 0x%x\n",user->mem_ctx)); + talloc_destroy (user->mem_ctx); - /* do we own the memory? */ - if (user->own_memory) - { - /* clear all pointer members */ - if (user->username) free(user->username); - if (user->full_name) free(user->full_name); - if (user->domain) free(user->domain); - if (user->nt_username) free(user->nt_username); - if (user->home_dir) free(user->home_dir); - if (user->dir_drive) free(user->dir_drive); - if (user->logon_script) free(user->logon_script); - if (user->profile_path) free(user->profile_path); - if (user->acct_desc) free(user->acct_desc); - if (user->workstations) free(user->workstations); - if (user->unknown_str) free(user->unknown_str); - if (user->munged_dial) free(user->munged_dial); - - if (user->lm_pw) free(user->lm_pw); - if (user->nt_pw) free(user->nt_pw); - } - /* now initialize */ pdb_init_sam(user); @@ -541,7 +528,7 @@ BOOL local_lookup_name(const char *c_domain, const char *c_user, DOM_SID *psid, (void)map_username(user); - if(!(pass = sys_getpwnam(user))) { + if(!(pass = Get_Pwnam(user, True))) { /* * Maybe it was a group ? */ @@ -793,97 +780,90 @@ void copy_id21_to_sam_passwd(SAM_ACCOUNT *to, SAM_USER_INFO_21 *from) **************************************************************/ void copy_sam_passwd(SAM_ACCOUNT *to, const SAM_ACCOUNT *from) { - static fstring smb_name=""; - static fstring full_name=""; - static fstring home_dir=""; - static fstring dir_drive=""; - static fstring logon_script=""; - static fstring profile_path=""; - static fstring acct_desc=""; - static fstring workstations=""; - static fstring unknown_str=""; - static fstring munged_dial=""; - static uint8 lm_pw[16], nt_pw[16]; + int len; + + if (!from || !to) return; - if (from == NULL || to == NULL) - return; + pdb_clear_sam (to); - /* we won't own this memory so set the flag. - This will also clear the strings from 'to' */ - pdb_set_mem_ownership (to, False); - + /* copy all non-pointers */ memcpy(to, from, sizeof(*from)); - if (from->username != NULL) - { - fstrcpy(smb_name , from->username); - to->username = smb_name; - } - - if (from->full_name != NULL) - { - fstrcpy(full_name, from->full_name); - to->full_name = full_name; + if (from->username) { + len=strlen(from->username)+1; + to->username = talloc(to->mem_ctx, len); + StrnCpy (to->username, from->username, len-1); } - if (from->home_dir != NULL) - { - fstrcpy(home_dir, from->home_dir); - to->home_dir = home_dir; + if (from->full_name) { + len=strlen(from->full_name)+1; + to->full_name = talloc(to->mem_ctx, len); + StrnCpy (to->full_name, from->full_name, len-1); } - if (from->dir_drive != NULL) - { - fstrcpy(dir_drive , from->dir_drive); - to->dir_drive = dir_drive; + if (from->nt_username) { + len=strlen(from->nt_username)+1; + to->nt_username = talloc(to->mem_ctx, len); + StrnCpy (to->nt_username, from->nt_username, len-1); } - if (from->logon_script != NULL) - { - fstrcpy(logon_script , from->logon_script); - to->logon_script = logon_script; + if (from->profile_path) { + len=strlen(from->profile_path)+1; + to->profile_path = talloc(to->mem_ctx, len); + StrnCpy (to->profile_path, from->profile_path, len-1); } - if (from->profile_path != NULL) - { - fstrcpy(profile_path , from->profile_path); - to->profile_path = profile_path; + if (from->logon_script) { + len=strlen(from->logon_script)+1; + to->logon_script = talloc(to->mem_ctx, len); + StrnCpy (to->logon_script, from->logon_script, len-1); } - if (from->acct_desc != NULL) - { - fstrcpy(acct_desc , from->acct_desc); - to->acct_desc = acct_desc; + if (from->home_dir) { + len=strlen(from->home_dir)+1; + to->home_dir = talloc(to->mem_ctx, len); + StrnCpy (to->home_dir, from->home_dir, len-1); } - - if (from->workstations != NULL) - { - fstrcpy(workstations , from->workstations); - to->workstations = workstations; + + if (from->dir_drive) { + len=strlen(from->dir_drive)+1; + to->dir_drive = talloc(to->mem_ctx, len); + StrnCpy (to->dir_drive, from->dir_drive, len-1); } - - if (from->unknown_str != NULL) - { - fstrcpy(unknown_str , from->unknown_str); - to->unknown_str = unknown_str; + + if (from->workstations) { + len=strlen(from->workstations)+1; + to->workstations = talloc(to->mem_ctx, len); + StrnCpy (to->workstations, from->workstations, len-1); } - - if (from->munged_dial != NULL) - { - fstrcpy(munged_dial , from->munged_dial); - to->munged_dial = munged_dial; + + if (from->acct_desc) { + len=strlen(from->acct_desc)+1; + to->acct_desc = talloc(to->mem_ctx, len); + StrnCpy (to->acct_desc, from->acct_desc, len-1); } - if (from->nt_pw != NULL) - { - memcpy (nt_pw, from->nt_pw, 16); - to->nt_pw = nt_pw; + if (from->munged_dial) { + len=strlen(from->munged_dial)+1; + to->munged_dial = talloc(to->mem_ctx, len); + StrnCpy (to->munged_dial, from->munged_dial, len); + } + + if (from->unknown_str) { + len=strlen(from->unknown_str)+1; + to->unknown_str = talloc(to->mem_ctx, len); + StrnCpy (to->unknown_str, from->unknown_str, len-1); } - if (from->lm_pw != NULL) - { - memcpy (lm_pw, from->lm_pw, 16); - to->lm_pw = lm_pw; + + if (from->nt_pw) { + to->nt_pw = talloc(to->mem_ctx, 16); + memcpy (to->nt_pw, from->nt_pw, 16); + } + + if (from->lm_pw) { + to->lm_pw = talloc(to->mem_ctx, 16); + memcpy (to->lm_pw, from->lm_pw, 16); } return; @@ -944,7 +924,6 @@ account without a valid local system user.\n", user_name); Because the new_sam_pwd only exists in the scope of this function we will not allocate memory for members */ pdb_init_sam (&new_sam_acct); - pdb_set_mem_ownership (&new_sam_acct, False); pdb_set_username (&new_sam_acct, user_name); pdb_set_fullname (&new_sam_acct, pwd->pw_gecos); pdb_set_uid (&new_sam_acct, pwd->pw_uid); @@ -1310,30 +1289,6 @@ uint32 pdb_get_unknown6 (SAM_ACCOUNT *sampass) /********************************************************************* collection of set...() functions for SAM_ACCOUNT_INFO ********************************************************************/ - -/******************************************************************** - The purpose of this flag is to determine whether or not we - should free the memory when we are done. This allows us to - use local static variables for string (reduce the number of - malloc() calls) while still allowing for flexibility of - dynamic objects. - - We always clear the structure even if setting the flag to the - same value. - *******************************************************************/ -void pdb_set_mem_ownership (SAM_ACCOUNT *sampass, BOOL flag) -{ - /* if we have no SAM_ACCOUNT struct or no change, then done */ - if (sampass == NULL) - return; - - /* clear the struct and set the ownership flag */ - pdb_clear_sam (sampass); - sampass->own_memory = flag; - - return; -} - BOOL pdb_set_acct_ctrl (SAM_ACCOUNT *sampass, uint16 flags) { if (!sampass) @@ -1458,250 +1413,332 @@ BOOL pdb_set_group_rid (SAM_ACCOUNT *sampass, uint32 grid) BOOL pdb_set_username (SAM_ACCOUNT *sampass, char *username) { - if (!sampass) - return False; + int len; + + if (!sampass || !sampass->mem_ctx) return False; - if (!sampass->own_memory) - sampass->username = username; - else + if (!username) { - if ( (sampass->username=strdup(username)) == NULL ) - { - DEBUG (0,("pdb_set_username: ERROR - Unable to malloc memory for [%s]\n", username)); - return False; - } + sampass->username = NULL; + return True; + } + + len = strlen(username)+1; + sampass->username = (char*)talloc(sampass->mem_ctx, len); + + if (sampass->username == NULL ) + { + DEBUG (0,("pdb_set_username: ERROR - Unable to talloc memory for [%s]\n", username)); + return False; } + + StrnCpy (sampass->username, username, len-1); return True; } BOOL pdb_set_domain (SAM_ACCOUNT *sampass, char *domain) { - if (!sampass) - return False; + int len; + + if (!sampass || !sampass->mem_ctx) return False; - if (!sampass->own_memory) - sampass->domain = domain; - else + if (!domain) { - if ( (sampass->domain=strdup(domain)) == NULL ) - { - DEBUG (0,("pdb_set_domain: ERROR - Unable to malloc memory for [%s]\n", domain)); - return False; - } + sampass->domain = NULL; + return True; } + len = strlen(domain)+1; + sampass->domain = talloc (sampass->mem_ctx, len); + + if (sampass->domain == NULL ) + { + DEBUG (0,("pdb_set_domain: ERROR - Unable to talloc memory for [%s]\n", domain)); + return False; + } + + StrnCpy (sampass->domain, domain, len-1); + return True; } BOOL pdb_set_nt_username (SAM_ACCOUNT *sampass, char *nt_username) { - if (!sampass) - return False; + int len; + + if (!sampass || !sampass->mem_ctx) return False; - if (!sampass->own_memory) - sampass->nt_username = nt_username; - else + if (!nt_username) { - if ( (sampass->nt_username=strdup(nt_username)) == NULL ) - { - DEBUG (0,("pdb_set_nt_username: ERROR - Unable to malloc memory for [%s]\n", nt_username)); - return False; - } + sampass->nt_username = NULL; + return True; + } + + len = strlen(nt_username)+1; + sampass->nt_username = talloc (sampass->mem_ctx, len); + + if (sampass->nt_username == NULL ) + { + DEBUG (0,("pdb_set_nt_username: ERROR - Unable to talloc memory for [%s]\n", nt_username)); + return False; } + + StrnCpy (sampass->nt_username, nt_username, len-1); return True; } BOOL pdb_set_fullname (SAM_ACCOUNT *sampass, char *fullname) { - if (!sampass) - return False; + int len; + + if (!sampass || !sampass->mem_ctx) return False; - if (!sampass->own_memory) - sampass->full_name = fullname; - else + if (!fullname) { - if ( (sampass->full_name=strdup(fullname)) == NULL ) - { - DEBUG (0,("pdb_set_fullname: ERROR - Unable to malloc memory for [%s]\n", fullname)); - return False; - } + sampass->full_name = NULL; + return True; } + len = strlen(fullname)+1; + sampass->full_name = talloc (sampass->mem_ctx, len); + + if (sampass->full_name == NULL ) + { + DEBUG (0,("pdb_set_fullname: ERROR - Unable to talloc memory for [%s]\n", fullname)); + return False; + } + + StrnCpy (sampass->full_name, fullname, len-1); + return True; } BOOL pdb_set_logon_script (SAM_ACCOUNT *sampass, char *logon_script) { - if (!sampass) - return False; + int len; + + if (!sampass || !sampass->mem_ctx) return False; - if (!sampass->own_memory) - sampass->logon_script = logon_script; - else + if (!logon_script) { - if ( (sampass->logon_script=strdup(logon_script)) == NULL ) - { - DEBUG (0,("pdb_set_logon_script: ERROR - Unable to malloc memory for [%s]\n", logon_script)); - return False; - } + sampass->logon_script = NULL; + return True; } + len = strlen(logon_script)+1; + sampass->logon_script = talloc (sampass->mem_ctx, len); + + if (sampass->logon_script == NULL ) + { + DEBUG (0,("pdb_set_logon_script: ERROR - Unable to talloc memory for [%s]\n", logon_script)); + return False; + } + + StrnCpy (sampass->logon_script, logon_script, len-1); + return True; } BOOL pdb_set_profile_path (SAM_ACCOUNT *sampass, char *profile_path) { - if (!sampass) - return False; + int len; + + if (!sampass || !sampass->mem_ctx) return False; - if (!sampass->own_memory) - sampass->profile_path = profile_path; - else + if (!profile_path) { - if ( (sampass->profile_path=strdup(profile_path)) == NULL ) - { - DEBUG (0,("pdb_set_profile_path: ERROR - Unable to malloc memory for [%s]\n", profile_path)); - return False; - } + sampass->profile_path = NULL; + return True; } + len = strlen(profile_path)+1; + sampass->profile_path = talloc (sampass->mem_ctx, len); + + if (!sampass->profile_path) + { + DEBUG (0,("pdb_set_profile_path: ERROR - Unable to talloc memory for [%s]\n", profile_path)); + return False; + } + + StrnCpy (sampass->profile_path, profile_path, len-1); + return True; } BOOL pdb_set_dir_drive (SAM_ACCOUNT *sampass, char *dir_drive) { - if (!sampass) - return False; + int len; + + if (!sampass || !sampass->mem_ctx) return False; - if (!sampass->own_memory) - sampass->dir_drive = dir_drive; - else + if (!dir_drive) { - if ( (sampass->dir_drive=strdup(dir_drive)) == NULL ) - { - DEBUG (0,("pdb_set_dir_drive: ERROR - Unable to malloc memory for [%s]\n", dir_drive)); - return False; - } + sampass->dir_drive = NULL; + return True; } + len = strlen(dir_drive)+1; + sampass->dir_drive = talloc (sampass->mem_ctx, len); + + if (sampass->dir_drive == NULL ) + { + DEBUG (0,("pdb_set_dir_drive: ERROR - Unable to talloc memory for [%s]\n", dir_drive)); + return False; + } + + StrnCpy (sampass->dir_drive, dir_drive, len-1); + return True; } BOOL pdb_set_homedir (SAM_ACCOUNT *sampass, char *homedir) { - if (!sampass) - return False; + int len; + + if (!sampass || !sampass->mem_ctx) return False; - if (!sampass->own_memory) - sampass->home_dir = homedir; - else + if (!homedir) { - if ( (sampass->home_dir=strdup(homedir)) == NULL ) - { - DEBUG (0,("pdb_set_home_dir: ERROR - Unable to malloc memory for [%s]\n", homedir)); - return False; - } + sampass->home_dir = NULL; + return True; } + len = strlen(homedir)+1; + sampass->home_dir = talloc (sampass->mem_ctx, len); + + if (sampass->home_dir == NULL ) + { + DEBUG (0,("pdb_set_homedir: ERROR - Unable to talloc memory for [%s]\n", homedir)); + return False; + } + + StrnCpy (sampass->home_dir, homedir, len-1); + return True; } BOOL pdb_set_acct_desc (SAM_ACCOUNT *sampass, char *acct_desc) { - if (!sampass) - return False; + int len; + + if (!sampass || !sampass->mem_ctx) return False; - if (!sampass->own_memory) - sampass->acct_desc = acct_desc; - else + if (!acct_desc) { - if ( (sampass->acct_desc=strdup(acct_desc)) == NULL ) - { - DEBUG (0,("pdb_set_acct_desc: ERROR - Unable to malloc memory for [%s]\n", acct_desc)); - return False; - } + sampass->acct_desc = NULL; + return True; + } + + len = strlen(acct_desc)+1; + sampass->acct_desc = talloc (sampass->mem_ctx, len); + + if (sampass->acct_desc == NULL ) + { + DEBUG (0,("pdb_set_acct_desc: ERROR - Unable to talloc memory for [%s]\n", acct_desc)); + return False; } + + StrnCpy (sampass->acct_desc, acct_desc, len-1); return True; } + BOOL pdb_set_workstations (SAM_ACCOUNT *sampass, char *workstations) { - if (!sampass) - return False; + int len; + + if (!sampass || !sampass->mem_ctx) return False; - if (!sampass->own_memory) - sampass->workstations = workstations; - else + if (!workstations) { - if ( (sampass->workstations=strdup(workstations)) == NULL ) - { - DEBUG (0,("pdb_set_workstations: ERROR - Unable to malloc memory for [%s]\n", workstations)); - return False; - } + sampass->workstations = NULL; + return True; } + len = strlen(workstations)+1; + sampass->workstations = talloc (sampass->mem_ctx, len); + + if (sampass->workstations == NULL ) + { + DEBUG (0,("pdb_set_workstations: ERROR - Unable to talloc memory for [%s]\n", workstations)); + return False; + } + + StrnCpy (sampass->workstations, workstations, len-1); + return True; } BOOL pdb_set_munged_dial (SAM_ACCOUNT *sampass, char *munged_dial) { - if (!sampass) - return False; + int len; + + if (!sampass || !sampass->mem_ctx) return False; - if (!sampass->own_memory) - sampass->munged_dial = munged_dial; - else + if (!munged_dial) { - if ( (sampass->munged_dial=strdup(munged_dial)) == NULL ) - { - DEBUG (0,("pdb_set_munged_dial: ERROR - Unable to malloc memory for [%s]\n", munged_dial)); - return False; - } + sampass->munged_dial = NULL; + return True; + } + + len = strlen(munged_dial)+1; + sampass->munged_dial = talloc (sampass->mem_ctx, len); + + if (sampass->munged_dial == NULL ) + { + DEBUG (0,("pdb_set_munged_dial: ERROR - Unable to talloc memory for [%s]\n", munged_dial)); + return False; } + + StrnCpy (sampass->munged_dial, munged_dial, len-1); return True; } BOOL pdb_set_nt_passwd (SAM_ACCOUNT *sampass, uint8 *pwd) { - if ( (!sampass) ||(pwd == NULL) ) - return False; + if (!sampass || !sampass->mem_ctx) return False; - if (!sampass->own_memory) - sampass->nt_pw = pwd; - else + if (!pwd) { - if ((sampass->nt_pw=(uint8*)malloc(sizeof(uint8)*16)) == NULL) - { - DEBUG(0,("pdb_set_nt_passwd: ERROR - out of memory for nt_pw!\n")); - return False; - } - if (!memcpy(sampass->nt_pw, pwd, 16)) - return False; - } + sampass->nt_pw = NULL; + return True; + } + + sampass->nt_pw = talloc (sampass->mem_ctx, 16); + + if (sampass->nt_pw == NULL ) + { + DEBUG (0,("pdb_set_nt_passwd: ERROR - Unable to talloc memory for [%s]\n", pwd)); + return False; + } + + memcpy (sampass->nt_pw, pwd, 16); return True; } BOOL pdb_set_lanman_passwd (SAM_ACCOUNT *sampass, uint8 *pwd) { - if ( (!sampass) ||(pwd == NULL) ) - return False; + if (!sampass || !sampass->mem_ctx) return False; + + if (!pwd) + { + sampass->lm_pw = NULL; + return True; + } - if (!sampass->own_memory) - sampass->lm_pw = pwd; - else + sampass->lm_pw = talloc (sampass->mem_ctx, 16); + + if (sampass->lm_pw == NULL ) { - if ((sampass->lm_pw=(uint8*)malloc(sizeof(uint8)*16)) == NULL) - { - DEBUG(0,("pdb_set_lanman_passwd: ERROR - out of memory for lm_pw!\n")); - return False; - } - if (!memcpy(sampass->lm_pw, pwd, 16)) - return False; - } + DEBUG (0,("pdb_set_lanman_passwd: ERROR - Unable to talloc memory for [%s]\n", pwd)); + return False; + } + + memcpy (sampass->lm_pw, pwd, 16); return True; } diff --git a/source3/passdb/pdb_smbpasswd.c b/source3/passdb/pdb_smbpasswd.c index a814c8da8e..8432a4cc23 100644 --- a/source3/passdb/pdb_smbpasswd.c +++ b/source3/passdb/pdb_smbpasswd.c @@ -3,7 +3,7 @@ * Version 1.9. SMB parameters and setup * Copyright (C) Andrew Tridgell 1992-1998 * Modified by Jeremy Allison 1995. - * Modified by Gerald (Jerry) Carter 2000 + * Modified by Gerald (Jerry) Carter 2000-2001 * * 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 @@ -58,6 +58,7 @@ static void *global_vp; in this module */ static SAM_ACCOUNT global_sam_pass; + enum pwf_access_type { PWF_READ, PWF_UPDATE, PWF_CREATE }; /*************************************************************** @@ -1153,7 +1154,9 @@ Error was %s\n", pwd->smb_name, pfile2, strerror(errno))); } /********************************************************************* - Create a SAM_ACCOUNT from a smb_passwd struct + Create a smb_passwd struct from a SAM_ACCOUNT. + We will not allocate any new memory. The smb_passwd struct + should only stay around as long as the SAM_ACCOUNT does. ********************************************************************/ static BOOL build_smb_pass (struct smb_passwd *smb_pw, SAM_ACCOUNT *sampass) { @@ -1165,58 +1168,17 @@ static BOOL build_smb_pass (struct smb_passwd *smb_pw, SAM_ACCOUNT *sampass) ZERO_STRUCTP (smb_pw); smb_pw->smb_userid = pdb_get_uid(sampass); - smb_pw->smb_name = strdup(pdb_get_username(sampass)); + smb_pw->smb_name = pdb_get_username(sampass); - if ((ptr=pdb_get_lanman_passwd(sampass)) != NULL) - { - if ((smb_pw->smb_passwd=(uint8*)malloc(sizeof(uint8)*16)) == NULL) - { - DEBUG (0,("build_smb_pass: ERROR - Unable to malloc memory!\n")); - return False; - } - memcpy (smb_pw->smb_passwd, ptr, sizeof(uint8)*16); - } + smb_pw->smb_passwd = pdb_get_lanman_passwd(sampass); + smb_pw->smb_nt_passwd = pdb_get_nt_passwd(sampass); - if ((ptr=pdb_get_nt_passwd(sampass)) != NULL) - { - if ((smb_pw->smb_nt_passwd=(uint8*)malloc(sizeof(uint8)*16)) == NULL) - { - DEBUG (0,("build_smb_pass: ERROR - Unable to malloc memory!\n")); - return False; - } - memcpy (smb_pw->smb_nt_passwd, ptr, sizeof(uint8)*16); - } - smb_pw->acct_ctrl = pdb_get_acct_ctrl(sampass); smb_pw->pass_last_set_time = pdb_get_pass_last_set_time(sampass); return True; -} - -/******************************************************************** - clear out memory allocated for pointer members - *******************************************************************/ -static void clear_smb_pass (struct smb_passwd *smb_pw) -{ - - /* valid poiner to begin with? */ - if (smb_pw == NULL) - return; - - /* clear out members */ - if (smb_pw->smb_name) - free (smb_pw->smb_name); - - if (smb_pw->smb_passwd) - free(smb_pw->smb_passwd); - - if (smb_pw->smb_nt_passwd) - free(smb_pw->smb_nt_passwd); - - return; -} - +} /********************************************************************* Create a SAM_ACCOUNT from a smb_passwd struct @@ -1224,29 +1186,26 @@ static void clear_smb_pass (struct smb_passwd *smb_pw) static BOOL build_sam_account (SAM_ACCOUNT *sam_pass, struct smb_passwd *pw_buf) { - struct passwd *pwfile; if (!sam_pass) return (False); - /* make sure that we own the memory here--also clears - any existing members as a side effect */ - pdb_set_mem_ownership(sam_pass, True); - - /* is the user valid? Verify in system password file... - + pdb_clear_sam (sam_pass); + + /* Verify in system password file... FIXME!!! This is where we should look up an internal mapping of allocated uid for machine accounts as well --jerry */ pwfile = sys_getpwnam(pw_buf->smb_name); if (pwfile == NULL) { - DEBUG(0,("build_sam_account: smbpasswd database is corrupt!\n")); - DEBUG(0,("build_sam_account: username %s not in unix passwd database!\n", pw_buf->smb_name)); + DEBUG(0,("build_sam_account: smbpasswd database is corrupt! username %s not in unix passwd database!\n", pw_buf->smb_name)); return False; } - + + /* FIXME!! This doesn't belong here. Should be set in net_sam_logon() + --jerry */ pstrcpy(samlogon_user, pw_buf->smb_name); pdb_set_uid (sam_pass, pwfile->pw_uid); @@ -1272,15 +1231,15 @@ static BOOL build_sam_account (SAM_ACCOUNT *sam_pass, gid_t gid = getegid(); sam_logon_in_ssb = True; - + pstrcpy(str, lp_logon_script()); standard_sub_advanced(-1, pw_buf->smb_name, "", gid, str); pdb_set_logon_script(sam_pass, str); - + pstrcpy(str, lp_logon_path()); standard_sub_advanced(-1, pw_buf->smb_name, "", gid, str); pdb_set_profile_path(sam_pass, str); - + pstrcpy(str, lp_logon_home()); standard_sub_advanced(-1, pw_buf->smb_name, "", gid, str); pdb_set_homedir(sam_pass, str); @@ -1379,8 +1338,12 @@ SAM_ACCOUNT* pdb_getsampwnam (char *username) char *user = NULL; fstring name; - DEBUG(10, ("search by name: %s\n", username)); + DEBUG(10, ("pdb_getsampwnam: search by name: %s\n", username)); +#if 0 /* JERRY - DEBUG */ + sleep (90000); +#endif + /* break the username from the domain if we have been given a string in the form 'DOMAIN\user' */ fstrcpy (name, username); @@ -1424,7 +1387,7 @@ SAM_ACCOUNT* pdb_getsampwnam (char *username) return (NULL); } - DEBUG(10, ("found by name: %s\n", smb_pw->smb_name)); + DEBUG(10, ("pdb_getsampwnam: found by name: %s\n", smb_pw->smb_name)); /* now build the SAM_ACCOUNT */ if (!build_sam_account (&global_sam_pass, smb_pw)) @@ -1440,7 +1403,7 @@ SAM_ACCOUNT* pdb_getsampwuid (uid_t uid) struct smb_passwd *smb_pw; void *fp = NULL; - DEBUG(10, ("search by uid: %d\n", uid)); + DEBUG(10, ("pdb_getsampwuid: search by uid: %d\n", uid)); /* Open the sam password file - not for update. */ fp = startsmbfilepwent(lp_smb_passwd_file(), PWF_READ, &pw_file_lock_depth); @@ -1463,7 +1426,7 @@ SAM_ACCOUNT* pdb_getsampwuid (uid_t uid) return (NULL); } - DEBUG(10, ("found by name: %s\n", smb_pw->smb_name)); + DEBUG(10, ("pdb_getsampwuid: found by name: %s\n", smb_pw->smb_name)); /* now build the SAM_ACCOUNT */ if (!build_sam_account (&global_sam_pass, smb_pw)) @@ -1478,7 +1441,7 @@ SAM_ACCOUNT* pdb_getsampwrid (uint32 rid) struct smb_passwd *smb_pw; void *fp = NULL; - DEBUG(10, ("search by rid: %d\n", rid)); + DEBUG(10, ("pdb_getsampwrid: search by rid: %d\n", rid)); /* Open the sam password file - not for update. */ fp = startsmbfilepwent(lp_smb_passwd_file(), PWF_READ, &pw_file_lock_depth); @@ -1501,7 +1464,7 @@ SAM_ACCOUNT* pdb_getsampwrid (uint32 rid) return (NULL); } - DEBUG(10, ("found by name: %s\n", smb_pw->smb_name)); + DEBUG(10, ("pdb_getsampwrid: found by name: %s\n", smb_pw->smb_name)); /* now build the SAM_ACCOUNT */ if (!build_sam_account (&global_sam_pass, smb_pw)) @@ -1522,9 +1485,6 @@ BOOL pdb_add_sam_account (SAM_ACCOUNT *sampass) /* add the entry */ ret = add_smbfilepwd_entry(&smb_pw); - /* clear memory from smb_passwd */ - clear_smb_pass (&smb_pw); - return (ret); } @@ -1538,10 +1498,7 @@ BOOL pdb_update_sam_account (SAM_ACCOUNT *sampass, BOOL override) /* update the entry */ ret = mod_smbfilepwd_entry(&smb_pw, override); - - /* clear memory from smb_passwd */ - clear_smb_pass (&smb_pw); - + return (ret); } diff --git a/source3/rpc_server/srv_samr_nt.c b/source3/rpc_server/srv_samr_nt.c index e0d6d6056e..7054f85ff9 100644 --- a/source3/rpc_server/srv_samr_nt.c +++ b/source3/rpc_server/srv_samr_nt.c @@ -2060,6 +2060,7 @@ static BOOL set_user_info_21(SAM_USER_INFO_21 *id21, uint32 rid) return False; /* we make a copy so that we can modify stuff */ + ZERO_STRUCT(new_pwd); copy_sam_passwd(&new_pwd, pwd); copy_id21_to_sam_passwd(&new_pwd, id21); @@ -2099,8 +2100,9 @@ static BOOL set_user_info_23(SAM_USER_INFO_23 *id23, uint32 rid) if (pwd == NULL) return False; - acct_ctrl = pdb_get_acct_ctrl(pwd); + acct_ctrl = pdb_get_acct_ctrl(pwd); + ZERO_STRUCT (new_pwd); copy_sam_passwd(&new_pwd, pwd); copy_id23_to_sam_passwd(&new_pwd, id23); |