4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
37 #include <sys/types.h>
39 #include <rpc/types.h>
40 #include <netinet/in.h>
41 #include <arpa/nameser.h>
46 #include <sys/socket.h>
47 #include <arpa/inet.h>
56 #define DNAMEMAX (NS_MAXCDNAME + 1)
63 #ifdef __LIBMAPID_IMPL
68 #define EMSG_NETDB_INTERNAL "Internal Resolver Error: %s"
70 #define EMSG_TRY_AGAIN "\"%s\" DNS nameserver(s) not responding" \
73 #define EMSG_NO_RECOVERY "Unrecoverable Resolver Error: %s"
75 #define EMSG_HOST_NOT_FOUND "Authoritative nameserver unresponsive " \
76 "to queries for domain \"%s\""
78 #define EMSG_NO_DATA "\"%s\" DNS TXT record not found: "\
79 "Defaulting to \"%s\""
81 #define EMSG_DNS_THREAD_ERROR "Unable to create DNS query thread"
83 #define EMSG_DNS_DISABLE "%s: Further DNS queries disabled !"
85 #define EMSG_DNS_RR_INVAL "\"%s\" Invalid DNS TXT record: "\
86 "Defaulting to \"%s\""
91 #define NFSMAPID_DNS_RR "_nfsv4idmapdomain"
92 #define NFSMAPID_DNS_TOUT_SECS (30LL)
93 #define NFSMAPID_SLOG_RATE 20 /* ~10 mins */
95 #define NS_ERRS 6 /* netdb.h */
99 uchar_t buf
[PACKETSZ
];
103 * NOTE: All s_ prefixed variables are only to be used by the DNS
104 * feature implementation (mapid.c). The exported globals
105 * (ie. seen by nfsmapid.c/nfsmapid_server.c) are the
106 * dns_ prefixed variables along with sysdns_domain.
110 static char s_dname
[DNAMEMAX
] = {0};
111 static char s_txt_rr
[DNAMEMAX
] = {0};
113 static rwlock_t s_dns_data_lock
= DEFAULTRWLOCK
;
114 static rwlock_t s_dns_impl_lock
= DEFAULTRWLOCK
;
115 static mutex_t s_res_lock
= ERRORCHECKMUTEX
;
116 static uint32_t s_dns_tout
= 0;
117 static thread_t s_dns_qthread
;
118 static bool_t s_dns_qthr_created
= FALSE
;
119 static bool_t s_dns_disabled
= FALSE
;
120 static struct __res_state s_res
= {0};
121 static thread_key_t s_thr_key
;
122 int lib_init_done
= 0;
124 static int resolv_init(void);
125 static void resolv_decode(void);
126 static int resolv_error(void);
127 static void resolv_get_txt_data(void);
128 static void resolv_txt_reset(void);
129 static void resolve_process_txt(uchar_t
*, int);
130 static int resolv_search(void);
131 static void resolv_destroy(void);
132 static uchar_t
*resolv_skip_rr(uchar_t
*, uchar_t
*);
133 static void domain_sync(cb_t
*, char *);
134 static int get_mtime(const char *, timestruc_t
*);
135 static void get_nfs_domain(void);
136 static void get_dns_domain(void);
137 static void get_dns_txt_domain(cb_t
*);
138 void _lib_init(void);
141 bool_t nfsmapid_debug
= FALSE
;
145 * mapid_domain_lock: rwlock used to serialize access/changes
146 * to the library's mapid_domain global var.
148 * mapid_domain: Library variable used to store the current
149 * domain configured for use in decoding/encoding
150 * outbound and inbound attr strings, accordingly.
152 * nfs_domain: If nfsmapid_domain var in SMF
153 * has been set, nfs_domain will hold this
154 * value for the duration of the instance;
155 * If the value ever changes, the change is
156 * detected via the use of nfs_mtime and
157 * nfs_domain is updated accordingly.
159 * dns_domain: If the system's resolver (/etc/resolv.conf)
160 * has been configured, dns_domain will hold
161 * the configured DNS domain as reported by the
162 * res_ninit() resolver interface. If the system's
163 * /etc/resolv.conf file is updated, the change
164 * is detected via the use of dns_mtime and
165 * dns_domain is updated accordingly.
167 rwlock_t mapid_domain_lock
= DEFAULTRWLOCK
;
168 uint32_t mapid_domain_len
= 0;
169 char mapid_domain
[DNAMEMAX
] = {0};
171 timestruc_t nfs_mtime
= {0};
172 uint32_t nfs_domain_len
= 0;
173 char nfs_domain
[DNAMEMAX
] = {0};
175 timestruc_t dns_mtime
= {0};
176 uint32_t dns_domain_len
= 0;
177 char dns_domain
[DNAMEMAX
] = {0};
179 int dns_txt_cached
= 0;
180 uint32_t dns_txt_domain_len
= 0;
181 char dns_txt_domain
[DNAMEMAX
] = {0};
182 char sysdns_domain
[DNAMEMAX
] = {0};
184 timestruc_t zapped_mtime
= {0};
186 #define ZAP_DOMAIN(which) \
188 bzero(which##_domain, DNAMEMAX);\
189 which##_domain_len = 0; \
190 which##_mtime = zapped_mtime; \
193 #define TIMESTRUC_EQ(a, b) \
194 (((a).tv_sec == (b).tv_sec) && \
195 ((a).tv_nsec == (b).tv_nsec))
199 #endif /* __LIBMAPID_IMPL */
202 * PSARC 2005/487 Consolidation Private Interfaces
203 * mapid_reeval_domain(), mapid_get_domain()
204 * Changes must be reviewed by Solaris File Sharing
206 extern void mapid_reeval_domain(cb_t
*);
207 extern char *mapid_get_domain(void);
210 * PSARC 2005/487 Contracted Sun Private Interface
211 * mapid_derive_domain(), mapid_stdchk_domain()
212 * Changes must be reviewed by Solaris File Sharing
213 * Changes must be communicated to contract-2005-487-01@sun.com
215 extern int mapid_stdchk_domain(const char *);
216 extern char *mapid_derive_domain(void);
222 #endif /* _MAPID_H */