diff options
author | Gerald Carter <jerry@samba.org> | 2001-12-27 06:38:04 +0000 |
---|---|---|
committer | Gerald Carter <jerry@samba.org> | 2001-12-27 06:38:04 +0000 |
commit | 04aff47c716a51a1039b44a81d6ff19eeaa09017 (patch) | |
tree | e2fc04ef3089c003baa711d55cd89310b824d44b /source3/passdb | |
parent | b6bbc39204a4676922099ab78b6c48009266d1bb (diff) | |
download | samba-04aff47c716a51a1039b44a81d6ff19eeaa09017.tar.gz samba-04aff47c716a51a1039b44a81d6ff19eeaa09017.tar.bz2 samba-04aff47c716a51a1039b44a81d6ff19eeaa09017.zip |
moving SAM_ACCOUNT to include a bit field for initialized
members (such as uid and gid). This way we will be able to
keep ourselves from writing out default smb.conf settings when
the admin doesn't want to, That part is not done yet.
Tested compiles with ldap/tdb/smbpasswd. Tested connection with smbpasswd
backend.
oh...and smbpasswd doesn'y automatically expire accounts after 21 days
from the last password change either now. Just ifdef'd out that code
in build_sam_account().
Will merge updates into 2.2 as they are necessary.
jerry
(This used to be commit f0d43791157d8f04a13a07d029f203ad4384d317)
Diffstat (limited to 'source3/passdb')
-rw-r--r-- | source3/passdb/passdb.c | 73 | ||||
-rw-r--r-- | source3/passdb/pdb_ldap.c | 11 | ||||
-rw-r--r-- | source3/passdb/pdb_nisplus.c | 4 | ||||
-rw-r--r-- | source3/passdb/pdb_smbpasswd.c | 22 | ||||
-rw-r--r-- | source3/passdb/pdb_tdb.c | 8 |
5 files changed, 45 insertions, 73 deletions
diff --git a/source3/passdb/passdb.c b/source3/passdb/passdb.c index 4c64ad5e01..ca7c508dc5 100644 --- a/source3/passdb/passdb.c +++ b/source3/passdb/passdb.c @@ -69,6 +69,9 @@ static BOOL pdb_fill_default_sam(SAM_ACCOUNT *user) /* Don't change these timestamp settings without a good reason. They are important for NT member server compatibility. */ + user->init_flag = FLAG_SAM_UNINIT; + user->uid = user->gid = -1; + user->logon_time = (time_t)0; user->pass_last_set_time = (time_t)0; user->pass_can_change_time = (time_t)0; @@ -135,16 +138,19 @@ BOOL pdb_init_sam_pw(SAM_ACCOUNT **new_sam_acct, const struct passwd *pwd) pdb_set_username(*new_sam_acct, pwd->pw_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_uid(*new_sam_acct, pwd->pw_uid); + pdb_set_gid(*new_sam_acct, pwd->pw_gid); + pdb_set_user_rid(*new_sam_acct, pdb_uid_to_user_rid(pwd->pw_uid)); /* call the mapping code here */ if(get_group_map_from_gid(pwd->pw_gid, &map, MAPPING_WITHOUT_PRIV)) { sid_peek_rid(&map.sid, &rid); - } else + } + else { rid=pdb_gid_to_group_rid(pwd->pw_gid); + } + pdb_set_group_rid(*new_sam_acct, rid); pstrcpy(str, lp_logon_path()); @@ -187,9 +193,6 @@ static BOOL pdb_free_sam_contents(SAM_ACCOUNT *user) SAFE_FREE(user->nt_pw); SAFE_FREE(user->lm_pw); - SAFE_FREE(user->uid); - SAFE_FREE(user->gid); - return True; } @@ -1186,20 +1189,20 @@ uint32 pdb_get_group_rid (const SAM_ACCOUNT *sampass) return (-1); } -uid_t *pdb_get_uid (const SAM_ACCOUNT *sampass) +uid_t pdb_get_uid (const SAM_ACCOUNT *sampass) { if (sampass) return (sampass->uid); else - return (NULL); + return (-1); } -gid_t *pdb_get_gid (const SAM_ACCOUNT *sampass) +gid_t pdb_get_gid (const SAM_ACCOUNT *sampass) { if (sampass) return (sampass->gid); else - return (NULL); + return (-1); } const char* pdb_get_username (const SAM_ACCOUNT *sampass) @@ -1403,59 +1406,25 @@ BOOL pdb_set_logons_divs (SAM_ACCOUNT *sampass, uint16 hours) return True; } -/********************************************************************* - Set the user's UNIX uid, as a pointer to malloc'ed memory. - ********************************************************************/ - -BOOL pdb_set_uid (SAM_ACCOUNT *sampass, const uid_t *uid) +BOOL pdb_set_uid (SAM_ACCOUNT *sampass, const uid_t uid) { if (!sampass) return False; - if (!uid) { - /* Allow setting to NULL */ - SAFE_FREE(sampass->uid); - return True; - } - - if (sampass->uid!=NULL) - DEBUG(4,("pdb_set_nt_passwd: uid non NULL overwritting ?\n")); - else - sampass->uid=(uid_t *)malloc(sizeof(uid_t)); - - if (sampass->uid==NULL) - return False; - - *sampass->uid = *uid; + sampass->uid = uid; + sampass->init_flag |= FLAG_SAM_UID; return True; } -/********************************************************************* - Set the user's UNIX gid, as a pointer to malloc'ed memory. - ********************************************************************/ - -BOOL pdb_set_gid (SAM_ACCOUNT *sampass, const gid_t *gid) +BOOL pdb_set_gid (SAM_ACCOUNT *sampass, const gid_t gid) { if (!sampass) return False; - - if (!gid) { - /* Allow setting to NULL */ - SAFE_FREE(sampass->gid); - return True; - } - - if (sampass->gid!=NULL) - DEBUG(4,("pdb_set_nt_passwd: gid non NULL overwritting ?\n")); - else - sampass->gid=(gid_t *)malloc(sizeof(gid_t)); - - if (sampass->gid==NULL) - return False; - - *sampass->gid = *gid; + + sampass->gid = gid; + sampass->init_flag |= FLAG_SAM_GID; return True; diff --git a/source3/passdb/pdb_ldap.c b/source3/passdb/pdb_ldap.c index f426f926b1..a6593491d0 100644 --- a/source3/passdb/pdb_ldap.c +++ b/source3/passdb/pdb_ldap.c @@ -485,8 +485,8 @@ static BOOL init_sam_from_ldap (SAM_ACCOUNT * sampass, pdb_set_hours_len(sampass, hours_len); pdb_set_logons_divs(sampass, logon_divs); - pdb_set_uid(sampass, &sys_user->pw_uid); - pdb_set_gid(sampass, &sys_user->pw_gid); + pdb_set_uid(sampass, sys_user->pw_uid); + pdb_set_gid(sampass, sys_user->pw_gid); pdb_set_user_rid(sampass, user_rid); pdb_set_group_rid(sampass, group_rid); @@ -577,9 +577,10 @@ static BOOL init_ldap_from_sam (LDAPMod *** mods, int ldap_state, const SAM_ACCO make_a_mod(mods, ldap_state, "description", pdb_get_acct_desc(sampass)); make_a_mod(mods, ldap_state, "userWorkstations", pdb_get_workstations(sampass)); - if ( !sampass->user_rid) - sampass->user_rid = pdb_uid_to_user_rid(pdb_get_uid(sampass)); - slprintf(temp, sizeof(temp) - 1, "%i", sampass->user_rid); + if ( !sampass->user_rid ) + slprintf(temp, sizeof(temp) - 1, "%i", pdb_uid_to_user_rid(pdb_get_uid(sampass))); + else + slprintf(temp, sizeof(temp) - 1, "%i", sampass->user_rid); make_a_mod(mods, ldap_state, "rid", temp); if ( !sampass->group_rid) { diff --git a/source3/passdb/pdb_nisplus.c b/source3/passdb/pdb_nisplus.c index 2820fa1414..27dd420f3f 100644 --- a/source3/passdb/pdb_nisplus.c +++ b/source3/passdb/pdb_nisplus.c @@ -313,8 +313,8 @@ static BOOL make_sam_from_nisp_object(SAM_ACCOUNT *pw_buf, const nis_object *obj pdb_set_workstations(pw_buf, ENTRY_VAL(obj, NPF_WORKSTATIONS)); pdb_set_munged_dial(pw_buf, NULL); - pdb_set_uid(pw_buf, &atoi(ENTRY_VAL(obj, NPF_UID))); - pdb_set_gid(pw_buf, &atoi(ENTRY_VAL(obj, NPF_SMB_GRPID))); + pdb_set_uid(pw_buf, atoi(ENTRY_VAL(obj, NPF_UID))); + pdb_set_gid(pw_buf, atoi(ENTRY_VAL(obj, NPF_SMB_GRPID))); pdb_set_user_rid(pw_buf, atoi(ENTRY_VAL(obj, NPF_USER_RID))); pdb_set_group_rid(pw_buf, atoi(ENTRY_VAL(obj, NPF_GROUP_RID))); diff --git a/source3/passdb/pdb_smbpasswd.c b/source3/passdb/pdb_smbpasswd.c index 9cfad2540c..8e942a60fb 100644 --- a/source3/passdb/pdb_smbpasswd.c +++ b/source3/passdb/pdb_smbpasswd.c @@ -1133,22 +1133,22 @@ Error was %s\n", pwd->smb_name, pfile2, strerror(errno))); ********************************************************************/ static BOOL build_smb_pass (struct smb_passwd *smb_pw, const SAM_ACCOUNT *sampass) { - uid_t *uid; - gid_t *gid; + uid_t uid; + gid_t gid; if (sampass == NULL) return False; uid = pdb_get_uid(sampass); gid = pdb_get_gid(sampass); - if (!uid || !gid) { + if (!IS_SAM_UNIX_USER(sampass)) { DEBUG(0,("build_sam_pass: Failing attempt to store user without a UNIX uid or gid. \n")); return False; } ZERO_STRUCTP(smb_pw); - smb_pw->smb_userid=*uid; + smb_pw->smb_userid=uid; smb_pw->smb_name=pdb_get_username(sampass); smb_pw->smb_passwd=pdb_get_lanman_passwd(sampass); @@ -1157,7 +1157,7 @@ static BOOL build_smb_pass (struct smb_passwd *smb_pw, const SAM_ACCOUNT *sampas smb_pw->acct_ctrl=pdb_get_acct_ctrl(sampass); smb_pw->pass_last_set_time=pdb_get_pass_last_set_time(sampass); - if (*uid != pdb_user_rid_to_uid(pdb_get_user_rid(sampass))) { + if (uid != pdb_user_rid_to_uid(pdb_get_user_rid(sampass))) { DEBUG(0,("build_sam_pass: Failing attempt to store user with non-uid based user RID. \n")); return False; } @@ -1174,7 +1174,7 @@ static BOOL build_smb_pass (struct smb_passwd *smb_pw, const SAM_ACCOUNT *sampas * our domain SID ? well known SID ? local SID ? */ - if (*gid != pdb_group_rid_to_gid(pdb_get_group_rid(sampass))) { + if (gid != pdb_group_rid_to_gid(pdb_get_group_rid(sampass))) { DEBUG(0,("build_sam_pass: Failing attempt to store user with non-gid based primary group RID. \n")); DEBUG(0,("build_sam_pass: %d %d %d. \n", *gid, pdb_group_rid_to_gid(pdb_get_group_rid(sampass)), pdb_get_group_rid(sampass))); return False; @@ -1206,8 +1206,8 @@ static BOOL build_sam_account(SAM_ACCOUNT *sam_pass, const struct smb_passwd *pw return False; } - pdb_set_uid (sam_pass, &pwfile->pw_uid); - pdb_set_gid (sam_pass, &pwfile->pw_gid); + pdb_set_uid (sam_pass, pwfile->pw_uid); + pdb_set_gid (sam_pass, pwfile->pw_gid); pdb_set_fullname(sam_pass, pwfile->pw_gecos); @@ -1236,12 +1236,13 @@ static BOOL build_sam_account(SAM_ACCOUNT *sam_pass, const struct smb_passwd *pw pdb_set_dir_drive (sam_pass, lp_logon_drive()); +#if 0 /* JERRY */ /* the smbpasswd format doesn't have a must change time field, so we can't get this right. The best we can do is to set this to some time in the future. 21 days seems as reasonable as any other value :) */ pdb_set_pass_must_change_time (sam_pass, pw_buf->pass_last_set_time + MAX_PASSWORD_AGE); - +#endif /* check if this is a user account or a machine account */ if (pw_buf->smb_name[strlen(pw_buf->smb_name)-1] != '$') { @@ -1524,7 +1525,8 @@ BOOL pdb_update_sam_account(const SAM_ACCOUNT *sampass, BOOL override) struct smb_passwd smb_pw; /* convert the SAM_ACCOUNT */ - build_smb_pass(&smb_pw, sampass); + if (!build_smb_pass(&smb_pw, sampass)) + return False; /* update the entry */ if(!mod_smbfilepwd_entry(&smb_pw, override)) diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 1f1d1ab455..08439a9d20 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -461,8 +461,8 @@ BOOL pdb_getsampwent(SAM_ACCOUNT *user) uid = pw->pw_uid; gid = pw->pw_gid; - pdb_set_uid (user, &uid); - pdb_set_gid (user, &gid); + pdb_set_uid (user, uid); + pdb_set_gid (user, gid); /* increment to next in line */ global_tdb_ent.key = tdb_nextkey (global_tdb_ent.passwd_tdb, global_tdb_ent.key); @@ -531,8 +531,8 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, const char *sname) if ((pw=sys_getpwnam(pdb_get_username(user)))) { uid = pw->pw_uid; gid = pw->pw_gid; - pdb_set_uid (user, &uid); - pdb_set_gid (user, &gid); + pdb_set_uid (user, uid); + pdb_set_gid (user, gid); } /* cleanup */ |