diff options
author | Fred Barclay <Fred-Barclay@users.noreply.github.com> | 2017-05-24 14:13:52 -0500 |
---|---|---|
committer | Fred Barclay <Fred-Barclay@users.noreply.github.com> | 2017-05-24 14:13:52 -0500 |
commit | 96c920e166b40bbe50f216e294f2efac154a1cb2 (patch) | |
tree | fa80a34e81863ab897f2f2b8ec4124b10d023516 /src/firecfg/main.c | |
parent | remove trailing whitespace from etc/ (diff) | |
download | firejail-96c920e166b40bbe50f216e294f2efac154a1cb2.tar.gz firejail-96c920e166b40bbe50f216e294f2efac154a1cb2.tar.zst firejail-96c920e166b40bbe50f216e294f2efac154a1cb2.zip |
Remove trailing whitespace from src/
Diffstat (limited to 'src/firecfg/main.c')
-rw-r--r-- | src/firecfg/main.c | 57 |
1 files changed, 28 insertions, 29 deletions
diff --git a/src/firecfg/main.c b/src/firecfg/main.c index 4f957b4ae..ea439cf0e 100644 --- a/src/firecfg/main.c +++ b/src/firecfg/main.c | |||
@@ -79,7 +79,7 @@ static void sound(void) { | |||
79 | if (!home) { | 79 | if (!home) { |
80 | goto errexit; | 80 | goto errexit; |
81 | } | 81 | } |
82 | 82 | ||
83 | // the input file is /etc/pulse/client.conf | 83 | // the input file is /etc/pulse/client.conf |
84 | FILE *fpin = fopen("/etc/pulse/client.conf", "r"); | 84 | FILE *fpin = fopen("/etc/pulse/client.conf", "r"); |
85 | if (!fpin) { | 85 | if (!fpin) { |
@@ -95,18 +95,18 @@ static void sound(void) { | |||
95 | free(fname); | 95 | free(fname); |
96 | if (!fpout) | 96 | if (!fpout) |
97 | goto errexit; | 97 | goto errexit; |
98 | 98 | ||
99 | // copy default config | 99 | // copy default config |
100 | char buf[MAX_BUF]; | 100 | char buf[MAX_BUF]; |
101 | while (fgets(buf, MAX_BUF, fpin)) | 101 | while (fgets(buf, MAX_BUF, fpin)) |
102 | fputs(buf, fpout); | 102 | fputs(buf, fpout); |
103 | 103 | ||
104 | // disable shm | 104 | // disable shm |
105 | fprintf(fpout, "\nenable-shm = no\n"); | 105 | fprintf(fpout, "\nenable-shm = no\n"); |
106 | fclose(fpin); | 106 | fclose(fpin); |
107 | fclose(fpout); | 107 | fclose(fpout); |
108 | printf("PulseAudio configured, please logout and login back again\n"); | 108 | printf("PulseAudio configured, please logout and login back again\n"); |
109 | return; | 109 | return; |
110 | 110 | ||
111 | errexit: | 111 | errexit: |
112 | fprintf(stderr, "Error: cannot configure sound file\n"); | 112 | fprintf(stderr, "Error: cannot configure sound file\n"); |
@@ -116,18 +116,18 @@ errexit: | |||
116 | // return 1 if the program is found | 116 | // return 1 if the program is found |
117 | static int find(const char *program, const char *directory) { | 117 | static int find(const char *program, const char *directory) { |
118 | int retval = 0; | 118 | int retval = 0; |
119 | 119 | ||
120 | char *fname; | 120 | char *fname; |
121 | if (asprintf(&fname, "/%s/%s", directory, program) == -1) | 121 | if (asprintf(&fname, "/%s/%s", directory, program) == -1) |
122 | errExit("asprintf"); | 122 | errExit("asprintf"); |
123 | 123 | ||
124 | struct stat s; | 124 | struct stat s; |
125 | if (stat(fname, &s) == 0) { | 125 | if (stat(fname, &s) == 0) { |
126 | if (arg_debug) | 126 | if (arg_debug) |
127 | printf("found %s in directory %s\n", program, directory); | 127 | printf("found %s in directory %s\n", program, directory); |
128 | retval = 1; | 128 | retval = 1; |
129 | } | 129 | } |
130 | 130 | ||
131 | free(fname); | 131 | free(fname); |
132 | return retval; | 132 | return retval; |
133 | } | 133 | } |
@@ -140,14 +140,14 @@ static int which(const char *program) { | |||
140 | find(program, "/sbin") || find(program, "/usr/sbin") || | 140 | find(program, "/sbin") || find(program, "/usr/sbin") || |
141 | find(program, "/usr/games")) | 141 | find(program, "/usr/games")) |
142 | return 1; | 142 | return 1; |
143 | 143 | ||
144 | // check environment | 144 | // check environment |
145 | char *path1 = getenv("PATH"); | 145 | char *path1 = getenv("PATH"); |
146 | if (path1) { | 146 | if (path1) { |
147 | char *path2 = strdup(path1); | 147 | char *path2 = strdup(path1); |
148 | if (!path2) | 148 | if (!path2) |
149 | errExit("strdup"); | 149 | errExit("strdup"); |
150 | 150 | ||
151 | // use path2 to count the entries | 151 | // use path2 to count the entries |
152 | char *ptr = strtok(path2, ":"); | 152 | char *ptr = strtok(path2, ":"); |
153 | while (ptr) { | 153 | while (ptr) { |
@@ -159,7 +159,7 @@ static int which(const char *program) { | |||
159 | } | 159 | } |
160 | free(path2); | 160 | free(path2); |
161 | } | 161 | } |
162 | 162 | ||
163 | return 0; | 163 | return 0; |
164 | } | 164 | } |
165 | 165 | ||
@@ -193,11 +193,11 @@ static void list(void) { | |||
193 | while ((entry = readdir(dir)) != NULL) { | 193 | while ((entry = readdir(dir)) != NULL) { |
194 | if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) | 194 | if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) |
195 | continue; | 195 | continue; |
196 | 196 | ||
197 | char *fullname; | 197 | char *fullname; |
198 | if (asprintf(&fullname, "/usr/local/bin/%s", entry->d_name) == -1) | 198 | if (asprintf(&fullname, "/usr/local/bin/%s", entry->d_name) == -1) |
199 | errExit("asprintf"); | 199 | errExit("asprintf"); |
200 | 200 | ||
201 | if (is_link(fullname)) { | 201 | if (is_link(fullname)) { |
202 | char* fname = realpath(fullname, NULL); | 202 | char* fname = realpath(fullname, NULL); |
203 | if (fname) { | 203 | if (fname) { |
@@ -208,7 +208,7 @@ static void list(void) { | |||
208 | } | 208 | } |
209 | free(fullname); | 209 | free(fullname); |
210 | } | 210 | } |
211 | 211 | ||
212 | closedir(dir); | 212 | closedir(dir); |
213 | free(firejail_exec); | 213 | free(firejail_exec); |
214 | } | 214 | } |
@@ -233,11 +233,11 @@ static void clear(void) { | |||
233 | while ((entry = readdir(dir)) != NULL) { | 233 | while ((entry = readdir(dir)) != NULL) { |
234 | if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) | 234 | if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) |
235 | continue; | 235 | continue; |
236 | 236 | ||
237 | char *fullname; | 237 | char *fullname; |
238 | if (asprintf(&fullname, "/usr/local/bin/%s", entry->d_name) == -1) | 238 | if (asprintf(&fullname, "/usr/local/bin/%s", entry->d_name) == -1) |
239 | errExit("asprintf"); | 239 | errExit("asprintf"); |
240 | 240 | ||
241 | if (is_link(fullname)) { | 241 | if (is_link(fullname)) { |
242 | char* fname = realpath(fullname, NULL); | 242 | char* fname = realpath(fullname, NULL); |
243 | if (fname) { | 243 | if (fname) { |
@@ -250,7 +250,7 @@ static void clear(void) { | |||
250 | } | 250 | } |
251 | free(fullname); | 251 | free(fullname); |
252 | } | 252 | } |
253 | 253 | ||
254 | closedir(dir); | 254 | closedir(dir); |
255 | free(firejail_exec); | 255 | free(firejail_exec); |
256 | } | 256 | } |
@@ -262,7 +262,7 @@ static void set_file(const char *name, const char *firejail_exec) { | |||
262 | char *fname; | 262 | char *fname; |
263 | if (asprintf(&fname, "/usr/local/bin/%s", name) == -1) | 263 | if (asprintf(&fname, "/usr/local/bin/%s", name) == -1) |
264 | errExit("asprintf"); | 264 | errExit("asprintf"); |
265 | 265 | ||
266 | struct stat s; | 266 | struct stat s; |
267 | if (stat(fname, &s) != 0) { | 267 | if (stat(fname, &s) != 0) { |
268 | int rv = symlink(firejail_exec, fname); | 268 | int rv = symlink(firejail_exec, fname); |
@@ -273,7 +273,7 @@ static void set_file(const char *name, const char *firejail_exec) { | |||
273 | else | 273 | else |
274 | printf(" %s created\n", name); | 274 | printf(" %s created\n", name); |
275 | } | 275 | } |
276 | 276 | ||
277 | free(fname); | 277 | free(fname); |
278 | } | 278 | } |
279 | 279 | ||
@@ -292,7 +292,7 @@ static void set_links(void) { | |||
292 | exit(1); | 292 | exit(1); |
293 | } | 293 | } |
294 | printf("Configuring symlinks in /usr/local/bin\n"); | 294 | printf("Configuring symlinks in /usr/local/bin\n"); |
295 | 295 | ||
296 | char buf[MAX_BUF]; | 296 | char buf[MAX_BUF]; |
297 | int lineno = 0; | 297 | int lineno = 0; |
298 | while (fgets(buf, MAX_BUF,fp)) { | 298 | while (fgets(buf, MAX_BUF,fp)) { |
@@ -305,18 +305,18 @@ static void set_links(void) { | |||
305 | fprintf(stderr, "Error: invalid line %d in %s\n", lineno, cfgfile); | 305 | fprintf(stderr, "Error: invalid line %d in %s\n", lineno, cfgfile); |
306 | exit(1); | 306 | exit(1); |
307 | } | 307 | } |
308 | 308 | ||
309 | // remove \n | 309 | // remove \n |
310 | char *ptr = strchr(buf, '\n'); | 310 | char *ptr = strchr(buf, '\n'); |
311 | if (ptr) | 311 | if (ptr) |
312 | *ptr = '\0'; | 312 | *ptr = '\0'; |
313 | 313 | ||
314 | // trim spaces | 314 | // trim spaces |
315 | ptr = buf; | 315 | ptr = buf; |
316 | while (*ptr == ' ' || *ptr == '\t') | 316 | while (*ptr == ' ' || *ptr == '\t') |
317 | ptr++; | 317 | ptr++; |
318 | char *start = ptr; | 318 | char *start = ptr; |
319 | 319 | ||
320 | // empty line | 320 | // empty line |
321 | if (*start == '\0') | 321 | if (*start == '\0') |
322 | continue; | 322 | continue; |
@@ -334,7 +334,7 @@ int have_profile(const char *filename) { | |||
334 | // remove .desktop extension | 334 | // remove .desktop extension |
335 | char *f1 = strdup(filename); | 335 | char *f1 = strdup(filename); |
336 | if (!f1) | 336 | if (!f1) |
337 | errExit("strdup"); | 337 | errExit("strdup"); |
338 | f1[strlen(filename) - 8] = '\0'; | 338 | f1[strlen(filename) - 8] = '\0'; |
339 | 339 | ||
340 | // build profile name | 340 | // build profile name |
@@ -358,7 +358,7 @@ static void fix_desktop_files(char *homedir) { | |||
358 | fprintf(stderr, "Error: this option is not supported for root user; please run as a regular user.\n"); | 358 | fprintf(stderr, "Error: this option is not supported for root user; please run as a regular user.\n"); |
359 | exit(1); | 359 | exit(1); |
360 | } | 360 | } |
361 | 361 | ||
362 | // destination | 362 | // destination |
363 | // create ~/.local/share/applications directory if necessary | 363 | // create ~/.local/share/applications directory if necessary |
364 | char *user_apps_dir; | 364 | char *user_apps_dir; |
@@ -373,7 +373,7 @@ static void fix_desktop_files(char *homedir) { | |||
373 | } | 373 | } |
374 | rv = chmod(user_apps_dir, 0700); | 374 | rv = chmod(user_apps_dir, 0700); |
375 | (void) rv; | 375 | (void) rv; |
376 | } | 376 | } |
377 | 377 | ||
378 | // source | 378 | // source |
379 | DIR *dir = opendir("/usr/share/applications"); | 379 | DIR *dir = opendir("/usr/share/applications"); |
@@ -527,7 +527,7 @@ static void fix_desktop_files(char *homedir) { | |||
527 | 527 | ||
528 | int main(int argc, char **argv) { | 528 | int main(int argc, char **argv) { |
529 | int i; | 529 | int i; |
530 | 530 | ||
531 | for (i = 1; i < argc; i++) { | 531 | for (i = 1; i < argc; i++) { |
532 | // default options | 532 | // default options |
533 | if (strcmp(argv[i], "--help") == 0 || | 533 | if (strcmp(argv[i], "--help") == 0 || |
@@ -572,7 +572,7 @@ int main(int argc, char **argv) { | |||
572 | return 1; | 572 | return 1; |
573 | } | 573 | } |
574 | } | 574 | } |
575 | 575 | ||
576 | // set symlinks in /usr/local/bin | 576 | // set symlinks in /usr/local/bin |
577 | if (getuid() != 0) { | 577 | if (getuid() != 0) { |
578 | fprintf(stderr, "Error: cannot set the symbolic links in /usr/local/bin\n"); | 578 | fprintf(stderr, "Error: cannot set the symbolic links in /usr/local/bin\n"); |
@@ -615,11 +615,10 @@ int main(int argc, char **argv) { | |||
615 | printf("%s %d %d %d %d\n", user, getuid(), getgid(), geteuid(), getegid()); | 615 | printf("%s %d %d %d %d\n", user, getuid(), getgid(), geteuid(), getegid()); |
616 | fix_desktop_files(home); | 616 | fix_desktop_files(home); |
617 | } | 617 | } |
618 | 618 | ||
619 | return 0; | 619 | return 0; |
620 | 620 | ||
621 | errexit: | 621 | errexit: |
622 | fprintf(stderr, "Error: cannot detect login user in order to set desktop files in ~/.local/share/applications\n"); | 622 | fprintf(stderr, "Error: cannot detect login user in order to set desktop files in ~/.local/share/applications\n"); |
623 | return 1; | 623 | return 1; |
624 | } | 624 | } |
625 | |||