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
2021-01-07
pjp
/*
002
2021-01-07
pjp
* Copyright (c) 2021 Peter J. Philipp
003
2021-01-07
pjp
* All rights reserved.
004
2021-01-07
pjp
*
005
2021-01-07
pjp
* Redistribution and use in source and binary forms, with or without
006
2021-01-07
pjp
* modification, are permitted provided that the following conditions
007
2021-01-07
pjp
* are met:
008
2021-01-07
pjp
* 1. Redistributions of source code must retain the above copyright
009
2021-01-07
pjp
* notice, this list of conditions and the following disclaimer.
010
2021-01-07
pjp
* 2. Redistributions in binary form must reproduce the above copyright
011
2021-01-07
pjp
* notice, this list of conditions and the following disclaimer in the
012
2021-01-07
pjp
* documentation and/or other materials provided with the distribution.
013
2021-01-07
pjp
* 3. The name of the author may not be used to endorse or promote products
014
2021-01-07
pjp
* derived from this software without specific prior written permission
015
2021-01-07
pjp
*
016
2021-01-07
pjp
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
017
2021-01-07
pjp
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
018
2021-01-07
pjp
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
019
2021-01-07
pjp
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
020
2021-01-07
pjp
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
021
2021-01-07
pjp
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
022
2021-01-07
pjp
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
023
2021-01-07
pjp
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
024
2021-01-07
pjp
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
025
2021-01-07
pjp
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
026
2021-01-07
pjp
*
027
2021-01-07
pjp
*/
028
2021-01-07
pjp
029
2021-01-07
pjp
#include <sys/types.h>
030
2021-01-07
pjp
#include <sys/socket.h>
031
2021-01-07
pjp
032
2021-01-07
pjp
#include <netinet/in.h>
033
2021-01-07
pjp
#include <arpa/inet.h>
034
2021-01-07
pjp
#include <netdb.h>
035
2021-01-07
pjp
036
2021-01-07
pjp
#include <stdio.h>
037
2021-01-07
pjp
#include <stdlib.h>
038
2021-01-07
pjp
#include <string.h>
039
2021-01-07
pjp
#include <errno.h>
040
2021-01-07
pjp
#include <syslog.h>
041
2021-01-07
pjp
#include <unistd.h>
042
2021-01-07
pjp
043
2021-01-07
pjp
#ifdef __linux__
044
2021-01-07
pjp
#include <grp.h>
045
2021-01-07
pjp
#define __USE_BSD 1
046
2021-01-07
pjp
#include <endian.h>
047
2021-01-07
pjp
#include <bsd/stdlib.h>
048
2021-01-07
pjp
#include <bsd/string.h>
049
2021-01-07
pjp
#include <bsd/sys/queue.h>
050
2021-01-07
pjp
#define __unused
051
2021-01-07
pjp
#include <bsd/sys/tree.h>
052
2021-01-07
pjp
#include <bsd/sys/endian.h>
053
2021-01-07
pjp
#else /* not linux */
054
2021-01-07
pjp
#include <sys/queue.h>
055
2021-01-07
pjp
#include <sys/tree.h>
056
2021-01-07
pjp
#endif /* __linux__ */
057
2021-01-07
pjp
058
2021-01-07
pjp
059
2021-01-07
pjp
060
2021-01-07
pjp
#include "ddd-dns.h"
061
2021-01-07
pjp
#include "ddd-db.h"
062
2021-01-07
pjp
063
2021-01-07
pjp
int insert_tsigpassname(char *);
064
2021-01-07
pjp
struct pnentry * have_tsigpassname(char *name, int namelen);
065
2021-01-07
pjp
int tsigpassname_contains(char *origname, int origlen, int *wildcard);
066
2021-01-07
pjp
int pncmp(struct pnentry *, struct pnentry *);
067
2021-01-07
pjp
068
2021-01-07
pjp
extern void dolog(int, char *, ...);
069
2021-01-07
pjp
extern char * dns_label(char *, int *);
070
2021-01-07
pjp
extern void ddd_shutdown(void);
071
2021-01-07
pjp
072
2021-01-07
pjp
extern int debug, verbose;
073
2021-01-07
pjp
074
2021-01-07
pjp
struct pntree pnhead = RB_INITIALIZER(&pnhead);
075
2021-01-07
pjp
RB_GENERATE(pntree, pnentry, pn_entry, pncmp);
076
2021-01-07
pjp
077
2021-01-07
pjp
int
078
2021-01-07
pjp
insert_tsigpassname(char *name)
079
2021-01-07
pjp
{
080
2021-01-07
pjp
struct pnentry *pnep;
081
2021-01-07
pjp
int len;
082
2021-01-07
pjp
char *tmp;
083
2021-01-07
pjp
char *p = name;
084
2021-01-07
pjp
085
2021-01-07
pjp
if (name[0] == '*' && name[1] == '.')
086
2021-01-07
pjp
p = &name[2];
087
2021-01-07
pjp
088
2021-01-07
pjp
if (strlen(p) > DNS_MAXNAME) {
089
2021-01-07
pjp
dolog(LOG_INFO, "domainname too long\n");
090
2021-01-07
pjp
return -1;
091
2021-01-07
pjp
}
092
2021-01-07
pjp
093
2021-01-07
pjp
pnep = malloc(sizeof(struct pnentry));
094
2021-01-07
pjp
if (pnep == NULL) {
095
2021-01-07
pjp
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
096
2021-01-07
pjp
return -1;
097
2021-01-07
pjp
}
098
2021-01-07
pjp
099
2021-01-07
pjp
tmp = dns_label(p, &len);
100
2021-01-07
pjp
pnep->namelen = len;
101
2021-01-07
pjp
memcpy(pnep->name, tmp, len);
102
2021-01-07
pjp
free(tmp);
103
2021-01-07
pjp
104
2021-01-07
pjp
pnep->humanname = strdup(name);
105
2021-01-07
pjp
if (pnep->humanname == NULL) {
106
2021-01-07
pjp
dolog(LOG_INFO, "strdup failed\n");
107
2021-01-07
pjp
return -1;
108
2021-01-07
pjp
}
109
2021-01-07
pjp
110
2021-01-07
pjp
RB_INSERT(pntree, &pnhead, pnep);
111
2021-01-07
pjp
return (0);
112
2021-01-07
pjp
}
113
2021-01-07
pjp
114
2021-01-07
pjp
struct pnentry *
115
2021-01-07
pjp
have_tsigpassname(char *name, int len)
116
2021-01-07
pjp
{
117
2021-01-07
pjp
struct pnentry find, *res;
118
2021-01-07
pjp
119
2021-01-07
pjp
memcpy(find.name, name, len);
120
2021-01-07
pjp
find.namelen = len;
121
2021-01-07
pjp
if ((res = RB_FIND(pntree, &pnhead, &find)) != NULL) {
122
2021-01-07
pjp
return (res);
123
2021-01-07
pjp
}
124
2021-01-07
pjp
125
2021-01-07
pjp
return NULL;
126
2021-01-07
pjp
}
127
2021-01-07
pjp
128
2021-01-07
pjp
int
129
2021-01-07
pjp
tsigpassname_contains(char *origname, int origlen, int *wildcard)
130
2021-01-07
pjp
{
131
2021-01-07
pjp
char *p = origname;
132
2021-01-07
pjp
int plen = origlen;
133
2021-01-07
pjp
struct pnentry *res;
134
2021-01-07
pjp
135
2021-01-07
pjp
for (; *p; plen--, p++) {
136
2021-01-07
pjp
if ((res = have_tsigpassname(p, plen)) != NULL)
137
2021-01-07
pjp
break;
138
2021-01-07
pjp
plen -= *p;
139
2021-01-07
pjp
p += *p;
140
2021-01-07
pjp
}
141
2021-01-07
pjp
142
2021-01-07
pjp
if (res == NULL)
143
2021-01-07
pjp
return 0;
144
2021-01-07
pjp
145
2021-01-07
pjp
if (res->wildcard == 1)
146
2021-01-07
pjp
*wildcard = 1;
147
2021-01-07
pjp
else
148
2021-01-07
pjp
*wildcard = 0;
149
2021-01-07
pjp
150
2021-01-07
pjp
return 1;
151
2021-01-07
pjp
}
152
2021-01-07
pjp
153
2021-01-07
pjp
int
154
2021-01-07
pjp
pncmp(struct pnentry *e1, struct pnentry *e2)
155
2021-01-07
pjp
{
156
2021-01-07
pjp
if (e1->namelen == e2->namelen)
157
2021-01-07
pjp
return (memcmp(e1->name, e2->name, e1->namelen));
158
2021-01-07
pjp
else if (e1->namelen < e2->namelen)
159
2021-01-07
pjp
return -1;
160
2021-01-07
pjp
else
161
2021-01-07
pjp
return 1;
162
2021-01-07
pjp
}
repomaster@centroid.eu