summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2002-01-20 17:03:23 +0000
committerSimo Sorce <idra@samba.org>2002-01-20 17:03:23 +0000
commit56d884eefeec40920fd51ce1e38798ac3ef799f0 (patch)
tree87d989ec854cf8f1ac002d27c0ec1250fbbfdacf
parent1a74d8d1f0758d15c5c35d20e33d9868565812cf (diff)
downloadsamba-56d884eefeec40920fd51ce1e38798ac3ef799f0.tar.gz
samba-56d884eefeec40920fd51ce1e38798ac3ef799f0.tar.bz2
samba-56d884eefeec40920fd51ce1e38798ac3ef799f0.zip
fixes from 2.2
(This used to be commit e8a891354d307b2352eac375b9be02d7616cdb61)
-rw-r--r--source3/passdb/pdb_tdb.c220
1 files changed, 127 insertions, 93 deletions
diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c
index 0e0bf541e3..90b7cb5a0a 100644
--- a/source3/passdb/pdb_tdb.c
+++ b/source3/passdb/pdb_tdb.c
@@ -85,6 +85,8 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state,
uint32 len = 0;
uint32 lmpwlen, ntpwlen, hourslen;
BOOL ret = True;
+ BOOL setflag;
+ gid_t gid;
if(sampass == NULL || buf == NULL) {
DEBUG(0, ("init_sam_from_buffer: NULL parameters found!\n"));
@@ -128,6 +130,27 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state,
goto done;
}
+ if ((tdb_state->permit_non_unix_accounts)
+ && (pdb_get_user_rid(sampass) >= tdb_state->low_nua_rid)
+ && (pdb_get_user_rid(sampass) <= tdb_state->high_nua_rid)) {
+
+ } else {
+ struct passwd *pw;
+ /* validate the account and fill in UNIX uid and gid. Standard
+ * getpwnam() is used instead of Get_Pwnam() as we do not need
+ * to try case permutations
+ */
+ if (!username || !(pw=getpwnam(username))) {
+ DEBUG(0,("tdb_sam: getpwnam(%s) return NULL. User does not exist!\n",
+ username?username:"NULL"));
+ ret = False;
+ goto done;
+ }
+ pdb_set_uid(sampass, pw->pw_uid);
+ gid = pw->pw_gid;
+ pdb_set_gid(sampass, gid);
+ }
+
pdb_set_logon_time(sampass, logon_time);
pdb_set_logoff_time(sampass, logoff_time);
pdb_set_kickoff_time(sampass, kickoff_time);
@@ -135,26 +158,65 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state,
pdb_set_pass_must_change_time(sampass, pass_must_change_time);
pdb_set_pass_last_set_time(sampass, pass_last_set_time);
- pdb_set_username (sampass, username_len?username:NULL);
- pdb_set_domain (sampass, domain_len?domain:NULL);
- pdb_set_nt_username (sampass, nt_username_len?nt_username:NULL);
- pdb_set_fullname (sampass, fullname_len?fullname:NULL);
- pdb_set_homedir (sampass, homedir_len?homedir:NULL, True);
- pdb_set_dir_drive (sampass, dir_drive_len?dir_drive:NULL, True);
- pdb_set_logon_script (sampass, logon_script_len?logon_script:NULL, True);
- pdb_set_profile_path (sampass, profile_path_len?profile_path:NULL, True);
- pdb_set_acct_desc (sampass, acct_desc_len?acct_desc:NULL);
- pdb_set_workstations (sampass, workstations_len?workstations:NULL);
- pdb_set_munged_dial (sampass, munged_dial_len?munged_dial:NULL);
- if (!pdb_set_lanman_passwd(sampass, lmpwlen?lm_pw_ptr:NULL)) {
+ pdb_set_username (sampass, username);
+ pdb_set_domain (sampass, domain);
+ pdb_set_nt_username (sampass, nt_username);
+ pdb_set_fullname (sampass, fullname);
+
+ if (homedir) setflag = True;
+ else {
+ setflag = False;
+ homedir = strdup(lp_logon_home());
+ if(!homedir) { ret = False; goto done; }
+ standard_sub_advanced(-1, username, "", gid, username, homedir);
+ DEBUG(5,("Home directory set back to %s\n", homedir));
+ }
+ pdb_set_homedir(sampass, homedir, setflag);
+
+ if (dir_drive) setflag = True;
+ else {
+ setflag = False;
+ dir_drive = strdup(lp_logon_drive());
+ if(!dir_drive) { ret = False; goto done; }
+ standard_sub_advanced(-1, username, "", gid, username, dir_drive);
+ DEBUG(5,("Home directory set back to %s\n", dir_drive));
+ }
+ pdb_set_dir_drive(sampass, dir_drive, setflag);
+
+ if (logon_script) setflag = True;
+ else {
+ setflag = False;
+ logon_script = strdup(lp_logon_script());
+ if(!logon_script) { ret = False; goto done; }
+ standard_sub_advanced(-1, username, "", gid, username, logon_script);
+ DEBUG(5,("Home directory set back to %s\n", logon_script));
+ }
+ pdb_set_logon_script(sampass, logon_script, setflag);
+
+ if (profile_path) setflag = True;
+ else {
+ setflag = False;
+ profile_path = strdup(lp_logon_path());
+ if(!profile_path) { ret = False; goto done; }
+ standard_sub_advanced(-1, username, "", gid, username, profile_path);
+ DEBUG(5,("Home directory set back to %s\n", profile_path));
+ }
+ pdb_set_profile_path(sampass, profile_path, setflag);
+
+ pdb_set_acct_desc (sampass, acct_desc);
+ pdb_set_workstations (sampass, workstations);
+ pdb_set_munged_dial (sampass, munged_dial);
+ if (!pdb_set_lanman_passwd(sampass, lm_pw_ptr)) {
ret = False;
goto done;
}
- if (!pdb_set_nt_passwd(sampass, ntpwlen?nt_pw_ptr:NULL)) {
+ if (!pdb_set_nt_passwd(sampass, nt_pw_ptr)) {
ret = False;
goto done;
}
+ /*pdb_set_uid(sampass, uid);
+ pdb_set_gid(sampass, gid);*/
pdb_set_user_rid(sampass, user_rid);
pdb_set_group_rid(sampass, group_rid);
pdb_set_unknown_3(sampass, unknown_3);
@@ -165,28 +227,6 @@ static BOOL init_sam_from_buffer (struct tdbsam_privates *tdb_state,
pdb_set_logon_divs(sampass, logon_divs);
pdb_set_hours(sampass, hours);
- if ((tdb_state->permit_non_unix_accounts)
- && (pdb_get_user_rid(sampass) >= tdb_state->low_nua_rid)
- && (pdb_get_user_rid(sampass) <= tdb_state->high_nua_rid)) {
-
- } else {
- struct passwd *pw;
- /* 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=getpwnam_alloc(pdb_get_username(sampass))) == NULL) {
- DEBUG(0,("init_sam_from_buffer: (tdbsam) getpwnam(%s) return NULL. User does not exist!\n",
- pdb_get_username(sampass)));
- return False;
- }
-
- pdb_set_uid(sampass, pw->pw_uid);
- pdb_set_gid(sampass, pw->pw_gid);
-
- passwd_free(&pw);
- }
-
done:
SAFE_FREE(username);
@@ -261,71 +301,65 @@ static uint32 init_buffer_from_sam (struct tdbsam_privates *tdb_state, uint8 **b
username = pdb_get_username(sampass);
- if (username)
- username_len = strlen(username) +1;
- else
- username_len = 0;
+ if (username) username_len = strlen(username) +1;
+ else username_len = 0;
+
domain = pdb_get_domain(sampass);
- if (domain)
- domain_len = strlen(domain) +1;
- else
- domain_len = 0;
+ if (domain) domain_len = strlen(domain) +1;
+ else domain_len = 0;
+
nt_username = pdb_get_nt_username(sampass);
- if (nt_username)
- nt_username_len = strlen(nt_username) +1;
- else
- nt_username_len = 0;
- dir_drive = pdb_get_dirdrive(sampass);
- if (dir_drive)
- dir_drive_len = strlen(dir_drive) +1;
- else
- dir_drive_len = 0;
- unknown_str = NULL;
- unknown_str_len = 0;
- munged_dial = pdb_get_munged_dial(sampass);
- if (munged_dial)
- munged_dial_len = strlen(munged_dial) +1;
- else
- munged_dial_len = 0;
-
+ if (nt_username) nt_username_len = strlen(nt_username) +1;
+ else nt_username_len = 0;
+
fullname = pdb_get_fullname(sampass);
- if (fullname)
- fullname_len = strlen(fullname) +1;
- else
- fullname_len = 0;
- homedir = pdb_get_homedir(sampass);
- if (homedir)
- homedir_len = strlen(homedir) +1;
- else
- homedir_len = 0;
- logon_script = pdb_get_logon_script(sampass);
- if (logon_script)
- logon_script_len = strlen(logon_script) +1;
- else
- logon_script_len = 0;
- profile_path = pdb_get_profile_path(sampass);
- if (profile_path)
- profile_path_len = strlen(profile_path) +1;
- else
- profile_path_len = 0;
- acct_desc = pdb_get_acct_desc(sampass);
- if (acct_desc)
- acct_desc_len = strlen(acct_desc) +1;
- else
- acct_desc_len = 0;
- workstations = pdb_get_workstations(sampass);
- if (workstations)
- workstations_len = strlen(workstations) +1;
- else
- workstations_len = 0;
+ if (fullname) fullname_len = strlen(fullname) +1;
+ else fullname_len = 0;
+
+ /*
+ * Only updates fields which have been set (not defaults from smb.conf)
+ */
+
+ if (IS_SAM_SET(sampass, FLAG_SAM_DRIVE)) dir_drive = pdb_get_dirdrive(sampass);
+ else dir_drive = NULL;
+ if (dir_drive) dir_drive_len = strlen(dir_drive) +1;
+ else dir_drive_len = 0;
+
+ if (IS_SAM_SET(sampass, FLAG_SAM_SMBHOME)) homedir = pdb_get_homedir(sampass);
+ else homedir = NULL;
+ if (homedir) homedir_len = strlen(homedir) +1;
+ else homedir_len = 0;
+
+ if (IS_SAM_SET(sampass, FLAG_SAM_LOGONSCRIPT)) logon_script = pdb_get_logon_script(sampass);
+ else logon_script = NULL;
+ if (logon_script) logon_script_len = strlen(logon_script) +1;
+ else logon_script_len = 0;
+
+ if (IS_SAM_SET(sampass, FLAG_SAM_PROFILE)) profile_path = pdb_get_profile_path(sampass);
+ else profile_path = NULL;
+ if (profile_path) profile_path_len = strlen(profile_path) +1;
+ else profile_path_len = 0;
lm_pw = pdb_get_lanman_passwd(sampass);
- if (!lm_pw)
- lm_pw_len = 0;
+ if (!lm_pw) lm_pw_len = 0;
nt_pw = pdb_get_nt_passwd(sampass);
- if (!nt_pw)
- nt_pw_len = 0;
+ if (!nt_pw) nt_pw_len = 0;
+
+ acct_desc = pdb_get_acct_desc(sampass);
+ if (acct_desc) acct_desc_len = strlen(acct_desc) +1;
+ else acct_desc_len = 0;
+
+ workstations = pdb_get_workstations(sampass);
+ if (workstations) workstations_len = strlen(workstations) +1;
+ else workstations_len = 0;
+
+ unknown_str = NULL;
+ unknown_str_len = 0;
+
+ munged_dial = pdb_get_munged_dial(sampass);
+ if (munged_dial) munged_dial_len = strlen(munged_dial) +1;
+ else munged_dial_len = 0;
/* one time to get the size needed */
len = tdb_pack(NULL, 0, TDB_FORMAT_STRING,