Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-storage/mail-error.c @ 8590:b9faf4db2a9f HEAD
Updated copyright notices to include year 2009.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 06 Jan 2009 09:25:38 -0500 |
parents | 1e42b631f037 |
children | 1bfe762cb9ff |
rev | line source |
---|---|
8590
b9faf4db2a9f
Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents:
8518
diff
changeset
|
1 /* Copyright (c) 2007-2009 Dovecot authors, see the included COPYING file */ |
5613 | 2 |
3 #include "lib.h" | |
8518
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
4 #include "str.h" |
5613 | 5 #include "mail-error.h" |
6 | |
8518
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
7 #include <sys/stat.h> |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
8 #include <unistd.h> |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
9 #include <pwd.h> |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
10 #include <grp.h> |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
11 |
5613 | 12 bool mail_error_from_errno(enum mail_error *error_r, |
13 const char **error_string_r) | |
14 { | |
15 if (ENOACCESS(errno)) { | |
16 *error_r = MAIL_ERROR_PERM; | |
17 *error_string_r = MAIL_ERRSTR_NO_PERMISSION; | |
18 } else if (ENOSPACE(errno)) { | |
19 *error_r = MAIL_ERROR_NOSPACE; | |
20 *error_string_r = MAIL_ERRSTR_NO_SPACE; | |
21 } else if (ENOTFOUND(errno)) { | |
22 *error_r = MAIL_ERROR_NOTFOUND; | |
23 *error_string_r = errno != ELOOP ? "Not found" : | |
24 "Directory structure is broken"; | |
25 } else { | |
26 return FALSE; | |
27 } | |
28 return TRUE; | |
29 } | |
8518
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
30 |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
31 const char *mail_error_eacces_msg(const char *func, const char *path) |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
32 { |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
33 const char *prev_path = path, *dir = "/", *p; |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
34 const struct passwd *pw; |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
35 const struct group *group; |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
36 string_t *errmsg; |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
37 struct stat st; |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
38 int ret = -1; |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
39 |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
40 errmsg = t_str_new(256); |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
41 str_printfa(errmsg, "%s(%s) failed: Permission denied (euid=%s", |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
42 func, path, dec2str(geteuid())); |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
43 |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
44 pw = getpwuid(geteuid()); |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
45 if (pw != NULL) |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
46 str_printfa(errmsg, "(%s)", pw->pw_name); |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
47 |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
48 str_printfa(errmsg, " egid=%s", dec2str(getegid())); |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
49 group = getgrgid(getegid()); |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
50 if (group != NULL) |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
51 str_printfa(errmsg, "(%s)", group->gr_name); |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
52 |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
53 while ((p = strrchr(prev_path, '/')) != NULL) { |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
54 dir = t_strdup_until(prev_path, p); |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
55 ret = stat(dir, &st); |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
56 if (ret == 0 || errno != EACCES) |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
57 break; |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
58 prev_path = dir; |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
59 dir = "/"; |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
60 } |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
61 |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
62 if (ret == 0) { |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
63 if (access(dir, X_OK) < 0 && errno == EACCES) |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
64 str_printfa(errmsg, " missing +x perm: %s", dir); |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
65 else if (prev_path == path && |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
66 access(path, R_OK) < 0 && errno == EACCES) |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
67 str_printfa(errmsg, " missing +r perm: %s", path); |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
68 } |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
69 str_append_c(errmsg, ')'); |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
70 return str_c(errmsg); |
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
71 } |