Mercurial > dovecot > original-hg > dovecot-1.2
comparison src/lib-storage/index/shared/shared-storage.c @ 8467:03c418eadc8b HEAD
mail_user_*() now handles home directory lookups when necessary.
Namespace owner is now a pointer to struct mail_user rather than a string.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 21 Nov 2008 18:32:02 +0200 |
parents | 027a61241ebb |
children | 983d38de06c9 |
comparison
equal
deleted
inserted
replaced
8466:4553e28eb4f5 | 8467:03c418eadc8b |
---|---|
2 | 2 |
3 #include "lib.h" | 3 #include "lib.h" |
4 #include "array.h" | 4 #include "array.h" |
5 #include "str.h" | 5 #include "str.h" |
6 #include "ioloop.h" | 6 #include "ioloop.h" |
7 #include "auth-master.h" | |
8 #include "var-expand.h" | 7 #include "var-expand.h" |
9 #include "index-storage.h" | 8 #include "index-storage.h" |
10 #include "shared-storage.h" | 9 #include "shared-storage.h" |
11 | 10 |
12 #include <stdlib.h> | 11 #include <stdlib.h> |
103 mailbox_list_init(_storage->list, _storage->ns, &list_set, | 102 mailbox_list_init(_storage->list, _storage->ns, &list_set, |
104 mail_storage_get_list_flags(_storage->flags)); | 103 mail_storage_get_list_flags(_storage->flags)); |
105 return 0; | 104 return 0; |
106 } | 105 } |
107 | 106 |
108 static void shared_storage_destroy(struct mail_storage *_storage) | 107 static void |
109 { | 108 get_nonexisting_user_location(struct shared_storage *storage, |
110 struct shared_storage *storage = (struct shared_storage *)_storage; | 109 const char *username, string_t *location) |
111 | |
112 if (storage->auth_master_conn != NULL) | |
113 auth_master_deinit(&storage->auth_master_conn); | |
114 index_storage_destroy(_storage); | |
115 } | |
116 | |
117 static void shared_storage_auth_master_init(struct shared_storage *storage) | |
118 { | |
119 const char *auth_socket_path; | |
120 bool debug; | |
121 | |
122 auth_socket_path = getenv("AUTH_SOCKET_PATH"); | |
123 if (auth_socket_path == NULL) { | |
124 auth_socket_path = t_strconcat(storage->base_dir, | |
125 "/auth-master", NULL); | |
126 } | |
127 | |
128 debug = (storage->storage.flags & MAIL_STORAGE_FLAG_DEBUG) != 0; | |
129 storage->auth_master_conn = auth_master_init(auth_socket_path, debug); | |
130 } | |
131 | |
132 static int | |
133 shared_storage_lookup_home(struct shared_storage *storage, | |
134 const char *user, const char **home_r) | |
135 { | |
136 struct auth_user_reply reply; | |
137 pool_t userdb_pool; | |
138 int ret; | |
139 | |
140 if (storage->auth_master_conn == NULL) | |
141 shared_storage_auth_master_init(storage); | |
142 | |
143 userdb_pool = pool_alloconly_create("userdb lookup", 512); | |
144 ret = auth_master_user_lookup(storage->auth_master_conn, user, | |
145 AUTH_SERVICE_INTERNAL, | |
146 userdb_pool, &reply); | |
147 if (ret > 0) | |
148 *home_r = t_strdup(reply.home); | |
149 pool_unref(&userdb_pool); | |
150 return ret; | |
151 } | |
152 | |
153 static void get_nonexisting_user_location(struct shared_storage *storage, | |
154 string_t *location) | |
155 { | 110 { |
156 /* user wasn't found. we'll still need to create the storage | 111 /* user wasn't found. we'll still need to create the storage |
157 to avoid exposing which users exist and which don't. */ | 112 to avoid exposing which users exist and which don't. */ |
158 str_append(location, storage->storage_class->name); | 113 str_append(location, storage->storage_class->name); |
159 str_append_c(location, ':'); | 114 str_append_c(location, ':'); |
160 | 115 |
161 /* use a reachable but non-existing path as the mail root directory */ | 116 /* use a reachable but non-existing path as the mail root directory */ |
162 str_append(location, storage->base_dir); | 117 str_append(location, storage->base_dir); |
163 str_append(location, PKG_RUNDIR"/user-not-found"); | 118 str_append(location, "/user-not-found/"); |
119 str_append(location, username); | |
164 } | 120 } |
165 | 121 |
166 int shared_storage_get_namespace(struct mail_storage *_storage, | 122 int shared_storage_get_namespace(struct mail_storage *_storage, |
167 const char **_name, | 123 const char **_name, |
168 struct mail_namespace **ns_r) | 124 struct mail_namespace **ns_r) |
176 { 'h', NULL }, | 132 { 'h', NULL }, |
177 { '\0', NULL } | 133 { '\0', NULL } |
178 }; | 134 }; |
179 struct var_expand_table *tab; | 135 struct var_expand_table *tab; |
180 struct mail_namespace *ns; | 136 struct mail_namespace *ns; |
137 struct mail_user *owner; | |
181 const char *domain = NULL, *username = NULL, *userdomain = NULL; | 138 const char *domain = NULL, *username = NULL, *userdomain = NULL; |
182 const char *name, *p, *next, **dest, *error; | 139 const char *name, *p, *next, **dest, *error; |
183 string_t *prefix, *location; | 140 string_t *prefix, *location; |
184 int ret; | 141 int ret; |
185 | 142 |
248 *_name = mail_namespace_fix_sep(ns, name); | 205 *_name = mail_namespace_fix_sep(ns, name); |
249 *ns_r = ns; | 206 *ns_r = ns; |
250 return 0; | 207 return 0; |
251 } | 208 } |
252 | 209 |
210 owner = mail_user_init(userdomain); | |
253 if (!var_has_key(storage->location, 'h')) | 211 if (!var_has_key(storage->location, 'h')) |
254 ret = 1; | 212 ret = 1; |
255 else { | 213 else { |
256 /* we'll need to look up the user's home directory */ | 214 /* we'll need to look up the user's home directory */ |
257 ret = shared_storage_lookup_home(storage, userdomain, | 215 if ((ret = mail_user_get_home(owner, &tab[3].value)) < 0) { |
258 &tab[3].value); | |
259 if (ret < 0) { | |
260 mail_storage_set_critical(_storage, "Namespace '%s': " | 216 mail_storage_set_critical(_storage, "Namespace '%s': " |
261 "Could not lookup home for user %s", | 217 "Could not lookup home for user %s", |
262 _storage->ns->prefix, userdomain); | 218 _storage->ns->prefix, userdomain); |
219 mail_user_unref(&owner); | |
263 return -1; | 220 return -1; |
264 } | 221 } |
265 } | 222 } |
266 | 223 |
267 /* create the new namespace */ | 224 /* create the new namespace */ |
268 ns = i_new(struct mail_namespace, 1); | 225 ns = i_new(struct mail_namespace, 1); |
269 ns->type = NAMESPACE_SHARED; | 226 ns->type = NAMESPACE_SHARED; |
270 ns->user = user; | 227 ns->user = user; |
271 ns->prefix = i_strdup(str_c(prefix)); | 228 ns->prefix = i_strdup(str_c(prefix)); |
272 ns->owner = i_strdup(userdomain); | 229 ns->owner = owner; |
273 ns->flags = NAMESPACE_FLAG_LIST_PREFIX | NAMESPACE_FLAG_HIDDEN | | 230 ns->flags = NAMESPACE_FLAG_LIST_PREFIX | NAMESPACE_FLAG_HIDDEN | |
274 NAMESPACE_FLAG_AUTOCREATED; | 231 NAMESPACE_FLAG_AUTOCREATED; |
275 ns->sep = _storage->ns->sep; | 232 ns->sep = _storage->ns->sep; |
276 | 233 |
277 location = t_str_new(256); | 234 location = t_str_new(256); |
278 if (ret > 0) | 235 if (ret > 0) |
279 var_expand(location, storage->location, tab); | 236 var_expand(location, storage->location, tab); |
280 else | 237 else |
281 get_nonexisting_user_location(storage, location); | 238 get_nonexisting_user_location(storage, userdomain, location); |
282 if (mail_storage_create(ns, NULL, str_c(location), _storage->flags, | 239 if (mail_storage_create(ns, NULL, str_c(location), _storage->flags, |
283 _storage->lock_method, &error) < 0) { | 240 _storage->lock_method, &error) < 0) { |
284 mail_storage_set_critical(_storage, "Namespace '%s': %s", | 241 mail_storage_set_critical(_storage, "Namespace '%s': %s", |
285 ns->prefix, error); | 242 ns->prefix, error); |
243 mail_namespace_destroy(ns); | |
286 return -1; | 244 return -1; |
287 } | 245 } |
288 mail_user_add_namespace(user, ns); | 246 mail_user_add_namespace(user, ns); |
289 _storage->ns->flags |= NAMESPACE_FLAG_USABLE; | 247 _storage->ns->flags |= NAMESPACE_FLAG_USABLE; |
290 | 248 |
352 { | 310 { |
353 NULL, | 311 NULL, |
354 NULL, | 312 NULL, |
355 shared_alloc, | 313 shared_alloc, |
356 shared_create, | 314 shared_create, |
357 shared_storage_destroy, | 315 index_storage_destroy, |
358 NULL, | 316 NULL, |
359 shared_mailbox_open, | 317 shared_mailbox_open, |
360 shared_mailbox_create | 318 shared_mailbox_create |
361 } | 319 } |
362 }; | 320 }; |