summaryrefslogtreecommitdiff
path: root/lib/libutil
diff options
context:
space:
mode:
authorad <ad@NetBSD.org>2000-09-18 16:36:33 +0000
committerad <ad@NetBSD.org>2000-09-18 16:36:33 +0000
commit8b2c913445ca82d8dcdca04a420061561a566cf2 (patch)
treef192c49843a528915c46fd569ade4ab48a4444f5 /lib/libutil
parent0940cdc61db3d2f163615230b77b36647f431545 (diff)
- Simplify code path.
- Make the first argument to secure_path() constant. - KNF.
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/secure_path.34
-rw-r--r--lib/libutil/securepath.c26
2 files changed, 14 insertions, 16 deletions
diff --git a/lib/libutil/secure_path.3 b/lib/libutil/secure_path.3
index daa839576b9..fe2972e18d9 100644
--- a/lib/libutil/secure_path.3
+++ b/lib/libutil/secure_path.3
@@ -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 --git a/lib/libutil/securepath.c b/lib/libutil/securepath.c
index 7e6e3b97e48..73f398e3c23 100644
--- a/lib/libutil/securepath.c
+++ b/lib/libutil/securepath.c
@@ -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 @@ __RCSID("$NetBSD: securepath.c,v 1.3 2000/07/05 11:46:42 ad Exp $");
#include <syslog.h>
int
-secure_path(char *path)
+secure_path(const char *path)
{
struct stat sb;
@@ -54,18 +54,16 @@ secure_path(char *path)
* 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);
}