Fix dhcp-name-match to always match client-supplied name.

This modifies commit 6ebdc95754.
This commit is contained in:
Simon Kelley
2019-12-05 23:44:29 +00:00
parent 0c211c4ec5
commit 34d41475e7
3 changed files with 63 additions and 67 deletions

View File

@@ -725,9 +725,37 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
client_hostname = daemon->dhcp_buff;
}
if (client_hostname && option_bool(OPT_LOG_OPTS))
my_syslog(MS_DHCP | LOG_INFO, _("%u client provides name: %s"), ntohl(mess->xid), client_hostname);
if (client_hostname)
{
struct dhcp_match_name *m;
size_t nl = strlen(client_hostname);
if (option_bool(OPT_LOG_OPTS))
my_syslog(MS_DHCP | LOG_INFO, _("%u client provides name: %s"), ntohl(mess->xid), client_hostname);
for (m = daemon->dhcp_name_match; m; m = m->next)
{
size_t ml = strlen(m->name);
char save = 0;
if (nl < ml)
continue;
if (nl > ml)
{
save = client_hostname[ml];
client_hostname[ml] = 0;
}
if (hostname_isequal(client_hostname, m->name) &&
(save == 0 || m->wildcard))
{
m->netid->next = netid;
netid = m->netid;
}
if (save != 0)
client_hostname[ml] = save;
}
}
if (have_config(config, CONFIG_NAME))
{
@@ -765,36 +793,6 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
}
}
}
if (hostname)
{
struct dhcp_match_name *m;
size_t nl = strlen(hostname);
for (m = daemon->dhcp_name_match; m; m = m->next)
{
size_t ml = strlen(m->name);
char save = 0;
if (nl < ml)
continue;
if (nl > ml)
{
save = hostname[ml];
hostname[ml] = 0;
}
if (hostname_isequal(hostname, m->name) &&
(save == 0 || m->wildcard))
{
m->netid->next = netid;
netid = m->netid;
}
if (save != 0)
hostname[ml] = save;
}
}
if (config)
{