1 |
207 |
jeremybenn |
/* Copyright (C) 1996,97,98,99,2000,2002,2004 Free Software Foundation, Inc.
|
2 |
|
|
This file is part of the GNU C Library.
|
3 |
|
|
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
|
4 |
|
|
|
5 |
|
|
The GNU C Library is free software; you can redistribute it and/or
|
6 |
|
|
modify it under the terms of the GNU Lesser General Public
|
7 |
|
|
License as published by the Free Software Foundation; either
|
8 |
|
|
version 2.1 of the License, or (at your option) any later version.
|
9 |
|
|
|
10 |
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
11 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13 |
|
|
Lesser General Public License for more details.
|
14 |
|
|
|
15 |
|
|
You should have received a copy of the GNU Lesser General Public
|
16 |
|
|
License along with the GNU C Library; if not, write to the Free
|
17 |
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
18 |
|
|
02111-1307 USA. */
|
19 |
|
|
|
20 |
|
|
#include <errno.h>
|
21 |
|
|
#define _IO_MTSAFE_IO
|
22 |
|
|
#include <bits/libc-lock.h>
|
23 |
|
|
|
24 |
|
|
#include "nsswitch.h"
|
25 |
|
|
|
26 |
|
|
/*******************************************************************\
|
27 |
|
|
|* Here we assume several symbols to be defined: *|
|
28 |
|
|
|* *|
|
29 |
|
|
|* LOOKUP_TYPE - the return type of the function *|
|
30 |
|
|
|* *|
|
31 |
|
|
|* SETFUNC_NAME - name of the non-reentrant setXXXent function *|
|
32 |
|
|
|* *|
|
33 |
|
|
|* GETFUNC_NAME - name of the non-reentrant getXXXent function *|
|
34 |
|
|
|* *|
|
35 |
|
|
|* ENDFUNC_NAME - name of the non-reentrant endXXXent function *|
|
36 |
|
|
|* *|
|
37 |
|
|
|* DATABASE_NAME - name of the database the function accesses *|
|
38 |
|
|
|* (e.g., host, services, ...) *|
|
39 |
|
|
|* *|
|
40 |
|
|
|* Optionally the following vars can be defined: *|
|
41 |
|
|
|* *|
|
42 |
|
|
|* STAYOPEN - variable declaration for setXXXent function *|
|
43 |
|
|
|* *|
|
44 |
|
|
|* STAYOPEN_VAR - variable name for setXXXent function *|
|
45 |
|
|
|* *|
|
46 |
|
|
|* NEED_H_ERRNO - an extra parameter will be passed to point to *|
|
47 |
|
|
|* the global `h_errno' variable. *|
|
48 |
|
|
|* *|
|
49 |
|
|
\*******************************************************************/
|
50 |
|
|
|
51 |
|
|
/* To make the real sources a bit prettier. */
|
52 |
|
|
#define REENTRANT_GETNAME APPEND_R (GETFUNC_NAME)
|
53 |
|
|
#define APPEND_R(Name) CONCAT2_2 (Name, _r)
|
54 |
|
|
#define INTERNAL(Name) CONCAT2_2 (__, Name)
|
55 |
|
|
#define CONCAT2_1(Pre, Post) CONCAT2_2 (Pre, Post)
|
56 |
|
|
#define CONCAT2_2(Pre, Post) Pre##Post
|
57 |
|
|
#define NEW(name) NEW1 (name)
|
58 |
|
|
#define NEW1(name) __new_##name
|
59 |
|
|
|
60 |
|
|
#define SETFUNC_NAME_STRING STRINGIZE (SETFUNC_NAME)
|
61 |
|
|
#define GETFUNC_NAME_STRING STRINGIZE (REENTRANT_GETNAME)
|
62 |
|
|
#define ENDFUNC_NAME_STRING STRINGIZE (ENDFUNC_NAME)
|
63 |
|
|
#define DATABASE_NAME_STRING STRINGIZE (DATABASE_NAME)
|
64 |
|
|
#define STRINGIZE(Name) STRINGIZE1 (Name)
|
65 |
|
|
#define STRINGIZE1(Name) #Name
|
66 |
|
|
|
67 |
|
|
#ifndef DB_LOOKUP_FCT
|
68 |
|
|
# define DB_LOOKUP_FCT CONCAT3_1 (__nss_, DATABASE_NAME, _lookup)
|
69 |
|
|
# define CONCAT3_1(Pre, Name, Post) CONCAT3_2 (Pre, Name, Post)
|
70 |
|
|
# define CONCAT3_2(Pre, Name, Post) Pre##Name##Post
|
71 |
|
|
#endif
|
72 |
|
|
|
73 |
|
|
/* Sometimes we need to store error codes in the `h_errno' variable. */
|
74 |
|
|
#ifdef NEED_H_ERRNO
|
75 |
|
|
# define H_ERRNO_PARM , int *h_errnop
|
76 |
|
|
# define H_ERRNO_VAR , &h_errno
|
77 |
|
|
# define H_ERRNO_VAR_P &h_errno
|
78 |
|
|
#else
|
79 |
|
|
# define H_ERRNO_PARM
|
80 |
|
|
# define H_ERRNO_VAR
|
81 |
|
|
# define H_ERRNO_VAR_P NULL
|
82 |
|
|
#endif
|
83 |
|
|
|
84 |
|
|
/* Some databases take the `stayopen' flag. */
|
85 |
|
|
#ifdef STAYOPEN
|
86 |
|
|
# define STAYOPEN_TMP CONCAT2_1 (STAYOPEN, _tmp)
|
87 |
|
|
# define STAYOPEN_TMPVAR &CONCAT2_1 (STAYOPEN_VAR, _tmp)
|
88 |
|
|
#else
|
89 |
|
|
# define STAYOPEN void
|
90 |
|
|
# define STAYOPEN_VAR 0
|
91 |
|
|
# define STAYOPEN_TMPVAR NULL
|
92 |
|
|
#endif
|
93 |
|
|
|
94 |
|
|
#ifndef NEED__RES
|
95 |
|
|
# define NEED__RES 0
|
96 |
|
|
#endif
|
97 |
|
|
|
98 |
|
|
/* This handle for the NSS data base is shared between all
|
99 |
|
|
set/get/endXXXent functions. */
|
100 |
|
|
static service_user *nip;
|
101 |
|
|
/* Remember the last service used since the last call to `endXXent'. */
|
102 |
|
|
static service_user *last_nip;
|
103 |
|
|
/* Remember the first service_entry, it's always the same. */
|
104 |
|
|
static service_user *startp;
|
105 |
|
|
|
106 |
|
|
#ifdef STAYOPEN_TMP
|
107 |
|
|
/* We need to remember the last `stayopen' flag given by the user
|
108 |
|
|
since the `setent' function is only called for the first available
|
109 |
|
|
service. */
|
110 |
|
|
static STAYOPEN_TMP;
|
111 |
|
|
#endif
|
112 |
|
|
|
113 |
|
|
/* Protect above variable against multiple uses at the same time. */
|
114 |
|
|
__libc_lock_define_initialized (static, lock)
|
115 |
|
|
|
116 |
|
|
/* The lookup function for the first entry of this service. */
|
117 |
|
|
extern int DB_LOOKUP_FCT (service_user **nip, const char *name, void **fctp)
|
118 |
|
|
internal_function;
|
119 |
|
|
libc_hidden_proto (DB_LOOKUP_FCT)
|
120 |
|
|
|
121 |
|
|
void
|
122 |
|
|
SETFUNC_NAME (STAYOPEN)
|
123 |
|
|
{
|
124 |
|
|
int save;
|
125 |
|
|
|
126 |
|
|
__libc_lock_lock (lock);
|
127 |
|
|
__nss_setent (SETFUNC_NAME_STRING, DB_LOOKUP_FCT, &nip, &startp,
|
128 |
|
|
&last_nip, STAYOPEN_VAR, STAYOPEN_TMPVAR, NEED__RES);
|
129 |
|
|
|
130 |
|
|
save = errno;
|
131 |
|
|
__libc_lock_unlock (lock);
|
132 |
|
|
__set_errno (save);
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
|
136 |
|
|
void
|
137 |
|
|
ENDFUNC_NAME (void)
|
138 |
|
|
{
|
139 |
|
|
int save;
|
140 |
|
|
|
141 |
|
|
/* If the service has not been used before do not do anything. */
|
142 |
|
|
if (startp != NULL)
|
143 |
|
|
{
|
144 |
|
|
__libc_lock_lock (lock);
|
145 |
|
|
__nss_endent (ENDFUNC_NAME_STRING, DB_LOOKUP_FCT, &nip, &startp,
|
146 |
|
|
&last_nip, NEED__RES);
|
147 |
|
|
save = errno;
|
148 |
|
|
__libc_lock_unlock (lock);
|
149 |
|
|
__set_errno (save);
|
150 |
|
|
}
|
151 |
|
|
}
|
152 |
|
|
|
153 |
|
|
|
154 |
|
|
int
|
155 |
|
|
INTERNAL (REENTRANT_GETNAME) (LOOKUP_TYPE *resbuf, char *buffer, size_t buflen,
|
156 |
|
|
LOOKUP_TYPE **result H_ERRNO_PARM)
|
157 |
|
|
{
|
158 |
|
|
int status;
|
159 |
|
|
int save;
|
160 |
|
|
|
161 |
|
|
__libc_lock_lock (lock);
|
162 |
|
|
status = __nss_getent_r (GETFUNC_NAME_STRING, SETFUNC_NAME_STRING,
|
163 |
|
|
DB_LOOKUP_FCT, &nip, &startp, &last_nip,
|
164 |
|
|
STAYOPEN_TMPVAR, NEED__RES, resbuf, buffer,
|
165 |
|
|
buflen, (void **) result, H_ERRNO_VAR_P);
|
166 |
|
|
save = errno;
|
167 |
|
|
__libc_lock_unlock (lock);
|
168 |
|
|
__set_errno (save);
|
169 |
|
|
return status;
|
170 |
|
|
}
|
171 |
|
|
|
172 |
|
|
|
173 |
|
|
#include <shlib-compat.h>
|
174 |
|
|
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1_2)
|
175 |
|
|
#define OLD(name) OLD1 (name)
|
176 |
|
|
#define OLD1(name) __old_##name
|
177 |
|
|
|
178 |
|
|
int
|
179 |
|
|
attribute_compat_text_section
|
180 |
|
|
OLD (REENTRANT_GETNAME) (LOOKUP_TYPE *resbuf, char *buffer, size_t buflen,
|
181 |
|
|
LOOKUP_TYPE **result H_ERRNO_PARM)
|
182 |
|
|
{
|
183 |
|
|
int ret = INTERNAL (REENTRANT_GETNAME) (resbuf, buffer, buflen,
|
184 |
|
|
result H_ERRNO_VAR);
|
185 |
|
|
|
186 |
|
|
if (ret != 0)
|
187 |
|
|
ret = -1;
|
188 |
|
|
|
189 |
|
|
return ret;
|
190 |
|
|
}
|
191 |
|
|
|
192 |
|
|
#define do_symbol_version(real, name, version) \
|
193 |
|
|
compat_symbol (libc, real, name, version)
|
194 |
|
|
do_symbol_version (OLD (REENTRANT_GETNAME), REENTRANT_GETNAME, GLIBC_2_0);
|
195 |
|
|
#endif
|
196 |
|
|
|
197 |
|
|
/* As INTERNAL (REENTRANT_GETNAME) may be hidden, we need an alias
|
198 |
|
|
in between so that the REENTRANT_GETNAME@@GLIBC_2.1.2 is not
|
199 |
|
|
hidden too. */
|
200 |
|
|
strong_alias (INTERNAL (REENTRANT_GETNAME), NEW (REENTRANT_GETNAME));
|
201 |
|
|
|
202 |
|
|
#define do_default_symbol_version(real, name, version) \
|
203 |
|
|
versioned_symbol (libc, real, name, version)
|
204 |
|
|
do_default_symbol_version (NEW (REENTRANT_GETNAME),
|
205 |
|
|
REENTRANT_GETNAME, GLIBC_2_1_2);
|
206 |
|
|
|
207 |
|
|
static_link_warning (SETFUNC_NAME)
|
208 |
|
|
static_link_warning (ENDFUNC_NAME)
|
209 |
|
|
static_link_warning (REENTRANT_GETNAME)
|