*** 1.1	1992/04/12 21:27:13
--- Makefile	1992/04/12 21:29:09
***************
*** 72,81 ****
  
  # If there are remote execution facilities defined,
  # enable them with switches here (see remote-*.c).
! REMOTE =
  
  # Any extra object files your system needs.
! extras =
  
  # Comment this out if POSIX.2 glob is installed on your system
  # (it's in the GNU C Library, so if you're using that, this is
--- 72,82 ----
  
  # If there are remote execution facilities defined,
  # enable them with switches here (see remote-*.c).
! CUSTOMSSRC = /usr/local/src/icsi/pmake/customs
! REMOTE = -DCUSTOMS -I$(CUSTOMSSRC) -I$(CUSTOMSSRC)/../lib/include -I$(CUSTOMSSRC)/../lib/lst
  
  # Any extra object files your system needs.
! extras = $(CUSTOMSSRC)/customslib.o $(CUSTOMSSRC)/rpc.o $(CUSTOMSSRC)/xlog.o $(CUSTOMSSRC)/../lib/sprite/libsprite.a $(CUSTOMSSRC)../lib/lst/liblst.a
  
  # Comment this out if POSIX.2 glob is installed on your system
  # (it's in the GNU C Library, so if you're using that, this is
***************
*** 97,102 ****
--- 98,105 ----
  # Number to put on the man page filename.
  manext = l
  
+ # Install make setuid for use with customs
+ user = root
  # Install make setgid to this group so it can read /dev/kmem.
  group = kmem
  
***************
*** 139,145 ****
  
  load.o: load.c
  	$(CC) $(CFLAGS) $(LOAD_AVG) -c load.c
! remote.o: remote.c
  	$(CC) $(CFLAGS) $(REMOTE) -c remote.c
  
  # For some losing Unix makes.
--- 142,148 ----
  
  load.o: load.c
  	$(CC) $(CFLAGS) $(LOAD_AVG) -c load.c
! remote.o: remote.c remote-stub.c remote-cstms.c
  	$(CC) $(CFLAGS) $(REMOTE) -c remote.c
  
  # For some losing Unix makes.
***************
*** 160,167 ****
  $(bindir)/$(instname): make
  	cp make $@.new
  # These are necessary for load-average checking to work on most Unix machines.
! 	chgrp $(group) $@.new
! 	chmod g+s $@.new
  	mv $@.new $@
  
  $(mandir)/$(instname).$(manext): make.man
--- 163,176 ----
  $(bindir)/$(instname): make
  	cp make $@.new
  # These are necessary for load-average checking to work on most Unix machines.
! 	if [ "$(group)" ]; then \
! 		chgrp $(group) $@.new ; \
! 		chmod g+s $@.new ; \
! 	fi
! 	if [ "$(user)" ]; then \
! 		chown $(user) $@.new ; \
! 		chmod u+s $@.new ; \
! 	fi
  	mv $@.new $@
  
  $(mandir)/$(instname).$(manext): make.man
*** 1.1	1992/04/12 06:02:06
--- job.c	1992/04/12 06:02:24
***************
*** 213,219 ****
  }
  
  /* Unblock the child termination signal and fatal signals.  */
! static void
  unblock_signals ()
  {
  #ifdef	USG
--- 213,219 ----
  }
  
  /* Unblock the child termination signal and fatal signals.  */
! void
  unblock_signals ()
  {
  #ifdef	USG
*** 1.1	1992/04/12 06:11:02
--- job.h	1992/04/12 06:11:38
***************
*** 26,31 ****
--- 26,32 ----
  extern void new_job ();
  extern void wait_for_children ();
  extern void push_signals_blocked_p (), pop_signals_blocked_p ();
+ extern void unblock_signals ();
  
  extern char **construct_command_argv ();
  extern void child_execute_job ();
*** 1.1	1992/04/11 04:52:27
--- load.c	1992/04/11 04:59:08
***************
*** 152,157 ****
--- 152,162 ----
  #define	LDAV_CVT	(((double) load) / 2048.0)
  #endif
  
+ #if	defined(sun)
+ #include <sys/param.h>
+ #define	LDAV_CVT	(((double) load) / FSCALE)
+ #endif
+ 
  #if	defined(ultrix) && defined(vax)
  #define	LDAV_TYPE	double
  #define	LDAV_CVT	(load)
*** 1.1	1992/04/11 05:52:50
--- remote-cstms.c	1992/04/12 08:12:22
***************
*** 17,39 ****
  
  #include "make.h"
  #include "commands.h"
  #include "customs.h"
  #include <sys/time.h>
  
  
  char *remote_description = "Customs";
  
  
  /* ExportPermit gotten by start_remote_job_p, and used by start_remote_job.  */
  static ExportPermit permit;
  
  /* Return nonzero if the next job should be done remotely.  */
  
  int
  start_remote_job_p ()
  {
!   if (Customs_Host (EXPORT_SAME, &permit) != RPC_SUCCESS)
!     return 0;
  
    return !CUSTOMS_FAIL (&permit.addr);
  }
--- 17,85 ----
  
  #include "make.h"
  #include "commands.h"
+ #include "job.h"
  #include "customs.h"
  #include <sys/time.h>
+ #include <netdb.h>
  
  
  char *remote_description = "Customs";
  
+ /* Program to monitor remote job.  Use absolute path to cut some overhead. */
+ #define EXPORT	"/usr/local/bin/export"
  
  /* ExportPermit gotten by start_remote_job_p, and used by start_remote_job.  */
  static ExportPermit permit;
  
+ static int remoteInit = 0;
+ static int noExport = 0;
+ 
+ /* Initialize remote excecution system. */
+ static void
+ remote_init ()
+ {
+   /* We may need to be root to make customs believe our uid.  In that case
+    * gnumake should be installed suid root.  */
+   make_access ();
+ 
+   /*
+    * Check for customs daemon.  Implicitly initializes customslib and creates
+    * socket to local daemon.
+    */
+   if (Customs_Ping() != RPC_SUCCESS)
+       noExport = 1;
+ 
+   remoteInit = 1;
+   user_access ();
+ 
+   return;
+ }
+ 
  /* Return nonzero if the next job should be done remotely.  */
  
  int
  start_remote_job_p ()
  {
!   Rpc_Stat status;
! 
!   if (!remoteInit)
!       remote_init ();
! 
!   if (noExport)
!       return 0;
! 
!   /* the first job should run locally, or, if the -l flag is given, we use
!      that as clue as to how many local jobs should be scheduled locally */
!   if (max_load_average < 0 && job_slots_used == 0
!       || job_slots_used < max_load_average)
!      return 0;
! 
!   status = Customs_Host (EXPORT_SAME, &permit);
!   if (status != RPC_SUCCESS)
!     {
!       error ("exporting: %s", Rpc_ErrorMessage (status));
!       return 0;
!     }
  
    return !CUSTOMS_FAIL (&permit.addr);
  }
***************
*** 58,63 ****
--- 104,110 ----
    extern int vfork (), execve ();
    PATH_VAR (cwd);
    char waybill[MAX_DATA_SIZE], msg[128];
+   WayBill *wb;
    struct timeval timeout;
    struct sockaddr_in sin;
    int len;
***************
*** 72,77 ****
--- 119,130 ----
        return 1;
      }
  
+   if (Customs_NormPath(cwd, sizeof(cwd)) < 0)
+     {
+       error ("exporting: path normalization failed: %s", cwd);
+       return 1;
+     }
+ 
    /* Create the return socket.  */
    retsock = Rpc_UdpCreate (True, 0);
    if (retsock < 0)
***************
*** 97,102 ****
--- 150,161 ----
    len = Customs_MakeWayBill (&permit, cwd, argv[0], argv,
  			     environ, retport, waybill);
  
+   /* Fix up the read uid and gid in the waybill to compensate for our own
+      suid/sgid status.  */
+   wb = (WayBill *)waybill;
+   wb->ruid = wb->euid;
+   wb->rgid = wb->egid;
+ 
    /* Send the request to the server, timing out in 20 seconds.  */
    timeout.tv_usec = 0;
    timeout.tv_sec = 20;
***************
*** 121,126 ****
--- 180,202 ----
        error ("CUSTOMS_IMPORT: %s", msg);
        return 1;
      }
+   else
+     {
+       struct hostent *he;
+ 
+       he = gethostbyaddr(&permit.addr,
+ 			 sizeof(permit.addr),
+ 			 AF_INET);
+       if (he == (struct hostent *)NULL) {
+ 	  error("*** exported to %s (id %u)",
+ 		InetNtoA(permit.addr),
+ 		permit.id);
+       } else {
+ 	  error("*** exported to %s (id %u)",
+ 		he->h_name,
+ 		permit.id);
+       }
+     }
  
    fflush (stdout);
    fflush (stderr);
***************
*** 137,148 ****
        /* Child side.  Run `export' to handle the connection.  */
        static char sock_buf[20], retsock_buf[20], id_buf[20];
        static char *new_argv[6] =
! 	{ "export", "-id", sock_buf, retsock_buf, id_buf, 0 };
  
        /* Set up the arguments.  */
        (void) sprintf (sock_buf, "%d", sock);
        (void) sprintf (retsock_buf, "%d", retsock);
        (void) sprintf (id_buf, "%x", permit.id);
  
        /* Run the command.  */
        (void) execvp (new_argv[0], new_argv);
--- 213,230 ----
        /* Child side.  Run `export' to handle the connection.  */
        static char sock_buf[20], retsock_buf[20], id_buf[20];
        static char *new_argv[6] =
! 	{ EXPORT, "-id", sock_buf, retsock_buf, id_buf, 0 };
  
        /* Set up the arguments.  */
        (void) sprintf (sock_buf, "%d", sock);
        (void) sprintf (retsock_buf, "%d", retsock);
        (void) sprintf (id_buf, "%x", permit.id);
+ 
+       /* Don't block signals for the new process.  */
+       unblock_signals ();
+ 
+       /* Be the user, permanently.  */
+       child_access ();
  
        /* Run the command.  */
        (void) execvp (new_argv[0], new_argv);
*** 1.1	1992/09/28 18:19:00
--- make.h	1992/09/28 18:20:48
***************
*** 116,123 ****
  
  #endif	/* USG.  */
  
! extern char *malloc (), *realloc ();
  extern void free ();
  
  #endif	/* Standard headers.  */
  
--- 116,128 ----
  
  #endif	/* USG.  */
  
! #ifdef __STDC__
! extern void *malloc (), *realloc ();
  extern void free ();
+ #else
+ extern char *malloc (), *realloc ();
+ extern int free ();
+ #endif
  
  #endif	/* Standard headers.  */
  
