annotate src/pop3/main.c @ 10130:d1384c2b08e5 HEAD

Merged single and multi mail_storage_service_*() functions.
author Timo Sirainen <tss@iki.fi>
date Wed, 21 Oct 2009 19:54:00 -0400
parents b584904d3bc7
children cb6dc691fa5a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8590
b9faf4db2a9f Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents: 8467
diff changeset
1 /* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
9219
97cdfeb57129 Renamed headers to prevent collision if they were flattened on an install.
Mark Washenberger
parents: 9177
diff changeset
3 #include "pop3-common.h"
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "ioloop.h"
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
5 #include "buffer.h"
9080
e560b92ed763 imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents: 9059
diff changeset
6 #include "istream.h"
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
7 #include "ostream.h"
9080
e560b92ed763 imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents: 9059
diff changeset
8 #include "base64.h"
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include "restrict-access.h"
9080
e560b92ed763 imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents: 9059
diff changeset
10 #include "master-service.h"
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
11 #include "master-login.h"
9661
1780d56a9160 imap/pop3: Compiling fix.
Timo Sirainen <tss@iki.fi>
parents: 9653
diff changeset
12 #include "master-interface.h"
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
13 #include "var-expand.h"
9080
e560b92ed763 imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents: 9059
diff changeset
14 #include "mail-storage-service.h"
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15
2873
72f28a4b964d Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
16 #include <stdio.h>
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 #include <stdlib.h>
2873
72f28a4b964d Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
18 #include <unistd.h>
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20 #define IS_STANDALONE() \
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
21 (getenv(MASTER_UID_ENV) == NULL)
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
22
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
23 static struct mail_storage_service_ctx *storage_service;
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
24 static struct master_login *master_login = NULL;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25
1646
a7c742b940e5 Added pop3 hooks
Timo Sirainen <tss@iki.fi>
parents: 1620
diff changeset
26 void (*hook_client_created)(struct client **client) = NULL;
a7c742b940e5 Added pop3 hooks
Timo Sirainen <tss@iki.fi>
parents: 1620
diff changeset
27
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
28 static void client_add_input(struct client *client, const buffer_t *buf)
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
29 {
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
30 struct ostream *output;
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
31
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
32 if (buf != NULL && buf->used > 0) {
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
33 if (!i_stream_add_data(client->input, buf->data, buf->used))
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
34 i_panic("Couldn't add client input to stream");
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
35 }
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
36
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
37 output = client->output;
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
38 o_stream_ref(output);
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
39 o_stream_cork(output);
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
40 if (!IS_STANDALONE())
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
41 client_send_line(client, "+OK Logged in.");
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
42 (void)client_handle_input(client);
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
43 o_stream_uncork(output);
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
44 o_stream_unref(&output);
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
45 }
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
46
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
47 static void
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
48 main_stdio_init_user(const struct pop3_settings *set,
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
49 struct mail_user *mail_user,
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
50 struct mail_storage_service_user *user)
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51 {
7927
2351a81ce699 If commands are pipelined after the login command, pass them to the
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
52 struct client *client;
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
53 buffer_t *input_buf;
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
54 const char *input_base64;
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
55
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
56 input_base64 = getenv("CLIENT_INPUT");
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
57 input_buf = input_base64 == NULL ? NULL :
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
58 t_base64_decode_str(input_base64);
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
59
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
60 client = client_create(STDIN_FILENO, STDOUT_FILENO,
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
61 mail_user, user, set);
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
62 client_add_input(client, input_buf);
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
63 }
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
64
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
65 static void main_stdio_run(void)
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
66 {
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
67 struct mail_storage_service_input input;
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
68 struct mail_user *mail_user;
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
69 const struct pop3_settings *set;
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
70 const char *value;
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
71 struct mail_storage_service_user *user;
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
72 const char *error;
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
73 pool_t user_pool;
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
74 int ret;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
76 memset(&input, 0, sizeof(input));
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
77 input.module = input.service = "pop3";
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
78 input.username = getenv("USER");
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
79 if (input.username == NULL && IS_STANDALONE())
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
80 input.username = getlogin();
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
81 if (input.username == NULL)
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
82 i_fatal("USER environment missing");
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
83 if ((value = getenv("IP")) != NULL)
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
84 net_addr2ip(value, &input.remote_ip);
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
85 if ((value = getenv("LOCAL_IP")) != NULL)
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
86 net_addr2ip(value, &input.local_ip);
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
87
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
88 user_pool = pool_alloconly_create("storage user pool", 512);
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
89 ret = mail_storage_service_lookup(storage_service, &input,
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
90 &user, &error);
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
91 if (ret <= 0)
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
92 i_fatal("User lookup failed: %s", error);
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
93 if (mail_storage_service_next(storage_service,
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
94 user, &mail_user, &error) < 0)
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
95 i_fatal("User init failed: %s", error);
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
96 set = mail_storage_service_user_get_set(user)[1];
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
97
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
98 restrict_access_allow_coredumps(TRUE);
9879
e11bd2547bb2 imap, pop3: shutdown_clients setting wasn't working.
Timo Sirainen <tss@iki.fi>
parents: 9661
diff changeset
99 if (set->shutdown_clients)
e11bd2547bb2 imap, pop3: shutdown_clients setting wasn't working.
Timo Sirainen <tss@iki.fi>
parents: 9661
diff changeset
100 master_service_set_die_with_master(master_service, TRUE);
4149
b10fa8ba01ca When master dies (by closing log file descriptor), kill ourself also.
Timo Sirainen <tss@iki.fi>
parents: 4074
diff changeset
101
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
102 /* fake that we're running, so we know if client was destroyed
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
103 while handling its initial input */
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
104 io_loop_set_running(current_ioloop);
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
105 main_stdio_init_user(set, mail_user, user);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
106 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
107
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
108 static void
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
109 login_client_connected(const struct master_login_client *client,
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
110 const char *username, const char *const *extra_fields)
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
111 {
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
112 struct mail_storage_service_input input;
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
113 struct mail_storage_service_user *user;
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
114 struct mail_user *mail_user;
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
115 struct client *pop3_client;
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
116 const struct pop3_settings *set;
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
117 const char *error;
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
118 buffer_t input_buf;
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
119
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
120 if (pop3_clients != NULL) {
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
121 i_error("Can't handle more than one connection currently");
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
122 (void)close(client->fd);
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
123 return;
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
124 }
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
125
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
126 memset(&input, 0, sizeof(input));
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
127 input.module = input.service = "pop3";
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
128 input.local_ip = client->auth_req.local_ip;
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
129 input.remote_ip = client->auth_req.remote_ip;
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
130 input.username = username;
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
131 input.userdb_fields = extra_fields;
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
132
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
133 if (input.username == NULL) {
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
134 i_error("login client: Username missing from auth reply");
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
135 (void)close(client->fd);
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
136 return;
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
137 }
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
138 master_login_deinit(&master_login);
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
139
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
140 if (mail_storage_service_lookup_next(storage_service, &input,
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
141 &user, &mail_user, &error) <= 0)
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
142 i_fatal("%s", error);
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
143 set = mail_storage_service_user_get_set(user)[1];
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
144
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
145 restrict_access_allow_coredumps(TRUE);
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
146 if (set->shutdown_clients)
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
147 master_service_set_die_with_master(master_service, TRUE);
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
148
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
149 /* fake that we're running, so we know if client was destroyed
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
150 while handling its initial input */
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
151 io_loop_set_running(current_ioloop);
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
152
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
153 buffer_create_const_data(&input_buf, client->data,
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
154 client->auth_req.data_size);
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
155 pop3_client = client_create(client->fd, client->fd, mail_user,
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
156 user, set);
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
157 T_BEGIN {
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
158 client_add_input(pop3_client, &input_buf);
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
159 } T_END;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
160 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
161
9159
6324a79d3ee1 Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents: 9147
diff changeset
162 static void client_connected(const struct master_service_connection *conn)
6324a79d3ee1 Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents: 9147
diff changeset
163 {
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
164 if (master_login == NULL) {
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
165 /* running standalone, we shouldn't even get here */
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
166 (void)close(conn->fd);
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
167 } else {
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
168 master_login_add(master_login, conn->fd);
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
169 }
9159
6324a79d3ee1 Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents: 9147
diff changeset
170 }
6324a79d3ee1 Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents: 9147
diff changeset
171
10120
b584904d3bc7 Moved process title init to lib-master. With Linux-hack enabled it now preserves command args.
Timo Sirainen <tss@iki.fi>
parents: 10119
diff changeset
172 int main(int argc, char *argv[])
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
173 {
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
174 static const struct setting_parser_info *set_roots[] = {
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
175 &pop3_setting_parser_info,
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
176 NULL
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
177 };
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
178 enum master_service_flags service_flags = 0;
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
179 enum mail_storage_service_flags storage_service_flags = 0;
9002
9d0037a997f4 Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
180
2873
72f28a4b964d Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
181 if (IS_STANDALONE() && getuid() == 0 &&
72f28a4b964d Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
182 net_getpeername(1, NULL, NULL) == 0) {
72f28a4b964d Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
183 printf("-ERR pop3 binary must not be started from "
72f28a4b964d Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
184 "inetd, use pop3-login instead.\n");
72f28a4b964d Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
185 return 1;
72f28a4b964d Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
186 }
72f28a4b964d Make sure imap or pop3 processes cannot be started from inetd.
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
187
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
188 if (IS_STANDALONE()) {
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
189 service_flags |= MASTER_SERVICE_FLAG_STANDALONE |
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
190 MASTER_SERVICE_FLAG_STD_CLIENT;
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
191 } else {
9970
4b28edba5ff9 imap, pop3: Process permissions weren't properly dropped.
Timo Sirainen <tss@iki.fi>
parents: 9969
diff changeset
192 storage_service_flags |=
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
193 MAIL_STORAGE_SERVICE_FLAG_DISALLOW_ROOT;
9970
4b28edba5ff9 imap, pop3: Process permissions weren't properly dropped.
Timo Sirainen <tss@iki.fi>
parents: 9969
diff changeset
194 }
9080
e560b92ed763 imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents: 9059
diff changeset
195
10119
1e63221f5c83 Moved most of getopt() handling to lib-master.
Timo Sirainen <tss@iki.fi>
parents: 10101
diff changeset
196 master_service = master_service_init("pop3", service_flags,
10120
b584904d3bc7 Moved process title init to lib-master. With Linux-hack enabled it now preserves command args.
Timo Sirainen <tss@iki.fi>
parents: 10119
diff changeset
197 &argc, &argv, NULL);
10119
1e63221f5c83 Moved most of getopt() handling to lib-master.
Timo Sirainen <tss@iki.fi>
parents: 10101
diff changeset
198 if (master_getopt(master_service) > 0)
1e63221f5c83 Moved most of getopt() handling to lib-master.
Timo Sirainen <tss@iki.fi>
parents: 10101
diff changeset
199 return FATAL_DEFAULT;
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
200 master_service_init_finish(master_service);
9147
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9106
diff changeset
201
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
202 storage_service =
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
203 mail_storage_service_init(master_service,
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
204 set_roots, storage_service_flags);
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
205
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
206 if (IS_STANDALONE()) {
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
207 T_BEGIN {
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
208 main_stdio_run();
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
209 } T_END;
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
210 } else {
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
211 master_login = master_login_init("auth-master",
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
212 login_client_connected);
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
213 io_loop_set_running(current_ioloop);
9080
e560b92ed763 imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents: 9059
diff changeset
214 }
e560b92ed763 imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents: 9059
diff changeset
215
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
216 if (io_loop_is_running(current_ioloop))
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
217 master_service_run(master_service, client_connected);
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
218 clients_destroy_all();
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
219
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
220 if (master_login != NULL)
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 9970
diff changeset
221 master_login_deinit(&master_login);
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10120
diff changeset
222 mail_storage_service_deinit(&storage_service);
9348
0c587f108916 lib-master has now a global master_service variable that all binaries use.
Timo Sirainen <tss@iki.fi>
parents: 9263
diff changeset
223 master_service_deinit(&master_service);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
224 return 0;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
225 }