~ubuntu-branches/ubuntu/hardy/squirrelmail/hardy-updates

« back to all changes in this revision

Viewing changes to functions/file_prefs.php

  • Committer: Bazaar Package Importer
  • Author(s): Thijs Kinkhorst
  • Date: 2005-02-06 21:41:51 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050206214151-z4n1o8mnttgzuj0y
Tags: 2:1.4.4-3
* Move default_pref config file from /var to /etc, as per Debian policy
  (Closes: #293281)
* [JvW] (finally) override two lintian warnings about nonstandard
  permissions that are intentional (Closes: #293366)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
/**
4
4
 * file_prefs.php
5
5
 *
6
 
 * Copyright (c) 1999-2003 The SquirrelMail Project Team
 
6
 * Copyright (c) 1999-2005 The SquirrelMail Project Team
7
7
 * Licensed under the GNU GPL. For full terms see the file COPYING.
8
8
 *
9
9
 * This contains functions for manipulating user preferences in files
10
10
 *
11
 
 * $Id: file_prefs.php,v 1.29 2003/10/28 21:27:46 tassium Exp $
 
11
 * @version $Id: file_prefs.php,v 1.26.2.8 2004/12/27 15:03:43 kink Exp $
12
12
 * @package squirrelmail
13
13
 */
14
14
 
20
20
 */
21
21
function cachePrefValues($data_dir, $username) {
22
22
    global $prefs_are_cached, $prefs_cache;
23
 
       
 
23
 
 
24
    sqgetGlobalVar('prefs_are_cached', $prefs_are_cached, SQ_SESSION );
24
25
    if ( isset($prefs_are_cached) && $prefs_are_cached) {
 
26
        sqgetGlobalVar('prefs_cache', $prefs_cache, SQ_SESSION );
25
27
        return;
26
28
    }
27
 
    
 
29
 
28
30
    sqsession_unregister('prefs_cache');
29
31
    sqsession_unregister('prefs_are_cached');
30
 
    
 
32
 
31
33
    /* Calculate the filename for the user's preference file */
32
34
    $filename = getHashedFile($username, $data_dir, "$username.pref");
33
35
 
82
84
    sqsession_register($prefs_cache, 'prefs_cache');
83
85
    sqsession_register($prefs_are_cached, 'prefs_are_cached');
84
86
}
85
 
   
 
87
 
86
88
/**
87
89
 * Return the value for the preference given by $string.
88
90
 */
91
93
 
92
94
    $result = do_hook_function('get_pref_override',array($username,$string));
93
95
    if (!$result) {
94
 
        cachePrefValues($data_dir, $username);
95
 
        if (isset($prefs_cache[$string])) {
96
 
            $result = $prefs_cache[$string];
97
 
        } else {
98
 
            $result = do_hook_function('get_pref', array($username,$string));
99
 
            if (!$result) {         
100
 
                $result = $default;
101
 
            }
102
 
        }
 
96
        cachePrefValues($data_dir, $username);
 
97
        if (isset($prefs_cache[$string])) {
 
98
            $result = $prefs_cache[$string];
 
99
        } else {
 
100
            $result = do_hook_function('get_pref', array($username,$string));
 
101
            if (!$result) {
 
102
                $result = $default;
 
103
            }
 
104
        }
103
105
    }
104
106
    return ($result);
105
107
}
109
111
 */
110
112
function savePrefValues($data_dir, $username) {
111
113
    global $prefs_cache;
112
 
   
 
114
 
113
115
    $filename = getHashedFile($username, $data_dir, "$username.pref");
114
116
 
115
117
    /* Open the file for writing, or else display an error to the user. */
120
122
    }
121
123
    foreach ($prefs_cache as $Key => $Value) {
122
124
        if (isset($Value)) {
123
 
            if ( @fwrite($file, $Key . '=' . $Value . "\n") === FALSE ) {
 
125
            if ( sq_fwrite($file, $Key . '=' . $Value . "\n") === FALSE ) {
124
126
               logout_error( sprintf( _("Preference file, %s, could not be written. Contact your system administrator to resolve this issue.") , $filename . '.tmp') );
125
127
               exit;
126
128
            }
143
145
    global $prefs_cache;
144
146
 
145
147
    cachePrefValues($data_dir, $username);
146
 
 
 
148
 
147
149
    if (isset($prefs_cache[$string])) {
148
150
        unset($prefs_cache[$string]);
149
151
    }
150
 
 
 
152
 
151
153
    savePrefValues($data_dir, $username);
152
154
}
153
155
 
182
184
 
183
185
    /* Then, check if the file exists. */
184
186
    if (!@file_exists($filename) ) {
185
 
        /* First, check the $data_dir for the default preference file. */
 
187
 
 
188
        /* If it does not exist, check for default_prefs */
 
189
 
 
190
        /* First, check legacy locations: data dir */
186
191
        if(substr($data_dir,-1) != '/') {
187
192
            $data_dir .= '/';
188
193
        }
189
194
        $default_pref = $data_dir . 'default_pref';
190
195
 
191
 
        /* If it is not there, check the internal data directory. */
 
196
        /* or legacy location: internal data dir */
192
197
        if (!@file_exists($default_pref)) {
193
198
            $default_pref = SM_PATH . 'data/default_pref';
194
199
        }
195
200
 
 
201
        /* If no legacies, check where we'd expect it to be located:
 
202
         * under config/ */
 
203
        if (!@file_exists($default_pref)) {
 
204
            $default_pref = SM_PATH . 'config/default_pref';
 
205
        }
 
206
 
196
207
        /* Otherwise, report an error. */
197
208
        $errTitle = sprintf( _("Error opening %s"), $default_pref );
198
209
        if (!is_readable($default_pref)) {
199
 
            $errString = $errTitle . "<br>\n" .
200
 
                         _("Default preference file not found or not readable!") . "<br>\n" .
201
 
                         _("Please contact your system administrator and report this error.") . "<br>\n";
 
210
            $errString = $errTitle . "<br />\n" .
 
211
                         _("Default preference file not found or not readable!") . "<br />\n" .
 
212
                         _("Please contact your system administrator and report this error.") . "<br />\n";
202
213
            logout_error( $errString, $errTitle );
203
214
            exit;
204
215
        } else if (!@copy($default_pref, $filename)) {
207
218
                $user_data = posix_getpwuid(posix_getuid());
208
219
                $uid = $user_data['name'];
209
220
            }
210
 
            $errString = $errTitle . '<br>' .
211
 
                       _("Could not create initial preference file!") . "<br>\n" .
 
221
            $errString = $errTitle . '<br />' .
 
222
                       _("Could not create initial preference file!") . "<br />\n" .
212
223
                       sprintf( _("%s should be writable by user %s"), $data_dir, $uid ) .
213
 
                       "<br>\n" . _("Please contact your system administrator and report this error.") . "<br>\n";
 
224
                       "<br />\n" . _("Please contact your system administrator and report this error.") . "<br />\n";
214
225
            logout_error( $errString, $errTitle );
215
226
            exit;
216
227
        }
221
232
 * Write the User Signature.
222
233
 */
223
234
function setSig($data_dir, $username, $number, $value) {
 
235
    // Limit signature size to 64KB (database BLOB limit)
 
236
    if (strlen($value)>65536) {
 
237
        error_option_save(_("Signature is too big."));
 
238
        return;
 
239
    }
224
240
    $filename = getHashedFile($username, $data_dir, "$username.si$number");
225
241
    /* Open the file for writing, or else display an error to the user. */
226
242
    if(!$file = @fopen("$filename.tmp", 'w')) {
227
243
        logout_error( sprintf( _("Signature file, %s, could not be opened. Contact your system administrator to resolve this issue."), $filename . '.tmp') );
228
244
        exit;
229
245
    }
230
 
    if ( @fwrite($file, $value) === FALSE ) {
 
246
    if ( sq_fwrite($file, $value) === FALSE ) {
231
247
       logout_error( sprintf( _("Signature file, %s, could not be written. Contact your system administrator to resolve this issue.") , $filename . '.tmp'));
232
248
       exit;
233
249
    }
261
277
    }
262
278
    return $sig;
263
279
}
 
280
 
 
281
// vim: et ts=4
 
282
?>