(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/eacces-error.c) |
| |
| 29 | | | static int test_access(const char *path, int mode, string_t *errmsg) |
| 30 | | | { |
| 31 | | | struct stat st; |
| 32 | | | |
| 33 | | | if (getuid() == geteuid()) { |
| 34 | | | if (access(path, mode) == 0) |
| 35 | | | return 0; |
| 36 | | | |
| 37 | | | if (errno != EACCES) {
x /usr/include/asm-generic/errno-base.h |
| |
16 | #define EACCES 13 /* Permission denied */ |
| |
|
| 38 | | | str_printfa(errmsg, " access(%s, %d) failed: %m", |
| 39 | | | path, mode); |
| 40 | | | } |
| 41 | | | return -1; |
| 42 | | | } |
| 43 | | | |
| 44 | | | |
| 45 | | | |
| 46 | | | switch (mode) { |
| 47 | | | case X_OK:
x /usr/include/unistd.h |
| |
284 | #define X_OK 1 /* Test for execute permission. */ |
| |
|
| 48 | | | if (stat(t_strconcat(path, "/test", NULL), &st) == 0) |
| 49 | | | return 0; |
| 50 | | | if (errno == ENOENT || errno == ENOTDIR)
x /usr/include/asm-generic/errno-base.h |
| |
5 | #define ENOENT 2 /* No such file or directory */ |
| |
x /usr/include/asm-generic/errno-base.h |
| |
23 | #define ENOTDIR 20 /* Not a directory */ |
| |
|
| 51 | | | return 0; |
| 52 | | | if (errno != EACCES)
x /usr/include/asm-generic/errno-base.h |
| |
16 | #define EACCES 13 /* Permission denied */ |
| |
|
| 53 | | | str_printfa(errmsg, " stat(%s/test) failed: %m", path); |
| 54 | | | return -1; |
| 55 | | | case R_OK:
x /usr/include/unistd.h |
| |
282 | #define R_OK 4 /* Test for read permission. */ |
| |
|
| 56 | | | mode = 04; |
Useless Assignment
This code assigns the variable the same value it already had. |
|
| 57 | | | break; |
| 58 | | | case W_OK:
x /usr/include/unistd.h |
| |
283 | #define W_OK 2 /* Test for write permission. */ |
| |
|
| 59 | | | mode = 02; |
| 60 | | | break; |
| 61 | | | default: |
| 62 | | | i_unreached();
x /home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/macros.h |
| |
208 | #define i_unreached() \ |
209 | i_panic("file %s: line %d: unreached", __FILE__, __LINE__) |
| |
|
| 63 | | | } |
| 64 | | | |
| 65 | | | if (stat(path, &st) < 0) { |
| 66 | | | str_printfa(errmsg, " stat(%s) failed: %m", path); |
| 67 | | | return -1; |
| 68 | | | } |
| 69 | | | |
| 70 | | | if (st.st_uid == geteuid()) |
| 71 | | | st.st_mode = (st.st_mode & 0700) >> 6; |
| 72 | | | else if (is_in_group(st.st_gid)) |
| 73 | | | st.st_mode = (st.st_mode & 0070) >> 3; |
| 74 | | | else |
| 75 | | | st.st_mode = (st.st_mode & 0007); |
| 76 | | | |
| 77 | | | if ((st.st_mode & mode) != 0) |
| 78 | | | return 0; |
| 79 | | | errno = EACCES;
x /usr/include/asm-generic/errno-base.h |
| |
16 | #define EACCES 13 /* Permission denied */ |
| |
|
| 80 | | | return -1; |
| 81 | | | } |
| |