]> git.ipfire.org Git - thirdparty/glibc.git/blame - nss/getXXent_r.c
[powerpc] No need to enter "Ignore Exceptions Mode"
[thirdparty/glibc.git] / nss / getXXent_r.c
CommitLineData
04277e02 1/* Copyright (C) 1996-2019 Free Software Foundation, Inc.
2303f5fd
UD
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
5f0e6fc7 4
2303f5fd 5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
5f0e6fc7 9
2303f5fd
UD
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
41bdb6e2 13 Lesser General Public License for more details.
5f0e6fc7 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
5f0e6fc7 18
d71b808a 19#include <errno.h>
ec999b8e 20#include <libc-lock.h>
5f0e6fc7
RM
21
22#include "nsswitch.h"
23
24/*******************************************************************\
25|* Here we assume several symbols to be defined: *|
26|* *|
27|* LOOKUP_TYPE - the return type of the function *|
28|* *|
29|* SETFUNC_NAME - name of the non-reentrant setXXXent function *|
30|* *|
31|* GETFUNC_NAME - name of the non-reentrant getXXXent function *|
32|* *|
33|* ENDFUNC_NAME - name of the non-reentrant endXXXent function *|
34|* *|
35|* DATABASE_NAME - name of the database the function accesses *|
36|* (e.g., host, services, ...) *|
37|* *|
38|* Optionally the following vars can be defined: *|
39|* *|
40|* STAYOPEN - variable declaration for setXXXent function *|
41|* *|
42|* STAYOPEN_VAR - variable name for setXXXent function *|
43|* *|
44|* NEED_H_ERRNO - an extra parameter will be passed to point to *|
45|* the global `h_errno' variable. *|
46|* *|
47\*******************************************************************/
48
49/* To make the real sources a bit prettier. */
50#define REENTRANT_GETNAME APPEND_R (GETFUNC_NAME)
2303f5fd
UD
51#define APPEND_R(Name) CONCAT2_2 (Name, _r)
52#define INTERNAL(Name) CONCAT2_2 (__, Name)
53#define CONCAT2_1(Pre, Post) CONCAT2_2 (Pre, Post)
54#define CONCAT2_2(Pre, Post) Pre##Post
bff334e0
UD
55#define NEW(name) NEW1 (name)
56#define NEW1(name) __new_##name
5f0e6fc7
RM
57
58#define SETFUNC_NAME_STRING STRINGIZE (SETFUNC_NAME)
ddc6fb0c 59#define GETFUNC_NAME_STRING STRINGIZE (REENTRANT_GETNAME)
5f0e6fc7
RM
60#define ENDFUNC_NAME_STRING STRINGIZE (ENDFUNC_NAME)
61#define DATABASE_NAME_STRING STRINGIZE (DATABASE_NAME)
2303f5fd
UD
62#define STRINGIZE(Name) STRINGIZE1 (Name)
63#define STRINGIZE1(Name) #Name
5f0e6fc7 64
77fe0b9c 65#ifndef DB_LOOKUP_FCT
384ca551 66# define DB_LOOKUP_FCT CONCAT3_1 (__nss_, DATABASE_NAME, _lookup2)
77fe0b9c
UD
67# define CONCAT3_1(Pre, Name, Post) CONCAT3_2 (Pre, Name, Post)
68# define CONCAT3_2(Pre, Name, Post) Pre##Name##Post
69#endif
5f0e6fc7
RM
70
71/* Sometimes we need to store error codes in the `h_errno' variable. */
72#ifdef NEED_H_ERRNO
73# define H_ERRNO_PARM , int *h_errnop
74# define H_ERRNO_VAR , &h_errno
8b801829 75# define H_ERRNO_VAR_P &h_errno
5f0e6fc7
RM
76#else
77# define H_ERRNO_PARM
78# define H_ERRNO_VAR
8b801829 79# define H_ERRNO_VAR_P NULL
5f0e6fc7
RM
80#endif
81
82/* Some databases take the `stayopen' flag. */
2303f5fd
UD
83#ifdef STAYOPEN
84# define STAYOPEN_TMP CONCAT2_1 (STAYOPEN, _tmp)
8b801829 85# define STAYOPEN_TMPVAR &CONCAT2_1 (STAYOPEN_VAR, _tmp)
2303f5fd
UD
86#else
87# define STAYOPEN void
8b801829
UD
88# define STAYOPEN_VAR 0
89# define STAYOPEN_TMPVAR NULL
5f0e6fc7
RM
90#endif
91
8b801829
UD
92#ifndef NEED__RES
93# define NEED__RES 0
94#endif
5f0e6fc7
RM
95
96/* This handle for the NSS data base is shared between all
97 set/get/endXXXent functions. */
98static service_user *nip;
d4a089cf
UD
99/* Remember the last service used since the last call to `endXXent'. */
100static service_user *last_nip;
5f0e6fc7
RM
101/* Remember the first service_entry, it's always the same. */
102static service_user *startp;
103
2303f5fd
UD
104#ifdef STAYOPEN_TMP
105/* We need to remember the last `stayopen' flag given by the user
106 since the `setent' function is only called for the first available
107 service. */
108static STAYOPEN_TMP;
109#endif
110
5f0e6fc7 111/* Protect above variable against multiple uses at the same time. */
1e16111c 112__libc_lock_define_initialized (static, lock)
5f0e6fc7
RM
113
114/* The lookup function for the first entry of this service. */
384ca551 115extern int DB_LOOKUP_FCT (service_user **nip, const char *name,
b2297409 116 const char *name2, void **fctp);
37ba7d66 117libc_hidden_proto (DB_LOOKUP_FCT)
3dbe1581 118\f
5f0e6fc7 119void
6dbe2837 120SETFUNC_NAME (STAYOPEN)
5f0e6fc7 121{
8b801829 122 int save;
5f0e6fc7
RM
123
124 __libc_lock_lock (lock);
8b801829
UD
125 __nss_setent (SETFUNC_NAME_STRING, DB_LOOKUP_FCT, &nip, &startp,
126 &last_nip, STAYOPEN_VAR, STAYOPEN_TMPVAR, NEED__RES);
5f0e6fc7 127
8b801829 128 save = errno;
5f0e6fc7 129 __libc_lock_unlock (lock);
8b801829 130 __set_errno (save);
5f0e6fc7
RM
131}
132
133
134void
6dbe2837 135ENDFUNC_NAME (void)
5f0e6fc7 136{
8b801829 137 int save;
5f0e6fc7 138
226e9fda
UD
139 /* If the service has not been used before do not do anything. */
140 if (startp != NULL)
141 {
142 __libc_lock_lock (lock);
143 __nss_endent (ENDFUNC_NAME_STRING, DB_LOOKUP_FCT, &nip, &startp,
144 &last_nip, NEED__RES);
145 save = errno;
146 __libc_lock_unlock (lock);
147 __set_errno (save);
148 }
5f0e6fc7
RM
149}
150
151
ba1ffaa1
UD
152int
153INTERNAL (REENTRANT_GETNAME) (LOOKUP_TYPE *resbuf, char *buffer, size_t buflen,
154 LOOKUP_TYPE **result H_ERRNO_PARM)
5f0e6fc7 155{
8b801829
UD
156 int status;
157 int save;
5f0e6fc7 158
3dbe1581 159 __libc_lock_lock (lock);
8b801829
UD
160 status = __nss_getent_r (GETFUNC_NAME_STRING, SETFUNC_NAME_STRING,
161 DB_LOOKUP_FCT, &nip, &startp, &last_nip,
162 STAYOPEN_TMPVAR, NEED__RES, resbuf, buffer,
163 buflen, (void **) result, H_ERRNO_VAR_P);
164 save = errno;
5f0e6fc7 165 __libc_lock_unlock (lock);
8b801829
UD
166 __set_errno (save);
167 return status;
5f0e6fc7 168}
16710d58
RM
169
170
deb84c43
UD
171#ifdef NO_COMPAT_NEEDED
172strong_alias (INTERNAL (REENTRANT_GETNAME), REENTRANT_GETNAME);
173#else
174# include <shlib-compat.h>
175# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1_2)
176# define OLD(name) OLD1 (name)
177# define OLD1(name) __old_##name
c2fa5b5a
UD
178
179int
4a381a81 180attribute_compat_text_section
c2fa5b5a
UD
181OLD (REENTRANT_GETNAME) (LOOKUP_TYPE *resbuf, char *buffer, size_t buflen,
182 LOOKUP_TYPE **result H_ERRNO_PARM)
183{
184 int ret = INTERNAL (REENTRANT_GETNAME) (resbuf, buffer, buflen,
185 result H_ERRNO_VAR);
186
187 if (ret != 0)
188 ret = -1;
189
190 return ret;
191}
192
deb84c43 193# define do_symbol_version(real, name, version) \
16710d58
RM
194 compat_symbol (libc, real, name, version)
195do_symbol_version (OLD (REENTRANT_GETNAME), REENTRANT_GETNAME, GLIBC_2_0);
deb84c43 196# endif
c2fa5b5a 197
bff334e0
UD
198/* As INTERNAL (REENTRANT_GETNAME) may be hidden, we need an alias
199 in between so that the REENTRANT_GETNAME@@GLIBC_2.1.2 is not
200 hidden too. */
201strong_alias (INTERNAL (REENTRANT_GETNAME), NEW (REENTRANT_GETNAME));
202
deb84c43 203# define do_default_symbol_version(real, name, version) \
16710d58 204 versioned_symbol (libc, real, name, version)
bff334e0 205do_default_symbol_version (NEW (REENTRANT_GETNAME),
16710d58 206 REENTRANT_GETNAME, GLIBC_2_1_2);
deb84c43 207#endif
2f7f7bc6 208
01767843
CM
209nss_interface_function (SETFUNC_NAME)
210nss_interface_function (ENDFUNC_NAME)
211nss_interface_function (REENTRANT_GETNAME)