This should (hopefully :-) be the final fix for the %U %G substitution
authorJeremy Allison <jra@samba.org>
Thu, 7 May 1998 19:04:14 +0000 (19:04 +0000)
committerJeremy Allison <jra@samba.org>
Thu, 7 May 1998 19:04:14 +0000 (19:04 +0000)
problem....
smbpass.c: Removed Luke's dire warning - as some of the functions in here
*need* to be called externally :-).
Jeremy.
(This used to be commit 1fd8d12ca414066acec71b33eb8a13e16c2acd3a)

source3/include/proto.h
source3/lib/util.c
source3/param/loadparm.c
source3/passdb/smbpass.c
source3/printing/printing.c
source3/smbd/ipc.c
source3/smbd/message.c
source3/smbd/server.c
source3/smbd/uid.c

index c6311b3068d8c79cab6e1c2e9c80e14e247de08e..3cc48bb78f388123bd3edb70f46bdd3ffb32b7b0 100644 (file)
@@ -1753,7 +1753,7 @@ int reply_lanman2(char *outbuf);
 int reply_nt1(char *outbuf);
 void close_cnum(int cnum, uint16 vuid);
 void exit_server(char *reason);
-void standard_sub(int cnum,char *str,uint16 vuid);
+void standard_sub(int cnum,char *str);
 char *smb_fn_name(int type);
 int chain_reply(char *inbuf,char *outbuf,int size,int bufsize);
 int construct_reply(char *inbuf,char *outbuf,int size,int bufsize);
index f5cfb974a2dab4cac6ddd4ff846cfc282ea132bf..2416110857955291bdbd118920688b1b05f62603 100644 (file)
@@ -4000,16 +4000,32 @@ void standard_sub_basic(char *str)
 {
        char *s, *p;
        char pidstr[10];
+        struct passwd *pass;
+        char *username = sam_logon_in_ssb ? samlogon_user : sesssetup_user;
 
        for (s = str ; s && *s && (p = strchr(s,'%')); s = p )
        {
                switch (*(p+1))
                {
+                        case 'G' :
+                        {
+                                if ((pass = Get_Pwnam(username,False))!=NULL)
+                                {
+                                        string_sub(p,"%G",gidtoname(pass->pw_gid));
+                                }
+                                else
+                                {
+                                        p += 2;
+                                }
+                                break;
+                        }
+                        case 'N' : string_sub(p,"%N", automount_server(username)); break;
                        case 'I' : string_sub(p,"%I", client_addr(Client)); break;
                        case 'L' : string_sub(p,"%L", local_machine); break;
                        case 'M' : string_sub(p,"%M", client_name(Client)); break;
                        case 'R' : string_sub(p,"%R", remote_proto); break;
                        case 'T' : string_sub(p,"%T", timestring()); break;
+                        case 'U' : string_sub(p,"%U", username); break;
                        case 'a' : string_sub(p,"%a", remote_arch); break;
                        case 'd' :
                        {
index 9ae845486a7a8708e9641cf023be2e266d294faf..ddc5cf3ab1594f854ce004bd28a69e7a90b8e89e 100644 (file)
@@ -754,8 +754,8 @@ static void init_globals(void)
   Globals.syslog = 1;
   Globals.bSyslogOnly = False;
   Globals.os_level = 0;
-  Globals.max_ttl = 60*60*4; /* 4 hours default */
-  Globals.max_wins_ttl = 60*60*24*3; /* 3 days default */
+  Globals.max_ttl = 60*60*24*3; /* 3 days default */
+  Globals.max_wins_ttl = 60*60*24*6; /* 6 days default */
   Globals.min_wins_ttl = 60*60*6; /* 6 hours default */
   Globals.ReadSize = 16*1024;
   Globals.lm_announce = 2;   /* = Auto: send only if LM clients found */
index defadadf693ba561f6ac8d288cd1561f789224dc..31567eafd808e2b4f8eb1bb14b7edd36e6406ea1 100644 (file)
  * Mass Ave, Cambridge, MA 02139, USA.
  */
 
-/*X*X*X*X*X*X*X**X*X*X*X*X*X*X**X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*
- *X*X*X*X*X*X*X**X*X*X*X*X*X*X**X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*
- *X*X*X*X*X*X*X**X*X*X*X*X*X*X**X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*
-
-     DO NOT CALL ANY OF THE ROUTINES IN THIS MODULE DIRECTLY.
-                       USE passdb.c INSTEAD.
-
- *X*X*X*X*X*X*X**X*X*X*X*X*X*X**X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*
- *X*X*X*X*X*X*X**X*X*X*X*X*X*X**X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*
- *X*X*X*X*X*X*X**X*X*X*X*X*X*X**X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*/
-
 #include "includes.h"
 
 extern int DEBUGLEVEL;
index bbc0ff6144bd4b65f53bdfe3b1eaca56b78212cb..c7db5744e266949bd7df420ea36a27fee8576089 100644 (file)
@@ -103,7 +103,7 @@ static char *build_print_command(int cnum, char *command, char *syscmd, char *fi
   
   string_sub(syscmd, "%p", tstr);
   
-  standard_sub(cnum,syscmd,UID_FIELD_INVALID);
+  standard_sub(cnum,syscmd);
   
   return (syscmd);
 }
@@ -1056,7 +1056,7 @@ int get_printqueue(int snum,int cnum,print_queue_struct **queue,
   pstrcpy(syscmd,lpq_command);
   string_sub(syscmd,"%p",printername);
 
-  standard_sub(cnum,syscmd,UID_FIELD_INVALID);
+  standard_sub(cnum,syscmd);
 
   sprintf(outfile,"%s/lpq.%08x",tmpdir(),str_checksum(syscmd));
   
@@ -1147,7 +1147,7 @@ void del_printqueue(int cnum,int snum,int jobid)
   pstrcpy(syscmd,lprm_command);
   string_sub(syscmd,"%p",printername);
   string_sub(syscmd,"%j",jobstr);
-  standard_sub(cnum,syscmd,UID_FIELD_INVALID);
+  standard_sub(cnum,syscmd);
 
   ret = smbrun(syscmd,NULL,False);
   DEBUG(3,("Running the command `%s' gave %d\n",syscmd,ret));  
@@ -1185,7 +1185,7 @@ void status_printjob(int cnum,int snum,int jobid,int status)
   pstrcpy(syscmd,lpstatus_command);
   string_sub(syscmd,"%p",printername);
   string_sub(syscmd,"%j",jobstr);
-  standard_sub(cnum,syscmd,UID_FIELD_INVALID);
+  standard_sub(cnum,syscmd);
 
   ret = smbrun(syscmd,NULL,False);
   DEBUG(3,("Running the command `%s' gave %d\n",syscmd,ret));  
index 48c0277165c8938ac1f35cf42504b10a03f8eda2..8be9c10a13f20263d632268b6d40b279e6d7874a 100644 (file)
@@ -85,7 +85,7 @@ static int CopyExpanded(int cnum, int snum, char** dst, char* src, int* n)
 
   StrnCpy(buf,src,sizeof(buf)/2);
   string_sub(buf,"%S",lp_servicename(snum));
-  standard_sub(cnum,buf,UID_FIELD_INVALID);
+  standard_sub(cnum,buf);
   StrnCpy(*dst,buf,*n);
   l = strlen(*dst) + 1;
   (*dst) += l;
@@ -110,7 +110,7 @@ static int StrlenExpanded(int cnum, int snum, char* s)
   if (!s) return(0);
   StrnCpy(buf,s,sizeof(buf)/2);
   string_sub(buf,"%S",lp_servicename(snum));
-  standard_sub(cnum,buf,UID_FIELD_INVALID);
+  standard_sub(cnum,buf);
   return strlen(buf) + 1;
 }
 
@@ -120,7 +120,7 @@ static char* Expand(int cnum, int snum, char* s)
   if (!s) return(NULL);
   StrnCpy(buf,s,sizeof(buf)/2);
   string_sub(buf,"%S",lp_servicename(snum));
-  standard_sub(cnum,buf,UID_FIELD_INVALID);
+  standard_sub(cnum,buf);
   return &buf[0];
 }
 
@@ -2058,7 +2058,7 @@ static BOOL api_RNetServerGetInfo(int cnum,uint16 vuid, char *param,char *data,
        SIVAL(p,6,0);
       } else {
        SIVAL(p,6,PTR_DIFF(p2,*rdata));
-       standard_sub(cnum,comment,vuid);
+       standard_sub(cnum,comment);
        StrnCpy(p2,comment,MAX(mdrcnt - struct_len,0));
        p2 = skip_string(p2,1);
       }
@@ -2584,7 +2584,7 @@ static BOOL api_WWkstaUserLogon(int cnum,uint16 vuid, char *param,char *data,
 /* JHT - By calling lp_logon_script() and standard_sub() we have */
 /* made sure all macros are fully substituted and available */
     logon_script = lp_logon_script();
-    standard_sub( cnum, logon_script, vuid );
+    standard_sub( cnum, logon_script );
     PACKS(&desc,"z", logon_script);            /* script path */
 /* End of JHT mods */
 
index 9fb506edd016560e60a07c9a7539d9c32fdaced8..24477f31ff6b7fe3204a86e751c2ba04bc5a2f5d 100644 (file)
@@ -78,7 +78,7 @@ static void msg_deliver(void)
       string_sub(s,"%s",name);
       string_sub(s,"%f",msgfrom);
       string_sub(s,"%t",msgto);
-      standard_sub(-1,s,UID_FIELD_INVALID);
+      standard_sub(-1,s);
       smbrun(s,NULL,False);
     }
 
index 6f5527714d64ff8c48ba7deeec7a52fa2ddef6d1..e4c00c141f782377408e81a8593ddba47d0eb6ae 100644 (file)
@@ -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();
index c01fa1b0520d792fcd3657a99e9901c2102d0994..a8e340e46fe308868880088f8a50d21e6e4d0e15 100644 (file)
@@ -28,7 +28,6 @@ static int initial_gid;
 
 /* what user is current? */
 struct current_user current_user;
-extern pstring sesssetup_user;
 
 pstring OriginalDir;
 
@@ -278,11 +277,6 @@ BOOL become_user(connection_struct *conn, int cnum, uint16 vuid)
   current_user.cnum = cnum;
   current_user.vuid = vuid;
 
-  /* Ensure sesssetup_user is set correctly if we are using
-     user security. */
-  if(vuser != NULL)
-    pstrcpy( sesssetup_user, vuser->requested_name);
-
   DEBUG(5,("become_user uid=(%d,%d) gid=(%d,%d)\n",
           getuid(),geteuid(),getgid(),getegid()));