annotate src/lib-storage/mail-storage-service.c @ 12772:e26af53b6b40

lib-storage: MAIL_STORAGE_SERVICE_FLAG_DEBUG didn't do anything.
author Timo Sirainen <tss@iki.fi>
date Fri, 04 Mar 2011 03:16:15 +0200
parents cec7fa92ff48
children 447bce266022
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10582
615eef3139c2 Updated copyright notices to include year 2010.
Timo Sirainen <tss@iki.fi>
parents: 10506
diff changeset
1 /* Copyright (c) 2009-2010 Dovecot authors, see the included COPYING file */
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "lib.h"
9495
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
4 #include "ioloop.h"
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "array.h"
9063
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
6 #include "hostpid.h"
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "module-dir.h"
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 #include "restrict-access.h"
10390
ce0ff560cd80 mail storage service: And added missing #include for previous change.
Timo Sirainen <tss@iki.fi>
parents: 10389
diff changeset
9 #include "eacces-error.h"
9063
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
10 #include "str.h"
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
11 #include "var-expand.h"
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
12 #include "dict.h"
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 #include "settings-parser.h"
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 #include "auth-master.h"
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 #include "master-service-private.h"
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 #include "master-service-settings.h"
10793
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
17 #include "master-service-settings-cache.h"
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 #include "mail-user.h"
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19 #include "mail-namespace.h"
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20 #include "mail-storage.h"
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21 #include "mail-storage-service.h"
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23 #include <stdlib.h>
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24 #include <sys/stat.h>
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25 #include <pwd.h>
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26 #include <grp.h>
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27
10138
8e3fd502d54e mail storage service: Returning "nice" from userdb again changes process priority.
Timo Sirainen <tss@iki.fi>
parents: 10134
diff changeset
28 #ifdef HAVE_SYS_TIME_H
8e3fd502d54e mail storage service: Returning "nice" from userdb again changes process priority.
Timo Sirainen <tss@iki.fi>
parents: 10134
diff changeset
29 # include <sys/time.h>
8e3fd502d54e mail storage service: Returning "nice" from userdb again changes process priority.
Timo Sirainen <tss@iki.fi>
parents: 10134
diff changeset
30 #endif
8e3fd502d54e mail storage service: Returning "nice" from userdb again changes process priority.
Timo Sirainen <tss@iki.fi>
parents: 10134
diff changeset
31 #ifdef HAVE_SYS_RESOURCE_H
8e3fd502d54e mail storage service: Returning "nice" from userdb again changes process priority.
Timo Sirainen <tss@iki.fi>
parents: 10134
diff changeset
32 # include <sys/resource.h>
8e3fd502d54e mail storage service: Returning "nice" from userdb again changes process priority.
Timo Sirainen <tss@iki.fi>
parents: 10134
diff changeset
33 #endif
8e3fd502d54e mail storage service: Returning "nice" from userdb again changes process priority.
Timo Sirainen <tss@iki.fi>
parents: 10134
diff changeset
34
9495
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
35 /* If time moves backwards more than this, kill ourself instead of sleeping. */
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
36 #define MAX_TIME_BACKWARDS_SLEEP 5
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
37 #define MAX_NOWARN_FORWARD_SECS 10
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
38
11018
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
39 #define ERRSTR_INVALID_USER_SETTINGS \
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
40 "Invalid user settings. Refer to server log for more information."
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
41
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
42 struct mail_storage_service_ctx {
10793
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
43 pool_t pool;
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44 struct master_service *service;
9289
0e02c867b15a mail storage multi service: Added support for iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 9263
diff changeset
45 struct auth_master_connection *conn;
0e02c867b15a mail storage multi service: Added support for iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 9263
diff changeset
46 struct auth_master_user_list_ctx *auth_list;
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
47 const struct setting_parser_info **set_roots;
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48 enum mail_storage_service_flags flags;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49
10793
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
50 const char *set_cache_module, *set_cache_service;
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
51 struct master_service_settings_cache *set_cache;
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
52
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
53 unsigned int debug:1;
11750
b0e0d4537496 mail-storage-service: Initialize logging with proper settings a bit earlier.
Timo Sirainen <tss@iki.fi>
parents: 11749
diff changeset
54 unsigned int log_initialized:1;
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55 };
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
57 struct mail_storage_service_user {
9108
14ebbf71ef3e mail_storage_service_multi*() API change and fixes.
Timo Sirainen <tss@iki.fi>
parents: 9106
diff changeset
58 pool_t pool;
9147
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9118
diff changeset
59 struct mail_storage_service_input input;
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9118
diff changeset
60
12722
888999441619 lib-storage: Give restrict_access() uid/gid source (userdb or mail_u/gid setting).
Timo Sirainen <tss@iki.fi>
parents: 12705
diff changeset
61 const char *system_groups_user, *uid_source, *gid_source;
9108
14ebbf71ef3e mail_storage_service_multi*() API change and fixes.
Timo Sirainen <tss@iki.fi>
parents: 9106
diff changeset
62 const struct mail_user_settings *user_set;
10134
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
63 const struct setting_parser_info *user_info;
9108
14ebbf71ef3e mail_storage_service_multi*() API change and fixes.
Timo Sirainen <tss@iki.fi>
parents: 9106
diff changeset
64 struct setting_parser_context *set_parser;
14ebbf71ef3e mail_storage_service_multi*() API change and fixes.
Timo Sirainen <tss@iki.fi>
parents: 9106
diff changeset
65 };
14ebbf71ef3e mail_storage_service_multi*() API change and fixes.
Timo Sirainen <tss@iki.fi>
parents: 9106
diff changeset
66
10857
02d4cc578d4b mail storage service: Exported modules as mail_storage_service_modules.
Timo Sirainen <tss@iki.fi>
parents: 10856
diff changeset
67 struct module *mail_storage_service_modules = NULL;
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68
11057
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
69 static bool
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
70 mail_user_set_get_mail_debug(const struct setting_parser_info *user_info,
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
71 const struct mail_user_settings *user_set)
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
72 {
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
73 const struct mail_storage_settings *mail_set;
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
74
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
75 mail_set = mail_user_set_get_driver_settings(user_info, user_set,
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
76 MAIL_STORAGE_SET_DRIVER_NAME);
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
77 return mail_set->mail_debug;
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
78 }
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
79
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
80 static void set_keyval(struct mail_storage_service_ctx *ctx,
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
81 struct mail_storage_service_user *user,
9082
ea2117eaa8d1 Added master_service_set().
Timo Sirainen <tss@iki.fi>
parents: 9080
diff changeset
82 const char *key, const char *value)
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
83 {
11057
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
84 struct setting_parser_context *set_parser = user->set_parser;
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
85 const char *str;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86
11057
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
87 if (master_service_set_has_config_override(ctx->service, key)) {
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
88 /* this setting was already overridden with -o parameter */
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
89 if (mail_user_set_get_mail_debug(user->user_info,
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
90 user->user_set)) {
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
91 i_debug("Ignoring overridden (-o) userdb setting: %s",
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
92 key);
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
93 }
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
94 return;
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
95 }
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
96
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97 str = t_strconcat(key, "=", value, NULL);
9108
14ebbf71ef3e mail_storage_service_multi*() API change and fixes.
Timo Sirainen <tss@iki.fi>
parents: 9106
diff changeset
98 if (settings_parse_line(set_parser, str) < 0) {
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
99 i_fatal("Invalid userdb input '%s': %s", str,
9108
14ebbf71ef3e mail_storage_service_multi*() API change and fixes.
Timo Sirainen <tss@iki.fi>
parents: 9106
diff changeset
100 settings_parser_get_error(set_parser));
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
101 }
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
102 }
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
103
11057
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
104 static int set_line(struct mail_storage_service_ctx *ctx,
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
105 struct mail_storage_service_user *user,
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
106 const char *line)
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
107 {
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
108 struct setting_parser_context *set_parser = user->set_parser;
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
109 bool mail_debug;
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
110 const char *key;
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
111 int ret;
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
112
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
113 mail_debug = mail_user_set_get_mail_debug(user->user_info,
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
114 user->user_set);
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
115 if (strchr(line, '=') == NULL)
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
116 line = t_strconcat(line, "=yes", NULL);
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
117 key = t_strcut(line, '=');
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
118
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
119 if (!settings_parse_is_valid_key(set_parser, key)) {
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
120 /* assume it's a plugin setting */
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
121 key = t_strconcat("plugin/", key, NULL);
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
122 line = t_strconcat("plugin/", line, NULL);
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
123 }
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
124
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
125 if (master_service_set_has_config_override(ctx->service, key)) {
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
126 /* this setting was already overridden with -o parameter */
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
127 if (mail_debug) {
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
128 i_debug("Ignoring overridden (-o) userdb setting: %s",
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
129 key);
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
130 }
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
131 return 1;
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
132 }
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
133
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
134 ret = settings_parse_line(set_parser, line);
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
135 if (mail_debug && ret >= 0) {
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
136 i_debug(ret == 0 ?
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
137 "Unknown userdb setting: %s" :
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
138 "Added userdb setting: %s", line);
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
139 }
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
140 return ret;
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
141 }
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
142
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
143 static bool validate_chroot(const struct mail_user_settings *user_set,
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
144 const char *dir)
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
145 {
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
146 const char *const *chroot_dirs;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
147
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
148 if (*dir == '\0')
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
149 return FALSE;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
150
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
151 if (*user_set->valid_chroot_dirs == '\0')
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
152 return FALSE;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
153
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
154 chroot_dirs = t_strsplit(user_set->valid_chroot_dirs, ":");
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
155 while (*chroot_dirs != NULL) {
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
156 if (**chroot_dirs != '\0' &&
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
157 strncmp(dir, *chroot_dirs, strlen(*chroot_dirs)) == 0)
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
158 return TRUE;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
159 chroot_dirs++;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
160 }
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
161 return FALSE;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
162 }
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
163
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
164 static int
11057
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
165 user_reply_handle(struct mail_storage_service_ctx *ctx,
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
166 struct mail_storage_service_user *user,
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
167 const struct auth_user_reply *reply,
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
168 const char **error_r)
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
169 {
12431
eeaf30cfad36 Fixed home=/home/./user style chrooting to work again.
Timo Sirainen <tss@iki.fi>
parents: 12302
diff changeset
170 const char *home = reply->home;
eeaf30cfad36 Fixed home=/home/./user style chrooting to work again.
Timo Sirainen <tss@iki.fi>
parents: 12302
diff changeset
171 const char *chroot = reply->chroot;
eeaf30cfad36 Fixed home=/home/./user style chrooting to work again.
Timo Sirainen <tss@iki.fi>
parents: 12302
diff changeset
172 const char *const *str, *line, *p;
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
173 unsigned int i, count;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
174 int ret = 0;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
175
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
176 if (reply->uid != (uid_t)-1) {
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
177 if (reply->uid == 0) {
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
178 *error_r = "userdb returned 0 as uid";
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
179 return -1;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
180 }
12722
888999441619 lib-storage: Give restrict_access() uid/gid source (userdb or mail_u/gid setting).
Timo Sirainen <tss@iki.fi>
parents: 12705
diff changeset
181 user->uid_source = "userdb lookup";
11057
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
182 set_keyval(ctx, user, "mail_uid", dec2str(reply->uid));
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
183 }
12722
888999441619 lib-storage: Give restrict_access() uid/gid source (userdb or mail_u/gid setting).
Timo Sirainen <tss@iki.fi>
parents: 12705
diff changeset
184 if (reply->gid != (uid_t)-1) {
888999441619 lib-storage: Give restrict_access() uid/gid source (userdb or mail_u/gid setting).
Timo Sirainen <tss@iki.fi>
parents: 12705
diff changeset
185 user->gid_source = "userdb lookup";
11057
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
186 set_keyval(ctx, user, "mail_gid", dec2str(reply->gid));
12722
888999441619 lib-storage: Give restrict_access() uid/gid source (userdb or mail_u/gid setting).
Timo Sirainen <tss@iki.fi>
parents: 12705
diff changeset
187 }
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
188
12431
eeaf30cfad36 Fixed home=/home/./user style chrooting to work again.
Timo Sirainen <tss@iki.fi>
parents: 12302
diff changeset
189 if (home != NULL && chroot == NULL &&
eeaf30cfad36 Fixed home=/home/./user style chrooting to work again.
Timo Sirainen <tss@iki.fi>
parents: 12302
diff changeset
190 *user->user_set->valid_chroot_dirs != '\0' &&
eeaf30cfad36 Fixed home=/home/./user style chrooting to work again.
Timo Sirainen <tss@iki.fi>
parents: 12302
diff changeset
191 (p = strstr(home, "/./")) != NULL) {
eeaf30cfad36 Fixed home=/home/./user style chrooting to work again.
Timo Sirainen <tss@iki.fi>
parents: 12302
diff changeset
192 /* wu-ftpd like <chroot>/./<home> - check only if there's even
eeaf30cfad36 Fixed home=/home/./user style chrooting to work again.
Timo Sirainen <tss@iki.fi>
parents: 12302
diff changeset
193 a possibility of using them (non-empty valid_chroot_dirs) */
eeaf30cfad36 Fixed home=/home/./user style chrooting to work again.
Timo Sirainen <tss@iki.fi>
parents: 12302
diff changeset
194 chroot = t_strdup_until(home, p);
eeaf30cfad36 Fixed home=/home/./user style chrooting to work again.
Timo Sirainen <tss@iki.fi>
parents: 12302
diff changeset
195 home = p + 2;
eeaf30cfad36 Fixed home=/home/./user style chrooting to work again.
Timo Sirainen <tss@iki.fi>
parents: 12302
diff changeset
196 }
eeaf30cfad36 Fixed home=/home/./user style chrooting to work again.
Timo Sirainen <tss@iki.fi>
parents: 12302
diff changeset
197
eeaf30cfad36 Fixed home=/home/./user style chrooting to work again.
Timo Sirainen <tss@iki.fi>
parents: 12302
diff changeset
198 if (home != NULL)
11057
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
199 set_keyval(ctx, user, "mail_home", reply->home);
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
200
12431
eeaf30cfad36 Fixed home=/home/./user style chrooting to work again.
Timo Sirainen <tss@iki.fi>
parents: 12302
diff changeset
201 if (chroot != NULL) {
eeaf30cfad36 Fixed home=/home/./user style chrooting to work again.
Timo Sirainen <tss@iki.fi>
parents: 12302
diff changeset
202 if (!validate_chroot(user->user_set, chroot)) {
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
203 *error_r = t_strdup_printf(
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
204 "userdb returned invalid chroot directory: %s "
12431
eeaf30cfad36 Fixed home=/home/./user style chrooting to work again.
Timo Sirainen <tss@iki.fi>
parents: 12302
diff changeset
205 "(see valid_chroot_dirs setting)", chroot);
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
206 return -1;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
207 }
12431
eeaf30cfad36 Fixed home=/home/./user style chrooting to work again.
Timo Sirainen <tss@iki.fi>
parents: 12302
diff changeset
208 set_keyval(ctx, user, "mail_chroot", chroot);
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
209 }
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
210
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
211 str = array_get(&reply->extra_fields, &count);
10879
ce166f70ea71 mail storage service: Only some userdb extra fields were used.
Timo Sirainen <tss@iki.fi>
parents: 10857
diff changeset
212 for (i = 0; i < count && ret >= 0; i++) {
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
213 line = str[i];
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
214 if (strncmp(line, "system_groups_user=", 19) == 0) {
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
215 user->system_groups_user =
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
216 p_strdup(user->pool, line + 19);
10138
8e3fd502d54e mail storage service: Returning "nice" from userdb again changes process priority.
Timo Sirainen <tss@iki.fi>
parents: 10134
diff changeset
217 } else if (strncmp(line, "nice=", 5) == 0) {
8e3fd502d54e mail storage service: Returning "nice" from userdb again changes process priority.
Timo Sirainen <tss@iki.fi>
parents: 10134
diff changeset
218 #ifdef HAVE_SETPRIORITY
8e3fd502d54e mail storage service: Returning "nice" from userdb again changes process priority.
Timo Sirainen <tss@iki.fi>
parents: 10134
diff changeset
219 int n = atoi(line + 5);
8e3fd502d54e mail storage service: Returning "nice" from userdb again changes process priority.
Timo Sirainen <tss@iki.fi>
parents: 10134
diff changeset
220
8e3fd502d54e mail storage service: Returning "nice" from userdb again changes process priority.
Timo Sirainen <tss@iki.fi>
parents: 10134
diff changeset
221 if (n != 0) {
8e3fd502d54e mail storage service: Returning "nice" from userdb again changes process priority.
Timo Sirainen <tss@iki.fi>
parents: 10134
diff changeset
222 if (setpriority(PRIO_PROCESS, 0, n) < 0)
8e3fd502d54e mail storage service: Returning "nice" from userdb again changes process priority.
Timo Sirainen <tss@iki.fi>
parents: 10134
diff changeset
223 i_error("setpriority(%d) failed: %m", n);
8e3fd502d54e mail storage service: Returning "nice" from userdb again changes process priority.
Timo Sirainen <tss@iki.fi>
parents: 10134
diff changeset
224 }
8e3fd502d54e mail storage service: Returning "nice" from userdb again changes process priority.
Timo Sirainen <tss@iki.fi>
parents: 10134
diff changeset
225 #endif
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
226 } else T_BEGIN {
11057
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
227 ret = set_line(ctx, user, line);
9963
6a3667ea47d7 Crashfix.
Timo Sirainen <tss@iki.fi>
parents: 9912
diff changeset
228 } T_END;
6a3667ea47d7 Crashfix.
Timo Sirainen <tss@iki.fi>
parents: 9912
diff changeset
229 }
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
230
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
231 if (ret < 0) {
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
232 *error_r = t_strdup_printf("Invalid userdb input '%s': %s",
11057
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
233 str[i], settings_parser_get_error(user->set_parser));
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
234 }
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
235 return ret;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
236 }
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
237
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
238 static int
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
239 service_auth_userdb_lookup(struct mail_storage_service_ctx *ctx,
9830
0919ab922086 Added auth_master_pass_lookup() and changed auth_master_used_lookup() API.
Timo Sirainen <tss@iki.fi>
parents: 9523
diff changeset
240 const struct mail_storage_service_input *input,
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 10098
diff changeset
241 pool_t pool, const char **user,
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 10098
diff changeset
242 const char *const **fields_r,
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
243 const char **error_r)
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
244 {
9830
0919ab922086 Added auth_master_pass_lookup() and changed auth_master_used_lookup() API.
Timo Sirainen <tss@iki.fi>
parents: 9523
diff changeset
245 struct auth_user_info info;
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 10098
diff changeset
246 const char *new_username;
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
247 int ret;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
248
9830
0919ab922086 Added auth_master_pass_lookup() and changed auth_master_used_lookup() API.
Timo Sirainen <tss@iki.fi>
parents: 9523
diff changeset
249 memset(&info, 0, sizeof(info));
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
250 info.service = ctx->service->name;
9830
0919ab922086 Added auth_master_pass_lookup() and changed auth_master_used_lookup() API.
Timo Sirainen <tss@iki.fi>
parents: 9523
diff changeset
251 info.local_ip = input->local_ip;
0919ab922086 Added auth_master_pass_lookup() and changed auth_master_used_lookup() API.
Timo Sirainen <tss@iki.fi>
parents: 9523
diff changeset
252 info.remote_ip = input->remote_ip;
0919ab922086 Added auth_master_pass_lookup() and changed auth_master_used_lookup() API.
Timo Sirainen <tss@iki.fi>
parents: 9523
diff changeset
253
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
254 ret = auth_master_user_lookup(ctx->conn, *user, &info, pool,
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 10098
diff changeset
255 &new_username, fields_r);
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
256 if (ret > 0) {
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 10098
diff changeset
257 if (strcmp(*user, new_username) != 0) {
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
258 if (ctx->debug)
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 10098
diff changeset
259 i_debug("changed username to %s", new_username);
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 10098
diff changeset
260 *user = t_strdup(new_username);
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 10098
diff changeset
261 }
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 10098
diff changeset
262 *user = new_username;
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 10098
diff changeset
263 } else if (ret == 0)
11018
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
264 *error_r = "Unknown user";
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
265 else if (**fields_r != NULL) {
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
266 *error_r = t_strdup(**fields_r);
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
267 ret = -2;
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
268 } else {
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
269 *error_r = MAIL_ERRSTR_CRITICAL_MSG;
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
270 }
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
271 return ret;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
272 }
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
273
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
274 static bool parse_uid(const char *str, uid_t *uid_r)
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
275 {
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
276 struct passwd *pw;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
277
11086
260e190306b0 Started using str_to_*() functions instead of libc's ones.
Timo Sirainen <tss@iki.fi>
parents: 11078
diff changeset
278 if (str_to_uid(str, uid_r) == 0)
260e190306b0 Started using str_to_*() functions instead of libc's ones.
Timo Sirainen <tss@iki.fi>
parents: 11078
diff changeset
279 return TRUE;
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
280
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
281 pw = getpwnam(str);
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
282 if (pw == NULL)
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
283 return FALSE;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
284
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
285 *uid_r = pw->pw_uid;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
286 return TRUE;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
287 }
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
288
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
289 static bool parse_gid(const char *str, gid_t *gid_r)
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
290 {
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
291 struct group *gr;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
292
11086
260e190306b0 Started using str_to_*() functions instead of libc's ones.
Timo Sirainen <tss@iki.fi>
parents: 11078
diff changeset
293 if (str_to_gid(str, gid_r) == 0)
260e190306b0 Started using str_to_*() functions instead of libc's ones.
Timo Sirainen <tss@iki.fi>
parents: 11078
diff changeset
294 return TRUE;
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
295
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
296 gr = getgrnam(str);
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
297 if (gr == NULL)
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
298 return FALSE;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
299
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
300 *gid_r = gr->gr_gid;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
301 return TRUE;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
302 }
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
303
10929
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
304 static int
12722
888999441619 lib-storage: Give restrict_access() uid/gid source (userdb or mail_u/gid setting).
Timo Sirainen <tss@iki.fi>
parents: 12705
diff changeset
305 service_drop_privileges(struct mail_storage_service_user *user,
888999441619 lib-storage: Give restrict_access() uid/gid source (userdb or mail_u/gid setting).
Timo Sirainen <tss@iki.fi>
parents: 12705
diff changeset
306 const struct mail_user_settings *set,
10123
f6257036f7ef mail_chroot can now contain %variables.
Timo Sirainen <tss@iki.fi>
parents: 10121
diff changeset
307 const char *home, const char *chroot,
10462
2a74d458339d Added mail_storage_service_restrict_setenv().
Timo Sirainen <tss@iki.fi>
parents: 10461
diff changeset
308 bool disallow_root, bool keep_setuid_root,
10929
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
309 bool setenv_only, const char **error_r)
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
310 {
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
311 struct restrict_access_settings rset;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
312 uid_t current_euid, setuid_uid = 0;
11136
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
313 const char *cur_chroot;
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
314
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
315 current_euid = geteuid();
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
316 restrict_access_init(&rset);
12017
d6f387fe1275 lib-storage: Preserve permission settings in master's service blocks.
Timo Sirainen <tss@iki.fi>
parents: 11906
diff changeset
317 restrict_access_get_env(&rset);
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
318 if (*set->mail_uid != '\0') {
10929
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
319 if (!parse_uid(set->mail_uid, &rset.uid)) {
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
320 *error_r = t_strdup_printf("Unknown mail_uid user: %s",
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
321 set->mail_uid);
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
322 return -1;
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
323 }
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
324 if (rset.uid < (uid_t)set->first_valid_uid ||
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
325 (set->last_valid_uid != 0 &&
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
326 rset.uid > (uid_t)set->last_valid_uid)) {
10929
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
327 *error_r = t_strdup_printf(
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
328 "Mail access for users with UID %s "
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
329 "not permitted (see first_valid_uid in config file).",
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
330 dec2str(rset.uid));
10929
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
331 return -1;
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
332 }
12722
888999441619 lib-storage: Give restrict_access() uid/gid source (userdb or mail_u/gid setting).
Timo Sirainen <tss@iki.fi>
parents: 12705
diff changeset
333 rset.uid_source = user->uid_source;
12042
14190cceb903 lda: Don't fail with "mail_uid/mail_gid not set" error when running without -u.
Timo Sirainen <tss@iki.fi>
parents: 12022
diff changeset
334 } else if (rset.uid == (uid_t)-1 &&
14190cceb903 lda: Don't fail with "mail_uid/mail_gid not set" error when running without -u.
Timo Sirainen <tss@iki.fi>
parents: 12022
diff changeset
335 disallow_root && current_euid == 0) {
12021
53e74e057506 lib-storage: Give better error message if user is missing UID/GID
Timo Sirainen <tss@iki.fi>
parents: 12017
diff changeset
336 *error_r = "User is missing UID (see mail_uid setting)";
53e74e057506 lib-storage: Give better error message if user is missing UID/GID
Timo Sirainen <tss@iki.fi>
parents: 12017
diff changeset
337 return -1;
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
338 }
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
339 if (*set->mail_gid != '\0') {
10929
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
340 if (!parse_gid(set->mail_gid, &rset.gid)) {
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
341 *error_r = t_strdup_printf("Unknown mail_gid group: %s",
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
342 set->mail_gid);
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
343 return -1;
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
344 }
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
345 if (rset.gid < (gid_t)set->first_valid_gid ||
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
346 (set->last_valid_gid != 0 &&
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
347 rset.gid > (gid_t)set->last_valid_gid)) {
10929
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
348 *error_r = t_strdup_printf(
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
349 "Mail access for users with GID %s "
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
350 "not permitted (see first_valid_gid in config file).",
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
351 dec2str(rset.gid));
10929
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
352 return -1;
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
353 }
12722
888999441619 lib-storage: Give restrict_access() uid/gid source (userdb or mail_u/gid setting).
Timo Sirainen <tss@iki.fi>
parents: 12705
diff changeset
354 rset.gid_source = user->gid_source;
12042
14190cceb903 lda: Don't fail with "mail_uid/mail_gid not set" error when running without -u.
Timo Sirainen <tss@iki.fi>
parents: 12022
diff changeset
355 } else if (rset.gid == (gid_t)-1 && disallow_root &&
14190cceb903 lda: Don't fail with "mail_uid/mail_gid not set" error when running without -u.
Timo Sirainen <tss@iki.fi>
parents: 12022
diff changeset
356 set->first_valid_gid > 0 && getegid() == 0) {
12021
53e74e057506 lib-storage: Give better error message if user is missing UID/GID
Timo Sirainen <tss@iki.fi>
parents: 12017
diff changeset
357 *error_r = "User is missing GID (see mail_gid setting)";
53e74e057506 lib-storage: Give better error message if user is missing UID/GID
Timo Sirainen <tss@iki.fi>
parents: 12017
diff changeset
358 return -1;
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
359 }
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
360 if (*set->mail_privileged_group != '\0') {
10403
a1018630276b mail_privileged_group was parsed as user, not group.
Timo Sirainen <tss@iki.fi>
parents: 10390
diff changeset
361 if (!parse_gid(set->mail_privileged_group, &rset.privileged_gid)) {
10929
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
362 *error_r = t_strdup_printf(
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
363 "Unknown mail_privileged_group: %s",
10403
a1018630276b mail_privileged_group was parsed as user, not group.
Timo Sirainen <tss@iki.fi>
parents: 10390
diff changeset
364 set->mail_gid);
10929
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
365 return -1;
10403
a1018630276b mail_privileged_group was parsed as user, not group.
Timo Sirainen <tss@iki.fi>
parents: 10390
diff changeset
366 }
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
367 }
12017
d6f387fe1275 lib-storage: Preserve permission settings in master's service blocks.
Timo Sirainen <tss@iki.fi>
parents: 11906
diff changeset
368 if (*set->mail_access_groups != '\0') {
d6f387fe1275 lib-storage: Preserve permission settings in master's service blocks.
Timo Sirainen <tss@iki.fi>
parents: 11906
diff changeset
369 rset.extra_groups = t_strconcat(set->mail_access_groups, ",",
d6f387fe1275 lib-storage: Preserve permission settings in master's service blocks.
Timo Sirainen <tss@iki.fi>
parents: 11906
diff changeset
370 rset.extra_groups, NULL);
d6f387fe1275 lib-storage: Preserve permission settings in master's service blocks.
Timo Sirainen <tss@iki.fi>
parents: 11906
diff changeset
371 }
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
372
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
373 rset.first_valid_gid = set->first_valid_gid;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
374 rset.last_valid_gid = set->last_valid_gid;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
375 /* we can't chroot if we want to switch between users. there's not
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
376 much point either (from security point of view) */
10123
f6257036f7ef mail_chroot can now contain %variables.
Timo Sirainen <tss@iki.fi>
parents: 10121
diff changeset
377 rset.chroot_dir = *chroot == '\0' || keep_setuid_root ? NULL : chroot;
12722
888999441619 lib-storage: Give restrict_access() uid/gid source (userdb or mail_u/gid setting).
Timo Sirainen <tss@iki.fi>
parents: 12705
diff changeset
378 rset.system_groups_user = user->system_groups_user;
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
379
11136
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
380 cur_chroot = restrict_access_get_current_chroot();
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
381 if (cur_chroot != NULL) {
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
382 if (rset.chroot_dir == NULL) {
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
383 *error_r = "Process is already chrooted, "
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
384 "can't un-chroot for this user";
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
385 return -1;
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
386 }
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
387 if (strcmp(rset.chroot_dir, cur_chroot) != 0) {
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
388 *error_r = t_strdup_printf(
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
389 "Process is already chrooted to %s, "
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
390 "can't chroot to %s", cur_chroot, chroot);
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
391 return -1;
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
392 }
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
393 /* chrooting to same directory where we're already chrooted */
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
394 rset.chroot_dir = NULL;
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
395 }
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
396
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
397 if (disallow_root &&
10929
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
398 (rset.uid == 0 || (rset.uid == (uid_t)-1 && current_euid == 0))) {
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
399 *error_r = "Mail access not allowed for root";
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
400 return -1;
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
401 }
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
402
9118
03fe226e85d4 mail-storage-service: Fixes to handling multiple users.
Timo Sirainen <tss@iki.fi>
parents: 9108
diff changeset
403 if (keep_setuid_root) {
03fe226e85d4 mail-storage-service: Fixes to handling multiple users.
Timo Sirainen <tss@iki.fi>
parents: 9108
diff changeset
404 if (current_euid != rset.uid) {
03fe226e85d4 mail-storage-service: Fixes to handling multiple users.
Timo Sirainen <tss@iki.fi>
parents: 9108
diff changeset
405 if (current_euid != 0) {
03fe226e85d4 mail-storage-service: Fixes to handling multiple users.
Timo Sirainen <tss@iki.fi>
parents: 9108
diff changeset
406 /* we're changing the UID,
03fe226e85d4 mail-storage-service: Fixes to handling multiple users.
Timo Sirainen <tss@iki.fi>
parents: 9108
diff changeset
407 switch back to root first */
03fe226e85d4 mail-storage-service: Fixes to handling multiple users.
Timo Sirainen <tss@iki.fi>
parents: 9108
diff changeset
408 if (seteuid(0) < 0)
03fe226e85d4 mail-storage-service: Fixes to handling multiple users.
Timo Sirainen <tss@iki.fi>
parents: 9108
diff changeset
409 i_fatal("seteuid(0) failed: %m");
03fe226e85d4 mail-storage-service: Fixes to handling multiple users.
Timo Sirainen <tss@iki.fi>
parents: 9108
diff changeset
410 }
03fe226e85d4 mail-storage-service: Fixes to handling multiple users.
Timo Sirainen <tss@iki.fi>
parents: 9108
diff changeset
411 setuid_uid = rset.uid;
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
412 }
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
413 rset.uid = (uid_t)-1;
9118
03fe226e85d4 mail-storage-service: Fixes to handling multiple users.
Timo Sirainen <tss@iki.fi>
parents: 9108
diff changeset
414 disallow_root = FALSE;
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
415 }
10462
2a74d458339d Added mail_storage_service_restrict_setenv().
Timo Sirainen <tss@iki.fi>
parents: 10461
diff changeset
416 if (!setenv_only) {
2a74d458339d Added mail_storage_service_restrict_setenv().
Timo Sirainen <tss@iki.fi>
parents: 10461
diff changeset
417 restrict_access(&rset, *home == '\0' ? NULL : home,
2a74d458339d Added mail_storage_service_restrict_setenv().
Timo Sirainen <tss@iki.fi>
parents: 10461
diff changeset
418 disallow_root);
2a74d458339d Added mail_storage_service_restrict_setenv().
Timo Sirainen <tss@iki.fi>
parents: 10461
diff changeset
419 } else {
2a74d458339d Added mail_storage_service_restrict_setenv().
Timo Sirainen <tss@iki.fi>
parents: 10461
diff changeset
420 restrict_access_set_env(&rset);
2a74d458339d Added mail_storage_service_restrict_setenv().
Timo Sirainen <tss@iki.fi>
parents: 10461
diff changeset
421 }
2a74d458339d Added mail_storage_service_restrict_setenv().
Timo Sirainen <tss@iki.fi>
parents: 10461
diff changeset
422 if (setuid_uid != 0 && !setenv_only) {
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
423 if (seteuid(setuid_uid) < 0)
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
424 i_fatal("seteuid(%s) failed: %m", dec2str(setuid_uid));
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
425 }
10929
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
426 return 0;
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
427 }
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
428
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
429 static int
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
430 mail_storage_service_init_post(struct mail_storage_service_ctx *ctx,
10134
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
431 struct mail_storage_service_user *user,
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
432 const char *home, struct mail_user **mail_user_r,
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
433 const char **error_r)
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
434 {
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
435 const struct mail_storage_settings *mail_set;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
436 struct mail_user *mail_user;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
437
10134
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
438 mail_user = mail_user_alloc(user->input.username, user->user_info,
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
439 user->user_set);
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
440 mail_user_set_home(mail_user, *home == '\0' ? NULL : home);
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
441 mail_user_set_vars(mail_user, geteuid(), ctx->service->name,
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
442 &user->input.local_ip, &user->input.remote_ip);
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
443
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
444 mail_set = mail_user_set_get_storage_set(mail_user);
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
445
9063
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
446 if (mail_set->mail_debug) {
10082
62b37dcf173e Log debug-level messages with i_debug().
Pascal Volk <user@localhost.localdomain.org>
parents: 9970
diff changeset
447 i_debug("Effective uid=%s, gid=%s, home=%s",
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
448 dec2str(geteuid()), dec2str(getegid()), home);
9063
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
449 }
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
450
10365
7664afedc7bb MAIL_STORAGE_SERVICE_FLAG_ENABLE_CORE_DUMPS: Also chdir() to home dir.
Timo Sirainen <tss@iki.fi>
parents: 10363
diff changeset
451 if ((ctx->flags & MAIL_STORAGE_SERVICE_FLAG_TEMP_PRIV_DROP) != 0 &&
7664afedc7bb MAIL_STORAGE_SERVICE_FLAG_ENABLE_CORE_DUMPS: Also chdir() to home dir.
Timo Sirainen <tss@iki.fi>
parents: 10363
diff changeset
452 (ctx->flags & MAIL_STORAGE_SERVICE_FLAG_ENABLE_CORE_DUMPS) == 0) {
9118
03fe226e85d4 mail-storage-service: Fixes to handling multiple users.
Timo Sirainen <tss@iki.fi>
parents: 9108
diff changeset
453 /* we don't want to write core files to any users' home
03fe226e85d4 mail-storage-service: Fixes to handling multiple users.
Timo Sirainen <tss@iki.fi>
parents: 9108
diff changeset
454 directories since they could contain information about other
03fe226e85d4 mail-storage-service: Fixes to handling multiple users.
Timo Sirainen <tss@iki.fi>
parents: 9108
diff changeset
455 users' mails as well. so do no chdiring to home. */
9523
3f9dcaf102d1 mail storage service: Added MAIL_STORAGE_SERVICE_FLAG_NO_CHDIR.
Timo Sirainen <tss@iki.fi>
parents: 9495
diff changeset
456 } else if (*home != '\0' &&
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
457 (ctx->flags & MAIL_STORAGE_SERVICE_FLAG_NO_CHDIR) == 0) {
9118
03fe226e85d4 mail-storage-service: Fixes to handling multiple users.
Timo Sirainen <tss@iki.fi>
parents: 9108
diff changeset
458 /* If possible chdir to home directory, so that core file
03fe226e85d4 mail-storage-service: Fixes to handling multiple users.
Timo Sirainen <tss@iki.fi>
parents: 9108
diff changeset
459 could be written in case we crash. */
9407
6a2660115d3d mail_storage_service*() chdired to base_dir instead of user's home dir.
Timo Sirainen <tss@iki.fi>
parents: 9300
diff changeset
460 if (chdir(home) < 0) {
10389
05b50522442f mail storage service: If chdir() fails with EACCES, give a better error message.
Timo Sirainen <tss@iki.fi>
parents: 10365
diff changeset
461 if (errno == EACCES) {
05b50522442f mail storage service: If chdir() fails with EACCES, give a better error message.
Timo Sirainen <tss@iki.fi>
parents: 10365
diff changeset
462 i_error("%s", eacces_error_get("chdir",
05b50522442f mail storage service: If chdir() fails with EACCES, give a better error message.
Timo Sirainen <tss@iki.fi>
parents: 10365
diff changeset
463 t_strconcat(home, "/", NULL)));
05b50522442f mail storage service: If chdir() fails with EACCES, give a better error message.
Timo Sirainen <tss@iki.fi>
parents: 10365
diff changeset
464 } if (errno != ENOENT)
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
465 i_error("chdir(%s) failed: %m", home);
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
466 else if (mail_set->mail_debug)
10082
62b37dcf173e Log debug-level messages with i_debug().
Pascal Volk <user@localhost.localdomain.org>
parents: 9970
diff changeset
467 i_debug("Home dir not found: %s", home);
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
468 }
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
469 }
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
470
9080
e560b92ed763 imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents: 9076
diff changeset
471 if (mail_user_init(mail_user, error_r) < 0) {
e560b92ed763 imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents: 9076
diff changeset
472 mail_user_unref(&mail_user);
e560b92ed763 imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents: 9076
diff changeset
473 return -1;
e560b92ed763 imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents: 9076
diff changeset
474 }
e560b92ed763 imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents: 9076
diff changeset
475 if (mail_namespaces_init(mail_user, error_r) < 0) {
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
476 mail_user_unref(&mail_user);
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
477 return -1;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
478 }
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
479 *mail_user_r = mail_user;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
480 return 0;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
481 }
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
482
9063
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
483 static const struct var_expand_table *
9147
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9118
diff changeset
484 get_var_expand_table(struct master_service *service,
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9118
diff changeset
485 struct mail_storage_service_input *input)
9063
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
486 {
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
487 static struct var_expand_table static_tab[] = {
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
488 { 'u', NULL, "user" },
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
489 { 'n', NULL, "username" },
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
490 { 'd', NULL, "domain" },
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
491 { 's', NULL, "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: 9118
diff changeset
492 { 'l', NULL, "lip" },
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9118
diff changeset
493 { 'r', NULL, "rip" },
9063
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
494 { 'p', NULL, "pid" },
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
495 { 'i', NULL, "uid" },
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
496 { '\0', NULL, NULL }
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
497 };
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
498 struct var_expand_table *tab;
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
499
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
500 tab = t_malloc(sizeof(static_tab));
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
501 memcpy(tab, static_tab, sizeof(static_tab));
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
502
9147
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9118
diff changeset
503 tab[0].value = input->username;
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9118
diff changeset
504 tab[1].value = t_strcut(input->username, '@');
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9118
diff changeset
505 tab[2].value = strchr(input->username, '@');
9063
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
506 if (tab[2].value != NULL) tab[2].value++;
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
507 tab[3].value = service->name;
9147
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9118
diff changeset
508 tab[4].value = net_ip2addr(&input->local_ip);
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9118
diff changeset
509 tab[5].value = net_ip2addr(&input->remote_ip);
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9118
diff changeset
510 tab[6].value = my_pid;
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9118
diff changeset
511 tab[7].value = dec2str(geteuid());
9063
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
512 return tab;
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
513 }
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
514
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
515 static const char *
9147
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9118
diff changeset
516 user_expand_varstr(struct master_service *service,
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9118
diff changeset
517 struct mail_storage_service_input *input, const char *str)
9063
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
518 {
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
519 string_t *ret;
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
520
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
521 if (*str == SETTING_STRVAR_EXPANDED[0])
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
522 return str + 1;
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
523
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
524 i_assert(*str == SETTING_STRVAR_UNEXPANDED[0]);
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
525
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
526 ret = t_str_new(256);
9147
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9118
diff changeset
527 var_expand(ret, str + 1, get_var_expand_table(service, input));
9063
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
528 return str_c(ret);
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
529 }
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
530
9147
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9118
diff changeset
531 static void
11750
b0e0d4537496 mail-storage-service: Initialize logging with proper settings a bit earlier.
Timo Sirainen <tss@iki.fi>
parents: 11749
diff changeset
532 mail_storage_service_init_log(struct mail_storage_service_ctx *ctx,
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
533 struct mail_storage_service_user *user)
9147
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9118
diff changeset
534 {
11750
b0e0d4537496 mail-storage-service: Initialize logging with proper settings a bit earlier.
Timo Sirainen <tss@iki.fi>
parents: 11749
diff changeset
535 ctx->log_initialized = TRUE;
9147
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9118
diff changeset
536 T_BEGIN {
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9118
diff changeset
537 string_t *str;
12498
1d1cd60d5429 mail storage service: Use ioloop log prefix automation.
Timo Sirainen <tss@iki.fi>
parents: 12431
diff changeset
538 struct ioloop_log *log;
9147
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9118
diff changeset
539
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9118
diff changeset
540 str = t_str_new(256);
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
541 var_expand(str, user->user_set->mail_log_prefix,
11750
b0e0d4537496 mail-storage-service: Initialize logging with proper settings a bit earlier.
Timo Sirainen <tss@iki.fi>
parents: 11749
diff changeset
542 get_var_expand_table(ctx->service, &user->input));
b0e0d4537496 mail-storage-service: Initialize logging with proper settings a bit earlier.
Timo Sirainen <tss@iki.fi>
parents: 11749
diff changeset
543 master_service_init_log(ctx->service, str_c(str));
12498
1d1cd60d5429 mail storage service: Use ioloop log prefix automation.
Timo Sirainen <tss@iki.fi>
parents: 12431
diff changeset
544
1d1cd60d5429 mail storage service: Use ioloop log prefix automation.
Timo Sirainen <tss@iki.fi>
parents: 12431
diff changeset
545 log = io_loop_log_new(current_ioloop);
1d1cd60d5429 mail storage service: Use ioloop log prefix automation.
Timo Sirainen <tss@iki.fi>
parents: 12431
diff changeset
546 io_loop_log_set_prefix(log, str_c(str));
1d1cd60d5429 mail storage service: Use ioloop log prefix automation.
Timo Sirainen <tss@iki.fi>
parents: 12431
diff changeset
547 io_loop_log_unref(&log);
9147
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9118
diff changeset
548 } T_END;
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9118
diff changeset
549 }
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9118
diff changeset
550
9495
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
551 static void mail_storage_service_time_moved(time_t old_time, time_t new_time)
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
552 {
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
553 long diff = new_time - old_time;
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
554
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
555 if (diff > 0) {
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
556 if (diff > MAX_NOWARN_FORWARD_SECS)
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
557 i_warning("Time jumped forwards %ld seconds", diff);
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
558 return;
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
559 }
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
560 diff = -diff;
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
561
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
562 if (diff > MAX_TIME_BACKWARDS_SLEEP) {
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
563 i_fatal("Time just moved backwards by %ld seconds. "
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
564 "This might cause a lot of problems, "
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
565 "so I'll just kill myself now. "
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
566 "http://wiki.dovecot.org/TimeMovedBackwards", diff);
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
567 } else {
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
568 i_error("Time just moved backwards by %ld seconds. "
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
569 "I'll sleep now until we're back in present. "
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
570 "http://wiki.dovecot.org/TimeMovedBackwards", diff);
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
571 /* Sleep extra second to make sure usecs also grows. */
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
572 diff++;
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
573
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
574 while (diff > 0 && sleep(diff) != 0) {
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
575 /* don't use sleep()'s return value, because
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
576 it could get us to a long loop in case
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
577 interrupts just keep coming */
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
578 diff = old_time - time(NULL) + 1;
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
579 }
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
580 }
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
581 }
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
582
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
583 struct mail_storage_service_ctx *
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
584 mail_storage_service_init(struct master_service *service,
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
585 const struct setting_parser_info *set_roots[],
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
586 enum mail_storage_service_flags flags)
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
587 {
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
588 struct mail_storage_service_ctx *ctx;
10793
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
589 pool_t pool;
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
590 unsigned int count;
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
591
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
592 (void)umask(0077);
9495
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
593 io_loop_set_time_moved_callback(current_ioloop,
b9f5982e68ee Mail storage service processes now sleep/die if time moves backwards.
Timo Sirainen <tss@iki.fi>
parents: 9447
diff changeset
594 mail_storage_service_time_moved);
9176
cf026a9180f1 mail-storage-service: Callmaster_service_init_finish().
Timo Sirainen <tss@iki.fi>
parents: 9159
diff changeset
595
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
596 mail_storage_init();
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
597 mail_storage_register_all();
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
598 mailbox_list_register_all();
10121
cb2882c142e1 Don't allow relative home directory paths.
Timo Sirainen <tss@iki.fi>
parents: 10101
diff changeset
599
10793
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
600 pool = pool_alloconly_create("mail storage service", 2048);
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
601 ctx = p_new(pool, struct mail_storage_service_ctx, 1);
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
602 ctx->pool = pool;
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
603 ctx->service = service;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
604 ctx->flags = flags;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
605
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
606 /* @UNSAFE */
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
607 if (set_roots == NULL)
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
608 count = 0;
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
609 else
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
610 for (count = 0; set_roots[count] != NULL; count++) ;
10814
dfca32cdab43 Memory leak fixes.
Timo Sirainen <tss@iki.fi>
parents: 10801
diff changeset
611 ctx->set_roots =
dfca32cdab43 Memory leak fixes.
Timo Sirainen <tss@iki.fi>
parents: 10801
diff changeset
612 p_new(pool, const struct setting_parser_info *, count + 2);
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
613 ctx->set_roots[0] = &mail_user_setting_parser_info;
11076
fa08ed2b7560 Small code changes to make static analyzer happier.
Timo Sirainen <tss@iki.fi>
parents: 11057
diff changeset
614 if (set_roots != NULL) {
fa08ed2b7560 Small code changes to make static analyzer happier.
Timo Sirainen <tss@iki.fi>
parents: 11057
diff changeset
615 memcpy(ctx->set_roots + 1, set_roots,
fa08ed2b7560 Small code changes to make static analyzer happier.
Timo Sirainen <tss@iki.fi>
parents: 11057
diff changeset
616 sizeof(*ctx->set_roots) * count);
fa08ed2b7560 Small code changes to make static analyzer happier.
Timo Sirainen <tss@iki.fi>
parents: 11057
diff changeset
617 }
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
618
9159
6324a79d3ee1 Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents: 9147
diff changeset
619 /* do all the global initialization. delay initializing plugins until
6324a79d3ee1 Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents: 9147
diff changeset
620 we drop privileges the first time. */
10498
569206178c09 mail storage service: Some flag enums were missing FLAG_ in the middle.
Timo Sirainen <tss@iki.fi>
parents: 10497
diff changeset
621 if ((flags & MAIL_STORAGE_SERVICE_FLAG_NO_LOG_INIT) == 0) {
11750
b0e0d4537496 mail-storage-service: Initialize logging with proper settings a bit earlier.
Timo Sirainen <tss@iki.fi>
parents: 11749
diff changeset
622 /* note: we may not have read any settings yet, so this logging
b0e0d4537496 mail-storage-service: Initialize logging with proper settings a bit earlier.
Timo Sirainen <tss@iki.fi>
parents: 11749
diff changeset
623 may still be going to wrong location */
12498
1d1cd60d5429 mail storage service: Use ioloop log prefix automation.
Timo Sirainen <tss@iki.fi>
parents: 12431
diff changeset
624 const char *log_prefix = t_strconcat(service->name, ": ", NULL);
1d1cd60d5429 mail storage service: Use ioloop log prefix automation.
Timo Sirainen <tss@iki.fi>
parents: 12431
diff changeset
625
1d1cd60d5429 mail storage service: Use ioloop log prefix automation.
Timo Sirainen <tss@iki.fi>
parents: 12431
diff changeset
626 master_service_init_log(service, log_prefix);
1d1cd60d5429 mail storage service: Use ioloop log prefix automation.
Timo Sirainen <tss@iki.fi>
parents: 12431
diff changeset
627 io_loop_set_default_log_prefix(current_ioloop, log_prefix);
10263
18f5fdeed659 mail storage service: Added MAIL_STORAGE_SERVICE_NO_LOG_INIT flag.
Timo Sirainen <tss@iki.fi>
parents: 10252
diff changeset
628 }
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
629 dict_drivers_register_builtin();
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
630 return ctx;
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
631 }
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
632
9830
0919ab922086 Added auth_master_pass_lookup() and changed auth_master_used_lookup() API.
Timo Sirainen <tss@iki.fi>
parents: 9523
diff changeset
633 struct auth_master_connection *
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
634 mail_storage_service_get_auth_conn(struct mail_storage_service_ctx *ctx)
9830
0919ab922086 Added auth_master_pass_lookup() and changed auth_master_used_lookup() API.
Timo Sirainen <tss@iki.fi>
parents: 9523
diff changeset
635 {
10273
4109e7f29735 Added mail_storage_service_init_settings().
Timo Sirainen <tss@iki.fi>
parents: 10263
diff changeset
636 i_assert(ctx->conn != NULL);
9830
0919ab922086 Added auth_master_pass_lookup() and changed auth_master_used_lookup() API.
Timo Sirainen <tss@iki.fi>
parents: 9523
diff changeset
637 return ctx->conn;
0919ab922086 Added auth_master_pass_lookup() and changed auth_master_used_lookup() API.
Timo Sirainen <tss@iki.fi>
parents: 9523
diff changeset
638 }
0919ab922086 Added auth_master_pass_lookup() and changed auth_master_used_lookup() API.
Timo Sirainen <tss@iki.fi>
parents: 9523
diff changeset
639
10134
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
640 int mail_storage_service_read_settings(struct mail_storage_service_ctx *ctx,
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
641 const struct mail_storage_service_input *input,
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
642 pool_t pool,
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
643 const struct setting_parser_info **user_info_r,
10793
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
644 const struct setting_parser_context **parser_r,
10134
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
645 const char **error_r)
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 10098
diff changeset
646 {
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
647 struct master_service_settings_input set_input;
11078
46d4f3264417 Fixed memory leak when parsing settings.
Timo Sirainen <tss@iki.fi>
parents: 11076
diff changeset
648 const struct setting_parser_info *const *roots;
10793
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
649 struct master_service_settings_output set_output;
11002
fdb352eecdac Dynamic settings parser allocation logic was wrong.
Timo Sirainen <tss@iki.fi>
parents: 10938
diff changeset
650 const struct dynamic_settings_parser *dyn_parsers;
10134
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
651 unsigned int i;
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 10098
diff changeset
652
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
653 memset(&set_input, 0, sizeof(set_input));
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
654 set_input.roots = ctx->set_roots;
12726
cec7fa92ff48 Added import_environment setting.
Timo Sirainen <tss@iki.fi>
parents: 12722
diff changeset
655 set_input.preserve_user = TRUE;
10134
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
656 /* settings reader may exec doveconf, which is going to clear
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
657 environment, and if we're not doing a userdb lookup we want to
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
658 use $HOME */
12302
27289650ed4c lib-storage: Added no_userdb_lookup flag to storage service lookups.
Timo Sirainen <tss@iki.fi>
parents: 12197
diff changeset
659 set_input.preserve_home =
10134
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
660 (ctx->flags & MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP) == 0;
12197
002a702cf06a lda: If doveconf fails, make it exit with EX_TEMPFAIL.
Timo Sirainen <tss@iki.fi>
parents: 12042
diff changeset
661 set_input.use_sysexits =
002a702cf06a lda: If doveconf fails, make it exit with EX_TEMPFAIL.
Timo Sirainen <tss@iki.fi>
parents: 12042
diff changeset
662 (ctx->flags & MAIL_STORAGE_SERVICE_FLAG_USE_SYSEXITS) != 0;
10134
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
663
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
664 if (input != NULL) {
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
665 set_input.module = input->module;
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
666 set_input.service = input->service;
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
667 set_input.username = input->username;
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
668 set_input.local_ip = input->local_ip;
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
669 set_input.remote_ip = input->remote_ip;
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
670 }
10793
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
671 if (ctx->set_cache == NULL) {
10856
8f8d2f8e029c mail storage service: Fixed crashing when iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 10814
diff changeset
672 ctx->set_cache_module = p_strdup(ctx->pool, set_input.module);
8f8d2f8e029c mail storage service: Fixed crashing when iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 10814
diff changeset
673 ctx->set_cache_service = p_strdup(ctx->pool, set_input.service);
10793
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
674 ctx->set_cache = master_service_settings_cache_init(
10856
8f8d2f8e029c mail storage service: Fixed crashing when iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 10814
diff changeset
675 ctx->service, set_input.module, set_input.service);
10938
7fa0cd9e3a89 mail_storage_service_read_settings() avoided execing doveconf too aggressively.
Timo Sirainen <tss@iki.fi>
parents: 10932
diff changeset
676 } else {
7fa0cd9e3a89 mail_storage_service_read_settings() avoided execing doveconf too aggressively.
Timo Sirainen <tss@iki.fi>
parents: 10932
diff changeset
677 /* already looked up settings at least once.
7fa0cd9e3a89 mail_storage_service_read_settings() avoided execing doveconf too aggressively.
Timo Sirainen <tss@iki.fi>
parents: 10932
diff changeset
678 we really shouldn't be execing anymore. */
7fa0cd9e3a89 mail_storage_service_read_settings() avoided execing doveconf too aggressively.
Timo Sirainen <tss@iki.fi>
parents: 10932
diff changeset
679 set_input.never_exec = TRUE;
10793
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
680 }
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
681
11002
fdb352eecdac Dynamic settings parser allocation logic was wrong.
Timo Sirainen <tss@iki.fi>
parents: 10938
diff changeset
682 dyn_parsers = mail_storage_get_dynamic_parsers(pool);
10856
8f8d2f8e029c mail storage service: Fixed crashing when iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 10814
diff changeset
683 if (null_strcmp(set_input.module, ctx->set_cache_module) == 0 &&
8f8d2f8e029c mail storage service: Fixed crashing when iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 10814
diff changeset
684 null_strcmp(set_input.service, ctx->set_cache_service) == 0) {
10793
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
685 if (master_service_settings_cache_read(ctx->set_cache,
11078
46d4f3264417 Fixed memory leak when parsing settings.
Timo Sirainen <tss@iki.fi>
parents: 11076
diff changeset
686 &set_input, dyn_parsers,
11018
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
687 parser_r, error_r) < 0) {
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
688 *error_r = t_strdup_printf(
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
689 "Error reading configuration: %s", *error_r);
10793
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
690 return -1;
11018
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
691 }
10793
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
692 } else {
11078
46d4f3264417 Fixed memory leak when parsing settings.
Timo Sirainen <tss@iki.fi>
parents: 11076
diff changeset
693 settings_parser_dyn_update(pool, &set_input.roots, dyn_parsers);
10793
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
694 if (master_service_settings_read(ctx->service, &set_input,
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
695 &set_output, error_r) < 0) {
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
696 *error_r = t_strdup_printf(
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
697 "Error reading configuration: %s", *error_r);
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
698 return -1;
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
699 }
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
700 *parser_r = ctx->service->set_parser;
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
701 }
10134
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
702
11078
46d4f3264417 Fixed memory leak when parsing settings.
Timo Sirainen <tss@iki.fi>
parents: 11076
diff changeset
703 roots = settings_parser_get_roots(*parser_r);
46d4f3264417 Fixed memory leak when parsing settings.
Timo Sirainen <tss@iki.fi>
parents: 11076
diff changeset
704 for (i = 0; roots[i] != NULL; i++) {
46d4f3264417 Fixed memory leak when parsing settings.
Timo Sirainen <tss@iki.fi>
parents: 11076
diff changeset
705 if (strcmp(roots[i]->module_name,
10793
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
706 mail_user_setting_parser_info.module_name) == 0) {
11078
46d4f3264417 Fixed memory leak when parsing settings.
Timo Sirainen <tss@iki.fi>
parents: 11076
diff changeset
707 *user_info_r = roots[i];
10134
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
708 return 0;
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
709 }
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
710 }
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
711 i_unreached();
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
712 return -1;
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
713 }
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 10098
diff changeset
714
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
715 static void
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
716 mail_storage_service_first_init(struct mail_storage_service_ctx *ctx,
10134
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
717 const struct setting_parser_info *user_info,
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
718 const struct mail_user_settings *user_set)
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
719 {
10497
3907cc4ecc4b Idle-disconnecting auth master connections is now optional. LMTP no longer does it.
Timo Sirainen <tss@iki.fi>
parents: 10468
diff changeset
720 enum auth_master_flags flags = 0;
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
721
10273
4109e7f29735 Added mail_storage_service_init_settings().
Timo Sirainen <tss@iki.fi>
parents: 10263
diff changeset
722 i_assert(ctx->conn == NULL);
4109e7f29735 Added mail_storage_service_init_settings().
Timo Sirainen <tss@iki.fi>
parents: 10263
diff changeset
723
10880
2d082200657d mail storage service: mail_debug=yes now logs what happens to userdb settings.
Timo Sirainen <tss@iki.fi>
parents: 10879
diff changeset
724 ctx->debug = mail_user_set_get_mail_debug(user_info, user_set);
10497
3907cc4ecc4b Idle-disconnecting auth master connections is now optional. LMTP no longer does it.
Timo Sirainen <tss@iki.fi>
parents: 10468
diff changeset
725 if (ctx->debug)
3907cc4ecc4b Idle-disconnecting auth master connections is now optional. LMTP no longer does it.
Timo Sirainen <tss@iki.fi>
parents: 10468
diff changeset
726 flags |= AUTH_MASTER_FLAG_DEBUG;
3907cc4ecc4b Idle-disconnecting auth master connections is now optional. LMTP no longer does it.
Timo Sirainen <tss@iki.fi>
parents: 10468
diff changeset
727 if ((ctx->flags & MAIL_STORAGE_SERVICE_FLAG_NO_IDLE_TIMEOUT) != 0)
3907cc4ecc4b Idle-disconnecting auth master connections is now optional. LMTP no longer does it.
Timo Sirainen <tss@iki.fi>
parents: 10468
diff changeset
728 flags |= AUTH_MASTER_FLAG_NO_IDLE_TIMEOUT;
3907cc4ecc4b Idle-disconnecting auth master connections is now optional. LMTP no longer does it.
Timo Sirainen <tss@iki.fi>
parents: 10468
diff changeset
729 ctx->conn = auth_master_init(user_set->auth_socket_path, flags);
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
730
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
731 i_assert(mail_user_auth_master_conn == NULL);
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
732 mail_user_auth_master_conn = ctx->conn;
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 10098
diff changeset
733 }
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 10098
diff changeset
734
10418
932afc022ea1 lib-storage: Added support for per-user plugins.
Timo Sirainen <tss@iki.fi>
parents: 10403
diff changeset
735 static void
932afc022ea1 lib-storage: Added support for per-user plugins.
Timo Sirainen <tss@iki.fi>
parents: 10403
diff changeset
736 mail_storage_service_load_modules(struct mail_storage_service_ctx *ctx,
10422
55c42d2f7002 module_dir_load*() API changed to take settings struct, with debug field.
Timo Sirainen <tss@iki.fi>
parents: 10418
diff changeset
737 const struct setting_parser_info *user_info,
10418
932afc022ea1 lib-storage: Added support for per-user plugins.
Timo Sirainen <tss@iki.fi>
parents: 10403
diff changeset
738 const struct mail_user_settings *user_set)
932afc022ea1 lib-storage: Added support for per-user plugins.
Timo Sirainen <tss@iki.fi>
parents: 10403
diff changeset
739 {
10422
55c42d2f7002 module_dir_load*() API changed to take settings struct, with debug field.
Timo Sirainen <tss@iki.fi>
parents: 10418
diff changeset
740 struct module_dir_load_settings mod_set;
10418
932afc022ea1 lib-storage: Added support for per-user plugins.
Timo Sirainen <tss@iki.fi>
parents: 10403
diff changeset
741
932afc022ea1 lib-storage: Added support for per-user plugins.
Timo Sirainen <tss@iki.fi>
parents: 10403
diff changeset
742 if (*user_set->mail_plugins == '\0')
932afc022ea1 lib-storage: Added support for per-user plugins.
Timo Sirainen <tss@iki.fi>
parents: 10403
diff changeset
743 return;
10498
569206178c09 mail storage service: Some flag enums were missing FLAG_ in the middle.
Timo Sirainen <tss@iki.fi>
parents: 10497
diff changeset
744 if ((ctx->flags & MAIL_STORAGE_SERVICE_FLAG_NO_PLUGINS) != 0)
10461
21c0676961e8 Mail storage service: Added MAIL_STORAGE_SERVICE_NO_PLUGINS flag.
Timo Sirainen <tss@iki.fi>
parents: 10422
diff changeset
745 return;
10418
932afc022ea1 lib-storage: Added support for per-user plugins.
Timo Sirainen <tss@iki.fi>
parents: 10403
diff changeset
746
10422
55c42d2f7002 module_dir_load*() API changed to take settings struct, with debug field.
Timo Sirainen <tss@iki.fi>
parents: 10418
diff changeset
747 memset(&mod_set, 0, sizeof(mod_set));
55c42d2f7002 module_dir_load*() API changed to take settings struct, with debug field.
Timo Sirainen <tss@iki.fi>
parents: 10418
diff changeset
748 mod_set.version = master_service_get_version_string(ctx->service);
11749
c53fb625b07e imap plugins now give a nicer error if tried to be loaded for non-imap binary.
Timo Sirainen <tss@iki.fi>
parents: 11136
diff changeset
749 mod_set.binary_name = master_service_get_name(ctx->service);
11906
02c9154efe81 If module can't be loaded due to missing dependency, suggest a setting how to do it.
Timo Sirainen <tss@iki.fi>
parents: 11762
diff changeset
750 mod_set.setting_name = "mail_plugins";
10422
55c42d2f7002 module_dir_load*() API changed to take settings struct, with debug field.
Timo Sirainen <tss@iki.fi>
parents: 10418
diff changeset
751 mod_set.require_init_funcs = TRUE;
10880
2d082200657d mail storage service: mail_debug=yes now logs what happens to userdb settings.
Timo Sirainen <tss@iki.fi>
parents: 10879
diff changeset
752 mod_set.debug = mail_user_set_get_mail_debug(user_info, user_set);
10422
55c42d2f7002 module_dir_load*() API changed to take settings struct, with debug field.
Timo Sirainen <tss@iki.fi>
parents: 10418
diff changeset
753
10857
02d4cc578d4b mail storage service: Exported modules as mail_storage_service_modules.
Timo Sirainen <tss@iki.fi>
parents: 10856
diff changeset
754 mail_storage_service_modules =
02d4cc578d4b mail storage service: Exported modules as mail_storage_service_modules.
Timo Sirainen <tss@iki.fi>
parents: 10856
diff changeset
755 module_dir_load_missing(mail_storage_service_modules,
02d4cc578d4b mail storage service: Exported modules as mail_storage_service_modules.
Timo Sirainen <tss@iki.fi>
parents: 10856
diff changeset
756 user_set->mail_plugin_dir,
02d4cc578d4b mail storage service: Exported modules as mail_storage_service_modules.
Timo Sirainen <tss@iki.fi>
parents: 10856
diff changeset
757 user_set->mail_plugins, &mod_set);
10418
932afc022ea1 lib-storage: Added support for per-user plugins.
Timo Sirainen <tss@iki.fi>
parents: 10403
diff changeset
758 }
932afc022ea1 lib-storage: Added support for per-user plugins.
Timo Sirainen <tss@iki.fi>
parents: 10403
diff changeset
759
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
760 int mail_storage_service_lookup(struct mail_storage_service_ctx *ctx,
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
761 const struct mail_storage_service_input *input,
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
762 struct mail_storage_service_user **user_r,
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
763 const char **error_r)
9108
14ebbf71ef3e mail_storage_service_multi*() API change and fixes.
Timo Sirainen <tss@iki.fi>
parents: 9106
diff changeset
764 {
12302
27289650ed4c lib-storage: Added no_userdb_lookup flag to storage service lookups.
Timo Sirainen <tss@iki.fi>
parents: 12197
diff changeset
765 const bool userdb_lookup = !input->no_userdb_lookup &&
27289650ed4c lib-storage: Added no_userdb_lookup flag to storage service lookups.
Timo Sirainen <tss@iki.fi>
parents: 12197
diff changeset
766 (ctx->flags & MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP) != 0;
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
767 struct mail_storage_service_user *user;
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
768 const char *username = input->username;
10134
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
769 const struct setting_parser_info *user_info;
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
770 const struct mail_user_settings *user_set;
11018
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
771 const char *const *userdb_fields, *error;
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
772 struct auth_user_reply reply;
10793
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
773 const struct setting_parser_context *set_parser;
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
774 pool_t user_pool, temp_pool;
10101
4fe8c4382712 Redesigned how login process passes connections to mail processes and changed related APIs.
Timo Sirainen <tss@iki.fi>
parents: 10098
diff changeset
775 int ret = 1;
9108
14ebbf71ef3e mail_storage_service_multi*() API change and fixes.
Timo Sirainen <tss@iki.fi>
parents: 9106
diff changeset
776
10684
e202b2b86702 Increased initial memory pool sizes.
Timo Sirainen <tss@iki.fi>
parents: 10582
diff changeset
777 user_pool = pool_alloconly_create("mail storage service user", 1024*5);
10134
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
778
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
779 if (mail_storage_service_read_settings(ctx, input, user_pool,
10793
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
780 &user_info, &set_parser,
11018
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
781 &error) < 0) {
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
782 i_error("user %s: %s", username, error);
10134
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
783 pool_unref(&user_pool);
11018
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
784 *error_r = MAIL_ERRSTR_CRITICAL_MSG;
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
785 return -1;
10134
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
786 }
11750
b0e0d4537496 mail-storage-service: Initialize logging with proper settings a bit earlier.
Timo Sirainen <tss@iki.fi>
parents: 11749
diff changeset
787 if ((ctx->flags & MAIL_STORAGE_SERVICE_FLAG_NO_LOG_INIT) == 0 &&
b0e0d4537496 mail-storage-service: Initialize logging with proper settings a bit earlier.
Timo Sirainen <tss@iki.fi>
parents: 11749
diff changeset
788 !ctx->log_initialized) {
b0e0d4537496 mail-storage-service: Initialize logging with proper settings a bit earlier.
Timo Sirainen <tss@iki.fi>
parents: 11749
diff changeset
789 /* initialize logging again, in case we only read the
b0e0d4537496 mail-storage-service: Initialize logging with proper settings a bit earlier.
Timo Sirainen <tss@iki.fi>
parents: 11749
diff changeset
790 settings for the first above */
b0e0d4537496 mail-storage-service: Initialize logging with proper settings a bit earlier.
Timo Sirainen <tss@iki.fi>
parents: 11749
diff changeset
791 ctx->log_initialized = TRUE;
b0e0d4537496 mail-storage-service: Initialize logging with proper settings a bit earlier.
Timo Sirainen <tss@iki.fi>
parents: 11749
diff changeset
792 master_service_init_log(ctx->service,
b0e0d4537496 mail-storage-service: Initialize logging with proper settings a bit earlier.
Timo Sirainen <tss@iki.fi>
parents: 11749
diff changeset
793 t_strconcat(ctx->service->name, ": ", NULL));
b0e0d4537496 mail-storage-service: Initialize logging with proper settings a bit earlier.
Timo Sirainen <tss@iki.fi>
parents: 11749
diff changeset
794 }
10793
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
795 user_set = settings_parser_get_list(set_parser)[1];
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
796
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
797 if (ctx->conn == NULL)
10134
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
798 mail_storage_service_first_init(ctx, user_info, user_set);
10418
932afc022ea1 lib-storage: Added support for per-user plugins.
Timo Sirainen <tss@iki.fi>
parents: 10403
diff changeset
799 /* load global plugins */
10422
55c42d2f7002 module_dir_load*() API changed to take settings struct, with debug field.
Timo Sirainen <tss@iki.fi>
parents: 10418
diff changeset
800 mail_storage_service_load_modules(ctx, user_info, user_set);
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
801
11762
065ff4f1c504 Increased some initial mempool sizes.
Timo Sirainen <tss@iki.fi>
parents: 11750
diff changeset
802 temp_pool = pool_alloconly_create("userdb lookup", 2048);
12302
27289650ed4c lib-storage: Added no_userdb_lookup flag to storage service lookups.
Timo Sirainen <tss@iki.fi>
parents: 12197
diff changeset
803 if (userdb_lookup) {
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
804 ret = service_auth_userdb_lookup(ctx, input, temp_pool,
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
805 &username, &userdb_fields,
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
806 error_r);
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
807 if (ret <= 0) {
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
808 pool_unref(&temp_pool);
10134
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
809 pool_unref(&user_pool);
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
810 return ret;
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
811 }
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
812 } else {
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
813 userdb_fields = input->userdb_fields;
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
814 }
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
815
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
816 user = p_new(user_pool, struct mail_storage_service_user, 1);
9108
14ebbf71ef3e mail_storage_service_multi*() API change and fixes.
Timo Sirainen <tss@iki.fi>
parents: 9106
diff changeset
817 memset(user_r, 0, sizeof(user_r));
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
818 user->pool = user_pool;
9147
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9118
diff changeset
819 user->input = *input;
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
820 user->input.userdb_fields = NULL;
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
821 user->input.username = p_strdup(user_pool, username);
10134
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
822 user->user_info = user_info;
9108
14ebbf71ef3e mail_storage_service_multi*() API change and fixes.
Timo Sirainen <tss@iki.fi>
parents: 9106
diff changeset
823
10793
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
824 user->set_parser = settings_parser_dup(set_parser, user_pool);
11018
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
825 if (!settings_parser_check(user->set_parser, user_pool, &error))
11136
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
826 i_panic("settings_parser_check() failed: %s", error);
10506
2f554f19adb5 mail storage service: When duping settings, they need to be also checked.
Timo Sirainen <tss@iki.fi>
parents: 10498
diff changeset
827
10793
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
828 user->user_set = settings_parser_get_list(user->set_parser)[1];
12722
888999441619 lib-storage: Give restrict_access() uid/gid source (userdb or mail_u/gid setting).
Timo Sirainen <tss@iki.fi>
parents: 12705
diff changeset
829 user->gid_source = "mail_gid setting";
888999441619 lib-storage: Give restrict_access() uid/gid source (userdb or mail_u/gid setting).
Timo Sirainen <tss@iki.fi>
parents: 12705
diff changeset
830 user->uid_source = "mail_uid setting";
9108
14ebbf71ef3e mail_storage_service_multi*() API change and fixes.
Timo Sirainen <tss@iki.fi>
parents: 9106
diff changeset
831
12772
e26af53b6b40 lib-storage: MAIL_STORAGE_SERVICE_FLAG_DEBUG didn't do anything.
Timo Sirainen <tss@iki.fi>
parents: 12726
diff changeset
832 if ((ctx->flags & MAIL_STORAGE_SERVICE_FLAG_DEBUG) != 0)
e26af53b6b40 lib-storage: MAIL_STORAGE_SERVICE_FLAG_DEBUG didn't do anything.
Timo Sirainen <tss@iki.fi>
parents: 12726
diff changeset
833 (void)settings_parse_line(user->set_parser, "mail_debug=yes");
e26af53b6b40 lib-storage: MAIL_STORAGE_SERVICE_FLAG_DEBUG didn't do anything.
Timo Sirainen <tss@iki.fi>
parents: 12726
diff changeset
834
12302
27289650ed4c lib-storage: Added no_userdb_lookup flag to storage service lookups.
Timo Sirainen <tss@iki.fi>
parents: 12197
diff changeset
835 if (!userdb_lookup) {
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
836 const char *home = getenv("HOME");
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
837 if (home != NULL)
11057
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
838 set_keyval(ctx, user, "mail_home", home);
9108
14ebbf71ef3e mail_storage_service_multi*() API change and fixes.
Timo Sirainen <tss@iki.fi>
parents: 9106
diff changeset
839 }
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
840
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
841 if (userdb_fields != NULL) {
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
842 auth_user_fields_parse(userdb_fields, temp_pool, &reply);
11057
f9e6078ca95c mail storage service: -o parameter now overrides userdb settings too.
Timo Sirainen <tss@iki.fi>
parents: 11039
diff changeset
843 if (user_reply_handle(ctx, user, &reply, &error) < 0) {
11018
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
844 i_error("user %s: Invalid settings in userdb: %s",
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
845 username, error);
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
846 *error_r = ERRSTR_INVALID_USER_SETTINGS;
10930
15860795f158 mail_storage_service_lookup*() now separates userdb lookup and user setting errors.
Timo Sirainen <tss@iki.fi>
parents: 10929
diff changeset
847 ret = -2;
11018
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
848 }
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
849 }
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
850 pool_unref(&temp_pool);
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
851
10418
932afc022ea1 lib-storage: Added support for per-user plugins.
Timo Sirainen <tss@iki.fi>
parents: 10403
diff changeset
852 /* load per-user plugins */
10930
15860795f158 mail_storage_service_lookup*() now separates userdb lookup and user setting errors.
Timo Sirainen <tss@iki.fi>
parents: 10929
diff changeset
853 if (ret > 0) {
15860795f158 mail_storage_service_lookup*() now separates userdb lookup and user setting errors.
Timo Sirainen <tss@iki.fi>
parents: 10929
diff changeset
854 mail_storage_service_load_modules(ctx, user_info,
15860795f158 mail_storage_service_lookup*() now separates userdb lookup and user setting errors.
Timo Sirainen <tss@iki.fi>
parents: 10929
diff changeset
855 user->user_set);
15860795f158 mail_storage_service_lookup*() now separates userdb lookup and user setting errors.
Timo Sirainen <tss@iki.fi>
parents: 10929
diff changeset
856 }
10418
932afc022ea1 lib-storage: Added support for per-user plugins.
Timo Sirainen <tss@iki.fi>
parents: 10403
diff changeset
857
9108
14ebbf71ef3e mail_storage_service_multi*() API change and fixes.
Timo Sirainen <tss@iki.fi>
parents: 9106
diff changeset
858 *user_r = user;
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
859 return ret;
9108
14ebbf71ef3e mail_storage_service_multi*() API change and fixes.
Timo Sirainen <tss@iki.fi>
parents: 9106
diff changeset
860 }
14ebbf71ef3e mail_storage_service_multi*() API change and fixes.
Timo Sirainen <tss@iki.fi>
parents: 9106
diff changeset
861
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
862 int mail_storage_service_next(struct mail_storage_service_ctx *ctx,
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
863 struct mail_storage_service_user *user,
11018
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
864 struct mail_user **mail_user_r)
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
865 {
9108
14ebbf71ef3e mail_storage_service_multi*() API change and fixes.
Timo Sirainen <tss@iki.fi>
parents: 9106
diff changeset
866 const struct mail_user_settings *user_set = user->user_set;
10929
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
867 const char *home, *chroot, *error;
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
868 unsigned int len;
10929
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
869 bool disallow_root =
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
870 (ctx->flags & MAIL_STORAGE_SERVICE_FLAG_DISALLOW_ROOT) != 0;
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
871 bool temp_priv_drop =
10929
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
872 (ctx->flags & MAIL_STORAGE_SERVICE_FLAG_TEMP_PRIV_DROP) != 0;
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
873
9063
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
874 /* variable strings are expanded in mail_user_init(),
10123
f6257036f7ef mail_chroot can now contain %variables.
Timo Sirainen <tss@iki.fi>
parents: 10121
diff changeset
875 but we need the home and chroot sooner so do them separately here. */
9147
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9118
diff changeset
876 home = user_expand_varstr(ctx->service, &user->input,
9108
14ebbf71ef3e mail_storage_service_multi*() API change and fixes.
Timo Sirainen <tss@iki.fi>
parents: 9106
diff changeset
877 user_set->mail_home);
10123
f6257036f7ef mail_chroot can now contain %variables.
Timo Sirainen <tss@iki.fi>
parents: 10121
diff changeset
878 chroot = user_expand_varstr(ctx->service, &user->input,
f6257036f7ef mail_chroot can now contain %variables.
Timo Sirainen <tss@iki.fi>
parents: 10121
diff changeset
879 user_set->mail_chroot);
9063
daa079a90b66 Fixed problems with getting home directory.
Timo Sirainen <tss@iki.fi>
parents: 9061
diff changeset
880
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
881 if (*home != '/' && *home != '\0') {
11018
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
882 i_error("user %s: "
10931
03b679cd8d1f mail_storage_service_next() didn't always set error string.
Timo Sirainen <tss@iki.fi>
parents: 10930
diff changeset
883 "Relative home directory paths not supported: %s",
03b679cd8d1f mail_storage_service_next() didn't always set error string.
Timo Sirainen <tss@iki.fi>
parents: 10930
diff changeset
884 user->input.username, home);
11018
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
885 return -2;
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
886 }
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
887
11136
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
888 len = strlen(chroot);
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
889 if (len > 2 && strcmp(chroot + len - 2, "/.") == 0 &&
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
890 strncmp(home, chroot, len - 2) == 0) {
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
891 /* mail_chroot = /chroot/. means that the home dir already
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
892 contains the chroot dir. remove it from home. */
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
893 if (!temp_priv_drop) {
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
894 home += len - 2;
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
895 if (*home == '\0')
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
896 home = "/";
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
897 chroot = t_strndup(chroot, len - 2);
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
898
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
899 set_keyval(ctx, user, "mail_home", home);
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
900 set_keyval(ctx, user, "mail_chroot", chroot);
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
901 }
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
902 } else if (len > 0 && temp_priv_drop) {
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
903 /* we're dropping privileges only temporarily, so we can't
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
904 chroot. fix home directory so we can access it. */
12705
0fc2d00f83df lib-storage: Fixed handling chroot/home for services that don't really chroot (lmtp).
Timo Sirainen <tss@iki.fi>
parents: 12498
diff changeset
905 if (*home == '\0' || strcmp(home, "/") == 0)
0fc2d00f83df lib-storage: Fixed handling chroot/home for services that don't really chroot (lmtp).
Timo Sirainen <tss@iki.fi>
parents: 12498
diff changeset
906 home = chroot;
0fc2d00f83df lib-storage: Fixed handling chroot/home for services that don't really chroot (lmtp).
Timo Sirainen <tss@iki.fi>
parents: 12498
diff changeset
907 else
0fc2d00f83df lib-storage: Fixed handling chroot/home for services that don't really chroot (lmtp).
Timo Sirainen <tss@iki.fi>
parents: 12498
diff changeset
908 home = t_strconcat(chroot, home, NULL);
0fc2d00f83df lib-storage: Fixed handling chroot/home for services that don't really chroot (lmtp).
Timo Sirainen <tss@iki.fi>
parents: 12498
diff changeset
909 chroot = "";
0fc2d00f83df lib-storage: Fixed handling chroot/home for services that don't really chroot (lmtp).
Timo Sirainen <tss@iki.fi>
parents: 12498
diff changeset
910 set_keyval(ctx, user, "mail_home", home);
11136
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
911 }
9d4a9abf3ec3 mail storage service: Fixed chroot handling.
Timo Sirainen <tss@iki.fi>
parents: 11086
diff changeset
912
10498
569206178c09 mail storage service: Some flag enums were missing FLAG_ in the middle.
Timo Sirainen <tss@iki.fi>
parents: 10497
diff changeset
913 if ((ctx->flags & MAIL_STORAGE_SERVICE_FLAG_NO_LOG_INIT) == 0)
11750
b0e0d4537496 mail-storage-service: Initialize logging with proper settings a bit earlier.
Timo Sirainen <tss@iki.fi>
parents: 11749
diff changeset
914 mail_storage_service_init_log(ctx, user);
9147
bf448752f6c4 Pass remote/local IPs to mail_users. Standalone mail programs now log with mail_log_prefix.
Timo Sirainen <tss@iki.fi>
parents: 9118
diff changeset
915
9080
e560b92ed763 imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents: 9076
diff changeset
916 if ((ctx->flags & MAIL_STORAGE_SERVICE_FLAG_NO_RESTRICT_ACCESS) == 0) {
12722
888999441619 lib-storage: Give restrict_access() uid/gid source (userdb or mail_u/gid setting).
Timo Sirainen <tss@iki.fi>
parents: 12705
diff changeset
917 if (service_drop_privileges(user, user_set, home, chroot,
888999441619 lib-storage: Give restrict_access() uid/gid source (userdb or mail_u/gid setting).
Timo Sirainen <tss@iki.fi>
parents: 12705
diff changeset
918 disallow_root, temp_priv_drop,
888999441619 lib-storage: Give restrict_access() uid/gid source (userdb or mail_u/gid setting).
Timo Sirainen <tss@iki.fi>
parents: 12705
diff changeset
919 FALSE, &error) < 0) {
11018
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
920 i_error("user %s: Couldn't drop privileges: %s",
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
921 user->input.username, error);
10929
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
922 return -1;
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
923 }
10363
dffe7da9ca2e mail-storage-service: Added MAIL_STORAGE_SERVICE_FLAG_ENABLE_CORE_DUMPS flag.
Timo Sirainen <tss@iki.fi>
parents: 10362
diff changeset
924 if (!temp_priv_drop ||
dffe7da9ca2e mail-storage-service: Added MAIL_STORAGE_SERVICE_FLAG_ENABLE_CORE_DUMPS flag.
Timo Sirainen <tss@iki.fi>
parents: 10362
diff changeset
925 (ctx->flags & MAIL_STORAGE_SERVICE_FLAG_ENABLE_CORE_DUMPS) != 0)
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
926 restrict_access_allow_coredumps(TRUE);
9080
e560b92ed763 imap and pop3 now use mail-storage-service API.
Timo Sirainen <tss@iki.fi>
parents: 9076
diff changeset
927 }
10418
932afc022ea1 lib-storage: Added support for per-user plugins.
Timo Sirainen <tss@iki.fi>
parents: 10403
diff changeset
928
932afc022ea1 lib-storage: Added support for per-user plugins.
Timo Sirainen <tss@iki.fi>
parents: 10403
diff changeset
929 /* privileges are dropped. initialize plugins that haven't been
932afc022ea1 lib-storage: Added support for per-user plugins.
Timo Sirainen <tss@iki.fi>
parents: 10403
diff changeset
930 initialized yet. */
10857
02d4cc578d4b mail storage service: Exported modules as mail_storage_service_modules.
Timo Sirainen <tss@iki.fi>
parents: 10856
diff changeset
931 module_dir_init(mail_storage_service_modules);
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
932
10134
545bdb7670d2 lib-storage: Changed APIs to fix reading settings for multiple users.
Timo Sirainen <tss@iki.fi>
parents: 10130
diff changeset
933 if (mail_storage_service_init_post(ctx, user, home,
11018
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
934 mail_user_r, &error) < 0) {
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
935 i_error("user %s: Initialization failed: %s",
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
936 user->input.username, error);
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
937 return -2;
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
938 }
9108
14ebbf71ef3e mail_storage_service_multi*() API change and fixes.
Timo Sirainen <tss@iki.fi>
parents: 9106
diff changeset
939 return 0;
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
940 }
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
941
10462
2a74d458339d Added mail_storage_service_restrict_setenv().
Timo Sirainen <tss@iki.fi>
parents: 10461
diff changeset
942 void mail_storage_service_restrict_setenv(struct mail_storage_service_ctx *ctx,
2a74d458339d Added mail_storage_service_restrict_setenv().
Timo Sirainen <tss@iki.fi>
parents: 10461
diff changeset
943 struct mail_storage_service_user *user)
2a74d458339d Added mail_storage_service_restrict_setenv().
Timo Sirainen <tss@iki.fi>
parents: 10461
diff changeset
944 {
2a74d458339d Added mail_storage_service_restrict_setenv().
Timo Sirainen <tss@iki.fi>
parents: 10461
diff changeset
945 const struct mail_user_settings *user_set = user->user_set;
10929
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
946 const char *home, *chroot, *error;
10462
2a74d458339d Added mail_storage_service_restrict_setenv().
Timo Sirainen <tss@iki.fi>
parents: 10461
diff changeset
947
2a74d458339d Added mail_storage_service_restrict_setenv().
Timo Sirainen <tss@iki.fi>
parents: 10461
diff changeset
948 home = user_expand_varstr(ctx->service, &user->input,
2a74d458339d Added mail_storage_service_restrict_setenv().
Timo Sirainen <tss@iki.fi>
parents: 10461
diff changeset
949 user_set->mail_home);
2a74d458339d Added mail_storage_service_restrict_setenv().
Timo Sirainen <tss@iki.fi>
parents: 10461
diff changeset
950 chroot = user_expand_varstr(ctx->service, &user->input,
2a74d458339d Added mail_storage_service_restrict_setenv().
Timo Sirainen <tss@iki.fi>
parents: 10461
diff changeset
951 user_set->mail_chroot);
2a74d458339d Added mail_storage_service_restrict_setenv().
Timo Sirainen <tss@iki.fi>
parents: 10461
diff changeset
952
12722
888999441619 lib-storage: Give restrict_access() uid/gid source (userdb or mail_u/gid setting).
Timo Sirainen <tss@iki.fi>
parents: 12705
diff changeset
953 if (service_drop_privileges(user, user_set, home, chroot,
888999441619 lib-storage: Give restrict_access() uid/gid source (userdb or mail_u/gid setting).
Timo Sirainen <tss@iki.fi>
parents: 12705
diff changeset
954 FALSE, FALSE, TRUE,
10929
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
955 &error) < 0)
a66d3650e3c3 mail_storage_service_next() now only returns -1 if user's privileges are invalid.
Timo Sirainen <tss@iki.fi>
parents: 10927
diff changeset
956 i_fatal("%s", error);
10462
2a74d458339d Added mail_storage_service_restrict_setenv().
Timo Sirainen <tss@iki.fi>
parents: 10461
diff changeset
957 }
2a74d458339d Added mail_storage_service_restrict_setenv().
Timo Sirainen <tss@iki.fi>
parents: 10461
diff changeset
958
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
959 int mail_storage_service_lookup_next(struct mail_storage_service_ctx *ctx,
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
960 const struct mail_storage_service_input *input,
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
961 struct mail_storage_service_user **user_r,
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
962 struct mail_user **mail_user_r,
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
963 const char **error_r)
9300
b66054f9b8fb Memory leak fixes.
Timo Sirainen <tss@iki.fi>
parents: 9289
diff changeset
964 {
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
965 struct mail_storage_service_user *user;
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
966 int ret;
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
967
11018
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
968 ret = mail_storage_service_lookup(ctx, input, &user, error_r);
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
969 if (ret <= 0)
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
970 return ret;
11018
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
971
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
972 ret = mail_storage_service_next(ctx, user, mail_user_r);
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
973 if (ret < 0) {
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
974 mail_storage_service_user_free(&user);
11018
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
975 *error_r = ret == -2 ? ERRSTR_INVALID_USER_SETTINGS :
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
976 MAIL_ERRSTR_CRITICAL_MSG;
2e08ce368bc0 Added support for userdb lookup to fail with a reason (many API changes).
Timo Sirainen <tss@iki.fi>
parents: 11015
diff changeset
977 return ret;
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
978 }
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
979 *user_r = user;
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
980 return 1;
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
981 }
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
982
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
983 void mail_storage_service_user_free(struct mail_storage_service_user **_user)
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
984 {
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
985 struct mail_storage_service_user *user = *_user;
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
986
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
987 *_user = NULL;
9300
b66054f9b8fb Memory leak fixes.
Timo Sirainen <tss@iki.fi>
parents: 9289
diff changeset
988 settings_parser_deinit(&user->set_parser);
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
989 pool_unref(&user->pool);
9300
b66054f9b8fb Memory leak fixes.
Timo Sirainen <tss@iki.fi>
parents: 9289
diff changeset
990 }
b66054f9b8fb Memory leak fixes.
Timo Sirainen <tss@iki.fi>
parents: 9289
diff changeset
991
10273
4109e7f29735 Added mail_storage_service_init_settings().
Timo Sirainen <tss@iki.fi>
parents: 10263
diff changeset
992 void mail_storage_service_init_settings(struct mail_storage_service_ctx *ctx,
4109e7f29735 Added mail_storage_service_init_settings().
Timo Sirainen <tss@iki.fi>
parents: 10263
diff changeset
993 const struct mail_storage_service_input *input)
10148
9df00624855b mail storage service: Fixed iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 10138
diff changeset
994 {
9df00624855b mail storage service: Fixed iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 10138
diff changeset
995 const struct setting_parser_info *user_info;
9df00624855b mail storage service: Fixed iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 10138
diff changeset
996 const struct mail_user_settings *user_set;
10793
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
997 const struct setting_parser_context *set_parser;
10148
9df00624855b mail storage service: Fixed iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 10138
diff changeset
998 const char *error;
9df00624855b mail storage service: Fixed iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 10138
diff changeset
999 pool_t temp_pool;
9df00624855b mail storage service: Fixed iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 10138
diff changeset
1000
10273
4109e7f29735 Added mail_storage_service_init_settings().
Timo Sirainen <tss@iki.fi>
parents: 10263
diff changeset
1001 if (ctx->conn != NULL)
4109e7f29735 Added mail_storage_service_init_settings().
Timo Sirainen <tss@iki.fi>
parents: 10263
diff changeset
1002 return;
4109e7f29735 Added mail_storage_service_init_settings().
Timo Sirainen <tss@iki.fi>
parents: 10263
diff changeset
1003
10148
9df00624855b mail storage service: Fixed iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 10138
diff changeset
1004 temp_pool = pool_alloconly_create("service all settings", 4096);
10273
4109e7f29735 Added mail_storage_service_init_settings().
Timo Sirainen <tss@iki.fi>
parents: 10263
diff changeset
1005 if (mail_storage_service_read_settings(ctx, input, temp_pool,
10793
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
1006 &user_info, &set_parser,
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
1007 &error) < 0)
10148
9df00624855b mail storage service: Fixed iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 10138
diff changeset
1008 i_fatal("%s", error);
10793
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
1009 user_set = settings_parser_get_list(set_parser)[1];
10148
9df00624855b mail storage service: Fixed iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 10138
diff changeset
1010
9df00624855b mail storage service: Fixed iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 10138
diff changeset
1011 mail_storage_service_first_init(ctx, user_info, user_set);
9df00624855b mail storage service: Fixed iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 10138
diff changeset
1012 pool_unref(&temp_pool);
9df00624855b mail storage service: Fixed iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 10138
diff changeset
1013 }
9df00624855b mail storage service: Fixed iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 10138
diff changeset
1014
9300
b66054f9b8fb Memory leak fixes.
Timo Sirainen <tss@iki.fi>
parents: 9289
diff changeset
1015 unsigned int
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
1016 mail_storage_service_all_init(struct mail_storage_service_ctx *ctx)
9300
b66054f9b8fb Memory leak fixes.
Timo Sirainen <tss@iki.fi>
parents: 9289
diff changeset
1017 {
b66054f9b8fb Memory leak fixes.
Timo Sirainen <tss@iki.fi>
parents: 9289
diff changeset
1018 if (ctx->auth_list != NULL)
b66054f9b8fb Memory leak fixes.
Timo Sirainen <tss@iki.fi>
parents: 9289
diff changeset
1019 (void)auth_master_user_list_deinit(&ctx->auth_list);
10273
4109e7f29735 Added mail_storage_service_init_settings().
Timo Sirainen <tss@iki.fi>
parents: 10263
diff changeset
1020 mail_storage_service_init_settings(ctx, NULL);
10148
9df00624855b mail storage service: Fixed iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 10138
diff changeset
1021
9300
b66054f9b8fb Memory leak fixes.
Timo Sirainen <tss@iki.fi>
parents: 9289
diff changeset
1022 ctx->auth_list = auth_master_user_list_init(ctx->conn);
b66054f9b8fb Memory leak fixes.
Timo Sirainen <tss@iki.fi>
parents: 9289
diff changeset
1023 return auth_master_user_list_count(ctx->auth_list);
b66054f9b8fb Memory leak fixes.
Timo Sirainen <tss@iki.fi>
parents: 9289
diff changeset
1024 }
b66054f9b8fb Memory leak fixes.
Timo Sirainen <tss@iki.fi>
parents: 9289
diff changeset
1025
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
1026 int mail_storage_service_all_next(struct mail_storage_service_ctx *ctx,
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
1027 const char **username_r)
9289
0e02c867b15a mail storage multi service: Added support for iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 9263
diff changeset
1028 {
0e02c867b15a mail storage multi service: Added support for iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 9263
diff changeset
1029 i_assert((ctx->flags & MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP) != 0);
0e02c867b15a mail storage multi service: Added support for iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 9263
diff changeset
1030
0e02c867b15a mail storage multi service: Added support for iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 9263
diff changeset
1031 *username_r = auth_master_user_list_next(ctx->auth_list);
0e02c867b15a mail storage multi service: Added support for iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 9263
diff changeset
1032 if (*username_r != NULL)
0e02c867b15a mail storage multi service: Added support for iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 9263
diff changeset
1033 return 1;
0e02c867b15a mail storage multi service: Added support for iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 9263
diff changeset
1034 return auth_master_user_list_deinit(&ctx->auth_list);
0e02c867b15a mail storage multi service: Added support for iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 9263
diff changeset
1035 }
0e02c867b15a mail storage multi service: Added support for iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 9263
diff changeset
1036
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
1037 void mail_storage_service_deinit(struct mail_storage_service_ctx **_ctx)
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1038 {
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
1039 struct mail_storage_service_ctx *ctx = *_ctx;
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1040
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1041 *_ctx = NULL;
9300
b66054f9b8fb Memory leak fixes.
Timo Sirainen <tss@iki.fi>
parents: 9289
diff changeset
1042 if (ctx->auth_list != NULL)
b66054f9b8fb Memory leak fixes.
Timo Sirainen <tss@iki.fi>
parents: 9289
diff changeset
1043 (void)auth_master_user_list_deinit(&ctx->auth_list);
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
1044 if (ctx->conn != NULL) {
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
1045 if (mail_user_auth_master_conn == ctx->conn)
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
1046 mail_user_auth_master_conn = NULL;
9289
0e02c867b15a mail storage multi service: Added support for iterating through all users.
Timo Sirainen <tss@iki.fi>
parents: 9263
diff changeset
1047 auth_master_deinit(&ctx->conn);
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
1048 }
10793
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
1049 if (ctx->set_cache != NULL)
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
1050 master_service_settings_cache_deinit(&ctx->set_cache);
bf4822f0846b lib-master: Added support for caching config lookups.
Timo Sirainen <tss@iki.fi>
parents: 10684
diff changeset
1051 pool_unref(&ctx->pool);
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
1052
10857
02d4cc578d4b mail storage service: Exported modules as mail_storage_service_modules.
Timo Sirainen <tss@iki.fi>
parents: 10856
diff changeset
1053 module_dir_unload(&mail_storage_service_modules);
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
1054 mail_storage_deinit();
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
1055 dict_drivers_unregister_builtin();
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1056 }
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1057
10130
d1384c2b08e5 Merged single and multi mail_storage_service_*() functions.
Timo Sirainen <tss@iki.fi>
parents: 10128
diff changeset
1058 void **mail_storage_service_user_get_set(struct mail_storage_service_user *user)
9118
03fe226e85d4 mail-storage-service: Fixes to handling multiple users.
Timo Sirainen <tss@iki.fi>
parents: 9108
diff changeset
1059 {
03fe226e85d4 mail-storage-service: Fixes to handling multiple users.
Timo Sirainen <tss@iki.fi>
parents: 9108
diff changeset
1060 return settings_parser_get_list(user->set_parser) + 1;
03fe226e85d4 mail-storage-service: Fixes to handling multiple users.
Timo Sirainen <tss@iki.fi>
parents: 9108
diff changeset
1061 }
03fe226e85d4 mail-storage-service: Fixes to handling multiple users.
Timo Sirainen <tss@iki.fi>
parents: 9108
diff changeset
1062
10307
c21543e87190 Forgot to commit mail_storage_service_user_get_input().
Timo Sirainen <tss@iki.fi>
parents: 10273
diff changeset
1063 const struct mail_storage_service_input *
c21543e87190 Forgot to commit mail_storage_service_user_get_input().
Timo Sirainen <tss@iki.fi>
parents: 10273
diff changeset
1064 mail_storage_service_user_get_input(struct mail_storage_service_user *user)
c21543e87190 Forgot to commit mail_storage_service_user_get_input().
Timo Sirainen <tss@iki.fi>
parents: 10273
diff changeset
1065 {
c21543e87190 Forgot to commit mail_storage_service_user_get_input().
Timo Sirainen <tss@iki.fi>
parents: 10273
diff changeset
1066 return &user->input;
c21543e87190 Forgot to commit mail_storage_service_user_get_input().
Timo Sirainen <tss@iki.fi>
parents: 10273
diff changeset
1067 }
c21543e87190 Forgot to commit mail_storage_service_user_get_input().
Timo Sirainen <tss@iki.fi>
parents: 10273
diff changeset
1068
10362
28cdf09c062b Added mail_storage_service_user_get_settings_parser().
Timo Sirainen <tss@iki.fi>
parents: 10307
diff changeset
1069 struct setting_parser_context *
28cdf09c062b Added mail_storage_service_user_get_settings_parser().
Timo Sirainen <tss@iki.fi>
parents: 10307
diff changeset
1070 mail_storage_service_user_get_settings_parser(struct mail_storage_service_user *user)
28cdf09c062b Added mail_storage_service_user_get_settings_parser().
Timo Sirainen <tss@iki.fi>
parents: 10307
diff changeset
1071 {
28cdf09c062b Added mail_storage_service_user_get_settings_parser().
Timo Sirainen <tss@iki.fi>
parents: 10307
diff changeset
1072 return user->set_parser;
28cdf09c062b Added mail_storage_service_user_get_settings_parser().
Timo Sirainen <tss@iki.fi>
parents: 10307
diff changeset
1073 }
28cdf09c062b Added mail_storage_service_user_get_settings_parser().
Timo Sirainen <tss@iki.fi>
parents: 10307
diff changeset
1074
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1075 void *mail_storage_service_get_settings(struct master_service *service)
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1076 {
9447
0a1f989bc5ad lib-storage: Avoid wasting data stack usage.
Timo Sirainen <tss@iki.fi>
parents: 9407
diff changeset
1077 void **sets, *set;
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1078
9447
0a1f989bc5ad lib-storage: Avoid wasting data stack usage.
Timo Sirainen <tss@iki.fi>
parents: 9407
diff changeset
1079 T_BEGIN {
0a1f989bc5ad lib-storage: Avoid wasting data stack usage.
Timo Sirainen <tss@iki.fi>
parents: 9407
diff changeset
1080 sets = master_service_settings_get_others(service);
0a1f989bc5ad lib-storage: Avoid wasting data stack usage.
Timo Sirainen <tss@iki.fi>
parents: 9407
diff changeset
1081 set = sets[1];
0a1f989bc5ad lib-storage: Avoid wasting data stack usage.
Timo Sirainen <tss@iki.fi>
parents: 9407
diff changeset
1082 } T_END;
0a1f989bc5ad lib-storage: Avoid wasting data stack usage.
Timo Sirainen <tss@iki.fi>
parents: 9407
diff changeset
1083 return set;
9059
94ecf8a8ed68 Added lib-master and mail-storage-service code that makes it easier to build new Dovecot binaries.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1084 }