/** * Create new system user * @access public * @param string $username System username * @param string $password Password * @param string $homedir Home directory * @param string $shell Shell path * @return SystemUser SystemUser instance */ public function Create($username, $password, $homedir = NULL, $shell = NULL) { // Check if skel exists if ($this->SkelDir && !is_readable($this->SkelDir)) Core::RaiseError(sprintf(_("User home skeleton directory (%s) not readable"), self::SKEL_DIR)); // Get default shell if (!$shell) $shell = $this->ShellPath; //Get default homedir if (!$homedir) $homedir = self::HOME_DIR ."/". $username; // Check useradd tool if (!is_executable($this->UserAddPath)) Core::RaiseError(sprintf(_("%s not executable"), $this->UserAddPath)); //Check chpasswd tool if (!is_executable($this->ChpasswdPath)) Core::RaiseError(sprintf(_("%s not executable"), $this->ChpasswdPath)); if ($this->SkelDir) $skeldir = "-k {$this->SkelDir}"; if ($this->SystemStats->IsFreeBSD) $args = "useradd {$username} -d {$homedir} -g {$this->UserGroup} {$skeldir} -s {$shell}"; else $args = " -d {$homedir} -s {$shell} -m {$skeldir} {$username}"; $retval = $this->Shell->ExecuteRaw("{$this->UserAddPath} {$args}"); if ($this->SystemStats->IsFreeBSD) $retval &= $this->Shell->ExecuteRaw("echo '{$password}' | {$this->ChpasswdPath} usermod {$username} $1 -h 0"); else $retval &= $this->Shell->ExecuteRaw("echo {$username}:{$password} | {$this->ChpasswdPath}"); // Return SystemUser or false $retval = $retval ? $this->GetUserByName($username) : false; return($retval); }