summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2017-10-21 13:27:16 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2017-10-21 13:27:16 +0000
commit1fee50f50ddbdb29210967d553fd2a6bc22aa4de (patch)
tree65d603c8dbf255e0ff70709e4c285f6d917bc6ea /sbin
parente11009a6f81cad01fae6c7dbb9a4f81f750de453 (diff)
Bring parse_client_lease_statement() into the new world by
return 0/1 for success.
Diffstat (limited to 'sbin')
-rw-r--r--sbin/dhclient/clparse.c42
1 files changed, 25 insertions, 17 deletions
diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c
index 7988b4b1535..138fb7116f2 100644
--- a/sbin/dhclient/clparse.c
+++ b/sbin/dhclient/clparse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clparse.c,v 1.143 2017/10/16 12:39:33 krw Exp $ */
+/* $OpenBSD: clparse.c,v 1.144 2017/10/21 13:27:15 krw Exp $ */
/* Parser for dhclient config and lease files. */
@@ -68,7 +68,8 @@ void parse_client_statement(FILE *, char *);
int parse_hex_octets(FILE *, unsigned int *, uint8_t **);
int parse_option_list(FILE *, int *, uint8_t *);
void parse_interface_declaration(FILE *, char *);
-struct client_lease *parse_client_lease_statement(FILE *, char *);
+int parse_client_lease_statement(FILE *, char *,
+ struct client_lease **);
void parse_client_lease_declaration(FILE *,
struct client_lease *, char *);
int parse_option_decl(FILE *, int *, struct option_data *);
@@ -180,8 +181,9 @@ read_client_conf(char *name)
void
read_client_leases(char *name, struct client_lease_tq *tq)
{
- FILE *cfile;
- int token;
+ struct client_lease *lp;
+ FILE *cfile;
+ int token;
TAILQ_INIT(tq);
@@ -198,8 +200,10 @@ read_client_leases(char *name, struct client_lease_tq *tq)
log_warnx("%s: expecting lease", log_procname);
break;
}
- add_lease(tq, parse_client_lease_statement(cfile, name));
+ if (parse_client_lease_statement(cfile, name, &lp) == 1)
+ add_lease(tq, lp);
} while (1);
+
fclose(cfile);
}
@@ -231,8 +235,9 @@ read_client_leases(char *name, struct client_lease_tq *tq)
void
parse_client_statement(FILE *cfile, char *name)
{
- char *val;
- int i, token;
+ struct client_lease *lp;
+ char *val;
+ int i, token;
token = next_token(NULL, cfile);
@@ -277,8 +282,8 @@ parse_client_statement(FILE *cfile, char *name)
parse_interface_declaration(cfile, name);
break;
case TOK_LEASE:
- add_lease(&config->static_leases,
- parse_client_lease_statement(cfile, name));
+ if (parse_client_lease_statement(cfile, name, &lp) == 1)
+ add_lease(&config->static_leases, lp);
break;
case TOK_LINK_TIMEOUT:
if (parse_lease_time(cfile, &config->link_timeout) == 1)
@@ -495,8 +500,9 @@ parse_interface_declaration(FILE *cfile, char *name)
* client-lease-declaration |
* client-lease-declarations client-lease-declaration
*/
-struct client_lease *
-parse_client_lease_statement(FILE *cfile, char *name)
+int
+parse_client_lease_statement(FILE *cfile, char *name,
+ struct client_lease **lp)
{
struct client_lease *lease;
int token;
@@ -506,7 +512,7 @@ parse_client_lease_statement(FILE *cfile, char *name)
parse_warn("expecting '{'.");
if (token != ';')
skip_to_semi(cfile);
- return NULL;
+ return 0;
}
lease = calloc(1, sizeof(*lease));
@@ -518,15 +524,17 @@ parse_client_lease_statement(FILE *cfile, char *name)
if (token == EOF) {
parse_warn("unterminated lease declaration.");
free_client_lease(lease);
- return NULL;
+ return 0;
+ }
+ if (token == '}') {
+ token = next_token(NULL, cfile);
+ *lp = lease;
+ return 1;
}
- if (token == '}')
- break;
parse_client_lease_declaration(cfile, lease, name);
} while (1);
- token = next_token(NULL, cfile);
- return lease;
+ return 0;
}
/*