[uClibc-cvs] uClibc/test/pwd_grp getgroups.c, NONE, 1.1 .cvsignore, 1.3, 1.4 Makefile, 1.11, 1.12 grcat.c, 1.1, 1.2 pwcat.c, 1.1, 1.2
Erik Andersen
andersen at uclibc.org
Sun Nov 2 21:55:09 UTC 2003
Update of /var/cvs/uClibc/test/pwd_grp
In directory winder:/tmp/cvs-serv23655
Modified Files:
.cvsignore Makefile grcat.c pwcat.c
Added Files:
getgroups.c
Log Message:
Additional passwd and group tests
Index: .cvsignore
===================================================================
RCS file: /var/cvs/uClibc/test/pwd_grp/.cvsignore,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- .cvsignore 1 Nov 2003 04:49:27 -0000 1.3
+++ .cvsignore 2 Nov 2003 21:55:06 -0000 1.4
@@ -1,23 +1,20 @@
test_grp
-test_grp.o
test_grp.out
test_grp_glibc
-test_grp_glibc.o
test_grp_glibc.out
test_pwd
test_pwd.out
test_pwd_glibc
test_pwd_glibc.out
pwcat
-pwcat.o
pwcat.out
pwcat_glibc
-pwcat_glibc.o
pwcat_glibc.out
grcat
-grcat.o
grcat.out
grcat_glibc
-grcat_glibc.o
grcat_glibc.out
-
+getgroups
+getgroups.out
+getgroups_glibc
+getgroups_glibc.out
Index: grcat.c
===================================================================
RCS file: /var/cvs/uClibc/test/pwd_grp/grcat.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- grcat.c 1 Nov 2003 04:49:27 -0000 1.1
+++ grcat.c 2 Nov 2003 21:55:06 -0000 1.2
@@ -8,40 +8,25 @@
* Public Domain
*/
-/* For OS/2, do nothing. */
-#if HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#if defined (STDC_HEADERS)
#include <stdlib.h>
-#endif
-
-#ifndef HAVE_GETGRENT
-int main() { return 0; }
-#else
#include <stdio.h>
#include <grp.h>
-int
-main(argc, argv)
-int argc;
-char **argv;
+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');
+ 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;
}
-#endif /* HAVE_GETGRENT */
Index: Makefile
===================================================================
RCS file: /var/cvs/uClibc/test/pwd_grp/Makefile,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- Makefile 1 Nov 2003 04:49:27 -0000 1.11
+++ Makefile 2 Nov 2003 21:55:06 -0000 1.12
@@ -24,7 +24,8 @@
TARGETS+=test_grp test_grp_glibc
TARGETS+=pwcat pwcat_glibc
TARGETS+=grcat grcat_glibc
-TARGETS+=test_pwd_diff test_grp_diff pwcat_diff grcat_diff
+TARGETS+=getgroups getgroups_glibc
+TARGETS+=test_pwd_diff test_grp_diff pwcat_diff grcat_diff getgroups_diff
all: $(TARGETS)
@@ -116,6 +117,28 @@
-./$@ 2>&1 >grcat_glibc.out
-@ echo " "
+getgroups: getgroups.c Makefile $(TESTDIR)/Config $(TESTDIR)/Rules.mak $(CC)
+ -@ echo "-------"
+ -@ echo " "
+ -@ echo "Compiling vs uClibc: "
+ -@ echo " "
+ $(CC) $(CFLAGS) -c $< -o $@.o
+ $(CC) $(LDFLAGS) $@.o -o $@ $(EXTRA_LIBS)
+ $(STRIPTOOL) -x -R .note -R .comment $@
+ -./$@ 2>&1 >getgroups.out
+ -@ echo " "
+
+getgroups_glibc: getgroups.c Makefile
+ -@ echo "-------"
+ -@ echo " "
+ -@ echo "Compiling vs GNU libc: "
+ -@ echo " "
+ $(HOSTCC) $(GLIBC_CFLAGS) -c $< -o $@.o
+ $(HOSTCC) $(GLIBC_LDFLAGS) $@.o -o $@
+ $(STRIPTOOL) -x -R .note -R .comment $@
+ -./$@ 2>&1 >getgroups_glibc.out
+ -@ echo " "
+
test_pwd_diff: test_pwd_glibc test_pwd
-@ echo "-------"
-@ echo " "
@@ -148,6 +171,14 @@
-diff -u grcat_glibc.out grcat.out
-@ echo " "
+getgroups_diff: getgroups_glibc getgroups
+ -@ echo "-------"
+ -@ echo " "
+ -@ echo "Diffing output: "
+ -@ echo " "
+ -diff -u getgroups_glibc.out getgroups.out
+ -@ echo " "
+
clean:
$(RM) *.[oa] *~ core $(TARGETS) *.out
--- NEW FILE: getgroups.c ---
/* 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>
#include <err.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)
{
warn("cannot find name for group ID %u", 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)
err(EXIT_FAILURE, "out of memory");
ng = getgroups (max_n_groups, g);
if (ng < 0)
{
warn("cannot get supplemental group list");
++fail;
free (groups);
}
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;
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);
}
Index: pwcat.c
===================================================================
RCS file: /var/cvs/uClibc/test/pwd_grp/pwcat.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- pwcat.c 1 Nov 2003 04:49:27 -0000 1.1
+++ pwcat.c 2 Nov 2003 21:55:06 -0000 1.2
@@ -8,28 +8,18 @@
* Public Domain
*/
-#if HAVE_CONFIG_H
-#include <config.h>
-#endif
-
#include <stdio.h>
#include <pwd.h>
-
-#if defined (STDC_HEADERS)
#include <stdlib.h>
-#endif
-int
-main(argc, argv)
-int argc;
-char **argv;
+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);
+ 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;
More information about the uClibc-cvs
mailing list