Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/imap/main.c @ 727:8dd8ebe6bcac HEAD
We use close-on-exec flag now to make sure that master process closes the
fds when executing other processes.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 01 Dec 2002 17:39:20 +0200 |
parents | 5690ce7151c9 |
children | 1b0205fc4153 |
rev | line source |
---|---|
0 | 1 /* Copyright (C) 2002 Timo Sirainen */ |
2 | |
3 #include "common.h" | |
4 #include "ioloop.h" | |
5 #include "lib-signals.h" | |
550
3a83b05a0be3
--with-rawlog: Build support for logging traffic of user sessions. If
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
6 #include "rawlog.h" |
0 | 7 #include "restrict-access.h" |
727
8dd8ebe6bcac
We use close-on-exec flag now to make sure that master process closes the
Timo Sirainen <tss@iki.fi>
parents:
621
diff
changeset
|
8 #include "fd-close-on-exec.h" |
0 | 9 |
10 #include <stdlib.h> | |
11 #include <syslog.h> | |
12 | |
13 IOLoop ioloop; | |
14 static char log_prefix[64]; | |
15 | |
16 static void sig_quit(int signo __attr_unused__) | |
17 { | |
18 io_loop_stop(ioloop); | |
19 } | |
20 | |
21 static void main_init(int use_syslog) | |
22 { | |
23 Client *client; | |
24 MailStorage *storage; | |
25 const char *logfile, *mail, *tag; | |
550
3a83b05a0be3
--with-rawlog: Build support for logging traffic of user sessions. If
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
26 int hin, hout; |
3a83b05a0be3
--with-rawlog: Build support for logging traffic of user sessions. If
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
27 |
3a83b05a0be3
--with-rawlog: Build support for logging traffic of user sessions. If
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
28 hin = 0; hout = 1; |
0 | 29 |
30 lib_init_signals(sig_quit); | |
31 | |
32 i_snprintf(log_prefix, sizeof(log_prefix), "imap(%s)", getenv("USER")); | |
33 | |
34 logfile = getenv("IMAP_LOGFILE"); | |
35 if (logfile != NULL) { | |
36 /* log failures into specified log file */ | |
37 i_set_failure_file(logfile, log_prefix); | |
35
b420373f88f6
Added log_path and log_timestamp settings to config file. Removed -l command
Timo Sirainen <tss@iki.fi>
parents:
22
diff
changeset
|
38 i_set_failure_timestamp_format(getenv("IMAP_LOGSTAMP")); |
0 | 39 } else if (use_syslog) { |
40 /* prefix with imapd(user) */ | |
41 openlog(log_prefix, 0, LOG_MAIL); | |
42 | |
43 i_set_panic_handler(i_syslog_panic_handler); | |
44 i_set_fatal_handler(i_syslog_fatal_handler); | |
45 i_set_error_handler(i_syslog_error_handler); | |
46 i_set_warning_handler(i_syslog_warning_handler); | |
47 } | |
48 | |
49 /* do the chrooting etc. */ | |
50 restrict_access_by_env(); | |
51 | |
597
99c7e303c92a
Drop root privileges before handling rawlog opening.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
52 rawlog_open(&hin, &hout); |
99c7e303c92a
Drop root privileges before handling rawlog opening.
Timo Sirainen <tss@iki.fi>
parents:
596
diff
changeset
|
53 |
0 | 54 mail_storage_register_all(); |
55 clients_init(); | |
56 | |
57 mail = getenv("MAIL"); | |
58 if (mail == NULL) { | |
59 /* support also maildir-specific environment */ | |
60 mail = getenv("MAILDIR"); | |
61 if (mail != NULL) | |
62 mail = t_strconcat("maildir:", mail, NULL); | |
63 } | |
64 | |
22
a946ce1f09b7
mbox fixes, not fully working yet but almost :)
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
65 storage = mail_storage_create_with_data(mail, getenv("USER")); |
0 | 66 if (storage == NULL) { |
67 /* failed */ | |
68 if (mail != NULL && *mail != '\0') | |
69 i_fatal("Failed to create storage with data: %s", mail); | |
70 else { | |
71 const char *home; | |
72 | |
73 home = getenv("HOME"); | |
74 if (home == NULL) home = "not set"; | |
75 | |
76 i_fatal("MAIL environment missing and " | |
77 "autodetection failed (home %s)", home); | |
78 } | |
620
d34ee528aa68
Send PREAUTH if we were started without LOGIN_TAG environment (ie. not
Timo Sirainen <tss@iki.fi>
parents:
597
diff
changeset
|
79 } |
d34ee528aa68
Send PREAUTH if we were started without LOGIN_TAG environment (ie. not
Timo Sirainen <tss@iki.fi>
parents:
597
diff
changeset
|
80 |
d34ee528aa68
Send PREAUTH if we were started without LOGIN_TAG environment (ie. not
Timo Sirainen <tss@iki.fi>
parents:
597
diff
changeset
|
81 client = client_create(hin, hout, storage); |
0 | 82 |
620
d34ee528aa68
Send PREAUTH if we were started without LOGIN_TAG environment (ie. not
Timo Sirainen <tss@iki.fi>
parents:
597
diff
changeset
|
83 tag = getenv("LOGIN_TAG"); |
d34ee528aa68
Send PREAUTH if we were started without LOGIN_TAG environment (ie. not
Timo Sirainen <tss@iki.fi>
parents:
597
diff
changeset
|
84 if (tag == NULL || *tag == '\0') { |
d34ee528aa68
Send PREAUTH if we were started without LOGIN_TAG environment (ie. not
Timo Sirainen <tss@iki.fi>
parents:
597
diff
changeset
|
85 client_send_line(client, t_strconcat( |
621 | 86 "* PREAUTH [CAPABILITY "CAPABILITY_STRING"] " |
620
d34ee528aa68
Send PREAUTH if we were started without LOGIN_TAG environment (ie. not
Timo Sirainen <tss@iki.fi>
parents:
597
diff
changeset
|
87 "Logged in as ", getenv("USER"), NULL)); |
d34ee528aa68
Send PREAUTH if we were started without LOGIN_TAG environment (ie. not
Timo Sirainen <tss@iki.fi>
parents:
597
diff
changeset
|
88 } else { |
d34ee528aa68
Send PREAUTH if we were started without LOGIN_TAG environment (ie. not
Timo Sirainen <tss@iki.fi>
parents:
597
diff
changeset
|
89 client_send_line(client, |
d34ee528aa68
Send PREAUTH if we were started without LOGIN_TAG environment (ie. not
Timo Sirainen <tss@iki.fi>
parents:
597
diff
changeset
|
90 t_strconcat(tag, " OK Logged in.", NULL)); |
0 | 91 } |
92 } | |
93 | |
94 static void main_deinit(void) | |
95 { | |
96 /* warn about being killed because of some signal, except SIGINT (^C) | |
97 which is too common at least while testing :) */ | |
98 if (lib_signal_kill != 0 && lib_signal_kill != 2) | |
99 i_warning("Killed with signal %d", lib_signal_kill); | |
100 | |
101 clients_deinit(); | |
102 | |
103 closelog(); | |
104 } | |
105 | |
106 int main(int argc, char *argv[]) | |
107 { | |
727
8dd8ebe6bcac
We use close-on-exec flag now to make sure that master process closes the
Timo Sirainen <tss@iki.fi>
parents:
621
diff
changeset
|
108 #ifdef DEBUG |
8dd8ebe6bcac
We use close-on-exec flag now to make sure that master process closes the
Timo Sirainen <tss@iki.fi>
parents:
621
diff
changeset
|
109 fd_debug_verify_leaks(3, 1024); |
8dd8ebe6bcac
We use close-on-exec flag now to make sure that master process closes the
Timo Sirainen <tss@iki.fi>
parents:
621
diff
changeset
|
110 #endif |
0 | 111 /* NOTE: we start rooted, so keep the code minimal until |
112 restrict_access_by_env() is called */ | |
113 lib_init(); | |
389
60040a9d243f
ioloop_create() takes now pool-parameter. io_buffer_create_mmaped() takes
Timo Sirainen <tss@iki.fi>
parents:
35
diff
changeset
|
114 ioloop = io_loop_create(system_pool); |
0 | 115 |
596
ab3590c3a7d9
Added verbose_proctitle setting: Show more verbose process titles (in ps).
Timo Sirainen <tss@iki.fi>
parents:
550
diff
changeset
|
116 main_init(argc >= 2 && strcmp(argv[1], "-s") == 0); |
0 | 117 io_loop_run(ioloop); |
118 main_deinit(); | |
119 | |
120 io_loop_destroy(ioloop); | |
121 lib_deinit(); | |
122 | |
123 return 0; | |
124 } |