~ubuntu-branches/ubuntu/utopic/dovecot/utopic-proposed

« back to all changes in this revision

Viewing changes to pigeonhole/src/lib-sieve/sieve-script-file.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-08 09:35:49 UTC
  • mfrom: (4.1.35 sid)
  • Revision ID: package-import@ubuntu.com-20140108093549-i72o93pux8p0dlaf
Tags: 1:2.2.9-1ubuntu1
* Merge from Debian unstable, remaining changes:
  + Add mail-stack-delivery package:
    - Update d/rules
    - d/control: convert existing dovecot-postfix package to a dummy
      package and add new mail-stack-delivery package.
    - Update maintainer scripts.
    - Rename d/dovecot-postfix.* to debian/mail-stack-delivery.*
    - d/mail-stack-delivery.preinst: Move previously installed backups and
      config files to a new package namespace.
    - d/mail-stack-delivery.prerm: Added to handle downgrades.
  + Use Snakeoil SSL certificates by default:
    - d/control: Depend on ssl-cert.
    - d/dovecot-core.postinst: Relax grep for SSL_* a bit.
  + Add autopkgtest to debian/tests/*.
  + Add ufw integration:
    - d/dovecot-core.ufw.profile: new ufw profile.
    - d/rules: install profile in dovecot-core.
    - d/control: dovecot-core - suggest ufw.
  + d/dovecot-core.dirs: Added usr/share/doc/dovecot-core
  + Add apport hook:
    - d/rules, d/source_dovecot.py
  + Add upstart job:
    - d/rules, d/dovecot-core.dovecot.upstart, d/control,
      d/dovecot-core.dirs, dovecot-imapd.{postrm, postinst, prerm},
      d/dovecot-pop3d.{postinst, postrm, prerm}.
      d/mail-stack-deliver.postinst: Convert init script to upstart.
  + Use the autotools-dev dh addon to update config.guess/config.sub for
    arm64.
* Dropped changes, included in Debian:
  - Update Dovecot name to reflect distribution in login greeting.
  - Update Drac plugin for >= 2.0.0 support.
* d/control: Drop dovecot-postfix package as its no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file
 
1
/* Copyright (c) 2002-2013 Pigeonhole authors, see the included COPYING file
2
2
 */
3
3
 
4
4
#include "lib.h"
22
22
/*
23
23
 * Configuration
24
24
 */
25
 
 
 
25
 
26
26
#define SIEVE_FILE_READ_BLOCK_SIZE (1024*8)
27
27
 
28
28
/*
70
70
                *error_r = SIEVE_ERROR_NOT_FOUND;
71
71
                break;
72
72
        case EACCES:
73
 
                sieve_critical(svinst, ehandler, name, "failed to open sieve script", 
 
73
                sieve_critical(svinst, ehandler, name, "failed to open sieve script",
74
74
                        "failed to stat sieve script: %s", eacces_error_get("stat", path));
75
 
                *error_r = SIEVE_ERROR_NO_PERM;
 
75
                *error_r = SIEVE_ERROR_NO_PERMISSION;
76
76
                break;
77
77
        default:
78
 
                sieve_critical(svinst, ehandler, name, "failed to open sieve script", 
 
78
                sieve_critical(svinst, ehandler, name, "failed to open sieve script",
79
79
                        "failed to stat sieve script: stat(%s) failed: %m", path);
80
 
                *error_r = SIEVE_ERROR_TEMP_FAIL;
 
80
                *error_r = SIEVE_ERROR_TEMP_FAILURE;
81
81
                break;
82
82
        }
83
83
}
88
88
 
89
89
static int sieve_file_script_stat
90
90
(const char *path, struct stat *st, struct stat *lnk_st)
91
 
{       
 
91
{
92
92
        if ( lstat(path, st) < 0 )
93
93
                return -1;
94
94
 
107
107
 
108
108
        pool = pool_alloconly_create("sieve_file_script", 1024);
109
109
        script = p_new(pool, struct sieve_file_script, 1);
110
 
        script->script = sieve_file_script; 
 
110
        script->script = sieve_file_script;
111
111
        script->script.pool = pool;
112
 
        
 
112
 
113
113
        return &script->script;
114
114
}
115
115
 
116
 
static int sieve_file_script_create
 
116
static int sieve_file_script_open
117
117
(struct sieve_script *_script, const char *path, const char *const *options,
118
118
        enum sieve_error *error_r)
119
119
{
133
133
 
134
134
                sieve_critical(svinst, ehandler, NULL, "failed to open sieve script",
135
135
                        "sieve file backend: invalid option `%s'", option);
136
 
                *error_r = SIEVE_ERROR_TEMP_FAIL;
 
136
                *error_r = SIEVE_ERROR_TEMP_FAILURE;
137
137
                return -1;
138
138
        }
139
139
 
140
140
        T_BEGIN {
141
 
                if ( (path[0] == '~' && (path[1] == '/' || path[1] == '\0')) || 
 
141
                if ( (path[0] == '~' && (path[1] == '/' || path[1] == '\0')) ||
142
142
                        (((svinst->flags & SIEVE_FLAG_HOME_RELATIVE) != 0 ) && path[0] != '/') ) {
143
143
                        /* home-relative path. change to absolute. */
144
144
                        const char *home = sieve_environment_get_homedir(svinst);
149
149
                                else
150
150
                                        path = t_strconcat(home, "/", path, NULL);
151
151
                        } else {
152
 
                                sieve_critical(svinst, ehandler, NULL, 
 
152
                                sieve_critical(svinst, ehandler, NULL,
153
153
                                        "failed to open sieve script",
154
154
                                        "sieve script file path %s is relative to home directory, "
155
155
                                        "but home directory is not available.", path);
156
 
                                *error_r = SIEVE_ERROR_TEMP_FAIL;
 
156
                                *error_r = SIEVE_ERROR_TEMP_FAILURE;
157
157
                                success = FALSE;
158
158
                        }
159
159
                }
162
162
                        if ( S_ISDIR(st.st_mode) ) {
163
163
                                /* Path is directory; name is used to find actual file */
164
164
                                if (name == 0 || *name == '\0') {
165
 
                                        sieve_critical(svinst, ehandler, NULL, 
 
165
                                        sieve_critical(svinst, ehandler, NULL,
166
166
                                                "failed to open sieve script",
167
167
                                                "sieve script file path '%s' is a directory.", path);
168
 
                                        *error_r = SIEVE_ERROR_TEMP_FAIL;
 
168
                                        *error_r = SIEVE_ERROR_TEMP_FAILURE;
169
169
                                        success = FALSE;
170
170
                                }       else {
171
 
                                        /* Extend path with filename */ 
 
171
                                        /* Extend path with filename */
172
172
                                        filename = sieve_scriptfile_from_name(name);
173
173
                                        basename = name;
174
174
                                        dirpath = path;
177
177
                                                path = t_strconcat(dirpath, filename, NULL);
178
178
                                        else
179
179
                                                path = t_strconcat(dirpath, "/", filename , NULL);
180
 
                        
 
180
 
181
181
                                        ret = sieve_file_script_stat(path, &st, &lnk_st);
182
182
                                }
183
183
 
202
202
                } else {
203
203
                        basename = name;
204
204
                }
205
 
                        
 
205
 
206
206
                if ( success ) {
207
207
                        if ( ret <= 0 ) {
208
208
                                sieve_file_script_handle_error(_script, path, name, error_r);
209
209
                                success = FALSE;
210
210
                        } else if (!S_ISREG(st.st_mode) ) {
211
 
                                sieve_critical(svinst, ehandler, name, 
 
211
                                sieve_critical(svinst, ehandler, name,
212
212
                                        "failed to open sieve script",
213
213
                                        "sieve script file '%s' is not a regular file.", path);
214
 
                                *error_r = SIEVE_ERROR_TEMP_FAIL;
 
214
                                *error_r = SIEVE_ERROR_TEMP_FAILURE;
215
215
                                success = FALSE;
216
 
                        } 
 
216
                        }
217
217
                }
218
218
 
219
219
                if ( success ) {
243
243
                        if ( script->script.name == NULL )
244
244
                                script->script.name = p_strdup(pool, basename);
245
245
                }
246
 
        } T_END;        
 
246
        } T_END;
247
247
 
248
248
        return ( success ? 0 : -1 );
249
249
}
250
250
 
251
 
static struct istream *sieve_file_script_open
252
 
(struct sieve_script *_script, enum sieve_error *error_r)
 
251
static int sieve_file_script_get_stream
 
252
(struct sieve_script *_script, struct istream **stream_r,
 
253
        enum sieve_error *error_r)
253
254
{
254
255
        struct sieve_file_script *script = (struct sieve_file_script *)_script;
255
256
        struct sieve_instance *svinst = _script->svinst;
261
262
 
262
263
        if ( (fd=open(script->path, O_RDONLY)) < 0 ) {
263
264
                sieve_file_script_handle_error(_script, script->path, name, error_r);
264
 
                return NULL;
265
 
        }       
266
 
        
 
265
                return -1;
 
266
        }
 
267
 
267
268
        if ( fstat(fd, &st) != 0 ) {
268
269
                sieve_critical(svinst, ehandler, name,
269
270
                        "failed to open sieve script",
270
271
                        "failed to open sieve script: fstat(fd=%s) failed: %m", script->path);
271
 
                *error_r = SIEVE_ERROR_TEMP_FAIL;
 
272
                *error_r = SIEVE_ERROR_TEMP_FAILURE;
272
273
                result = NULL;
273
274
        } else {
274
275
                /* Re-check the file type just to be sure */
276
277
                        sieve_critical(svinst, ehandler, name,
277
278
                                "failed to open sieve script",
278
279
                                "sieve script file '%s' is not a regular file", script->path);
279
 
                        *error_r = SIEVE_ERROR_TEMP_FAIL;
 
280
                        *error_r = SIEVE_ERROR_TEMP_FAILURE;
280
281
                        result = NULL;
281
282
                } else {
282
283
                        result = i_stream_create_fd(fd, SIEVE_FILE_READ_BLOCK_SIZE, TRUE);
287
288
        if ( result == NULL ) {
288
289
                /* Something went wrong, close the fd */
289
290
                if ( close(fd) != 0 ) {
290
 
                        sieve_sys_error(svinst, 
 
291
                        sieve_sys_error(svinst,
291
292
                                "failed to close sieve script: close(fd=%s) failed: %m", script->path);
292
293
                }
293
294
        }
294
 
        
295
 
        return result;
 
295
 
 
296
        *stream_r = result;
 
297
        return 0;
296
298
}
297
299
 
298
300
static int sieve_file_script_get_size
310
312
        struct sieve_file_script *script = (struct sieve_file_script *)_script;
311
313
        struct sieve_file_script *other = (struct sieve_file_script *)_other;
312
314
 
313
 
        if ( script == NULL || other == NULL ) 
314
 
                return -1;      
 
315
        if ( script == NULL || other == NULL )
 
316
                return FALSE;
315
317
 
316
318
        return ( script->st.st_ino == other->st.st_ino );
317
319
}
324
326
        struct sieve_binary *sbin = sieve_binary_block_get_binary(sblock);
325
327
        time_t time = ( script->st.st_mtime > script->lnk_st.st_mtime ?
326
328
                script->st.st_mtime : script->lnk_st.st_mtime );
327
 
        
 
329
 
328
330
        if ( sieve_binary_mtime(sbin) <= time )
329
331
                return 0;
330
332
 
356
358
        .driver_name = SIEVE_FILE_SCRIPT_DRIVER_NAME,
357
359
        .v = {
358
360
                sieve_file_script_alloc,
359
 
                sieve_file_script_create,
360
361
                NULL,
361
362
 
362
363
                sieve_file_script_open,
363
 
                NULL,   
 
364
 
 
365
                sieve_file_script_get_stream,
364
366
 
365
367
                sieve_file_script_binary_read_metadata,
366
368
                NULL,