From 40084edcaa45688d03279acca8aad09c68b8c9e9 Mon Sep 17 00:00:00 2001 From: lissav Date: Mon, 3 Oct 2011 19:03:03 +0000 Subject: [PATCH] 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 --- perl-xCAT/xCAT/Utils.pm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/perl-xCAT/xCAT/Utils.pm b/perl-xCAT/xCAT/Utils.pm index 1c59d3629..efcbaabe9 100644 --- a/perl-xCAT/xCAT/Utils.pm +++ b/perl-xCAT/xCAT/Utils.pm @@ -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; } #--------------------------------------------------------------------------------