From: barrett@daisy.ee.und.ac.za (Alan P Barrett)
Newsgroups: comp.sys.hp
Subject: Re: Has anyone ported "op" to HP-UX ...?
Date: 30 Dec 1992 11:53:24 +0200
Organization: Dept. Elec. Eng., Univ. Natal, Durban, S. Africa
NNTP-Posting-Host: daisy.ee.und.ac.za

Here are the diffs between the alpha version of op posted to the net some
time ago, and my version which runs on HP-UX 7.0.  A later (non-alpha)
version of op was recently posted to one of the sources groups, but I
haven't integrated my changes into it.

--apb
Alan Barrett, Dept. of Electronic Eng., Univ. of Natal, Durban, South Africa
RFC822: barrett@ee.und.ac.za                    Bang: m2xenix!undeed!barrett

diff -u3 +recursive orig/Makefile apb/Makefile
--- orig/Makefile	Wed Dec 30 11:46:43 1992
+++ apb/Makefile	Wed Dec 30 11:46:58 1992
@@ -1,11 +1,12 @@
 CFLAGS=-g -I.
 
-VPF = vfprintf.o
+# VPF = vfprintf.o
 REG = regexp.o regsub.o regerror.o
 OBJ = lex.o main.o atov.o $(REG) $(VPF)
+LIBS = -lBSD
 
 op: $(OBJ) $(REG)
-	$(CC) $(CFLAGS) -o $@ $(OBJ) -ll
+	$(CC) $(CFLAGS) -o $@ $(OBJ) -ll $(LIBS)
 
 clean:
 	rm -f $(OBJ) op core 
diff -u3 +recursive orig/main.c apb/main.c
--- orig/main.c	Wed Dec 30 11:46:45 1992
+++ apb/main.c	Wed Dec 30 11:46:59 1992
@@ -17,6 +17,16 @@
 #include "defs.h"
 #include "regexp.h"
 
+/* I don't know why they use both re_comp and regcomp.
+ * I am not even sure what re_comp and re_exec do.
+ * I assume that re_comp magicly keeps the compiled regexp for use
+ * by re_exec.
+ * --apb */
+static regexp *re_reg = NULL;
+#define re_comp(pat) ((re_reg ? (void)free(re_reg) : (void)0), \
+		      ((re_reg = regcomp(pat))==NULL))
+#define re_exec(str) (regexec(re_reg,(str)))
+
 #ifndef LOG_AUTH
 /*
 **  Pmax's don't have LOG_AUTH
@@ -373,20 +383,27 @@
 	char		*new_argv[MAXARG];
 	char		str[MAXSTRLEN], buf[4*MAXSTRLEN];
 
-	if ((cp = FindOpt(cmd, "uid")) == NULL) {
-		if (setuid(0) < 0)
-			fatal("Unable to set uid to default", cp);
+	/* The order of some of these actions is important.
+	 *
+	 * chroot and setgroups don't work unless we are root, so they
+	 * must happen before setuid.
+	 * chdir should probably happen after setgroups and setuid so that
+	 * they will fail if the target user doesn't have permission to
+	 * do them.
+	 */
+
+	if ((cp = FindOpt(cmd, "chroot")) == NULL) {
+		;		/* don't have a default */
 	} else {
-		if ((pw = getpwnam(cp)) == NULL) {
-			if (setuid(atoi(cp)) < 0)
-				fatal("Unable to set uid to %s", cp);
-		}
-		if (setuid(pw->pw_uid) < 0)
-			fatal("Unable to set uid to %s", cp);
+		if (chroot(cp) < 0)
+			fatal("Unable to chroot to %s", cp);
 	}
 
 	if ((cp = FindOpt(cmd, "gid")) == NULL) {
 		;		/* don't have a default */
+				/* XXX The default set of gids should
+				 * probably be based on what would happen
+				 * if the target user really logged in */
 	} else {
 		for (cp=GetField(cp, str); cp!=NULL; cp=GetField(cp, str)) {
 			if ((gr = getgrnam(cp)) != NULL)
@@ -398,6 +415,18 @@
 			fatal("Set group failed");
 	}
 
+	if ((cp = FindOpt(cmd, "uid")) == NULL) {
+		if (setuid(0) < 0)
+			fatal("Unable to set uid to default", cp);
+	} else {
+		if ((pw = getpwnam(cp)) == NULL) {
+			if (setuid(atoi(cp)) < 0)
+				fatal("Unable to set uid to %s", cp);
+		}
+		if (setuid(pw->pw_uid) < 0)
+			fatal("Unable to set uid to %s", cp);
+	}
+
 	if ((cp = FindOpt(cmd, "umask")) == NULL) {
 		if (umask(0022) < 0)
 			fatal("Unable to set umask to default");
@@ -404,13 +433,6 @@
 	} else {
 		if (umask(atov(cp, 8)) < 0)
 			fatal("Unable to set umask to %s", cp);
-	}
-
-	if ((cp = FindOpt(cmd, "chroot")) == NULL) {
-		;		/* don't have a default */
-	} else {
-		if (chroot(cp) < 0)
-			fatal("Unable to chroot to %s", cp);
 	}
 
 	if ((cp = FindOpt(cmd, "dir")) == NULL) {
Newsgroups: comp.sys.hp,comp.unix.admin