Source-Changes-HG archive

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

[src/trunk]: src/lib/libutil - Simplify code path.



details:   https://anonhg.NetBSD.org/src/rev/12be120d7447
branches:  trunk
changeset: 497077:12be120d7447
user:      ad <ad%NetBSD.org@localhost>
date:      Mon Sep 18 16:36:33 2000 +0000

description:
- Simplify code path.
- Make the first argument to secure_path() constant.
- KNF.

diffstat:

 lib/libutil/secure_path.3 |   4 ++--
 lib/libutil/securepath.c  |  26 ++++++++++++--------------
 2 files changed, 14 insertions(+), 16 deletions(-)

diffs (73 lines):

diff -r 04100d713261 -r 12be120d7447 lib/libutil/secure_path.3
--- a/lib/libutil/secure_path.3 Mon Sep 18 16:27:24 2000 +0000
+++ b/lib/libutil/secure_path.3 Mon Sep 18 16:36:33 2000 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: secure_path.3,v 1.1 2000/07/07 11:05:07 itojun Exp $
+.\"    $NetBSD: secure_path.3,v 1.2 2000/09/18 16:36:33 ad Exp $
 .\"
 .\" Copyright (c) 1996,1997 Berkeley Software Design, Inc. All rights reserved.
 .\"
@@ -43,7 +43,7 @@
 .Sh SYNOPSIS
 .Fd #include <util.h>
 .Ft int
-.Fn secure_path "char *path"
+.Fn secure_path "const char *path"
 .Sh DESCRIPTION
 The
 .Fn secure_path
diff -r 04100d713261 -r 12be120d7447 lib/libutil/securepath.c
--- a/lib/libutil/securepath.c  Mon Sep 18 16:27:24 2000 +0000
+++ b/lib/libutil/securepath.c  Mon Sep 18 16:36:33 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: securepath.c,v 1.3 2000/07/05 11:46:42 ad Exp $        */
+/*     $NetBSD: securepath.c,v 1.4 2000/09/18 16:36:33 ad Exp $        */
 
 /*-
  * Copyright (c) 1995,1997 Berkeley Software Design, Inc. All rights reserved.
@@ -36,7 +36,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: securepath.c,v 1.3 2000/07/05 11:46:42 ad Exp $");
+__RCSID("$NetBSD: securepath.c,v 1.4 2000/09/18 16:36:33 ad Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/types.h>
@@ -46,7 +46,7 @@
 #include <syslog.h>
 
 int
-secure_path(char *path)
+secure_path(const char *path)
 {
        struct stat sb;
 
@@ -54,18 +54,16 @@
         * If not a regular file, or is owned/writeable by someone
         * other than root, quit.
         */
-       if (lstat(path, &sb) < 0) {
-               /* syslog(LOG_ERR, "cannot stat %s: %m", path); */
-               return (-1);
-       } else if (!S_ISREG(sb.st_mode)) {
+       if (lstat(path, &sb) < 0)
+               /* syslog(LOG_ERR, "cannot stat %s: %m", path) */;
+       else if (!S_ISREG(sb.st_mode))
                syslog(LOG_ERR, "%s: not a regular file", path);
-               return (-1);
-       } else if (sb.st_uid != 0) {
+       else if (sb.st_uid != 0)
                syslog(LOG_ERR, "%s: not owned by root", path);
-               return (-1);
-       } else if (sb.st_mode & (S_IWGRP | S_IWOTH)) {
+       else if ((sb.st_mode & (S_IWGRP | S_IWOTH)) != 0)
                syslog(LOG_ERR, "%s: writeable by non-root", path);
-               return (-1);
-       }
-       return (0);
+       else
+               return (0);
+
+       return (-1);
 }



Home | Main Index | Thread Index | Old Index