2 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (c) 1996,1999 by Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
15 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include "port_before.h"
22 #include <sys/types.h>
24 #include <netinet/in.h>
25 #include <arpa/nameser.h>
32 #include <isc/memcluster.h>
35 #include "port_after.h"
43 struct irs_rule
* rules
;
44 struct irs_rule
* rule
;
50 static void ng_close(struct irs_ng
*);
51 static int ng_next(struct irs_ng
*, const char **,
52 const char **, const char **);
53 static int ng_test(struct irs_ng
*, const char *,
54 const char *, const char *,
56 static void ng_rewind(struct irs_ng
*, const char *);
57 static void ng_minimize(struct irs_ng
*);
62 irs_gen_ng(struct irs_acc
*this) {
63 struct gen_p
*accpvt
= (struct gen_p
*)this->private;
67 if (!(ng
= memget(sizeof *ng
))) {
71 memset(ng
, 0x5e, sizeof *ng
);
72 if (!(pvt
= memget(sizeof *pvt
))) {
73 memput(ng
, sizeof *ng
);
77 memset(pvt
, 0, sizeof *pvt
);
78 pvt
->rules
= accpvt
->map_rules
[irs_ng
];
79 pvt
->rule
= pvt
->rules
;
84 ng
->rewind
= ng_rewind
;
85 ng
->minimize
= ng_minimize
;
92 ng_close(struct irs_ng
*this) {
93 struct pvt
*pvt
= (struct pvt
*)this->private;
97 memput(pvt
, sizeof *pvt
);
98 memput(this, sizeof *this);
102 ng_next(struct irs_ng
*this, const char **host
, const char **user
,
105 struct pvt
*pvt
= (struct pvt
*)this->private;
109 ng
= pvt
->rule
->inst
->ng
;
110 if ((*ng
->next
)(ng
, host
, user
, domain
) == 1)
112 if (!(pvt
->rule
->flags
& IRS_CONTINUE
))
114 pvt
->rule
= pvt
->rule
->next
;
116 ng
= pvt
->rule
->inst
->ng
;
117 (*ng
->rewind
)(ng
, pvt
->curgroup
);
124 ng_test(struct irs_ng
*this, const char *name
,
125 const char *user
, const char *host
, const char *domain
)
127 struct pvt
*pvt
= (struct pvt
*)this->private;
128 struct irs_rule
*rule
;
133 for (rule
= pvt
->rules
; rule
; rule
= rule
->next
) {
135 rval
= (*ng
->test
)(ng
, name
, user
, host
, domain
);
136 if (rval
|| !(rule
->flags
& IRS_CONTINUE
))
143 ng_rewind(struct irs_ng
*this, const char *group
) {
144 struct pvt
*pvt
= (struct pvt
*)this->private;
147 pvt
->rule
= pvt
->rules
;
150 pvt
->curgroup
= strdup(group
);
151 ng
= pvt
->rule
->inst
->ng
;
152 (*ng
->rewind
)(ng
, pvt
->curgroup
);
157 ng_minimize(struct irs_ng
*this) {
158 struct pvt
*pvt
= (struct pvt
*)this->private;
159 struct irs_rule
*rule
;
161 for (rule
= pvt
->rules
; rule
!= NULL
; rule
= rule
->next
) {
162 struct irs_ng
*ng
= rule
->inst
->ng
;