~ubuntu-branches/ubuntu/wily/dovecot/wily

« back to all changes in this revision

Viewing changes to src/imap/main.c

  • Committer: Package Import Robot
  • Author(s): Jaldhar H. Vyas
  • Date: 2013-09-09 00:57:32 UTC
  • mfrom: (1.13.11)
  • mto: (4.8.5 experimental) (1.16.1)
  • mto: This revision was merged to the branch mainline in revision 97.
  • Revision ID: package-import@ubuntu.com-20130909005732-dn1eell8srqbhh0e
Tags: upstream-2.2.5
ImportĀ upstreamĀ versionĀ 2.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2002-2012 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2002-2013 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "imap-common.h"
4
4
#include "ioloop.h"
8
8
#include "str.h"
9
9
#include "base64.h"
10
10
#include "process-title.h"
 
11
#include "randgen.h"
11
12
#include "restrict-access.h"
12
13
#include "fd-close-on-exec.h"
 
14
#include "settings-parser.h"
13
15
#include "master-interface.h"
14
16
#include "master-service.h"
15
17
#include "master-login.h"
85
87
 
86
88
static void client_kill_idle(struct client *client)
87
89
{
88
 
        if (client->output_lock != NULL)
 
90
        if (client->output_cmd_lock != NULL)
89
91
                return;
90
92
 
91
93
        client_send_line(client, "* BYE Server shutting down.");
196
198
        struct mail_storage_service_user *user;
197
199
        struct mail_user *mail_user;
198
200
        struct client *client;
199
 
        const struct imap_settings *set;
 
201
        struct imap_settings *set;
200
202
        enum mail_auth_request_flags flags;
201
203
 
202
204
        if (mail_storage_service_lookup_next(storage_service, input,
208
210
        if (set->verbose_proctitle)
209
211
                verbose_proctitle = TRUE;
210
212
 
 
213
        settings_var_expand(&imap_setting_parser_info, set, mail_user->pool,
 
214
                            mail_user_var_expand_table(mail_user));
 
215
 
211
216
        client = client_create(fd_in, fd_out, input->session_id,
212
217
                               mail_user, user, set);
213
218
        T_BEGIN {
235
240
        if (input.username == NULL)
236
241
                i_fatal("USER environment missing");
237
242
        if ((value = getenv("IP")) != NULL)
238
 
                net_addr2ip(value, &input.remote_ip);
 
243
                (void)net_addr2ip(value, &input.remote_ip);
239
244
        if ((value = getenv("LOCAL_IP")) != NULL)
240
 
                net_addr2ip(value, &input.local_ip);
 
245
                (void)net_addr2ip(value, &input.local_ip);
241
246
 
242
247
        input_base64 = getenv("CLIENT_INPUT");
243
248
        input_buf = input_base64 == NULL ? NULL :
267
272
        input.userdb_fields = extra_fields;
268
273
        input.session_id = client->session_id;
269
274
 
270
 
        buffer_create_const_data(&input_buf, client->data,
271
 
                                 client->auth_req.data_size);
 
275
        buffer_create_from_const_data(&input_buf, client->data,
 
276
                                      client->auth_req.data_size);
272
277
        if (client_create_from_input(&input, client, client->fd, client->fd,
273
278
                                     &input_buf, &error) < 0) {
274
 
                if (write(client->fd, MSG_BYE_INTERNAL_ERROR,
 
279
                int fd = client->fd;
 
280
 
 
281
                if (write(fd, MSG_BYE_INTERNAL_ERROR,
275
282
                          strlen(MSG_BYE_INTERNAL_ERROR)) < 0) {
276
283
                        if (errno != EAGAIN && errno != EPIPE)
277
284
                                i_error("write(client) failed: %m");
278
285
                }
279
286
                i_error("%s", error);
280
 
                (void)close(client->fd);
 
287
                i_close_fd(&fd);
281
288
                master_service_client_connection_destroyed(master_service);
282
289
        }
283
290
}
319
326
 
320
327
        memset(&login_set, 0, sizeof(login_set));
321
328
        login_set.postlogin_timeout_secs = MASTER_POSTLOGIN_TIMEOUT_DEFAULT;
 
329
        login_set.request_auth_token = TRUE;
322
330
 
323
331
        if (IS_STANDALONE() && getuid() == 0 &&
324
332
            net_getpeername(1, NULL, NULL) == 0) {
355
363
                }
356
364
        }
357
365
 
358
 
        login_set.auth_socket_path = t_abspath("auth-master");
359
 
        if (argv[optind] != NULL)
360
 
                login_set.postlogin_socket_path = t_abspath(argv[optind]);
361
 
        login_set.callback = login_client_connected;
362
 
        login_set.failure_callback = login_client_failed;
363
 
 
364
 
        master_service_init_finish(master_service);
365
366
        master_service_set_die_callback(master_service, imap_die);
366
367
 
367
368
        /* plugins may want to add commands, so this needs to be called early */
368
369
        commands_init();
369
370
        imap_fetch_handlers_init();
370
371
 
 
372
        random_init();
371
373
        storage_service =
372
374
                mail_storage_service_init(master_service,
373
375
                                          set_roots, storage_service_flags);
 
376
        master_service_init_finish(master_service);
374
377
 
375
378
        /* fake that we're running, so we know if client was destroyed
376
379
           while handling its initial input */
380
383
                T_BEGIN {
381
384
                        main_stdio_run(username);
382
385
                } T_END;
383
 
        } else {
 
386
        } else T_BEGIN {
 
387
                login_set.auth_socket_path = t_abspath("auth-master");
 
388
                if (argv[optind] != NULL) {
 
389
                        login_set.postlogin_socket_path =
 
390
                                t_abspath(argv[optind]);
 
391
                }
 
392
                login_set.callback = login_client_connected;
 
393
                login_set.failure_callback = login_client_failed;
 
394
 
384
395
                master_login = master_login_init(master_service, &login_set);
385
396
                io_loop_set_running(current_ioloop);
386
 
        }
 
397
        } T_END;
387
398
 
388
399
        if (io_loop_is_running(current_ioloop))
389
400
                master_service_run(master_service, client_connected);
396
407
        imap_fetch_handlers_deinit();
397
408
        commands_deinit();
398
409
 
 
410
        random_deinit();
399
411
        master_service_deinit(&master_service);
400
412
        return 0;
401
413
}