1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20: #include <errno.h>
21: #include <bits/libc-lock.h>
22:
23: #include "nsswitch.h"
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: #define REENTRANT_GETNAME APPEND_R (GETFUNC_NAME)
52: #define APPEND_R(Name) CONCAT2_2 (Name, _r)
53: #define INTERNAL(Name) CONCAT2_2 (__, Name)
54: #define CONCAT2_1(Pre, Post) CONCAT2_2 (Pre, Post)
55: #define CONCAT2_2(Pre, Post) Pre##Post
56: #define NEW(name) NEW1 (name)
57: #define NEW1(name) __new_##name
58:
59: #define SETFUNC_NAME_STRING STRINGIZE (SETFUNC_NAME)
60: #define GETFUNC_NAME_STRING STRINGIZE (REENTRANT_GETNAME)
61: #define ENDFUNC_NAME_STRING STRINGIZE (ENDFUNC_NAME)
62: #define DATABASE_NAME_STRING STRINGIZE (DATABASE_NAME)
63: #define STRINGIZE(Name) STRINGIZE1 (Name)
64: #define STRINGIZE1(Name) #Name
65:
66: #ifndef DB_LOOKUP_FCT
67: # define DB_LOOKUP_FCT CONCAT3_1 (__nss_, DATABASE_NAME, _lookup)
68: # define CONCAT3_1(Pre, Name, Post) CONCAT3_2 (Pre, Name, Post)
69: # define CONCAT3_2(Pre, Name, Post) Pre##Name##Post
70: #endif
71:
72:
73: #ifdef NEED_H_ERRNO
74: # define H_ERRNO_PARM , int *h_errnop
75: # define H_ERRNO_VAR , &h_errno
76: # define H_ERRNO_VAR_P &h_errno
77: #else
78: # define H_ERRNO_PARM
79: # define H_ERRNO_VAR
80: # define H_ERRNO_VAR_P NULL
81: #endif
82:
83:
84: #ifdef STAYOPEN
85: # define STAYOPEN_TMP CONCAT2_1 (STAYOPEN, _tmp)
86: # define STAYOPEN_TMPVAR &CONCAT2_1 (STAYOPEN_VAR, _tmp)
87: #else
88: # define STAYOPEN void
89: # define STAYOPEN_VAR 0
90: # define STAYOPEN_TMPVAR NULL
91: #endif
92:
93: #ifndef NEED__RES
94: # define NEED__RES 0
95: #endif
96:
97:
98:
99: static service_user *nip;
100:
101: static service_user *last_nip;
102:
103: static service_user *startp;
104:
105: #ifdef STAYOPEN_TMP
106:
107:
108:
109: static STAYOPEN_TMP;
110: #endif
111:
112:
113: __libc_lock_define_initialized (static, lock)
114:
115:
116: extern int DB_LOOKUP_FCT (service_user **nip, const char *name, void **fctp)
117: internal_function;
118: libc_hidden_proto (DB_LOOKUP_FCT)
119: ^L
120: void
121: SETFUNC_NAME (STAYOPEN)
122: {
123: int save;
124:
125: __libc_lock_lock (lock);
126: __nss_setent (SETFUNC_NAME_STRING, DB_LOOKUP_FCT, &nip, &startp,
127: &last_nip, STAYOPEN_VAR, STAYOPEN_TMPVAR, NEED__RES);
128:
129: save = errno;
130: __libc_lock_unlock (lock);
131: __set_errno (save);
132: }
133:
134:
135: void
136: ENDFUNC_NAME (void)
137: {
138: int save;
139:
140:
141: if (startp != NULL)
142: {
143: __libc_lock_lock (lock);
144: __nss_endent (ENDFUNC_NAME_STRING, DB_LOOKUP_FCT, &nip, &startp,
145: &last_nip, NEED__RES);
146: save = errno;
147: __libc_lock_unlock (lock);
148: __set_errno (save);
149: }
150: }
151:
152:
153: int
154: INTERNAL (REENTRANT_GETNAME) (LOOKUP_TYPE *resbuf, char *buffer, size_t buflen,
155: LOOKUP_TYPE **result H_ERRNO_PARM)
156: {
157: int status;
158: int save;
159:
160: __libc_lock_lock (lock);
161: status = __nss_getent_r (GETFUNC_NAME_STRING, SETFUNC_NAME_STRING,
162: DB_LOOKUP_FCT, &nip, &startp, &last_nip,
163: STAYOPEN_TMPVAR, NEED__RES, resbuf, buffer,
164: buflen, (void **) result, H_ERRNO_VAR_P);
165: save = errno;
166: __libc_lock_unlock (lock);
167: __set_errno (save);
168: return status;
169: }
170:
171:
172: #include <shlib-compat.h>
173: #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1_2)
174: #define OLD(name) OLD1 (name)
175: #define OLD1(name) __old_##name
176:
177: int
178: attribute_compat_text_section
179: OLD (REENTRANT_GETNAME) (LOOKUP_TYPE *resbuf, char *buffer, size_t buflen,
180: LOOKUP_TYPE **result H_ERRNO_PARM)
181: {
182: int ret = INTERNAL (REENTRANT_GETNAME) (resbuf, buffer, buflen,
183: result H_ERRNO_VAR);
184:
185: if (ret != 0)
186: ret = -1;
187:
188: return ret;
189: }
190:
191: #define do_symbol_version(real, name, version) \
192: compat_symbol (libc, real, name, version)
193: do_symbol_version (OLD (REENTRANT_GETNAME), REENTRANT_GETNAME, GLIBC_2_0);
194: #endif
195:
196:
197:
198:
199: strong_alias (INTERNAL (REENTRANT_GETNAME), NEW (REENTRANT_GETNAME));
200:
201: #define do_default_symbol_version(real, name, version) \
202: versioned_symbol (libc, real, name, version)
203: do_default_symbol_version (NEW (REENTRANT_GETNAME),
204: REENTRANT_GETNAME, GLIBC_2_1_2);
205:
206: static_link_warning (SETFUNC_NAME)
207: static_link_warning (ENDFUNC_NAME)
208: static_link_warning (REENTRANT_GETNAME)