annotate src/lib-storage/mail-error.c @ 8641:02ba04b6aa07 HEAD

Fix to previous commit to actually compile..
author Timo Sirainen <tss@iki.fi>
date Fri, 16 Jan 2009 12:29:30 -0500
parents 1bfe762cb9ff
children dd53d40a2f09
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
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
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "mail-error.h"
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
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
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 bool mail_error_from_errno(enum mail_error *error_r,
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 const char **error_string_r)
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 {
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 if (ENOACCESS(errno)) {
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 *error_r = MAIL_ERROR_PERM;
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 *error_string_r = MAIL_ERRSTR_NO_PERMISSION;
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 } else if (ENOSPACE(errno)) {
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19 *error_r = MAIL_ERROR_NOSPACE;
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20 *error_string_r = MAIL_ERRSTR_NO_SPACE;
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21 } else if (ENOTFOUND(errno)) {
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22 *error_r = MAIL_ERROR_NOTFOUND;
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23 *error_string_r = errno != ELOOP ? "Not found" :
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24 "Directory structure is broken";
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25 } else {
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26 return FALSE;
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27 }
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28 return TRUE;
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
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);
8640
1bfe762cb9ff Permission error logging: If UNIX permissions appear to be ok, suggest ACL problem.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
68 else
8641
02ba04b6aa07 Fix to previous commit to actually compile..
Timo Sirainen <tss@iki.fi>
parents: 8640
diff changeset
69 str_printfa(errmsg, " UNIX perms seem ok, ACL problem?");
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
70 }
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 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
72 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
73 }