| ---
tdnarea.c (1938B)
---
1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include "dns.h"
8
9 Area *owned;
10 Area *delegated;
11
12 /*
13 * true if a name is in our area
14 */
15 Area*
16 inmyarea(char *name)
17 {
18 int len;
19 Area *s, *d;
20
21 len = strlen(name);
22 for(s = owned; s; s = s->next){
23 if(s->len > len)
24 continue;
25 if(cistrcmp(s->soarr->owner->name, name + len - s->len) == 0)
26 if(len == s->len || name[len - s->len - 1] == '.')
27 break;
28 }
29 if(s == 0)
30 return 0;
31
32 for(d = delegated; d; d = d->next){
33 if(d->len > len)
34 continue;
35 if(cistrcmp(d->soarr->owner->name, name + len - d->len) == 0)
36 if(len == d->len || name[len - d->len - 1] == '.')
37 return 0;
38 }
39
40 return s;
41 }
42
43 /*
44 * our area is the part of the domain tree that
45 * we serve
46 */
47 void
48 addarea(DN *dp, RR *rp, Ndbtuple *t)
49 {
50 Area **l, *s;
51
52 if(t->val[0])
53 l = &delegated;
54 else
55 l = &owned;
56
57 /*
58 * The area contains a copy of the soa rr that created it.
59 * The owner of the the soa rr should stick around as long
60 * as the area does.
61 */
62 s = emalloc(sizeof(*s));
63 s->len = strlen(dp->name);
64 rrcopy(rp, &s->soarr);
65 s->soarr->owner = dp;
66 s->soarr->db = 1;
67 s->soarr->ttl = Hour;
68 s->neednotify = 1;
69 s->needrefresh = 0;
70
71 syslog(0, logfile, "new area %s", dp->name);
72
73 s->next = *l;
74 *l = s;
75 }
76
77 void
78 freearea(Area **l)
79 {
80 Area *s;
81
82 while(s = *l){
83 *l = s->next;
84 rrfree(s->soarr);
85 free(s);
86 }
87 }
88
89 /*
90 * refresh all areas that need it
91 * this entails running a command 'zonerefreshprogram'. This could
92 * copy over databases from elsewhere or just do a zone transfer.
93 */
94 void
95 refresh_areas(Area *s)
96 {
97 Waitmsg *w;
98 char *argv[3];
99
100 argv[0] = zonerefreshprogram;
101 argv[1] = "XXX";
102 argv[2] = nil;
103
104 for(; s != nil; s = s->next){
105 if(!s->needrefresh)
106 continue;
107
108 if(zonerefreshprogram == nil){
109 s->needrefresh = 0;
110 continue;
111 }
112
113 argv[1] = s->soarr->owner->name;
114 w = runproc(argv[0], argv, 0);
115 free(w);
116 }
117 } |