4 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (c) 1996, 1998 by Internet Software Consortium.
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
17 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #if !defined(LINT) && !defined(CODECENTER)
21 static const char rcsid
[] = "Id: irp_ng.c,v 1.4 2006/12/07 04:46:27 marka Exp";
26 #include "port_before.h"
37 #include <isc/memcluster.h>
38 #include <isc/irpmarshall.h>
43 #include "port_after.h"
48 struct irp_p
*girpdata
;
55 static void ng_rewind(struct irs_ng
*, const char*);
56 static void ng_close(struct irs_ng
*);
57 static int ng_next(struct irs_ng
*, const char **, const char **,
59 static int ng_test(struct irs_ng
*, const char *,
60 const char *, const char *,
62 static void ng_minimize(struct irs_ng
*);
68 * Intialize the irp netgroup module.
73 irs_irp_ng(struct irs_acc
*this) {
77 if (!(ng
= memget(sizeof *ng
))) {
81 memset(ng
, 0x5e, sizeof *ng
);
83 if (!(pvt
= memget(sizeof *pvt
))) {
84 memput(ng
, sizeof *ng
);
88 memset(pvt
, 0, sizeof *pvt
);
89 pvt
->girpdata
= this->private;
95 ng
->rewind
= ng_rewind
;
96 ng
->minimize
= ng_minimize
;
105 * void ng_close(struct irs_ng *this)
110 ng_close(struct irs_ng
*this) {
111 struct pvt
*pvt
= (struct pvt
*)this->private;
115 memput(pvt
, sizeof *pvt
);
116 memput(this, sizeof *this);
123 * void ng_rewind(struct irs_ng *this, const char *group)
129 ng_rewind(struct irs_ng
*this, const char *group
) {
130 struct pvt
*pvt
= (struct pvt
*)this->private;
134 if (irs_irp_connection_setup(pvt
->girpdata
, &pvt
->warned
) != 0) {
138 if (irs_irp_send_command(pvt
->girpdata
,
139 "setnetgrent %s", group
) != 0) {
143 code
= irs_irp_read_response(pvt
->girpdata
, text
, sizeof text
);
144 if (code
!= IRPD_GETNETGR_SETOK
) {
145 if (irp_log_errors
) {
146 syslog(LOG_WARNING
, "setnetgrent(%s) failed: %s",
155 * Get the next netgroup item from the cache.
160 ng_next(struct irs_ng
*this, const char **host
, const char **user
,
163 struct pvt
*pvt
= (struct pvt
*)this->private;
170 if (irs_irp_connection_setup(pvt
->girpdata
, &pvt
->warned
) != 0) {
174 if (irs_irp_send_command(pvt
->girpdata
, "getnetgrent") != 0)
177 if (irs_irp_get_full_response(pvt
->girpdata
, &code
,
179 &body
, &bodylen
) != 0) {
183 if (code
== IRPD_GETNETGR_OK
) {
184 if (irp_unmarshall_ng(host
, user
, domain
, body
) == 0) {
190 memput(body
, bodylen
);
197 * Search for a match in a netgroup.
202 ng_test(struct irs_ng
*this, const char *name
,
203 const char *host
, const char *user
, const char *domain
)
205 struct pvt
*pvt
= (struct pvt
*)this->private;
214 if (irs_irp_connection_setup(pvt
->girpdata
, &pvt
->warned
) != 0) {
218 if (irp_marshall_ng(host
, user
, domain
, &body
, &bodylen
) != 0) {
222 if (irs_irp_send_command(pvt
->girpdata
, "innetgr %s", body
) == 0) {
223 code
= irs_irp_read_response(pvt
->girpdata
, text
, sizeof text
);
224 if (code
== IRPD_GETNETGR_MATCHES
) {
229 memput(body
, bodylen
);
238 * void ng_minimize(struct irs_ng *this)
243 ng_minimize(struct irs_ng
*this) {
244 struct pvt
*pvt
= (struct pvt
*)this->private;
246 irs_irp_disconnect(pvt
->girpdata
);