Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/regress/sys/kern/getcwd fail more gracefully if not root



details:   https://anonhg.NetBSD.org/src/rev/515bc9a629b0
branches:  trunk
changeset: 467612:515bc9a629b0
user:      sommerfe <sommerfe%NetBSD.org@localhost>
date:      Fri Mar 26 13:14:12 1999 +0000

description:
fail more gracefully if not root

diffstat:

 regress/sys/kern/getcwd/Makefile |   6 +++++-
 regress/sys/kern/getcwd/getcwd.c |  27 ++++++++++++++++++++++++---
 2 files changed, 29 insertions(+), 4 deletions(-)

diffs (83 lines):

diff -r c6412be75bcf -r 515bc9a629b0 regress/sys/kern/getcwd/Makefile
--- a/regress/sys/kern/getcwd/Makefile  Fri Mar 26 13:12:43 1999 +0000
+++ b/regress/sys/kern/getcwd/Makefile  Fri Mar 26 13:14:12 1999 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.1 1999/03/22 18:14:39 sommerfe Exp $
+#      $NetBSD: Makefile,v 1.2 1999/03/26 13:14:12 sommerfe Exp $
 
 PROG=  getcwd
 SRCS=  getcwd.c old_getcwd.c
@@ -8,5 +8,9 @@
 
 regress:
        @./getcwd -r
+       @./getcwd -p
+
+long-regress:
+       @find /usr -type d -print | ./getcwd -s
 
 .include <bsd.prog.mk>
diff -r c6412be75bcf -r 515bc9a629b0 regress/sys/kern/getcwd/getcwd.c
--- a/regress/sys/kern/getcwd/getcwd.c  Fri Mar 26 13:12:43 1999 +0000
+++ b/regress/sys/kern/getcwd/getcwd.c  Fri Mar 26 13:14:12 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: getcwd.c,v 1.1 1999/03/22 18:14:39 sommerfe Exp $ */
+/* $NetBSD: getcwd.c,v 1.2 1999/03/26 13:14:12 sommerfe Exp $ */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -41,6 +41,7 @@
  */
 
 #include <assert.h>
+#include <err.h>
 #include <errno.h>
 #include <pwd.h>
 #include <stdio.h>
@@ -238,6 +239,12 @@
 {
        char kbuf[1024];
        
+       if (geteuid() != 0) 
+         {
+           fprintf(stderr, "Not root; skipping permission tests\n");
+           return;         
+         }
+           
        mkdir ("/tmp/permdir", 0700);
        mkdir ("/tmp/permdir/subdir", 0755);
        chdir ("/tmp/permdir/subdir");
@@ -258,6 +265,12 @@
        int pid, status;
        char kbuf[1024];
        
+       if (geteuid() != 0) 
+         {
+           fprintf(stderr, "Not root; skipping chroot tests\n");
+           return;
+         }
+
        /* XXX we need fchroot to do this properly.. */
        mkdir ("/tmp/chrootdir", 0755);
        mkdir ("/tmp/chrootdir/subdir", 0755);
@@ -417,10 +430,18 @@
                char *cp = strrchr(buf, '\n');
                if (cp) *cp = '\0';
 
-               chdir (buf);
+               if (chdir (buf) < 0) {
+                       warn("Can't change directory to %s", buf);
+                       continue;
+               }
+               
 
                cp = old_getcwd (ubuf, MAXPATHLEN);
-               assert (strcmp (buf, ubuf) == 0);               
+               if (strcmp(buf, ubuf) != 0) {
+                       warnx("In %s, old_getcwd says %s\n",
+                           buf, ubuf);
+               }
+
 
                CHECK(buf, __getcwd (kbuf, MAXPATHLEN),
                    strlen(ubuf)+1, 0);



Home | Main Index | Thread Index | Old Index