11741Srmesta /* 21741Srmesta * CDDL HEADER START 31741Srmesta * 41741Srmesta * The contents of this file are subject to the terms of the 51741Srmesta * Common Development and Distribution License (the "License"). 61741Srmesta * You may not use this file except in compliance with the License. 71741Srmesta * 81741Srmesta * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 91741Srmesta * or http://www.opensolaris.org/os/licensing. 101741Srmesta * See the License for the specific language governing permissions 111741Srmesta * and limitations under the License. 121741Srmesta * 131741Srmesta * When distributing Covered Code, include this CDDL HEADER in each 141741Srmesta * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 151741Srmesta * If applicable, add the following below this CDDL HEADER, with the 161741Srmesta * fields enclosed by brackets "[]" replaced with your own identifying 171741Srmesta * information: Portions Copyright [yyyy] [name of copyright owner] 181741Srmesta * 191741Srmesta * CDDL HEADER END 201741Srmesta */ 211741Srmesta /* 22*7693SVallish.Vaidyeshwara@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 231741Srmesta * Use is subject to license terms. 241741Srmesta */ 251741Srmesta 261741Srmesta #ifndef _MAPID_H 271741Srmesta #define _MAPID_H 281741Srmesta 291741Srmesta #ifdef __cplusplus 301741Srmesta extern "C" { 311741Srmesta #endif 321741Srmesta 331741Srmesta #include <stdio.h> 341741Srmesta #include <stdlib.h> 351741Srmesta #include <unistd.h> 361741Srmesta #include <string.h> 371741Srmesta #include <strings.h> 381741Srmesta #include <sys/types.h> 391741Srmesta #include <sys/stat.h> 401741Srmesta #include <rpc/types.h> 411741Srmesta #include <netinet/in.h> 421741Srmesta #include <arpa/nameser.h> 431741Srmesta #include <resolv.h> 441741Srmesta #include <netdb.h> 451741Srmesta #include <errno.h> 461741Srmesta #include <ctype.h> 471741Srmesta #include <sys/socket.h> 481741Srmesta #include <arpa/inet.h> 491741Srmesta #include <assert.h> 501741Srmesta #include <synch.h> 511741Srmesta #include <syslog.h> 521741Srmesta #include <locale.h> 531741Srmesta #include <thread.h> 541741Srmesta #include <deflt.h> 551741Srmesta #include <nfs/nfs4.h> 561741Srmesta 571741Srmesta #define DNAMEMAX (NS_MAXCDNAME + 1) 581741Srmesta 591741Srmesta typedef struct { 601741Srmesta void *(*fcn)(void *); 611741Srmesta int signal; 621741Srmesta } cb_t; 631741Srmesta 641741Srmesta #ifdef __LIBMAPID_IMPL 651741Srmesta 661741Srmesta /* 671741Srmesta * Error Messages 681741Srmesta */ 691741Srmesta #define EMSG_NETDB_INTERNAL "Internal Resolver Error: %s" 701741Srmesta 711741Srmesta #define EMSG_TRY_AGAIN "\"%s\" DNS nameserver(s) not responding" \ 721741Srmesta "...\tRetrying" 731741Srmesta 741741Srmesta #define EMSG_NO_RECOVERY "Unrecoverable Resolver Error: %s" 751741Srmesta 761741Srmesta #define EMSG_HOST_NOT_FOUND "Authoritative nameserver unresponsive " \ 771741Srmesta "to queries for domain \"%s\"" 781741Srmesta 791741Srmesta #define EMSG_NO_DATA "\"%s\" DNS TXT record not found: "\ 801741Srmesta "Defaulting to \"%s\"" 811741Srmesta 821741Srmesta #define EMSG_DNS_THREAD_ERROR "Unable to create DNS query thread" 831741Srmesta 841741Srmesta #define EMSG_DNS_DISABLE "%s: Further DNS queries disabled !" 851741Srmesta 861741Srmesta #define EMSG_DNS_RR_INVAL "\"%s\" Invalid DNS TXT record: "\ 871741Srmesta "Defaulting to \"%s\"" 881741Srmesta 891741Srmesta /* 901741Srmesta * DNS related info 911741Srmesta */ 921741Srmesta #define NFSMAPID_DNS_RR "_nfsv4idmapdomain" 931741Srmesta #define NFSMAPID_DNS_TOUT_SECS (30LL) 941741Srmesta #define NFSMAPID_SLOG_RATE 20 /* ~10 mins */ 951741Srmesta 961741Srmesta #define NS_ERRS 6 /* netdb.h */ 971741Srmesta 981741Srmesta typedef union { 991741Srmesta HEADER hdr; 1001741Srmesta uchar_t buf[PACKETSZ]; 1011741Srmesta } ans_t; 1021741Srmesta 1031741Srmesta /* 1041741Srmesta * NOTE: All s_ prefixed variables are only to be used by the DNS 1051741Srmesta * feature implementation (mapid.c). The exported globals 1061741Srmesta * (ie. seen by nfsmapid.c/nfsmapid_server.c) are the 1071741Srmesta * dns_ prefixed variables along with sysdns_domain. 1081741Srmesta */ 1091741Srmesta static ans_t s_ans; 1101741Srmesta static int s_anslen; 1111741Srmesta static char s_dname[DNAMEMAX] = {0}; 1121741Srmesta static char s_txt_rr[DNAMEMAX] = {0}; 1131741Srmesta 1141741Srmesta static rwlock_t s_dns_data_lock = DEFAULTRWLOCK; 1151741Srmesta static rwlock_t s_dns_impl_lock = DEFAULTRWLOCK; 1161741Srmesta static mutex_t s_res_lock = ERRORCHECKMUTEX; 1171741Srmesta static uint32_t s_dns_tout = 0; 1181741Srmesta static thread_t s_dns_qthread; 1191741Srmesta static bool_t s_dns_qthr_created = FALSE; 1201741Srmesta static bool_t s_dns_disabled = FALSE; 1211741Srmesta static struct __res_state s_res = {0}; 1221741Srmesta static thread_key_t s_thr_key; 1231741Srmesta int lib_init_done = 0; 1241741Srmesta 1251741Srmesta static int resolv_init(void); 1261741Srmesta static void resolv_decode(void); 1271741Srmesta static int resolv_error(void); 1281741Srmesta static void resolv_get_txt_data(void); 1291741Srmesta static void resolv_txt_reset(void); 1301741Srmesta static void resolve_process_txt(uchar_t *, int); 1311741Srmesta static int resolv_search(void); 132*7693SVallish.Vaidyeshwara@Sun.COM static void resolv_destroy(void); 1331741Srmesta static uchar_t *resolv_skip_rr(uchar_t *, uchar_t *); 1341741Srmesta static void domain_sync(cb_t *, char *); 1351741Srmesta static int get_mtime(const char *, timestruc_t *); 1361741Srmesta static void get_nfs_domain(void); 1371741Srmesta static void get_dns_domain(void); 1381741Srmesta static void get_dns_txt_domain(cb_t *); 1391741Srmesta void _lib_init(void); 1401741Srmesta 1411741Srmesta #ifdef DEBUG 1421741Srmesta bool_t nfsmapid_debug = FALSE; 1431741Srmesta #endif /* DEBUG */ 1441741Srmesta 1451741Srmesta /* 1461741Srmesta * mapid_domain_lock: rwlock used to serialize access/changes 1471741Srmesta * to the library's mapid_domain global var. 1481741Srmesta * 1491741Srmesta * mapid_domain: Library variable used to store the current 1501741Srmesta * domain configured for use in decoding/encoding 1511741Srmesta * outbound and inbound attr strings, accordingly. 1521741Srmesta * 1531741Srmesta * nfs_domain: If /etc/default/nfs NFSMAPID_DOMAIN var 1541741Srmesta * has been set, nfs_domain will hold this 1551741Srmesta * value for the duration of the instance; 1561741Srmesta * If the value ever changes, the change is 1571741Srmesta * detected via the use of nfs_mtime and 1581741Srmesta * nfs_domain is updated accordingly. 1591741Srmesta * 1601741Srmesta * dns_domain: If the system's resolver (/etc/resolv.conf) 1611741Srmesta * has been configured, dns_domain will hold 1621741Srmesta * the configured DNS domain as reported by the 1631741Srmesta * res_ninit() resolver interface. If the system's 1641741Srmesta * /etc/resolv.conf file is updated, the change 1651741Srmesta * is detected via the use of dns_mtime and 1661741Srmesta * dns_domain is updated accordingly. 1671741Srmesta */ 1681741Srmesta rwlock_t mapid_domain_lock = DEFAULTRWLOCK; 1691741Srmesta uint32_t mapid_domain_len = 0; 1701741Srmesta char mapid_domain[DNAMEMAX] = {0}; 1711741Srmesta 1721741Srmesta timestruc_t nfs_mtime = {0}; 1731741Srmesta uint32_t nfs_domain_len = 0; 1741741Srmesta char nfs_domain[DNAMEMAX] = {0}; 1751741Srmesta 1761741Srmesta timestruc_t dns_mtime = {0}; 1771741Srmesta uint32_t dns_domain_len = 0; 1781741Srmesta char dns_domain[DNAMEMAX] = {0}; 1791741Srmesta 1801741Srmesta int dns_txt_cached = 0; 1811741Srmesta uint32_t dns_txt_domain_len = 0; 1821741Srmesta char dns_txt_domain[DNAMEMAX] = {0}; 1831741Srmesta char sysdns_domain[DNAMEMAX] = {0}; 1841741Srmesta 1851741Srmesta timestruc_t zapped_mtime = {0}; 1861741Srmesta 1871741Srmesta #define ZAP_DOMAIN(which) \ 1881741Srmesta { \ 1891741Srmesta bzero(which##_domain, DNAMEMAX);\ 1901741Srmesta which##_domain_len = 0; \ 1911741Srmesta which##_mtime = zapped_mtime; \ 1921741Srmesta } 1931741Srmesta 1941741Srmesta #define TIMESTRUC_EQ(a, b) \ 1951741Srmesta (((a).tv_sec == (b).tv_sec) && \ 1961741Srmesta ((a).tv_nsec == (b).tv_nsec)) 1971741Srmesta 1981741Srmesta 1991741Srmesta 2001741Srmesta #endif /* __LIBMAPID_IMPL */ 2011741Srmesta 2021741Srmesta /* 2031741Srmesta * PSARC 2005/487 Consolidation Private Interfaces 2041741Srmesta * mapid_reeval_domain(), mapid_get_domain() 2051741Srmesta * Changes must be reviewed by Solaris File Sharing 2061741Srmesta */ 2071741Srmesta extern void mapid_reeval_domain(cb_t *); 2081741Srmesta extern char *mapid_get_domain(void); 2091741Srmesta 2101741Srmesta /* 2111741Srmesta * PSARC 2005/487 Contracted Sun Private Interface 2121741Srmesta * mapid_derive_domain(), mapid_stdchk_domain() 2131741Srmesta * Changes must be reviewed by Solaris File Sharing 2141741Srmesta * Changes must be communicated to contract-2005-487-01@sun.com 2151741Srmesta */ 2161741Srmesta extern int mapid_stdchk_domain(const char *); 2171741Srmesta extern char *mapid_derive_domain(void); 2181741Srmesta 2191741Srmesta #ifdef __cplusplus 2201741Srmesta } 2211741Srmesta #endif 2221741Srmesta 2231741Srmesta #endif /* _MAPID_H */ 224