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