Blame
Date:
Thu Nov 19 09:25:28 2020 UTC
Message:
update README before 1.5.0 release
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-10-26
pjp
/*
030
2020-07-16
pjp
* $Id: ent.c,v 1.11 2020/07/16 17:54:03 pjp Exp $
031
2017-10-26
pjp
*/
032
2017-10-26
pjp
033
2017-01-09
pjp
/*
034
2020-07-16
pjp
* this file is based on passlist.c
035
2017-01-09
pjp
*/
036
2017-01-09
pjp
037
2019-06-06
pjp
#include <sys/types.h>
038
2019-06-06
pjp
#include <sys/socket.h>
039
2019-06-06
pjp
040
2019-06-06
pjp
#include <netinet/in.h>
041
2019-06-06
pjp
#include <arpa/inet.h>
042
2019-06-06
pjp
#include <netdb.h>
043
2019-06-06
pjp
044
2019-06-06
pjp
#include <stdio.h>
045
2019-06-06
pjp
#include <stdlib.h>
046
2019-06-06
pjp
#include <string.h>
047
2019-06-06
pjp
#include <errno.h>
048
2019-06-06
pjp
#include <syslog.h>
049
2019-06-06
pjp
050
2019-06-06
pjp
#ifdef __linux__
051
2019-06-06
pjp
#include <grp.h>
052
2019-06-06
pjp
#define __USE_BSD 1
053
2019-06-06
pjp
#include <endian.h>
054
2019-06-06
pjp
#include <bsd/stdlib.h>
055
2019-06-06
pjp
#include <bsd/string.h>
056
2019-06-06
pjp
#include <bsd/sys/queue.h>
057
2019-06-06
pjp
#define __unused
058
2019-06-06
pjp
#include <bsd/sys/tree.h>
059
2019-06-06
pjp
#include <bsd/sys/endian.h>
060
2019-06-06
pjp
#else /* not linux */
061
2019-06-06
pjp
#include <sys/queue.h>
062
2019-06-06
pjp
#include <sys/tree.h>
063
2019-06-06
pjp
#endif /* __linux__ */
064
2019-06-06
pjp
065
2019-06-06
pjp
066
2017-01-09
pjp
#include "ddd-dns.h"
067
2017-01-09
pjp
#include "ddd-db.h"
068
2017-01-09
pjp
069
2017-06-26
pjp
int init_entlist(ddDB *);
070
2017-01-09
pjp
int check_ent(char *, int);
071
2017-01-09
pjp
static int ent_contains(char *, int, char *, int);
072
2017-01-09
pjp
073
2017-01-09
pjp
extern void dolog(int, char *, ...);
074
2017-01-09
pjp
extern int memcasecmp(u_char *, u_char *, int);
075
2017-01-09
pjp
076
2017-01-09
pjp
extern int debug, verbose;
077
2017-01-09
pjp
078
2017-01-09
pjp
SLIST_HEAD(listhead, ententry) enthead;
079
2017-01-09
pjp
080
2017-06-26
pjp
081
2017-01-09
pjp
static struct ententry {
082
2017-01-09
pjp
char *name;
083
2017-01-09
pjp
int len;
084
2017-01-09
pjp
SLIST_ENTRY(ententry) ent_entry;
085
2017-01-09
pjp
} *ent2, *entp;
086
2017-01-09
pjp
087
2017-06-26
pjp
extern int domaincmp(struct node *e1, struct node *e2);
088
2017-01-09
pjp
089
2017-01-09
pjp
090
2017-01-09
pjp
/*
091
2017-01-09
pjp
* INIT_ENTLIST - initialize the ent singly linked list
092
2017-01-09
pjp
*/
093
2017-01-09
pjp
094
2017-01-09
pjp
int
095
2017-06-26
pjp
init_entlist(ddDB *db)
096
2017-01-09
pjp
{
097
2017-06-26
pjp
struct node *n, *nx;
098
2019-02-15
pjp
struct rbtree *rbt = NULL;
099
2017-01-09
pjp
100
2017-01-09
pjp
SLIST_INIT(&enthead);
101
2017-01-09
pjp
102
2019-02-19
pjp
RB_FOREACH_SAFE(n, domaintree, &db->head, nx) {
103
2019-02-15
pjp
rbt = (struct rbtree *)n->data;
104
2017-01-09
pjp
ent2 = malloc(sizeof(struct ententry));
105
2017-01-09
pjp
if (ent2 == NULL) {
106
2017-01-09
pjp
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
107
2017-01-09
pjp
return -1;
108
2017-01-09
pjp
}
109
2017-01-09
pjp
110
2019-02-15
pjp
ent2->name = malloc(rbt->zonelen);
111
2017-01-09
pjp
if (ent2->name == NULL) {
112
2017-01-09
pjp
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
113
2017-01-09
pjp
return -1;
114
2017-01-09
pjp
}
115
2017-01-09
pjp
116
2017-01-09
pjp
117
2019-02-15
pjp
memcpy(ent2->name, rbt->zone, rbt->zonelen);
118
2019-02-15
pjp
ent2->len = rbt->zonelen;
119
2017-01-09
pjp
120
2017-01-09
pjp
SLIST_INSERT_HEAD(&enthead, ent2, ent_entry);
121
2017-06-26
pjp
}
122
2017-01-09
pjp
123
2017-01-09
pjp
124
2017-01-09
pjp
return 0;
125
2017-01-09
pjp
}
126
2017-01-09
pjp
127
2017-01-09
pjp
/*
128
2017-01-09
pjp
* Check if the provided name is an empty non-terminating (ENT) name, if so
129
2017-01-09
pjp
* return 1, else return 0
130
2017-01-09
pjp
*/
131
2017-01-09
pjp
132
2017-01-09
pjp
int
133
2017-01-09
pjp
check_ent(char *name, int len)
134
2017-01-09
pjp
{
135
2017-01-09
pjp
/* walk the dns forest searching for a matching ENT */
136
2017-01-09
pjp
SLIST_FOREACH(entp, &enthead, ent_entry) {
137
2017-01-09
pjp
/* skip ent candidates that are too short */
138
2017-01-09
pjp
if (entp->len <= len)
139
2017-01-09
pjp
continue;
140
2017-01-09
pjp
if (ent_contains(name, len, entp->name, entp->len)) {
141
2017-01-09
pjp
return (1);
142
2017-01-09
pjp
}
143
2017-01-09
pjp
}
144
2017-01-09
pjp
145
2017-01-09
pjp
return (0);
146
2017-01-09
pjp
}
147
2017-01-09
pjp
148
2017-01-09
pjp
149
2017-01-09
pjp
static int
150
2017-01-09
pjp
ent_contains(char *name, int len, char *entname, int entlen)
151
2017-01-09
pjp
{
152
2017-01-09
pjp
char *p;
153
2017-01-09
pjp
int l;
154
2017-01-09
pjp
155
2017-01-09
pjp
p = entname;
156
2017-01-09
pjp
l = entlen;
157
2017-01-09
pjp
while (*p) {
158
2017-01-09
pjp
l -= (*p + 1);
159
2017-01-09
pjp
p += (*p + 1);
160
2017-01-09
pjp
161
2017-01-09
pjp
if (l != len)
162
2017-01-09
pjp
continue;
163
2017-01-09
pjp
164
2017-01-09
pjp
if (memcasecmp(name, p, l) == 0)
165
2018-05-11
pjp
goto exists; /* ? */
166
2017-01-09
pjp
}
167
2017-01-09
pjp
168
2017-01-09
pjp
return 0;
169
2018-05-11
pjp
170
2018-05-11
pjp
exists:
171
2018-05-11
pjp
/*
172
2018-05-11
pjp
* we take a second look, to make sure that we don't hit the
173
2018-05-11
pjp
* base of an ENT...this was overlooked originally
174
2018-05-11
pjp
*/
175
2018-05-11
pjp
176
2018-05-11
pjp
SLIST_FOREACH(ent2, &enthead, ent_entry) {
177
2018-05-11
pjp
if (ent2->len != l)
178
2018-05-11
pjp
continue;
179
2018-05-11
pjp
180
2018-05-11
pjp
if (memcasecmp(ent2->name, p, l) == 0)
181
2018-05-11
pjp
return 0;
182
2018-05-11
pjp
}
183
2018-05-11
pjp
184
2018-05-11
pjp
return 1;
185
2017-01-09
pjp
}
repomaster@centroid.eu