Skip to content

Commit 4e87ecd

Browse files
committed
Compiles, binds to control ports. Compiles also without SSL (no
control ports). svn:NO TEST git-svn-id: file:///svn/nsd/trunk@3383 a26ef69c-88ff-0310-839f-98b793d9c207
1 parent cee36fb commit 4e87ecd

10 files changed

+289
-206
lines changed

Makefile.in

+8-7
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ CPPFLAGS = @CPPFLAGS@
4040
CFLAGS = @CFLAGS@
4141
LDFLAGS = @LDFLAGS@
4242
LIBS = @LIBS@
43+
SSL_LIBS = @SSL_LIBS@
4344
LIBOBJS = @LIBOBJS@
4445
INSTALL = $(srcdir)/install-sh -c
4546
INSTALL_PROGRAM = $(INSTALL)
@@ -177,7 +178,7 @@ whole: nsd-notify nsd-xfer nsdc.sh nsd-control-setup.sh nsd-checkconf nsd-contro
177178
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o nsd -combine -fwhole-program `echo $(NSD_OBJ) | sed -e 's;\\([^ \\.]*\\)\\.o;$(srcdir)/\\1.c;g'` $(LIBOBJS) $(LIBS)
178179

179180
nsd: $(NSD_OBJ) $(LIBOBJS)
180-
$(LINK) -o $@ $(NSD_OBJ) $(LIBOBJS) -lssl $(LIBS)
181+
$(LINK) -o $@ $(NSD_OBJ) $(LIBOBJS) $(SSL_LIBS)$(LIBS)
181182

182183
nsd-notify: $(NSD_NOTIFY_OBJ) $(LIBOBJS)
183184
$(LINK) -o $@ $(NSD_NOTIFY_OBJ) $(LIBOBJS) $(LIBS)
@@ -186,7 +187,7 @@ nsd-checkconf: $(NSD_CHECKCONF_OBJ) $(LIBOBJS)
186187
$(LINK) -o $@ $(NSD_CHECKCONF_OBJ) $(LIBOBJS) $(LIBS)
187188

188189
nsd-control: $(NSD_CONTROL_OBJ) $(LIBOBJS)
189-
$(LINK) -o $@ $(NSD_CONTROL_OBJ) $(LIBOBJS) -lssl $(LIBS)
190+
$(LINK) -o $@ $(NSD_CONTROL_OBJ) $(LIBOBJS) $(SSL_LIBS)$(LIBS)
190191

191192
nsd-xfer: $(NSD_XFER_OBJ) $(LIBOBJS)
192193
$(LINK) -o $@ $(NSD_XFER_OBJ) $(LIBOBJS) $(LIBS)
@@ -195,7 +196,7 @@ nsd-patch: $(NSD_PATCH_OBJ) $(LIBOBJS)
195196
$(LINK) -o $@ $(NSD_PATCH_OBJ) $(LIBOBJS) $(LIBS)
196197

197198
cutest: $(CUTEST_OBJ) $(LIBOBJS)
198-
$(LINK) -o $@ $(CUTEST_OBJ) $(LIBOBJS) -lssl $(LIBS)
199+
$(LINK) -o $@ $(CUTEST_OBJ) $(LIBOBJS) $(SSL_LIBS)$(LIBS)
199200

200201
udb-inspect: udb-inspect.o $(COMMON_OBJ) $(LIBOBJS)
201202
$(LINK) -o $@ udb-inspect.o $(COMMON_OBJ) $(LIBOBJS) $(LIBS)
@@ -396,7 +397,7 @@ namedb.o: $(srcdir)/namedb.c config.h $(srcdir)/namedb.h $(srcdir)/dname.h $(src
396397
$(srcdir)/util.h $(srcdir)/dns.h $(srcdir)/radtree.h
397398
netio.o: $(srcdir)/netio.c config.h $(srcdir)/netio.h $(srcdir)/region-allocator.h $(srcdir)/util.h
398399
nsd.o: $(srcdir)/nsd.c config.h $(srcdir)/nsd.h $(srcdir)/dns.h $(srcdir)/edns.h $(srcdir)/buffer.h $(srcdir)/region-allocator.h \
399-
$(srcdir)/util.h $(srcdir)/options.h $(srcdir)/rbtree.h $(srcdir)/tsig.h $(srcdir)/dname.h
400+
$(srcdir)/util.h $(srcdir)/options.h $(srcdir)/rbtree.h $(srcdir)/tsig.h $(srcdir)/dname.h $(srcdir)/remote.h
400401
nsd-checkconf.o: $(srcdir)/nsd-checkconf.c config.h $(srcdir)/tsig.h $(srcdir)/buffer.h \
401402
$(srcdir)/region-allocator.h $(srcdir)/util.h $(srcdir)/dname.h $(srcdir)/options.h $(srcdir)/rbtree.h
402403
nsd-control.o: $(srcdir)/nsd-control.c config.h $(srcdir)/util.h $(srcdir)/options.h $(srcdir)/region-allocator.h \
@@ -425,12 +426,12 @@ rbtree.o: $(srcdir)/rbtree.c config.h $(srcdir)/rbtree.h $(srcdir)/region-alloca
425426
rdata.o: $(srcdir)/rdata.c config.h $(srcdir)/rdata.h $(srcdir)/dns.h $(srcdir)/namedb.h $(srcdir)/dname.h $(srcdir)/buffer.h \
426427
$(srcdir)/region-allocator.h $(srcdir)/util.h $(srcdir)/radtree.h $(srcdir)/zonec.h
427428
region-allocator.o: $(srcdir)/region-allocator.c config.h $(srcdir)/region-allocator.h $(srcdir)/util.h
428-
remote.o: $(srcdir)/remote.c config.h $(srcdir)/remote.h $(srcdir)/util.h $(srcdir)/options.h $(srcdir)/region-allocator.h \
429-
$(srcdir)/rbtree.h
429+
remote.o: $(srcdir)/remote.c config.h $(srcdir)/remote.h $(srcdir)/util.h $(srcdir)/netio.h $(srcdir)/region-allocator.h \
430+
$(srcdir)/options.h $(srcdir)/rbtree.h
430431
server.o: $(srcdir)/server.c config.h $(srcdir)/axfr.h $(srcdir)/nsd.h $(srcdir)/dns.h $(srcdir)/edns.h $(srcdir)/buffer.h \
431432
$(srcdir)/region-allocator.h $(srcdir)/util.h $(srcdir)/query.h $(srcdir)/namedb.h $(srcdir)/dname.h $(srcdir)/radtree.h $(srcdir)/packet.h \
432433
$(srcdir)/tsig.h $(srcdir)/netio.h $(srcdir)/xfrd.h $(srcdir)/rbtree.h $(srcdir)/options.h $(srcdir)/xfrd-tcp.h $(srcdir)/difffile.h $(srcdir)/udb.h \
433-
$(srcdir)/nsec3.h $(srcdir)/ipc.h
434+
$(srcdir)/nsec3.h $(srcdir)/ipc.h $(srcdir)/remote.h
434435
tsig.o: $(srcdir)/tsig.c config.h $(srcdir)/tsig.h $(srcdir)/buffer.h $(srcdir)/region-allocator.h $(srcdir)/util.h $(srcdir)/dname.h \
435436
$(srcdir)/tsig-openssl.h $(srcdir)/dns.h $(srcdir)/packet.h $(srcdir)/namedb.h $(srcdir)/radtree.h $(srcdir)/query.h $(srcdir)/nsd.h $(srcdir)/edns.h
436437
tsig-openssl.o: $(srcdir)/tsig-openssl.c config.h $(srcdir)/tsig-openssl.h $(srcdir)/region-allocator.h \

configure.ac

+10-4
Original file line numberDiff line numberDiff line change
@@ -685,10 +685,16 @@ esac
685685

686686
# we need SSL for TSIG (and maybe also for NSEC3).
687687
CHECK_SSL
688-
ACX_LIB_SSL
689-
AC_CHECK_HEADERS([openssl/ssl.h],,, [AC_INCLUDES_DEFAULT])
690-
AC_CHECK_HEADERS([openssl/err.h],,, [AC_INCLUDES_DEFAULT])
691-
AC_CHECK_HEADERS([openssl/rand.h],,, [AC_INCLUDES_DEFAULT])
688+
if test x$HAVE_SSL = x"yes"; then
689+
ACX_LIB_SSL
690+
SSL_LIBS="-lssl "
691+
AC_SUBST(SSL_LIBS)
692+
AC_CHECK_HEADERS([openssl/ssl.h],,, [AC_INCLUDES_DEFAULT])
693+
AC_CHECK_HEADERS([openssl/err.h],,, [AC_INCLUDES_DEFAULT])
694+
AC_CHECK_HEADERS([openssl/rand.h],,, [AC_INCLUDES_DEFAULT])
695+
else
696+
AC_MSG_WARN([No SSL, therefore remote-control is disabled])
697+
fi
692698

693699
AC_ARG_ENABLE(nsec3, AC_HELP_STRING([--disable-nsec3], [Disable NSEC3 support]))
694700
case "$enable_nsec3" in

netio.c

-7
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ int pselect(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
2525
#include <sys/select.h>
2626
#endif
2727

28-
29-
struct netio_handler_list
30-
{
31-
netio_handler_list_type *next;
32-
netio_handler_type *handler;
33-
};
34-
3528
netio_type *
3629
netio_create(region_type *region)
3730
{

netio.h

+7
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ struct netio_handler
134134
};
135135

136136

137+
struct netio_handler_list
138+
{
139+
netio_handler_list_type *next;
140+
netio_handler_type *handler;
141+
};
142+
143+
137144
/*
138145
* Create a new netio instance using the specified REGION. The netio
139146
* instance is cleaned up when the REGION is deallocated.

nsd-control.c

+10
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
*/
4343

4444
#include "config.h"
45+
#ifdef HAVE_SSL
46+
4547
#include <sys/types.h>
4648
#include <unistd.h>
4749
#ifdef HAVE_OPENSSL_SSL_H
@@ -375,3 +377,11 @@ int main(int argc, char* argv[])
375377

376378
return go(cfgfile, svr, argc, argv);
377379
}
380+
381+
#else /* HAVE_SSL */
382+
int main(void)
383+
{
384+
printf("error: NSD was compiled without SSL.\n");
385+
return 1;
386+
}
387+
#endif /* HAVE_SSL */

nsd.c

+14-11
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "nsd.h"
4444
#include "options.h"
4545
#include "tsig.h"
46+
#include "remote.h"
4647

4748
/* The server handler... */
4849
static struct nsd nsd;
@@ -903,17 +904,15 @@ main(int argc, char *argv[])
903904
/* Child */
904905
break;
905906
case -1:
906-
log_msg(LOG_ERR, "fork() failed: %s", strerror(errno));
907-
exit(1);
907+
error("fork() failed: %s", strerror(errno));
908908
default:
909909
/* Parent is done */
910910
exit(0);
911911
}
912912

913913
/* Detach ourselves... */
914914
if (setsid() == -1) {
915-
log_msg(LOG_ERR, "setsid() failed: %s", strerror(errno));
916-
exit(1);
915+
error("setsid() failed: %s", strerror(errno));
917916
}
918917

919918
if ((fd = open("/dev/null", O_RDWR, 0)) != -1) {
@@ -955,10 +954,16 @@ main(int argc, char *argv[])
955954

956955
/* Initialize the server... */
957956
if (server_init(&nsd) != 0) {
958-
log_msg(LOG_ERR, "server initialization failed, %s could "
957+
error("server initialization failed, %s could "
959958
"not be started", argv0);
960-
exit(1);
961959
}
960+
#if defined(HAVE_SSL)
961+
if(nsd.options->control_enable) {
962+
/* read ssl keys while superuser and outside chroot */
963+
if(!(nsd.rc = daemon_remote_create(nsd.options)))
964+
error("could not perform remote control setup");
965+
}
966+
#endif /* HAVE_SSL */
962967

963968
/* Set user context */
964969
#ifdef HAVE_GETPWNAM
@@ -998,8 +1003,7 @@ main(int argc, char *argv[])
9981003
nsd.options->difffile += l;
9991004

10001005
if (chroot(nsd.chrootdir)) {
1001-
log_msg(LOG_ERR, "unable to chroot: %s", strerror(errno));
1002-
exit(1);
1006+
error("unable to chroot: %s", strerror(errno));
10031007
}
10041008
DEBUG(DEBUG_IPC,1, (LOG_INFO, "changed root directory to %s",
10051009
nsd.chrootdir));
@@ -1059,10 +1063,9 @@ main(int argc, char *argv[])
10591063
server_start_xfrd(&nsd, 0);
10601064
}
10611065
if (server_prepare(&nsd) != 0) {
1062-
log_msg(LOG_ERR, "server preparation failed, %s could "
1063-
"not be started", argv0);
10641066
unlinkpid(nsd.pidfile);
1065-
exit(1);
1067+
error("server preparation failed, %s could "
1068+
"not be started", argv0);
10661069
}
10671070
if(nsd.server_kind == NSD_SERVER_MAIN) {
10681071
server_send_soa_xfrd(&nsd);

nsd.h

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
struct netio_handler;
1818
struct nsd_options;
1919
struct udb_base;
20+
struct daemon_remote;
2021

2122
/* The NSD runtime states and NSD ipc command values */
2223
#define NSD_RUN 0
@@ -151,6 +152,7 @@ struct nsd
151152
int mytask; /* the base used by this process */
152153
struct netio_handler* xfrd_listener;
153154
pid_t xfrd_pid;
155+
struct daemon_remote* rc;
154156

155157
/* Configuration */
156158
const char *dbfile;

0 commit comments

Comments
 (0)