Browse Source

remove all handling of netmasks/prefix lengths - we don't need that in ntpd.

fixes the dns resolves to v4 and v6 addresses bug found by phessler
hacked on the Calgary->Montreal flight that proved that Air Canada _does_
have some modern aircrafts with good seats
OPENBSD_3_6
henning 20 years ago
parent
commit
7364dc1c59
3 changed files with 16 additions and 61 deletions
  1. +12
    -43
      src/usr.sbin/ntpd/config.c
  2. +2
    -2
      src/usr.sbin/ntpd/ntpd.h
  3. +2
    -16
      src/usr.sbin/ntpd/parse.y

+ 12
- 43
src/usr.sbin/ntpd/config.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: config.c,v 1.6 2004/07/07 05:47:57 henning Exp $ */
/* $OpenBSD: config.c,v 1.7 2004/07/08 01:22:57 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -27,9 +27,9 @@
#include "ntpd.h"
struct ntp_addr *host_v4(const char *, u_int8_t *);
struct ntp_addr *host_v4(const char *);
struct ntp_addr *host_v6(const char *);
struct ntp_addr *host_dns(const char *, u_int8_t *);
struct ntp_addr *host_dns(const char *);
int
check_file_secrecy(int fd, const char *fname)
@ -55,67 +55,39 @@ check_file_secrecy(int fd, const char *fname)
}
struct ntp_addr *
host(const char *s, u_int8_t *len)
host(const char *s)
{
int mask;
char *p, *q, *ps;
struct ntp_addr *h = NULL;
if ((p = strrchr(s, '/')) != NULL) {
errno = 0;
mask = strtol(p+1, &q, 0);
if (errno == ERANGE || !q || *q || mask > 128 || q == (p+1)) {
log_warnx("invalid netmask");
return (NULL);
}
if ((ps = malloc(strlen(s) - strlen(p) + 1)) == NULL)
fatal("host: malloc");
strlcpy(ps, s, strlen(s) - strlen(p) + 1);
} else {
if ((ps = strdup(s)) == NULL)
fatal("host: strdup");
mask = 128;
}
if (!strcmp(s, "*"))
if ((h = calloc(1, sizeof(struct ntp_addr))) == NULL)
fatal(NULL);
/* IPv4 address? */
if (h == NULL)
h = host_v4(s, len);
h = host_v4(s);
/* IPv6 address? */
if (h == NULL) {
h = host_v6(ps);
*len = mask;
}
if (h == NULL)
h = host_v6(s);
/* Hostname? */
if (h == NULL)
h = host_dns(ps, len);
free(ps);
h = host_dns(s);
return (h);
}
struct ntp_addr *
host_v4(const char *s, u_int8_t *len)
host_v4(const char *s)
{
struct in_addr ina;
struct sockaddr_in *sa_in;
struct ntp_addr *h;
int bits = 32;
bzero(&ina, sizeof(struct in_addr));
if (strrchr(s, '/') != NULL) {
if ((bits = inet_net_pton(AF_INET, s, &ina, sizeof(ina))) == -1)
return (NULL);
} else {
if (inet_pton(AF_INET, s, &ina) != 1)
return (NULL);
}
if (inet_pton(AF_INET, s, &ina) != 1)
return (NULL);
if ((h = calloc(1, sizeof(struct ntp_addr))) == NULL)
fatal(NULL);
@ -123,7 +95,6 @@ host_v4(const char *s, u_int8_t *len)
sa_in->sin_len = sizeof(struct sockaddr_in);
sa_in->sin_family = AF_INET;
sa_in->sin_addr.s_addr = ina.s_addr;
*len = bits;
return (h);
}
@ -158,7 +129,7 @@ host_v6(const char *s)
}
struct ntp_addr *
host_dns(const char *s, u_int8_t *len)
host_dns(const char *s)
{
struct addrinfo hints, *res0, *res;
int error;
@ -185,13 +156,11 @@ host_dns(const char *s, u_int8_t *len)
sa_in->sin_len = sizeof(struct sockaddr_in);
sa_in->sin_addr.s_addr = ((struct sockaddr_in *)
res->ai_addr)->sin_addr.s_addr;
*len = 32;
} else {
sa_in6 = (struct sockaddr_in6 *)&h->ss;
sa_in6->sin6_len = sizeof(struct sockaddr_in6);
memcpy(&sa_in6->sin6_addr, &((struct sockaddr_in6 *)
res->ai_addr)->sin6_addr, sizeof(struct in6_addr));
*len = 128;
}
h->next = hh;


+ 2
- 2
src/usr.sbin/ntpd/ntpd.h View File

@ -1,4 +1,4 @@
/* $OpenBSD: ntpd.h,v 1.17 2004/07/07 07:32:05 alexander Exp $ */
/* $OpenBSD: ntpd.h,v 1.18 2004/07/08 01:22:57 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -184,7 +184,7 @@ int cmdline_symset(char *);
/* config.c */
int check_file_secrecy(int, const char *);
struct ntp_addr *host(const char *, u_int8_t *);
struct ntp_addr *host(const char *);
/* ntp_msg.c */
int ntp_getmsg(char *, ssize_t, struct ntp_msg *);


+ 2
- 16
src/usr.sbin/ntpd/parse.y View File

@ -1,4 +1,4 @@
/* $OpenBSD: parse.y,v 1.7 2004/07/07 06:51:16 deraadt Exp $ */
/* $OpenBSD: parse.y,v 1.8 2004/07/08 01:22:57 henning Exp $ */
/*
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -170,27 +170,13 @@ conf_main : LISTEN ON address {
;
address : STRING {
u_int8_t len;
struct ntp_addr *h;
if (($$ = host($1, &len)) == NULL) {
if (($$ = host($1)) == NULL) {
yyerror("could not parse address spec \"%s\"",
$1);
free($1);
YYERROR;
}
free($1);
for (h = $$; h != NULL; h = h->next)
if ((h->ss.ss_family == AF_INET && len != 32) ||
(h->ss.ss_family == AF_INET6 && len != 128))
{
/* unreachable */
yyerror("got prefixlen %u, expected %u",
len, h->ss.ss_family ==
AF_INET ? 32 : 128);
YYERROR;
}
}
;


Loading…
Cancel
Save