diff options
Diffstat (limited to 'test/pwd_grp')
-rw-r--r-- | test/pwd_grp/.indent.pro | 33 | ||||
-rw-r--r-- | test/pwd_grp/Makefile | 8 | ||||
-rw-r--r-- | test/pwd_grp/Makefile.in | 8 | ||||
-rw-r--r-- | test/pwd_grp/getgroups.c | 100 | ||||
-rw-r--r-- | test/pwd_grp/grcat.c | 32 | ||||
-rw-r--r-- | test/pwd_grp/pwcat.c | 26 | ||||
-rw-r--r-- | test/pwd_grp/test_grp.c | 87 | ||||
-rw-r--r-- | test/pwd_grp/test_pwd.c | 74 |
8 files changed, 368 insertions, 0 deletions
diff --git a/test/pwd_grp/.indent.pro b/test/pwd_grp/.indent.pro new file mode 100644 index 0000000..492ecf1 --- /dev/null +++ b/test/pwd_grp/.indent.pro @@ -0,0 +1,33 @@ +--blank-lines-after-declarations +--blank-lines-after-procedures +--break-before-boolean-operator +--no-blank-lines-after-commas +--braces-on-if-line +--braces-on-struct-decl-line +--comment-indentation25 +--declaration-comment-column25 +--no-comment-delimiters-on-blank-lines +--cuddle-else +--continuation-indentation4 +--case-indentation0 +--else-endif-column33 +--space-after-cast +--line-comments-indentation0 +--declaration-indentation1 +--dont-format-first-column-comments +--dont-format-comments +--honour-newlines +--indent-level4 +/* changed from 0 to 4 */ +--parameter-indentation4 +--line-length78 /* changed from 75 */ +--continue-at-parentheses +--no-space-after-function-call-names +--dont-break-procedure-type +--dont-star-comments +--leave-optional-blank-lines +--dont-space-special-semicolon +--tab-size4 +/* additions by Mark */ +--case-brace-indentation0 +--leave-preprocessor-space diff --git a/test/pwd_grp/Makefile b/test/pwd_grp/Makefile new file mode 100644 index 0000000..fa2aacb --- /dev/null +++ b/test/pwd_grp/Makefile @@ -0,0 +1,8 @@ +# uClibc pwd_grp tests +# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + +top_builddir=../../ +top_srcdir=../../ +include ../Rules.mak +-include Makefile.in +include ../Test.mak diff --git a/test/pwd_grp/Makefile.in b/test/pwd_grp/Makefile.in new file mode 100644 index 0000000..d561f3d --- /dev/null +++ b/test/pwd_grp/Makefile.in @@ -0,0 +1,8 @@ +# uClibc pwd_grp tests +# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + +DODIFF_test_pwd := 1 +DODIFF_test_grp := 1 +DODIFF_pwcat := 1 +DODIFF_grcat := 1 +DODIFF_getgroups := 1 diff --git a/test/pwd_grp/getgroups.c b/test/pwd_grp/getgroups.c new file mode 100644 index 0000000..c343552 --- /dev/null +++ b/test/pwd_grp/getgroups.c @@ -0,0 +1,100 @@ +/* This test was ripped out of GNU 'id' from coreutils-5.0 + * by Erik Andersen. + * + * + * id is Copyright (C) 1989-2003 Free Software Foundation, Inc. + * and licensed under the GPL v2 or later, and was written by + * Arnold Robbins, with a major rewrite by David MacKenzie, + */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> +#include <pwd.h> +#include <grp.h> + +/* The number of errors encountered so far. */ +static int problems = 0; + +/* Print the name or value of group ID GID. */ +static void print_group(gid_t gid) +{ + struct group *grp = NULL; + + grp = getgrgid(gid); + if (grp == NULL) { + fprintf(stderr, "cannot find name for group ID %u\n", gid); + problems++; + } + + if (grp == NULL) + printf("%u", (unsigned)gid); + else + printf("%s", grp->gr_name); +} + +static int xgetgroups(gid_t gid, int *n_groups, gid_t ** groups) +{ + int max_n_groups; + int ng; + gid_t *g; + int fail = 0; + + max_n_groups = getgroups(0, NULL); + + /* Add 1 just in case max_n_groups is zero. */ + g = (gid_t *) malloc(max_n_groups * sizeof(gid_t) + 1); + if (g == NULL) { + fprintf(stderr, "out of memory\n"); + exit(EXIT_FAILURE); + } + ng = getgroups(max_n_groups, g); + + if (ng < 0) { + fprintf(stderr, "cannot get supplemental group list\n"); + ++fail; + free(g); + } + if (!fail) { + *n_groups = ng; + *groups = g; + } + return fail; +} + +/* Print all of the distinct groups the user is in. */ +int main(int argc, char *argv[]) +{ + struct passwd *pwd; + + pwd = getpwuid(getuid()); + if (pwd == NULL) + problems++; + + print_group(getgid()); + if (getegid() != getgid()) { + putchar(' '); + print_group(getegid()); + } + + { + int n_groups = 0; + gid_t *groups; + register int i; + + if (xgetgroups((pwd ? pwd->pw_gid : (gid_t) - 1), + &n_groups, &groups)) { + return ++problems; + } + + for (i = 0; i < n_groups; i++) + if (groups[i] != getgid() && groups[i] != getegid()) { + putchar(' '); + print_group(groups[i]); + } + free(groups); + } + putchar('\n'); + return (problems != 0); +} diff --git a/test/pwd_grp/grcat.c b/test/pwd_grp/grcat.c new file mode 100644 index 0000000..a896140 --- /dev/null +++ b/test/pwd_grp/grcat.c @@ -0,0 +1,32 @@ +/* + * grcat.c + * + * Generate a printable version of the group database + */ +/* + * Arnold Robbins, arnold@gnu.org, May 1993 + * Public Domain + */ + +#include <stdlib.h> +#include <stdio.h> +#include <grp.h> + +int main(int argc, char **argv) +{ + struct group *g; + int i; + + while ((g = getgrent()) != NULL) { + printf("%s:%s:%ld:", g->gr_name, g->gr_passwd, + (long) g->gr_gid); + for (i = 0; g->gr_mem[i] != NULL; i++) { + printf("%s", g->gr_mem[i]); + if (g->gr_mem[i+1] != NULL) + putchar(','); + } + putchar('\n'); + } + endgrent(); + return 0; +} diff --git a/test/pwd_grp/pwcat.c b/test/pwd_grp/pwcat.c new file mode 100644 index 0000000..afad8e1 --- /dev/null +++ b/test/pwd_grp/pwcat.c @@ -0,0 +1,26 @@ +/* + * pwcat.c + * + * Generate a printable version of the password database + */ +/* + * Arnold Robbins, arnold@gnu.org, May 1993 + * Public Domain + */ + +#include <stdio.h> +#include <pwd.h> +#include <stdlib.h> + +int main(int argc, char **argv) +{ + struct passwd *p; + + while ((p = getpwent()) != NULL) + printf("%s:%s:%ld:%ld:%s:%s:%s\n", + p->pw_name, p->pw_passwd, (long) p->pw_uid, + (long) p->pw_gid, p->pw_gecos, p->pw_dir, p->pw_shell); + + endpwent(); + return 0; +} diff --git a/test/pwd_grp/test_grp.c b/test/pwd_grp/test_grp.c new file mode 100644 index 0000000..573806c --- /dev/null +++ b/test/pwd_grp/test_grp.c @@ -0,0 +1,87 @@ +/* + * test_grp.c - This file is part of the libc-8086/grp package for ELKS, + * Copyright (C) 1995, 1996 Nat Friedman <ndf@linux.mit.edu>. + * + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +#include <unistd.h> +#include <stdio.h> +#include <fcntl.h> +#include <grp.h> + +int main(int argc, char **argv) +{ + struct group *group; + char **tmp_mem; + int test_gid; + + fprintf(stdout, "Beginning test of libc/grp...\n"); + + fprintf(stdout, "=> Testing setgrent(), getgrent(), endgrent()...\n"); + fprintf(stdout, "-> setgrent()...\n"); + setgrent(); + fprintf(stdout, "-> getgrent()...\n"); + printf + ("********************************************************************************\n"); + while ((group = getgrent()) != NULL) { + printf("gr_name\t\t: %s\n", group->gr_name); + printf("gr_passwd\t: %s\n", group->gr_passwd); + printf("gr_gid\t\t: %d\n", (int) group->gr_gid); + printf("gr_mem\t\t: "); + fflush(stdout); + tmp_mem = group->gr_mem; + while (*tmp_mem != NULL) { + printf("%s, ", *tmp_mem); + tmp_mem++; + } + printf + ("\n********************************************************************************\n"); + } + fprintf(stdout, "-> endgrent()...\n"); + endgrent(); + fprintf(stdout, + "=> Test of setgrent(), getgrent(), endgrent() complete.\n"); + fprintf(stdout, "=> Testing getgrid(), getgrnam()...\n"); + fprintf(stdout, "-> getgrgid()...\n"); + printf + ("********************************************************************************\n"); + for (test_gid = 0; test_gid < 100; test_gid++) { + fprintf(stdout, "-> getgrgid(%d)...\n", test_gid); + group = getgrgid((gid_t) test_gid); + if (group != NULL) { + printf("gr_name\t: %s\n", group->gr_name); + printf("gr_passwd\t: %s\n", group->gr_passwd); + printf("gr_gid\t: %d\n", (int) group->gr_gid); + printf("gr_mem\t\t: "); + fflush(stdout); + tmp_mem = group->gr_mem; + while (*tmp_mem != NULL) { + printf("%s, ", *tmp_mem); + tmp_mem++; + } + } + printf + ("\n********************************************************************************\n"); + } + fprintf(stdout, "-> getgrnam()...\n"); + group = getgrnam("root"); + if (group == NULL) { + printf(">NULL<\n"); + } else { + printf("gr_name\t: %s\n", group->gr_name); + printf("gr_passwd\t: %s\n", group->gr_passwd); + printf("gr_gid\t: %d\n", (int) group->gr_gid); + printf("gr_mem\t\t: "); + fflush(stdout); + tmp_mem = group->gr_mem; + while (*tmp_mem != NULL) { + printf("%s, ", *tmp_mem); + tmp_mem++; + } + printf("\n"); + } + + + return 0; +} diff --git a/test/pwd_grp/test_pwd.c b/test/pwd_grp/test_pwd.c new file mode 100644 index 0000000..065864e --- /dev/null +++ b/test/pwd_grp/test_pwd.c @@ -0,0 +1,74 @@ +/* + * test_pwd.c - This file is part of the libc-8086/pwd package for ELKS, + * Copyright (C) 1995, 1996 Nat Friedman <ndf@linux.mit.edu>. + * + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +#include <unistd.h> +#include <stdio.h> +#include <fcntl.h> +#include <pwd.h> + +int main(int argc, char **argv) +{ + struct passwd *passwd; + int test_uid; + + fprintf(stdout, "Beginning test of libc/pwd...\n"); + + fprintf(stdout, "=> Testing setpwent(), getpwent(), endpwent()...\n"); + fprintf(stdout, "-> setpwent()...\n"); + setpwent(); + fprintf(stdout, "-> getpwent()...\n"); + printf + ("********************************************************************************\n"); + while ((passwd = getpwent()) != NULL) { + printf("pw_name\t\t: %s\n", passwd->pw_name); + printf("pw_passwd\t: %s\n", passwd->pw_passwd); + printf("pw_uid\t\t: %d\n", (int) passwd->pw_uid); + printf("pw_gid\t\t: %d\n", (int) passwd->pw_gid); + printf("pw_gecos\t: %s\n", passwd->pw_gecos); + printf("pw_dir\t\t: %s\n", passwd->pw_dir); + printf("pw_shell\t: %s\n", passwd->pw_shell); + printf + ("********************************************************************************\n"); + } + fprintf(stdout, "-> endpwent()...\n"); + endpwent(); + fprintf(stdout, + "=> Test of setpwent(), getpwent(), endpwent() complete.\n"); + fprintf(stdout, "=> Testing getpwuid(), getpwnam()...\n"); + fprintf(stdout, "-> getpwuid()...\n"); + printf + ("********************************************************************************\n"); + for (test_uid = 0; test_uid < 1000; test_uid++) { + fprintf(stdout, "-> getpwuid(%d)...\n", test_uid); + passwd = getpwuid((uid_t) test_uid); + if (passwd != NULL) { + printf("pw_name\t\t: %s\n", passwd->pw_name); + printf("pw_passwd\t: %s\n", passwd->pw_passwd); + printf("pw_uid\t\t: %d\n", (int) passwd->pw_uid); + printf("pw_gid\t\t: %d\n", (int) passwd->pw_gid); + printf("pw_gecos\t: %s\n", passwd->pw_gecos); + printf("pw_dir\t\t: %s\n", passwd->pw_dir); + printf("pw_shell\t: %s\n", passwd->pw_shell); + printf + ("********************************************************************************\n"); + } + } + fprintf(stdout, "-> getpwnam()...\n"); + passwd = getpwnam("root"); + if (passwd == NULL) { + printf(">NULL<\n"); + } else { + printf("pw_name\t\t: %s\n", passwd->pw_name); + printf("pw_passwd\t: %s\n", passwd->pw_passwd); + printf("pw_uid\t\t: %d\n", (int) passwd->pw_uid); + printf("pw_gid\t\t: %d\n", (int) passwd->pw_gid); + printf("pw_gecos\t: %s\n", passwd->pw_gecos); + printf("pw_dir\t\t: %s\n", passwd->pw_dir); + printf("pw_shell\t: %s\n", passwd->pw_shell); + } + return 0; +} |