summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2007-12-09 19:03:49 +0100
committerVolker Lendecke <vl@samba.org>2007-12-10 12:22:01 +0100
commit2585232054934bc60e1384f2bdb93bc43f75c7da (patch)
tree436db623f8cb7c2639b8f0b7a0bda7f030351ffb /source3
parent3a9576c724460381782f6e39126f353c054699af (diff)
downloadsamba-2585232054934bc60e1384f2bdb93bc43f75c7da.tar.gz
samba-2585232054934bc60e1384f2bdb93bc43f75c7da.tar.bz2
samba-2585232054934bc60e1384f2bdb93bc43f75c7da.zip
Simplify add_session_user
(This used to be commit f98082ccf048a2de6fea8d922264879305b3d2c8)
Diffstat (limited to 'source3')
-rw-r--r--source3/smbd/password.c58
1 files changed, 25 insertions, 33 deletions
diff --git a/source3/smbd/password.c b/source3/smbd/password.c
index 75f05dea67..b3005ba082 100644
--- a/source3/smbd/password.c
+++ b/source3/smbd/password.c
@@ -22,7 +22,6 @@
/* users from session setup */
static char *session_userlist = NULL;
-static int len_session_userlist = 0;
/* workgroup from session setup. */
static char *session_workgroup = NULL;
@@ -383,46 +382,39 @@ int register_existing_vuid(uint16 vuid,
void add_session_user(const char *user)
{
- fstring suser;
- struct passwd *passwd;
+ struct passwd *pw;
+ char *tmp;
- if (!(passwd = Get_Pwnam(user)))
- return;
-
- fstrcpy(suser,passwd->pw_name);
+ pw = Get_Pwnam_alloc(talloc_tos(), user);
- if(!*suser)
+ if (pw == NULL) {
return;
+ }
- if( session_userlist && in_list(suser,session_userlist,False) )
- return;
+ if (session_userlist == NULL) {
+ session_userlist = SMB_STRDUP(pw->pw_name);
+ goto done;
+ }
- if( !session_userlist ||
- (strlen(suser) + strlen(session_userlist) + 2 >=
- len_session_userlist) ) {
- char *newlist;
+ if (in_list(pw->pw_name,session_userlist,False) ) {
+ goto done;
+ }
- if (len_session_userlist > 128 * 1024) {
- DEBUG(3,("add_session_user: session userlist already "
- "too large.\n"));
- return;
- }
- newlist = (char *)SMB_REALLOC_KEEP_OLD_ON_ERROR(
- session_userlist,
- len_session_userlist + 1024 );
- if( newlist == NULL ) {
- DEBUG(1,("Unable to resize session_userlist\n"));
- return;
- }
- if (!session_userlist) {
- *newlist = '\0';
- }
- session_userlist = newlist;
- len_session_userlist += 1024;
+ if (strlen(session_userlist) > 128 * 1024) {
+ DEBUG(3,("add_session_user: session userlist already "
+ "too large.\n"));
+ goto done;
+ }
+
+ if (asprintf(&tmp, "%s %s", session_userlist, pw->pw_name) == -1) {
+ DEBUG(3, ("asprintf failed\n"));
+ goto done;
}
- safe_strcat(session_userlist," ",len_session_userlist-1);
- safe_strcat(session_userlist,suser,len_session_userlist-1);
+ SAFE_FREE(session_userlist);
+ session_userlist = tmp;
+ done:
+ TALLOC_FREE(pw);
}
/****************************************************************************