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.1.206.1 2004/03/09 08:33:37 marka Exp $";
24 #include "port_before.h"
35 #include <isc/memcluster.h>
36 #include <isc/irpmarshall.h>
41 #include "port_after.h"
46 struct irp_p *girpdata;
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 **,
57 static int ng_test(struct irs_ng *, const char *,
58 const char *, const char *,
60 static void ng_minimize(struct irs_ng *);
68 * struct irs_ng * irs_irp_ng(struct irs_acc *this)
72 * Intialize the irp netgroup module.
77 irs_irp_ng(struct irs_acc *this) {
81 if (!(ng = memget(sizeof *ng))) {
85 memset(ng, 0x5e, sizeof *ng);
87 if (!(pvt = memget(sizeof *pvt))) {
88 memput(ng, sizeof *ng);
92 memset(pvt, 0, sizeof *pvt);
93 pvt->girpdata = this->private;
99 ng->rewind = ng_rewind;
100 ng->minimize = ng_minimize;
109 * void ng_close(struct irs_ng *this)
114 ng_close(struct irs_ng *this) {
115 struct pvt *pvt = (struct pvt *)this->private;
119 memput(pvt, sizeof *pvt);
120 memput(this, sizeof *this);
127 * void ng_rewind(struct irs_ng *this, const char *group)
133 ng_rewind(struct irs_ng *this, const char *group) {
134 struct pvt *pvt = (struct pvt *)this->private;
138 if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
142 if (irs_irp_send_command(pvt->girpdata,
143 "setnetgrent %s", group) != 0) {
147 code = irs_irp_read_response(pvt->girpdata, text, sizeof text);
148 if (code != IRPD_GETNETGR_SETOK) {
149 if (irp_log_errors) {
150 syslog(LOG_WARNING, "setnetgrent(%s) failed: %s",
162 * int ng_next(struct irs_ng *this, const char **host, const char **user,
163 * const char **domain)
167 * Get the next netgroup item from the cache.
172 ng_next(struct irs_ng *this, const char **host, const char **user,
175 struct pvt *pvt = (struct pvt *)this->private;
182 if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
186 if (irs_irp_send_command(pvt->girpdata, "getnetgrent") != 0)
189 if (irs_irp_get_full_response(pvt->girpdata, &code,
191 &body, &bodylen) != 0) {
195 if (code == IRPD_GETNETGR_OK) {
196 if (irp_unmarshall_ng(host, user, domain, body) == 0) {
202 memput(body, bodylen);
211 * int ng_test(struct irs_ng *this, const char *name, const char *host,
212 * const char *user, const char *domain)
216 * Search for a match in a netgroup.
221 ng_test(struct irs_ng *this, const char *name,
222 const char *host, const char *user, const char *domain)
224 struct pvt *pvt = (struct pvt *)this->private;
233 if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
237 if (irp_marshall_ng(host, user, domain, &body, &bodylen) != 0) {
241 if (irs_irp_send_command(pvt->girpdata, "innetgr %s", body) == 0) {
242 memput(body, bodylen);
244 code = irs_irp_read_response(pvt->girpdata, text, sizeof text);
245 if (code == IRPD_GETNETGR_MATCHES) {
257 * void ng_minimize(struct irs_ng *this)
262 ng_minimize(struct irs_ng *this) {
263 struct pvt *pvt = (struct pvt *)this->private;
265 irs_irp_disconnect(pvt->girpdata);