4 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (c) 1996-1999 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(LIBC_SCCS) && !defined(lint)
21 static const char rcsid
[] = "Id: nis.c,v 1.3 2005/04/27 04:56:32 sra Exp";
26 #include "port_before.h"
32 #include <rpcsvc/yp_prot.h>
33 #include <rpcsvc/ypclnt.h>
39 #include <sys/types.h>
40 #include <netinet/in.h>
42 #undef T_NULL /* Silence re-definition warning of T_NULL. */
44 #include <arpa/nameser.h>
47 #include <isc/memcluster.h>
50 #include "port_after.h"
58 static void nis_close(struct irs_acc
*);
59 static struct __res_state
* nis_res_get(struct irs_acc
*);
60 static void nis_res_set(struct irs_acc
*, struct __res_state
*,
66 irs_nis_acc(const char *options
) {
73 if (yp_get_default_domain(&domain
) != 0)
75 if (!(nis
= memget(sizeof *nis
))) {
79 memset(nis
, 0, sizeof *nis
);
80 if (!(acc
= memget(sizeof *acc
))) {
81 memput(nis
, sizeof *nis
);
85 memset(acc
, 0x5e, sizeof *acc
);
87 nis
->domain
= strdup(domain
);
89 acc
->gr_map
= irs_nis_gr
;
94 acc
->pw_map
= irs_nis_pw
;
98 acc
->sv_map
= irs_nis_sv
;
99 acc
->pr_map
= irs_nis_pr
;
100 acc
->ho_map
= irs_nis_ho
;
101 acc
->nw_map
= irs_nis_nw
;
102 acc
->ng_map
= irs_nis_ng
;
103 acc
->res_get
= nis_res_get
;
104 acc
->res_set
= nis_res_set
;
105 acc
->close
= nis_close
;
111 static struct __res_state
*
112 nis_res_get(struct irs_acc
*this) {
113 struct nis_p
*nis
= (struct nis_p
*)this->private;
115 if (nis
->res
== NULL
) {
116 struct __res_state
*res
;
117 res
= (struct __res_state
*)malloc(sizeof *res
);
120 memset(res
, 0, sizeof *res
);
121 nis_res_set(this, res
, free
);
124 if ((nis
->res
->options
& RES_INIT
) == 0 &&
125 res_ninit(nis
->res
) < 0)
132 nis_res_set(struct irs_acc
*this, struct __res_state
*res
,
133 void (*free_res
)(void *)) {
134 struct nis_p
*nis
= (struct nis_p
*)this->private;
136 if (nis
->res
&& nis
->free_res
) {
137 res_nclose(nis
->res
);
138 (*nis
->free_res
)(nis
->res
);
142 nis
->free_res
= free_res
;
146 nis_close(struct irs_acc
*this) {
147 struct nis_p
*nis
= (struct nis_p
*)this->private;
149 if (nis
->res
&& nis
->free_res
)
150 (*nis
->free_res
)(nis
->res
);
152 memput(nis
, sizeof *nis
);
153 memput(this, sizeof *this);
156 #endif /*WANT_IRS_NIS*/