--domain=# is valid. --synth-domain=# isn't.

This commit is contained in:
Simon Kelley committed 2023-03-31 23:28:56 +01:00
1 parent c244d92d8a
commit 047256a6d8
1 file changed
+160 -157
+160 -157
View File
@@ -2568,179 +2568,182 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
case 's': /* --domain */ case 's': /* --domain */
case LOPT_SYNTH: /* --synth-domain */ case LOPT_SYNTH: /* --synth-domain */
if (strcmp (arg, "#") == 0) {
set_option_bool(OPT_RESOLV_DOMAIN); char *d, *d_raw = arg;
else comma = split(arg);
{ if (!(d = canonicalise_opt(d_raw)))
char *d, *d_raw = arg; ret_err(gen_err);
comma = split(arg); else
if (!(d = canonicalise_opt(d_raw))) {
ret_err(gen_err); free(d); /* allocate this again below. */
else if (comma)
{ {
free(d); /* allocate this again below. */ struct cond_domain *new = opt_malloc(sizeof(struct cond_domain));
if (comma) char *netpart;
{
struct cond_domain *new = opt_malloc(sizeof(struct cond_domain));
char *netpart;
new->prefix = NULL; new->prefix = NULL;
new->indexed = 0; new->indexed = 0;
new->prefixlen = 0; new->prefixlen = 0;
unhide_metas(comma); unhide_metas(comma);
if ((netpart = split_chr(comma, '/'))) if ((netpart = split_chr(comma, '/')))
{ {
int msize; int msize;
arg = split(netpart); arg = split(netpart);
if (!atoi_check(netpart, &msize)) if (!atoi_check(netpart, &msize))
ret_err_free(gen_err, new); ret_err_free(gen_err, new);
else if (inet_pton(AF_INET, comma, &new->start)) else if (inet_pton(AF_INET, comma, &new->start))
{ {
int mask; int mask;
if (msize > 32) if (msize > 32)
ret_err_free(_("bad prefix length"), new); ret_err_free(_("bad prefix length"), new);
mask = (1 << (32 - msize)) - 1; mask = (1 << (32 - msize)) - 1;
new->is6 = 0; new->is6 = 0;
new->start.s_addr = ntohl(htonl(new->start.s_addr) & ~mask); new->start.s_addr = ntohl(htonl(new->start.s_addr) & ~mask);
new->end.s_addr = new->start.s_addr | htonl(mask); new->end.s_addr = new->start.s_addr | htonl(mask);
if (arg) if (arg)
{ {
if (option != 's') if (option != 's')
{ {
if (!(new->prefix = canonicalise_opt(arg)) || if (!(new->prefix = canonicalise_opt(arg)) ||
strlen(new->prefix) > MAXLABEL - INET_ADDRSTRLEN) strlen(new->prefix) > MAXLABEL - INET_ADDRSTRLEN)
ret_err_free(_("bad prefix"), new); ret_err_free(_("bad prefix"), new);
} }
else if (strcmp(arg, "local") != 0) else if (strcmp(arg, "local") != 0)
ret_err_free(gen_err, new); ret_err_free(gen_err, new);
else else
{ {
/* local=/xxx.yyy.zzz.in-addr.arpa/ */ /* local=/xxx.yyy.zzz.in-addr.arpa/ */
domain_rev4(0, NULL, &new->start, msize); domain_rev4(0, NULL, &new->start, msize);
/* local=/<domain>/ */ /* local=/<domain>/ */
/* d_raw can't failed to canonicalise here, checked above. */ /* d_raw can't failed to canonicalise here, checked above. */
add_update_server(SERV_LITERAL_ADDRESS, NULL, NULL, NULL, d_raw, NULL); add_update_server(SERV_LITERAL_ADDRESS, NULL, NULL, NULL, d_raw, NULL);
} }
} }
} }
else if (inet_pton(AF_INET6, comma, &new->start6)) else if (inet_pton(AF_INET6, comma, &new->start6))
{ {
u64 mask, addrpart = addr6part(&new->start6); u64 mask, addrpart = addr6part(&new->start6);
if (msize > 128) if (msize > 128)
ret_err_free(_("bad prefix length"), new); ret_err_free(_("bad prefix length"), new);
mask = (1LLU << (128 - msize)) - 1LLU; mask = (1LLU << (128 - msize)) - 1LLU;
new->is6 = 1; new->is6 = 1;
new->prefixlen = msize; new->prefixlen = msize;
/* prefix==64 overflows the mask calculation above */ /* prefix==64 overflows the mask calculation above */
if (msize <= 64) if (msize <= 64)
mask = (u64)-1LL; mask = (u64)-1LL;
new->end6 = new->start6; new->end6 = new->start6;
setaddr6part(&new->start6, addrpart & ~mask); setaddr6part(&new->start6, addrpart & ~mask);
setaddr6part(&new->end6, addrpart | mask); setaddr6part(&new->end6, addrpart | mask);
if (arg) if (arg)
{ {
if (option != 's') if (option != 's')
{ {
if (!(new->prefix = canonicalise_opt(arg)) || if (!(new->prefix = canonicalise_opt(arg)) ||
strlen(new->prefix) > MAXLABEL - INET6_ADDRSTRLEN) strlen(new->prefix) > MAXLABEL - INET6_ADDRSTRLEN)
ret_err_free(_("bad prefix"), new); ret_err_free(_("bad prefix"), new);
} }
else if (strcmp(arg, "local") != 0) else if (strcmp(arg, "local") != 0)
ret_err_free(gen_err, new); ret_err_free(gen_err, new);
else else
{ {
/* generate the equivalent of /* generate the equivalent of
local=/xxx.yyy.zzz.ip6.arpa/ */ local=/xxx.yyy.zzz.ip6.arpa/ */
domain_rev6(0, NULL, &new->start6, msize); domain_rev6(0, NULL, &new->start6, msize);
/* local=/<domain>/ */ /* local=/<domain>/ */
/* d_raw can't failed to canonicalise here, checked above. */ /* d_raw can't failed to canonicalise here, checked above. */
add_update_server(SERV_LITERAL_ADDRESS, NULL, NULL, NULL, d_raw, NULL); add_update_server(SERV_LITERAL_ADDRESS, NULL, NULL, NULL, d_raw, NULL);
} }
} }
} }
else else
ret_err_free(gen_err, new); ret_err_free(gen_err, new);
} }
else else
{ {
char *prefstr; char *prefstr;
arg = split(comma); arg = split(comma);
prefstr = split(arg); prefstr = split(arg);
if (inet_pton(AF_INET, comma, &new->start)) if (inet_pton(AF_INET, comma, &new->start))
{ {
new->is6 = 0; new->is6 = 0;
if (!arg) if (!arg)
new->end.s_addr = new->start.s_addr; new->end.s_addr = new->start.s_addr;
else if (!inet_pton(AF_INET, arg, &new->end)) else if (!inet_pton(AF_INET, arg, &new->end))
ret_err_free(gen_err, new); ret_err_free(gen_err, new);
} }
else if (inet_pton(AF_INET6, comma, &new->start6)) else if (inet_pton(AF_INET6, comma, &new->start6))
{ {
new->is6 = 1; new->is6 = 1;
if (!arg) if (!arg)
memcpy(&new->end6, &new->start6, IN6ADDRSZ); memcpy(&new->end6, &new->start6, IN6ADDRSZ);
else if (!inet_pton(AF_INET6, arg, &new->end6)) else if (!inet_pton(AF_INET6, arg, &new->end6))
ret_err_free(gen_err, new); ret_err_free(gen_err, new);
} }
else if (option == 's') else if (option == 's')
{ {
/* subnet from interface. */ /* subnet from interface. */
new->interface = opt_string_alloc(comma); new->interface = opt_string_alloc(comma);
new->al = NULL; new->al = NULL;
} }
else else
ret_err_free(gen_err, new); ret_err_free(gen_err, new);
if (option != 's' && prefstr) if (option != 's' && prefstr)
{ {
if (!(new->prefix = canonicalise_opt(prefstr)) || if (!(new->prefix = canonicalise_opt(prefstr)) ||
strlen(new->prefix) > MAXLABEL - INET_ADDRSTRLEN) strlen(new->prefix) > MAXLABEL - INET_ADDRSTRLEN)
ret_err_free(_("bad prefix"), new); ret_err_free(_("bad prefix"), new);
} }
} }
new->domain = canonicalise_opt(d_raw); new->domain = canonicalise_opt(d_raw);
if (option == 's') if (option == 's')
{ {
new->next = daemon->cond_domain; new->next = daemon->cond_domain;
daemon->cond_domain = new; daemon->cond_domain = new;
} }
else else
{ {
char *star; char *star;
if (new->prefix && if (new->prefix &&
(star = strrchr(new->prefix, '*')) (star = strrchr(new->prefix, '*'))
&& *(star+1) == 0) && *(star+1) == 0)
{ {
*star = 0; *star = 0;
new->indexed = 1; new->indexed = 1;
if (new->is6 && new->prefixlen < 64) if (new->is6 && new->prefixlen < 64)
ret_err_free(_("prefix length too small"), new); ret_err_free(_("prefix length too small"), new);
} }
new->next = daemon->synth_domains; new->next = daemon->synth_domains;
daemon->synth_domains = new; daemon->synth_domains = new;
} }
} }
else if (option == 's') else if (option == 's')
daemon->domain_suffix = canonicalise_opt(d_raw); {
else if (strcmp (arg, "#") == 0)
ret_err(gen_err); set_option_bool(OPT_RESOLV_DOMAIN);
} else
} daemon->domain_suffix = canonicalise_opt(d_raw);
break; }
else
ret_err(gen_err);
}
break;
}
case LOPT_CPE_ID: /* --add-dns-client */ case LOPT_CPE_ID: /* --add-dns-client */
if (arg) if (arg)