Detect FPU by checking CPUID features.
[dragonfly.git] / contrib / bind-9.5.2 / lib / bind / irs / irp_ng.c
blob1af862cab434124a9337688f8a3059e403f98505
1 /*
2 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (c) 1996, 1998 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.
18 #if !defined(LINT) && !defined(CODECENTER)
19 static const char rcsid[] = "$Id: irp_ng.c,v 1.4 2006/12/07 04:46:27 marka Exp $";
20 #endif
22 /* Imports */
24 #include "port_before.h"
26 #include <errno.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <unistd.h>
31 #include <syslog.h>
33 #include <irs.h>
34 #include <irp.h>
35 #include <isc/memcluster.h>
36 #include <isc/irpmarshall.h>
38 #include "irs_p.h"
39 #include "irp_p.h"
41 #include "port_after.h"
43 /* Definitions */
45 struct pvt {
46 struct irp_p *girpdata;
47 int warned;
51 /* Forward */
53 static void ng_rewind(struct irs_ng *, const char*);
54 static void ng_close(struct irs_ng *);
55 static int ng_next(struct irs_ng *, const char **, const char **,
56 const char **);
57 static int ng_test(struct irs_ng *, const char *,
58 const char *, const char *,
59 const char *);
60 static void ng_minimize(struct irs_ng *);
63 /* Public */
65 /*%
66 * Intialize the irp netgroup module.
70 struct irs_ng *
71 irs_irp_ng(struct irs_acc *this) {
72 struct irs_ng *ng;
73 struct pvt *pvt;
75 if (!(ng = memget(sizeof *ng))) {
76 errno = ENOMEM;
77 return (NULL);
79 memset(ng, 0x5e, sizeof *ng);
81 if (!(pvt = memget(sizeof *pvt))) {
82 memput(ng, sizeof *ng);
83 errno = ENOMEM;
84 return (NULL);
86 memset(pvt, 0, sizeof *pvt);
87 pvt->girpdata = this->private;
89 ng->private = pvt;
90 ng->close = ng_close;
91 ng->next = ng_next;
92 ng->test = ng_test;
93 ng->rewind = ng_rewind;
94 ng->minimize = ng_minimize;
95 return (ng);
98 /* Methods */
103 * void ng_close(struct irs_ng *this)
107 static void
108 ng_close(struct irs_ng *this) {
109 struct pvt *pvt = (struct pvt *)this->private;
111 ng_minimize(this);
113 memput(pvt, sizeof *pvt);
114 memput(this, sizeof *this);
121 * void ng_rewind(struct irs_ng *this, const char *group)
126 static void
127 ng_rewind(struct irs_ng *this, const char *group) {
128 struct pvt *pvt = (struct pvt *)this->private;
129 char text[256];
130 int code;
132 if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
133 return;
136 if (irs_irp_send_command(pvt->girpdata,
137 "setnetgrent %s", group) != 0) {
138 return;
141 code = irs_irp_read_response(pvt->girpdata, text, sizeof text);
142 if (code != IRPD_GETNETGR_SETOK) {
143 if (irp_log_errors) {
144 syslog(LOG_WARNING, "setnetgrent(%s) failed: %s",
145 group, text);
149 return;
153 * Get the next netgroup item from the cache.
157 static int
158 ng_next(struct irs_ng *this, const char **host, const char **user,
159 const char **domain)
161 struct pvt *pvt = (struct pvt *)this->private;
162 int code;
163 char *body = NULL;
164 size_t bodylen;
165 int rval = 0;
166 char text[256];
168 if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
169 return (0);
172 if (irs_irp_send_command(pvt->girpdata, "getnetgrent") != 0)
173 return (0);
175 if (irs_irp_get_full_response(pvt->girpdata, &code,
176 text, sizeof text,
177 &body, &bodylen) != 0) {
178 return (0);
181 if (code == IRPD_GETNETGR_OK) {
182 if (irp_unmarshall_ng(host, user, domain, body) == 0) {
183 rval = 1;
187 if (body != NULL) {
188 memput(body, bodylen);
191 return (rval);
195 * Search for a match in a netgroup.
199 static int
200 ng_test(struct irs_ng *this, const char *name,
201 const char *host, const char *user, const char *domain)
203 struct pvt *pvt = (struct pvt *)this->private;
204 char *body = NULL;
205 size_t bodylen = 0;
206 int code;
207 char text[256];
208 int rval = 0;
210 UNUSED(name);
212 if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
213 return (0);
216 if (irp_marshall_ng(host, user, domain, &body, &bodylen) != 0) {
217 return (0);
220 if (irs_irp_send_command(pvt->girpdata, "innetgr %s", body) == 0) {
221 code = irs_irp_read_response(pvt->girpdata, text, sizeof text);
222 if (code == IRPD_GETNETGR_MATCHES) {
223 rval = 1;
227 memput(body, bodylen);
229 return (rval);
236 * void ng_minimize(struct irs_ng *this)
240 static void
241 ng_minimize(struct irs_ng *this) {
242 struct pvt *pvt = (struct pvt *)this->private;
244 irs_irp_disconnect(pvt->girpdata);
250 /* Private */
253 /*! \file */