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 #include "port_before.h"
24 #include <rpcsvc/yp_prot.h>
25 #include <rpcsvc/ypclnt.h>
31 #include <sys/types.h>
32 #include <netinet/in.h>
34 #undef T_NULL /* Silence re-definition warning of T_NULL. */
36 #include <arpa/nameser.h>
39 #include <isc/memcluster.h>
42 #include "port_after.h"
50 static void nis_close(struct irs_acc
*);
51 static struct __res_state
* nis_res_get(struct irs_acc
*);
52 static void nis_res_set(struct irs_acc
*, struct __res_state
*,
58 irs_nis_acc(const char *options
) {
65 if (yp_get_default_domain(&domain
) != 0)
67 if (!(nis
= memget(sizeof *nis
))) {
71 memset(nis
, 0, sizeof *nis
);
72 if (!(acc
= memget(sizeof *acc
))) {
73 memput(nis
, sizeof *nis
);
77 memset(acc
, 0x5e, sizeof *acc
);
79 nis
->domain
= strdup(domain
);
81 acc
->gr_map
= irs_nis_gr
;
86 acc
->pw_map
= irs_nis_pw
;
90 acc
->sv_map
= irs_nis_sv
;
91 acc
->pr_map
= irs_nis_pr
;
92 acc
->ho_map
= irs_nis_ho
;
93 acc
->nw_map
= irs_nis_nw
;
94 acc
->ng_map
= irs_nis_ng
;
95 acc
->res_get
= nis_res_get
;
96 acc
->res_set
= nis_res_set
;
97 acc
->close
= nis_close
;
103 static struct __res_state
*
104 nis_res_get(struct irs_acc
*this) {
105 struct nis_p
*nis
= (struct nis_p
*)this->private;
107 if (nis
->res
== NULL
) {
108 struct __res_state
*res
;
109 res
= (struct __res_state
*)malloc(sizeof *res
);
112 memset(res
, 0, sizeof *res
);
113 nis_res_set(this, res
, free
);
116 if ((nis
->res
->options
& RES_INIT
) == 0 &&
117 res_ninit(nis
->res
) < 0)
124 nis_res_set(struct irs_acc
*this, struct __res_state
*res
,
125 void (*free_res
)(void *)) {
126 struct nis_p
*nis
= (struct nis_p
*)this->private;
128 if (nis
->res
&& nis
->free_res
) {
129 res_nclose(nis
->res
);
130 (*nis
->free_res
)(nis
->res
);
134 nis
->free_res
= free_res
;
138 nis_close(struct irs_acc
*this) {
139 struct nis_p
*nis
= (struct nis_p
*)this->private;
141 if (nis
->res
&& nis
->free_res
)
142 (*nis
->free_res
)(nis
->res
);
144 memput(nis
, sizeof *nis
);
145 memput(this, sizeof *this);
148 #endif /*WANT_IRS_NIS*/