10Sstevel@tonic-gate /* 2*11038SRao.Shoaib@Sun.COM * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") 30Sstevel@tonic-gate * Copyright (c) 1996-1999 by Internet Software Consortium. 40Sstevel@tonic-gate * 50Sstevel@tonic-gate * Permission to use, copy, modify, and distribute this software for any 60Sstevel@tonic-gate * purpose with or without fee is hereby granted, provided that the above 70Sstevel@tonic-gate * copyright notice and this permission notice appear in all copies. 80Sstevel@tonic-gate * 9*11038SRao.Shoaib@Sun.COM * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 10*11038SRao.Shoaib@Sun.COM * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11*11038SRao.Shoaib@Sun.COM * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 12*11038SRao.Shoaib@Sun.COM * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13*11038SRao.Shoaib@Sun.COM * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14*11038SRao.Shoaib@Sun.COM * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 15*11038SRao.Shoaib@Sun.COM * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 160Sstevel@tonic-gate */ 170Sstevel@tonic-gate 180Sstevel@tonic-gate #if !defined(LINT) && !defined(CODECENTER) 19*11038SRao.Shoaib@Sun.COM static const char rcsid[] = "$Id: lcl.c,v 1.4 2005/04/27 04:56:30 sra Exp $"; 200Sstevel@tonic-gate #endif 210Sstevel@tonic-gate 220Sstevel@tonic-gate /* Imports */ 230Sstevel@tonic-gate 240Sstevel@tonic-gate #include "port_before.h" 250Sstevel@tonic-gate 260Sstevel@tonic-gate #include <stdlib.h> 270Sstevel@tonic-gate #include <errno.h> 280Sstevel@tonic-gate #include <string.h> 290Sstevel@tonic-gate 300Sstevel@tonic-gate #include <sys/types.h> 310Sstevel@tonic-gate #include <netinet/in.h> 320Sstevel@tonic-gate #include <arpa/nameser.h> 330Sstevel@tonic-gate #include <resolv.h> 340Sstevel@tonic-gate 350Sstevel@tonic-gate #include <isc/memcluster.h> 360Sstevel@tonic-gate 370Sstevel@tonic-gate #include <irs.h> 380Sstevel@tonic-gate 390Sstevel@tonic-gate #include "port_after.h" 400Sstevel@tonic-gate 410Sstevel@tonic-gate #include "irs_p.h" 420Sstevel@tonic-gate #include "lcl_p.h" 430Sstevel@tonic-gate 440Sstevel@tonic-gate /* Forward. */ 450Sstevel@tonic-gate 460Sstevel@tonic-gate static void lcl_close(struct irs_acc *); 470Sstevel@tonic-gate static struct __res_state * lcl_res_get(struct irs_acc *); 480Sstevel@tonic-gate static void lcl_res_set(struct irs_acc *, struct __res_state *, 490Sstevel@tonic-gate void (*)(void *)); 500Sstevel@tonic-gate 510Sstevel@tonic-gate /* Public */ 520Sstevel@tonic-gate 530Sstevel@tonic-gate struct irs_acc * 540Sstevel@tonic-gate irs_lcl_acc(const char *options) { 550Sstevel@tonic-gate struct irs_acc *acc; 560Sstevel@tonic-gate struct lcl_p *lcl; 570Sstevel@tonic-gate 580Sstevel@tonic-gate UNUSED(options); 590Sstevel@tonic-gate 600Sstevel@tonic-gate if (!(acc = memget(sizeof *acc))) { 610Sstevel@tonic-gate errno = ENOMEM; 620Sstevel@tonic-gate return (NULL); 630Sstevel@tonic-gate } 640Sstevel@tonic-gate memset(acc, 0x5e, sizeof *acc); 650Sstevel@tonic-gate if (!(lcl = memget(sizeof *lcl))) { 660Sstevel@tonic-gate errno = ENOMEM; 670Sstevel@tonic-gate free(acc); 680Sstevel@tonic-gate return (NULL); 690Sstevel@tonic-gate } 700Sstevel@tonic-gate memset(lcl, 0x5e, sizeof *lcl); 710Sstevel@tonic-gate lcl->res = NULL; 720Sstevel@tonic-gate lcl->free_res = NULL; 730Sstevel@tonic-gate acc->private = lcl; 740Sstevel@tonic-gate #ifdef WANT_IRS_GR 750Sstevel@tonic-gate acc->gr_map = irs_lcl_gr; 760Sstevel@tonic-gate #else 770Sstevel@tonic-gate acc->gr_map = NULL; 780Sstevel@tonic-gate #endif 790Sstevel@tonic-gate #ifdef WANT_IRS_PW 800Sstevel@tonic-gate acc->pw_map = irs_lcl_pw; 810Sstevel@tonic-gate #else 820Sstevel@tonic-gate acc->pw_map = NULL; 830Sstevel@tonic-gate #endif 840Sstevel@tonic-gate acc->sv_map = irs_lcl_sv; 850Sstevel@tonic-gate acc->pr_map = irs_lcl_pr; 860Sstevel@tonic-gate acc->ho_map = irs_lcl_ho; 870Sstevel@tonic-gate acc->nw_map = irs_lcl_nw; 880Sstevel@tonic-gate acc->ng_map = irs_lcl_ng; 890Sstevel@tonic-gate acc->res_get = lcl_res_get; 900Sstevel@tonic-gate acc->res_set = lcl_res_set; 910Sstevel@tonic-gate acc->close = lcl_close; 920Sstevel@tonic-gate return (acc); 930Sstevel@tonic-gate } 940Sstevel@tonic-gate 950Sstevel@tonic-gate /* Methods */ 960Sstevel@tonic-gate static struct __res_state * 970Sstevel@tonic-gate lcl_res_get(struct irs_acc *this) { 980Sstevel@tonic-gate struct lcl_p *lcl = (struct lcl_p *)this->private; 990Sstevel@tonic-gate 1000Sstevel@tonic-gate if (lcl->res == NULL) { 1010Sstevel@tonic-gate struct __res_state *res; 1020Sstevel@tonic-gate res = (struct __res_state *)malloc(sizeof *res); 1030Sstevel@tonic-gate if (res == NULL) 1040Sstevel@tonic-gate return (NULL); 1050Sstevel@tonic-gate memset(res, 0, sizeof *res); 1060Sstevel@tonic-gate lcl_res_set(this, res, free); 1070Sstevel@tonic-gate } 1080Sstevel@tonic-gate 109*11038SRao.Shoaib@Sun.COM if ((lcl->res->options & RES_INIT) == 0U && 1100Sstevel@tonic-gate res_ninit(lcl->res) < 0) 1110Sstevel@tonic-gate return (NULL); 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate return (lcl->res); 1140Sstevel@tonic-gate } 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate static void 1170Sstevel@tonic-gate lcl_res_set(struct irs_acc *this, struct __res_state *res, 1180Sstevel@tonic-gate void (*free_res)(void *)) { 1190Sstevel@tonic-gate struct lcl_p *lcl = (struct lcl_p *)this->private; 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate if (lcl->res && lcl->free_res) { 1220Sstevel@tonic-gate res_nclose(lcl->res); 1230Sstevel@tonic-gate (*lcl->free_res)(lcl->res); 1240Sstevel@tonic-gate } 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate lcl->res = res; 1270Sstevel@tonic-gate lcl->free_res = free_res; 1280Sstevel@tonic-gate } 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate static void 1310Sstevel@tonic-gate lcl_close(struct irs_acc *this) { 1320Sstevel@tonic-gate struct lcl_p *lcl = (struct lcl_p *)this->private; 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate if (lcl) { 1350Sstevel@tonic-gate if (lcl->free_res) 1360Sstevel@tonic-gate (*lcl->free_res)(lcl->res); 1370Sstevel@tonic-gate memput(lcl, sizeof *lcl); 1380Sstevel@tonic-gate } 1390Sstevel@tonic-gate memput(this, sizeof *this); 1400Sstevel@tonic-gate } 141*11038SRao.Shoaib@Sun.COM 142*11038SRao.Shoaib@Sun.COM /*! \file */ 143