nsswitch: use new internal API (callers)

Stitch new ABI and types throughout all NSS callers.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
This commit is contained in:
DJ Delorie 2020-11-09 22:09:34 -05:00
parent 6eceded941
commit f4f3b09111
26 changed files with 87 additions and 261 deletions

View File

@ -10,7 +10,7 @@ typedef enum nss_status (*get_function) (struct group *, char *,
static enum nss_status
compat_call (service_user *nip, const char *user, gid_t group, long int *start,
compat_call (nss_action_list nip, const char *user, gid_t group, long int *start,
long int *size, gid_t **groupsp, long int limit, int *errnop)
{
struct group grpbuf;

View File

@ -63,7 +63,6 @@ internal_getgrouplist (const char *user, gid_t group, long int *size,
#endif
enum nss_status status = NSS_STATUS_UNAVAIL;
int no_more = 0;
/* Never store more than the starting *SIZE number of elements. */
assert (*size > 0);
@ -71,28 +70,23 @@ internal_getgrouplist (const char *user, gid_t group, long int *size,
/* Start is one, because we have the first group as parameter. */
long int start = 1;
if (__nss_initgroups_database == NULL)
{
if (__nss_database_lookup2 ("initgroups", NULL, "",
&__nss_initgroups_database) < 0)
{
if (__nss_group_database == NULL)
no_more = __nss_database_lookup2 ("group", NULL, "files",
&__nss_group_database);
nss_action_list nip;
__nss_initgroups_database = __nss_group_database;
}
else
if (__nss_database_get (nss_database_initgroups, &nip))
{
use_initgroups_entry = true;
}
else if (__nss_database_get (nss_database_group, &nip))
{
use_initgroups_entry = false;
}
else
/* __nss_initgroups_database might have been set through
__nss_configure_lookup in which case use_initgroups_entry was
not set here. */
use_initgroups_entry = __nss_initgroups_database != __nss_group_database;
{
nip = __nss_action_parse ("files");
use_initgroups_entry = false;
}
service_user *nip = __nss_initgroups_database;
while (! no_more)
while (nip && nip->module)
{
long int prev_start = start;
@ -134,10 +128,7 @@ internal_getgrouplist (const char *user, gid_t group, long int *size,
&& nss_next_action (nip, status) == NSS_ACTION_RETURN)
break;
if (nip->next == NULL)
no_more = -1;
else
nip = nip->next;
nip++;
}
return start;

View File

@ -30,9 +30,7 @@ typedef int (*lookup_function) (const char *, struct etherent *, char *, int,
int
ether_hostton (const char *hostname, struct ether_addr *addr)
{
static service_user *startp;
static lookup_function start_fct;
service_user *nip;
nss_action_list nip;
union
{
lookup_function f;
@ -42,22 +40,7 @@ ether_hostton (const char *hostname, struct ether_addr *addr)
enum nss_status status = NSS_STATUS_UNAVAIL;
struct etherent etherent;
if (startp == NULL)
{
no_more = __nss_ethers_lookup2 (&nip, "gethostton_r", NULL, &fct.ptr);
if (no_more)
startp = (service_user *) -1;
else
{
startp = nip;
start_fct = fct.f;
}
}
else
{
fct.f = start_fct;
no_more = (nip = startp) == (service_user *) -1;
}
while (no_more == 0)
{

View File

@ -31,9 +31,7 @@ typedef int (*lookup_function) (const struct ether_addr *, struct etherent *,
int
ether_ntohost (char *hostname, const struct ether_addr *addr)
{
static service_user *startp;
static lookup_function start_fct;
service_user *nip;
nss_action_list nip;
union
{
lookup_function f;
@ -43,22 +41,7 @@ ether_ntohost (char *hostname, const struct ether_addr *addr)
enum nss_status status = NSS_STATUS_UNAVAIL;
struct etherent etherent;
if (startp == NULL)
{
no_more = __nss_ethers_lookup2 (&nip, "getntohost_r", NULL, &fct.ptr);
if (no_more)
startp = (service_user *) -1;
else
{
startp = nip;
start_fct = fct.f;
}
}
else
{
fct.f = start_fct;
no_more = (nip = startp) == (service_user *) -1;
}
while (no_more == 0)
{

View File

@ -39,40 +39,12 @@ static struct __netgrent dataset;
/* Set up NIP to run through the services. Return nonzero if there are no
services (left). */
static int
setup (void **fctp, service_user **nipp)
setup (void **fctp, nss_action_list *nipp)
{
/* Remember the first service_entry, it's always the same. */
static bool startp_initialized;
static service_user *startp;
int no_more;
if (!startp_initialized)
{
/* Executing this more than once at the same time must yield the
same result every time. So we need no locking. */
no_more = __nss_netgroup_lookup2 (nipp, "setnetgrent", NULL, fctp);
startp = no_more ? (service_user *) -1 : *nipp;
#ifdef PTR_MANGLE
PTR_MANGLE (startp);
#endif
atomic_write_barrier ();
startp_initialized = true;
}
else
{
service_user *nip = startp;
#ifdef PTR_DEMANGLE
PTR_DEMANGLE (nip);
#endif
if (nip == (service_user *) -1)
/* No services at all. */
return 1;
/* Reset to the beginning of the service list. */
*nipp = nip;
/* Look up the first function. */
no_more = __nss_lookup (nipp, "setnetgrent", NULL, fctp);
}
return no_more;
}
@ -100,7 +72,7 @@ endnetgrent_hook (struct __netgrent *datap)
{
enum nss_status (*endfct) (struct __netgrent *);
if (datap->nip == NULL || datap->nip == (service_user *) -1l)
if (datap->nip == NULL || datap->nip == (nss_action_list) -1l)
return;
endfct = __nss_lookup_function (datap->nip, "endnetgrent");
@ -133,7 +105,7 @@ __internal_setnetgrent_reuse (const char *group, struct __netgrent *datap,
/* Ignore status, we force check in `__nss_next2'. */
status = DL_CALL_FCT (*fct.f, (group, datap));
service_user *old_nip = datap->nip;
nss_action_list old_nip = datap->nip;
no_more = __nss_next2 (&datap->nip, "setnetgrent", NULL, &fct.ptr,
status, 0);
@ -275,7 +247,7 @@ __internal_getnetgrent_r (char **hostp, char **userp, char **domainp,
/* This bogus function pointer is a special marker left by
__nscd_setnetgrent to tell us to use the data it left
before considering any modules. */
if (datap->nip == (service_user *) -1l)
if (datap->nip == (nss_action_list) -1l)
fct = nscd_getnetgrent;
else
#endif

View File

@ -64,7 +64,7 @@ struct __netgrent
/* This handle for the NSS data base is shared between all
set/get/endXXXent functions. */
service_user *nip;
struct nss_action *nip;
};

View File

@ -71,20 +71,15 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,
dbg_log (_("Reloading \"%s\" in hosts cache!"), (char *) key);
}
static service_user *hosts_database;
service_user *nip;
nss_action_list nip;
int no_more;
int rc6 = 0;
int rc4 = 0;
int herrno = 0;
if (hosts_database == NULL)
no_more = __nss_database_lookup2 ("hosts", NULL,
"dns [!UNAVAIL=return] files",
&hosts_database);
else
no_more = 0;
nip = hosts_database;
&nip);
/* Initialize configurations. */
struct resolv_context *ctx = __resolv_context_get ();
@ -442,10 +437,10 @@ next_nip:
if (nss_next_action (nip, status[1]) == NSS_ACTION_RETURN)
break;
if (nip->next == NULL)
if (nip[1].module == NULL)
no_more = -1;
else
nip = nip->next;
++nip;
}
/* No result found. Create a negative result record. */

View File

@ -48,4 +48,4 @@
#include <check_native.c>
/* Some variables normally defined in libc. */
service_user *__nss_hosts_database attribute_hidden;
nss_action_list __nss_hosts_database attribute_hidden;

View File

@ -77,8 +77,8 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req,
dbg_log (_("Reloading \"%s\" in group cache!"), (char *) key);
}
static service_user *group_database;
service_user *nip;
static nss_action_list group_database;
nss_action_list nip;
int no_more;
if (group_database == NULL)
@ -161,10 +161,10 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req,
&& nss_next_action (nip, status) == NSS_ACTION_RETURN)
break;
if (nip->next == NULL)
if (nip[1].module == NULL)
no_more = -1;
else
nip = nip->next;
++nip;
}
bool all_written;

View File

@ -124,7 +124,7 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,
dbg_log (_("Reloading \"%s\" in netgroup cache!"), key);
}
static service_user *netgroup_database;
static nss_action_list netgroup_database;
time_t timeout;
struct dataset *dataset;
bool cacheable = false;
@ -175,7 +175,7 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,
void *ptr;
} setfct;
service_user *nip = netgroup_database;
nss_action_list nip = netgroup_database;
int no_more = __nss_lookup (&nip, "setnetgrent", NULL, &setfct.ptr);
while (!no_more)
{

View File

@ -116,7 +116,7 @@ __nscd_setnetgrent (const char *group, struct __netgrent *datap)
datap->data_size = datalen;
datap->cursor = respdata;
datap->first = 1;
datap->nip = (service_user *) -1l;
datap->nip = (nss_action_list) -1l;
datap->known_groups = NULL;
datap->needed_groups = NULL;

View File

@ -53,11 +53,10 @@
#endif
int
DB_LOOKUP_FCT (service_user **ni, const char *fct_name, const char *fct2_name,
DB_LOOKUP_FCT (nss_action_list *ni, const char *fct_name, const char *fct2_name,
void **fctp)
{
if (DATABASE_NAME_SYMBOL == NULL
&& __nss_database_lookup2 (DATABASE_NAME_STRING, ALTERNATE_NAME_STRING,
if (__nss_database_lookup2 (DATABASE_NAME_STRING, ALTERNATE_NAME_STRING,
DEFAULT_CONFIG, &DATABASE_NAME_SYMBOL) < 0)
return -1;

View File

@ -29,7 +29,7 @@
glibc 2.7 and earlier and glibc 2.8 and later, even on i386. */
int
attribute_compat_text_section
__nss_passwd_lookup (service_user **ni, const char *fct_name, void **fctp)
__nss_passwd_lookup (nss_action_list *ni, const char *fct_name, void **fctp)
{
__set_errno (ENOSYS);
return -1;
@ -46,11 +46,11 @@ compat_symbol (libc, __nss_hosts_lookup, __nss_hosts_lookup, GLIBC_2_0);
/* These functions were exported under a non-GLIBC_PRIVATE version,
even though it is not usable externally due to the service_user
type dependency. */
(now nss_action_list) type dependency. */
int
attribute_compat_text_section
__nss_next (service_user **ni, const char *fct_name, void **fctp, int status,
__nss_next (nss_action_list *ni, const char *fct_name, void **fctp, int status,
int all_values)
{
return -1;
@ -60,7 +60,7 @@ compat_symbol (libc, __nss_next, __nss_next, GLIBC_2_0);
int
attribute_compat_text_section
__nss_database_lookup (const char *database, const char *alternate_name,
const char *defconfig, service_user **ni)
const char *defconfig, nss_action_list *ni)
{
*ni = NULL;
return -1;

View File

@ -179,7 +179,7 @@ typedef enum nss_status (*lookup_function) (ADD_PARAMS, LOOKUP_TYPE *, char *,
EXTRA_PARAMS);
/* The lookup function for the first entry of this service. */
extern int DB_LOOKUP_FCT (service_user **nip, const char *name,
extern int DB_LOOKUP_FCT (nss_action_list *nip, const char *name,
const char *name2, void **fctp);
libc_hidden_proto (DB_LOOKUP_FCT)
@ -189,10 +189,7 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer,
size_t buflen, LOOKUP_TYPE **result H_ERRNO_PARM
EXTRA_PARAMS)
{
static bool startp_initialized;
static service_user *startp;
static lookup_function start_fct;
service_user *nip;
nss_action_list nip;
int do_merge = 0;
LOOKUP_TYPE mergegrp;
char *mergebuf = NULL;
@ -227,6 +224,7 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer,
PREPROCESS;
#endif
#ifdef HANDLE_DIGITS_DOTS
switch (__nss_hostname_digits_dots (name, resbuf, &buffer, NULL,
buflen, result, &status, AF_VAL,
@ -264,47 +262,8 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer,
}
#endif
if (! startp_initialized)
{
no_more = DB_LOOKUP_FCT (&nip, REENTRANT_NAME_STRING,
REENTRANT2_NAME_STRING, &fct.ptr);
if (no_more)
{
void *tmp_ptr = (service_user *) -1l;
#ifdef PTR_MANGLE
PTR_MANGLE (tmp_ptr);
#endif
startp = tmp_ptr;
}
else
{
void *tmp_ptr = fct.l;
#ifdef PTR_MANGLE
PTR_MANGLE (tmp_ptr);
#endif
start_fct = tmp_ptr;
tmp_ptr = nip;
#ifdef PTR_MANGLE
PTR_MANGLE (tmp_ptr);
#endif
startp = tmp_ptr;
}
/* Make sure start_fct and startp are written before
startp_initialized. */
atomic_write_barrier ();
startp_initialized = true;
}
else
{
fct.l = start_fct;
nip = startp;
#ifdef PTR_DEMANGLE
PTR_DEMANGLE (fct.l);
PTR_DEMANGLE (nip);
#endif
no_more = nip == (service_user *) -1l;
}
while (no_more == 0)
{

View File

@ -95,11 +95,11 @@
/* This handle for the NSS data base is shared between all
set/get/endXXXent functions. */
static service_user *nip;
static nss_action_list nip;
/* Remember the last service used since the last call to `endXXent'. */
static service_user *last_nip;
/* Remember the first service_entry, it's always the same. */
static service_user *startp;
static nss_action_list last_nip;
/* Remember the first service_entry across set/get/endent. */
static nss_action_list startp;
#ifdef STAYOPEN_TMP
/* We need to remember the last `stayopen' flag given by the user
@ -112,7 +112,7 @@ static STAYOPEN_TMP;
__libc_lock_define_initialized (static, lock)
/* The lookup function for the first entry of this service. */
extern int DB_LOOKUP_FCT (service_user **nip, const char *name,
extern int DB_LOOKUP_FCT (nss_action_list *nip, const char *name,
const char *name2, void **fctp);
libc_hidden_proto (DB_LOOKUP_FCT)

View File

@ -25,20 +25,20 @@
services (left). */
static int
setup (const char *func_name, db_lookup_function lookup_fct,
void **fctp, service_user **nip, service_user **startp, int all)
void **fctp, nss_action_list *nip, nss_action_list *startp, int all)
{
int no_more;
if (*startp == NULL)
if (*startp == NULL || all)
{
no_more = lookup_fct (nip, func_name, NULL, fctp);
*startp = no_more ? (service_user *) -1l : *nip;
*startp = no_more ? (nss_action_list) -1l : *nip;
}
else if (*startp == (service_user *) -1l)
else if (*startp == (nss_action_list) -1l)
/* No services at all. */
return 1;
else
{
if (all || !*nip)
if (!*nip)
/* Reset to the beginning of the service list. */
*nip = *startp;
/* Look up the first function. */
@ -49,8 +49,8 @@ setup (const char *func_name, db_lookup_function lookup_fct,
void
__nss_setent (const char *func_name, db_lookup_function lookup_fct,
service_user **nip, service_user **startp,
service_user **last_nip, int stayopen, int *stayopen_tmp,
nss_action_list *nip, nss_action_list *startp,
nss_action_list *last_nip, int stayopen, int *stayopen_tmp,
int res)
{
union
@ -110,8 +110,8 @@ __nss_setent (const char *func_name, db_lookup_function lookup_fct,
void
__nss_endent (const char *func_name, db_lookup_function lookup_fct,
service_user **nip, service_user **startp,
service_user **last_nip, int res)
nss_action_list *nip, nss_action_list *startp,
nss_action_list *last_nip, int res)
{
union
{
@ -154,8 +154,8 @@ int
__nss_getent_r (const char *getent_func_name,
const char *setent_func_name,
db_lookup_function lookup_fct,
service_user **nip, service_user **startp,
service_user **last_nip, int *stayopen_tmp, int res,
nss_action_list *nip, nss_action_list *startp,
nss_action_list *last_nip, int *stayopen_tmp, int res,
void *resbuf, char *buffer, size_t buflen,
void **result, int *h_errnop)
{

View File

@ -30,7 +30,7 @@
NSS_DECLARE_MODULE_FUNCTIONS (compat)
static service_user *ni;
static nss_action_list ni;
static enum nss_status (*setgrent_impl) (int stayopen);
static enum nss_status (*getgrnam_r_impl) (const char *name,
struct group * grp, char *buffer,

View File

@ -33,7 +33,7 @@
NSS_DECLARE_MODULE_FUNCTIONS (compat)
static service_user *ni;
static nss_action_list ni;
static enum nss_status (*initgroups_dyn_impl) (const char *, gid_t,
long int *, long int *,
gid_t **, long int, int *);

View File

@ -34,7 +34,7 @@
NSS_DECLARE_MODULE_FUNCTIONS (compat)
static service_user *ni;
static nss_action_list ni;
static enum nss_status (*setpwent_impl) (int stayopen);
static enum nss_status (*getpwnam_r_impl) (const char *name,
struct passwd * pwd, char *buffer,

View File

@ -34,7 +34,7 @@
NSS_DECLARE_MODULE_FUNCTIONS (compat)
static service_user *ni;
static nss_action_list ni;
static enum nss_status (*setspent_impl) (int stayopen);
static enum nss_status (*getspnam_r_impl) (const char *name, struct spwd * sp,
char *buffer, size_t buflen,

View File

@ -58,7 +58,7 @@ _res_hconf_init (void)
#undef USE_NSCD
#include "../sysdeps/posix/getaddrinfo.c"
service_user *__nss_hosts_database attribute_hidden;
nss_action_list __nss_hosts_database attribute_hidden;
/* This is the beginning of the real test code. The above defines
(among other things) the function rfc3484_sort. */

View File

@ -58,7 +58,7 @@ _res_hconf_init (void)
#undef USE_NSCD
#include "../sysdeps/posix/getaddrinfo.c"
service_user *__nss_hosts_database attribute_hidden;
nss_action_list __nss_hosts_database attribute_hidden;
/* This is the beginning of the real test code. The above defines
(among other things) the function rfc3484_sort. */

View File

@ -58,7 +58,7 @@ _res_hconf_init (void)
#undef USE_NSCD
#include "../sysdeps/posix/getaddrinfo.c"
service_user *__nss_hosts_database attribute_hidden;
nss_action_list __nss_hosts_database attribute_hidden;
/* This is the beginning of the real test code. The above defines
(among other things) the function rfc3484_sort. */

View File

@ -145,9 +145,7 @@ int
netname2user (const char *netname, uid_t * uidp, gid_t * gidp,
int *gidlenp, gid_t * gidlist)
{
static service_user *startp;
static netname2user_function start_fct;
service_user *nip;
nss_action_list nip;
union
{
netname2user_function f;
@ -156,22 +154,7 @@ netname2user (const char *netname, uid_t * uidp, gid_t * gidp,
enum nss_status status = NSS_STATUS_UNAVAIL;
int no_more;
if (startp == NULL)
{
no_more = __nss_publickey_lookup2 (&nip, "netname2user", NULL, &fct.ptr);
if (no_more)
startp = (service_user *) - 1;
else
{
startp = nip;
start_fct = fct.f;
}
}
else
{
fct.f = start_fct;
no_more = (nip = startp) == (service_user *) - 1;
}
while (!no_more)
{

View File

@ -34,9 +34,7 @@ typedef int (*secret_function) (const char *, char *, const char *, int *);
int
getpublickey (const char *name, char *key)
{
static service_user *startp;
static public_function start_fct;
service_user *nip;
nss_action_list nip;
union
{
public_function f;
@ -45,22 +43,7 @@ getpublickey (const char *name, char *key)
enum nss_status status = NSS_STATUS_UNAVAIL;
int no_more;
if (startp == NULL)
{
no_more = __nss_publickey_lookup2 (&nip, "getpublickey", NULL, &fct.ptr);
if (no_more)
startp = (service_user *) -1;
else
{
startp = nip;
start_fct = fct.f;
}
}
else
{
fct.f = start_fct;
no_more = (nip = startp) == (service_user *) -1;
}
while (! no_more)
{
@ -77,9 +60,7 @@ libc_hidden_nolink_sunrpc (getpublickey, GLIBC_2_0)
int
getsecretkey (const char *name, char *key, const char *passwd)
{
static service_user *startp;
static secret_function start_fct;
service_user *nip;
nss_action_list nip;
union
{
secret_function f;
@ -88,22 +69,7 @@ getsecretkey (const char *name, char *key, const char *passwd)
enum nss_status status = NSS_STATUS_UNAVAIL;
int no_more;
if (startp == NULL)
{
no_more = __nss_publickey_lookup2 (&nip, "getsecretkey", NULL, &fct.ptr);
if (no_more)
startp = (service_user *) -1;
else
{
startp = nip;
start_fct = fct.f;
}
}
else
{
fct.f = start_fct;
no_more = (nip = startp) == (service_user *) -1;
}
while (! no_more)
{

View File

@ -307,7 +307,7 @@ convert_hostent_to_gaih_addrtuple (const struct addrinfo *req,
memory allocation failure. The returned string is allocated on the
heap; the caller has to free it. */
static char *
getcanonname (service_user *nip, struct gaih_addrtuple *at, const char *name)
getcanonname (nss_action_list nip, struct gaih_addrtuple *at, const char *name)
{
nss_getcanonname_r *cfct = __nss_lookup_function (nip, "getcanonname_r");
char *s = (char *) name;
@ -538,7 +538,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
struct gaih_addrtuple **pat = &at;
int no_data = 0;
int no_inet6_data = 0;
service_user *nip;
nss_action_list nip;
enum nss_status inet6_status = NSS_STATUS_UNAVAIL;
enum nss_status status = NSS_STATUS_UNAVAIL;
int no_more;
@ -720,13 +720,9 @@ gaih_inet (const char *name, const struct gaih_service *service,
}
#endif
if (__nss_hosts_database == NULL)
no_more = __nss_database_lookup2 ("hosts", NULL,
"dns [!UNAVAIL=return] files",
&__nss_hosts_database);
else
no_more = 0;
nip = __nss_hosts_database;
&nip);
/* If we are looking for both IPv4 and IPv6 address we don't
want the lookup functions to automatically promote IPv4
@ -905,10 +901,9 @@ gaih_inet (const char *name, const struct gaih_service *service,
if (nss_next_action (nip, status) == NSS_ACTION_RETURN)
break;
if (nip->next == NULL)
nip++;
if (nip->module == NULL)
no_more = -1;
else
nip = nip->next;
}
__resolv_context_put (res_ctx);