From 69d3b9bf3b4a1313ab345b49a7407d42ae9c4c9b Mon Sep 17 00:00:00 2001 From: hickert Date: Thu, 3 Apr 2008 09:52:45 +0000 Subject: [PATCH] Updated sudo git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@10133 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../plugins/admin/sudo/class_sudoOptions.inc | 143 ++++++++---------- gosa-core/plugins/admin/sudo/options.tpl | 4 +- 2 files changed, 70 insertions(+), 77 deletions(-) diff --git a/gosa-core/plugins/admin/sudo/class_sudoOptions.inc b/gosa-core/plugins/admin/sudo/class_sudoOptions.inc index 0b1572211..2bf27f823 100644 --- a/gosa-core/plugins/admin/sudo/class_sudoOptions.inc +++ b/gosa-core/plugins/admin/sudo/class_sudoOptions.inc @@ -34,66 +34,10 @@ class sudo_options extends plugin { plugin::plugin ($config, $dn); + /**** + Create a list of known options + ****/ $options = array(); - - $option['long_otp_prompt']= array('NAME' =>'long_otp_prompt' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['ignore_dot']= array('NAME' =>'ignore_dot' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['mail_always']= array('NAME' =>'mail_always' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['mail_badpass']= array('NAME' =>'mail_badpass' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['mail_no_user']= array('NAME' =>'mail_no_user' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['mail_no_host']= array('NAME' =>'mail_no_host' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['mail_no_perms']= array('NAME' =>'mail_no_perms' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['tty_tickets']= array('NAME' =>'tty_tickets' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['authenticate']= array('NAME' =>'authenticate' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['root_sudo']= array('NAME' =>'root_sudo' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['log_host']= array('NAME' =>'log_host' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['log_year']= array('NAME' =>'log_year' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['shell_noargs']= array('NAME' =>'shell_noargs' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['set_home']= array('NAME' =>'set_home' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['always_set_home']= array('NAME' =>'always_set_home' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['path_info']= array('NAME' =>'path_info' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['preserve_groups']= array('NAME' =>'preserve_groups' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['fqdn']= array('NAME' =>'fqdn' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['insults']= array('NAME' =>'insults' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['requiretty']= array('NAME' =>'requiretty' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['env_editor']= array('NAME' =>'env_editor' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['rootpw']= array('NAME' =>'rootpw' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['runaspw']= array('NAME' =>'runaspw' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['targetpw']= array('NAME' =>'targetpw' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['set_logname']= array('NAME' =>'set_logname' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['stay_setuid']= array('NAME' =>'stay_setuid' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['env_reset']= array('NAME' =>'env_reset' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['use_loginclass']= array('NAME' =>'use_loginclass' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['noexec']= array('NAME' =>'noexec' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['ignore_local_sudoers']= array('NAME' =>'ignore_local_sudoers' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['passwd_tries']= array('NAME' =>'passwd_tries' , 'TYPE' => 'INTEGER' , 'DEFAULT' => ''); - $option['loglinelen']= array('NAME' =>'loglinelen' , 'TYPE' => 'BOOL_INTEGER' , 'DEFAULT' => ''); - $option['timestamp_timeout']= array('NAME' =>'timestamp_timeout' , 'TYPE' => 'BOOL_INTEGER' , 'DEFAULT' => ''); - $option['passwd_timeout']= array('NAME' =>'passwd_timeout' , 'TYPE' => 'BOOL_INTEGER' , 'DEFAULT' => ''); - $option['umask']= array('NAME' =>'umask' , 'TYPE' => 'BOOL_INTEGER' , 'DEFAULT' => ''); - $option['mailsub']= array('NAME' =>'mailsub' , 'TYPE' => 'STRINGS' , 'DEFAULT' => ''); - $option['badpass_message']= array('NAME' =>'badpass_message' , 'TYPE' => 'STRINGS' , 'DEFAULT' => ''); - $option['timestampdir']= array('NAME' =>'timestampdir' , 'TYPE' => 'STRINGS' , 'DEFAULT' => ''); - $option['timestampowner']= array('NAME' =>'timestampowner' , 'TYPE' => 'STRINGS' , 'DEFAULT' => ''); - $option['passprompt']= array('NAME' =>'passprompt' , 'TYPE' => 'STRINGS' , 'DEFAULT' => ''); - $option['runas_default']= array('NAME' =>'runas_default' , 'TYPE' => 'STRINGS' , 'DEFAULT' => ''); - $option['syslog_goodpri']= array('NAME' =>'syslog_goodpri' , 'TYPE' => 'STRINGS' , 'DEFAULT' => ''); - $option['syslog_badpri']= array('NAME' =>'syslog_badpri' , 'TYPE' => 'STRINGS' , 'DEFAULT' => ''); - $option['editor']= array('NAME' =>'editor' , 'TYPE' => 'STRINGS' , 'DEFAULT' => ''); - $option['noexec_file']= array('NAME' =>'noexec_file' , 'TYPE' => 'STRINGS' , 'DEFAULT' => ''); - $option['lecture']= array('NAME' =>'lecture' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); - $option['lecture_file']= array('NAME' =>'lecture_file' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); - $option['logfile']= array('NAME' =>'logfile' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); - $option['syslog']= array('NAME' =>'syslog' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); - $option['mailerpath']= array('NAME' =>'mailerpath' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); - $option['mailerflags']= array('NAME' =>'mailerflags' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); - $option['mailto']= array('NAME' =>'mailto' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); - $option['exempt_group']= array('NAME' =>'exempt_group' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); - $option['verifypw']= array('NAME' =>'verifypw' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); - $option['listpw']= array('NAME' =>'listpw' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); - $option['env_check']= array('NAME' =>'env_check' , 'TYPE' => 'LISTS' , 'DEFAULT' => ''); - $option['env_delete']= array('NAME' =>'env_delete' , 'TYPE' => 'LISTS' , 'DEFAULT' => ''); - $option['env_keep']= array('NAME' =>'env_keep' , 'TYPE' => 'LISTS' , 'DEFAULT' => ''); $option['long_otp_prompt']= array('NAME' =>'long_otp_prompt' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); $option['ignore_dot']= array('NAME' =>'ignore_dot' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); $option['mail_always']= array('NAME' =>'mail_always' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); @@ -129,16 +73,16 @@ class sudo_options extends plugin $option['timestamp_timeout']= array('NAME' =>'timestamp_timeout' , 'TYPE' => 'BOOL_INTEGER' , 'DEFAULT' => ''); $option['passwd_timeout']= array('NAME' =>'passwd_timeout' , 'TYPE' => 'BOOL_INTEGER' , 'DEFAULT' => ''); $option['umask']= array('NAME' =>'umask' , 'TYPE' => 'BOOL_INTEGER' , 'DEFAULT' => ''); - $option['mailsub']= array('NAME' =>'mailsub' , 'TYPE' => 'STRINGS' , 'DEFAULT' => ''); - $option['badpass_message']= array('NAME' =>'badpass_message' , 'TYPE' => 'STRINGS' , 'DEFAULT' => ''); - $option['timestampdir']= array('NAME' =>'timestampdir' , 'TYPE' => 'STRINGS' , 'DEFAULT' => ''); - $option['timestampowner']= array('NAME' =>'timestampowner' , 'TYPE' => 'STRINGS' , 'DEFAULT' => ''); - $option['passprompt']= array('NAME' =>'passprompt' , 'TYPE' => 'STRINGS' , 'DEFAULT' => ''); - $option['runas_default']= array('NAME' =>'runas_default' , 'TYPE' => 'STRINGS' , 'DEFAULT' => ''); - $option['syslog_goodpri']= array('NAME' =>'syslog_goodpri' , 'TYPE' => 'STRINGS' , 'DEFAULT' => ''); - $option['syslog_badpri']= array('NAME' =>'syslog_badpri' , 'TYPE' => 'STRINGS' , 'DEFAULT' => ''); - $option['editor']= array('NAME' =>'editor' , 'TYPE' => 'STRINGS' , 'DEFAULT' => ''); - $option['noexec_file']= array('NAME' =>'noexec_file' , 'TYPE' => 'STRINGS' , 'DEFAULT' => ''); + $option['mailsub']= array('NAME' =>'mailsub' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); + $option['badpass_message']= array('NAME' =>'badpass_message' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); + $option['timestampdir']= array('NAME' =>'timestampdir' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); + $option['timestampowner']= array('NAME' =>'timestampowner' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); + $option['passprompt']= array('NAME' =>'passprompt' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); + $option['runas_default']= array('NAME' =>'runas_default' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); + $option['syslog_goodpri']= array('NAME' =>'syslog_goodpri' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); + $option['syslog_badpri']= array('NAME' =>'syslog_badpri' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); + $option['editor']= array('NAME' =>'editor' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); + $option['noexec_file']= array('NAME' =>'noexec_file' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); $option['lecture']= array('NAME' =>'lecture' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); $option['lecture_file']= array('NAME' =>'lecture_file' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); $option['logfile']= array('NAME' =>'logfile' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); @@ -155,26 +99,43 @@ class sudo_options extends plugin ksort($option); $this->options = $option; - + /**** + Parse given sudoOption attributes + ****/ $this->sudoOption = array(); - if(isset($this->attrs['sudoOption'])){ for($i = 0 ; $i < $this->attrs['sudoOption']['count']; $i++){ - $negation = FALSE; - $value = ""; - + /**** + Detect attribute name/value/negation + ****/ $opt = $this->attrs['sudoOption'][$i]; + + /* Get negation */ + $negation = FALSE; if(preg_match("/^!/",$opt)){ $negation = TRUE; $opt = preg_replace("/^!/","",$opt); } + /* Get value / name*/ + $value = ""; if(preg_match("/=/",$opt)){ $value = preg_replace("/^[^=]*+=/","",$opt); $opt = preg_replace("/=.*$/","",$opt); } + /* Check if the given value is part of our options list. + If it is not, add it as type STRING and display a warning. + */ + if(!isset($this->options[$opt])){ + $this->options[$opt]=array('NAME'=>$opt,'TYPE'=>'STRING','DEFAULT' => ''); + msg_dialog::display(_("Unknown option"), + sprintf(_("The sudo option '%s' is unkown to GOsa, it is now temporarily added as type string."), + $opt),WARNING_DIALOG); + } + + /* Create internal sudoOption object */ $option = array(); $option['NAME'] = $opt; $option['VALUE'] = array($value); @@ -195,6 +156,7 @@ class sudo_options extends plugin } } + /* Special handling for BOOLEAN values */ if(in_array($this->options[$opt]['TYPE'],array("BOOLEAN"))){ $option['NEGATE'] = FALSE; if($negation){ @@ -204,6 +166,7 @@ class sudo_options extends plugin } } + /* Append values */ if(!isset($this->sudoOption[$opt])){ $this->sudoOption[$opt] = $option; }else{ @@ -218,6 +181,9 @@ class sudo_options extends plugin /* Call parent execute */ plugin::execute(); + /***** + Handle Posts + *****/ foreach($_POST as $name => $value){ if(preg_match("/^negOption_/",$name)){ $opt = preg_replace("/^negOption_/","",$name); @@ -260,11 +226,24 @@ class sudo_options extends plugin } break; } + + if(preg_match("/^delOption_/",$name)){ + + /***** + Remove options + *****/ + $opt = preg_replace("/^delOption_/","",$name); + $opt = preg_replace("/_[^_]*$/","",$opt); + if(isset($this->sudoOption[$opt])){ + unset($this->sudoOption[$opt]); + } + break; + } } $smarty = get_smarty(); - $smarty->assign("map", array("STRINGS" => _("string"), "BOOLEAN" => _("bool"), + $smarty->assign("map", array("STRING" => _("string"), "BOOLEAN" => _("bool"), "INTEGER" => _("integer") , "BOOL_INTEGER" => _("integer")."-"._("bool") , "STRING_BOOL" => _("string")."-"._("bool"),"LISTS" => _("lists"))); $smarty->assign("sudoOption",$this->sudoOption); @@ -281,13 +260,25 @@ class sudo_options extends plugin { plugin::save_object(); + if(isset($_POST['add_option']) && isset($_POST['option'])){ + $opt = get_post("option"); + if(isset($this->options[$opt]) && !isset($this->sudoOption[$opt])){ + $type = $this->options[$opt]['TYPE']; + $val = array($this->options[$opt]['DEFAULT']); + $option = array("NAME" => $opt, "VALUE" => $val , "NEGATE" => FALSE); + $this->sudoOption[$opt] = $option; + } + } + foreach($this->sudoOption as $name => $opt){ /**** Get posted value for BOOLEAN ****/ if(in_array($this->options[$name]['TYPE'],array("BOOLEAN"))){ - $this->sudoOption[$name]['VALUE'][0] = get_post('option_value__'.$name); + if(isset($_POST['option_value__'.$name])){ + $this->sudoOption[$name]['VALUE'][0] = get_post('option_value__'.$name); + } } /**** diff --git a/gosa-core/plugins/admin/sudo/options.tpl b/gosa-core/plugins/admin/sudo/options.tpl index 94685e32e..c1dbe46da 100644 --- a/gosa-core/plugins/admin/sudo/options.tpl +++ b/gosa-core/plugins/admin/sudo/options.tpl @@ -1,10 +1,12 @@ - + {foreach from=$sudoOption item=item key=key} -- 2.30.2