diff options
-rw-r--r-- | src/lib/firejail_user.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/lib/firejail_user.c b/src/lib/firejail_user.c index 03aaa3b4e..4dbbcee2a 100644 --- a/src/lib/firejail_user.c +++ b/src/lib/firejail_user.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include "../include/firejail_user.h" | 29 | #include "../include/firejail_user.h" |
30 | #include <sys/types.h> | 30 | #include <sys/types.h> |
31 | #include <pwd.h> | 31 | #include <pwd.h> |
32 | #include <errno.h> | ||
32 | 33 | ||
33 | #define MAXBUF 4098 | 34 | #define MAXBUF 4098 |
34 | 35 | ||
@@ -113,15 +114,22 @@ int firejail_user_check(const char *name) { | |||
113 | 114 | ||
114 | // check file existence | 115 | // check file existence |
115 | char *fname = get_fname(); | 116 | char *fname = get_fname(); |
117 | assert(fname); | ||
116 | if (access(fname, F_OK)) { | 118 | if (access(fname, F_OK)) { |
117 | free(fname); | 119 | if (errno == ENOENT) { // assume the user doesn't care about access checking |
118 | return 1; // assume the user doesn't care about access checking | 120 | free(fname); |
121 | return 1; | ||
122 | } | ||
123 | else { // for example no search permission on SYSCONFDIR | ||
124 | fprintf(stderr, "Error: cannot access %s\n", fname); | ||
125 | perror("access"); | ||
126 | exit(1); | ||
127 | } | ||
119 | } | 128 | } |
120 | 129 | ||
121 | FILE *fp = fopen(fname, "r"); | 130 | FILE *fp = fopen(fname, "r"); |
122 | if (!fp) { | 131 | if (!fp) { |
123 | fprintf(stderr, "Error: cannot open %s for reading. " | 132 | fprintf(stderr, "Error: cannot read %s\n", fname); |
124 | "See \"man firejail-users\" for more information about this file.\n", fname); | ||
125 | perror("fopen"); | 133 | perror("fopen"); |
126 | exit(1); | 134 | exit(1); |
127 | } | 135 | } |
@@ -166,6 +174,7 @@ void firejail_user_add(const char *name) { | |||
166 | if (access(fname, F_OK) == 0) { | 174 | if (access(fname, F_OK) == 0) { |
167 | if (firejail_user_check(name)) { | 175 | if (firejail_user_check(name)) { |
168 | printf("User %s already in the database\n", name); | 176 | printf("User %s already in the database\n", name); |
177 | free(fname); | ||
169 | return; | 178 | return; |
170 | } | 179 | } |
171 | } | 180 | } |