document distributed with 4.1BSD
[unix-history] / usr / src / usr.bin / ex / ex.c
index 96034c3..1720e71 100644 (file)
@@ -1,5 +1,19 @@
-/* Copyright (c) 1981 Regents of the University of California */
-static char *sccsid = "@(#)ex.c        7.2     %G%";
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+char *copyright =
+"@(#) Copyright (c) 1980 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif not lint
+
+#ifndef lint
+static char *sccsid = "@(#)ex.c        7.5 (Berkeley) %G%";
+#endif not lint
+
 #include "ex.h"
 #include "ex_argv.h"
 #include "ex_temp.h"
 #include "ex.h"
 #include "ex_argv.h"
 #include "ex_temp.h"
@@ -307,8 +321,11 @@ main(ac, av)
                        commands(1,1);
                else {
                        globp = 0;
                        commands(1,1);
                else {
                        globp = 0;
-                       if ((cp = getenv("HOME")) != 0 && *cp)
-                               source(strcat(strcpy(genbuf, cp), "/.exrc"), 1);
+                       if ((cp = getenv("HOME")) != 0 && *cp) {
+                               (void) strcat(strcpy(genbuf, cp), "/.exrc");
+                               if (iownit(genbuf))
+                                       source(genbuf, 1);
+                       }
                }
                /*
                 * Allow local .exrc too.  This loses if . is $HOME,
                }
                /*
                 * Allow local .exrc too.  This loses if . is $HOME,
@@ -316,7 +333,8 @@ main(ac, av)
                 * like putting a version command in .exrc.  Besides,
                 * they should be using EXINIT, not .exrc, right?
                 */
                 * like putting a version command in .exrc.  Besides,
                 * they should be using EXINIT, not .exrc, right?
                 */
-               source(".exrc", 1);
+                if (iownit(".exrc"))
+                       source(".exrc", 1);
        }
        init(); /* moved after prev 2 chunks to fix directory option */
 
        }
        init(); /* moved after prev 2 chunks to fix directory option */
 
@@ -416,3 +434,18 @@ register char *p;
                        r = p+1;
        return(r);
 }
                        r = p+1;
        return(r);
 }
+
+/*
+ * Check ownership of file.  Return nonzero if it exists and is owned by the
+ * user or the option sourceany is used
+ */
+iownit(file)
+char *file;
+{
+       struct stat sb;
+
+       if (stat(file, &sb) == 0 && (value(SOURCEANY) || sb.st_uid == getuid()))
+               return(1);
+       else
+               return(0);
+}