[Fusionforge-commits] r16015 - in trunk/src: common/include etc/config.ini.d www/admin
Olivier Berger
olberger at fusionforge.org
Thu Jul 19 15:49:00 CEST 2012
Author: olberger
Date: 2012-07-19 15:48:59 +0200 (Thu, 19 Jul 2012)
New Revision: 16015
Modified:
trunk/src/common/include/User.class.php
trunk/src/common/include/account.php
trunk/src/common/include/config-vars.php
trunk/src/etc/config.ini.d/defaults.ini
trunk/src/www/admin/admin_utils.php
Log:
Add new user_default_shell config var and use of /var/lib/gforge/chroot/etc/shells
Modified: trunk/src/common/include/User.class.php
===================================================================
--- trunk/src/common/include/User.class.php 2012-07-19 13:40:51 UTC (rev 16014)
+++ trunk/src/common/include/User.class.php 2012-07-19 13:48:59 UTC (rev 16015)
@@ -363,11 +363,12 @@
$this->setError(_('Invalid Unix Name.'));
return false;
}
+ $shell = account_get_user_default_shell();
// if we got this far, it must be good
$confirm_hash = substr(md5($password1 . util_randbytes() . microtime()),0,16);
db_begin();
- $result = db_query_params('INSERT INTO users (user_name,user_pw,unix_pw,realname,firstname,lastname,email,add_date,status,confirm_hash,mail_siteupdates,mail_va,language,timezone,jabber_address,jabber_only,unix_box,address,address2,phone,fax,title,ccode,theme_id,tooltips)
- VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25)',
+ $result = db_query_params('INSERT INTO users (user_name,user_pw,unix_pw,realname,firstname,lastname,email,add_date,status,confirm_hash,mail_siteupdates,mail_va,language,timezone,jabber_address,jabber_only,unix_box,address,address2,phone,fax,title,ccode,theme_id,tooltips,shell)
+ VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26)',
array($unix_name,
md5($password1),
account_genunixpw($password1),
@@ -392,7 +393,8 @@
htmlspecialchars($title),
$ccode,
$theme_id,
- $tooltips));
+ $tooltips,
+ $shell));
if (!$result) {
$this->setError(_('Insert Failed: ') . db_error());
db_rollback();
@@ -1054,17 +1056,11 @@
*/
function setShell($shell) {
global $SYS;
- $shells = file('/etc/shells');
- $shells[count($shells)] = "/bin/cvssh";
- $out_shells = array();
- foreach ($shells as $s) {
- if (substr($s, 0, 1) == '#') {
- continue;
- }
- $out_shells[] = chop($s);
- }
- if (!in_array($shell, $out_shells)) {
- $this->setError(_('ERROR: Invalid Shell'));
+
+ $shells = account_getavailableshells();
+
+ if (!in_array($shell, $shells)) {
+ $this->setError( sprintf(_('ERROR: Invalid Shell %s'), $shell) );
return false;
}
Modified: trunk/src/common/include/account.php
===================================================================
--- trunk/src/common/include/account.php 2012-07-19 13:40:51 UTC (rev 16014)
+++ trunk/src/common/include/account.php 2012-07-19 13:48:59 UTC (rev 16015)
@@ -199,26 +199,79 @@
}
/**
+ * account_get_user_default_shell() - return default user shell
+ *
+ */
+function account_get_user_default_shell() {
+ $user_default_shell = forge_get_config('user_default_shell');
+ if (! isset($user_default_shell)) {
+ // same as in DB schema before that config var was introduced
+ $user_default_shell = '/bin/bash';
+ }
+ return $user_default_shell;
+}
+
+/**
+ * account_getavailableshells() - return available shells for the users
+ *
+ */
+function account_getavailableshells($add_user_default_shell = TRUE) {
+ // we'd better use the shells defined inside the 'chroot' in /var/lib/gforge/chroot/etc/shells it it exists
+ $chroot = forge_get_config('chroot');
+ $shells_file = $chroot.'/etc/shells';
+ if(! file_exists($shells_file) ) {
+ // otherwise, fallback to /etc/shells
+ $shells_file = '/etc/shells';
+ }
+ $shells = file($shells_file);
+
+ $out_shells = array();
+ foreach ($shells as $s) {
+ if (substr($s, 0, 1) == '#') {
+ continue;
+ }
+ $out_shells[] = chop($s);
+ }
+ if ($add_user_default_shell) {
+ $user_default_shell = account_get_user_default_shell();
+ if (! file_exists($user_default_shell) ) {
+ // we'll always add cvssh if no other defaukt set ... TODO: explain why ?
+ $user_default_shell = "/bin/cvssh";
+ }
+ if (!in_array($user_default_shell, $out_shells)) {
+ $out_shells[count($out_shells)] = $user_default_shell;
+ }
+ }
+ return $out_shells;
+}
+
+/**
* account_shellselects() - Print out shell selects
*
* @param string The current shell
*
*/
function account_shellselects($current) {
- $shells = file("/etc/shells");
- $shells[count($shells)] = "/bin/cvssh";
+ $html = '';
- for ($i = 0; $i < count($shells); $i++) {
- $this_shell = chop($shells[$i]);
-
- if ($current == $this_shell) {
- echo "<option selected=\"selected\" value=$this_shell>$this_shell</option>\n";
- } else {
- if (! preg_match("/^#/",$this_shell)){
- echo "<option value=\"$this_shell\">$this_shell</option>\n";
- }
- }
+ $shells = account_getavailableshells();
+
+ $found = false;
+ for ($i = 0; $i < count($shells); $i++) {
+ $this_shell = $shells[$i];
+
+ if ($current == $this_shell) {
+ $found = true;
+ $html .= "<option selected=\"selected\" value=\"$this_shell\">$this_shell</option>\n";
+ } else {
+ $html .= "<option value=\"$this_shell\">$this_shell</option>\n";
+ }
+ }
+ if(! $found) {
+ // add the current option but unselectable -> defaults to cvssh if no other option in /var/lib/gforge/chroot/etc/shells
+ $html .= "<option value=\"$current\" disabled=\"disabled\">$current</option>\n";
}
+ echo $html;
}
/**
Modified: trunk/src/common/include/config-vars.php
===================================================================
--- trunk/src/common/include/config-vars.php 2012-07-19 13:40:51 UTC (rev 16014)
+++ trunk/src/common/include/config-vars.php 2012-07-19 13:48:59 UTC (rev 16015)
@@ -154,6 +154,8 @@
forge_define_config_item ('use_rdf', 'core', $GLOBALS['sys_use_rdf']) ;
forge_set_config_item_bool ('use_rdf', 'core') ;
forge_define_config_item ('installation_environment', 'core', $GLOBALS['sys_install_type']) ;
+ forge_define_config_item ('user_default_shell', 'core', '/bin/bash') ;
+
}
// Arch plugin
Modified: trunk/src/etc/config.ini.d/defaults.ini
===================================================================
--- trunk/src/etc/config.ini.d/defaults.ini 2012-07-19 13:40:51 UTC (rev 16014)
+++ trunk/src/etc/config.ini.d/defaults.ini 2012-07-19 13:48:59 UTC (rev 16015)
@@ -84,5 +84,6 @@
use_project_full_list = yes
allow_project_without_template = yes
use_webdav = no
+user_default_shell = "/bin/bash"
scm_single_host = yes
Modified: trunk/src/www/admin/admin_utils.php
===================================================================
--- trunk/src/www/admin/admin_utils.php 2012-07-19 13:40:51 UTC (rev 16014)
+++ trunk/src/www/admin/admin_utils.php 2012-07-19 13:48:59 UTC (rev 16015)
@@ -41,6 +41,11 @@
if (!function_exists("pg_pconnect")) {
$result[] = 'ERROR: Missing Postgresql support in PHP, please install/compile php-pg.';
}
+ $user_default_shell = forge_get_config('user_default_shell');
+ $shells = account_getavailableshells();
+ if (!in_array($user_default_shell, $shells)) {
+ $result[] = 'WARNING: default user shell "'. $user_default_shell .'" not in allowed shells (check ini var "user_default_shell" and contents of '. forge_get_config('chroot') .'/etc/shells or /etc/shells).';
+ }
return $result;
}
More information about the Fusionforge-commits
mailing list