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 $";
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
*);
66 * Intialize the irp netgroup module.
71 irs_irp_ng(struct irs_acc
*this) {
75 if (!(ng
= memget(sizeof *ng
))) {
79 memset(ng
, 0x5e, sizeof *ng
);
81 if (!(pvt
= memget(sizeof *pvt
))) {
82 memput(ng
, sizeof *ng
);
86 memset(pvt
, 0, sizeof *pvt
);
87 pvt
->girpdata
= this->private;
93 ng
->rewind
= ng_rewind
;
94 ng
->minimize
= ng_minimize
;
103 * void ng_close(struct irs_ng *this)
108 ng_close(struct irs_ng
*this) {
109 struct pvt
*pvt
= (struct pvt
*)this->private;
113 memput(pvt
, sizeof *pvt
);
114 memput(this, sizeof *this);
121 * void ng_rewind(struct irs_ng *this, const char *group)
127 ng_rewind(struct irs_ng
*this, const char *group
) {
128 struct pvt
*pvt
= (struct pvt
*)this->private;
132 if (irs_irp_connection_setup(pvt
->girpdata
, &pvt
->warned
) != 0) {
136 if (irs_irp_send_command(pvt
->girpdata
,
137 "setnetgrent %s", group
) != 0) {
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",
153 * Get the next netgroup item from the cache.
158 ng_next(struct irs_ng
*this, const char **host
, const char **user
,
161 struct pvt
*pvt
= (struct pvt
*)this->private;
168 if (irs_irp_connection_setup(pvt
->girpdata
, &pvt
->warned
) != 0) {
172 if (irs_irp_send_command(pvt
->girpdata
, "getnetgrent") != 0)
175 if (irs_irp_get_full_response(pvt
->girpdata
, &code
,
177 &body
, &bodylen
) != 0) {
181 if (code
== IRPD_GETNETGR_OK
) {
182 if (irp_unmarshall_ng(host
, user
, domain
, body
) == 0) {
188 memput(body
, bodylen
);
195 * Search for a match in a netgroup.
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;
212 if (irs_irp_connection_setup(pvt
->girpdata
, &pvt
->warned
) != 0) {
216 if (irp_marshall_ng(host
, user
, domain
, &body
, &bodylen
) != 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
) {
227 memput(body
, bodylen
);
236 * void ng_minimize(struct irs_ng *this)
241 ng_minimize(struct irs_ng
*this) {
242 struct pvt
*pvt
= (struct pvt
*)this->private;
244 irs_irp_disconnect(pvt
->girpdata
);