Commit Diff
Diff:
f665f992b81aec4f83c19b8a31315d1c9c7df32b
9c4921a5918c8baac9f2e2903dfc6d58a0c63395
Commit:
9c4921a5918c8baac9f2e2903dfc6d58a0c63395
Tree:
346a461e9b1b2f2b8ba4589826b37026db5db795
Author:
pbug <pbug@delphinusdns.org>
Committer:
pbug <pbug@delphinusdns.org>
Date:
Thu Apr 10 09:56:09 2008 UTC
Message:
* port to Linux * compiles and runs on: - NetBSD 4.0 - FreeBSD 7.0 - DragonFlyBSD - OpenBSD 4.2 - Linux Redhat WS 5
blob - ffa9b491393f5bc2342eac3ddced1c67f8bfde6d
blob + 9135f78e6e555be1810bbc6e0cfb59d23bf9ecae
--- README
+++ README
@@ -1,6 +1,10 @@
README
+FIRSTOFF
+
To install type make, followed by make install.
+(In linux type make -f Makefile.linux, make a user named "named" for the
+chroot to work).
By default installation the configuration file is not installed you need to
do this manually. Also by default the config file is specified as
@@ -13,3 +17,12 @@ straight forward.
Enjoy using Wildcard DNS.
-peter
+
+COMPATIBILITY
+
+------------------+----------+------------+-----------+----------+-----------+
+Operating System: |NetBSD 4.0| OpenBSD 4.2|FreeBSD 7.0| DragonFly|Redhat WS5 |
+------------------+----------+------------+-----------+----------+-----------+
+compiles & makes | yes | yes | yes | yes | yes |
+responds queries | yes | yes | yes | yes | yes |
+------------------+----------+------------+-----------+----------+-----------+
blob - a3a4f09038850f8a9dd31aa7e9940b3dbcdf7da4
blob + 83d025556082e5507f50663406f3bdc958d6296d
--- include.h
+++ include.h
@@ -51,4 +51,8 @@
#include <pwd.h>
#include <ifaddrs.h>
+#ifndef NTOHS
+#include "endian.h"
+#endif
+
#endif
blob - ca0227f462f1fa467ce26155b57db643f8558f95
blob + 1b766d80dc5aece8e2c2d6ef2a481250f8e22a9b
--- main.c
+++ main.c
@@ -131,6 +131,22 @@ main(int argc, char *argv[])
exit(1);
}
+#if DB_VERSION_MAJOR > 3
+
+ if (db_create((DB **)&db, (DB_ENV *)NULL, 0) != 0) {
+ perror("db_create");
+ exit(1);
+ }
+
+ if (db->open(db, NULL, NULL, NULL, DB_BTREE, DB_CREATE, 0600) != 0) {
+ perror("db->open");
+ db->close(db, DB_NOSYNC);
+ exit(1);
+ }
+
+#else
+
+
db = dbopen(NULL, O_RDWR, 0, DB_BTREE, NULL);
if (db == NULL) {
@@ -138,6 +154,7 @@ main(int argc, char *argv[])
exit(1);
}
+#endif
parse_file(db, conffile);
@@ -269,8 +286,10 @@ main(int argc, char *argv[])
}
}
+#ifndef DEBUG
/* chroot to the drop priv user home directory */
chroot(pw->pw_dir);
+#endif
/* set groups */
@@ -279,6 +298,7 @@ main(int argc, char *argv[])
exit(1);
}
+#ifdef __OpenBSD__
if (setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) < 0) {
perror("setresgid");
exit(1);
@@ -289,6 +309,18 @@ main(int argc, char *argv[])
exit(1);
}
+#else
+ if (setgid(pw->pw_gid) < 0) {
+ perror("setgid");
+ exit(1);
+ }
+ if (setuid(pw->pw_uid) < 0) {
+ perror("setuid");
+ exit(1);
+ }
+#endif
+
+
#ifndef DEBUG
daemon(0,0);
#endif
@@ -374,7 +406,7 @@ mainloop(int *udp, int *tcp, int sockcount, char **ide
if (FD_ISSET(udp[i], &rset)) {
so = udp[i];
fromlen = sizeof(sockaddr_large);
- len = recvfrom(so, buf, sizeof(buf), 0, from, &fromlen);
+ len = recvfrom(so, buf, sizeof(buf), 0, from, (socklen_t *)&fromlen);
if (len < 0) {
syslog(LOG_INFO, "recvfrom: on descriptor %u interface \"%s\" %m", so, ident[i]);
continue;
@@ -608,7 +640,8 @@ build_question(char *buf, int len)
/* find the end of name */
for (i = sizeof(struct dns_header); i < len; i++) {
- if (buf[i] == NULL) {
+ /* XXX */
+ if (buf[i] == 0) {
end_name = &buf[i];
break;
}
@@ -709,12 +742,15 @@ build_question(char *buf, int len)
/* i is reused here to count every character, this is not a bug */
for (i++; i < labelend; i++) {
+ int c0;
+
if ((buf[i] & 0xc0) == 0xc0) {
syslog(LOG_INFO, "has compressed name");
free_question(q);
return NULL; /* XXX should say error */
}
- *p++ = tolower(buf[i]);
+ c0 = buf[i];
+ *p++ = tolower(c0);
}
*p++ = '.';
@@ -733,8 +769,11 @@ build_question(char *buf, int len)
/* make it lower case */
for (i = 0; i < q->hdr->namelen; i++) {
- if (isalpha(q->hdr->name[i])) {
- q->hdr->name[i] = tolower(q->hdr->name[i]);
+ int c0;
+
+ c0 = q->hdr->name[i];
+ if (isalpha(c0)) {
+ q->hdr->name[i] = tolower(c0);
}
}
@@ -785,7 +824,12 @@ dns_label(char *name, int *returnlen)
if (name == NULL)
return NULL;
+#if __linux__
+ strncpy(tname, name, sizeof(tname));
+ tname[sizeof(tname) - 1] = 0;
+#else
strlcpy(tname, name, sizeof(tname));
+#endif
len = strlen(tname);
if (tname[len - 1] == '.')
@@ -808,7 +852,13 @@ dns_label(char *name, int *returnlen)
for (i = 0, p = dnslabel; i < lc; i++) {
len = strlen(labels[i]);
*p++ = len;
+#if __linux__
+ /* XXX */
+ strncpy(p, labels[i], newlen - (p - dnslabel) + 1);
+ p[newlen - (p - dnslabel)] = 0;
+#else
strlcpy(p, labels[i], newlen - (p - dnslabel) + 1);
+#endif
p += len;
}
@@ -818,8 +868,11 @@ dns_label(char *name, int *returnlen)
*/
for (i = 0, p = dnslabel; i < *returnlen; i++) {
- if (isalpha(*p))
- *p = tolower(*p);
+ int c;
+
+ c = *p;
+ if (isalpha(c))
+ *p = tolower(c);
p++;
}
@@ -851,7 +904,7 @@ compress_label(char *buf, int offset, int labellen)
p = &buf[offset - labellen];
checklen = labellen;
- for (;*p != NULL;) {
+ for (;*p != 0;) {
for (i = sizeof(struct dns_header); i < (offset - labellen); i++) {
@@ -867,7 +920,7 @@ compress_label(char *buf, int offset, int labellen)
*/
for (j = 0; j < checklen; j++) {
- if (expandbuf[j] == NULL)
+ if (expandbuf[j] == 0)
break; /* end of lookup */
checkcompress = (u_int16_t *)&expandbuf[j];
if ((ntohs(*checkcompress) & 0xc000) == 0xc000){
@@ -882,7 +935,7 @@ compress_label(char *buf, int offset, int labellen)
memcpy((char*)&expandbuf[j], (char*)&buf[expandoffset], expandlen); /* XXX expensive */
/* check once more that our search does not terminate */
- if (expandbuf[j] == NULL) {
+ if (expandbuf[j] == 0) {
e = &expandbuf[j];
break;
}
@@ -894,7 +947,7 @@ compress_label(char *buf, int offset, int labellen)
}
/* check packet for a matching name */
- if (*e == NULL && memcasecmp(&expandbuf[0], p, checklen) == 0) {
+ if (*e == 0 && memcasecmp(&expandbuf[0], p, checklen) == 0) {
compressmark = &buf[i];
goto out; /* found one */
}
@@ -944,8 +997,13 @@ memcasecmp(char *b1, char *b2, int len)
int identical = 1;
for (i = 0; i < len; i++) {
- if ((isalpha(b1[i]) ? tolower(b1[i]) : b1[i]) !=
- (isalpha(b2[i]) ? tolower(b2[i]) : b2[i])) {
+ int c0, c1;
+
+ c0 = b1[i];
+ c1 = b2[i];
+
+ if ((isalpha(c0) ? tolower(c0) : c0) !=
+ (isalpha(c1) ? tolower(c1) : c1)) {
identical = 0;
break;
}
@@ -968,11 +1026,12 @@ int
lookup_zone(DB *db, struct question *question, struct domain *sd, int *lzerrno, char *replystring)
{
- char *p;
int plen, onemore = 0;
int ret = 0;
int returnval;
+
char *wildlookup = "*";
+ char *p;
DBT key, data;
@@ -990,19 +1049,27 @@ lookup_zone(DB *db, struct question *question, struct
do {
+ memset(&key, 0, sizeof(key));
+ memset(&data, 0, sizeof(data));
+
key.data = (char *)p;
key.size = plen;
data.data = NULL;
data.size = 0;
+
+#if DB_VERSION_MAJOR > 3
+ ret = db->get(db, NULL, &key, &data, 0);
+#else
ret = db->get(db, &key, &data, 0);
+#endif
if (ret != 0) {
/* next label */
- if (*p != NULL) {
+ if (*p != 0) {
plen -= (*p + 1);
p = (p + (*p + 1));
- } else if (*p == NULL && ! onemore) {
+ } else if (*p == 0 && ! onemore) {
plen = 1;
onemore = 1;
continue;
@@ -1100,13 +1167,21 @@ lookup_zone(DB *db, struct question *question, struct
}
- } while (*p != NULL && ret != 0);
+ } while (*p != 0 && ret != 0);
if (ret != 0) {
+ memset(&key, 0, sizeof(key));
+ memset(&data, 0, sizeof(data));
+
key.data = wildlookup;
key.size = 1;
- if (db->get(db, &key, &data, 0) != 0) {
+#if DB_VERSION_MAJOR > 3
+ if ((ret = db->get(db, NULL, &key, &data, 0)) != 0) {
+ db->err(db, ret, "db->get");
+#else
+ if (db->get(db, &key, &data, 0) != 0) {
+#endif
syslog(LOG_INFO, "don't have wildcard answer");
*lzerrno = ERR_NXDOMAIN;
return -1;
blob - a0dcd35a4ac3a96293289b23dd2af3eee8e6944f
blob + 111c22e797138c9fbbfb676011953c29e57e0ad2
--- parse.c
+++ parse.c
@@ -54,25 +54,27 @@ struct myrr_lookup {
int
parse_file(DB *db, char *file)
{
- FILE *f;
-
int len, i;
int tokenlen;
u_int16_t type;
u_int32_t ttl;
+ int converted_namelen;
+ int line = 0;
+#if DB_VERSION_MAJOR > 3
+ int ret;
+#endif
+
char buf[1024];
char domainname[DNS_MAXNAME + 1];
char *converted_name;
- int converted_namelen;
char *p, *endline, *start, *starttoken;
char save;
- int line = 0;
DBT key, data;
+ FILE *f;
- struct domain sdomain;
-
in_addr_t *ia;
+ struct domain sdomain;
struct in6_addr *ia6;
if ((f = fopen(file, "r")) == NULL) {
@@ -133,7 +135,9 @@ parse_file(DB *db, char *file)
c = starttoken;
for (i = 0; i < tokenlen; i++) {
- domainname[i] = tolower(*c++);
+ int c0;
+ c0 = *c++;
+ domainname[i] = tolower(c0);
}
if (domainname[tokenlen - 1] != '.' &&
@@ -162,6 +166,8 @@ parse_file(DB *db, char *file)
}
}
+ memset(&key, 0, sizeof(key));
+ memset(&data, 0, sizeof(data));
key.data = (char *)converted_name;
key.size = converted_namelen;
@@ -170,7 +176,11 @@ parse_file(DB *db, char *file)
data.size = 0;
memset((char *)&sdomain, 0, sizeof(struct domain));
- if (db->get(db, &key, &data, 0) == 0) {
+#if DB_VERSION_MAJOR > 3
+ if (db->get(db, NULL, &key, &data, 0) == 0) {
+#else
+ if (db->get(db, &key, &data, 0) == 0) {
+#endif
if (data.size != sizeof(struct domain)) {
fprintf(stderr, "damaged btree database\n");
fclose(f);
@@ -184,7 +194,13 @@ parse_file(DB *db, char *file)
#endif
}
+#if __linux__
+ strncpy((char *)&sdomain.zonename[0], (char *)&domainname[0],
+ sizeof(sdomain.zonename));
+ sdomain.zonename[sizeof(sdomain.zonename) - 1] = 0;
+#else
strlcpy((char *)&sdomain.zonename[0], (char *)&domainname[0], sizeof(sdomain.zonename));
+#endif
if (++p >= endline) {
fprintf(stderr, "(2) malformed line %d", line);
@@ -203,7 +219,7 @@ parse_file(DB *db, char *file)
tokenlen = (p - starttoken);
save = *p;
- *p = NULL;
+ *p = 0;
type = 0;
for (i = 0; mysrr_lookup[i].name != NULL; i++) {
@@ -238,7 +254,7 @@ parse_file(DB *db, char *file)
tokenlen = (p - starttoken);
save = *p;
- *p = NULL;
+ *p = 0;
ttl = atoi(starttoken);
@@ -279,7 +295,7 @@ parse_file(DB *db, char *file)
case DNS_TYPE_AAAA:
p = endline;
save = *p;
- *p = NULL;
+ *p = 0;
if (sdomain.aaaa_count < 10) {
ia6 = (struct in6_addr *) &sdomain.aaaa[sdomain.aaaa_count];
sdomain.aaaa_count++;
@@ -312,7 +328,7 @@ parse_file(DB *db, char *file)
tokenlen = (p - starttoken);
save = *p;
- *p = NULL;
+ *p = 0;
if (sdomain.mx_count < 10) {
sdomain.mx[sdomain.mx_count].preference = atoi(starttoken);
@@ -332,7 +348,7 @@ parse_file(DB *db, char *file)
p = endline;
save = *p;
- *p = NULL;
+ *p = 0;
{
@@ -364,7 +380,7 @@ parse_file(DB *db, char *file)
tokenlen = (p - starttoken);
save = *p;
- *p = NULL;
+ *p = 0;
{
char *name;
@@ -397,7 +413,7 @@ parse_file(DB *db, char *file)
tokenlen = (p - starttoken);
save = *p;
- *p = NULL;
+ *p = 0;
{
char *name;
@@ -430,7 +446,7 @@ parse_file(DB *db, char *file)
tokenlen = (p - starttoken);
save = *p;
- *p = NULL;
+ *p = 0;
sdomain.soa.serial = atoi(starttoken);
@@ -453,7 +469,7 @@ parse_file(DB *db, char *file)
tokenlen = (p - starttoken);
save = *p;
- *p = NULL;
+ *p = 0;
sdomain.soa.refresh = atoi(starttoken);
@@ -476,7 +492,7 @@ parse_file(DB *db, char *file)
tokenlen = (p - starttoken);
save = *p;
- *p = NULL;
+ *p = 0;
sdomain.soa.retry = atoi(starttoken);
@@ -499,7 +515,7 @@ parse_file(DB *db, char *file)
tokenlen = (p - starttoken);
save = *p;
- *p = NULL;
+ *p = 0;
sdomain.soa.expire = atoi(starttoken);
@@ -516,7 +532,7 @@ parse_file(DB *db, char *file)
tokenlen = (p - starttoken);
save = *p;
- *p = NULL;
+ *p = 0;
sdomain.soa.minttl = atoi(starttoken);
*p = save;
@@ -527,7 +543,7 @@ parse_file(DB *db, char *file)
case DNS_TYPE_PTR:
p = endline;
save = *p;
- *p = NULL;
+ *p = 0;
{
char *name;
@@ -549,7 +565,7 @@ parse_file(DB *db, char *file)
case DNS_TYPE_NS:
p = endline;
save = *p;
- *p = NULL;
+ *p = 0;
{
char *name;
@@ -576,7 +592,7 @@ parse_file(DB *db, char *file)
p = endline;
save = *p;
- *p = NULL;
+ *p = 0;
{
char *name;
@@ -601,14 +617,24 @@ parse_file(DB *db, char *file)
/* write new record into btree database */
+ memset(&key, 0, sizeof(key));
+ memset(&data, 0, sizeof(data));
+
key.data = (char *)converted_name;
key.size = converted_namelen;
data.data = (void *)&sdomain;
data.size = sizeof(struct domain);
- if (db->put(db, &key, &data, 0) < 0) {
+#if DB_VERSION_MAJOR > 3
+ /* XXX */
+ if ((ret = db->put(db, NULL, &key, &data, 0)) != 0) {
+ fprintf(stderr, "db->put: %s, key=%s data=%s\n"
+ , db_strerror(ret), key.data, data.data);
+#else
+ if (db->put(db, &key, &data, 0) < 0) {
perror("db->put");
+#endif
fclose(f);
return -1;
}
@@ -616,7 +642,7 @@ parse_file(DB *db, char *file)
skip:
#ifdef DEBUG
save = *endline;
- *endline = NULL;
+ *endline = 0;
printf("line %d: \"%s\"\n", line, start);
@@ -642,8 +668,23 @@ skip:
DB *
opendatabase(DB *ret)
{
- ret = dbopen(NULL, O_RDWR, 0, DB_BTREE, NULL);
-
+#if DB_VERSION_MAJOR > 3
+
+ if (db_create((DB **)&ret, (DB_ENV *)NULL, 0) != 0) {
+ perror("db_create");
+ exit(1);
+ }
+
+ if (ret->open(ret, NULL, NULL, NULL, DB_BTREE, DB_CREATE, 0) != 0) {
+ perror("db->open");
+ ret->close(ret, DB_NOSYNC);
+ exit(1);
+ }
+
+#else
+ ret = dbopen(NULL, O_RDWR, 0, DB_BTREE, NULL);
+#endif
+
return (ret);
}
repomaster@centroid.eu