From: Roy Marples Date: Wed, 10 Sep 2014 10:00:08 +0000 (+0000) Subject: Allow SSIDs with non printable characters to be used in ssid selection in X-Git-Tag: v6.4.4~27 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=71650ebcdedb8250c6a3a6384ef7aabf4be7c650;p=thirdparty%2Fdhcpcd.git Allow SSIDs with non printable characters to be used in ssid selection in dhcpcd.conf and generate more accurate stable private addresses. --- diff --git a/dhcpcd.c b/dhcpcd.c index dd684147..8dbebd7a 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -489,8 +489,18 @@ int dhcpcd_selectprofile(struct interface *ifp, const char *profile) { struct if_options *ifo; - - ifo = read_config(ifp->ctx, ifp->name, ifp->ssid, profile); + char pssid[PROFILE_LEN]; + + if (ifp->ssid_len) { + ssize_t r; + r =print_string(pssid, sizeof(pssid), ifp->ssid, ifp->ssid_len); + if (r == -1) { + syslog(LOG_ERR, "%s: %s: %m", ifp->name, __func__); + pssid[0] = '\0'; + } + } else + pssid[0] = '\0'; + ifo = read_config(ifp->ctx, ifp->name, pssid, profile); if (ifo == NULL) { syslog(LOG_DEBUG, "%s: no profile %s", ifp->name, profile); return -1; diff --git a/dhcpcd.h b/dhcpcd.h index cedab5fb..4b6624b9 100644 --- a/dhcpcd.h +++ b/dhcpcd.h @@ -64,7 +64,7 @@ struct interface { unsigned int metric; int carrier; int wireless; - char ssid[IF_SSIDSIZE]; + uint8_t ssid[IF_SSIDSIZE]; unsigned int ssid_len; char profile[PROFILE_LEN]; diff --git a/if-bsd.c b/if-bsd.c index 455665fb..6c16a5eb 100644 --- a/if-bsd.c +++ b/if-bsd.c @@ -138,7 +138,7 @@ if_openlinksocket(void) } static int -if_getssid1(const char *ifname, char *ssid) +if_getssid1(const char *ifname, uint8_t *ssid) { int s, retval = -1; #if defined(SIOCG80211NWID) diff --git a/if-linux-wext.c b/if-linux-wext.c index 117eb1a5..d4050cb4 100644 --- a/if-linux-wext.c +++ b/if-linux-wext.c @@ -60,10 +60,10 @@ /* We can't include if.h or dhcpcd.h because * they would pull in net/if.h, which defeats the purpose of this hack. */ #define IF_SSIDSIZE 33 -int if_getssid_wext(const char *ifname, char *ssid); +int if_getssid_wext(const char *ifname, uint8_t *ssid); int -if_getssid_wext(const char *ifname, char *ssid) +if_getssid_wext(const char *ifname, uint8_t *ssid) { #ifdef SIOCGIWESSID int s, retval; diff --git a/if-linux.c b/if-linux.c index 246f2532..f326ed11 100644 --- a/if-linux.c +++ b/if-linux.c @@ -87,7 +87,7 @@ #include #include #else -int if_getssid_wext(const char *ifname, char *ssid); +int if_getssid_wext(const char *ifname, uint8_t *ssid); #endif #define bpf_insn sock_filter @@ -933,7 +933,7 @@ gnl_getfamily(struct dhcpcd_ctx *ctx, const char *name) nlm.ghdr.version = 1; if (nla_put_string(&nlm.hdr, sizeof(nlm), CTRL_ATTR_FAMILY_NAME, name) == -1) - return -1; + return -1; return send_netlink(ctx, NULL, NETLINK_GENERIC, &nlm.hdr, &_gnl_getfamily); } @@ -977,7 +977,7 @@ if_getssid(struct interface *ifp) nlm.hdr.nlmsg_flags = NLM_F_REQUEST; nlm.ghdr.cmd = NL80211_CMD_GET_INTERFACE; nla_put_32(&nlm.hdr, sizeof(nlm), NL80211_ATTR_IFINDEX, ifp->index); - + return send_netlink(ifp->ctx, ifp, NETLINK_GENERIC, &nlm.hdr, &_if_getssid); } @@ -1453,7 +1453,7 @@ static struct rtattr * add_attr_nest(struct nlmsghdr *n, unsigned short maxlen, unsigned short type) { struct rtattr *nest; - + nest = NLMSG_TAIL(n); add_attr_l(n, maxlen, type, NULL, 0); return nest; @@ -1484,7 +1484,7 @@ if_disable_autolinklocal(struct dhcpcd_ctx *ctx, const char *ifname) IN6_ADDR_GEN_MODE_NONE); add_attr_nest_end(&nlm.hdr, afs6); add_attr_nest_end(&nlm.hdr, afs); - + return send_netlink(ctx, NULL, NETLINK_ROUTE, &nlm.hdr, NULL); } diff --git a/ipv6.c b/ipv6.c index 3bf4bc05..5986a18a 100644 --- a/ipv6.c +++ b/ipv6.c @@ -301,7 +301,7 @@ static int ipv6_makestableprivate1(struct in6_addr *addr, const struct in6_addr *prefix, int prefix_len, const unsigned char *netiface, size_t netiface_len, - const char *netid, size_t netid_len, + const unsigned char *netid, size_t netid_len, uint32_t *dad_counter, const unsigned char *secret, size_t secret_len) { @@ -376,7 +376,7 @@ ipv6_makestableprivate(struct in6_addr *addr, * as the interface identifier */ r = ipv6_makestableprivate1(addr, prefix, prefix_len, ifp->hwaddr, ifp->hwlen, - ifp->ssid, strlen(ifp->ssid), + ifp->ssid, ifp->ssid_len, &dad, ifp->ctx->secret, ifp->ctx->secret_len);