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

« back to all changes in this revision

Viewing changes to src/lmtp/client.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) 2009-2012 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2009-2013 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "lib.h"
4
4
#include "array.h"
8
8
#include "istream.h"
9
9
#include "ostream.h"
10
10
#include "hostpid.h"
 
11
#include "process-title.h"
11
12
#include "var-expand.h"
12
13
#include "settings-parser.h"
13
14
#include "master-service.h"
31
32
static struct client *clients = NULL;
32
33
unsigned int clients_count = 0;
33
34
 
 
35
void client_state_set(struct client *client, const char *name)
 
36
{
 
37
        client->state.name = name;
 
38
 
 
39
        if (!client->service_set->verbose_proctitle)
 
40
                return;
 
41
        if (clients_count == 0)
 
42
                process_title_set("[idling]");
 
43
        else if (clients_count > 1)
 
44
                process_title_set(t_strdup_printf("[%u clients]", clients_count));
 
45
        else
 
46
                process_title_set(t_strdup_printf("[%s]", client->state.name));
 
47
}
 
48
 
34
49
static void client_idle_timeout(struct client *client)
35
50
{
36
51
        client_destroy(client,
68
83
                return cmd_rset(client, args);
69
84
        if (strcmp(cmd, "NOOP") == 0)
70
85
                return cmd_noop(client, args);
 
86
        if (strcmp(cmd, "XCLIENT") == 0)
 
87
                return cmd_xclient(client, args);
71
88
 
72
89
        client_send_line(client, "502 5.5.2 Unknown command");
73
90
        return 0;
156
173
        lmtp_settings_dup(set_parser, client->pool, &lmtp_set, &lda_set);
157
174
        settings_var_expand(&lmtp_setting_parser_info, lmtp_set, client->pool,
158
175
                mail_storage_service_get_var_expand_table(storage_service, &input));
 
176
        client->service_set = master_service_settings_get(master_service);
159
177
        client->lmtp_set = lmtp_set;
160
 
        client->set = lda_set;
 
178
        client->unexpanded_lda_set = lda_set;
161
179
}
162
180
 
163
181
static void client_generate_session_id(struct client *client)
172
190
        client->state.session_id = p_strdup(client->state_pool, str_c(id));
173
191
}
174
192
 
175
 
static const char *client_remote_id(struct client *client)
 
193
const char *client_remote_id(struct client *client)
176
194
{
177
195
        const char *addr;
178
196
 
179
197
        addr = net_ip2addr(&client->remote_ip);
180
 
        if (addr == NULL)
 
198
        if (addr[0] == '\0')
181
199
                addr = "local";
182
200
        return addr;
183
201
}
215
233
 
216
234
        client->input = i_stream_create_fd(fd_in, CLIENT_MAX_INPUT_SIZE, FALSE);
217
235
        client->output = o_stream_create_fd(fd_out, (size_t)-1, FALSE);
 
236
        o_stream_set_no_error_handling(client->output, TRUE);
218
237
 
219
238
        client_io_reset(client);
220
239
        client->state_pool = pool_alloconly_create("client state", 4096);
221
240
        client->state.mail_data_fd = -1;
222
 
        client->state.name = "banner";
223
241
        client_read_settings(client);
224
242
        client_raw_user_create(client);
225
243
        client_generate_session_id(client);
226
 
        client->my_domain = client->set->hostname;
 
244
        client->my_domain = client->unexpanded_lda_set->hostname;
227
245
        client->lhlo = i_strdup("missing");
 
246
        client->proxy_ttl = LMTP_PROXY_DEFAULT_TTL;
228
247
 
229
248
        DLLIST_PREPEND(&clients, client);
230
249
        clients_count++;
231
250
 
 
251
        client_state_set(client, "banner");
232
252
        client_send_line(client, "220 %s %s", client->my_domain,
233
253
                         client->lmtp_set->login_greeting);
234
254
        i_info("Connect from %s", client_remote_id(client));
239
259
                    const char *reason)
240
260
{
241
261
        client_disconnect(client, prefix, reason);
 
262
        o_stream_uncork(client->output);
242
263
 
243
264
        clients_count--;
244
265
        DLLIST_REMOVE(&clients, client);
245
266
 
 
267
        client_state_set(client, "destroyed");
 
268
 
246
269
        if (client->raw_mail_user != NULL)
247
270
                mail_user_unref(&client->raw_mail_user);
248
271
        if (client->proxy != NULL)
294
317
{
295
318
        struct mail_recipient *rcpt;
296
319
 
 
320
        if (client->proxy != NULL)
 
321
                lmtp_proxy_deinit(&client->proxy);
 
322
 
297
323
        if (array_is_created(&client->state.rcpt_to)) {
298
324
                array_foreach_modifiable(&client->state.rcpt_to, rcpt)
299
325
                        mail_storage_service_user_free(&rcpt->service_user);
323
349
        client->state.mail_data_fd = -1;
324
350
 
325
351
        client_generate_session_id(client);
326
 
        client->state.name = "reset";
 
352
        client_state_set(client, "reset");
327
353
}
328
354
 
329
355
void client_send_line(struct client *client, const char *fmt, ...)
337
363
                str = t_str_new(256);
338
364
                str_vprintfa(str, fmt, args);
339
365
                str_append(str, "\r\n");
340
 
                o_stream_send(client->output, str_data(str), str_len(str));
 
366
                o_stream_nsend(client->output, str_data(str), str_len(str));
341
367
        } T_END;
342
368
        va_end(args);
343
369
}
344
370
 
 
371
bool client_is_trusted(struct client *client)
 
372
{
 
373
        const char *const *net;
 
374
        struct ip_addr net_ip;
 
375
        unsigned int bits;
 
376
 
 
377
        if (client->lmtp_set->login_trusted_networks == NULL)
 
378
                return FALSE;
 
379
 
 
380
        net = t_strsplit_spaces(client->lmtp_set->login_trusted_networks, ", ");
 
381
        for (; *net != NULL; net++) {
 
382
                if (net_parse_range(*net, &net_ip, &bits) < 0) {
 
383
                        i_error("login_trusted_networks: "
 
384
                                "Invalid network '%s'", *net);
 
385
                        break;
 
386
                }
 
387
 
 
388
                if (net_is_in_network(&client->remote_ip, &net_ip, bits))
 
389
                        return TRUE;
 
390
        }
 
391
        return FALSE;
 
392
}
 
393
 
345
394
void clients_destroy(void)
346
395
{
347
396
        while (clients != NULL) {