Browse Source

do not listen anywhere by default.

listen on *
listens, well, everywhere.
OPENBSD_3_6
henning 20 years ago
parent
commit
e74cfb6cd2
4 changed files with 26 additions and 8 deletions
  1. +5
    -1
      src/usr.sbin/ntpd/config.c
  2. +2
    -1
      src/usr.sbin/ntpd/ntpd.h
  3. +17
    -4
      src/usr.sbin/ntpd/parse.y
  4. +2
    -2
      src/usr.sbin/ntpd/server.c

+ 5
- 1
src/usr.sbin/ntpd/config.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: config.c,v 1.5 2004/07/07 03:53:14 henning Exp $ */
/* $OpenBSD: config.c,v 1.6 2004/07/07 05:47:57 henning Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -77,6 +77,10 @@ host(const char *s, u_int8_t *len)
mask = 128; mask = 128;
} }
if (!strcmp(s, "*"))
if ((h = calloc(1, sizeof(struct ntp_addr))) == NULL)
fatal(NULL);
/* IPv4 address? */ /* IPv4 address? */
if (h == NULL) if (h == NULL)
h = host_v4(s, len); h = host_v4(s, len);


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

@ -1,4 +1,4 @@
/* $OpenBSD: ntpd.h,v 1.15 2004/07/07 03:15:37 henning Exp $ */
/* $OpenBSD: ntpd.h,v 1.16 2004/07/07 05:47:57 henning Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -90,6 +90,7 @@ struct ntpd_conf {
TAILQ_HEAD(listen_addrs, listen_addr) listen_addrs; TAILQ_HEAD(listen_addrs, listen_addr) listen_addrs;
TAILQ_HEAD(ntp_peers, ntp_peer) ntp_peers; TAILQ_HEAD(ntp_peers, ntp_peer) ntp_peers;
u_int8_t opts; u_int8_t opts;
u_int8_t listen_all;
}; };
struct buf { struct buf {


+ 17
- 4
src/usr.sbin/ntpd/parse.y View File

@ -1,4 +1,4 @@
/* $OpenBSD: parse.y,v 1.5 2004/07/07 03:15:37 henning Exp $ */
/* $OpenBSD: parse.y,v 1.6 2004/07/07 05:47:57 henning Exp $ */
/* /*
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -124,12 +124,17 @@ varset : STRING '=' string {
} }
; ;
conf_main : LISTEN ON address {
conf_main : LISTEN ON address {
struct listen_addr *la; struct listen_addr *la;
struct ntp_addr *h, *next; struct ntp_addr *h, *next;
for (h = $3; h != NULL; h = next) { for (h = $3; h != NULL; h = next) {
next = h->next; next = h->next;
if (h->ss.ss_family == AF_UNSPEC) {
conf->listen_all = 1;
free(h);
continue;
}
la = calloc(1, sizeof(struct listen_addr)); la = calloc(1, sizeof(struct listen_addr));
if (la == NULL) if (la == NULL)
fatal("listen on calloc"); fatal("listen on calloc");
@ -144,9 +149,15 @@ conf_main : LISTEN ON address {
| SERVER address { | SERVER address {
struct ntp_peer *p; struct ntp_peer *p;
struct ntp_addr *h, *next; struct ntp_addr *h, *next;
for (h = $2; h != NULL; h = next) {
for (h = $2; h != NULL; h = next) {
next = h->next; next = h->next;
if (h->ss.ss_family != AF_INET &&
h->ss.ss_family != AF_INET6) {
yyerror("IPv4 or IPv6 address "
"or hostname expected");
YYERROR;
}
p = calloc(1, sizeof(struct ntp_peer)); p = calloc(1, sizeof(struct ntp_peer));
if (p == NULL) if (p == NULL)
fatal("conf_main server calloc"); fatal("conf_main server calloc");
@ -483,6 +494,8 @@ parse_config(char *filename, struct ntpd_conf *xconf)
TAILQ_INSERT_TAIL(&xconf->ntp_peers, p, entry); TAILQ_INSERT_TAIL(&xconf->ntp_peers, p, entry);
} }
xconf->listen_all = conf->listen_all;
free(conf); free(conf);
return (errors ? -1 : 0); return (errors ? -1 : 0);


+ 2
- 2
src/usr.sbin/ntpd/server.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: server.c,v 1.4 2004/07/04 18:07:15 henning Exp $ */
/* $OpenBSD: server.c,v 1.5 2004/07/07 05:47:57 henning Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -36,7 +36,7 @@ setup_listeners(struct servent *se, struct ntpd_conf *conf, u_int *cnt)
struct sockaddr *sap; struct sockaddr *sap;
u_int new_cnt = 0; u_int new_cnt = 0;
if (TAILQ_EMPTY(&conf->listen_addrs)) {
if (conf->listen_all) {
if (getifaddrs(&ifap) == -1) if (getifaddrs(&ifap) == -1)
fatal("getifaddrs"); fatal("getifaddrs");


Loading…
Cancel
Save