summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiklas Hallqvist <niklas@cvs.openbsd.org>2000-10-13 13:22:03 +0000
committerNiklas Hallqvist <niklas@cvs.openbsd.org>2000-10-13 13:22:03 +0000
commit53dee6c83c078c4fad978c6719a51078220f17d1 (patch)
treebd40fbb3069bf9b7f6cd0073d7cd56eb96b47a69
parente08ecb7d4496d04875f0ec5ee1f094068401c284 (diff)
regress/b2n/Makefile: Merge with EOM 1.12
regress/ec2n/Makefile: Merge with EOM 1.9 conf.c: Merge with EOM 1.40 util.c: Merge with EOM 1.17 author: ho Add file permission check to private key file. Split out check function to util.c.
-rw-r--r--sbin/isakmpd/conf.c30
-rw-r--r--sbin/isakmpd/regress/b2n/Makefile6
-rw-r--r--sbin/isakmpd/regress/ec2n/Makefile6
-rw-r--r--sbin/isakmpd/util.c42
4 files changed, 53 insertions, 31 deletions
diff --git a/sbin/isakmpd/conf.c b/sbin/isakmpd/conf.c
index 688ed85ef33..a11970988d5 100644
--- a/sbin/isakmpd/conf.c
+++ b/sbin/isakmpd/conf.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: conf.c,v 1.20 2000/10/13 12:19:57 niklas Exp $ */
-/* $EOM: conf.c,v 1.39 2000/10/13 12:20:35 ho Exp $ */
+/* $OpenBSD: conf.c,v 1.21 2000/10/13 13:22:01 niklas Exp $ */
+/* $EOM: conf.c,v 1.40 2000/10/13 13:04:16 ho Exp $ */
/*
* Copyright (c) 1998, 1999, 2000 Niklas Hallqvist. All rights reserved.
@@ -51,6 +51,7 @@
#include "app.h"
#include "conf.h"
#include "log.h"
+#include "util.h"
struct conf_trans {
TAILQ_ENTRY (conf_trans) link;
@@ -500,36 +501,19 @@ conf_reinit (void)
{
struct conf_binding *cb = 0;
int fd, i, trans;
- struct stat st;
off_t sz;
char *new_conf_addr = 0;
+ if (check_file_secrecy (conf_path, &sz))
+ return;
+
fd = open (conf_path, O_RDONLY);
if (fd == -1)
{
log_error ("conf_reinit: open (\"%s\", O_RDONLY) failed", conf_path);
return;
}
- if (fstat (fd, &st) == -1)
- {
- log_error ("conf_reinit: fstat (%d, &st) failed", fd);
- goto fail;
- }
- if (st.st_uid != geteuid () && st.st_uid != getuid ())
- {
- log_print ("conf_reinit: not loading %s - file owner is not process "
- "user", conf_path);
- close (fd);
- return;
- }
- if ((st.st_mode & (S_IRWXG | S_IRWXO)) != 0)
- {
- log_print ("conf_reinit: not loading %s - too open permissions",
- conf_path);
- close (fd);
- return;
- }
- sz = st.st_size;
+
new_conf_addr = malloc (sz);
if (!new_conf_addr)
{
diff --git a/sbin/isakmpd/regress/b2n/Makefile b/sbin/isakmpd/regress/b2n/Makefile
index d42653b32ca..6bdc12fb5dd 100644
--- a/sbin/isakmpd/regress/b2n/Makefile
+++ b/sbin/isakmpd/regress/b2n/Makefile
@@ -1,10 +1,10 @@
-# $OpenBSD: Makefile,v 1.5 2000/04/07 22:21:55 niklas Exp $
-# $EOM: Makefile,v 1.11 2000/04/07 19:20:24 niklas Exp $
+# $OpenBSD: Makefile,v 1.6 2000/10/13 13:22:01 niklas Exp $
+# $EOM: Makefile,v 1.12 2000/10/13 13:04:17 ho Exp $
# Test some math
PROG= b2ntest
-SRCS= math_2n.c b2ntest.c util.c sysdep.c
+SRCS= b2ntest.c log.c math_2n.c sysdep.c util.c
NOMAN=
TOPSRC= ${.CURDIR}/../..
TOPOBJ!= cd ${TOPSRC}; printf "all:\n\t@pwd\n" |${MAKE} -f-
diff --git a/sbin/isakmpd/regress/ec2n/Makefile b/sbin/isakmpd/regress/ec2n/Makefile
index d75d7cc0a02..b21842abb1d 100644
--- a/sbin/isakmpd/regress/ec2n/Makefile
+++ b/sbin/isakmpd/regress/ec2n/Makefile
@@ -1,10 +1,10 @@
-# $OpenBSD: Makefile,v 1.5 2000/04/07 22:06:11 niklas Exp $
-# $EOM: Makefile,v 1.8 2000/03/28 21:22:06 ho Exp $
+# $OpenBSD: Makefile,v 1.6 2000/10/13 13:22:01 niklas Exp $
+# $EOM: Makefile,v 1.9 2000/10/13 13:04:17 ho Exp $
# Test EC2N:
PROG= ec2ntest
-SRCS= math_2n.c math_ec2n.c ec2ntest.c util.c sysdep.c
+SRCS= math_2n.c math_ec2n.c ec2ntest.c log.c sysdep.c util.c
TOPSRC= ${.CURDIR}/../..
TOPOBJ!= cd ${TOPSRC}; printf "all:\n\t@pwd\n" |${MAKE} -f-
OS!= awk '/^OS=/ { print $$2 }' ${.CURDIR}/../../Makefile
diff --git a/sbin/isakmpd/util.c b/sbin/isakmpd/util.c
index 7201d2f21dd..666d45b219e 100644
--- a/sbin/isakmpd/util.c
+++ b/sbin/isakmpd/util.c
@@ -1,8 +1,9 @@
-/* $OpenBSD: util.c,v 1.7 2000/10/07 06:59:39 niklas Exp $ */
-/* $EOM: util.c,v 1.16 2000/10/04 16:36:56 itojun Exp $ */
+/* $OpenBSD: util.c,v 1.8 2000/10/13 13:22:02 niklas Exp $ */
+/* $EOM: util.c,v 1.17 2000/10/13 13:04:16 ho Exp $ */
/*
* Copyright (c) 1998, 1999 Niklas Hallqvist. All rights reserved.
+ * Copyright (c) 2000 Håkan Olsson. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -35,8 +36,10 @@
*/
#include <sys/types.h>
+#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include "sysdep.h"
@@ -160,3 +163,38 @@ hex2raw (char *s, u_int8_t *buf, size_t sz)
}
return 0;
}
+
+/*
+ * Perform sanity check on files containing secret information.
+ * Returns -1 on failure, 0 otherwise.
+ * Also, if *file_size != NULL, store file size here.
+ */
+int
+check_file_secrecy (char *name, off_t *file_size)
+{
+ struct stat st;
+
+ if (lstat (name, &st) == -1)
+ {
+ log_error ("check_file_secrecy: lstat (\"%s\") failed", name);
+ return -1;
+ }
+ if (st.st_uid != geteuid () && st.st_uid != getuid ())
+ {
+ log_print ("check_file_secrecy: "
+ "not loading %s - file owner is not process user", name);
+ return -1;
+ }
+ if ((st.st_mode & (S_IRWXG | S_IRWXO)) != 0)
+ {
+ log_print ("conf_file_secrecy: not loading %s - too open permissions",
+ name);
+ return -1;
+ }
+
+ if (file_size)
+ *file_size = st.st_size;
+
+ return 0;
+}
+