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.
18 #if defined(LIBC_SCCS) && !defined(lint)
19 static const char rcsid[] = "$Id: nis.c,v 1.1.206.1 2004/03/09 08:33:38 marka Exp $";
24 #include "port_before.h"
30 #include <rpcsvc/yp_prot.h>
31 #include <rpcsvc/ypclnt.h>
37 #include <sys/types.h>
38 #include <netinet/in.h>
40 #undef T_NULL /* Silence re-definition warning of T_NULL. */
42 #include <arpa/nameser.h>
45 #include <isc/memcluster.h>
48 #include "port_after.h"
56 static void nis_close(struct irs_acc *);
57 static struct __res_state * nis_res_get(struct irs_acc *);
58 static void nis_res_set(struct irs_acc *, struct __res_state *,
64 irs_nis_acc(const char *options) {
71 if (yp_get_default_domain(&domain) != 0)
73 if (!(nis = memget(sizeof *nis))) {
77 memset(nis, 0, sizeof *nis);
78 if (!(acc = memget(sizeof *acc))) {
79 memput(nis, sizeof *nis);
83 memset(acc, 0x5e, sizeof *acc);
85 nis->domain = strdup(domain);
87 acc->gr_map = irs_nis_gr;
92 acc->pw_map = irs_nis_pw;
96 acc->sv_map = irs_nis_sv;
97 acc->pr_map = irs_nis_pr;
98 acc->ho_map = irs_nis_ho;
99 acc->nw_map = irs_nis_nw;
100 acc->ng_map = irs_nis_ng;
101 acc->res_get = nis_res_get;
102 acc->res_set = nis_res_set;
103 acc->close = nis_close;
109 static struct __res_state *
110 nis_res_get(struct irs_acc *this) {
111 struct nis_p *nis = (struct nis_p *)this->private;
113 if (nis->res == NULL) {
114 struct __res_state *res;
115 res = (struct __res_state *)malloc(sizeof *res);
118 memset(res, 0, sizeof *res);
119 nis_res_set(this, res, free);
122 if ((nis->res->options & RES_INIT) == 0 &&
123 res_ninit(nis->res) < 0)
130 nis_res_set(struct irs_acc *this, struct __res_state *res,
131 void (*free_res)(void *)) {
132 struct nis_p *nis = (struct nis_p *)this->private;
134 if (nis->res && nis->free_res) {
135 res_nclose(nis->res);
136 (*nis->free_res)(nis->res);
140 nis->free_res = free_res;
144 nis_close(struct irs_acc *this) {
145 struct nis_p *nis = (struct nis_p *)this->private;
147 if (nis->res && nis->free_res)
148 (*nis->free_res)(nis->res);
150 memput(nis, sizeof *nis);
151 memput(this, sizeof *this);
154 #endif /*WANT_IRS_NIS*/