mirror of
https://sourceware.org/git/glibc.git
synced 2025-08-08 17:42:12 +03:00
Extend NSS test suite
* nss/nss_test.h: New. * nss/nss_test1.h: Rewrite to use test-provided data. Add group tests. Parameterize to allow multiple instances. * nss/nss_test2.h: New. Second instance. * nss/nss_test.ver: New. * nss/nss_test1.c: Update to use new framework. * nss/nss_test2.c: New. * nss/nss_test3.c: New. * nss/nss_test4.c: New. * nss/nss_test5.c: New. * nss/Makefile: Build new tests. * shlib-versions: Add libnss_test2.
This commit is contained in:
@@ -1,9 +1,49 @@
|
||||
/* Basic test of passwd database handling.
|
||||
Copyright (C) 2017 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <nss.h>
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "nss_test.h"
|
||||
|
||||
static int hook_called = 0;
|
||||
|
||||
/* Note: the values chosen here are arbitrary; they need only be
|
||||
unique within the table. However, they do need to match the
|
||||
"pwdids" array further down. */
|
||||
static struct passwd pwd_table[] = {
|
||||
PWD (100),
|
||||
PWD (30),
|
||||
PWD (200),
|
||||
PWD (60),
|
||||
PWD (20000),
|
||||
PWD_LAST ()
|
||||
};
|
||||
|
||||
void
|
||||
_nss_test1_init_hook(test_tables *t)
|
||||
{
|
||||
hook_called = 1;
|
||||
t->pwd_table = pwd_table;
|
||||
}
|
||||
|
||||
static int
|
||||
do_test (void)
|
||||
@@ -12,20 +52,26 @@ do_test (void)
|
||||
|
||||
__nss_configure_lookup ("passwd", "test1");
|
||||
|
||||
/* This must match the pwd_table above. */
|
||||
static const unsigned int pwdids[] = { 100, 30, 200, 60, 20000 };
|
||||
#define npwdids (sizeof (pwdids) / sizeof (pwdids[0]))
|
||||
|
||||
setpwent ();
|
||||
|
||||
const unsigned int *np = pwdids;
|
||||
for (struct passwd *p = getpwent (); p != NULL; ++np, p = getpwent ())
|
||||
if (p->pw_uid != *np || strncmp (p->pw_name, "name", 4) != 0
|
||||
|| atol (p->pw_name + 4) != *np)
|
||||
{
|
||||
printf ("passwd entry %td wrong (%s, %u)\n",
|
||||
np - pwdids, p->pw_name, p->pw_uid);
|
||||
retval = 1;
|
||||
break;
|
||||
}
|
||||
{
|
||||
retval += compare_passwds (np-pwdids, p, & pwd_table[np-pwdids]);
|
||||
|
||||
if (p->pw_uid != *np || strncmp (p->pw_name, "name", 4) != 0
|
||||
|| atol (p->pw_name + 4) != *np)
|
||||
{
|
||||
printf ("FAIL: passwd entry %td wrong (%s, %u)\n",
|
||||
np - pwdids, p->pw_name, p->pw_uid);
|
||||
retval = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
endpwent ();
|
||||
|
||||
@@ -37,14 +83,14 @@ do_test (void)
|
||||
struct passwd *p = getpwnam (buf);
|
||||
if (p == NULL || p->pw_uid != pwdids[i] || strcmp (buf, p->pw_name) != 0)
|
||||
{
|
||||
printf ("passwd entry \"%s\" wrong\n", buf);
|
||||
printf ("FAIL: passwd entry \"%s\" wrong\n", buf);
|
||||
retval = 1;
|
||||
}
|
||||
|
||||
p = getpwuid (pwdids[i]);
|
||||
if (p == NULL || p->pw_uid != pwdids[i] || strcmp (buf, p->pw_name) != 0)
|
||||
{
|
||||
printf ("passwd entry %u wrong\n", pwdids[i]);
|
||||
printf ("FAIL: passwd entry %u wrong\n", pwdids[i]);
|
||||
retval = 1;
|
||||
}
|
||||
|
||||
@@ -53,18 +99,24 @@ do_test (void)
|
||||
p = getpwnam (buf);
|
||||
if (p != NULL)
|
||||
{
|
||||
printf ("passwd entry \"%s\" wrong\n", buf);
|
||||
printf ("FAIL: passwd entry \"%s\" wrong\n", buf);
|
||||
retval = 1;
|
||||
}
|
||||
|
||||
p = getpwuid (pwdids[i] + 1);
|
||||
if (p != NULL)
|
||||
{
|
||||
printf ("passwd entry %u wrong\n", pwdids[i] + 1);
|
||||
printf ("FAIL: passwd entry %u wrong\n", pwdids[i] + 1);
|
||||
retval = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hook_called)
|
||||
{
|
||||
retval = 1;
|
||||
printf("FAIL: init hook never called\n");
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user