[PATCH 7/7] nscd: Add basic test
DJ Delorie
dj@redhat.com
Tue Feb 10 20:32:29 GMT 2026
Florian Weimer <fweimer@redhat.com> writes:
> + large_gecos = xasprintf ("large_gecos%0999d", 1234);
> + FILE *fp = xfopen ("/etc/passwd", "a");
Append, so not replacing testroot files, ok.
> + {
> + FILE *fp = xfopen ("/etc/group", "a");
> +
> + /* large-group has many members. Bumping the 1999 limit to 9999
> + triggers an issue related to bug 33460 (short write in nscd). */
> + fputs ("large-group:x:20017:large-group-user-0", fp);
> + for (int i = 1; i <= 1999; ++i)
> + fprintf (fp, ",large-group-user-%d", i);
> + fputc ('\n', fp);
Ok.
> + /* user3 has many groups. */
> + for (int i = 1002; i <= 9999; ++i)
> + fprintf (fp, "user3-group%d:x:%d:user3\n", i, i);
> +
> + xfclose (fp);
> + }
> +}
Ok.
> +static void
> +test_passwd (void)
> +{
> + {
> + const char *expected =
> + "name: root\n"
> + "passwd: x\n"
> + "uid: 0\n"
> + "gid: 0\n"
> + "gecos: Super User\n"
> + "dir: /root\n"
> + "shell: /bin/bash\n"
> + ;
> + invalidate ("passwd");
> + check_passwd ("root by name", getpwnam ("root"), expected);
> + invalidate ("passwd");
> + check_passwd ("root by uid", getpwuid (0), expected);
> + }
It occurs to me, we have similar code in nss/nss_test.h
> + {
> + const char *expected =
> + "name: wheel\n"
> + "passwd: x\n"
> + "gid: 10\n"
> + "member: user1\n"
> + "member: user2\n"
> + ;
> + invalidate ("group");
> + check_group ("wheel by name", getgrnam ("wheel"), expected);
> + check_group ("wheel by name", getgrnam ("wheel"), expected);
> + check_group ("wheel by name", getgrnam ("wheel"), expected);
> + check_group ("wheel by name", getgrnam ("wheel"), expected);
> + check_group ("wheel by name", getgrnam ("wheel"), expected);
> + check_group ("wheel by name", getgrnam ("wheel"), expected);
> + check_group ("wheel by name", getgrnam ("wheel"), expected);
> + check_group ("wheel by name", getgrnam ("wheel"), expected);
> + check_group ("wheel by name", getgrnam ("wheel"), expected);
I don't see what you're doing here, which at least means it needs a
comment.
Otherwise LGTM
Reviewed-by: DJ Delorie <dj@redhat.com>
More information about the Libc-alpha
mailing list