1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. 3*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 4*7c478bd9Sstevel@tonic-gate */ 5*7c478bd9Sstevel@tonic-gate 6*7c478bd9Sstevel@tonic-gate /* 7*7c478bd9Sstevel@tonic-gate * Copyright (c) 1996-1999 by Internet Software Consortium. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * Permission to use, copy, modify, and distribute this software for any 10*7c478bd9Sstevel@tonic-gate * purpose with or without fee is hereby granted, provided that the above 11*7c478bd9Sstevel@tonic-gate * copyright notice and this permission notice appear in all copies. 12*7c478bd9Sstevel@tonic-gate * 13*7c478bd9Sstevel@tonic-gate * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS 14*7c478bd9Sstevel@tonic-gate * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES 15*7c478bd9Sstevel@tonic-gate * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE 16*7c478bd9Sstevel@tonic-gate * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 17*7c478bd9Sstevel@tonic-gate * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 18*7c478bd9Sstevel@tonic-gate * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 19*7c478bd9Sstevel@tonic-gate * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 20*7c478bd9Sstevel@tonic-gate * SOFTWARE. 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate 23*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 24*7c478bd9Sstevel@tonic-gate 25*7c478bd9Sstevel@tonic-gate #if defined(LIBC_SCCS) && !defined(lint) 26*7c478bd9Sstevel@tonic-gate static const char rcsid[] = "$Id: nis.c,v 1.15 2001/05/29 05:49:11 marka Exp $"; 27*7c478bd9Sstevel@tonic-gate #endif 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate /* Imports */ 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #include "port_before.h" 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate #ifdef WANT_IRS_NIS 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate #include <rpc/rpc.h> 36*7c478bd9Sstevel@tonic-gate #include <rpc/xdr.h> 37*7c478bd9Sstevel@tonic-gate #include <rpcsvc/yp_prot.h> 38*7c478bd9Sstevel@tonic-gate #include <rpcsvc/ypclnt.h> 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 41*7c478bd9Sstevel@tonic-gate #include <string.h> 42*7c478bd9Sstevel@tonic-gate #include <errno.h> 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 45*7c478bd9Sstevel@tonic-gate #include <netinet/in.h> 46*7c478bd9Sstevel@tonic-gate #include <arpa/nameser.h> 47*7c478bd9Sstevel@tonic-gate #include <resolv.h> 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate #include <isc/memcluster.h> 50*7c478bd9Sstevel@tonic-gate #include <irs.h> 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate #include "port_after.h" 53*7c478bd9Sstevel@tonic-gate 54*7c478bd9Sstevel@tonic-gate #include "irs_p.h" 55*7c478bd9Sstevel@tonic-gate #include "hesiod.h" 56*7c478bd9Sstevel@tonic-gate #include "nis_p.h" 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate /* Forward */ 59*7c478bd9Sstevel@tonic-gate 60*7c478bd9Sstevel@tonic-gate static void nis_close(struct irs_acc *); 61*7c478bd9Sstevel@tonic-gate static struct __res_state * nis_res_get(struct irs_acc *); 62*7c478bd9Sstevel@tonic-gate static void nis_res_set(struct irs_acc *, struct __res_state *, 63*7c478bd9Sstevel@tonic-gate void (*)(void *)); 64*7c478bd9Sstevel@tonic-gate 65*7c478bd9Sstevel@tonic-gate /* Public */ 66*7c478bd9Sstevel@tonic-gate 67*7c478bd9Sstevel@tonic-gate struct irs_acc * 68*7c478bd9Sstevel@tonic-gate irs_nis_acc(const char *options) { 69*7c478bd9Sstevel@tonic-gate struct nis_p *nis; 70*7c478bd9Sstevel@tonic-gate struct irs_acc *acc; 71*7c478bd9Sstevel@tonic-gate char *domain; 72*7c478bd9Sstevel@tonic-gate 73*7c478bd9Sstevel@tonic-gate UNUSED(options); 74*7c478bd9Sstevel@tonic-gate 75*7c478bd9Sstevel@tonic-gate if (yp_get_default_domain(&domain) != 0) 76*7c478bd9Sstevel@tonic-gate return (NULL); 77*7c478bd9Sstevel@tonic-gate if (!(nis = memget(sizeof *nis))) { 78*7c478bd9Sstevel@tonic-gate errno = ENOMEM; 79*7c478bd9Sstevel@tonic-gate return (NULL); 80*7c478bd9Sstevel@tonic-gate } 81*7c478bd9Sstevel@tonic-gate memset(nis, 0, sizeof *nis); 82*7c478bd9Sstevel@tonic-gate if (!(acc = memget(sizeof *acc))) { 83*7c478bd9Sstevel@tonic-gate memput(nis, sizeof *nis); 84*7c478bd9Sstevel@tonic-gate errno = ENOMEM; 85*7c478bd9Sstevel@tonic-gate return (NULL); 86*7c478bd9Sstevel@tonic-gate } 87*7c478bd9Sstevel@tonic-gate memset(acc, 0x5e, sizeof *acc); 88*7c478bd9Sstevel@tonic-gate acc->private = nis; 89*7c478bd9Sstevel@tonic-gate nis->domain = strdup(domain); 90*7c478bd9Sstevel@tonic-gate #ifdef WANT_IRS_GR 91*7c478bd9Sstevel@tonic-gate acc->gr_map = irs_nis_gr; 92*7c478bd9Sstevel@tonic-gate #else 93*7c478bd9Sstevel@tonic-gate acc->gr_map = NULL; 94*7c478bd9Sstevel@tonic-gate #endif 95*7c478bd9Sstevel@tonic-gate #ifdef WANT_IRS_PW 96*7c478bd9Sstevel@tonic-gate acc->pw_map = irs_nis_pw; 97*7c478bd9Sstevel@tonic-gate #else 98*7c478bd9Sstevel@tonic-gate acc->pw_map = NULL; 99*7c478bd9Sstevel@tonic-gate #endif 100*7c478bd9Sstevel@tonic-gate acc->sv_map = irs_nis_sv; 101*7c478bd9Sstevel@tonic-gate acc->pr_map = irs_nis_pr; 102*7c478bd9Sstevel@tonic-gate acc->ho_map = irs_nis_ho; 103*7c478bd9Sstevel@tonic-gate acc->nw_map = irs_nis_nw; 104*7c478bd9Sstevel@tonic-gate acc->ng_map = irs_nis_ng; 105*7c478bd9Sstevel@tonic-gate acc->res_get = nis_res_get; 106*7c478bd9Sstevel@tonic-gate acc->res_set = nis_res_set; 107*7c478bd9Sstevel@tonic-gate acc->close = nis_close; 108*7c478bd9Sstevel@tonic-gate return (acc); 109*7c478bd9Sstevel@tonic-gate } 110*7c478bd9Sstevel@tonic-gate 111*7c478bd9Sstevel@tonic-gate /* Methods */ 112*7c478bd9Sstevel@tonic-gate 113*7c478bd9Sstevel@tonic-gate static struct __res_state * 114*7c478bd9Sstevel@tonic-gate nis_res_get(struct irs_acc *this) { 115*7c478bd9Sstevel@tonic-gate struct nis_p *nis = (struct nis_p *)this->private; 116*7c478bd9Sstevel@tonic-gate 117*7c478bd9Sstevel@tonic-gate if (nis->res == NULL) { 118*7c478bd9Sstevel@tonic-gate struct __res_state *res; 119*7c478bd9Sstevel@tonic-gate res = (struct __res_state *)malloc(sizeof *res); 120*7c478bd9Sstevel@tonic-gate if (res == NULL) 121*7c478bd9Sstevel@tonic-gate return (NULL); 122*7c478bd9Sstevel@tonic-gate memset(res, 0, sizeof *res); 123*7c478bd9Sstevel@tonic-gate nis_res_set(this, res, free); 124*7c478bd9Sstevel@tonic-gate } 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate if ((nis->res->options & RES_INIT) == 0 && 127*7c478bd9Sstevel@tonic-gate res_ninit(nis->res) < 0) 128*7c478bd9Sstevel@tonic-gate return (NULL); 129*7c478bd9Sstevel@tonic-gate 130*7c478bd9Sstevel@tonic-gate return (nis->res); 131*7c478bd9Sstevel@tonic-gate } 132*7c478bd9Sstevel@tonic-gate 133*7c478bd9Sstevel@tonic-gate static void 134*7c478bd9Sstevel@tonic-gate nis_res_set(struct irs_acc *this, struct __res_state *res, 135*7c478bd9Sstevel@tonic-gate void (*free_res)(void *)) { 136*7c478bd9Sstevel@tonic-gate struct nis_p *nis = (struct nis_p *)this->private; 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate if (nis->res && nis->free_res) { 139*7c478bd9Sstevel@tonic-gate res_nclose(nis->res); 140*7c478bd9Sstevel@tonic-gate (*nis->free_res)(nis->res); 141*7c478bd9Sstevel@tonic-gate } 142*7c478bd9Sstevel@tonic-gate 143*7c478bd9Sstevel@tonic-gate nis->res = res; 144*7c478bd9Sstevel@tonic-gate nis->free_res = free_res; 145*7c478bd9Sstevel@tonic-gate } 146*7c478bd9Sstevel@tonic-gate 147*7c478bd9Sstevel@tonic-gate static void 148*7c478bd9Sstevel@tonic-gate nis_close(struct irs_acc *this) { 149*7c478bd9Sstevel@tonic-gate struct nis_p *nis = (struct nis_p *)this->private; 150*7c478bd9Sstevel@tonic-gate 151*7c478bd9Sstevel@tonic-gate if (nis->res && nis->free_res) 152*7c478bd9Sstevel@tonic-gate (*nis->free_res)(nis->res); 153*7c478bd9Sstevel@tonic-gate free(nis->domain); 154*7c478bd9Sstevel@tonic-gate memput(nis, sizeof *nis); 155*7c478bd9Sstevel@tonic-gate memput(this, sizeof *this); 156*7c478bd9Sstevel@tonic-gate } 157*7c478bd9Sstevel@tonic-gate 158*7c478bd9Sstevel@tonic-gate #endif /*WANT_IRS_NIS*/ 159