Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/ifconfig Add to the string parse object (pstr), and its...



details:   https://anonhg.NetBSD.org/src/rev/58801de56f24
branches:  trunk
changeset: 755987:58801de56f24
user:      dyoung <dyoung%NetBSD.org@localhost>
date:      Thu Jul 01 16:44:05 2010 +0000

description:
Add to the string parse object (pstr), and its constructors, a flag that
tells whether it should detect and convert to binary a hexadecimal octet
string of the form 0x0123ABab, or leave those strings undecoded.

If the argument for a 'media', 'mediamode', 'mediaopt', '-mediaopt',
'nwkey', or 'bssid' keyword is a hexadecimal octet string, do not detect
and decode it.  (Note that setifnwkey decodes hexadecimal strings on its
own.)

This fixes a bug noticed by Jim Miller where the trailing zero-octets
were discarded from hexadecimal octet-string arguments for 'nwkey'.

diffstat:

 sbin/ifconfig/ieee80211.c |  16 ++++++++--------
 sbin/ifconfig/media.c     |  18 +++++++++---------
 sbin/ifconfig/parse.c     |   6 +++---
 sbin/ifconfig/parse.h     |  11 +++++++++--
 sbin/ifconfig/util.c      |   9 +++++----
 sbin/ifconfig/util.h      |   2 +-
 6 files changed, 35 insertions(+), 27 deletions(-)

diffs (208 lines):

diff -r 535b9ba53d69 -r 58801de56f24 sbin/ifconfig/ieee80211.c
--- a/sbin/ifconfig/ieee80211.c Thu Jul 01 16:28:21 2010 +0000
+++ b/sbin/ifconfig/ieee80211.c Thu Jul 01 16:44:05 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ieee80211.c,v 1.23 2009/01/18 00:24:29 lukem Exp $     */
+/*     $NetBSD: ieee80211.c,v 1.24 2010/07/01 16:44:05 dyoung Exp $    */
 
 /*
  * Copyright (c) 1983, 1993
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ieee80211.c,v 1.23 2009/01/18 00:24:29 lukem Exp $");
+__RCSID("$NetBSD: ieee80211.c,v 1.24 2010/07/01 16:44:05 dyoung Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -184,11 +184,11 @@
     0, INT_MAX, 10, setifpowersavesleep, "powersavesleep",
     &command_root.pb_parser);
 
-struct pstr parse_nwkey = PSTR_INITIALIZER(&parse_nwkey, "nwkey", setifnwkey,
-    "nwkey", &command_root.pb_parser);
+struct pstr parse_nwkey = PSTR_INITIALIZER1(&parse_nwkey, "nwkey", setifnwkey,
+    "nwkey", false, &command_root.pb_parser);
 
-struct pstr parse_bssid = PSTR_INITIALIZER(&parse_bssid, "bssid", setifbssid,
-    "bssid", &command_root.pb_parser);
+struct pstr parse_bssid = PSTR_INITIALIZER1(&parse_bssid, "bssid", setifbssid,
+    "bssid", false, &command_root.pb_parser);
 
 static int
 set80211(prop_dictionary_t env, uint16_t type, int16_t val, int16_t len,
@@ -375,7 +375,7 @@
                        val += 2;
                        for (i = 0; i < IEEE80211_WEP_NKID; i++) {
                                val = get_string(val, ",", keybuf[i],
-                                   &nwkey.i_key[i].i_keylen);
+                                   &nwkey.i_key[i].i_keylen, true);
                                if (val == NULL) {
                                        errno = EINVAL;
                                        return -1;
@@ -386,7 +386,7 @@
                        }
                } else {
                        val = get_string(val, NULL, keybuf[0],
-                           &nwkey.i_key[0].i_keylen);
+                           &nwkey.i_key[0].i_keylen, true);
                        if (val == NULL) {
                                errno = EINVAL;
                                return -1;
diff -r 535b9ba53d69 -r 58801de56f24 sbin/ifconfig/media.c
--- a/sbin/ifconfig/media.c     Thu Jul 01 16:28:21 2010 +0000
+++ b/sbin/ifconfig/media.c     Thu Jul 01 16:44:05 2010 +0000
@@ -1,6 +1,6 @@
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: media.c,v 1.3 2008/07/15 21:27:58 dyoung Exp $");
+__RCSID("$NetBSD: media.c,v 1.4 2010/07/01 16:44:05 dyoung Exp $");
 #endif /* not lint */
 
 #include <assert.h>
@@ -51,21 +51,21 @@
 static const struct ifmedia_status_description ifm_status_descriptions[] =
     IFM_STATUS_DESCRIPTIONS;
 
-static struct pstr mediamode = PSTR_INITIALIZER(&mediamode, "mediamode",
-    setmediamode, "mediamode", &command_root.pb_parser);
+static struct pstr mediamode = PSTR_INITIALIZER1(&mediamode, "mediamode",
+    setmediamode, "mediamode", false, &command_root.pb_parser);
 
 static struct pinteger mediainst = PINTEGER_INITIALIZER1(&mediainst,
     "mediainst", 0, IFM_INST_MAX, 10, setmediainst, "mediainst",
     &command_root.pb_parser);
 
-static struct pstr unmediaopt = PSTR_INITIALIZER(&unmediaopt, "-mediaopt",
-    unsetmediaopt, "unmediaopt", &command_root.pb_parser);
+static struct pstr unmediaopt = PSTR_INITIALIZER1(&unmediaopt, "-mediaopt",
+    unsetmediaopt, "unmediaopt", false, &command_root.pb_parser);
 
-static struct pstr mediaopt = PSTR_INITIALIZER(&mediaopt, "mediaopt",
-    setmediaopt, "mediaopt", &command_root.pb_parser);
+static struct pstr mediaopt = PSTR_INITIALIZER1(&mediaopt, "mediaopt",
+    setmediaopt, "mediaopt", false, &command_root.pb_parser);
 
-static struct pstr media = PSTR_INITIALIZER(&media, "media", setmedia, "media",
-    &command_root.pb_parser);
+static struct pstr media = PSTR_INITIALIZER1(&media, "media", setmedia, "media",
+    false, &command_root.pb_parser);
 
 static const struct kwinst mediakw[] = {
          {.k_word = "instance", .k_key = "anymedia", .k_type = KW_T_BOOL,
diff -r 535b9ba53d69 -r 58801de56f24 sbin/ifconfig/parse.c
--- a/sbin/ifconfig/parse.c     Thu Jul 01 16:28:21 2010 +0000
+++ b/sbin/ifconfig/parse.c     Thu Jul 01 16:44:05 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.15 2010/04/20 21:25:25 plunky Exp $        */
+/*     $NetBSD: parse.c,v 1.16 2010/07/01 16:44:05 dyoung Exp $        */
 
 /*-
  * Copyright (c) 2008 David Young.  All rights reserved.
@@ -27,7 +27,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: parse.c,v 1.15 2010/04/20 21:25:25 plunky Exp $");
+__RCSID("$NetBSD: parse.c,v 1.16 2010/07/01 16:44:05 dyoung Exp $");
 #endif /* not lint */
 
 #include <err.h>
@@ -155,7 +155,7 @@
        }
 
        len = (int)sizeof(buf);
-       if (get_string(arg, NULL, buf, &len) == NULL) {
+       if (get_string(arg, NULL, buf, &len, ps->ps_hexok) == NULL) {
                errno = EINVAL;
                return -1;
        }
diff -r 535b9ba53d69 -r 58801de56f24 sbin/ifconfig/parse.h
--- a/sbin/ifconfig/parse.h     Thu Jul 01 16:28:21 2010 +0000
+++ b/sbin/ifconfig/parse.h     Thu Jul 01 16:44:05 2010 +0000
@@ -83,11 +83,17 @@
 }
 
 #define        PSTR_INITIALIZER(__ps, __name, __defexec, __defkey, __defnext)  \
+    PSTR_INITIALIZER1((__ps), (__name), (__defexec), (__defkey),       \
+    true, (__defnext))
+
+#define        PSTR_INITIALIZER1(__ps, __name, __defexec, __defkey, __defhexok,\
+    __defnext)                                                         \
 {                                                                      \
        .ps_parser = {.p_name = (__name), .p_methods = &pstr_methods,   \
                       .p_exec = (__defexec),                           \
                       .p_nextparser = (__defnext)},                    \
-       .ps_key = (__defkey)                                            \
+       .ps_key = (__defkey),                                           \
+       .ps_hexok = (__defhexok)                                        \
 }
 
 #define        PADDR_INITIALIZER(__pa, __name, __defexec, __addrkey,           \
@@ -203,6 +209,7 @@
 struct pstr {
        struct parser           ps_parser;
        const char              *ps_key;
+       bool                    ps_hexok;
 };
 
 struct pinteger {
@@ -257,7 +264,7 @@
 struct paddr *paddr_create(const char *, parser_exec_t, const char *,
     const char *, struct parser *);
 struct pstr *pstr_create(const char *, parser_exec_t, const char *,
-    struct parser *);
+    bool, struct parser *);
 struct piface *piface_create(const char *, parser_exec_t, const char *,
     struct parser *);
 struct pkw *pkw_create(const char *, parser_exec_t,
diff -r 535b9ba53d69 -r 58801de56f24 sbin/ifconfig/util.c
--- a/sbin/ifconfig/util.c      Thu Jul 01 16:28:21 2010 +0000
+++ b/sbin/ifconfig/util.c      Thu Jul 01 16:44:05 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: util.c,v 1.14 2010/07/01 16:12:23 dyoung Exp $ */
+/*     $NetBSD: util.c,v 1.15 2010/07/01 16:44:05 dyoung Exp $ */
 
 /*-
  * Copyright (c) 2008 David Young.  All rights reserved.
@@ -27,7 +27,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: util.c,v 1.14 2010/07/01 16:12:23 dyoung Exp $");
+__RCSID("$NetBSD: util.c,v 1.15 2010/07/01 16:44:05 dyoung Exp $");
 #endif /* not lint */
 
 #include <ctype.h>
@@ -78,7 +78,8 @@
 }
 
 const char *
-get_string(const char *val, const char *sep, u_int8_t *buf, int *lenp)
+get_string(const char *val, const char *sep, u_int8_t *buf, int *lenp,
+    bool hexok)
 {
        int len;
        bool hexstr;
@@ -86,7 +87,7 @@
 
        len = *lenp;
        p = buf;
-       hexstr = (val[0] == '0' && tolower((u_char)val[1]) == 'x');
+       hexstr = hexok && val[0] == '0' && tolower((u_char)val[1]) == 'x';
        if (hexstr)
                val += 2;
        for (;;) {
diff -r 535b9ba53d69 -r 58801de56f24 sbin/ifconfig/util.h
--- a/sbin/ifconfig/util.h      Thu Jul 01 16:28:21 2010 +0000
+++ b/sbin/ifconfig/util.h      Thu Jul 01 16:44:05 2010 +0000
@@ -17,7 +17,7 @@
 };
 
 void print_link_addresses(prop_dictionary_t, bool);
-const char *get_string(const char *, const char *, u_int8_t *, int *);
+const char *get_string(const char *, const char *, u_int8_t *, int *, bool);
 const struct afswtch *lookup_af_byname(const char *);
 const struct afswtch *lookup_af_bynum(int);
 void   print_string(const u_int8_t *, int);



Home | Main Index | Thread Index | Old Index