summaryrefslogtreecommitdiff
path: root/usr/src/lib/libresolv2_joy/common/sunw/sunw_mtctxres.c
blob: cc2a485ede8d6735e7b4ecbf17ca81d2192e3eda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#include <port_before.h>
#include <thread.h>
#include <errno.h>
#include <netdb.h>
#include <malloc.h>
#include <string.h>
#include <resolv_mt.h>
#include <irs.h>
#include <port_after.h>

#pragma redefine_extname __h_errno __joy_h_errno

/*
 * much of the original version of sunw_mtxtxres.c was incorporated into
 * ISC libbind as resolv/mtctxres.c. The following bits have not yet made
 * it into ISC libbind.
 */

/*
 * There used to be a private, MT-safe resolver interface that used TSD
 * to store per-thread _res, h_errno, etc. We continue to provide the
 * access functions __res_get_res() and __res_get_h_errno() so that binaries
 * that used the private interface will continue to work.
 */

#ifdef	_res
#undef	_res
#endif

extern struct __res_state	*__res_state(void);

struct __res_state *
__res_get_res(void) {
	return (__res_state());
}


#ifdef	h_errno
#undef	h_errno
#endif

extern int			*__h_errno(void);

int *
__res_get_h_errno(void) {
	return (__h_errno());
}


#ifdef SUNW_HOSTS_FALLBACK

/*
 * When the name service switch calls libresolv, it doesn't want fallback
 * to /etc/hosts, so we provide a method to turn it off.
 */

void
__joy_res_set_no_hosts_fallback(void) {
	___mtctxres()->no_hosts_fallback_private = 1;
}

void
__joy_res_unset_no_hosts_fallback(void) {
	___mtctxres()->no_hosts_fallback_private = 0;
}

int
__res_no_hosts_fallback(void) {
	return (___mtctxres()->no_hosts_fallback_private);
}

#endif  /* SUNW_HOSTS_FALLBACK */

#ifdef	SUNW_OVERRIDE_RETRY

/*
 * The NS switch wants to be able to override the number of retries.
 */

int
__joy_res_override_retry(int retry) {
	___mtctxres()->retry_private = retry;
	/*
	 * This function doesn't really need a return value; saving the
	 * old retry setting, and restoring it, is handled by __res_retry()
	 * and __res_retry_reset() below. However, the nss_dns library
	 * must have a private version of this function to be used when
	 * running with an old libresolv. That private nss_dns function
	 * needs a return value, and a function pointer is used to select
	 * the right function at runtime. Thus, __res_override_retry
	 * must have a function prototype consistent with the private
	 * nss_dns function, i.e., one that returns an int.
	 *
	 * Given that we do have a return value, that value must be zero.
	 * That's because retry_private == 0 is used to indicate that
	 * no override retry value is in effect, and the way we expect
	 * nss_dns to call us is:
	 *
	 *	int oldretry = __res_override_retry(N);
	 *	<whatever>
	 *	(void)__res_override_retry(old_retry);
	 */
	return (0);
}

int
__res_retry(int retry) {
	mtctxres_t	*mt = ___mtctxres();

	mt->retry_save = retry;
	return ((mt->retry_private != 0) ? mt->retry_private : retry);
}

int
__res_retry_reset(void) {
	mtctxres_t	*mt = ___mtctxres();

	return (mt->retry_save);
}

#endif	/* SUNW_OVERRIDE_RETRY */