diff options
author | Jean-François Micouleau <jfm@samba.org> | 2001-05-04 15:44:27 +0000 |
---|---|---|
committer | Jean-François Micouleau <jfm@samba.org> | 2001-05-04 15:44:27 +0000 |
commit | f35157f39293f9fa240a28642c41708b55d301c8 (patch) | |
tree | cd0eb02e9b316899d2cfb9b8cc2784ad739c60a5 /source3/passdb | |
parent | 1f7a451c1e059b5a86e1e78debd582579aa7bcb7 (diff) | |
download | samba-f35157f39293f9fa240a28642c41708b55d301c8.tar.gz samba-f35157f39293f9fa240a28642c41708b55d301c8.tar.xz samba-f35157f39293f9fa240a28642c41708b55d301c8.zip |
Big cleanup of passdb and backends.
I did some basic tests but I have probably broken something. Notably the
password changing. So don't cry ;-)
J.F.
(This used to be commit a4a4c02b12f030a3b9e6225b999c90689dfc4719)
Diffstat (limited to 'source3/passdb')
-rw-r--r-- | source3/passdb/passdb.c | 733 | ||||
-rw-r--r-- | source3/passdb/pdb_smbpasswd.c | 222 | ||||
-rw-r--r-- | source3/passdb/pdb_tdb.c | 97 |
3 files changed, 434 insertions, 618 deletions
diff --git a/source3/passdb/passdb.c b/source3/passdb/passdb.c index 50bf5e73f3..3df58b2e7a 100644 --- a/source3/passdb/passdb.c +++ b/source3/passdb/passdb.c @@ -98,49 +98,66 @@ static void pdb_init_dispinfo(struct sam_disp_info *user) } /************************************************************* - initialises a struct sam_passwd. + alloc memory and initialises a struct sam_passwd. ************************************************************/ -void pdb_init_sam(SAM_ACCOUNT *user) +BOOL pdb_init_sam(SAM_ACCOUNT **user) { - if (user == NULL) - return; + if (*user != NULL) { + DEBUG(0,("pdb_init_sam: SAM_ACCOUNT was non NULL\n")); +#if 0 + smb_panic("NULL pointer passed to pdb_init_sam\n"); +#endif + return False; + } - ZERO_STRUCTP(user); - - user->mem_ctx = talloc_init(); - DEBUG(10, ("pdb_init_sam: obtained a talloc context of 0x%x\n", - (unsigned)user->mem_ctx)); - - user->logon_time = (time_t)0; - user->logoff_time = (time_t)-1; - user->kickoff_time = (time_t)-1; - user->pass_last_set_time = (time_t)-1; - user->pass_can_change_time = (time_t)-1; - user->pass_must_change_time = (time_t)-1; - - user->unknown_3 = 0x00ffffff; /* don't know */ - user->logon_divs = 168; /* hours per week */ - user->hours_len = 21; /* 21 times 8 bits = 168 */ - memset(user->hours, 0xff, user->hours_len); /* available at all hours */ - user->unknown_5 = 0x00000000; /* don't know */ - user->unknown_6 = 0x000004ec; /* don't know */ + *user=(SAM_ACCOUNT *)malloc(sizeof(SAM_ACCOUNT)); + + if (*user==NULL) { + DEBUG(0,("pdb_init_sam: error while allocating memory\n")); + return False; + } + + ZERO_STRUCTP(*user); + + (*user)->logon_time = (time_t)0; + (*user)->logoff_time = (time_t)-1; + (*user)->kickoff_time = (time_t)-1; + (*user)->pass_last_set_time = (time_t)-1; + (*user)->pass_can_change_time = (time_t)-1; + (*user)->pass_must_change_time = (time_t)-1; + + (*user)->unknown_3 = 0x00ffffff; /* don't know */ + (*user)->logon_divs = 168; /* hours per week */ + (*user)->hours_len = 21; /* 21 times 8 bits = 168 */ + memset((*user)->hours, 0xff, (*user)->hours_len); /* available at all hours */ + (*user)->unknown_5 = 0x00000000; /* don't know */ + (*user)->unknown_6 = 0x000004ec; /* don't know */ + + return True; } /************************************************************ - free all pointer members and then reinit the SAM_ACCOUNT + free the SAM_ACCOUNT and the NT/LM hashes. ***********************************************************/ -void pdb_clear_sam(SAM_ACCOUNT *user) +BOOL pdb_clear_sam(SAM_ACCOUNT *user) { - if (user == NULL) - return; + if (user == NULL) { + DEBUG(0,("pdb_clear_sam: SAM_ACCOUNT was NULL\n")); +#if 0 + smb_panic("NULL pointer passed to pdb_clear_sam\n"); +#endif + return False; + } - /* free upany memory used */ - DEBUG(10, ("pdb_clear_sam: releasing memory. talloc context is 0x%x\n",(unsigned)user->mem_ctx)); - talloc_destroy (user->mem_ctx); - - /* now initialize */ - pdb_init_sam(user); + if (user->nt_pw) + free(user->nt_pw); + + if (user->lm_pw) + free(user->lm_pw); + + free(user); + return True; } @@ -455,9 +472,10 @@ BOOL local_lookup_rid(uint32 rid, char *name, enum SID_NAME_USE *psid_name_use) } } else { - gid_t gid; + gid_t gid=-1; struct group *gr; - + GROUP_MAP map; + DOM_SID sid; /* * Don't try to convert the rid to a name if running * in appliance mode @@ -466,11 +484,30 @@ BOOL local_lookup_rid(uint32 rid, char *name, enum SID_NAME_USE *psid_name_use) if (lp_hide_local_users()) return False; - gid = pdb_user_rid_to_gid(rid); - gr = getgrgid(gid); + /* + * First try the TDB. If the RID exists and is mapped to a unix group, + * return the NT name and the type. + */ + + sid_copy(&sid, &global_sam_sid); + sid_append_rid(&sid, rid); + if (get_group_map_from_sid(sid, &map) && map.gid!=-1) { + *psid_name_use = map.sid_name_use; + fstrcpy(name, map.nt_name); - *psid_name_use = SID_NAME_ALIAS; + DEBUG(5,("local_lookup_rid: found NT group %s mapped to Unix gid %u for rid %u\n", + name, (unsigned int)map.gid, (unsigned int)rid )); + if(!getgrgid(gid)) + return False; + else + return True; + } + + *psid_name_use = SID_NAME_ALIAS; + gid = pdb_user_rid_to_gid(rid); + + gr = getgrgid(gid); DEBUG(5,("local_local_rid: looking up gid %u %s\n", (unsigned int)gid, gr ? "succeeded" : "failed" )); @@ -481,8 +518,7 @@ BOOL local_lookup_rid(uint32 rid, char *name, enum SID_NAME_USE *psid_name_use) fstrcpy( name, gr->gr_name); - DEBUG(5,("local_lookup_rid: found group %s for rid %u\n", name, - (unsigned int)rid )); + DEBUG(5,("local_lookup_rid: found group %s for rid %u\n", name, (unsigned int)rid )); } return True; @@ -529,21 +565,34 @@ BOOL local_lookup_name(const char *c_domain, const char *c_user, DOM_SID *psid, (void)map_username(user); - if(!(pass = Get_Pwnam(user, True))) { + if((pass = Get_Pwnam(user, True))) { + sid_append_rid( &local_sid, pdb_uid_to_user_rid(pass->pw_uid)); + *psid_name_use = SID_NAME_USER; + } else { /* * Maybe it was a group ? */ - struct group *grp = getgrnam(user); + GROUP_MAP map; + struct group *grp = NULL; - if(!grp) - return False; + /* It can be a mapped group */ + if (get_group_map_from_ntname(user, &map) && map.gid!=-1) { - sid_append_rid( &local_sid, pdb_gid_to_group_rid(grp->gr_gid)); - *psid_name_use = SID_NAME_ALIAS; - } else { + grp=getgrgid(map.gid); + if (!grp) + return False; - sid_append_rid( &local_sid, pdb_uid_to_user_rid(pass->pw_uid)); - *psid_name_use = SID_NAME_USER; + sid_copy(&local_sid, &map.sid); + *psid_name_use = map.sid_name_use; + } else { + /* It wasn't mapped, it can be a Unix group */ + grp=getgrnam(user); + if(!grp) + return False; + + sid_append_rid( &local_sid, pdb_gid_to_group_rid(grp->gr_gid)); + *psid_name_use = SID_NAME_ALIAS; + } } sid_copy( psid, &local_sid); @@ -661,13 +710,10 @@ BOOL local_sid_to_gid(gid_t *pgid, DOM_SID *psid, enum SID_NAME_USE *name_type) return True; } -static void select_name(fstring *string, char **name, const UNISTR2 *from) +static void select_name(pstring string, const UNISTR2 *from) { if (from->buffer != 0) - { - unistr2_to_ascii(*string, from, sizeof(*string)); - *name = *string; - } + unistr2_to_ascii(string, from, sizeof(*string)); } /************************************************************* @@ -675,16 +721,6 @@ static void select_name(fstring *string, char **name, const UNISTR2 *from) **************************************************************/ void copy_id23_to_sam_passwd(SAM_ACCOUNT *to, SAM_USER_INFO_23 *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; if (from == NULL || to == NULL) return; @@ -696,16 +732,16 @@ void copy_id23_to_sam_passwd(SAM_ACCOUNT *to, SAM_USER_INFO_23 *from) to->pass_can_change_time = nt_time_to_unix(&from->pass_can_change_time); to->pass_must_change_time = nt_time_to_unix(&from->pass_must_change_time); - select_name(&smb_name , &to->username , &from->uni_user_name ); - select_name(&full_name , &to->full_name , &from->uni_full_name ); - select_name(&home_dir , &to->home_dir , &from->uni_home_dir ); - select_name(&dir_drive , &to->dir_drive , &from->uni_dir_drive ); - select_name(&logon_script, &to->logon_script, &from->uni_logon_script); - select_name(&profile_path, &to->profile_path, &from->uni_profile_path); - select_name(&acct_desc , &to->acct_desc , &from->uni_acct_desc ); - select_name(&workstations, &to->workstations, &from->uni_workstations); - select_name(&unknown_str , &to->unknown_str , &from->uni_unknown_str ); - select_name(&munged_dial , &to->munged_dial , &from->uni_munged_dial ); + select_name(to->username , &from->uni_user_name ); + select_name(to->full_name , &from->uni_full_name ); + select_name(to->home_dir , &from->uni_home_dir ); + select_name(to->dir_drive , &from->uni_dir_drive ); + select_name(to->logon_script, &from->uni_logon_script); + select_name(to->profile_path, &from->uni_profile_path); + select_name(to->acct_desc , &from->uni_acct_desc ); + select_name(to->workstations, &from->uni_workstations); + select_name(to->unknown_str , &from->uni_unknown_str ); + select_name(to->munged_dial , &from->uni_munged_dial ); to->user_rid = from->user_rid; to->group_rid = from->group_rid; @@ -726,17 +762,6 @@ void copy_id23_to_sam_passwd(SAM_ACCOUNT *to, SAM_USER_INFO_23 *from) **************************************************************/ void copy_id21_to_sam_passwd(SAM_ACCOUNT *to, SAM_USER_INFO_21 *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; - if (from == NULL || to == NULL) return; @@ -747,16 +772,16 @@ void copy_id21_to_sam_passwd(SAM_ACCOUNT *to, SAM_USER_INFO_21 *from) to->pass_can_change_time = nt_time_to_unix(&from->pass_can_change_time); to->pass_must_change_time = nt_time_to_unix(&from->pass_must_change_time); - select_name(&smb_name , &to->username , &from->uni_user_name ); - select_name(&full_name , &to->full_name , &from->uni_full_name ); - select_name(&home_dir , &to->home_dir , &from->uni_home_dir ); - select_name(&dir_drive , &to->dir_drive , &from->uni_dir_drive ); - select_name(&logon_script, &to->logon_script, &from->uni_logon_script); - select_name(&profile_path, &to->profile_path, &from->uni_profile_path); - select_name(&acct_desc , &to->acct_desc , &from->uni_acct_desc ); - select_name(&workstations, &to->workstations, &from->uni_workstations); - select_name(&unknown_str , &to->unknown_str , &from->uni_unknown_str ); - select_name(&munged_dial , &to->munged_dial , &from->uni_munged_dial ); + select_name(to->username , &from->uni_user_name ); + select_name(to->full_name , &from->uni_full_name ); + select_name(to->home_dir , &from->uni_home_dir ); + select_name(to->dir_drive , &from->uni_dir_drive ); + select_name(to->logon_script, &from->uni_logon_script); + select_name(to->profile_path, &from->uni_profile_path); + select_name(to->acct_desc , &from->uni_acct_desc ); + select_name(to->workstations, &from->uni_workstations); + select_name(to->unknown_str , &from->uni_unknown_str ); + select_name(to->munged_dial , &from->uni_munged_dial ); to->user_rid = from->user_rid; to->group_rid = from->group_rid; @@ -781,93 +806,9 @@ 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) { - int len; - if (!from || !to) return; - pdb_clear_sam (to); - - /* copy all non-pointers */ - memcpy(to, from, sizeof(*from)); - - if (from->username) { - len=strlen(from->username)+1; - to->username = talloc(to->mem_ctx, len); - StrnCpy (to->username, from->username, len-1); - } - - 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->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->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->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->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->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->workstations) { - len=strlen(from->workstations)+1; - to->workstations = talloc(to->mem_ctx, len); - StrnCpy (to->workstations, from->workstations, len-1); - } - - 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->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->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; + memcpy(to, from, sizeof(SAM_ACCOUNT)); } /************************************************************* @@ -886,8 +827,8 @@ BOOL local_password_change(char *user_name, int local_flags, char *msg_str, size_t msg_str_len) { struct passwd *pwd = NULL; - SAM_ACCOUNT *sam_pass; - SAM_ACCOUNT new_sam_acct; + SAM_ACCOUNT *sam_pass=NULL; + SAM_ACCOUNT *new_sam_acct=NULL; uchar new_p16[16]; uchar new_nt_p16[16]; @@ -912,62 +853,60 @@ account without a valid local system user.\n", user_name); nt_lm_owf_gen(new_passwd, new_nt_p16, new_p16); /* Get the smb passwd entry for this user */ - sam_pass = pdb_getsampwnam(user_name); - if (sam_pass == NULL) - { - if(!(local_flags & LOCAL_ADD_USER)) - { + pdb_init_sam(&sam_pass); + if(!pdb_getsampwnam(sam_pass, user_name)) { + pdb_clear_sam(sam_pass); + return False; + } + + if (sam_pass == NULL) { + if(!(local_flags & LOCAL_ADD_USER)) { slprintf(err_str, err_str_len-1,"Failed to find entry for user %s.\n", user_name); + pdb_clear_sam(sam_pass); return False; } /* create the SAM_ACCOUNT struct and call pdb_add_sam_account. 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_username (&new_sam_acct, user_name); - pdb_set_fullname (&new_sam_acct, pwd->pw_gecos); - pdb_set_uid (&new_sam_acct, pwd->pw_uid); - pdb_set_gid (&new_sam_acct, pwd->pw_gid); - pdb_set_pass_last_set_time(&new_sam_acct, time(NULL)); - pdb_set_profile_path (&new_sam_acct, lp_logon_path()); - pdb_set_homedir (&new_sam_acct, lp_logon_home()); - pdb_set_dir_drive (&new_sam_acct, lp_logon_drive()); - pdb_set_logon_script (&new_sam_acct, lp_logon_script()); + pdb_init_sam(&new_sam_acct); + 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); + pdb_set_gid(new_sam_acct, pwd->pw_gid); + pdb_set_pass_last_set_time(new_sam_acct, time(NULL)); + pdb_set_profile_path(new_sam_acct, lp_logon_path()); + pdb_set_homedir(new_sam_acct, lp_logon_home()); + pdb_set_dir_drive(new_sam_acct, lp_logon_drive()); + pdb_set_logon_script(new_sam_acct, lp_logon_script()); /* set account flags */ - pdb_set_acct_ctrl(&new_sam_acct,((local_flags & LOCAL_TRUST_ACCOUNT) ? ACB_WSTRUST : ACB_NORMAL) ); + pdb_set_acct_ctrl(new_sam_acct,((local_flags & LOCAL_TRUST_ACCOUNT) ? ACB_WSTRUST : ACB_NORMAL) ); + if (local_flags & LOCAL_DISABLE_USER) - { - pdb_set_acct_ctrl (&new_sam_acct, pdb_get_acct_ctrl(&new_sam_acct)|ACB_DISABLED); - } + pdb_set_acct_ctrl (new_sam_acct, pdb_get_acct_ctrl(new_sam_acct)|ACB_DISABLED); + if (local_flags & LOCAL_SET_NO_PASSWORD) - { - pdb_set_acct_ctrl (&new_sam_acct, pdb_get_acct_ctrl(&new_sam_acct)|ACB_PWNOTREQ); - } - else - { + pdb_set_acct_ctrl (new_sam_acct, pdb_get_acct_ctrl(new_sam_acct)|ACB_PWNOTREQ); + else { /* set the passwords here. if we get to here it means we have a valid, active account */ - pdb_set_lanman_passwd (&new_sam_acct, new_p16); - pdb_set_nt_passwd (&new_sam_acct, new_nt_p16); + pdb_set_lanman_passwd (new_sam_acct, new_p16); + pdb_set_nt_passwd (new_sam_acct, new_nt_p16); } - - - if (pdb_add_sam_account(&new_sam_acct)) - { + + pdb_clear_sam(sam_pass); + + if (pdb_add_sam_account(new_sam_acct)) { slprintf(msg_str, msg_str_len-1, "Added user %s.\n", user_name); - pdb_clear_sam (&new_sam_acct); + pdb_clear_sam(new_sam_acct); return True; - } - else - { + } else { slprintf(err_str, err_str_len-1, "Failed to add entry for user %s.\n", user_name); + pdb_clear_sam(new_sam_acct); return False; } - } - else - { + } else { /* the entry already existed */ local_flags &= ~LOCAL_ADD_USER; } @@ -978,25 +917,21 @@ account without a valid local system user.\n", user_name); */ if(local_flags & LOCAL_DISABLE_USER) - { pdb_set_acct_ctrl (sam_pass, pdb_get_acct_ctrl(sam_pass)|ACB_DISABLED); - } else if (local_flags & LOCAL_ENABLE_USER) - { - if(pdb_get_lanman_passwd(sam_pass) == NULL) { + if(pdb_get_lanman_passwd(sam_pass) == NULL) { pdb_set_lanman_passwd (sam_pass, new_p16); pdb_set_nt_passwd (sam_pass, new_nt_p16); } pdb_set_acct_ctrl (sam_pass, pdb_get_acct_ctrl(sam_pass)&(~ACB_DISABLED)); - } else if (local_flags & LOCAL_SET_NO_PASSWORD) - { + } else if (local_flags & LOCAL_SET_NO_PASSWORD) { pdb_set_acct_ctrl (sam_pass, pdb_get_acct_ctrl(sam_pass)|ACB_PWNOTREQ); /* This is needed to preserve ACB_PWNOTREQ in mod_smbfilepwd_entry */ pdb_set_lanman_passwd (sam_pass, NULL); pdb_set_nt_passwd (sam_pass, NULL); - } + } else { /* @@ -1015,20 +950,19 @@ account without a valid local system user.\n", user_name); pdb_set_nt_passwd (sam_pass, new_nt_p16); } - if(local_flags & LOCAL_DELETE_USER) - { - if (!pdb_delete_sam_account(user_name)) - { + if(local_flags & LOCAL_DELETE_USER) { + if (!pdb_delete_sam_account(user_name)) { slprintf(err_str,err_str_len-1, "Failed to delete entry for user %s.\n", user_name); + pdb_clear_sam(sam_pass); return False; } slprintf(msg_str, msg_str_len-1, "Deleted user %s.\n", user_name); } else { - if(!pdb_update_sam_account(sam_pass, True)) - { + if(!pdb_update_sam_account(sam_pass, True)) { slprintf(err_str, err_str_len-1, "Failed to modify entry for user %s.\n", user_name); + pdb_clear_sam(sam_pass); return False; } if(local_flags & LOCAL_DISABLE_USER) @@ -1039,6 +973,7 @@ account without a valid local system user.\n", user_name); slprintf(msg_str, msg_str_len-1, "User %s password set to none.\n", user_name); } + pdb_clear_sam(sam_pass); return True; } @@ -1412,333 +1347,182 @@ BOOL pdb_set_group_rid (SAM_ACCOUNT *sampass, uint32 grid) return True; } -BOOL pdb_set_username (SAM_ACCOUNT *sampass, char *username) -{ - int len; - - if (!sampass || !sampass->mem_ctx) return False; - - if (!username) - { - 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)); +/********************************************************************* + set the user's UNIX name + ********************************************************************/ +BOOL pdb_set_username(SAM_ACCOUNT *sampass, char *username) +{ + if (!sampass || !username) return False; - } - - StrnCpy (sampass->username, username, len-1); + + StrnCpy (sampass->username, username, strlen(username)); return True; } -BOOL pdb_set_domain (SAM_ACCOUNT *sampass, char *domain) -{ - int len; - - if (!sampass || !sampass->mem_ctx) return False; - - if (!domain) - { - 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)); +/********************************************************************* + set the domain name + ********************************************************************/ +BOOL pdb_set_domain(SAM_ACCOUNT *sampass, char *domain) +{ + if (!sampass || !domain) return False; - } - - StrnCpy (sampass->domain, domain, len-1); + + StrnCpy (sampass->domain, domain, strlen(domain)); return True; } -BOOL pdb_set_nt_username (SAM_ACCOUNT *sampass, char *nt_username) +/********************************************************************* + set the user's NT name + ********************************************************************/ +BOOL pdb_set_nt_username(SAM_ACCOUNT *sampass, char *nt_username) { - int len; - - if (!sampass || !sampass->mem_ctx) return False; - - if (!nt_username) - { - 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)); + if (!sampass || !nt_username) return False; - } - - StrnCpy (sampass->nt_username, nt_username, len-1); + + StrnCpy (sampass->nt_username, nt_username, strlen(nt_username)); return True; } -BOOL pdb_set_fullname (SAM_ACCOUNT *sampass, char *fullname) +/********************************************************************* + set the user's full name + ********************************************************************/ +BOOL pdb_set_fullname(SAM_ACCOUNT *sampass, char *fullname) { - int len; - - if (!sampass || !sampass->mem_ctx) return False; - - if (!fullname) - { - 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)); + if (!sampass || !fullname) return False; - } - - StrnCpy (sampass->full_name, fullname, len-1); + + StrnCpy (sampass->full_name, fullname, strlen(fullname)); return True; } -BOOL pdb_set_logon_script (SAM_ACCOUNT *sampass, char *logon_script) +/********************************************************************* + set the user's logon script + ********************************************************************/ +BOOL pdb_set_logon_script(SAM_ACCOUNT *sampass, char *logon_script) { - int len; - - if (!sampass || !sampass->mem_ctx) return False; - - if (!logon_script) - { - 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)); + if (!sampass || !logon_script) return False; - } - - StrnCpy (sampass->logon_script, logon_script, len-1); + + StrnCpy (sampass->logon_script, logon_script, strlen(logon_script)); return True; } +/********************************************************************* + set the user's profile path + ********************************************************************/ BOOL pdb_set_profile_path (SAM_ACCOUNT *sampass, char *profile_path) { - int len; - - if (!sampass || !sampass->mem_ctx) return False; - - if (!profile_path) - { - 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)); + if (!sampass || !profile_path) return False; - } - StrnCpy (sampass->profile_path, profile_path, len-1); + StrnCpy (sampass->profile_path, profile_path, strlen(profile_path)); return True; } +/********************************************************************* + set the user's directory drive + ********************************************************************/ BOOL pdb_set_dir_drive (SAM_ACCOUNT *sampass, char *dir_drive) { - int len; - - if (!sampass || !sampass->mem_ctx) return False; - - if (!dir_drive) - { - 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)); + if (!sampass || !dir_drive) return False; - } - - StrnCpy (sampass->dir_drive, dir_drive, len-1); + + StrnCpy (sampass->dir_drive, dir_drive, strlen(dir_drive)); return True; } +/********************************************************************* + set the user's home directory + ********************************************************************/ BOOL pdb_set_homedir (SAM_ACCOUNT *sampass, char *homedir) { - int len; - - if (!sampass || !sampass->mem_ctx) return False; - - if (!homedir) - { - 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)); + if (!sampass || !homedir) return False; - } - StrnCpy (sampass->home_dir, homedir, len-1); + StrnCpy (sampass->home_dir, homedir, strlen(homedir)); return True; } +/********************************************************************* + set the user's account description + ********************************************************************/ BOOL pdb_set_acct_desc (SAM_ACCOUNT *sampass, char *acct_desc) { - int len; - - if (!sampass || !sampass->mem_ctx) return False; - - if (!acct_desc) - { - 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)); + if (!sampass || !acct_desc) return False; - } - StrnCpy (sampass->acct_desc, acct_desc, len-1); + StrnCpy (sampass->acct_desc, acct_desc, strlen(acct_desc)); return True; } +/********************************************************************* + set the user's workstation allowed list + ********************************************************************/ BOOL pdb_set_workstations (SAM_ACCOUNT *sampass, char *workstations) { - int len; - - if (!sampass || !sampass->mem_ctx) return False; + if (!sampass || !workstations) return False; - if (!workstations) - { - 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); + StrnCpy (sampass->workstations, workstations, strlen(workstations)); return True; } +/********************************************************************* + set the user's dial string + ********************************************************************/ BOOL pdb_set_munged_dial (SAM_ACCOUNT *sampass, char *munged_dial) { - int len; - - if (!sampass || !sampass->mem_ctx) return False; + if (!sampass || !munged_dial) return False; - if (!munged_dial) - { - 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); + StrnCpy (sampass->munged_dial, munged_dial, strlen(munged_dial)); return True; } +/********************************************************************* + set the user's NT hash + ********************************************************************/ BOOL pdb_set_nt_passwd (SAM_ACCOUNT *sampass, uint8 *pwd) { - if (!sampass || !sampass->mem_ctx) return False; - - if (!pwd) - { - sampass->nt_pw = NULL; - return True; - } + if (!sampass || !pwd) return False; - 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; - } + if (sampass->nt_pw!=NULL) + DEBUG(0,("pdb_set_nt_passwd: NT hash non NULL overwritting ?\n")); + else + sampass->nt_pw=(unsigned char *)malloc(sizeof(unsigned char)*16); + if (sampass->nt_pw==NULL) + return False; + memcpy (sampass->nt_pw, pwd, 16); return True; } +/********************************************************************* + set the user's LM hash + ********************************************************************/ BOOL pdb_set_lanman_passwd (SAM_ACCOUNT *sampass, uint8 *pwd) { - if (!sampass || !sampass->mem_ctx) return False; + if (!sampass || !*pwd) return False; - if (!pwd) - { - sampass->lm_pw = NULL; - return True; - } - - sampass->lm_pw = talloc (sampass->mem_ctx, 16); - - if (sampass->lm_pw == NULL ) - { - DEBUG (0,("pdb_set_lanman_passwd: ERROR - Unable to talloc memory for [%s]\n", pwd)); - return False; - } + if (sampass->lm_pw!=NULL) + DEBUG(0,("pdb_set_nt_passwd: LM hash non NULL overwritting ?\n")); + else + sampass->lm_pw=(unsigned char *)malloc(sizeof(unsigned char)*16); + if (sampass->lm_pw==NULL) + return False; + memcpy (sampass->lm_pw, pwd, 16); return True; @@ -1773,7 +1557,7 @@ BOOL pdb_set_unknown_6 (SAM_ACCOUNT *sampass, uint32 unkn) BOOL pdb_set_hours (SAM_ACCOUNT *sampass, uint8 *hours) { - if (!sampass || !sampass->mem_ctx) return False; + if (!sampass) return False; if (!hours) { @@ -1785,4 +1569,3 @@ BOOL pdb_set_hours (SAM_ACCOUNT *sampass, uint8 *hours) return True; } - diff --git a/source3/passdb/pdb_smbpasswd.c b/source3/passdb/pdb_smbpasswd.c index 57253d9b78..3679bd1319 100644 --- a/source3/passdb/pdb_smbpasswd.c +++ b/source3/passdb/pdb_smbpasswd.c @@ -56,7 +56,7 @@ static void *global_vp; /* static memory area used by all passdb search functions in this module */ -static SAM_ACCOUNT global_sam_pass; +/*static SAM_ACCOUNT global_sam_pass;*/ enum pwf_access_type { PWF_READ, PWF_UPDATE, PWF_CREATE }; @@ -1163,16 +1163,16 @@ static BOOL build_smb_pass (struct smb_passwd *smb_pw, SAM_ACCOUNT *sampass) if (sampass == NULL) return False; - ZERO_STRUCTP (smb_pw); + ZERO_STRUCTP(smb_pw); - smb_pw->smb_userid = pdb_get_uid(sampass); - smb_pw->smb_name = pdb_get_username(sampass); + smb_pw->smb_userid=pdb_get_uid(sampass); + smb_pw->smb_name=pdb_get_username(sampass); - smb_pw->smb_passwd = pdb_get_lanman_passwd(sampass); - smb_pw->smb_nt_passwd = pdb_get_nt_passwd(sampass); + smb_pw->smb_passwd=pdb_get_lanman_passwd(sampass); + smb_pw->smb_nt_passwd=pdb_get_nt_passwd(sampass); - smb_pw->acct_ctrl = pdb_get_acct_ctrl(sampass); - smb_pw->pass_last_set_time = pdb_get_pass_last_set_time(sampass); + smb_pw->acct_ctrl=pdb_get_acct_ctrl(sampass); + smb_pw->pass_last_set_time=pdb_get_pass_last_set_time(sampass); return True; @@ -1181,23 +1181,21 @@ static BOOL build_smb_pass (struct smb_passwd *smb_pw, SAM_ACCOUNT *sampass) /********************************************************************* Create a SAM_ACCOUNT from a smb_passwd struct ********************************************************************/ -static BOOL build_sam_account (SAM_ACCOUNT *sam_pass, - struct smb_passwd *pw_buf) +static BOOL build_sam_account(SAM_ACCOUNT *sam_pass, struct smb_passwd *pw_buf) { - struct passwd *pwfile; + struct passwd *pwfile; - if (!sam_pass) - return (False); - - pdb_clear_sam (sam_pass); + if (sam_pass==NULL) { + DEBUG(5,("build_sam_account: SAM_ACCOUNT is NULL\n")); + return False; + } /* 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) - { + if (pwfile == NULL) { DEBUG(0,("build_sam_account: smbpasswd database is corrupt! username %s not in unix passwd database!\n", pw_buf->smb_name)); return False; } @@ -1206,17 +1204,25 @@ static BOOL build_sam_account (SAM_ACCOUNT *sam_pass, --jerry */ pstrcpy(samlogon_user, pw_buf->smb_name); - pdb_set_uid (sam_pass, pwfile->pw_uid); - pdb_set_gid (sam_pass, pwfile->pw_gid); - pdb_set_user_rid (sam_pass, pdb_uid_to_user_rid (pdb_get_uid(sam_pass)) ); - pdb_set_username (sam_pass, pw_buf->smb_name); - pdb_set_nt_passwd (sam_pass, pw_buf->smb_nt_passwd); + pdb_set_uid (sam_pass, pwfile->pw_uid); + pdb_set_gid (sam_pass, pwfile->pw_gid); + pdb_set_fullname(sam_pass, pwfile->pw_gecos); + + pdb_set_user_rid(sam_pass, pdb_uid_to_user_rid (pwfile->pw_uid)); + + /* should check the group mapping here instead of static mappig. JFM */ + pdb_set_group_rid(sam_pass, pdb_gid_to_group_rid(pwfile->pw_gid)); + + pdb_set_username (sam_pass, pw_buf->smb_name); + pdb_set_nt_passwd (sam_pass, pw_buf->smb_nt_passwd); pdb_set_lanman_passwd (sam_pass, pw_buf->smb_passwd); - pdb_set_acct_ctrl (sam_pass, pw_buf->acct_ctrl); + pdb_set_acct_ctrl (sam_pass, pw_buf->acct_ctrl); pdb_set_pass_last_set_time (sam_pass, pw_buf->pass_last_set_time); pdb_set_pass_can_change_time (sam_pass, pw_buf->pass_last_set_time); - pdb_set_domain (sam_pass, lp_workgroup()); + pdb_set_domain (sam_pass, lp_workgroup()); + pdb_set_dir_drive (sam_pass, lp_logon_drive()); + /* FIXME!! What should this be set to? New smb.conf parameter maybe? max password age? For now, we'll use the current time + 21 days. --jerry */ @@ -1241,17 +1247,9 @@ static BOOL build_sam_account (SAM_ACCOUNT *sam_pass, pstrcpy(str, lp_logon_home()); standard_sub_advanced(-1, pw_buf->smb_name, "", gid, str); pdb_set_homedir(sam_pass, str); - - pdb_set_fullname(sam_pass, pwfile->pw_gecos); - - /* set other user information that we have */ - pdb_set_group_rid (sam_pass, pdb_gid_to_group_rid(pdb_get_gid(&global_sam_pass)) ); - pdb_set_dir_drive (sam_pass, lp_logon_drive()); - + sam_logon_in_ssb = False; - } - else - { + } else { /* lkclXXXX this is OBSERVED behaviour by NT PDCs, enforced here. */ pdb_set_group_rid (sam_pass, DOMAIN_GROUP_RID_USERS); } @@ -1295,31 +1293,34 @@ void pdb_endsampwent (void) } /***************************************************************** - pdb_getsampwent() uses a static memory ares (returning a pointer - to this) for all instances. This is identical behavior to the - getpwnam() call. If the caller wishes to save the SAM_ACCOUNT - struct, it should make a copy immediately after calling this - function. ****************************************************************/ -SAM_ACCOUNT* pdb_getsampwent (void) +BOOL pdb_getsampwent(SAM_ACCOUNT *user) { - struct smb_passwd *pw_buf; - - + struct smb_passwd *pw_buf=NULL; + DEBUG(5,("pdb_getsampwent\n")); + if (user==NULL) { + DEBUG(5,("pdb_getsampwent: user is NULL\n")); +#if 0 + smb_panic("NULL pointer passed to pdb_getsampwent\n"); +#endif + return False; + } + /* do we have an entry? */ pw_buf = getsmbfilepwent(global_vp); if (pw_buf == NULL) - return NULL; + return False; - /* build the SAM_ACCOUNT entry from the smb_passwd struct. - This will also clear out the previous SAM_ACCOUNT fields */ - if (!build_sam_account (&global_sam_pass, pw_buf)) - return NULL; + /* build the SAM_ACCOUNT entry from the smb_passwd struct. */ + if (!build_sam_account(user, pw_buf)) + return False; + + DEBUG(5,("pdb_getsampwent:done\n")); /* success */ - return &global_sam_pass; + return True; } @@ -1328,13 +1329,13 @@ SAM_ACCOUNT* pdb_getsampwent (void) call getpwnam() for unix account information until we have found the correct entry ***************************************************************/ -SAM_ACCOUNT* pdb_getsampwnam (char *username) +BOOL pdb_getsampwnam(SAM_ACCOUNT *sam_acct, char *username) { - struct smb_passwd *smb_pw; - void *fp = NULL; - char *domain = NULL; - char *user = NULL; - fstring name; + struct smb_passwd *smb_pw; + void *fp = NULL; + char *domain = NULL; + char *user = NULL; + fstring name; DEBUG(10, ("pdb_getsampwnam: search by name: %s\n", username)); @@ -1345,8 +1346,7 @@ SAM_ACCOUNT* pdb_getsampwnam (char *username) /* break the username from the domain if we have been given a string in the form 'DOMAIN\user' */ fstrcpy (name, username); - if ((user=strchr(name, '\\')) != NULL) - { + if ((user=strchr(name, '\\')) != NULL) { domain = name; *user = '\0'; user++; @@ -1354,18 +1354,17 @@ SAM_ACCOUNT* pdb_getsampwnam (char *username) /* if a domain was specified and it wasn't ours then there is no chance of matching */ - if ( (domain) && (!StrCaseCmp(domain, lp_workgroup())) ) - return (NULL); + if ( domain && !StrCaseCmp(domain, lp_workgroup()) ) + return False; /* startsmbfilepwent() is used here as we don't want to lookup the UNIX account in the local system password file until we have a match. */ fp = startsmbfilepwent(lp_smb_passwd_file(), PWF_READ, &pw_file_lock_depth); - if (fp == NULL) - { + if (fp == NULL) { DEBUG(0, ("unable to open passdb database.\n")); - return NULL; + return False; } /* if we have a domain name, then we should map it to a UNIX @@ -1381,35 +1380,40 @@ SAM_ACCOUNT* pdb_getsampwnam (char *username) /* did we locate the username in smbpasswd */ if (smb_pw == NULL) - { - return (NULL); - } + return False; DEBUG(10, ("pdb_getsampwnam: found by name: %s\n", smb_pw->smb_name)); + + if (!sam_acct) { + DEBUG(10,("pdb_getsampwnam:SAM_ACCOUNT is NULL\n")); +#if 0 + smb_panic("NULL pointer passed to pdb_getsampwnam\n"); +#endif + return False; + } /* now build the SAM_ACCOUNT */ - if (!build_sam_account (&global_sam_pass, smb_pw)) - return NULL; + if (!build_sam_account(sam_acct, smb_pw)) + return False; /* success */ - return (&global_sam_pass); + return True; } -SAM_ACCOUNT* pdb_getsampwuid (uid_t uid) +BOOL pdb_getsampwuid (SAM_ACCOUNT *sam_acct, uid_t uid) { - struct smb_passwd *smb_pw; - void *fp = NULL; + struct smb_passwd *smb_pw; + void *fp = NULL; 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); - if (fp == NULL) - { + if (fp == NULL) { DEBUG(0, ("unable to open passdb database.\n")); - return NULL; + return False; } while ( ((smb_pw=getsmbfilepwent(fp)) != NULL) && (smb_pw->smb_userid != uid) ) @@ -1417,37 +1421,41 @@ SAM_ACCOUNT* pdb_getsampwuid (uid_t uid) endsmbfilepwent(fp, &pw_file_lock_depth); - /* did we locate the username in smbpasswd */ if (smb_pw == NULL) - { - return (NULL); - } + return False; DEBUG(10, ("pdb_getsampwuid: found by name: %s\n", smb_pw->smb_name)); + if (!sam_acct) { + DEBUG(10,("pdb_getsampwuid:SAM_ACCOUNT is NULL\n")); +#if 0 + smb_panic("NULL pointer passed to pdb_getsampwuid\n"); +#endif + return False; + } + /* now build the SAM_ACCOUNT */ - if (!build_sam_account (&global_sam_pass, smb_pw)) - return NULL; + if (!build_sam_account(sam_acct, smb_pw)) + return False; /* success */ - return (&global_sam_pass); + return True; } -SAM_ACCOUNT* pdb_getsampwrid (uint32 rid) +BOOL pdb_getsampwrid(SAM_ACCOUNT *sam_acct,uint32 rid) { - struct smb_passwd *smb_pw; - void *fp = NULL; + struct smb_passwd *smb_pw; + void *fp = NULL; 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); - if (fp == NULL) - { + if (fp == NULL) { DEBUG(0, ("unable to open passdb database.\n")); - return NULL; + return False; } while ( ((smb_pw=getsmbfilepwent(fp)) != NULL) && (pdb_uid_to_user_rid(smb_pw->smb_userid) != rid) ) @@ -1458,51 +1466,57 @@ SAM_ACCOUNT* pdb_getsampwrid (uint32 rid) /* did we locate the username in smbpasswd */ if (smb_pw == NULL) - { - return (NULL); - } + return False; DEBUG(10, ("pdb_getsampwrid: found by name: %s\n", smb_pw->smb_name)); + if (!sam_acct) { + DEBUG(10,("pdb_getsampwrid:SAM_ACCOUNT is NULL\n")); +#if 0 + smb_panic("NULL pointer passed to pdb_getsampwrid\n"); +#endif + return False; + } + /* now build the SAM_ACCOUNT */ - if (!build_sam_account (&global_sam_pass, smb_pw)) - return NULL; + if (!build_sam_account (sam_acct, smb_pw)) + return False; /* success */ - return (&global_sam_pass); + return True; } -BOOL pdb_add_sam_account (SAM_ACCOUNT *sampass) +BOOL pdb_add_sam_account(SAM_ACCOUNT *sampass) { - struct smb_passwd smb_pw; - BOOL ret; + struct smb_passwd smb_pw; /* convert the SAM_ACCOUNT */ build_smb_pass(&smb_pw, sampass); /* add the entry */ - ret = add_smbfilepwd_entry(&smb_pw); + if(!add_smbfilepwd_entry(&smb_pw)) + return False; - return (ret); + return True; } -BOOL pdb_update_sam_account (SAM_ACCOUNT *sampass, BOOL override) +BOOL pdb_update_sam_account(SAM_ACCOUNT *sampass, BOOL override) { - struct smb_passwd smb_pw; - BOOL ret; + struct smb_passwd smb_pw; /* convert the SAM_ACCOUNT */ build_smb_pass(&smb_pw, sampass); /* update the entry */ - ret = mod_smbfilepwd_entry(&smb_pw, override); + if(!mod_smbfilepwd_entry(&smb_pw, override)) + return False; - return (ret); + return True; } BOOL pdb_delete_sam_account (char* username) { - return ( del_smbfilepwd_entry(username) ); + return del_smbfilepwd_entry(username); } #else diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 8db8b2e60d..0bf8ca2da5 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -40,7 +40,7 @@ struct tdb_enum_info }; static struct tdb_enum_info global_tdb_ent; -static SAM_ACCOUNT global_sam_pass; +/*static SAM_ACCOUNT global_sam_pass;*/ /********************************************************************** Intialize a SAM_ACCOUNT struct from a BYTE buffer of size len @@ -79,7 +79,6 @@ static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, uint8 *buf, *nt_pw_ptr; uint32 len = 0; uint32 lmpwlen, ntpwlen, hourslen; - /* unpack the buffer into variables */ len = tdb_unpack (buf, buflen, TDB_FORMAT_STRING, @@ -376,7 +375,7 @@ void pdb_endsampwent(void) /***************************************************************** Get one SAM_ACCOUNT from the TDB (next in line) *****************************************************************/ -SAM_ACCOUNT* pdb_getsampwent(void) +BOOL pdb_getsampwent(SAM_ACCOUNT *user) { TDB_DATA data; struct passwd *pw; @@ -385,6 +384,11 @@ SAM_ACCOUNT* pdb_getsampwent(void) char *prefix = USERPREFIX; int prefixlen = strlen (prefix); + if (user==NULL) { + DEBUG(0,("pdb_get_sampwent: SAM_ACCOUNT is NULL.\n")); + return False; + } + /* skip all RID entries */ while ((global_tdb_ent.key.dsize != 0) && (strncmp (global_tdb_ent.key.dptr, prefix, prefixlen))) /* increment to next in line */ @@ -394,56 +398,55 @@ SAM_ACCOUNT* pdb_getsampwent(void) if(global_tdb_ent.passwd_tdb == NULL) { DEBUG(0,("pdb_get_sampwent: Bad TDB Context pointer.\n")); - return NULL; + return False; } data = tdb_fetch (global_tdb_ent.passwd_tdb, global_tdb_ent.key); if (!data.dptr) { DEBUG(5,("pdb_getsampwent: database entry not found.\n")); - return NULL; + return False; } /* unpack the buffer */ - pdb_clear_sam (&global_sam_pass); - if (!init_sam_from_buffer (&global_sam_pass, data.dptr, data.dsize)) + if (!init_sam_from_buffer (user, data.dptr, data.dsize)) { DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); - return NULL; + return False; } /* validate the account and fill in UNIX uid and gid. sys_getpwnam() is used instaed of Get_Pwnam() as we do not need to try case permutations */ - if ((pw=sys_getpwnam(pdb_get_username(&global_sam_pass))) == NULL) + if ((pw=sys_getpwnam(pdb_get_username(user))) == NULL) { DEBUG(0,("pdb_getsampwent: getpwnam(%s) return NULL. User does not exist!\n", - pdb_get_username(&global_sam_pass))); - return NULL; + pdb_get_username(user))); + return False; } uid = pw->pw_uid; gid = pw->pw_gid; - pdb_set_uid (&global_sam_pass, uid); - pdb_set_gid (&global_sam_pass, gid); + pdb_set_uid (user, uid); + pdb_set_gid (user, gid); /* 21 days from present */ - pdb_set_pass_must_change_time(&global_sam_pass, time(NULL)+1814400); + pdb_set_pass_must_change_time(user, time(NULL)+1814400); - standard_sub_advanced(-1, pdb_get_username(&global_sam_pass), "", gid, pdb_get_logon_script(&global_sam_pass)); - standard_sub_advanced(-1, pdb_get_username(&global_sam_pass), "", gid, pdb_get_profile_path(&global_sam_pass)); - standard_sub_advanced(-1, pdb_get_username(&global_sam_pass), "", gid, pdb_get_homedir(&global_sam_pass)); + standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_logon_script(user)); + standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_profile_path(user)); + standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_homedir(user)); /* increment to next in line */ global_tdb_ent.key = tdb_nextkey (global_tdb_ent.passwd_tdb, global_tdb_ent.key); - return (&global_sam_pass); + return True; } /****************************************************************** Lookup a name in the SAM TDB ******************************************************************/ -SAM_ACCOUNT* pdb_getsampwnam (char *sname) +BOOL pdb_getsampwnam (SAM_ACCOUNT *user, char *sname) { TDB_CONTEXT *pwd_tdb; TDB_DATA data, key; @@ -453,7 +456,13 @@ SAM_ACCOUNT* pdb_getsampwnam (char *sname) fstring name; uid_t uid; gid_t gid; - + + + if (user==NULL) { + DEBUG(0,("pdb_getsampwnam: SAM_ACCOUNT is NULL.\n")); + return False; + } + fstrcpy (name, sname); strlower (name); pstrcpy (tdbfile, lp_private_dir()); @@ -478,53 +487,58 @@ SAM_ACCOUNT* pdb_getsampwnam (char *sname) DEBUG(5,("pdb_getsampwnam (TDB): error fetching database.\n")); DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); tdb_close (pwd_tdb); - return NULL; + return False; } /* unpack the buffer */ - pdb_clear_sam (&global_sam_pass); - if (!init_sam_from_buffer (&global_sam_pass, data.dptr, data.dsize)) + /*pdb_clear_sam (&global_sam_pass);*/ + if (!init_sam_from_buffer (user, data.dptr, data.dsize)) { DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); - return NULL; + return False; } /* validate the account and fill in UNIX uid and gid. sys_getpwnam() is used instaed of Get_Pwnam() as we do not need to try case permutations */ - if ((pw=sys_getpwnam(pdb_get_username(&global_sam_pass))) == NULL) + if ((pw=sys_getpwnam(pdb_get_username(user))) == NULL) { DEBUG(0,("pdb_getsampwent: getpwnam(%s) return NULL. User does not exist!\n", - pdb_get_username(&global_sam_pass))); - return NULL; + pdb_get_username(user))); + return False; } uid = pw->pw_uid; gid = pw->pw_gid; - pdb_set_uid (&global_sam_pass, uid); - pdb_set_gid (&global_sam_pass, gid); + pdb_set_uid (user, uid); + pdb_set_gid (user, gid); /* 21 days from present */ - pdb_set_pass_must_change_time(&global_sam_pass, time(NULL)+1814400); + pdb_set_pass_must_change_time(user, time(NULL)+1814400); - standard_sub_advanced(-1, pdb_get_username(&global_sam_pass), "", gid, pdb_get_logon_script(&global_sam_pass)); - standard_sub_advanced(-1, pdb_get_username(&global_sam_pass), "", gid, pdb_get_profile_path(&global_sam_pass)); - standard_sub_advanced(-1, pdb_get_username(&global_sam_pass), "", gid, pdb_get_homedir(&global_sam_pass)); + standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_logon_script(user)); + standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_profile_path(user)); + standard_sub_advanced(-1, pdb_get_username(user), "", gid, pdb_get_homedir(user)); /* cleanup */ tdb_close (pwd_tdb); - return (&global_sam_pass); + return True; } /*************************************************************************** Search by uid **************************************************************************/ -SAM_ACCOUNT* pdb_getsampwuid (uid_t uid) +BOOL pdb_getsampwuid (SAM_ACCOUNT* user, uid_t uid) { struct passwd *pw; fstring name; + if (user==NULL) { + DEBUG(0,("pdb_getsampwuid: SAM_ACCOUNT is NULL.\n")); + return False; + } + pw = sys_getpwuid(uid); if (pw == NULL) { @@ -533,14 +547,14 @@ SAM_ACCOUNT* pdb_getsampwuid (uid_t uid) } fstrcpy (name, pw->pw_name); - return pdb_getsampwnam (name); + return pdb_getsampwnam (user, name); } /*************************************************************************** Search by rid **************************************************************************/ -SAM_ACCOUNT* pdb_getsampwrid (uint32 rid) +BOOL pdb_getsampwrid (SAM_ACCOUNT *user, uint32 rid) { TDB_CONTEXT *pwd_tdb; TDB_DATA data, key; @@ -548,6 +562,11 @@ SAM_ACCOUNT* pdb_getsampwrid (uint32 rid) pstring tdbfile; fstring name; + if (user==NULL) { + DEBUG(0,("pdb_getsampwrid: SAM_ACCOUNT is NULL.\n")); + return False; + } + pstrcpy (tdbfile, lp_private_dir()); pstrcat (tdbfile, PASSDB_FILE_NAME); @@ -570,14 +589,14 @@ SAM_ACCOUNT* pdb_getsampwrid (uint32 rid) DEBUG(5,("pdb_getsampwrid (TDB): error fetching database.\n")); DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb))); tdb_close (pwd_tdb); - return NULL; + return False; } fstrcpy (name, data.dptr); tdb_close (pwd_tdb); - return pdb_getsampwnam (name); + return pdb_getsampwnam (user, name); } |