[3215] in Athena Bugs

home help back first fref pref prev next nref lref last post

su: getwd: can't stat . (Did you su in a fascist directory?)

daemon@ATHENA.MIT.EDU (qjb@ATHENA.MIT.EDU)
Fri Sep 15 12:37:57 1989

From: <qjb@ATHENA.MIT.EDU>
Date: Fri, 15 Sep 89 12:37:29 -0400
To: bugs@ATHENA.MIT.EDU

The problem with not being able to su from a restricted
directory has been one that we have been dealing with for some
time.  The following patch provides a very simple solution:

**=> /paris/source <=**
soup% su
Password:
getwd: can't stat .
(Did you su in a fascist directory?)

Exit 1               su
**=> /paris/source <=**
soup% /mit/qjb/tmp/su
Password:
Warning: changing working directory to /.
**=> / <=**
soup#


Here's the patch:

=======================

*** /paris/source/4.3/bin/su.c	Thu Mar 10 16:30:13 1988
--- /mit/qjb/tmp/su.c	Fri Sep 15 12:31:20 1989
***************
*** 31,36 ****
--- 31,37 ----
  #include <sys/time.h>
  #include <sys/resource.h>
  #include <sys/stat.h>
+ #include <sys/param.h>
  
  char	userbuf[16]	= "USER=";
  char	homebuf[128]	= "HOME=";
***************
*** 61,66 ****
--- 62,68 ----
  	char *mytty;
  	FILE *fp;
  	register char *p;
+ 	char working_dir[MAXPATHLEN];
  
  	openlog("su", LOG_ODELAY, LOG_AUTH);
  
***************
*** 178,183 ****
--- 180,190 ----
  		*argv = "-su";
  	} else
  		*argv = "su";
+ 	bzero(working_dir, sizeof(working_dir));
+ 	if (getwd(working_dir) == 0) {
+ 	    fprintf(stderr, "Warning: changing working directory to /.\n");
+ 	    chdir("/");
+ 	}
  	execv(shell, argv);
  	fprintf(stderr, "No shell\n");
  	exit(7);

=========================


I think this is worthy of inclusion in the release.  This not
only takes care of the problem of suing in a restricted
directory but of any other problem that getwd may encounter...

                                Jay

home help back first fref pref prev next nref lref last post