Blame
Date:
Mon Jan 11 09:00:47 2021 UTC
Message:
a usleep makes it unnecessary slow, I guess it forces a context switch...
001
2017-01-09
pjp
/*
002
2019-02-15
pjp
* Copyright (c) 2017-2019 Peter J. Philipp
003
2017-01-09
pjp
* All rights reserved.
004
2017-01-09
pjp
*
005
2017-01-09
pjp
* Redistribution and use in source and binary forms, with or without
006
2017-01-09
pjp
* modification, are permitted provided that the following conditions
007
2017-01-09
pjp
* are met:
008
2017-01-09
pjp
* 1. Redistributions of source code must retain the above copyright
009
2017-01-09
pjp
* notice, this list of conditions and the following disclaimer.
010
2017-01-09
pjp
* 2. Redistributions in binary form must reproduce the above copyright
011
2017-01-09
pjp
* notice, this list of conditions and the following disclaimer in the
012
2017-01-09
pjp
* documentation and/or other materials provided with the distribution.
013
2017-01-09
pjp
* 3. The name of the author may not be used to endorse or promote products
014
2017-01-09
pjp
* derived from this software without specific prior written permission
015
2017-01-09
pjp
*
016
2017-01-09
pjp
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
017
2017-01-09
pjp
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
018
2017-01-09
pjp
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
019
2017-01-09
pjp
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
020
2017-01-09
pjp
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
021
2017-01-09
pjp
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
022
2017-01-09
pjp
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
023
2017-01-09
pjp
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
024
2017-01-09
pjp
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
025
2017-01-09
pjp
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
026
2017-01-09
pjp
*
027
2017-01-09
pjp
*/
028
2017-01-09
pjp
029
2017-01-09
pjp
/*
030
2020-07-16
pjp
* this file is based on passlist.c
031
2017-01-09
pjp
*/
032
2017-01-09
pjp
033
2019-06-06
pjp
#include <sys/types.h>
034
2019-06-06
pjp
#include <sys/socket.h>
035
2019-06-06
pjp
036
2019-06-06
pjp
#include <netinet/in.h>
037
2019-06-06
pjp
#include <arpa/inet.h>
038
2019-06-06
pjp
#include <netdb.h>
039
2019-06-06
pjp
040
2019-06-06
pjp
#include <stdio.h>
041
2019-06-06
pjp
#include <stdlib.h>
042
2019-06-06
pjp
#include <string.h>
043
2019-06-06
pjp
#include <errno.h>
044
2019-06-06
pjp
#include <syslog.h>
045
2019-06-06
pjp
046
2019-06-06
pjp
#ifdef __linux__
047
2019-06-06
pjp
#include <grp.h>
048
2019-06-06
pjp
#define __USE_BSD 1
049
2019-06-06
pjp
#include <endian.h>
050
2019-06-06
pjp
#include <bsd/stdlib.h>
051
2019-06-06
pjp
#include <bsd/string.h>
052
2019-06-06
pjp
#include <bsd/sys/queue.h>
053
2019-06-06
pjp
#define __unused
054
2019-06-06
pjp
#include <bsd/sys/tree.h>
055
2019-06-06
pjp
#include <bsd/sys/endian.h>
056
2019-06-06
pjp
#else /* not linux */
057
2019-06-06
pjp
#include <sys/queue.h>
058
2019-06-06
pjp
#include <sys/tree.h>
059
2019-06-06
pjp
#endif /* __linux__ */
060
2019-06-06
pjp
061
2019-06-06
pjp
062
2017-01-09
pjp
#include "ddd-dns.h"
063
2017-01-09
pjp
#include "ddd-db.h"
064
2017-01-09
pjp
065
2017-06-26
pjp
int init_entlist(ddDB *);
066
2017-01-09
pjp
int check_ent(char *, int);
067
2017-01-09
pjp
static int ent_contains(char *, int, char *, int);
068
2017-01-09
pjp
069
2017-01-09
pjp
extern void dolog(int, char *, ...);
070
2017-01-09
pjp
extern int memcasecmp(u_char *, u_char *, int);
071
2017-01-09
pjp
072
2017-01-09
pjp
extern int debug, verbose;
073
2017-01-09
pjp
074
2017-01-09
pjp
SLIST_HEAD(listhead, ententry) enthead;
075
2017-01-09
pjp
076
2017-06-26
pjp
077
2017-01-09
pjp
static struct ententry {
078
2017-01-09
pjp
char *name;
079
2017-01-09
pjp
int len;
080
2017-01-09
pjp
SLIST_ENTRY(ententry) ent_entry;
081
2017-01-09
pjp
} *ent2, *entp;
082
2017-01-09
pjp
083
2017-06-26
pjp
extern int domaincmp(struct node *e1, struct node *e2);
084
2017-01-09
pjp
085
2017-01-09
pjp
086
2017-01-09
pjp
/*
087
2017-01-09
pjp
* INIT_ENTLIST - initialize the ent singly linked list
088
2017-01-09
pjp
*/
089
2017-01-09
pjp
090
2017-01-09
pjp
int
091
2017-06-26
pjp
init_entlist(ddDB *db)
092
2017-01-09
pjp
{
093
2017-06-26
pjp
struct node *n, *nx;
094
2019-02-15
pjp
struct rbtree *rbt = NULL;
095
2017-01-09
pjp
096
2017-01-09
pjp
SLIST_INIT(&enthead);
097
2017-01-09
pjp
098
2019-02-19
pjp
RB_FOREACH_SAFE(n, domaintree, &db->head, nx) {
099
2019-02-15
pjp
rbt = (struct rbtree *)n->data;
100
2017-01-09
pjp
ent2 = malloc(sizeof(struct ententry));
101
2017-01-09
pjp
if (ent2 == NULL) {
102
2017-01-09
pjp
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
103
2017-01-09
pjp
return -1;
104
2017-01-09
pjp
}
105
2017-01-09
pjp
106
2019-02-15
pjp
ent2->name = malloc(rbt->zonelen);
107
2017-01-09
pjp
if (ent2->name == NULL) {
108
2017-01-09
pjp
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
109
2017-01-09
pjp
return -1;
110
2017-01-09
pjp
}
111
2017-01-09
pjp
112
2017-01-09
pjp
113
2019-02-15
pjp
memcpy(ent2->name, rbt->zone, rbt->zonelen);
114
2019-02-15
pjp
ent2->len = rbt->zonelen;
115
2017-01-09
pjp
116
2017-01-09
pjp
SLIST_INSERT_HEAD(&enthead, ent2, ent_entry);
117
2017-06-26
pjp
}
118
2017-01-09
pjp
119
2017-01-09
pjp
120
2017-01-09
pjp
return 0;
121
2017-01-09
pjp
}
122
2017-01-09
pjp
123
2017-01-09
pjp
/*
124
2017-01-09
pjp
* Check if the provided name is an empty non-terminating (ENT) name, if so
125
2017-01-09
pjp
* return 1, else return 0
126
2017-01-09
pjp
*/
127
2017-01-09
pjp
128
2017-01-09
pjp
int
129
2017-01-09
pjp
check_ent(char *name, int len)
130
2017-01-09
pjp
{
131
2017-01-09
pjp
/* walk the dns forest searching for a matching ENT */
132
2017-01-09
pjp
SLIST_FOREACH(entp, &enthead, ent_entry) {
133
2017-01-09
pjp
/* skip ent candidates that are too short */
134
2017-01-09
pjp
if (entp->len <= len)
135
2017-01-09
pjp
continue;
136
2017-01-09
pjp
if (ent_contains(name, len, entp->name, entp->len)) {
137
2017-01-09
pjp
return (1);
138
2017-01-09
pjp
}
139
2017-01-09
pjp
}
140
2017-01-09
pjp
141
2017-01-09
pjp
return (0);
142
2017-01-09
pjp
}
143
2017-01-09
pjp
144
2017-01-09
pjp
145
2017-01-09
pjp
static int
146
2017-01-09
pjp
ent_contains(char *name, int len, char *entname, int entlen)
147
2017-01-09
pjp
{
148
2017-01-09
pjp
char *p;
149
2017-01-09
pjp
int l;
150
2017-01-09
pjp
151
2017-01-09
pjp
p = entname;
152
2017-01-09
pjp
l = entlen;
153
2017-01-09
pjp
while (*p) {
154
2017-01-09
pjp
l -= (*p + 1);
155
2017-01-09
pjp
p += (*p + 1);
156
2017-01-09
pjp
157
2017-01-09
pjp
if (l != len)
158
2017-01-09
pjp
continue;
159
2017-01-09
pjp
160
2017-01-09
pjp
if (memcasecmp(name, p, l) == 0)
161
2018-05-11
pjp
goto exists; /* ? */
162
2017-01-09
pjp
}
163
2017-01-09
pjp
164
2017-01-09
pjp
return 0;
165
2018-05-11
pjp
166
2018-05-11
pjp
exists:
167
2018-05-11
pjp
/*
168
2018-05-11
pjp
* we take a second look, to make sure that we don't hit the
169
2018-05-11
pjp
* base of an ENT...this was overlooked originally
170
2018-05-11
pjp
*/
171
2018-05-11
pjp
172
2018-05-11
pjp
SLIST_FOREACH(ent2, &enthead, ent_entry) {
173
2018-05-11
pjp
if (ent2->len != l)
174
2018-05-11
pjp
continue;
175
2018-05-11
pjp
176
2018-05-11
pjp
if (memcasecmp(ent2->name, p, l) == 0)
177
2018-05-11
pjp
return 0;
178
2018-05-11
pjp
}
179
2018-05-11
pjp
180
2018-05-11
pjp
return 1;
181
2017-01-09
pjp
}
repomaster@centroid.eu