From ccb13cfe7c506159412f124b17e1bba61a035913 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Thu, 9 Aug 2001 22:11:19 +0000 Subject: 2001-08-09 Fernando-Ruiz Casas * libc/getgrent.c, libc/getpwent.c: the 'ls' and more related command previous failed after a chroot(). (unknown user & group) --- cpukit/libcsupport/src/getgrent.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'cpukit/libcsupport/src/getgrent.c') diff --git a/cpukit/libcsupport/src/getgrent.c b/cpukit/libcsupport/src/getgrent.c index e4fc0fe474..104b0a317f 100644 --- a/cpukit/libcsupport/src/getgrent.c +++ b/cpukit/libcsupport/src/getgrent.c @@ -21,6 +21,9 @@ #include #include +#include + + static struct group gr_group; /* password structure */ static FILE *group_fp; @@ -47,11 +50,14 @@ int getgrnam_r( ) { FILE *fp; + rtems_user_env_t * aux=rtems_current_user_env; /* save */ init_etc_passwd_group(); + rtems_current_user_env=&rtems_global_user_env; /* set root */ if ((fp = fopen ("/etc/group", "r")) == NULL) { errno = EINVAL; + rtems_current_user_env=aux; /* restore */ return -1; } @@ -66,11 +72,13 @@ int getgrnam_r( if (!strcmp (groupname, name)) { fclose (fp); *result = grp; + rtems_current_user_env=aux; /* restore */ return 0; } } fclose (fp); errno = EINVAL; + rtems_current_user_env=aux; /* restore */ return -1; } @@ -96,11 +104,15 @@ int getgrgid_r( ) { FILE *fp; + rtems_user_env_t * aux=rtems_current_user_env; /* save */ + init_etc_passwd_group(); + rtems_current_user_env=&rtems_global_user_env; /* set root */ if ((fp = fopen ("/etc/group", "r")) == NULL) { errno = EINVAL; + rtems_current_user_env=aux; /* restore */ return -1; } @@ -116,11 +128,13 @@ int getgrgid_r( if (gid == gr_group.gr_gid) { fclose (fp); *result = grp; + rtems_current_user_env=aux; /* restore */ return 0; } } fclose (fp); errno = EINVAL; + rtems_current_user_env=aux; /* restore */ return -1; } @@ -160,12 +174,15 @@ struct group *getgrent( void ) void setgrent () { + rtems_user_env_t * aux=rtems_current_user_env; /* save */ init_etc_passwd_group(); + rtems_current_user_env=&rtems_global_user_env; /* set root */ if (group_fp != NULL) fclose (group_fp); group_fp = fopen ("/etc/group", "r"); + rtems_current_user_env=aux; /* restore */ } void -- cgit v1.2.3