Re: Userclass option the Microsoft way
Roy Marples
Tue Feb 18 22:17:57 2020
Hi Jonas
On 17/02/2020 17:44, Jonas Ramstrand wrote:
I don't get the userclass to work towards Microsoft dhcp-server... Would it be
possible to get a patch with - - msuserclass?
Using dhcpcd 8.1.2
Try the attached patch.
It will likely only apply to the dhcpcd master branch.
Roy
diff --git a/src/if-options.c b/src/if-options.c
index 4fc70610..a1bd6950 100644
--- a/src/if-options.c
+++ b/src/if-options.c
@@ -106,6 +106,7 @@
#define O_LASTLEASE_EXTEND O_BASE + 46
#define O_INACTIVE O_BASE + 47
#define O_MUDURL O_BASE + 48
+#define O_MSUSERCLASS O_BASE + 49
const struct option cf_options[] = {
{"background", no_argument, NULL, 'b'},
@@ -129,6 +130,7 @@ const struct option cf_options[] = {
{"inform6", optional_argument, NULL, O_INFORM6},
{"timeout", required_argument, NULL, 't'},
{"userclass", required_argument, NULL, 'u'},
+ {"msuserclass", required_argument, NULL, O_MSUSERCLASS},
{"vendor", required_argument, NULL, 'v'},
{"waitip", optional_argument, NULL, 'w'},
{"exit", no_argument, NULL, 'x'},
@@ -287,6 +289,7 @@ add_environ(char ***array, const char *value, int uniq)
#define PARSE_STRING_NULL 1
#define PARSE_HWADDR 2
#define parse_string(a, b, c) parse_str((a), (b), (c), PARSE_STRING)
+#define parse_nstring(a, b, c) parse_str((a), (b), (c), PARSE_STRING_NULL)
#define parse_hwaddr(a, b, c) parse_str((a), (b), (c), PARSE_HWADDR)
static ssize_t
parse_str(char *sbuf, size_t slen, const char *str, int flags)
@@ -723,7 +726,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
ARG_REQUIRED;
if (ifo->script != default_script)
free(ifo->script);
- s = parse_str(NULL, 0, arg, PARSE_STRING_NULL);
+ s = parse_nstring(NULL, 0, arg);
if (s == 0) {
ifo->script = NULL;
break;
@@ -734,7 +737,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
logerr(__func__);
return -1;
}
- s = parse_str(ifo->script, dl, arg, PARSE_STRING_NULL);
+ s = parse_nstring(ifo->script, dl, arg);
if (s == -1 ||
ifo->script[0] == '\0' ||
strcmp(ifo->script, "/dev/null") == 0)
@@ -755,7 +758,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
ifo->options |= DHCPCD_HOSTNAME;
break;
}
- s = parse_string(ifo->hostname, HOSTNAME_MAX_LEN, arg);
+ s = parse_nstring(ifo->hostname, sizeof(ifo->hostname), arg);
if (s == -1) {
logerr("%s: hostname", __func__);
return -1;
@@ -764,7 +767,6 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
logerrx("hostname cannot begin with .");
return -1;
}
- ifo->hostname[s] = '\0';
if (ifo->hostname[0] == '\0')
ifo->options &= ~DHCPCD_HOSTNAME;
else
@@ -882,9 +884,9 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
}
break;
case 'u':
- s = USERCLASS_MAX_LEN - ifo->userclass[0] - 1;
+ dl = sizeof(ifo->userclass) - ifo->userclass[0] - 1;
s = parse_string((char *)ifo->userclass +
- ifo->userclass[0] + 2, (size_t)s, arg);
+ ifo->userclass[0] + 2, dl, arg);
if (s == -1) {
logerr("userclass");
return -1;
@@ -894,6 +896,17 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
ifo->userclass[0] = (uint8_t)(ifo->userclass[0] + s +1);
}
break;
+ case O_MSUSERCLASS:
+ /* Some Microsoft DHCP servers expect userclass to be an
+ * opaque blob. This is not RFC 3004 compliant. */
+ s = parse_string((char *)ifo->userclass + 1,
+ sizeof(ifo->userclass) - 1, arg);
+ if (s == -1) {
+ logerr("msuserclass");
+ return -1;
+ }
+ ifo->userclass[0] = (uint8_t)s;
+ break;
case 'v':
ARG_REQUIRED;
p = strchr(arg, ',');
Archive administrator: postmaster@marples.name