Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib/home-expand.c @ 9191:b340ecb24469 HEAD
Fix VPATH build of RQUOTA support.
Some rpcgen derive #include "..." paths from the infile argument.
This will be off for VPATH builds, as the generated rquota_xdr.c
code will look in $(srcdir), but we'll generate the rquota.h file in
$(builddir). Play safe and copy rquota.x to $(builddir) first.
This fixes the build on openSUSE 11.1.
author | Matthias Andree <matthias.andree@gmx.de> |
---|---|
date | Tue, 07 Jul 2009 21:01:36 +0200 |
parents | b9faf4db2a9f |
children | 00cd9aacd03c |
rev | line source |
---|---|
8590
b9faf4db2a9f
Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
1 /* Copyright (c) 2003-2009 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" |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 #include "home-expand.h" |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include <stdlib.h> |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 #include <pwd.h> |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 |
4984 | 9 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
|
10 { |
4984 | 11 const char *path = *_path; |
1151
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 const char *home, *p, *orig_path; |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 struct passwd *pw; |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 |
1588 | 15 if (path == NULL || *path != '~') |
4984 | 16 return 0; |
1151
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 orig_path = path++; |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 if (*path == '/' || *path == '\0') { |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 home = getenv("HOME"); |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 if (*path != '\0') path++; |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 } else { |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 p = strchr(path, '/'); |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 if (p == NULL) { |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 pw = getpwnam(path); |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 path = ""; |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 } else { |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 pw = getpwnam(t_strdup_until(path, p)); |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 path = p+1; |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
30 } |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
31 |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 home = pw == NULL ? NULL : pw->pw_dir; |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
33 } |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
34 |
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
35 if (home == NULL) |
4984 | 36 return -1; |
37 | |
38 if (*path == '\0') | |
39 *_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
|
40 else |
4984 | 41 *_path = t_strconcat(home, "/", path, NULL); |
42 return 0; | |
1151
058f6c26f405
Added mail_full_filesystem_access setting. Some of the setting variable
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
43 } |
4984 | 44 |
45 const char *home_expand(const char *path) | |
46 { | |
47 (void)home_try_expand(&path); | |
48 return path; | |
49 } | |
5385 | 50 |
51 const char *home_expand_tilde(const char *path, const char *home) | |
52 { | |
53 if (path == NULL || *path != '~') | |
54 return path; | |
55 | |
56 if (path[1] == '\0') | |
57 return home; | |
58 if (path[1] != '/') | |
59 return path; | |
60 | |
61 /* ~/ used */ | |
62 return t_strconcat(home, path + 1, NULL); | |
63 } |