Commit Diff
Diff:
5528a18e8f06ca7c0c89b23b2e2d57778e70f263
dbaa9c14090fe4bb617b8f490a0de5310ce71e8b
Commit:
dbaa9c14090fe4bb617b8f490a0de5310ce71e8b
Tree:
a1fe51c673076257283a689f4cca124d591f1775
Author:
pbug <pbug@delphinusdns.org>
Committer:
pbug <pbug@delphinusdns.org>
Date:
Thu Sep 23 18:40:43 2010 UTC
Message:
* parse SOA records * on NOERROR do something (but it's wrong and will be changed) compiles on OpenBSD
blob - 16e9ae6df35a19d37b7dcee316927be9ac4cf3bb
blob + 9954f7c641c45631058d66b9ab28189152b250dd
--- recurse.c
+++ recurse.c
@@ -50,6 +50,7 @@ void reply_raw(DB *db, struct recurses *sr, struct dom
extern void build_reply(struct sreply *reply, int so, char *buf, int len, struct question *q, struct sockaddr *sa, socklen_t slen, struct domain *sd1, struct domain *sd2, u_int8_t region, int istcp, int wildcard, struct recurses *sr);
extern void reply_a(struct sreply *, DB *);
extern int memcasecmp(u_char *, u_char *, int);
+extern int get_soa(DB *, struct question *, struct domain *, int);
void remove_zone(DB *db, struct domain *sd);
SLIST_HEAD(listhead, recurseentry) recursehead;
@@ -64,7 +65,7 @@ struct recurseentry {
} *rn1, *rn2, *rnp;
-static const char rcsid[] = "$Id: recurse.c,v 1.13 2010/09/21 19:04:43 pbug Exp $";
+static const char rcsid[] = "$Id: recurse.c,v 1.14 2010/09/23 18:40:43 pbug Exp $";
/*
* INIT_RECURSE - initialize the recurse singly linked list
@@ -230,7 +231,16 @@ recurseloop(int sp, int *raw, DB *db)
sr1->launched = 1;
type = lookup_zone(db, sr1->question, &sd, &lzerrno, (char *)fakereplystring, wildcard);
if (type < 0) {
- netlookup(db, sr1);
+ switch (lzerrno) {
+ case ERR_NXDOMAIN:
+ netlookup(db, sr1);
+ break;
+ case ERR_NOERROR:
+ sr1->callback->hascallback--;
+ free_question(sr1->question);
+ free(sr1);
+ break;
+ }
} else {
sr1->callback->hascallback--;
free_question(sr1->question);
@@ -300,9 +310,22 @@ recurseloop(int sp, int *raw, DB *db)
type = lookup_zone(db, sr->question, &sd, &lzerrno, (char *)fakereplystring, wildcard);
if (type < 0) {
- if (netlookup(db, sr) < 0)
+ switch (lzerrno) {
+ case ERR_NXDOMAIN:
+ if (netlookup(db, sr) < 0)
continue;
+ case ERR_NOERROR:
+ memset(&sd, 0, sizeof(sd));
+
+ if (get_soa(db, sr->question, &sd, wildcard) < 0)
+ continue;
+ reply_raw(db, sr, &sd, raw);
+ free_question(sr->question);
+ free(sr);
+ continue;
+ }
+
SLIST_INSERT_HEAD(&recurseshead, sr, entries);
} else {
syslog(LOG_DEBUG, "we had the record in our cache, reply action");
@@ -739,7 +762,7 @@ recurse_parse(DB *db, struct recurses *sr, u_char *buf
u_int32_t ttl;
u_int16_t rdlength;
} __attribute__((packed));
- struct soa {
+ struct mysoa {
u_int32_t serial;
u_int32_t refresh;
u_int32_t retry;
@@ -748,6 +771,8 @@ recurse_parse(DB *db, struct recurses *sr, u_char *buf
} __attribute__((packed));
struct answer *a;
+ struct mysoa *mysoa;
+ struct soa *soa;
u_int i, j, k;
u_int16_t *compressor;
@@ -864,7 +889,7 @@ recurse_parse(DB *db, struct recurses *sr, u_char *buf
if (p > end)
goto end;
- p += sizeof(struct soa); /* advance struct soa */
+ p += sizeof(struct mysoa); /* advance struct soa */
break;
default:
@@ -1188,8 +1213,36 @@ again:
if (p > end)
goto end;
- p += sizeof(struct soa); /* advance struct soa */
+ mysoa = (struct mysoa *)p;
+ p += sizeof(struct mysoa); /* advance struct soa */
+ /* malloc struct soa */
+
+ soa = malloc(sizeof(struct soa));
+ if (soa == NULL) {
+ syslog(LOG_ERR, "malloc: %m");
+ return (-1);
+ }
+
+ memcpy(soa->nsserver, converted_name[i - 1], cn_len[i - 1]);
+ soa->nsserver_len = cn_len[i - 1];
+ memcpy(soa->responsible_person, converted_name[i], cn_len[i]);
+ soa->rp_len = cn_len[i];
+ soa->serial = mysoa->serial;
+ soa->refresh = mysoa->refresh;
+ soa->retry = mysoa->retry;
+ soa->expire = mysoa->expire;
+ soa->minttl = mysoa->minttl;
+
+ sdomain.soa = soa;
+ sdomain.flags |= DOMAIN_HAVE_SOA;
+ sdomain.created = time(NULL);
+ sdomain.ttl = a->ttl;
+
+ if (! (sdomain.flags & DOMAIN_STATIC_ZONE)) {
+ update_db(db, &sdomain);
+ }
+
break;
default:
break;
@@ -1377,6 +1430,12 @@ fakerecurse(DB *db, struct recurses *sr, struct ns *ns
return (0);
}
+
+/*
+ * REPLY_RAW -
+ *
+ *
+ */
void
reply_raw(DB *db, struct recurses *sr, struct domain *sd, int *raw)
repomaster@centroid.eu