Fix "default" case in switch statement

Format code
Add hgignore file
This commit is contained in:
Andreas Boehler 2014-11-12 21:45:11 +01:00
parent 7d18f65f67
commit 2e83d3a059
6 changed files with 562 additions and 506 deletions

2
.hgignore Normal file
View File

@ -0,0 +1,2 @@
.project
.settings

View File

@ -12,25 +12,33 @@ OCP\JSON::callCheck();
$l = new OC_L10N('use_sql'); $l = new OC_L10N('use_sql');
$params = array('sql_host', 'sql_user', 'sql_database', 'sql_password', $params = array('sql_host', 'sql_user', 'sql_database', 'sql_password',
'sql_table', 'sql_column_username', 'sql_column_password', 'sql_table', 'sql_column_username', 'sql_column_password', 'sql_type',
'sql_type', 'sql_column_active', 'strip_domain', 'default_domain', 'sql_column_active', 'strip_domain', 'default_domain', 'crypt_type',
'crypt_type', 'sql_column_displayname', 'domain_settings', 'map_array', 'domain_array'); 'sql_column_displayname', 'domain_settings', 'map_array', 'domain_array');
if (isset($_POST['appname']) && $_POST['appname'] == "user_sql") { if(isset($_POST['appname']) && $_POST['appname'] == "user_sql")
foreach ($params as $param) { {
if (isset($_POST[$param])) { foreach($params as $param)
if ($param === 'strip_domain') { {
if(isset($_POST[$param]))
{
if($param === 'strip_domain')
{
OCP\Config::setAppValue('user_sql', 'strip_domain', true); OCP\Config::setAppValue('user_sql', 'strip_domain', true);
} else { } else
{
OCP\Config::setAppValue('user_sql', $param, $_POST[$param]); OCP\Config::setAppValue('user_sql', $param, $_POST[$param]);
} }
} else { } else
if ($param === 'strip_domain') { {
if($param === 'strip_domain')
{
OCP\Config::setAppValue('user_sql', 'strip_domain', false); OCP\Config::setAppValue('user_sql', 'strip_domain', false);
} }
} }
} }
} else { } else
{
OC_JSON::error(array("data" => array("message" => $l -> t("Not submitted for us.")))); OC_JSON::error(array("data" => array("message" => $l -> t("Not submitted for us."))));
return false; return false;
} }

View File

@ -1,29 +1,29 @@
// declare namespace // declare namespace
var user_sql = user_sql || {}; var user_sql = user_sql ||
{
};
user_sql.adminSettingsCheckRadio = function() { user_sql.adminSettingsCheckRadio = function()
{
if($('#domain_none').attr("checked") == "checked") if($('#domain_none').attr("checked") == "checked")
{ {
$('#default_domain').attr("disabled", true); $('#default_domain').attr("disabled", true);
$('#inputServerDomain').attr("disabled", true); $('#inputServerDomain').attr("disabled", true);
$('#inputMapDomain').attr("disabled", true); $('#inputMapDomain').attr("disabled", true);
$('#domainAddMap').attr("disabled", true); $('#domainAddMap').attr("disabled", true);
} } else if($('#domain_server').attr("checked") == "checked")
else if($('#domain_server').attr("checked") == "checked")
{ {
$('#default_domain').attr("disabled", true); $('#default_domain').attr("disabled", true);
$('#inputServerDomain').attr("disabled", true); $('#inputServerDomain').attr("disabled", true);
$('#inputMapDomain').attr("disabled", true); $('#inputMapDomain').attr("disabled", true);
$('#domainAddMap').attr("disabled", true); $('#domainAddMap').attr("disabled", true);
} } else if($('#domain_mapping').attr("checked") == "checked")
else if($('#domain_mapping').attr("checked") == "checked")
{ {
$('#default_domain').attr("disabled", true); $('#default_domain').attr("disabled", true);
$('#inputServerDomain').removeAttr("disabled"); $('#inputServerDomain').removeAttr("disabled");
$('#inputMapDomain').removeAttr("disabled"); $('#inputMapDomain').removeAttr("disabled");
$('#domainAddMap').removeAttr("disabled"); $('#domainAddMap').removeAttr("disabled");
} } else if($('#domain_default').attr("checked") == "checked")
else if($('#domain_default').attr("checked") == "checked")
{ {
$('#default_domain').removeAttr("disabled"); $('#default_domain').removeAttr("disabled");
$('#inputServerDomain').attr("disabled", true); $('#inputServerDomain').attr("disabled", true);
@ -34,20 +34,24 @@ user_sql.adminSettingsCheckRadio = function() {
/** /**
* init admin settings view * init admin settings view
*/ */
user_sql.adminSettingsUI = function() { user_sql.adminSettingsUI = function()
{
if ($('#sql').length > 0) { if($('#sql').length > 0)
{
// enable tabs on settings page // enable tabs on settings page
$('#sql').tabs(); $('#sql').tabs();
$('#sqlSubmit').click(function(event) { $('#sqlSubmit').click(function(event)
{
event.preventDefault(); event.preventDefault();
var self = $(this); var self = $(this);
var post = $('#sqlForm').serializeArray(); var post = $('#sqlForm').serializeArray();
var domainArr = new Array(); var domainArr = new Array();
var mapArr = new Array(); var mapArr = new Array();
$('#domain_map_entries tr').each(function() { $('#domain_map_entries tr').each(function()
{
var d = $(this).find("td:first").html(); var d = $(this).find("td:first").html();
var m = $(this).find("td").eq(1).html(); var m = $(this).find("td").eq(1).html();
if(d != undefined && m != undefined) if(d != undefined && m != undefined)
@ -56,21 +60,33 @@ user_sql.adminSettingsUI = function() {
domainArr.push(d); domainArr.push(d);
} }
}); });
post.push({name: 'map_array', value: mapArr}); post.push(
post.push({name: 'domain_array', value: domainArr}); {
name : 'map_array',
value : mapArr
});
post.push(
{
name : 'domain_array',
value : domainArr
});
$('#sql_update_message').show(); $('#sql_update_message').show();
$('#sql_success_message').hide(); $('#sql_success_message').hide();
$('#sql_error_message').hide(); $('#sql_error_message').hide();
// Ajax foobar // Ajax foobar
$.post(OC.filePath('user_sql', 'ajax', 'settings.php'), post, function(data) { $.post(OC.filePath('user_sql', 'ajax', 'settings.php'), post, function(data)
{
$('#sql_update_message').hide(); $('#sql_update_message').hide();
if (data.status == 'success') { if(data.status == 'success')
{
$('#sql_success_message').html(data.data.message); $('#sql_success_message').html(data.data.message);
$('#sql_success_message').show(); $('#sql_success_message').show();
window.setTimeout(function() { window.setTimeout(function()
{
$('#sql_success_message').hide(); $('#sql_success_message').hide();
}, 10000); }, 10000);
} else { } else
{
$('#sql_error_message').html(data.data.message); $('#sql_error_message').html(data.data.message);
$('#sql_error_message').show(); $('#sql_error_message').show();
} }
@ -78,33 +94,40 @@ user_sql.adminSettingsUI = function() {
return false; return false;
}); });
$('#domain_none').click(function(event) { $('#domain_none').click(function(event)
{
user_sql.adminSettingsCheckRadio(); user_sql.adminSettingsCheckRadio();
}); });
$('#domain_server').click(function(event) { $('#domain_server').click(function(event)
{
user_sql.adminSettingsCheckRadio(); user_sql.adminSettingsCheckRadio();
}); });
$('#domain_mapping').click(function(event) { $('#domain_mapping').click(function(event)
{
user_sql.adminSettingsCheckRadio(); user_sql.adminSettingsCheckRadio();
}); });
$('#domain_default').click(function(event) { $('#domain_default').click(function(event)
{
user_sql.adminSettingsCheckRadio(); user_sql.adminSettingsCheckRadio();
}); });
$('#domainAddMap').click(function(event) { $('#domainAddMap').click(function(event)
{
event.preventDefault(); event.preventDefault();
var newDomain = $('#inputServerDomain').val(); var newDomain = $('#inputServerDomain').val();
var newMap = $('#inputMapDomain').val(); var newMap = $('#inputMapDomain').val();
$('#domain_map_entries > tbody:last').append('<tr><td>' + newDomain + '</td><td>' + newMap + '</td><td><a class="deleteLink" href="#" >delete</a></td></tr>'); $('#domain_map_entries > tbody:last').append('<tr><td>' + newDomain + '</td><td>' + newMap + '</td><td><a class="deleteLink" href="#" >delete</a></td></tr>');
$('#inputServerDomain').val(""); $('#inputServerDomain').val("");
$('#inputMapDomain').val(""); $('#inputMapDomain').val("");
$("#domain_map_entries .deleteLink").on("click",function() { $("#domain_map_entries .deleteLink").on("click", function()
{
var tr = $(this).closest('tr'); var tr = $(this).closest('tr');
tr.css("background-color", "#FF3700"); tr.css("background-color", "#FF3700");
tr.fadeOut(400, function(){ tr.fadeOut(400, function()
{
tr.remove(); tr.remove();
}); });
return false; return false;
@ -113,15 +136,19 @@ user_sql.adminSettingsUI = function() {
} }
}; };
$(document).ready(function() { $(document).ready(function()
if ($('#sql')) { {
if($('#sql'))
{
user_sql.adminSettingsUI(); user_sql.adminSettingsUI();
user_sql.adminSettingsCheckRadio(); user_sql.adminSettingsCheckRadio();
$("#domain_map_entries .deleteLink").on("click",function() { $("#domain_map_entries .deleteLink").on("click", function()
{
var tr = $(this).closest('tr'); var tr = $(this).closest('tr');
tr.css("background-color", "#FF3700"); tr.css("background-color", "#FF3700");
tr.fadeOut(400, function(){ tr.fadeOut(400, function()
{
tr.remove(); tr.remove();
}); });
return false; return false;

View File

@ -20,10 +20,9 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
$params = array('sql_host', 'sql_user', 'sql_database', 'sql_password', $params = array('sql_host', 'sql_user', 'sql_database', 'sql_password', 'sql_table',
'sql_table', 'sql_column_username', 'sql_column_password', 'sql_column_username', 'sql_column_password', 'sql_type', 'sql_column_active',
'sql_type', 'sql_column_active', 'strip_domain', 'default_domain', 'strip_domain', 'default_domain', 'crypt_type', 'sql_column_displayname', 'domain_map', 'domain_settings');
'crypt_type', 'sql_column_displayname', 'domain_map', 'domain_settings');
OCP\Util::addStyle('user_sql', 'settings'); OCP\Util::addStyle('user_sql', 'settings');
OCP\Util::addScript('user_sql', 'settings'); OCP\Util::addScript('user_sql', 'settings');
@ -31,7 +30,8 @@ OCP\User::checkAdminUser();
// fill template // fill template
$tmpl = new OCP\Template('user_sql', 'settings'); $tmpl = new OCP\Template('user_sql', 'settings');
foreach($params as $param){ foreach($params as $param)
{
$value = htmlentities(OCP\Config::getAppValue('user_sql', $param, '')); $value = htmlentities(OCP\Config::getAppValue('user_sql', $param, ''));
$tmpl -> assign($param, $value); $tmpl -> assign($param, $value);
} }
@ -57,5 +57,4 @@ $tmpl->assign( 'domain_settings', OCP\Config::getAppValue( 'user_sql', 'domain_s
$ocVersion = @reset(OCP\Util::getVersion()); $ocVersion = @reset(OCP\Util::getVersion());
$tmpl -> assign('ocVersion', $ocVersion); $tmpl -> assign('ocVersion', $ocVersion);
return $tmpl -> fetchPage(); return $tmpl -> fetchPage();

View File

@ -1,7 +1,5 @@
<?php <?php $ocVersion = $_['ocVersion'];
$ocVersion = $_['ocVersion'];
$cfgClass = $ocVersion >= 7 ? 'section' : 'personalblock'; $cfgClass = $ocVersion >= 7 ? 'section' : 'personalblock';
?> ?>
@ -28,7 +26,8 @@ $cfgClass = $ocVersion >= 7 ? 'section' : 'personalblock';
<?php else: ?> <?php else: ?>
<option value="<?php echo $driver; ?>"><?php echo $name; ?></option> <option value="<?php echo $driver; ?>"><?php echo $name; ?></option>
<?php endif; <?php endif;
endforeach; ?> endforeach;
?>
</select></td> </select></td>
</tr> </tr>
@ -55,7 +54,8 @@ $cfgClass = $ocVersion >= 7 ? 'section' : 'personalblock';
<?php else: ?> <?php else: ?>
<option value="<?php echo $driver; ?>"><?php echo $name; ?></option> <option value="<?php echo $driver; ?>"><?php echo $name; ?></option>
<?php endif; <?php endif;
endforeach; ?> endforeach;
?>
</select></td> </select></td>
</tr> </tr>
<tr><td><label for="sql_column_active"><?php echo $l -> t('User Active Column'); ?></label></td><td><input type="text" id="sql_column_active" name="sql_column_active" value="<?php echo $_['sql_column_active']; ?>" /></td></tr> <tr><td><label for="sql_column_active"><?php echo $l -> t('User Active Column'); ?></label></td><td><input type="text" id="sql_column_active" name="sql_column_active" value="<?php echo $_['sql_column_active']; ?>" /></td></tr>
@ -64,15 +64,26 @@ $cfgClass = $ocVersion >= 7 ? 'section' : 'personalblock';
<fieldset id="sql-3"> <fieldset id="sql-3">
<table> <table>
<tr><td><label for="domain_settings"><?php echo $l -> t('Domain Settings'); ?></label></td><td><table> <tr><td><label for="domain_settings"><?php echo $l -> t('Domain Settings'); ?></label></td><td><table>
<tr><td><input type="radio" name="domain_settings" id="domain_none" value="none" <?php if($_['domain_settings'] == "") echo 'checked="checked"'; ?>><?php echo $l->t('No Mapping') ?></td></tr> <tr><td><input type="radio" name="domain_settings" id="domain_none" value="none" <?php
<tr><td><input type="radio" name="domain_settings" id="domain_server" value="server" <?php if($_['domain_settings'] == "server") echo 'checked="checked"'; ?>><?php echo $l->t('Append Server Hostname') ?></td><td></td></tr> if($_['domain_settings'] == "")
<tr><td><input type="radio" name="domain_settings" id="domain_default" value="default" <?php if($_['domain_settings'] == "default") echo 'checked="checked"'; ?>><?php echo $l->t('Append Default') ?></td><td><input type="text" id="default_domain" name="default_domain" value="<?php echo $_['default_domain']; ?>" /></td></tr> echo 'checked="checked"';
<tr><td><input type="radio" name="domain_settings" id="domain_mapping" value="mapping" <?php if($_['domain_settings'] == "mapping") echo 'checked="checked"'; ?>><?php echo $l->t('Map Domains') ?></td><td> ?>><?php echo $l->t('No Mapping') ?></td></tr>
<tr><td><input type="radio" name="domain_settings" id="domain_server" value="server" <?php
if($_['domain_settings'] == "server")
echo 'checked="checked"';
?>><?php echo $l->t('Append Server Hostname') ?></td><td></td></tr>
<tr><td><input type="radio" name="domain_settings" id="domain_default" value="default" <?php
if($_['domain_settings'] == "default")
echo 'checked="checked"';
?>><?php echo $l->t('Append Default') ?></td><td><input type="text" id="default_domain" name="default_domain" value="<?php echo $_['default_domain']; ?>" /></td></tr>
<tr><td><input type="radio" name="domain_settings" id="domain_mapping" value="mapping" <?php
if($_['domain_settings'] == "mapping")
echo 'checked="checked"';
?>><?php echo $l->t('Map Domains') ?></td><td>
<table id="domain_map_entries" cellspacing="2" cellpadding="2"> <table id="domain_map_entries" cellspacing="2" cellpadding="2">
<tbody> <tbody>
<tr><th><input type="text" placeholder="Server Domain" id="inputServerDomain"></th><th><input type="text" placeholder="Map to Domain" id="inputMapDomain"></th><th><input id="domainAddMap" type="submit" value="<?php echo $l -> t('Add Entry'); ?>" /></th></tr> <tr><th><input type="text" placeholder="Server Domain" id="inputServerDomain"></th><th><input type="text" placeholder="Map to Domain" id="inputMapDomain"></th><th><input id="domainAddMap" type="submit" value="<?php echo $l -> t('Add Entry'); ?>" /></th></tr>
<?php <?php $domains = explode(",", $_['domain_array']);
$domains = explode(",", $_['domain_array']);
$maps = explode(",", $_['map_array']); $maps = explode(",", $_['map_array']);
for($i = 0; $i < count($domains); $i++) for($i = 0; $i < count($domains); $i++)
{ {
@ -83,7 +94,10 @@ $cfgClass = $ocVersion >= 7 ? 'section' : 'personalblock';
</tbody> </tbody>
</table></td></tr> </table></td></tr>
</table></td></tr> </table></td></tr>
<tr><td><label for="strip_domain"><?php echo $l->t('Strip Domain Part from Username');?></label></td><td><input type="checkbox" id="strip_domain" name="strip_domain" value="1"<?php if($_['strip_domain']) echo ' checked'; ?> title="Strip Domain Part from Username when logging in and retrieving username lists"></td></tr> <tr><td><label for="strip_domain"><?php echo $l -> t('Strip Domain Part from Username'); ?></label></td><td><input type="checkbox" id="strip_domain" name="strip_domain" value="1"<?php
if($_['strip_domain'])
echo ' checked';
?> title="Strip Domain Part from Username when logging in and retrieving username lists"></td></tr>
</table> </table>
</fieldset> </fieldset>

View File

@ -25,7 +25,8 @@
* *
*/ */
class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface { class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface
{
protected $cache; protected $cache;
// cached settings // cached settings
protected $sql_host; protected $sql_host;
@ -72,8 +73,7 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
{ {
$this -> db = new PDO($dsn, $this -> sql_username, $this -> sql_password); $this -> db = new PDO($dsn, $this -> sql_username, $this -> sql_password);
$this -> db_conn = true; $this -> db_conn = true;
} } catch (PDOException $e)
catch (PDOException $e)
{ {
OC_Log::write('OC_USER_SQL', 'Failed to connect to the database: ' . $e -> getMessage(), OC_Log::ERROR); OC_Log::write('OC_USER_SQL', 'Failed to connect to the database: ' . $e -> getMessage(), OC_Log::ERROR);
} }
@ -86,9 +86,6 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
switch($this->domain_settings) switch($this->domain_settings)
{ {
case "none":
OC_Log::write('OC_USER_SQL', "No mapping", OC_Log::DEBUG);
break;
case "default" : case "default" :
OC_Log::write('OC_USER_SQL', "Default mapping", OC_Log::DEBUG); OC_Log::write('OC_USER_SQL', "Default mapping", OC_Log::DEBUG);
if($this -> default_domain && (strpos($uid, '@') === false)) if($this -> default_domain && (strpos($uid, '@') === false))
@ -115,9 +112,12 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
} }
} }
break; break;
case "none" :
default :
OC_Log::write('OC_USER_SQL', "No mapping", OC_Log::DEBUG);
break;
} }
$uid = strtolower($uid); $uid = strtolower($uid);
OC_Log::write('OC_USER_SQL', 'Returning mapped UID: ' . $uid, OC_Log::DEBUG); OC_Log::write('OC_USER_SQL', 'Returning mapped UID: ' . $uid, OC_Log::DEBUG);
return $uid; return $uid;
@ -128,11 +128,13 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
return (bool)((OC_USER_BACKEND_CHECK_PASSWORD | OC_USER_BACKEND_GET_DISPLAYNAME) & $actions); return (bool)((OC_USER_BACKEND_CHECK_PASSWORD | OC_USER_BACKEND_GET_DISPLAYNAME) & $actions);
} }
public function hasUserListings() { public function hasUserListings()
{
return true; return true;
} }
public function createUser() { public function createUser()
{
// Can't create user // Can't create user
OC_Log::write('OC_USER_SQL', 'Not possible to create local users from web frontend using SQL user backend', OC_Log::ERROR); OC_Log::write('OC_USER_SQL', 'Not possible to create local users from web frontend using SQL user backend', OC_Log::ERROR);
return false; return false;
@ -145,8 +147,10 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
return false; return false;
} }
public function setPassword ( $uid, $password ) { public function setPassword($uid, $password)
// Update the user's password - this might affect other services, that user the same database, as well {
// Update the user's password - this might affect other services, that
// user the same database, as well
OC_Log::write('OC_USER_SQL', "Entering setPassword for UID: $uid", OC_Log::DEBUG); OC_Log::write('OC_USER_SQL', "Entering setPassword for UID: $uid", OC_Log::DEBUG);
if(!$this -> db_conn) if(!$this -> db_conn)
{ {
@ -235,8 +239,7 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
$uid = $uid[0]; $uid = $uid[0];
} }
return $uid; return $uid;
} } else
else
{ {
OC_Log::write('OC_USER_SQL', "Passwords do not match, return false", OC_Log::DEBUG); OC_Log::write('OC_USER_SQL', "Passwords do not match, return false", OC_Log::DEBUG);
return false; return false;
@ -320,7 +323,8 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
$cacheKey = 'sql_user_exists_' . $uid; $cacheKey = 'sql_user_exists_' . $uid;
$cacheVal = $this -> cache -> get($cacheKey); $cacheVal = $this -> cache -> get($cacheKey);
if(!is_null($cacheVal)) return (bool)$cacheVal; if(!is_null($cacheVal))
return (bool)$cacheVal;
OC_Log::write('OC_USER_SQL', "Entering userExists() for UID: $uid", OC_Log::DEBUG); OC_Log::write('OC_USER_SQL', "Entering userExists() for UID: $uid", OC_Log::DEBUG);
if(!$this -> db_conn) if(!$this -> db_conn)
@ -350,8 +354,7 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
{ {
OC_Log::write('OC_USER_SQL', "Empty row, user does not exists, return false", OC_Log::DEBUG); OC_Log::write('OC_USER_SQL', "Empty row, user does not exists, return false", OC_Log::DEBUG);
return false; return false;
} } else
else
{ {
OC_Log::write('OC_USER_SQL', "User exists, return true", OC_Log::DEBUG); OC_Log::write('OC_USER_SQL', "User exists, return true", OC_Log::DEBUG);
return true; return true;
@ -392,8 +395,7 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
{ {
OC_Log::write('OC_USER_SQL', "Empty row, user has no display name or does not exist, return false", OC_Log::DEBUG); OC_Log::write('OC_USER_SQL', "Empty row, user has no display name or does not exist, return false", OC_Log::DEBUG);
return false; return false;
} } else
else
{ {
OC_Log::write('OC_USER_SQL', "User exists, return true", OC_Log::DEBUG); OC_Log::write('OC_USER_SQL', "User exists, return true", OC_Log::DEBUG);
$displayName = utf8_encode($row[$this -> sql_column_displayname]); $displayName = utf8_encode($row[$this -> sql_column_displayname]);
@ -414,11 +416,13 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
} }
/** /**
* The following functions were directly taken from PostfixAdmin and just slightly modified * The following functions were directly taken from PostfixAdmin and just
* slightly modified
* to suit our needs. * to suit our needs.
* Encrypt a password, using the apparopriate hashing mechanism as defined in * Encrypt a password, using the apparopriate hashing mechanism as defined in
* config.inc.php ($this->crypt_type). * config.inc.php ($this->crypt_type).
* When wanting to compare one pw to another, it's necessary to provide the salt used - hence * When wanting to compare one pw to another, it's necessary to provide the
* salt used - hence
* the second parameter ($pw_db), which is the existing hash from the DB. * the second parameter ($pw_db), which is the existing hash from the DB.
* *
* @param string $pw * @param string $pw
@ -432,27 +436,28 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
$password = ""; $password = "";
$salt = ""; $salt = "";
if ($this->crypt_type == 'md5crypt') { if($this -> crypt_type == 'md5crypt')
{
$split_salt = preg_split('/\$/', $pw_db); $split_salt = preg_split('/\$/', $pw_db);
if (isset ($split_salt[2])) { if(isset($split_salt[2]))
{
$salt = $split_salt[2]; $salt = $split_salt[2];
} }
$password = $this -> md5crypt($pw, $salt); $password = $this -> md5crypt($pw, $salt);
} } elseif($this -> crypt_type == 'md5')
{
elseif ($this->crypt_type == 'md5') {
$password = md5($pw); $password = md5($pw);
} } elseif($this -> crypt_type == 'system')
{
elseif ($this->crypt_type == 'system') { // We never generate salts, as user creation is not allowed here // We never generate salts, as user creation is not allowed here
$password = crypt($pw, $pw_db); $password = crypt($pw, $pw_db);
} } elseif($this -> crypt_type == 'cleartext')
{
elseif ($this->crypt_type == 'cleartext') {
$password = $pw; $password = $pw;
} }
// See https://sourceforge.net/tracker/?func=detail&atid=937966&aid=1793352&group_id=191583 // See
// https://sourceforge.net/tracker/?func=detail&atid=937966&aid=1793352&group_id=191583
// this is apparently useful for pam_mysql etc. // this is apparently useful for pam_mysql etc.
elseif($this -> crypt_type == 'mysql_encrypt') elseif($this -> crypt_type == 'mysql_encrypt')
{ {
@ -460,10 +465,12 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
{ {
return false; return false;
} }
if ($pw_db!="") { if($pw_db != "")
{
$salt = substr($pw_db, 0, 2); $salt = substr($pw_db, 0, 2);
$query = "SELECT ENCRYPT(:pw, :salt);"; $query = "SELECT ENCRYPT(:pw, :salt);";
} else { } else
{
$query = "SELECT ENCRYPT(:pw);"; $query = "SELECT ENCRYPT(:pw);";
} }
@ -481,9 +488,7 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
return false; return false;
} }
$password = $row[0]; $password = $row[0];
} } elseif($this -> crypt_type == 'mysql_password')
elseif($this->crypt_type == 'mysql_password')
{ {
if(!$this -> db_conn) if(!$this -> db_conn)
{ {
@ -515,9 +520,8 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
} }
$password = ($salt) ? md5($pw . $salt) : md5($pw); $password = ($salt) ? md5($pw . $salt) : md5($pw);
$password .= ':' . $salt; $password .= ':' . $salt;
} } else
{
else {
OC_Log::write('OC_USER_SQL', "unknown/invalid crypt_type settings: $this->crypt_type", OC_Log::ERROR); OC_Log::write('OC_USER_SQL', "unknown/invalid crypt_type settings: $this->crypt_type", OC_Log::ERROR);
die('unknown/invalid Encryption type setting: ' . $this -> crypt_type); die('unknown/invalid Encryption type setting: ' . $this -> crypt_type);
} }
@ -535,10 +539,13 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
{ {
$MAGIC = "$1$"; $MAGIC = "$1$";
if ($magic == "") $magic = $MAGIC; if($magic == "")
if ($salt == "") $salt = $this->create_salt (); $magic = $MAGIC;
if($salt == "")
$salt = $this -> create_salt();
$slist = explode("$", $salt); $slist = explode("$", $salt);
if ($slist[0] == "1") $salt = $slist[1]; if($slist[0] == "1")
$salt = $slist[1];
$salt = substr($salt, 0, 8); $salt = substr($salt, 0, 8);
$ctx = $pw . $magic . $salt; $ctx = $pw . $magic . $salt;
@ -549,8 +556,7 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
if($i > 16) if($i > 16)
{ {
$ctx .= substr($final, 0, 16); $ctx .= substr($final, 0, 16);
} } else
else
{ {
$ctx .= substr($final, 0, $i); $ctx .= substr($final, 0, $i);
} }
@ -559,8 +565,10 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
while($i > 0) while($i > 0)
{ {
if ($i & 1) $ctx .= chr (0); if($i & 1)
else $ctx .= $pw[0]; $ctx .= chr(0);
else
$ctx .= $pw[0];
$i = $i>>1; $i = $i>>1;
} }
$final = $this -> pahex2bin(md5($ctx)); $final = $this -> pahex2bin(md5($ctx));
@ -571,18 +579,18 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
if($i & 1) if($i & 1)
{ {
$ctx1 .= $pw; $ctx1 .= $pw;
} } else
else
{ {
$ctx1 .= substr($final, 0, 16); $ctx1 .= substr($final, 0, 16);
} }
if ($i % 3) $ctx1 .= $salt; if($i % 3)
if ($i % 7) $ctx1 .= $pw; $ctx1 .= $salt;
if($i % 7)
$ctx1 .= $pw;
if($i & 1) if($i & 1)
{ {
$ctx1 .= substr($final, 0, 16); $ctx1 .= substr($final, 0, 16);
} } else
else
{ {
$ctx1 .= $pw; $ctx1 .= $pw;
} }
@ -610,8 +618,7 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
if(function_exists('hex2bin')) if(function_exists('hex2bin'))
{ {
return hex2bin($str); return hex2bin($str);
} } else
else
{ {
$len = strlen($str); $len = strlen($str);
$nstr = ""; $nstr = "";
@ -638,5 +645,4 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
} }
} }
?> ?>