summaryrefslogtreecommitdiff
path: root/source3/smbd
diff options
context:
space:
mode:
Diffstat (limited to 'source3/smbd')
-rw-r--r--source3/smbd/password.c64
-rw-r--r--source3/smbd/session.c4
2 files changed, 27 insertions, 41 deletions
diff --git a/source3/smbd/password.c b/source3/smbd/password.c
index bf4e9258ff..b7945bd7ea 100644
--- a/source3/smbd/password.c
+++ b/source3/smbd/password.c
@@ -92,14 +92,7 @@ void invalidate_vuid(uint16 vuid)
if (vuser == NULL)
return;
- SAFE_FREE(vuser->homedir);
- SAFE_FREE(vuser->unix_homedir);
- SAFE_FREE(vuser->logon_script);
-
session_yield(vuser);
- SAFE_FREE(vuser->session_keystr);
-
- TALLOC_FREE(vuser->server_info);
data_blob_free(&vuser->session_key);
@@ -109,10 +102,7 @@ void invalidate_vuid(uint16 vuid)
from the vuid 'owner' of connections */
conn_clear_vuid_cache(vuid);
- SAFE_FREE(vuser->groups);
- TALLOC_FREE(vuser->nt_user_token);
-
- SAFE_FREE(vuser);
+ TALLOC_FREE(vuser);
num_validated_vuids--;
}
@@ -153,7 +143,7 @@ int register_vuid(auth_serversupplied_info *server_info,
DATA_BLOB session_key, DATA_BLOB response_blob,
const char *smb_name)
{
- user_struct *vuser = NULL;
+ user_struct *vuser;
/* Paranoia check. */
if(lp_security() == SEC_SHARE) {
@@ -166,14 +156,12 @@ int register_vuid(auth_serversupplied_info *server_info,
return UID_FIELD_INVALID;
}
- if((vuser = SMB_MALLOC_P(user_struct)) == NULL) {
- DEBUG(0,("Failed to malloc users struct!\n"));
+ if((vuser = talloc_zero(NULL, user_struct)) == NULL) {
+ DEBUG(0,("Failed to talloc users struct!\n"));
data_blob_free(&session_key);
return UID_FIELD_INVALID;
}
- ZERO_STRUCTP(vuser);
-
/* Allocate a free vuid. Yes this is a linear search... :-) */
while( get_valid_user_struct(next_vuid) != NULL ) {
next_vuid++;
@@ -203,6 +191,11 @@ int register_vuid(auth_serversupplied_info *server_info,
return vuser->vuid;
}
+ /* use this to keep tabs on all our info from the authentication */
+ vuser->server_info = server_info;
+ /* Ensure that the server_info will dissapear with the vuser it is now attached to */
+ talloc_steal(vuser, vuser->server_info);
+
/* the next functions should be done by a SID mapping system (SMS) as
* the new real sam db won't have reference to unix uids or gids
*/
@@ -212,14 +205,13 @@ int register_vuid(auth_serversupplied_info *server_info,
vuser->n_groups = server_info->n_groups;
if (vuser->n_groups) {
- if (!(vuser->groups = (gid_t *)memdup(server_info->groups,
- sizeof(gid_t) *
- vuser->n_groups))) {
- DEBUG(0,("register_vuid: failed to memdup "
+ if (!(vuser->groups = (gid_t *)talloc_memdup(vuser, server_info->groups,
+ sizeof(gid_t) *
+ vuser->n_groups))) {
+ DEBUG(0,("register_vuid: failed to talloc_memdup "
"vuser->groups\n"));
data_blob_free(&session_key);
- free(vuser);
- TALLOC_FREE(server_info);
+ TALLOC_FREE(vuser);
return UID_FIELD_INVALID;
}
}
@@ -247,24 +239,26 @@ int register_vuid(auth_serversupplied_info *server_info,
const char *unix_homedir =
pdb_get_unix_homedir(server_info->sam_account);
if (unix_homedir) {
- vuser->unix_homedir =
- smb_xstrdup(unix_homedir);
+ vuser->unix_homedir = unix_homedir;
}
} else {
struct passwd *passwd =
- getpwnam_alloc(NULL, vuser->user.unix_name);
+ getpwnam_alloc(vuser, vuser->user.unix_name);
if (passwd) {
- vuser->unix_homedir =
- smb_xstrdup(passwd->pw_dir);
+ vuser->unix_homedir = passwd->pw_dir;
+ /* Ensure that the unix_homedir now
+ * belongs to vuser, so it goes away
+ * with it, not with passwd below: */
+ talloc_steal(vuser, vuser->unix_homedir);
TALLOC_FREE(passwd);
}
}
if (homedir) {
- vuser->homedir = smb_xstrdup(homedir);
+ vuser->homedir = homedir;
}
if (logon_script) {
- vuser->logon_script = smb_xstrdup(logon_script);
+ vuser->logon_script = logon_script;
}
}
@@ -280,23 +274,15 @@ int register_vuid(auth_serversupplied_info *server_info,
vuser->user.full_name));
if (server_info->ptok) {
- vuser->nt_user_token = dup_nt_token(NULL, server_info->ptok);
+ vuser->nt_user_token = dup_nt_token(vuser, server_info->ptok);
} else {
DEBUG(1, ("server_info does not contain a user_token - "
"cannot continue\n"));
- TALLOC_FREE(server_info);
+ TALLOC_FREE(vuser);
data_blob_free(&session_key);
- SAFE_FREE(vuser->homedir);
- SAFE_FREE(vuser->unix_homedir);
- SAFE_FREE(vuser->logon_script);
-
- SAFE_FREE(vuser);
return UID_FIELD_INVALID;
}
- /* use this to keep tabs on all our info from the authentication */
- vuser->server_info = server_info;
-
DEBUG(3,("UNIX uid %d is UNIX user %s, and will be vuid %u\n",
(int)vuser->uid,vuser->user.unix_name, vuser->vuid));
diff --git a/source3/smbd/session.c b/source3/smbd/session.c
index a3334a353e..05b1026f41 100644
--- a/source3/smbd/session.c
+++ b/source3/smbd/session.c
@@ -153,9 +153,9 @@ BOOL session_claim(user_struct *vuser)
sessionid.id_str, sessionid.id_num);
}
- vuser->session_keystr = SMB_STRDUP(keystr);
+ vuser->session_keystr = talloc_strdup(vuser, keystr);
if (!vuser->session_keystr) {
- DEBUG(0, ("session_claim: strdup() failed for session_keystr\n"));
+ DEBUG(0, ("session_claim: talloc_strdup() failed for session_keystr\n"));
return False;
}
return True;