cvs commit: ALFS/nALFS/src/handlers stage.c su.c

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Tue Dec 30 07:58:13 PST 2003


kpfleming    03/12/30 08:58:13

  Modified:    nALFS/src/handlers stage.c su.c
  Log:
  change handlers to use getpwent() instead of fgetpwent() so pw entries can come from sources other than /etc/passwd (if the user is using glibc NSS, for example)
  
  Revision  Changes    Path
  1.14      +3 -8      ALFS/nALFS/src/handlers/stage.c
  
  Index: stage.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/stage.c,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- stage.c	23 Nov 2003 19:38:16 -0000	1.13
  +++ stage.c	30 Dec 2003 15:58:13 -0000	1.14
  @@ -103,23 +103,18 @@
   static INLINE int change_to_user(const char *user)
   {
   	struct passwd *pw;
  -	FILE *fp;
   
   
  -	if ((fp = fopen("/etc/passwd", "r")) == NULL) {
  -		Nprint_h_err("Unable to open /etc/passwd: %s",
  -			strerror(errno));
  -		return -1;
  -	}
  +	setpwent();
   
   	/* getpwnam() is failing in chroot() */
  -	while ((pw = fgetpwent(fp))) {
  +	while ((pw = getpwent())) {
   		if (strcmp(pw->pw_name, user) == 0) {
   			break;
   		}
   	}
   
  -	fclose(fp);
  +	endpwent();
   
   	if (pw == NULL) {
   		Nprint_h_err("User %s doesn't exist.", user);
  
  
  
  1.13      +3 -8      ALFS/nALFS/src/handlers/su.c
  
  Index: su.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/su.c,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- su.c	6 Nov 2003 17:01:13 -0000	1.12
  +++ su.c	30 Dec 2003 15:58:13 -0000	1.13
  @@ -98,23 +98,18 @@
   static INLINE int change_to_user(const char *user)
   {
   	struct passwd *pw;
  -	FILE *fp;
   
   
  -	if ((fp = fopen("/etc/passwd", "r")) == NULL) {
  -		Nprint_h_err("Unable to open /etc/passwd: %s",
  -			strerror(errno));
  -		return -1;
  -	}
  +	setpwent();
   
   	/* getpwnam() is failing in chroot() */
  -	while ((pw = fgetpwent(fp))) {
  +	while ((pw = getpwent())) {
   		if (strcmp(pw->pw_name, user) == 0) {
   			break;
   		}
   	}
   
  -	fclose(fp);
  +	endpwent();
   
   	if (pw == NULL) {
   		Nprint_h_err("User %s doesn't exist.", user);
  
  
  



More information about the alfs-log mailing list