1 /* Copyright (C) 1996-2024 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
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.
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
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
22 #include <libc-lock.h>
25 #include <stdio_ext.h>
31 #include <netinet/ether.h>
36 #if !defined DO_STATIC_NSS || defined SHARED
37 # include <gnu/lib-names.h>
41 #include "../nscd/nscd_proto.h"
45 /* Declare external database variables. */
46 #define DEFINE_DATABASE(name) \
47 nss_action_list __nss_##name##_database attribute_hidden; \
48 weak_extern (__nss_##name##_database)
49 #include "databases.def"
50 #undef DEFINE_DATABASE
54 /* Flags whether custom rules for database is set. */
55 bool __nss_database_custom
[NSS_DBSIDX_max
];
58 /*__libc_lock_define_initialized (static, lock)*/
64 __nss_lookup (nss_action_list
*ni
, const char *fct_name
, const char *fct2_name
,
67 *fctp
= __nss_lookup_function (*ni
, fct_name
);
68 if (*fctp
== NULL
&& fct2_name
!= NULL
)
69 *fctp
= __nss_lookup_function (*ni
, fct2_name
);
72 && nss_next_action (*ni
, NSS_STATUS_UNAVAIL
) == NSS_ACTION_CONTINUE
73 && (*ni
)[1].module
!= NULL
)
77 *fctp
= __nss_lookup_function (*ni
, fct_name
);
78 if (*fctp
== NULL
&& fct2_name
!= NULL
)
79 *fctp
= __nss_lookup_function (*ni
, fct2_name
);
82 return *fctp
!= NULL
? 0 : (*ni
)[1].module
== NULL
? 1 : -1;
84 libc_hidden_def (__nss_lookup
)
88 0 == adjusted for next function
91 __nss_next2 (nss_action_list
*ni
, const char *fct_name
, const char *fct2_name
,
92 void **fctp
, int status
, int all_values
)
96 if (nss_next_action (*ni
, NSS_STATUS_TRYAGAIN
) == NSS_ACTION_RETURN
97 && nss_next_action (*ni
, NSS_STATUS_UNAVAIL
) == NSS_ACTION_RETURN
98 && nss_next_action (*ni
, NSS_STATUS_NOTFOUND
) == NSS_ACTION_RETURN
99 && nss_next_action (*ni
, NSS_STATUS_SUCCESS
) == NSS_ACTION_RETURN
)
104 /* This is really only for debugging. */
105 if (__builtin_expect (NSS_STATUS_TRYAGAIN
> status
106 || status
> NSS_STATUS_RETURN
, 0))
107 __libc_fatal ("Illegal status in __nss_next.\n");
109 if (nss_next_action (*ni
, status
) == NSS_ACTION_RETURN
)
113 if ((*ni
)[1].module
== NULL
)
120 *fctp
= __nss_lookup_function (*ni
, fct_name
);
121 if (*fctp
== NULL
&& fct2_name
!= NULL
)
122 *fctp
= __nss_lookup_function (*ni
, fct2_name
);
125 && nss_next_action (*ni
, NSS_STATUS_UNAVAIL
) == NSS_ACTION_CONTINUE
126 && (*ni
)[1].module
!= NULL
);
128 return *fctp
!= NULL
? 0 : -1;
130 libc_hidden_def (__nss_next2
)
133 __nss_lookup_function (nss_action_list ni
, const char *fct_name
)
135 if (ni
->module
== NULL
)
137 return __nss_module_get_function (ni
->module
, fct_name
);
139 libc_hidden_def (__nss_lookup_function
)