forked from Lainports/freebsd-ports
There are a few bugs in dnrd that should probably be fixed by the author but could be made to work on bsd: 1. Initialization in common.h of recv_addr is broken, causing at least the '-a' switch not to work. Instead of assuming positions of fields in the struct across platforms I thought it safer to do a standard initialization in main(). 2. The buffer overflow code in udp.c:dnsrecv() is off by one, rejecting messages where the size exactly fills the available buffer. I also changed to the calls to dnsrecv to pass 512 as the max size instead of the buffers that seem to be padded by 4 bytes for a reason I don't understand. This causes a calling named to resend packets. Eventually one seems to get through but response times can be painfully slow. PR: ports/41128 Submitted by: Michael C. Adler <mad1@tapil.com>
94 lines
2.9 KiB
C
94 lines
2.9 KiB
C
--- main.c.orig Fri Jan 5 01:40:42 2001
|
|
+++ main.c Sat Jan 3 16:39:25 2004
|
|
@@ -18,6 +18,7 @@
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
*/
|
|
|
|
+#include <sys/types.h>
|
|
#include "relay.h"
|
|
#include "cache.h"
|
|
#include "common.h"
|
|
@@ -26,7 +27,6 @@
|
|
#include "master.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
-#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/socket.h>
|
|
#include <sys/stat.h>
|
|
@@ -82,6 +82,10 @@
|
|
/*
|
|
* Parse the command line.
|
|
*/
|
|
+ memset(&recv_addr, 0, sizeof(recv_addr));
|
|
+ recv_addr.sin_family = AF_INET;
|
|
+ recv_addr.sin_port = htons(53);
|
|
+
|
|
parse_args(argc, argv);
|
|
|
|
openlog(progname, LOG_PID, LOG_DAEMON);
|
|
@@ -170,20 +174,20 @@
|
|
* Change our root and current working directories to /etc/dnrd.
|
|
* Also, so some sanity checking on that directory first.
|
|
*/
|
|
- dirp = opendir("/etc/dnrd");
|
|
+ dirp = opendir("%%PREFIX%%/etc/dnrd");
|
|
if (!dirp) {
|
|
- log_msg(LOG_ERR, "The directory /etc/dnrd must be created before "
|
|
+ log_msg(LOG_ERR, "The directory %%PREFIX%%/etc/dnrd must be created before "
|
|
"dnrd will run");
|
|
}
|
|
|
|
- rslt = stat("/etc/dnrd", &st);
|
|
+ rslt = stat("%%PREFIX%%/etc/dnrd", &st);
|
|
if (st.st_uid != 0) {
|
|
- log_msg(LOG_ERR, "The /etc/dnrd directory must be owned by root");
|
|
+ log_msg(LOG_ERR, "The %%PREFIX%%/dnrd directory must be owned by root");
|
|
cleanexit(-1);
|
|
}
|
|
if ((st.st_mode & (S_IWGRP | S_IWOTH)) != 0) {
|
|
log_msg(LOG_ERR,
|
|
- "The /etc/dnrd directory should only be user writable");
|
|
+ "The %%PREFIX%%/etc/dnrd directory should only be user writable");
|
|
cleanexit(-1);
|
|
}
|
|
|
|
@@ -198,31 +202,31 @@
|
|
|
|
if (rslt) continue;
|
|
if (S_ISDIR(st.st_mode)) {
|
|
- log_msg(LOG_ERR, "The /etc/dnrd directory must not contain "
|
|
+ log_msg(LOG_ERR, "The %%PREFIX%%/etc/dnrd directory must not contain "
|
|
"subdirectories");
|
|
cleanexit(-1);
|
|
}
|
|
if ((st.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH|S_IWGRP|S_IWOTH)) != 0) {
|
|
- log_msg(LOG_ERR, "A file in /etc/dnrd has either execute "
|
|
+ log_msg(LOG_ERR, "A file in %%PREFIX%%/etc/dnrd has either execute "
|
|
"permissions or non-user write permission. Please do a "
|
|
"\"chmod a-x,go-w\" on all files in this directory");
|
|
cleanexit(-1);
|
|
}
|
|
if (st.st_uid != 0) {
|
|
- log_msg(LOG_ERR, "All files in /etc/dnrd must be owned by root");
|
|
+ log_msg(LOG_ERR, "All files in %%PREFIX%%/etc/dnrd must be owned by root");
|
|
cleanexit(-1);
|
|
}
|
|
}
|
|
closedir(dirp);
|
|
|
|
- if (chdir("/etc/dnrd")) {
|
|
+ if (chdir("%%PREFIX%%/etc/dnrd")) {
|
|
log_msg(LOG_ERR, "couldn't chdir to %s, %s",
|
|
- "/etc/dnrd", strerror(errno));
|
|
+ "%%PREFIX%%/etc/dnrd", strerror(errno));
|
|
cleanexit(-1);
|
|
}
|
|
- if (chroot("/etc/dnrd")) {
|
|
+ if (chroot("%%PREFIX%%/etc/dnrd")) {
|
|
log_msg(LOG_ERR, "couldn't chroot to %s, %s",
|
|
- "/etc/dnrd", strerror(errno));
|
|
+ "%%PREFIX%%/etc/dnrd", strerror(errno));
|
|
cleanexit(-1);
|
|
}
|
|
|