summaryrefslogtreecommitdiff
path: root/usr.sbin/dhcp
diff options
context:
space:
mode:
authorAngelos D. Keromytis <angelos@cvs.openbsd.org>2001-01-06 20:01:41 +0000
committerAngelos D. Keromytis <angelos@cvs.openbsd.org>2001-01-06 20:01:41 +0000
commit3fb6d44d29c17669ec159776981182b0f76f6089 (patch)
treeef0309ee9cf2adecec96876497f463c5b8fd289d /usr.sbin/dhcp
parent60e991e887d020cdedfa29ac3e15da5015575933 (diff)
Also protect write_client_lease() in bind_lease()
Diffstat (limited to 'usr.sbin/dhcp')
-rw-r--r--usr.sbin/dhcp/dhclient/dhclient.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/usr.sbin/dhcp/dhclient/dhclient.c b/usr.sbin/dhcp/dhclient/dhclient.c
index d9934182b70..c73f10d7654 100644
--- a/usr.sbin/dhcp/dhclient/dhclient.c
+++ b/usr.sbin/dhcp/dhclient/dhclient.c
@@ -56,7 +56,7 @@
#ifndef lint
static char copyright[] =
-"$Id: dhclient.c,v 1.14 2001/01/06 19:55:06 angelos Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n";
+"$Id: dhclient.c,v 1.15 2001/01/06 20:01:40 angelos Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
@@ -181,7 +181,7 @@ int main (argc, argv, envp)
read_client_conf ();
/* Lock the leases file */
- fd = open(path_dhclient_db, O_RDONLY | O_EXLOCK, 0);
+ fd = open (path_dhclient_db, O_RDONLY | O_EXLOCK, 0);
if (fd < 0)
error ("can't open and lock %s: %m", path_dhclient_db);
@@ -503,12 +503,22 @@ void dhcpack (packet)
void bind_lease (ip)
struct interface_info *ip;
{
+ int fd;
+
/* Remember the medium. */
ip -> client -> new -> medium = ip -> client -> medium;
+ /* Lock the leases file */
+ fd = open (path_dhclient_db, O_RDONLY | O_EXLOCK, 0);
+ if (fd < 0)
+ error ("can't open and lock %s: %m", path_dhclient_db);
+
/* Write out the new lease. */
write_client_lease (ip, ip -> client -> new);
+ /* Close and unlock lease file */
+ close(fd);
+
/* Run the client script with the new parameters. */
script_init (ip, (ip -> client -> state == S_REQUESTING
? "BOUND"
@@ -1711,7 +1721,7 @@ void rewrite_client_leases ()
fclose (leaseFile);
leaseFile = fopen (path_dhclient_db, "w");
if (!leaseFile)
- error ("can't create /var/db/dhclient.leases: %m");
+ error ("can't create %s: %m", path_dhclient_db);
/* Write out all the leases attached to configured interfaces that
we know about. */
@@ -1750,7 +1760,7 @@ void write_client_lease (ip, lease)
if (!leaseFile) { /* XXX */
leaseFile = fopen (path_dhclient_db, "w");
if (!leaseFile)
- error ("can't create /var/db/dhclient.leases: %m");
+ error ("can't create %s: %m", path_dhclient_db);
}
fprintf (leaseFile, "lease {\n");