allow to create Samba profile path via lamdaemon

This commit is contained in:
Roland Gruber 2013-02-27 18:56:23 +00:00
parent 4403ba7727
commit 94bb540b2c
3 changed files with 212 additions and 5 deletions

View File

@ -4,7 +4,7 @@
#
# This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
# Copyright (C) 2003 - 2006 Tilo Lutz
# Copyright (C) 2006 - 2011 Roland Gruber
# Copyright (C) 2006 - 2013 Roland Gruber
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -27,7 +27,7 @@ use Sys::Syslog;
# Defines the protocol version of the lamdaemon script.
# This will only be changed when additional commands are added etc.
my $LAMDAEMON_PROTOCOL_VERSION = 2;
my $LAMDAEMON_PROTOCOL_VERSION = 3;
my $SPLIT_DELIMITER = "###x##y##x###";
@ -125,6 +125,9 @@ elsif (($vals[1] eq 'test')) {
elsif ($vals[1] eq 'home') {
manageHomedirs();
}
elsif ($vals[1] eq 'directory') {
manageDirectories();
}
elsif ($vals[1] eq 'quota') {
manageQuotas();
}
@ -287,6 +290,51 @@ sub checkHomedir {
}
}
#
# Handles all directory related commands
#
sub manageDirectories {
if ($vals[2] eq 'add') {
createDirectory();
}
else {
# Show error if undefined command is used
$return = "ERROR,Lamdaemon ($hostname),Unknown home command $vals[2].";
logMessage(LOG_ERR, "Unknown command $vals[2]");
}
}
#
# Creates a directory of the user
#
sub createDirectory {
my $homedir = $vals[3];
if ($homedir eq '') {
$return = "ERROR,Lamdaemon ($hostname),No directory specified.";
logMessage(LOG_ERR, "No directory specified to create.");
return;
}
my $path = $homedir;
# split homedir to set all directories below the last dir. to 0755
$path =~ s,/(?:[^/]*)$,,;
($<, $>) = ($>, $<); # Get root privileges
if (! -e $path) {
system 'mkdir', '-m', '0755', '-p', $path; # Create paths to homedir
}
if (! -e $homedir) {
system 'mkdir', '-m', $vals[4], $homedir; # Create homedir itself
system 'chown', '-hR', "$vals[5]:$vals[6]" , $homedir; # Change owner to new user
system 'chmod', $vals[4], $homedir; # Edit chmod rights
$return = "INFO,Lamdaemon ($hostname),Directory created (" . $homedir . ").";
logMessage(LOG_INFO, "Directory created (" . $homedir . ")");
}
else {
$return = "ERROR,Lamdaemon ($hostname),Directory already exists (" . $homedir . ").";
logMessage(LOG_ERR, "Directory already exists (" . $homedir . ")");
}
($<, $>) = ($>, $<); # Give up root previleges
}
#
# Handles all quota related commands
#

View File

@ -64,6 +64,8 @@ class sambaSamAccount extends baseModule implements passwordService {
private $cachedGroupSIDList = null;
/** cache for domain list */
private $cachedDomainList = null;
/** delimiter for lamdaemon commands */
private static $SPLIT_DELIMITER = "###x##y##x###";
/**
@ -1188,7 +1190,18 @@ class sambaSamAccount extends baseModule implements passwordService {
if (isset($this->attributes['sambaProfilePath'][0])) {
$sambaProfilePath = $this->attributes['sambaProfilePath'][0];
}
$return->addElement(new htmlTableExtendedInputField(_('Profile path'), 'sambaProfilePath', $sambaProfilePath, 'profilePath'), true);
$return->addElement(new htmlOutputText(_('Profile path')));
$sambaProfilePathGroup = new htmlGroup();
$sambaProfilePathGroup->addElement(new htmlInputField('sambaProfilePath', $sambaProfilePath));
if (($_SESSION['config']->get_scriptPath() != null) && ($_SESSION['config']->get_scriptPath() != '')) {
if (get_preg($sambaProfilePath, 'homeDirectory')) {
$sambaProfilePathButton = new htmlAccountPageButton(get_class($this), 'profilePath', 'manage', '../graphics/folder.png', true);
$sambaProfilePathButton->setTitle(_('Manage profile directory'));
$sambaProfilePathGroup->addElement($sambaProfilePathButton);
}
}
$return->addElement($sambaProfilePathGroup);
$return->addElement(new htmlHelpLink('profilePath'), true);
}
// logon script
if (!$this->isBooleanConfigOptionSet('sambaSamAccount_hideLogonScript')) {
@ -1532,6 +1545,152 @@ class sambaSamAccount extends baseModule implements passwordService {
return $return;
}
/**
* Displays manage profile path page.
*
* @return htmlElement meta HTML code
*/
function display_html_profilePath() {
$return = new htmlTable();
$return->addElement(new htmlOutputText(_('Profile path')));
$return->addElement(new htmlSpacer('5px', null));
$return->addElement(new htmlOutputText($this->attributes['sambaProfilePath'][0]), true);
$return->addElement(new htmlSpacer(null, '10px'), true);
$homeServerContainer = new htmlTable();
$homeServerContainer->colspan = 5;
// get list of lamdaemon servers
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
for ($i = 0; $i < sizeof($lamdaemonServers); $i++) {
$temp = explode(":", $lamdaemonServers[$i]);
$server = $temp[0];
$label = $temp[0];
if (isset($temp[1])) {
$label = $temp[1];
}
$result = lamdaemon(
implode(
self::$SPLIT_DELIMITER,
array(
$this->attributes['uid'][0],
"home",
"check",
$this->attributes['sambaProfilePath'][0])
),
$server);
// lamdaemon results
if (is_array($result)) {
$returnValue = trim($result[0]);
if ($returnValue == 'ok') {
$homeServerContainer->addElement(new htmlOutputText($label));
$homeServerContainer->addElement(new htmlSpacer('5px', null));
$homeServerContainer->addElement(new htmlImage('../../graphics/pass.png', 16, 16));
$homeServerContainer->addElement(new htmlSpacer('5px', null));
$homeServerContainer->addElement(new htmlAccountPageButton(get_class($this), 'homedir', 'delete_' . $i, _('Delete')));
}
elseif ($returnValue == 'missing') {
$homeServerContainer->addElement(new htmlOutputText($label));
$homeServerContainer->addElement(new htmlSpacer('5px', null));
$homeServerContainer->addElement(new htmlImage('../../graphics/fail.png', 16, 16));
$homeServerContainer->addElement(new htmlSpacer('5px', null));
$homeServerContainer->addElement(new htmlAccountPageButton(get_class($this), 'homedir', 'create_' . $i, _('Create')));
}
elseif (trim($returnValue) != '') {
$messageParams = explode(",", $returnValue);
if (isset($messageParams[2])) {
$message = new htmlStatusMessage($messageParams[0], htmlspecialchars($messageParams[1]), htmlspecialchars($messageParams[2]));
}
elseif (($messageParams[0] == 'ERROR') || ($messageParams[0] == 'WARN') || ($messageParams[0] == 'INFO')) {
$message = new htmlStatusMessage($messageParams[0], htmlspecialchars($messageParams[1]));
}
else {
$message = new htmlStatusMessage('WARN', htmlspecialchars($messageParams[0]));
}
$message->colspan = 5;
$homeServerContainer->addElement($message, true);
}
$homeServerContainer->addNewLine();
}
}
$return->addElement($homeServerContainer, true);
$return->addElement(new htmlSpacer(null, '10px'), true);
$return->addElement(new htmlAccountPageButton(get_class($this), 'attributes', 'back', _('Back')));
return $return;
}
/**
* Processes user input of the profile path check page.
* It checks if all input values are correct and updates the associated LDAP attributes.
*
* @return array list of info/error messages
*/
function process_profilePath() {
$return = array();
$unixAttrs = $this->getAccountContainer()->getAccountModule('posixAccount')->getAttributes();
$uidNumber = $unixAttrs['uidNumber'][0];
$gidNumber = $unixAttrs['gidNumber'][0];
if (empty($uidNumber) || empty($gidNumber)) {
return;
}
// get list of lamdaemon servers
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
for ($i = 0; $i < sizeof($lamdaemonServers); $i++) {
$temp = explode(":", $lamdaemonServers[$i]);
$server = $temp[0];
if (isset($_POST['form_subpage_' . get_class($this) . '_homedir_create_' . $i])) {
$result = lamdaemon(
implode(
self::$SPLIT_DELIMITER,
array(
$this->attributes['uid'][0],
"directory",
"add",
$this->attributes['sambaProfilePath'][0],
"0".$_SESSION['config']->get_scriptRights(),
$uidNumber,
$gidNumber)
),
$server);
// lamdaemon results
if (is_array($result)) {
foreach ($result as $singleresult) {
$singleresult = explode(",", $singleresult);
if (is_array($singleresult)) {
if (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'WARN') || ($singleresult[0] == 'INFO')) {
$return[] = $singleresult;
}
}
}
}
}
elseif (isset($_POST['form_subpage_' . get_class($this) . '_homedir_delete_' . $i])) {
$result = lamdaemon(
implode(
self::$SPLIT_DELIMITER,
array(
$this->attributes['uid'][0],
"home",
"rem",
$this->attributes['sambaProfilePath'][0],
$uidNumber
)
),
$server);
// lamdaemon results
if (is_array($result)) {
foreach ($result as $singleresult) {
$singleresult = explode(",", $singleresult);
if (is_array($singleresult)) {
if (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'WARN') || ($singleresult[0] == 'INFO')) {
$return[] = $singleresult;
}
}
}
}
}
}
return $return;
}
/**
* Returns a list of elements for the account profiles.
*

View File

@ -3,7 +3,7 @@
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2006 - 2012 Roland Gruber
Copyright (C) 2006 - 2013 Roland Gruber
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -171,7 +171,7 @@ function lamTestLamdaemon($command, $stopTest, $handle, $testText, $container) {
*/
function lamRunLamdaemonTestSuite($serverName, $serverTitle, $testQuota, $container) {
$SPLIT_DELIMITER = "###x##y##x###";
$LAMDAEMON_PROTOCOL_VERSION = '2';
$LAMDAEMON_PROTOCOL_VERSION = '3';
$okImage = "../../graphics/pass.png";
$failImage = "../../graphics/fail.png";