Add BIND 9.2.4rc7.
[dragonfly.git] / contrib / bind-9.2.4rc7 / lib / bind / irs / nis.c
blob828128e1ceb0645c290ca19723f99c06ff68fe11
1 /*
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.2.1 2004/03/09 09:17:33 marka Exp $";
20 #endif
22 /* Imports */
24 #include "port_before.h"
26 #ifdef WANT_IRS_NIS
28 #include <rpc/rpc.h>
29 #include <rpc/xdr.h>
30 #include <rpcsvc/yp_prot.h>
31 #include <rpcsvc/ypclnt.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <errno.h>
37 #include <sys/types.h>
38 #include <netinet/in.h>
39 #ifdef T_NULL
40 #undef T_NULL /* Silence re-definition warning of T_NULL. */
41 #endif
42 #include <arpa/nameser.h>
43 #include <resolv.h>
45 #include <isc/memcluster.h>
46 #include <irs.h>
48 #include "port_after.h"
50 #include "irs_p.h"
51 #include "hesiod.h"
52 #include "nis_p.h"
54 /* Forward */
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 *,
59 void (*)(void *));
61 /* Public */
63 struct irs_acc *
64 irs_nis_acc(const char *options) {
65 struct nis_p *nis;
66 struct irs_acc *acc;
67 char *domain;
69 UNUSED(options);
71 if (yp_get_default_domain(&domain) != 0)
72 return (NULL);
73 if (!(nis = memget(sizeof *nis))) {
74 errno = ENOMEM;
75 return (NULL);
77 memset(nis, 0, sizeof *nis);
78 if (!(acc = memget(sizeof *acc))) {
79 memput(nis, sizeof *nis);
80 errno = ENOMEM;
81 return (NULL);
83 memset(acc, 0x5e, sizeof *acc);
84 acc->private = nis;
85 nis->domain = strdup(domain);
86 #ifdef WANT_IRS_GR
87 acc->gr_map = irs_nis_gr;
88 #else
89 acc->gr_map = NULL;
90 #endif
91 #ifdef WANT_IRS_PW
92 acc->pw_map = irs_nis_pw;
93 #else
94 acc->pw_map = NULL;
95 #endif
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;
104 return (acc);
107 /* Methods */
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);
116 if (res == NULL)
117 return (NULL);
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)
124 return (NULL);
126 return (nis->res);
129 static void
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);
139 nis->res = res;
140 nis->free_res = free_res;
143 static void
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);
149 free(nis->domain);
150 memput(nis, sizeof *nis);
151 memput(this, sizeof *this);
154 #endif /*WANT_IRS_NIS*/