18200fe25Srmesta /* 28200fe25Srmesta * CDDL HEADER START 38200fe25Srmesta * 48200fe25Srmesta * The contents of this file are subject to the terms of the 58200fe25Srmesta * Common Development and Distribution License (the "License"). 68200fe25Srmesta * You may not use this file except in compliance with the License. 78200fe25Srmesta * 88200fe25Srmesta * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 98200fe25Srmesta * or http://www.opensolaris.org/os/licensing. 108200fe25Srmesta * See the License for the specific language governing permissions 118200fe25Srmesta * and limitations under the License. 128200fe25Srmesta * 138200fe25Srmesta * When distributing Covered Code, include this CDDL HEADER in each 148200fe25Srmesta * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 158200fe25Srmesta * If applicable, add the following below this CDDL HEADER, with the 168200fe25Srmesta * fields enclosed by brackets "[]" replaced with your own identifying 178200fe25Srmesta * information: Portions Copyright [yyyy] [name of copyright owner] 188200fe25Srmesta * 198200fe25Srmesta * CDDL HEADER END 208200fe25Srmesta */ 218200fe25Srmesta /* 22*dd51520eSPavan Mettu - Oracle Corporation - Menlo Park United States * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 238200fe25Srmesta */ 248200fe25Srmesta 258200fe25Srmesta #ifndef _MAPID_H 268200fe25Srmesta #define _MAPID_H 278200fe25Srmesta 288200fe25Srmesta #ifdef __cplusplus 298200fe25Srmesta extern "C" { 308200fe25Srmesta #endif 318200fe25Srmesta 328200fe25Srmesta #include <stdio.h> 338200fe25Srmesta #include <stdlib.h> 348200fe25Srmesta #include <unistd.h> 358200fe25Srmesta #include <string.h> 368200fe25Srmesta #include <strings.h> 378200fe25Srmesta #include <sys/types.h> 388200fe25Srmesta #include <sys/stat.h> 398200fe25Srmesta #include <rpc/types.h> 408200fe25Srmesta #include <netinet/in.h> 418200fe25Srmesta #include <arpa/nameser.h> 428200fe25Srmesta #include <resolv.h> 438200fe25Srmesta #include <netdb.h> 448200fe25Srmesta #include <errno.h> 458200fe25Srmesta #include <ctype.h> 468200fe25Srmesta #include <sys/socket.h> 478200fe25Srmesta #include <arpa/inet.h> 488200fe25Srmesta #include <assert.h> 498200fe25Srmesta #include <synch.h> 508200fe25Srmesta #include <syslog.h> 518200fe25Srmesta #include <locale.h> 528200fe25Srmesta #include <thread.h> 538200fe25Srmesta #include <deflt.h> 548200fe25Srmesta #include <nfs/nfs4.h> 558200fe25Srmesta 568200fe25Srmesta #define DNAMEMAX (NS_MAXCDNAME + 1) 578200fe25Srmesta 588200fe25Srmesta typedef struct { 598200fe25Srmesta void *(*fcn)(void *); 608200fe25Srmesta int signal; 618200fe25Srmesta } cb_t; 628200fe25Srmesta 638200fe25Srmesta #ifdef __LIBMAPID_IMPL 648200fe25Srmesta 658200fe25Srmesta /* 668200fe25Srmesta * Error Messages 678200fe25Srmesta */ 688200fe25Srmesta #define EMSG_NETDB_INTERNAL "Internal Resolver Error: %s" 698200fe25Srmesta 708200fe25Srmesta #define EMSG_TRY_AGAIN "\"%s\" DNS nameserver(s) not responding" \ 718200fe25Srmesta "...\tRetrying" 728200fe25Srmesta 738200fe25Srmesta #define EMSG_NO_RECOVERY "Unrecoverable Resolver Error: %s" 748200fe25Srmesta 758200fe25Srmesta #define EMSG_HOST_NOT_FOUND "Authoritative nameserver unresponsive " \ 768200fe25Srmesta "to queries for domain \"%s\"" 778200fe25Srmesta 788200fe25Srmesta #define EMSG_NO_DATA "\"%s\" DNS TXT record not found: "\ 798200fe25Srmesta "Defaulting to \"%s\"" 808200fe25Srmesta 818200fe25Srmesta #define EMSG_DNS_THREAD_ERROR "Unable to create DNS query thread" 828200fe25Srmesta 838200fe25Srmesta #define EMSG_DNS_DISABLE "%s: Further DNS queries disabled !" 848200fe25Srmesta 858200fe25Srmesta #define EMSG_DNS_RR_INVAL "\"%s\" Invalid DNS TXT record: "\ 868200fe25Srmesta "Defaulting to \"%s\"" 878200fe25Srmesta 888200fe25Srmesta /* 898200fe25Srmesta * DNS related info 908200fe25Srmesta */ 918200fe25Srmesta #define NFSMAPID_DNS_RR "_nfsv4idmapdomain" 928200fe25Srmesta #define NFSMAPID_DNS_TOUT_SECS (30LL) 938200fe25Srmesta #define NFSMAPID_SLOG_RATE 20 /* ~10 mins */ 948200fe25Srmesta 958200fe25Srmesta #define NS_ERRS 6 /* netdb.h */ 968200fe25Srmesta 978200fe25Srmesta typedef union { 988200fe25Srmesta HEADER hdr; 998200fe25Srmesta uchar_t buf[PACKETSZ]; 1008200fe25Srmesta } ans_t; 1018200fe25Srmesta 1028200fe25Srmesta /* 1038200fe25Srmesta * NOTE: All s_ prefixed variables are only to be used by the DNS 1048200fe25Srmesta * feature implementation (mapid.c). The exported globals 1058200fe25Srmesta * (ie. seen by nfsmapid.c/nfsmapid_server.c) are the 1068200fe25Srmesta * dns_ prefixed variables along with sysdns_domain. 1078200fe25Srmesta */ 1088200fe25Srmesta static ans_t s_ans; 1098200fe25Srmesta static int s_anslen; 1108200fe25Srmesta static char s_dname[DNAMEMAX] = {0}; 1118200fe25Srmesta static char s_txt_rr[DNAMEMAX] = {0}; 1128200fe25Srmesta 1138200fe25Srmesta static rwlock_t s_dns_data_lock = DEFAULTRWLOCK; 1148200fe25Srmesta static rwlock_t s_dns_impl_lock = DEFAULTRWLOCK; 1158200fe25Srmesta static mutex_t s_res_lock = ERRORCHECKMUTEX; 1168200fe25Srmesta static uint32_t s_dns_tout = 0; 1178200fe25Srmesta static thread_t s_dns_qthread; 1188200fe25Srmesta static bool_t s_dns_qthr_created = FALSE; 1198200fe25Srmesta static bool_t s_dns_disabled = FALSE; 1208200fe25Srmesta static struct __res_state s_res = {0}; 1218200fe25Srmesta static thread_key_t s_thr_key; 1228200fe25Srmesta int lib_init_done = 0; 1238200fe25Srmesta 1248200fe25Srmesta static int resolv_init(void); 1258200fe25Srmesta static void resolv_decode(void); 1268200fe25Srmesta static int resolv_error(void); 1278200fe25Srmesta static void resolv_get_txt_data(void); 1288200fe25Srmesta static void resolv_txt_reset(void); 1298200fe25Srmesta static void resolve_process_txt(uchar_t *, int); 1308200fe25Srmesta static int resolv_search(void); 131bfa62c28SVallish Vaidyeshwara static void resolv_destroy(void); 1328200fe25Srmesta static uchar_t *resolv_skip_rr(uchar_t *, uchar_t *); 1338200fe25Srmesta static void domain_sync(cb_t *, char *); 1348200fe25Srmesta static int get_mtime(const char *, timestruc_t *); 1358200fe25Srmesta static void get_nfs_domain(void); 1368200fe25Srmesta static void get_dns_domain(void); 1378200fe25Srmesta static void get_dns_txt_domain(cb_t *); 1388200fe25Srmesta void _lib_init(void); 1398200fe25Srmesta 1408200fe25Srmesta #ifdef DEBUG 1418200fe25Srmesta bool_t nfsmapid_debug = FALSE; 1428200fe25Srmesta #endif /* DEBUG */ 1438200fe25Srmesta 1448200fe25Srmesta /* 1458200fe25Srmesta * mapid_domain_lock: rwlock used to serialize access/changes 1468200fe25Srmesta * to the library's mapid_domain global var. 1478200fe25Srmesta * 1488200fe25Srmesta * mapid_domain: Library variable used to store the current 1498200fe25Srmesta * domain configured for use in decoding/encoding 1508200fe25Srmesta * outbound and inbound attr strings, accordingly. 1518200fe25Srmesta * 152*dd51520eSPavan Mettu - Oracle Corporation - Menlo Park United States * nfs_domain: If nfsmapid_domain var in SMF 1538200fe25Srmesta * has been set, nfs_domain will hold this 1548200fe25Srmesta * value for the duration of the instance; 1558200fe25Srmesta * If the value ever changes, the change is 1568200fe25Srmesta * detected via the use of nfs_mtime and 1578200fe25Srmesta * nfs_domain is updated accordingly. 1588200fe25Srmesta * 1598200fe25Srmesta * dns_domain: If the system's resolver (/etc/resolv.conf) 1608200fe25Srmesta * has been configured, dns_domain will hold 1618200fe25Srmesta * the configured DNS domain as reported by the 1628200fe25Srmesta * res_ninit() resolver interface. If the system's 1638200fe25Srmesta * /etc/resolv.conf file is updated, the change 1648200fe25Srmesta * is detected via the use of dns_mtime and 1658200fe25Srmesta * dns_domain is updated accordingly. 1668200fe25Srmesta */ 1678200fe25Srmesta rwlock_t mapid_domain_lock = DEFAULTRWLOCK; 1688200fe25Srmesta uint32_t mapid_domain_len = 0; 1698200fe25Srmesta char mapid_domain[DNAMEMAX] = {0}; 1708200fe25Srmesta 1718200fe25Srmesta timestruc_t nfs_mtime = {0}; 1728200fe25Srmesta uint32_t nfs_domain_len = 0; 1738200fe25Srmesta char nfs_domain[DNAMEMAX] = {0}; 1748200fe25Srmesta 1758200fe25Srmesta timestruc_t dns_mtime = {0}; 1768200fe25Srmesta uint32_t dns_domain_len = 0; 1778200fe25Srmesta char dns_domain[DNAMEMAX] = {0}; 1788200fe25Srmesta 1798200fe25Srmesta int dns_txt_cached = 0; 1808200fe25Srmesta uint32_t dns_txt_domain_len = 0; 1818200fe25Srmesta char dns_txt_domain[DNAMEMAX] = {0}; 1828200fe25Srmesta char sysdns_domain[DNAMEMAX] = {0}; 1838200fe25Srmesta 1848200fe25Srmesta timestruc_t zapped_mtime = {0}; 1858200fe25Srmesta 1868200fe25Srmesta #define ZAP_DOMAIN(which) \ 1878200fe25Srmesta { \ 1888200fe25Srmesta bzero(which##_domain, DNAMEMAX);\ 1898200fe25Srmesta which##_domain_len = 0; \ 1908200fe25Srmesta which##_mtime = zapped_mtime; \ 1918200fe25Srmesta } 1928200fe25Srmesta 1938200fe25Srmesta #define TIMESTRUC_EQ(a, b) \ 1948200fe25Srmesta (((a).tv_sec == (b).tv_sec) && \ 1958200fe25Srmesta ((a).tv_nsec == (b).tv_nsec)) 1968200fe25Srmesta 1978200fe25Srmesta 1988200fe25Srmesta 1998200fe25Srmesta #endif /* __LIBMAPID_IMPL */ 2008200fe25Srmesta 2018200fe25Srmesta /* 2028200fe25Srmesta * PSARC 2005/487 Consolidation Private Interfaces 2038200fe25Srmesta * mapid_reeval_domain(), mapid_get_domain() 2048200fe25Srmesta * Changes must be reviewed by Solaris File Sharing 2058200fe25Srmesta */ 2068200fe25Srmesta extern void mapid_reeval_domain(cb_t *); 2078200fe25Srmesta extern char *mapid_get_domain(void); 2088200fe25Srmesta 2098200fe25Srmesta /* 2108200fe25Srmesta * PSARC 2005/487 Contracted Sun Private Interface 2118200fe25Srmesta * mapid_derive_domain(), mapid_stdchk_domain() 2128200fe25Srmesta * Changes must be reviewed by Solaris File Sharing 2138200fe25Srmesta * Changes must be communicated to contract-2005-487-01@sun.com 2148200fe25Srmesta */ 2158200fe25Srmesta extern int mapid_stdchk_domain(const char *); 2168200fe25Srmesta extern char *mapid_derive_domain(void); 2178200fe25Srmesta 2188200fe25Srmesta #ifdef __cplusplus 2198200fe25Srmesta } 2208200fe25Srmesta #endif 2218200fe25Srmesta 2228200fe25Srmesta #endif /* _MAPID_H */ 223