]>
git.ipfire.org Git - thirdparty/glibc.git/blob - nss/nsswitch.c
40109c744d9f270e59efd2fb7be6c35dd56f187b
1 /* Copyright (C) 1996-2020 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
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.
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.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
23 #include <libc-lock.h>
26 #include <stdio_ext.h>
32 #include <netinet/ether.h>
37 #if !defined DO_STATIC_NSS || defined SHARED
38 # include <gnu/lib-names.h>
42 #include "../nscd/nscd_proto.h"
46 /* Declare external database variables. */
47 #define DEFINE_DATABASE(name) \
48 nss_action_list __nss_##name##_database attribute_hidden; \
49 weak_extern (__nss_##name##_database)
50 #include "databases.def"
51 #undef DEFINE_DATABASE
54 #undef DEFINE_DATABASE
55 #define DEFINE_DATABASE(name) #name,
56 static const char * database_names
[] = {
57 #include "databases.def"
62 /* Flags whether custom rules for database is set. */
63 bool __nss_database_custom
[NSS_DBSIDX_max
];
67 /*__libc_lock_define_initialized (static, lock)*/
69 /* -1 == database not found
70 0 == database entry pointer stored */
72 __nss_database_lookup2 (const char *database
, const char *alternate_name
,
73 const char *defconfig
, nss_action_list
*ni
)
77 for (database_id
= 0; database_names
[database_id
]; database_id
++)
78 if (strcmp (database_names
[database_id
], database
) == 0)
81 if (database_names
[database_id
] == NULL
)
84 if (__nss_database_get (database_id
, ni
))
95 libc_hidden_def (__nss_database_lookup2
)
102 __nss_lookup (nss_action_list
*ni
, const char *fct_name
, const char *fct2_name
,
105 *fctp
= __nss_lookup_function (*ni
, fct_name
);
106 if (*fctp
== NULL
&& fct2_name
!= NULL
)
107 *fctp
= __nss_lookup_function (*ni
, fct2_name
);
110 && nss_next_action (*ni
, NSS_STATUS_UNAVAIL
) == NSS_ACTION_CONTINUE
111 && (*ni
)[1].module
!= NULL
)
115 *fctp
= __nss_lookup_function (*ni
, fct_name
);
116 if (*fctp
== NULL
&& fct2_name
!= NULL
)
117 *fctp
= __nss_lookup_function (*ni
, fct2_name
);
120 return *fctp
!= NULL
? 0 : (*ni
)[1].module
== NULL
? 1 : -1;
122 libc_hidden_def (__nss_lookup
)
126 0 == adjusted for next function
129 __nss_next2 (nss_action_list
*ni
, const char *fct_name
, const char *fct2_name
,
130 void **fctp
, int status
, int all_values
)
134 if (nss_next_action (*ni
, NSS_STATUS_TRYAGAIN
) == NSS_ACTION_RETURN
135 && nss_next_action (*ni
, NSS_STATUS_UNAVAIL
) == NSS_ACTION_RETURN
136 && nss_next_action (*ni
, NSS_STATUS_NOTFOUND
) == NSS_ACTION_RETURN
137 && nss_next_action (*ni
, NSS_STATUS_SUCCESS
) == NSS_ACTION_RETURN
)
142 /* This is really only for debugging. */
143 if (__builtin_expect (NSS_STATUS_TRYAGAIN
> status
144 || status
> NSS_STATUS_RETURN
, 0))
145 __libc_fatal ("Illegal status in __nss_next.\n");
147 if (nss_next_action (*ni
, status
) == NSS_ACTION_RETURN
)
151 if ((*ni
)[1].module
== NULL
)
158 *fctp
= __nss_lookup_function (*ni
, fct_name
);
159 if (*fctp
== NULL
&& fct2_name
!= NULL
)
160 *fctp
= __nss_lookup_function (*ni
, fct2_name
);
163 && nss_next_action (*ni
, NSS_STATUS_UNAVAIL
) == NSS_ACTION_CONTINUE
164 && (*ni
)[1].module
!= NULL
);
166 return *fctp
!= NULL
? 0 : -1;
168 libc_hidden_def (__nss_next2
)
171 __nss_lookup_function (nss_action_list ni
, const char *fct_name
)
173 if (ni
->module
== NULL
)
175 return __nss_module_get_function (ni
->module
, fct_name
);
177 libc_hidden_def (__nss_lookup_function
)