~james-page/ubuntu/raring/dovecot/autopkgtest

« back to all changes in this revision

Viewing changes to pigeonhole/src/managesieve/cmd-setactive.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-06-11 11:11:54 UTC
  • mfrom: (1.15.2) (4.1.27 sid)
  • Revision ID: package-import@ubuntu.com-20120611111154-678cwbdj6ktgsv1h
Tags: 1:2.1.7-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/{control,rules}: enable PIE hardening.
  + 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.
  + d/control: Added Pre-Depends: dpkg (>= 1.15.6) to dovecot-dbg to support
    xz compression in Ubuntu.
  + d/control: Demote dovecot-common Recommends: to Suggests: to prevent
    install of extra packages on upgrade.
  + d/patches/dovecot-drac.patch: Updated with version for dovecot >= 2.0.0.
  + d/control: Drop B-D on systemd.
* Dropped changes:
  + d/patches/fix-racey-restart.patch: part of 2.1.x, no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 */
3
3
 
4
4
#include "lib.h"
 
5
#include "str.h"
5
6
 
 
7
#include "sieve.h"
6
8
#include "sieve-storage.h"
7
9
#include "sieve-storage-script.h"
8
10
 
14
16
        struct client *client = cmd->client;
15
17
        struct sieve_storage *storage = client->storage;
16
18
        const char *scriptname;
17
 
        struct sieve_script *script;;
 
19
        struct sieve_script *script;
18
20
        int ret;
19
21
 
20
22
        /* <scriptname> */
21
23
        if ( !client_read_string_args(cmd, 1, TRUE, &scriptname) )
22
24
                return FALSE;
23
25
 
 
26
        /* Activate, or .. */
24
27
        if ( *scriptname != '\0' ) {
 
28
                string_t *errors = NULL;
 
29
                bool warnings = FALSE;
 
30
                bool success = TRUE;
 
31
 
25
32
                script = sieve_storage_script_init(storage, scriptname);
26
 
 
27
33
                if ( script == NULL ) {
28
34
                        client_send_storage_error(client, storage);
29
35
                        return TRUE;
30
36
                }
 
37
 
 
38
                if ( sieve_storage_script_is_active(script) <= 0 ) {
 
39
                        /* Script is first being activated; compile it again without the UPLOAD
 
40
                         * flag.
 
41
                         */
 
42
                        T_BEGIN {
 
43
                                struct sieve_error_handler *ehandler;
 
44
                                enum sieve_compile_flags cpflags = 
 
45
                                        SIEVE_COMPILE_FLAG_NOGLOBAL | SIEVE_COMPILE_FLAG_ACTIVATED;
 
46
                                struct sieve_binary *sbin;
 
47
 
 
48
                                /* Prepare error handler */
 
49
                                errors = str_new(default_pool, 1024);
 
50
                                ehandler = sieve_strbuf_ehandler_create(client->svinst, errors, TRUE, 
 
51
                                        client->set->managesieve_max_compile_errors);
 
52
 
 
53
                                /* Compile */
 
54
                                if ( (sbin=sieve_compile_script
 
55
                                        (script, ehandler, cpflags, NULL)) == NULL ) {
 
56
                                        success = FALSE;
 
57
                                } else {
 
58
                                        sieve_close(&sbin);
 
59
                                }
 
60
 
 
61
                                warnings = ( sieve_get_warnings(ehandler) > 0 );
 
62
                                sieve_error_handler_unref(&ehandler);
 
63
                        } T_END;
 
64
                }
31
65
        
32
 
                ret = sieve_storage_script_activate(script);
33
 
                if ( ret < 0 )
34
 
                        client_send_storage_error(client, storage);
35
 
                else
36
 
                        client_send_ok(client, ret ? 
37
 
                                "Setactive completed." :
38
 
                                "Script is already active.");
 
66
                /* Activate only when script is valid (or already active) */
 
67
                if ( success ) {
 
68
                        /* Refresh activation no matter what; this can also resolve some erroneous
 
69
                         * situations.
 
70
                         */
 
71
                        ret = sieve_storage_script_activate(script);
 
72
                        if ( ret < 0 ) {
 
73
                                client_send_storage_error(client, storage);
 
74
                        } else {
 
75
                                if ( warnings ) {
 
76
                                        client_send_okresp(client, "WARNINGS", str_c(errors));
 
77
                                } else {
 
78
                                        client_send_ok(client, ( ret > 0 ? 
 
79
                                                "Setactive completed." :
 
80
                                                "Script is already active." ));
 
81
                                }
 
82
                        }
 
83
                } else {
 
84
                        client_send_no(client, str_c(errors));
 
85
                }
39
86
 
 
87
                if ( errors != NULL )
 
88
                        str_free(&errors);
40
89
                sieve_script_unref(&script);
 
90
 
 
91
        /* ... deactivate */
41
92
        } else {
42
93
                ret = sieve_storage_deactivate(storage);
43
94
                
44
95
                if ( ret < 0 )
45
96
                        client_send_storage_error(client, storage);
46
97
                else
47
 
                        client_send_ok(client, ret ?
 
98
                        client_send_ok(client, ( ret > 0 ?
48
99
                                "Active script is now deactivated." :
49
 
                                "No scripts currently active.");        
 
100
                                "No scripts currently active." ));      
50
101
        }
51
102
 
52
103
        return TRUE;