-/* $OpenBSD: clparse.c,v 1.156 2017/12/13 18:53:04 krw Exp $ */
+/* $OpenBSD: clparse.c,v 1.157 2017/12/16 20:47:53 krw Exp $ */
/* Parser for dhclient config and lease files. */
#include "dhctoken.h"
#include "log.h"
-void parse_client_statement(FILE *, char *);
+void parse_conf_declaration(FILE *, char *);
int parse_hex_octets(FILE *, unsigned int *, uint8_t **);
int parse_option_list(FILE *, int *, uint8_t *);
int parse_interface_declaration(FILE *, char *);
-int parse_client_lease_statement(FILE *, char *,
+int parse_lease(FILE *, char *,
struct client_lease **);
-void parse_client_lease_declaration(FILE *,
+void parse_lease_declaration(FILE *,
struct client_lease *, char *);
int parse_option_decl(FILE *, int *, struct option_data *);
int parse_reject_statement(FILE *);
}
/*
- * client-conf-file :== client-declarations EOF
- * client-declarations :== <nil>
- * | client-declaration
- * | client-declarations client-declaration
+ * conf :== conf_declarations EOF
+ * conf-declarations :== <nil>
+ * | conf-declaration
+ * | conf-declarations conf-declaration
*/
void
-read_client_conf(char *name)
+read_conf(char *name)
{
struct option_data *option;
FILE *cfile;
token = peek_token(NULL, cfile);
if (token == EOF)
break;
- parse_client_statement(cfile, name);
+ parse_conf_declaration(cfile, name);
}
fclose(cfile);
}
}
/*
- * lease-file :== client-lease-statements EOF
- * client-lease-statements :== <nil>
- * | client-lease-statements LEASE client-lease-statement
+ * lease-db :== leases EOF
+ * leases :== <nil>
+ * | LEASE lease
+ * | leases LEASE lease
*/
void
-read_client_leases(char *name, struct client_lease_tq *tq)
+read_lease_db(char *name, struct client_lease_tq *tq)
{
struct client_lease *lp;
FILE *cfile;
TAILQ_INIT(tq);
- if ((cfile = fopen(path_dhclient_db, "r")) == NULL)
+ if ((cfile = fopen(path_lease_db, "r")) == NULL)
return;
- new_parse(path_dhclient_db);
+ new_parse(path_lease_db);
for (;;) {
token = next_token(NULL, cfile);
log_warnx("%s: expecting lease", log_procname);
break;
}
- if (parse_client_lease_statement(cfile, name, &lp) == 1)
+ if (parse_lease(cfile, name, &lp) == 1)
add_lease(tq, lp);
}
}
/*
- * client-declaration :==
+ * conf-declaration :==
* TOK_APPEND option-decl |
* TOK_BACKOFF_CUTOFF number |
* TOK_DEFAULT option-decl |
* TOK_TIMEOUT number
*/
void
-parse_client_statement(FILE *cfile, char *name)
+parse_conf_declaration(FILE *cfile, char *name)
{
uint8_t list[DHO_COUNT];
char *val;
/*
* interface-declaration :==
- * INTERFACE string LBRACE client-declarations RBRACE
+ * INTERFACE string LBRACE conf-declarations RBRACE
*/
int
parse_interface_declaration(FILE *cfile, char *name)
token = next_token(NULL, cfile);
return 1;
}
- parse_client_statement(cfile, name);
+ parse_conf_declaration(cfile, name);
}
return 0;
}
/*
- * client-lease-statement :==
- * RBRACE client-lease-declarations LBRACE
+ * lease :== RBRACE lease-declarations LBRACE
*
- * client-lease-declarations :==
+ * lease-declarations :==
* <nil> |
- * client-lease-declaration |
- * client-lease-declarations client-lease-declaration
+ * lease-declaration |
+ * lease-declarations lease-declaration
*/
int
-parse_client_lease_statement(FILE *cfile, char *name,
+parse_lease(FILE *cfile, char *name,
struct client_lease **lp)
{
struct client_lease *lease;
for (;;) {
token = peek_token(NULL, cfile);
if (token == EOF) {
- parse_warn("unterminated lease declaration.");
+ parse_warn("unterminated lease.");
free_client_lease(lease);
break;
}
}
return 1;
}
- parse_client_lease_declaration(cfile, lease, name);
+ parse_lease_declaration(cfile, lease, name);
}
return 0;
}
/*
- * client-lease-declaration :==
+ * lease-declaration :==
* BOOTP |
* EXPIRE time-decl |
* FILENAME string |
* SSID string
*/
void
-parse_client_lease_declaration(FILE *cfile, struct client_lease *lease,
+parse_lease_declaration(FILE *cfile, struct client_lease *lease,
char *name)
{
char *val;
-/* $OpenBSD: dhclient.c,v 1.540 2017/12/09 15:48:04 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.541 2017/12/16 20:47:53 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
#include "privsep.h"
char *path_dhclient_conf = _PATH_DHCLIENT_CONF;
-char *path_dhclient_db = NULL;
+char *path_lease_db = NULL;
char *log_procname;
char path_option_db[PATH_MAX];
void make_request(struct interface_info *, struct client_lease *);
void make_decline(struct interface_info *, struct client_lease *);
-void rewrite_client_leases(struct interface_info *);
+void write_lease_db(struct interface_info *);
void rewrite_option_db(char *, struct client_lease *, struct client_lease *);
char *lease_as_string(char *, char *, struct client_lease *);
struct proposal *lease_as_proposal(struct client_lease *);
ignore_list = optarg;
break;
case 'l':
- path_dhclient_db = optarg;
- if (lstat(path_dhclient_db, &sb) != -1) {
+ path_lease_db = optarg;
+ if (lstat(path_lease_db, &sb) != -1) {
if (S_ISREG(sb.st_mode) == 0)
fatalx("'%s' is not a regular file",
- path_dhclient_db);
+ path_lease_db);
}
break;
case 'L':
config = calloc(1, sizeof(*config));
if (config == NULL)
fatal("config");
- read_client_conf(ifi->name);
+ read_conf(ifi->name);
if ((cmd_opts & OPT_NOACTION) != 0)
return 0;
if ((pw = getpwnam("_dhcp")) == NULL)
fatalx("no such user: _dhcp");
- if (path_dhclient_db == NULL && asprintf(&path_dhclient_db, "%s.%s",
- _PATH_DHCLIENT_DB, ifi->name) == -1)
- fatal("path_dhclient_db");
+ if (path_lease_db == NULL && asprintf(&path_lease_db, "%s.%s",
+ _PATH_LEASE_DB, ifi->name) == -1)
+ fatal("path_lease_db");
/* 2nd stage (post fork) config setup. */
if (ignore_list != NULL)
take_charge(ifi, routefd);
- if ((fd = open(path_dhclient_db,
+ if ((fd = open(path_lease_db,
O_RDONLY|O_EXLOCK|O_CREAT|O_NOFOLLOW, 0640)) == -1)
- fatal("open(%s)", path_dhclient_db);
- read_client_leases(ifi->name, &ifi->leases);
- if ((leaseFile = fopen(path_dhclient_db, "w")) == NULL)
- fatal("fopen(%s)", path_dhclient_db);
- rewrite_client_leases(ifi);
+ fatal("open(%s)", path_lease_db);
+ read_lease_db(ifi->name, &ifi->lease_db);
+ if ((leaseFile = fopen(path_lease_db, "w")) == NULL)
+ fatal("fopen(%s)", path_lease_db);
+ write_lease_db(ifi);
close(fd);
if (strlen(path_option_db) != 0) {
delete_address(ifi->active->address);
/* XXX Do we really want to remove a NAK'd lease from the database? */
- TAILQ_REMOVE(&ifi->leases, ifi->active, next);
+ TAILQ_REMOVE(&ifi->lease_db, ifi->active, next);
free_client_lease(ifi->active);
ifi->active = NULL;
* dynamic leases.
*/
seen = 0;
- TAILQ_FOREACH_SAFE(lease, &ifi->leases, next, pl) {
+ TAILQ_FOREACH_SAFE(lease, &ifi->lease_db, next, pl) {
if (ifi->active == NULL)
continue;
if (ifi->ssid_len != lease->ssid_len)
seen = 1;
else if (lease_expiry(lease) < cur_time ||
lease->address.s_addr == ifi->active->address.s_addr) {
- TAILQ_REMOVE(&ifi->leases, lease, next);
+ TAILQ_REMOVE(&ifi->lease_db, lease, next);
free_client_lease(lease);
}
}
if (seen == 0)
- TAILQ_INSERT_HEAD(&ifi->leases, ifi->active, next);
+ TAILQ_INSERT_HEAD(&ifi->lease_db, ifi->active, next);
- /* Write out new leases file. */
- rewrite_client_leases(ifi);
+ /* Write out new lease db. */
+ write_lease_db(ifi);
ifi->state = S_BOUND;
}
void
-rewrite_client_leases(struct interface_info *ifi)
+write_lease_db(struct interface_info *ifi)
{
struct client_lease *lp;
char *leasestr;
* the chonological order required.
*/
time(&cur_time);
- TAILQ_FOREACH_REVERSE(lp, &ifi->leases, client_lease_tq, next) {
+ TAILQ_FOREACH_REVERSE(lp, &ifi->lease_db, client_lease_tq, next) {
if (lease_expiry(lp) < cur_time)
continue;
leasestr = lease_as_string(ifi->name, "lease", lp);
/* Run through the list of leases and see if one can be used. */
i = DHO_DHCP_CLIENT_IDENTIFIER;
- TAILQ_FOREACH(lp, &ifi->leases, next) {
+ TAILQ_FOREACH(lp, &ifi->lease_db, next) {
if (lp->ssid_len != ifi->ssid_len)
continue;
if (memcmp(lp->ssid, ifi->ssid, lp->ssid_len) != 0)
-/* $OpenBSD: dhcpd.h,v 1.241 2017/12/09 15:48:04 krw Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.242 2017/12/16 20:47:53 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
struct in_addr requested_address;
struct client_lease *active;
struct client_lease *offer;
- struct client_lease_tq leases;
+ struct client_lease_tq lease_db;
};
#define _PATH_DHCLIENT_CONF "/etc/dhclient.conf"
-#define _PATH_DHCLIENT_DB "/var/db/dhclient.leases"
+#define _PATH_LEASE_DB "/var/db/dhclient.leases"
/* options.c */
int pack_options(unsigned char *, int,
/* dhclient.c */
extern char *path_dhclient_conf;
-extern char *path_dhclient_db;
+extern char *path_lease_db;
extern char *log_procname;
extern struct client_config *config;
extern struct imsgbuf *unpriv_ibuf;
uint32_t wrapsum(uint32_t);
/* clparse.c */
-void read_client_conf(char *);
-void read_client_leases(char *, struct client_lease_tq *);
+void read_conf(char *);
+void read_lease_db(char *, struct client_lease_tq *);
/* kroute.c */
unsigned int extract_classless_route(uint8_t *, unsigned int,