diff options
Diffstat (limited to 'source3/smbd/server.c')
-rw-r--r-- | source3/smbd/server.c | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/source3/smbd/server.c b/source3/smbd/server.c index 6f5527714d..e4c00c141f 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -3537,7 +3537,7 @@ int make_connection(char *service,char *user,char *password, int pwlen, char *de { pstring s; pstrcpy(s,lp_pathname(snum)); - standard_sub(cnum,s,vuid); + standard_sub(cnum,s); string_set(&pcon->connectpath,s); DEBUG(3,("Connect path is %s\n",s)); } @@ -3574,7 +3574,7 @@ int make_connection(char *service,char *user,char *password, int pwlen, char *de { pstring cmd; pstrcpy(cmd,lp_rootpreexec(SNUM(cnum))); - standard_sub(cnum,cmd,vuid); + standard_sub(cnum,cmd); DEBUG(5,("cmd=%s\n",cmd)); smbrun(cmd,NULL,False); } @@ -3628,7 +3628,7 @@ int make_connection(char *service,char *user,char *password, int pwlen, char *de { pstring cmd; pstrcpy(cmd,lp_preexec(SNUM(cnum))); - standard_sub(cnum,cmd,vuid); + standard_sub(cnum,cmd); smbrun(cmd,NULL,False); } @@ -4222,7 +4222,7 @@ void close_cnum(int cnum, uint16 vuid) { pstring cmd; strcpy(cmd,lp_postexec(SNUM(cnum))); - standard_sub(cnum,cmd,vuid); + standard_sub(cnum,cmd); smbrun(cmd,NULL,False); unbecome_user(); } @@ -4233,7 +4233,7 @@ void close_cnum(int cnum, uint16 vuid) { pstring cmd; strcpy(cmd,lp_rootpostexec(SNUM(cnum))); - standard_sub(cnum,cmd,vuid); + standard_sub(cnum,cmd); smbrun(cmd,NULL,False); } @@ -4338,16 +4338,10 @@ void exit_server(char *reason) /**************************************************************************** do some standard substitutions in a string ****************************************************************************/ -void standard_sub(int cnum,char *str,uint16 vuid) +void standard_sub(int cnum,char *str) { if (VALID_CNUM(cnum)) { char *p, *s, *home; - struct passwd *pass; - char *username = sesssetup_user; - user_struct *vuser = get_valid_user_struct(vuid); - - if(vuser != NULL) - pstrcpy( sesssetup_user, vuser->requested_name); for ( s=str ; (p=strchr(s, '%')) != NULL ; s=p ) { switch (*(p+1)) { @@ -4359,23 +4353,15 @@ void standard_sub(int cnum,char *str,uint16 vuid) case 'P' : string_sub(p,"%P",Connections[cnum].connectpath); break; case 'S' : string_sub(p,"%S",lp_servicename(Connections[cnum].service)); break; case 'g' : string_sub(p,"%g",gidtoname(Connections[cnum].gid)); break; - case 'G' : - { - if ((pass = Get_Pwnam(sesssetup_user,False))!=NULL) - string_sub(p,"%G",gidtoname(pass->pw_gid)); - else - p += 2; - break; - } case 'u' : string_sub(p,"%u",Connections[cnum].user); break; - case 'U' : string_sub(p,"%U", username); break; /* * Patch from jkf@soton.ac.uk + * Left the %N (NIS server name) in standard_sub_basic as it + * is a feature for logon servers, hence uses the username. * The %p (NIS server path) code is here as it is used * instead of the default "path =" string in [homes] and so * needs the service name, not the username. */ - case 'N' : string_sub(p,"%N", automount_server(username)); break; case 'p' : string_sub(p,"%p",automount_path(lp_servicename(Connections[cnum].service))); break; case '\0' : p++; break; /* don't run off the end of the string */ default : p+=2; break; @@ -4595,11 +4581,31 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize { int cnum = SVAL(inbuf,smb_tid); int flags = smb_messages[match].flags; + static uint16 last_session_tag = UID_FIELD_INVALID; /* In share mode security we must ignore the vuid. */ uint16 session_tag = (lp_security() == SEC_SHARE) ? UID_FIELD_INVALID : SVAL(inbuf,smb_uid); /* Ensure this value is replaced in the incoming packet. */ SSVAL(inbuf,smb_uid,session_tag); + /* + * Ensure the correct username is in sesssetup_user. + * This is a really ugly bugfix for problems with + * multiple session_setup_and_X's being done and + * allowing %U and %G substitutions to work correctly. + * There is a reason this code is done here, don't + * move it unless you know what you're doing... :-). + * JRA. + */ + if(session_tag != last_session_tag ) { + user_struct *vuser = NULL; + + last_session_tag = session_tag; + if(session_tag != UID_FIELD_INVALID) + vuser = get_valid_user_struct(session_tag); + if(vuser != NULL) + pstrcpy( sesssetup_user, vuser->requested_name); + } + /* does this protocol need to be run as root? */ if (!(flags & AS_USER)) unbecome_user(); |