X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Ffile_prefs.php;h=e852387ef90b43f69036ec392dfa12bcfd8c75b7;hb=15d98101f0c2b3cae541e1e8de0f5edfaa820965;hp=4f8f03029273c5a4841b356ab02ac0ebc00123fe;hpb=6c84ba1ec45ab854c37b6f65c5b4d84ab1c7aad4;p=squirrelmail.git
diff --git a/functions/file_prefs.php b/functions/file_prefs.php
index 4f8f0302..e852387e 100644
--- a/functions/file_prefs.php
+++ b/functions/file_prefs.php
@@ -184,35 +184,42 @@ function checkForPrefs($data_dir, $username, $filename = '') {
/* Then, check if the file exists. */
if (!@file_exists($filename) ) {
- /* First, check the $data_dir for the default preference file. */
+
+ /* If it does not exist, check for default_prefs */
+
+ /* First, check legacy locations: data dir */
if(substr($data_dir,-1) != '/') {
$data_dir .= '/';
}
$default_pref = $data_dir . 'default_pref';
- /* If it is not there, check the internal data directory. */
+ /* or legacy location: internal data dir */
if (!@file_exists($default_pref)) {
$default_pref = SM_PATH . 'data/default_pref';
}
- /* Otherwise, report an error. */
- $errTitle = sprintf( _("Error opening %s"), $default_pref );
- if (!is_readable($default_pref)) {
- $errString = $errTitle . "
\n" .
- _("Default preference file not found or not readable!") . "
\n" .
- _("Please contact your system administrator and report this error.") . "
\n";
- logout_error( $errString, $errTitle );
- exit;
- } else if (!@copy($default_pref, $filename)) {
+ /* If no legacies, check where we'd expect it to be located:
+ * under config/ */
+ if (!@file_exists($default_pref)) {
+ $default_pref = SM_PATH . 'config/default_pref';
+ }
+
+ /* If a default_pref file found, try to copy it, if none found,
+ * try to create an empty one. If that fails, report an error.
+ */
+ if (
+ ( is_readable($default_pref) && !@copy($default_pref, $filename) ) ||
+ !@touch($filename)
+ ) {
$uid = 'httpd';
if (function_exists('posix_getuid')){
$user_data = posix_getpwuid(posix_getuid());
$uid = $user_data['name'];
}
- $errString = $errTitle . '
' .
- _("Could not create initial preference file!") . "
\n" .
- sprintf( _("%s should be writable by user %s"), $data_dir, $uid ) .
- "
\n" . _("Please contact your system administrator and report this error.") . "
\n";
+ $errTitle = _("Could not create initial preference file!");
+ $errString = $errTitle . "
\n" .
+ sprintf( _("%s should be writable by user %s"), $data_dir, $uid ) . "
\n" .
+ _("Please contact your system administrator and report this error.") . "
\n";
logout_error( $errString, $errTitle );
exit;
}
@@ -270,4 +277,4 @@ function getSig($data_dir, $username, $number) {
}
// vim: et ts=4
-?>
\ No newline at end of file
+?>