From 3de860ad2d24f56af21326ddac35d62ab5b7bc04 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be>
Date: Mon, 12 Dec 2016 05:23:18 +0100
Subject: [PATCH] Fixes #5272 Add ability to select the default shell

---
 contrib/openldap/core-fd-conf.schema                 | 11 +++++++++--
 .../admin/departments/class_departmentManagement.inc |  2 +-
 plugins/config/class_configInLdap.inc                | 12 ++++++++++++
 plugins/personal/posix/class_posixAccount.inc        |  9 ++++++---
 4 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/contrib/openldap/core-fd-conf.schema b/contrib/openldap/core-fd-conf.schema
index dff0cbff2..b3e113fb5 100644
--- a/contrib/openldap/core-fd-conf.schema
+++ b/contrib/openldap/core-fd-conf.schema
@@ -394,7 +394,7 @@ attributetype ( 1.3.6.1.4.1.38414.8.18.2 NAME 'fdTabHook'
   SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )
 
 attributetype ( 1.3.6.1.4.1.38414.8.18.3 NAME 'fdShells'
-  DESC 'FusionDirectory - available shell'
+  DESC 'FusionDirectory - available shells'
   EQUALITY caseExactIA5Match
   SUBSTR caseExactIA5SubstringsMatch
   SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )
@@ -423,6 +423,13 @@ attributetype ( 1.3.6.1.4.1.38414.8.18.7 NAME 'fdDepartmentCategories'
   SUBSTR caseExactIA5SubstringsMatch
   SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )
 
+attributetype ( 1.3.6.1.4.1.38414.8.18.8 NAME 'fdDefaultShell'
+  DESC 'FusionDirectory - default shell'
+  EQUALITY caseExactIA5Match
+  SUBSTR caseExactIA5SubstringsMatch
+  SYNTAX 1.3.6.1.4.1.1466.115.121.1.26
+  SINGLE-VALUE)
+
 # Plugins
 
 attributetype ( 1.3.6.1.4.1.38414.8.19.1 NAME 'fdOGroupRDN'
@@ -597,7 +604,7 @@ objectclass ( 1.3.6.1.4.1.38414.8.2.1 NAME 'fusionDirectoryConf'
     fdHttpAuthActivated $ fdHttpHeaderAuthActivated $ fdHttpHeaderAuthHeaderName $
     fdDisplayErrors $ fdLdapMaxQueryTime $ fdLdapStats $ fdDebugLevel $
     fdEnableSnapshots $ fdSnapshotBase $
-    fdTabHook $ fdShells $ fdDisplayHookOutput $
+    fdTabHook $ fdShells $ fdDefaultShell $ fdDisplayHookOutput $
     fdAclTabOnObjects $ fdDepartmentCategories $
     fdRfc2307bis $ fdCopyPaste $ fdSnapshotURI $
     fdSnapshotAdminDn $ fdSnapshotAdminPassword $ fdPersonalTitleInDN $ fdAccountRDN $
diff --git a/plugins/admin/departments/class_departmentManagement.inc b/plugins/admin/departments/class_departmentManagement.inc
index b57f6f503..eccb920cb 100644
--- a/plugins/admin/departments/class_departmentManagement.inc
+++ b/plugins/admin/departments/class_departmentManagement.inc
@@ -27,7 +27,7 @@ class departmentManagement extends simpleManagement
   protected $departmentRootVisible  = FALSE;
   protected $baseMode               = TRUE;
 
-  /* Return plugin informations for acl handling */
+  /* Return plugin information for acl handling */
   static function plInfo()
   {
     return array(
diff --git a/plugins/config/class_configInLdap.inc b/plugins/config/class_configInLdap.inc
index 2a44f5647..8b29b79fd 100644
--- a/plugins/config/class_configInLdap.inc
+++ b/plugins/config/class_configInLdap.inc
@@ -458,6 +458,10 @@ class configInLdap extends simplePlugin
             array('/bin/ash','/bin/bash','/bin/csh','/bin/sh','/bin/ksh',
                   '/bin/tcsh','/bin/dash','/bin/zsh','/sbin/nologin', '/bin/false', '/usr/bin/git-shell')
           ),
+          new SelectAttribute (
+            _('Default shell'), _('Shell used by default when activating Unix tab.'),
+            'fdDefaultShell', TRUE
+          ),
           new BooleanAttribute (
             _('Show ACL tab on all objects'),
             _('For very specific ACL rights setting where you might need to give right on a single object.'),
@@ -499,6 +503,8 @@ class configInLdap extends simplePlugin
 
     $this->fusionConfigMd5 = md5_file(CACHE_DIR."/".CLASS_CACHE);
 
+    $this->attributesAccess['fdDefaultShell']->setChoices($this->fdShells);
+
     $this->attributesAccess['fdHttpAuthActivated']->setManagedAttributes(
       array(
         'erase' => array (
@@ -564,6 +570,12 @@ class configInLdap extends simplePlugin
     return $this->dn;
   }
 
+  function save_object()
+  {
+    parent::save_object();
+    $this->attributesAccess['fdDefaultShell']->setChoices($this->fdShells);
+  }
+
   static function get_themes()
   {
     $themesdir  = '../ihtml/themes/';
diff --git a/plugins/personal/posix/class_posixAccount.inc b/plugins/personal/posix/class_posixAccount.inc
index fa6282f6d..079fd325a 100644
--- a/plugins/personal/posix/class_posixAccount.inc
+++ b/plugins/personal/posix/class_posixAccount.inc
@@ -107,6 +107,7 @@ class posixAccount extends simplePlugin
   // The main function : information about attributes
   static function getAttributesInfo ()
   {
+    global $config;
     return array(
       'main' => array(
         'name'  => _('Unix'),
@@ -119,7 +120,9 @@ class posixAccount extends simplePlugin
           new StringAttribute('gecos', 'gecos', 'gecos'),
           new SelectAttribute(
             _('Shell'), _('Which shell should be used when this user log in'),
-            'loginShell', TRUE
+            'loginShell', TRUE,
+            $config->get_cfg_value('Shells', array(_('unconfigured'))),
+            $config->get_cfg_value('DefaultShell', '')
           ),
           new SelectAttribute(
             _('Primary group'), _('Primary group for this user'),
@@ -285,11 +288,11 @@ class posixAccount extends simplePlugin
     }
 
     /* Generate shell list from config */
-    $loginShellList = $config->get_cfg_value('Shells', array(_('unconfigured')));
+    $loginShellList = $this->attributesAccess['loginShell']->getChoices();
 
     /* Insert possibly missing loginShell */
     $loginShell = $this->attributesAccess['loginShell']->getValue();
-    if ($loginShell != "" && !in_array($loginShell, $loginShellList)) {
+    if (($loginShell != '') && !in_array($loginShell, $loginShellList)) {
       $loginShellList[] = $loginShell;
     }
     $this->attributesAccess['loginShell']->setChoices($loginShellList);
-- 
GitLab