diff options
Diffstat (limited to 'src/firecfg')
-rw-r--r-- | src/firecfg/main.c | 55 |
1 files changed, 52 insertions, 3 deletions
diff --git a/src/firecfg/main.c b/src/firecfg/main.c index c8af9d03a..af5ebef98 100644 --- a/src/firecfg/main.c +++ b/src/firecfg/main.c | |||
@@ -34,6 +34,7 @@ | |||
34 | 34 | ||
35 | #include "../include/common.h" | 35 | #include "../include/common.h" |
36 | static int arg_debug = 0; | 36 | static int arg_debug = 0; |
37 | #define MAX_BUF 1024 | ||
37 | 38 | ||
38 | static void usage(void) { | 39 | static void usage(void) { |
39 | printf("firecfg - version %s\n\n", VERSION); | 40 | printf("firecfg - version %s\n\n", VERSION); |
@@ -46,6 +47,7 @@ static void usage(void) { | |||
46 | printf("Usage: firecfg [OPTIONS]\n\n"); | 47 | printf("Usage: firecfg [OPTIONS]\n\n"); |
47 | printf(" --clean - remove all firejail symbolic links.\n\n"); | 48 | printf(" --clean - remove all firejail symbolic links.\n\n"); |
48 | printf(" --debug - print debug messages.\n\n"); | 49 | printf(" --debug - print debug messages.\n\n"); |
50 | printf(" --fix-sound - create ~/.config/pulse/client.conf file.\n\n"); | ||
49 | printf(" --help, -? - this help screen.\n\n"); | 51 | printf(" --help, -? - this help screen.\n\n"); |
50 | printf(" --list - list all firejail symbolic links.\n\n"); | 52 | printf(" --list - list all firejail symbolic links.\n\n"); |
51 | printf(" --version - print program version and exit.\n\n"); | 53 | printf(" --version - print program version and exit.\n\n"); |
@@ -67,6 +69,49 @@ static void usage(void) { | |||
67 | printf("Homepage: http://firejail.wordpress.com\n\n"); | 69 | printf("Homepage: http://firejail.wordpress.com\n\n"); |
68 | } | 70 | } |
69 | 71 | ||
72 | static void sound(void) { | ||
73 | struct passwd *pw = getpwuid(getuid()); | ||
74 | if (!pw) { | ||
75 | goto errexit; | ||
76 | } | ||
77 | char *home = pw->pw_dir; | ||
78 | if (!home) { | ||
79 | goto errexit; | ||
80 | } | ||
81 | |||
82 | // the input file is /etc/pulse/client.conf | ||
83 | FILE *fpin = fopen("/etc/pulse/client.conf", "r"); | ||
84 | if (!fpin) { | ||
85 | fprintf(stderr, "PulseAudio is not available on this platform, there is nothing to fix...\n"); | ||
86 | return; | ||
87 | } | ||
88 | |||
89 | // the dest is PulseAudio user config file | ||
90 | char *fname; | ||
91 | if (asprintf(&fname, "%s/.config/pulse/client.conf", home) == -1) | ||
92 | errExit("asprintf"); | ||
93 | FILE *fpout = fopen(fname, "w"); | ||
94 | free(fname); | ||
95 | if (!fpout) | ||
96 | goto errexit; | ||
97 | |||
98 | // copy default config | ||
99 | char buf[MAX_BUF]; | ||
100 | while (fgets(buf, MAX_BUF, fpin)) | ||
101 | fputs(buf, fpout); | ||
102 | |||
103 | // disable shm | ||
104 | fprintf(fpout, "\nenable-shm = no\n"); | ||
105 | fclose(fpin); | ||
106 | fclose(fpout); | ||
107 | printf("PulseAudio configured, please logout and login back again\n"); | ||
108 | return; | ||
109 | |||
110 | errexit: | ||
111 | fprintf(stderr, "Error: cannot configure sound file\n"); | ||
112 | exit(1); | ||
113 | } | ||
114 | |||
70 | // return 1 if the program is found | 115 | // return 1 if the program is found |
71 | static int find(const char *program, const char *directory) { | 116 | static int find(const char *program, const char *directory) { |
72 | int retval = 0; | 117 | int retval = 0; |
@@ -231,7 +276,6 @@ static void set_file(const char *name, const char *firejail_exec) { | |||
231 | free(fname); | 276 | free(fname); |
232 | } | 277 | } |
233 | 278 | ||
234 | #define MAX_BUF 1024 | ||
235 | static void set_links(void) { | 279 | static void set_links(void) { |
236 | char *cfgfile; | 280 | char *cfgfile; |
237 | if (asprintf(&cfgfile, "%s/firejail/firecfg.config", LIBDIR) == -1) | 281 | if (asprintf(&cfgfile, "%s/firejail/firecfg.config", LIBDIR) == -1) |
@@ -504,6 +548,10 @@ int main(int argc, char **argv) { | |||
504 | list(); | 548 | list(); |
505 | return 0; | 549 | return 0; |
506 | } | 550 | } |
551 | else if (strcmp(argv[i], "--fix-sound") == 0) { | ||
552 | sound(); | ||
553 | return 0; | ||
554 | } | ||
507 | else { | 555 | else { |
508 | fprintf(stderr, "Error: invalid command line option\n"); | 556 | fprintf(stderr, "Error: invalid command line option\n"); |
509 | usage(); | 557 | usage(); |
@@ -513,8 +561,9 @@ int main(int argc, char **argv) { | |||
513 | 561 | ||
514 | // set symlinks in /usr/local/bin | 562 | // set symlinks in /usr/local/bin |
515 | if (getuid() != 0) { | 563 | if (getuid() != 0) { |
516 | fprintf(stderr, "Error: you need to be root to run this command\n"); | 564 | fprintf(stderr, "Error: cannot set the symbolic links in /usr/local/bin\n"); |
517 | exit(1); | 565 | fprintf(stderr, "The proper way to run this command is \"sudo firecfg\".\n"); |
566 | return 1; | ||
518 | } | 567 | } |
519 | set_links(); | 568 | set_links(); |
520 | 569 | ||