diff options
author | netblue30 <netblue30@protonmail.com> | 2023-02-05 10:17:26 -0500 |
---|---|---|
committer | netblue30 <netblue30@protonmail.com> | 2023-02-05 10:17:26 -0500 |
commit | 5d0822c52c9a5e631676899e9642911d9143dba8 (patch) | |
tree | dd3f6c7688f208c63aa470f8cf2d399588f067e0 /src | |
parent | private-etc: cleanup tool (diff) | |
download | firejail-5d0822c52c9a5e631676899e9642911d9143dba8.tar.gz firejail-5d0822c52c9a5e631676899e9642911d9143dba8.tar.zst firejail-5d0822c52c9a5e631676899e9642911d9143dba8.zip |
private-etc: big profile changes
Diffstat (limited to 'src')
-rw-r--r-- | src/tools/cleanup_etc.c | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/src/tools/cleanup_etc.c b/src/tools/cleanup_etc.c index 5c926a8c6..3b368b116 100644 --- a/src/tools/cleanup_etc.c +++ b/src/tools/cleanup_etc.c | |||
@@ -91,29 +91,27 @@ static void arr_clean(void) { | |||
91 | arr_x11 = 0; | 91 | arr_x11 = 0; |
92 | } | 92 | } |
93 | 93 | ||
94 | static void arr_print(void) { | 94 | static char *arr_print(void) { |
95 | printf("private-etc "); | 95 | char *last_line = outptr; |
96 | outprintf("private-etc "); | 96 | outprintf("private-etc "); |
97 | 97 | ||
98 | if (arr_games) { | 98 | if (arr_games) |
99 | printf("@games,"); | ||
100 | outprintf("@games,"); | 99 | outprintf("@games,"); |
101 | } | 100 | if (arr_tls_ca) |
102 | if (arr_tls_ca) { | ||
103 | printf("@tls-ca,"); | ||
104 | outprintf("@tls-ca,"); | 101 | outprintf("@tls-ca,"); |
105 | } | 102 | if (arr_x11) |
106 | if (arr_x11) { | ||
107 | printf("@x11,"); | ||
108 | outprintf("@x11,"); | 103 | outprintf("@x11,"); |
109 | } | 104 | |
110 | int i; | 105 | int i; |
111 | for (i = 0; i < arr_cnt; i++) { | 106 | for (i = 0; i < arr_cnt; i++) |
112 | printf("%s,", arr[i]); | ||
113 | outprintf("%s,", arr[i]); | 107 | outprintf("%s,", arr[i]); |
108 | if (*(outptr - 1) == ' ' || *(outptr - 1) == ',') { | ||
109 | outptr--; | ||
110 | *outptr = '\0'; | ||
114 | } | 111 | } |
115 | printf("\n"); | ||
116 | outprintf("\n"); | 112 | outprintf("\n"); |
113 | |||
114 | return last_line; | ||
117 | } | 115 | } |
118 | 116 | ||
119 | static void process_file(const char *fname) { | 117 | static void process_file(const char *fname) { |
@@ -127,6 +125,7 @@ static void process_file(const char *fname) { | |||
127 | 125 | ||
128 | outptr = outbuf; | 126 | outptr = outbuf; |
129 | *outptr = '\0'; | 127 | *outptr = '\0'; |
128 | arr_clean(); | ||
130 | 129 | ||
131 | char line[MAX_BUF]; | 130 | char line[MAX_BUF]; |
132 | char orig_line[MAX_BUF]; | 131 | char orig_line[MAX_BUF]; |
@@ -135,17 +134,14 @@ static void process_file(const char *fname) { | |||
135 | while (fgets(line, MAX_BUF, fp)) { | 134 | while (fgets(line, MAX_BUF, fp)) { |
136 | cnt++; | 135 | cnt++; |
137 | if (strncmp(line, "private-etc ", 12) != 0) { | 136 | if (strncmp(line, "private-etc ", 12) != 0) { |
138 | sprintf(outptr, "%s", line); | 137 | outprintf("%s", line); |
139 | outptr += strlen(outptr); | ||
140 | continue; | 138 | continue; |
141 | } | 139 | } |
140 | strcpy(orig_line,line); | ||
142 | char *ptr = strchr(line, '\n'); | 141 | char *ptr = strchr(line, '\n'); |
143 | if (ptr) | 142 | if (ptr) |
144 | *ptr = '\0'; | 143 | *ptr = '\0'; |
145 | 144 | ||
146 | print = 1; | ||
147 | strcpy(orig_line,line); | ||
148 | |||
149 | ptr = line + 12; | 145 | ptr = line + 12; |
150 | while (*ptr == ' ' || *ptr == '\t') | 146 | while (*ptr == ' ' || *ptr == '\t') |
151 | ptr++; | 147 | ptr++; |
@@ -154,7 +150,7 @@ static void process_file(const char *fname) { | |||
154 | char *ptr2 = ptr; | 150 | char *ptr2 = ptr; |
155 | while (*ptr2 != '\0') { | 151 | while (*ptr2 != '\0') { |
156 | if (*ptr2 == ' ' || *ptr2 == '\t') { | 152 | if (*ptr2 == ' ' || *ptr2 == '\t') { |
157 | fprintf(stderr, "Error: invlid private-etc line %s:%d\n", fname, cnt); | 153 | fprintf(stderr, "Error: invalid private-etc line %s:%d\n", fname, cnt); |
158 | exit(1); | 154 | exit(1); |
159 | } | 155 | } |
160 | ptr2++; | 156 | ptr2++; |
@@ -183,17 +179,21 @@ static void process_file(const char *fname) { | |||
183 | ptr = strtok(NULL, ","); | 179 | ptr = strtok(NULL, ","); |
184 | } | 180 | } |
185 | 181 | ||
186 | printf("\n%s: %s\n%s: ", fname, orig_line, fname); | 182 | char *last_line = arr_print(); |
187 | arr_print(); | 183 | if (strcmp(last_line, orig_line) == 0) { |
188 | arr_clean(); | 184 | fclose(fp); |
185 | return; | ||
186 | } | ||
187 | printf("\n********************\n%s\n\n%s\n%s\n", fname, orig_line, last_line); | ||
188 | print = 1; | ||
189 | } | 189 | } |
190 | 190 | ||
191 | fclose(fp); | 191 | fclose(fp); |
192 | 192 | ||
193 | if (print) { | 193 | if (print) { |
194 | printf("Replace %s file? (Y/N): ", fname); | 194 | // printf("Replace? (Y/N): ", fname); |
195 | fgets(line, MAX_BUF, stdin); | 195 | // fgets(line, MAX_BUF, stdin); |
196 | if (*line == 'y' || *line == 'Y') { | 196 | // if (*line == 'y' || *line == 'Y') { |
197 | fp = fopen(fname, "w"); | 197 | fp = fopen(fname, "w"); |
198 | if (!fp) { | 198 | if (!fp) { |
199 | fprintf(stderr, "Error: cannot open profile file\n"); | 199 | fprintf(stderr, "Error: cannot open profile file\n"); |
@@ -201,7 +201,7 @@ static void process_file(const char *fname) { | |||
201 | } | 201 | } |
202 | fprintf(fp, "%s", outbuf); | 202 | fprintf(fp, "%s", outbuf); |
203 | fclose(fp); | 203 | fclose(fp); |
204 | } | 204 | // } |
205 | } | 205 | } |
206 | } | 206 | } |
207 | 207 | ||