fix getHomeDir so it can find the home directory even if the id is not in /etc/passwd (for example in LDAP)
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@10692 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
		| @@ -1495,7 +1495,8 @@ sub getTftpDir | ||||
| =head3    getHomeDir | ||||
|  | ||||
|         Get the path the  user home directory from /etc/passwd. | ||||
|  | ||||
|         If /etc/passwd returns nothing ( id maybe in LDAP) then | ||||
|         su - userid -c  pwd to figure out where home is | ||||
|         Arguments: | ||||
|                 none | ||||
|         Returns: | ||||
| @@ -1506,6 +1507,7 @@ sub getTftpDir | ||||
|                 none | ||||
|         Example: | ||||
|                 $myHome = xCAT::Utils->getHomeDir(); | ||||
|                 $myHome = xCAT::Utils->getHomeDir($userid); | ||||
|         Comments: | ||||
|                 none | ||||
|  | ||||
| @@ -1517,6 +1519,7 @@ sub getHomeDir | ||||
| { | ||||
|     my ($class, $username) = @_; | ||||
|     my @user; | ||||
|     my $homedir; | ||||
|     if ($username) | ||||
|     { | ||||
|         @user = getpwnam($username); | ||||
| @@ -1524,8 +1527,16 @@ sub getHomeDir | ||||
|     else | ||||
|     { | ||||
|         @user = getpwuid($>); | ||||
|         $username=$user[0]; | ||||
|     } | ||||
|     return $user[7]; | ||||
|      | ||||
|     if ($user[7]) { #  if homedir  | ||||
|       $homedir= $user[7]; | ||||
|     } else { # no home | ||||
|       $homedir=`su - $username -c  pwd`; | ||||
|       chop $homedir;  | ||||
|     } | ||||
|     return $homedir; | ||||
| } | ||||
|  | ||||
| #-------------------------------------------------------------------------------- | ||||
|   | ||||
		Reference in New Issue
	
	Block a user