parse_lease_time() is an unnecessary abstraction. Just use
authorkrw <krw@openbsd.org>
Thu, 4 Jan 2018 03:02:05 +0000 (03:02 +0000)
committerkrw <krw@openbsd.org>
Thu, 4 Jan 2018 03:02:05 +0000 (03:02 +0000)
parse_number('L') since it is parsing unsigned 32bit integers.

sbin/dhclient/clparse.c
sbin/dhclient/dhcpd.h
sbin/dhclient/parse.c

index ee8d2a2..e2b382c 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: clparse.c,v 1.162 2018/01/04 02:27:55 krw Exp $       */
+/*     $OpenBSD: clparse.c,v 1.163 2018/01/04 03:02:05 krw Exp $       */
 
 /* Parser for dhclient config and lease files. */
 
@@ -244,6 +244,7 @@ parse_conf_declaration(FILE *cfile, char *name)
        uint8_t                  list[DHO_COUNT];
        char                    *val;
        int                      i, count, token;
+       uint32_t                 t;
 
        token = next_token(NULL, cfile);
 
@@ -255,8 +256,10 @@ parse_conf_declaration(FILE *cfile, char *name)
                }
                break;
        case TOK_BACKOFF_CUTOFF:
-               if (parse_lease_time(cfile, &config->backoff_cutoff) == 1)
+               if (parse_number(cfile, (unsigned char *)&t, 'L') == 1) {
+                       config->backoff_cutoff = ntohl(t);
                        parse_semi(cfile);
+               }
                break;
        case TOK_DEFAULT:
                if (parse_option_decl(cfile, &i, config->defaults) == 1) {
@@ -283,8 +286,10 @@ parse_conf_declaration(FILE *cfile, char *name)
                }
                break;
        case TOK_INITIAL_INTERVAL:
-               if (parse_lease_time(cfile, &config->initial_interval) == 1)
+               if (parse_number(cfile, (unsigned char *)&t, 'L') == 1) {
+                       config->initial_interval = ntohl(t);
                        parse_semi(cfile);
+               }
                break;
        case TOK_INTERFACE:
                if (parse_interface_declaration(cfile, name) == 1)
@@ -294,8 +299,10 @@ parse_conf_declaration(FILE *cfile, char *name)
                skip_to_semi(cfile);
                break;
        case TOK_LINK_TIMEOUT:
-               if (parse_lease_time(cfile, &config->link_timeout) == 1)
+               if (parse_number(cfile, (unsigned char *)&t, 'L') == 1) {
+                       config->link_timeout = ntohl(t);
                        parse_semi(cfile);
+               }
                break;
        case TOK_NEXT_SERVER:
                if (parse_ip_addr(cfile, &config->next_server) == 1)
@@ -308,8 +315,10 @@ parse_conf_declaration(FILE *cfile, char *name)
                }
                break;
        case TOK_REBOOT:
-               if (parse_lease_time(cfile, &config->reboot_timeout) == 1)
+               if (parse_number(cfile, (unsigned char *)&t, 'L') == 1) {
+                       config->reboot_timeout = ntohl(t);
                        parse_semi(cfile);
+               }
                break;
        case TOK_REJECT:
                if (parse_reject_statement(cfile) == 1)
@@ -326,12 +335,16 @@ parse_conf_declaration(FILE *cfile, char *name)
                        parse_semi(cfile);
                break;
        case TOK_RETRY:
-               if (parse_lease_time(cfile, &config->retry_interval) == 1)
+               if (parse_number(cfile, (unsigned char *)&t, 'L') == 1) {
+                       config->retry_interval = ntohl(t);
                        parse_semi(cfile);
+               }
                break;
        case TOK_SELECT_TIMEOUT:
-               if (parse_lease_time(cfile, &config->select_interval) == 1)
+               if (parse_number(cfile, (unsigned char *)&t, 'L') == 1) {
+                       config->select_interval = ntohl(t);
                        parse_semi(cfile);
+               }
                break;
        case TOK_SEND:
                if (parse_option_decl(cfile, &i, config->send_options) == 1)
@@ -351,8 +364,10 @@ parse_conf_declaration(FILE *cfile, char *name)
                }
                break;
        case TOK_TIMEOUT:
-               if (parse_lease_time(cfile, &config->timeout) == 1)
+               if (parse_number(cfile, (unsigned char *)&t, 'L') == 1) {
+                       config->timeout = ntohl(t);
                        parse_semi(cfile);
+               }
                break;
        default:
                parse_warn("expecting statement.");
index 6dec72f..7e31a0a 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: dhcpd.h,v 1.244 2018/01/04 02:27:55 krw Exp $ */
+/*     $OpenBSD: dhcpd.h,v 1.245 2018/01/04 03:02:05 krw Exp $ */
 
 /*
  * Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -180,7 +180,6 @@ int          parse_semi(FILE *);
 int             parse_string(FILE *, unsigned int *, char **);
 int             parse_ip_addr(FILE *, struct in_addr *);
 int             parse_cidr(FILE *, unsigned char *);
-int             parse_lease_time(FILE *, time_t *);
 int             parse_number(FILE *, unsigned char *, char);
 int             parse_boolean(FILE *, unsigned char *);
 void            parse_warn(char *);
index 1f161e8..bd77733 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: parse.c,v 1.78 2018/01/04 02:27:55 krw Exp $  */
+/*     $OpenBSD: parse.c,v 1.79 2018/01/04 03:02:05 krw Exp $  */
 
 /* Common parser code for dhcpd and dhclient. */
 
@@ -225,31 +225,6 @@ parse_ip_addr(FILE *cfile, struct in_addr *addr)
        return 0;
 }
 
-/*
- * lease-time :== NUMBER SEMI
- */
-int
-parse_lease_time(FILE *cfile, time_t *timep)
-{
-       const char      *errstr;
-       char            *val;
-       long long        numval;
-       int              token;
-
-       token = next_token(&val, cfile);
-       numval = strtonum(val, 0, UINT32_MAX, &errstr);
-       if (errstr == NULL) {
-               *timep = numval;
-               return 1;
-       }
-
-       parse_warn("expecting integer between 0 and 4294967295.");
-       if (token != ';')
-               skip_to_semi(cfile);
-
-       return 0;
-}
-
 int
 parse_boolean(FILE *cfile, unsigned char *buf)
 {