2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#ifndef _MAPID_H
2N/A#define _MAPID_H
2N/A
2N/A#ifdef __cplusplus
2N/Aextern "C" {
2N/A#endif
2N/A
2N/A#include <stdio.h>
2N/A#include <stdlib.h>
2N/A#include <unistd.h>
2N/A#include <string.h>
2N/A#include <strings.h>
2N/A#include <sys/types.h>
2N/A#include <sys/stat.h>
2N/A#include <rpc/types.h>
2N/A#include <netinet/in.h>
2N/A#include <arpa/nameser.h>
2N/A#include <resolv.h>
2N/A#include <netdb.h>
2N/A#include <errno.h>
2N/A#include <ctype.h>
2N/A#include <sys/socket.h>
2N/A#include <arpa/inet.h>
2N/A#include <assert.h>
2N/A#include <synch.h>
2N/A#include <syslog.h>
2N/A#include <locale.h>
2N/A#include <thread.h>
2N/A#include <deflt.h>
2N/A#include <nfs/nfs4.h>
2N/A
2N/A#define DNAMEMAX (NS_MAXCDNAME + 1)
2N/A
2N/Atypedef struct {
2N/A void *(*fcn)(void *);
2N/A int signal;
2N/A} cb_t;
2N/A
2N/A#ifdef __LIBMAPID_IMPL
2N/A
2N/A/*
2N/A * Error Messages
2N/A */
2N/A#define EMSG_NETDB_INTERNAL "Internal Resolver Error: %s"
2N/A
2N/A#define EMSG_TRY_AGAIN "\"%s\" DNS nameserver(s) not responding" \
2N/A "...\tRetrying"
2N/A
2N/A#define EMSG_NO_RECOVERY "Unrecoverable Resolver Error: %s"
2N/A
2N/A#define EMSG_HOST_NOT_FOUND "Authoritative nameserver unresponsive " \
2N/A "to queries for domain \"%s\""
2N/A
2N/A#define EMSG_NO_DATA "\"%s\" DNS TXT record not found: "\
2N/A "Defaulting to \"%s\""
2N/A
2N/A#define EMSG_DNS_THREAD_ERROR "Unable to create DNS query thread"
2N/A
2N/A#define EMSG_DNS_DISABLE "%s: Further DNS queries disabled !"
2N/A
2N/A#define EMSG_DNS_RR_INVAL "\"%s\" Invalid DNS TXT record: "\
2N/A "Defaulting to \"%s\""
2N/A
2N/A/*
2N/A * DNS related info
2N/A */
2N/A#define NFSMAPID_DNS_RR "_nfsv4idmapdomain"
2N/A#define NFSMAPID_DNS_TOUT_SECS (30LL)
2N/A#define NFSMAPID_SLOG_RATE 20 /* ~10 mins */
2N/A
2N/A#define NS_ERRS 6 /* netdb.h */
2N/A
2N/Atypedef union {
2N/A HEADER hdr;
2N/A uchar_t buf[PACKETSZ];
2N/A} ans_t;
2N/A
2N/A/*
2N/A * NOTE: All s_ prefixed variables are only to be used by the DNS
2N/A * feature implementation (mapid.c). The exported globals
2N/A * (ie. seen by nfsmapid.c/nfsmapid_server.c) are the
2N/A * dns_ prefixed variables along with sysdns_domain.
2N/A */
2N/Astatic ans_t s_ans;
2N/Astatic int s_anslen;
2N/Astatic char s_dname[DNAMEMAX] = {0};
2N/Astatic char s_txt_rr[DNAMEMAX] = {0};
2N/A
2N/Astatic rwlock_t s_dns_data_lock = DEFAULTRWLOCK;
2N/Astatic rwlock_t s_dns_impl_lock = DEFAULTRWLOCK;
2N/Astatic mutex_t s_res_lock = ERRORCHECKMUTEX;
2N/Astatic uint32_t s_dns_tout = 0;
2N/Astatic thread_t s_dns_qthread;
2N/Astatic bool_t s_dns_qthr_created = FALSE;
2N/Astatic bool_t s_dns_disabled = FALSE;
2N/Astatic struct __res_state s_res = {0};
2N/Astatic thread_key_t s_thr_key;
2N/Aint lib_init_done = 0;
2N/A
2N/Astatic int resolv_init(void);
2N/Astatic void resolv_decode(void);
2N/Astatic int resolv_error(void);
2N/Astatic void resolv_get_txt_data(void);
2N/Astatic void resolv_txt_reset(void);
2N/Astatic void resolve_process_txt(uchar_t *, int);
2N/Astatic int resolv_search(void);
2N/Astatic void resolv_destroy(void);
2N/Astatic uchar_t *resolv_skip_rr(uchar_t *, uchar_t *);
2N/Astatic void domain_sync(cb_t *, char *);
2N/Astatic int get_mtime(const char *, timestruc_t *);
2N/Astatic void get_nfs_domain(void);
2N/Astatic void get_dns_domain(void);
2N/Astatic void get_dns_txt_domain(cb_t *);
2N/Avoid _lib_init(void);
2N/A
2N/A#ifdef DEBUG
2N/Abool_t nfsmapid_debug = FALSE;
2N/A#endif /* DEBUG */
2N/A
2N/A/*
2N/A * mapid_domain_lock: rwlock used to serialize access/changes
2N/A * to the library's mapid_domain global var.
2N/A *
2N/A * mapid_domain: Library variable used to store the current
2N/A * domain configured for use in decoding/encoding
2N/A * outbound and inbound attr strings, accordingly.
2N/A *
2N/A * nfs_domain: If nfsmapid_domain var in SMF
2N/A * has been set, nfs_domain will hold this
2N/A * value for the duration of the instance;
2N/A * If the value ever changes, the change is
2N/A * detected via the use of nfs_mtime and
2N/A * nfs_domain is updated accordingly.
2N/A *
2N/A * dns_domain: If the system's resolver (/etc/resolv.conf)
2N/A * has been configured, dns_domain will hold
2N/A * the configured DNS domain as reported by the
2N/A * res_ninit() resolver interface. If the system's
2N/A * /etc/resolv.conf file is updated, the change
2N/A * is detected via the use of dns_mtime and
2N/A * dns_domain is updated accordingly.
2N/A */
2N/Arwlock_t mapid_domain_lock = DEFAULTRWLOCK;
2N/Auint32_t mapid_domain_len = 0;
2N/Achar mapid_domain[DNAMEMAX] = {0};
2N/A
2N/Atimestruc_t nfs_mtime = {0};
2N/Auint32_t nfs_domain_len = 0;
2N/Achar nfs_domain[DNAMEMAX] = {0};
2N/A
2N/Atimestruc_t dns_mtime = {0};
2N/Auint32_t dns_domain_len = 0;
2N/Achar dns_domain[DNAMEMAX] = {0};
2N/A
2N/Aint dns_txt_cached = 0;
2N/Auint32_t dns_txt_domain_len = 0;
2N/Achar dns_txt_domain[DNAMEMAX] = {0};
2N/Achar sysdns_domain[DNAMEMAX] = {0};
2N/A
2N/Atimestruc_t zapped_mtime = {0};
2N/A
2N/A#define ZAP_DOMAIN(which) \
2N/A { \
2N/A bzero(which##_domain, DNAMEMAX);\
2N/A which##_domain_len = 0; \
2N/A which##_mtime = zapped_mtime; \
2N/A }
2N/A
2N/A#define TIMESTRUC_EQ(a, b) \
2N/A (((a).tv_sec == (b).tv_sec) && \
2N/A ((a).tv_nsec == (b).tv_nsec))
2N/A
2N/A
2N/A
2N/A#endif /* __LIBMAPID_IMPL */
2N/A
2N/A/*
2N/A * PSARC 2005/487 Consolidation Private Interfaces
2N/A * mapid_reeval_domain(), mapid_get_domain()
2N/A * Changes must be reviewed by Solaris File Sharing
2N/A */
2N/Aextern void mapid_reeval_domain(cb_t *);
2N/Aextern char *mapid_get_domain(void);
2N/A
2N/A/*
2N/A * PSARC 2005/487 Contracted Sun Private Interface
2N/A * mapid_derive_domain(), mapid_stdchk_domain()
2N/A * Changes must be reviewed by Solaris File Sharing
2N/A * Changes must be communicated to contract-2005-487-01@sun.com
2N/A */
2N/Aextern int mapid_stdchk_domain(const char *);
2N/Aextern char *mapid_derive_domain(void);
2N/A
2N/A#ifdef __cplusplus
2N/A}
2N/A#endif
2N/A
2N/A#endif /* _MAPID_H */