BSD 4_3_Reno release
[unix-history] / usr / src / usr.bin / sccs / sccs.c
index a974465..41d6473 100644 (file)
@@ -3,16 +3,18 @@
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms are permitted
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
+ * provided that: (1) source distributions retain this entire copyright
+ * notice and comment, and (2) distributions including binaries display
+ * the following acknowledgement:  ``This product includes software
+ * developed by the University of California, Berkeley and its contributors''
+ * in the documentation or other materials provided with the distribution
+ * and in all advertising materials mentioning features or use of this
+ * software. Neither the name of the University nor the names of its
+ * contributors may be used to endorse or promote products derived
  * from this software without specific prior written permission.
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * from this software without specific prior written permission.
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
@@ -22,7 +24,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)sccs.c     5.6 (Berkeley) %G%";
+static char sccsid[] = "@(#)sccs.c     5.9 (Berkeley) 6/1/90";
 #endif /* not lint */
 
 # include <stdio.h>
 #endif /* not lint */
 
 # include <stdio.h>
@@ -33,6 +35,7 @@ static char sccsid[] = "@(#)sccs.c    5.6 (Berkeley) %G%";
 # include <signal.h>
 # include <sysexits.h>
 # include <pwd.h>
 # include <signal.h>
 # include <sysexits.h>
 # include <pwd.h>
+# include "pathnames.h"
 
 /*
 **  SCCS.C -- human-oriented front end to the SCCS system.
 
 /*
 **  SCCS.C -- human-oriented front end to the SCCS system.
@@ -138,10 +141,6 @@ static char sccsid[] = "@(#)sccs.c 5.6 (Berkeley) %G%";
 # define MYNAME                "sccs"  /* name used for printing errors */
 # endif NOT MYNAME
 
 # define MYNAME                "sccs"  /* name used for printing errors */
 # endif NOT MYNAME
 
-# ifndef PROGPATH
-# define PROGPATH(name)        "/usr/local/name"       /* place to find binaries */
-# endif PROGPATH
-
 /****************  End of Configuration Information  ****************/
 \f
 typedef char   bool;
 /****************  End of Configuration Information  ****************/
 \f
 typedef char   bool;
@@ -482,7 +481,7 @@ command(argv, forkflag, arg0)
          case SHELL:           /* call a shell file */
                *ap = cmd->sccspath;
                *--ap = "sh";
          case SHELL:           /* call a shell file */
                *ap = cmd->sccspath;
                *--ap = "sh";
-               rval = callprog("/bin/sh", cmd->sccsflags, ap, forkflag);
+               rval = callprog(_PATH_BSHELL, cmd->sccsflags, ap, forkflag);
                break;
 
          case PROG:            /* call an sccs prog */
                break;
 
          case PROG:            /* call an sccs prog */
@@ -803,6 +802,7 @@ makefile(name)
        char buf[3*FBUFSIZ];
        extern char *malloc();
        extern char *rindex();
        char buf[3*FBUFSIZ];
        extern char *malloc();
        extern char *rindex();
+       extern bool safepath();
        extern bool isdir();
        register char *q;
 
        extern bool isdir();
        register char *q;
 
@@ -813,23 +813,21 @@ makefile(name)
                p++;
 
        /*
                p++;
 
        /*
-       **  See if the name can be used as-is.
+       **  Check to see that the path is "safe", i.e., that we
+       **  are not letting some nasty person use the setuid part
+       **  of this program to look at or munge some presumably
+       **  hidden files.
        */
 
        */
 
-       if (SccsPath[0] != '/' || name[0] == '/' || strncmp(name, "./", 2) == 0)
-       {
-               if (strncmp(p, "s.", 2) == 0)
-                       return (name);
-               if (isdir(name))
-                       return (name);
-       }
+       if (SccsDir[0] == '/' && !safepath(name))
+               return (NULL);
 
        /*
 
        /*
-       **  Create the actual pathname.
+       **  Create the base pathname.
        */
 
        /* first the directory part */
        */
 
        /* first the directory part */
-       if (name[0] != '/')
+       if (SccsDir[0] != '\0' && name[0] != '/' && strncmp(name, "./", 2) != 0)
        {
                gstrcpy(buf, SccsDir, sizeof(buf));
                gstrcat(buf, "/", sizeof(buf));
        {
                gstrcpy(buf, SccsDir, sizeof(buf));
                gstrcat(buf, "/", sizeof(buf));
@@ -838,9 +836,13 @@ makefile(name)
                gstrcpy(buf, "", sizeof(buf));
        
        /* then the head of the pathname */
                gstrcpy(buf, "", sizeof(buf));
        
        /* then the head of the pathname */
-       strncat(buf, name, p - name);
+       gstrncat(buf, name, p - name, sizeof(buf));
        q = &buf[strlen(buf)];
        q = &buf[strlen(buf)];
-       strcpy(q, p);
+
+       /* now copy the final part of the name, in case useful */
+       gstrcpy(q, p, sizeof(buf));
+
+       /* so is it useful? */
        if (strncmp(p, "s.", 2) != 0 && !isdir(buf))
        {
                /* sorry, no; copy the SCCS pathname & the "s." */
        if (strncmp(p, "s.", 2) != 0 && !isdir(buf))
        {
                /* sorry, no; copy the SCCS pathname & the "s." */
@@ -854,10 +856,22 @@ makefile(name)
        /* if i haven't changed it, why did I do all this? */
        if (strcmp(buf, name) == 0)
                p = name;
        /* if i haven't changed it, why did I do all this? */
        if (strcmp(buf, name) == 0)
                p = name;
+       else
+       {
+               /* but if I have, squirrel it away */
+               p = malloc(strlen(buf) + 1);
+               if (p == NULL)
+               {
+                       perror("Sccs: no mem");
+                       exit(EX_OSERR);
+               }
+               strcpy(p, buf);
+       }
 
 
-       return (stat(name, &stbuf) >= 0 && (stbuf.st_mode & S_IFMT) == S_IFDIR);
+       return (p);
 }
 }
-\f/*
+\f
+/*
 **  ISDIR -- return true if the argument is a directory.
 **
 **     Parameters:
 **  ISDIR -- return true if the argument is a directory.
 **
 **     Parameters:
@@ -1144,7 +1158,7 @@ unedit(fn)
 {
        register FILE *pfp;
        char *cp, *pfn;
 {
        register FILE *pfp;
        char *cp, *pfn;
-       static char tfn[] = "/tmp/sccsXXXXX";
+       static char tfn[] = _PATH_TMP;
        FILE *tfp;
        register char *q;
        bool delete = FALSE;
        FILE *tfp;
        register char *q;
        bool delete = FALSE;
@@ -1305,33 +1319,9 @@ dodiff(getv, gfile)
        register int pid;
        auto int st;
        extern int errno;
        register int pid;
        auto int st;
        extern int errno;
-       int (*osig)();
-       register char *p;
-       register char **ap;
-       bool makescript = FALSE;
+       sig_t osig;
 
 
-       for (ap = getv; *ap != NULL; ap++)
-       {
-               p = *ap;
-               if (p[0] == '-')
-               {
-                       switch (p[1])
-                       {
-                         case 'E':
-                               p[1] = 'e';
-                               makescript = TRUE;
-                               break;
-                       }
-               }
-       }
-
-       if (makescript)
-       {
-               printf("sccs edit %s\n", gfile);
-               printf("ed - %s << 'xxEOFxx'\n", gfile);
-       }
-       else
-               printf("\n------- %s -------\n", gfile);
+       printf("\n------- %s -------\n", gfile);
        fflush(stdout);
 
        /* create context for diff to run in */
        fflush(stdout);
 
        /* create context for diff to run in */
@@ -1368,15 +1358,6 @@ dodiff(getv, gfile)
                }
                command(&getv[1], FALSE, "-diff:elsfhbC");
        }
                }
                command(&getv[1], FALSE, "-diff:elsfhbC");
        }
-
-       if (makescript)
-       {
-               printf("w\n");
-               printf("q\n");
-               printf("'xxEOFxx'\n");
-               printf("sccs delta %s\n", gfile);
-       }
-
        return (rval);
 }
 \f
        return (rval);
 }
 \f