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))
{
@@ -766,36 +794,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)
{
struct dhcp_netid_list *list;

View File

@@ -501,9 +501,37 @@ static int dhcp6_no_relay(struct state *state, int msg_type, void *inbuff, size_
if (legal_hostname(daemon->dhcp_buff))
{
struct dhcp_match_name *m;
size_t nl = strlen(daemon->dhcp_buff);
state->client_hostname = daemon->dhcp_buff;
if (option_bool(OPT_LOG_OPTS))
my_syslog(MS_DHCP | LOG_INFO, _("%u client provides name: %s"), state->xid, state->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 = state->client_hostname[ml];
state->client_hostname[ml] = 0;
}
if (hostname_isequal(state->client_hostname, m->name) &&
(save == 0 || m->wildcard))
{
m->netid->next = state->tags;
state->tags = m->netid;
}
if (save != 0)
state->client_hostname[ml] = save;
}
}
}
}
@@ -536,36 +564,6 @@ static int dhcp6_no_relay(struct state *state, int msg_type, void *inbuff, size_
}
}
if (state->hostname)
{
struct dhcp_match_name *m;
size_t nl = strlen(state->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 = state->hostname[ml];
state->hostname[ml] = 0;
}
if (hostname_isequal(state->hostname, m->name) &&
(save == 0 || m->wildcard))
{
m->netid->next = state->tags;
state->tags = m->netid;
}
if (save != 0)
state->hostname[ml] = save;
}
}
if (config)
{
struct dhcp_netid_list *list;