Mercurial > dovecot > core-2.2
annotate src/lib/home-expand.c @ 22955:812e5c961328
fts: Indexing virtual mailbox didn't always index the last mails
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Thu, 03 May 2018 18:33:00 +0300 |
parents | cb108f786fb4 |
children |
rev | line source |
---|---|
22713
cb108f786fb4
Updated copyright notices to include the year 2018.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
1 /* Copyright (c) 2003-2018 Dovecot authors, see the included COPYING file */ |
1151
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "lib.h" |
12859
02829f7f79c7
Replaced all getpw/gr*() to use i_getpw/gr*() with improved error handling.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
4 #include "ipwd.h" |
1151
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #include "home-expand.h" |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 |
4984 | 8 int home_try_expand(const char **_path) |
1151
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 { |
4984 | 10 const char *path = *_path; |
12859
02829f7f79c7
Replaced all getpw/gr*() to use i_getpw/gr*() with improved error handling.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
11 const char *name, *home, *p; |
02829f7f79c7
Replaced all getpw/gr*() to use i_getpw/gr*() with improved error handling.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
12 struct passwd pw; |
1151
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 |
1588 | 14 if (path == NULL || *path != '~') |
4984 | 15 return 0; |
1151
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 |
11039 | 17 path++; |
1151
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 if (*path == '/' || *path == '\0') { |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 home = getenv("HOME"); |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 if (*path != '\0') path++; |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 } else { |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 p = strchr(path, '/'); |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 if (p == NULL) { |
12859
02829f7f79c7
Replaced all getpw/gr*() to use i_getpw/gr*() with improved error handling.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
24 name = path; |
1151
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 path = ""; |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 } else { |
12859
02829f7f79c7
Replaced all getpw/gr*() to use i_getpw/gr*() with improved error handling.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
27 name = t_strdup_until(path, p); |
1151
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 path = p+1; |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 } |
12859
02829f7f79c7
Replaced all getpw/gr*() to use i_getpw/gr*() with improved error handling.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
30 switch (i_getpwnam(name, &pw)) { |
02829f7f79c7
Replaced all getpw/gr*() to use i_getpw/gr*() with improved error handling.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
31 case -1: |
02829f7f79c7
Replaced all getpw/gr*() to use i_getpw/gr*() with improved error handling.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
32 i_error("getpwnam(%s) failed: %m", name); |
02829f7f79c7
Replaced all getpw/gr*() to use i_getpw/gr*() with improved error handling.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
33 home = NULL; |
02829f7f79c7
Replaced all getpw/gr*() to use i_getpw/gr*() with improved error handling.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
34 break; |
02829f7f79c7
Replaced all getpw/gr*() to use i_getpw/gr*() with improved error handling.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
35 case 0: |
02829f7f79c7
Replaced all getpw/gr*() to use i_getpw/gr*() with improved error handling.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
36 home = NULL; |
02829f7f79c7
Replaced all getpw/gr*() to use i_getpw/gr*() with improved error handling.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
37 break; |
02829f7f79c7
Replaced all getpw/gr*() to use i_getpw/gr*() with improved error handling.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
38 default: |
02829f7f79c7
Replaced all getpw/gr*() to use i_getpw/gr*() with improved error handling.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
39 home = pw.pw_dir; |
02829f7f79c7
Replaced all getpw/gr*() to use i_getpw/gr*() with improved error handling.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
40 break; |
02829f7f79c7
Replaced all getpw/gr*() to use i_getpw/gr*() with improved error handling.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
41 } |
1151
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 } |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
43 |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
44 if (home == NULL) |
4984 | 45 return -1; |
46 | |
47 if (*path == '\0') | |
48 *_path = t_strdup(home); | |
1151
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
49 else |
4984 | 50 *_path = t_strconcat(home, "/", path, NULL); |
51 return 0; | |
1151
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 } |
4984 | 53 |
54 const char *home_expand(const char *path) | |
55 { | |
56 (void)home_try_expand(&path); | |
57 return path; | |
58 } | |
5385 | 59 |
60 const char *home_expand_tilde(const char *path, const char *home) | |
61 { | |
62 if (path == NULL || *path != '~') | |
63 return path; | |
64 | |
65 if (path[1] == '\0') | |
66 return home; | |
67 if (path[1] != '/') | |
68 return path; | |
69 | |
70 /* ~/ used */ | |
71 return t_strconcat(home, path + 1, NULL); | |
72 } |