Mercurial > trustbridge
comparison cinst/mozilla.c @ 975:b3695a3399de
(issue86) Install into default directories on Linux
If the mozilla process is now started as root it will
try to write into the default directories for NSS Shared
and mozilla / thunderbird profiles.
Cinst will now start the mozilla process once as root.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Fri, 29 Aug 2014 12:59:44 +0200 |
parents | 56ca8f2fd433 |
children | 1743895b39b8 |
comparison
equal
deleted
inserted
replaced
974:cbd32175c56c | 975:b3695a3399de |
---|---|
24 * the databases. | 24 * the databases. |
25 * | 25 * |
26 * This tool tries to find all NSS databases the user has | 26 * This tool tries to find all NSS databases the user has |
27 * access to and to execute the instructions on all of them. | 27 * access to and to execute the instructions on all of them. |
28 * | 28 * |
29 * If the tool is executed with a UID of 0 or with admin privileges under | |
30 * windows it will not look into the user directories but instead try | |
31 * to write the system wide defaults. | |
32 * | |
29 * If there are other processes accessing the databases the caller | 33 * If there are other processes accessing the databases the caller |
30 * has to ensure that those are terminated before this process is | 34 * has to ensure that those are terminated before this process is |
31 * executed. | 35 * executed. |
32 * | 36 * |
33 * If the same certificate is marked to be installed and to be removed | 37 * If the same certificate is marked to be installed and to be removed |
42 * with the profile name that it modified. | 46 * with the profile name that it modified. |
43 * | 47 * |
44 */ | 48 */ |
45 | 49 |
46 /** | 50 /** |
47 * @brief Needs to eb defined to get strnlen() | 51 * @brief Needs to be defined to get strnlen() |
48 */ | 52 */ |
49 #define _POSIX_C_SOURCE 200809L | 53 #define _POSIX_C_SOURCE 200809L |
50 | 54 |
51 /* REMOVEME: */ | 55 /* REMOVEME: */ |
52 #include <unistd.h> | 56 #include <unistd.h> |
69 #include "certhelp.h" | 73 #include "certhelp.h" |
70 #include "errorcodes.h" | 74 #include "errorcodes.h" |
71 #include "portpath.h" | 75 #include "portpath.h" |
72 #include "strhelp.h" | 76 #include "strhelp.h" |
73 #include "nss-secitemlist.h" | 77 #include "nss-secitemlist.h" |
78 #include "util.h" | |
74 | 79 |
75 #ifndef _WIN32 | 80 #ifndef _WIN32 |
76 #define CONFDIRS ".mozilla", ".thunderbird" | 81 #define CONFDIRS ".mozilla", ".thunderbird" |
82 /* Default installation directory of ubuntu 14.4 is respected */ | |
83 #define MOZILLA_DEFAULTS "/etc/thunderbird", "/etc/firefox" | |
77 #define NSSSHARED ".pki/nssdb" | 84 #define NSSSHARED ".pki/nssdb" |
85 #define NSSSHARED_GLOBAL "/etc/pki/nssdb" | |
78 #define TARGET_LINUX 1 | 86 #define TARGET_LINUX 1 |
79 #else | 87 #else |
88 #define MOZILLA_DEFAULTS 0 | |
80 #define CONFDIRS "Mozilla", "Thunderbird" | 89 #define CONFDIRS "Mozilla", "Thunderbird" |
81 #define NSSSHARED "" | 90 #define NSSSHARED "" |
82 #define TARGET_LINUX 0 | 91 #define TARGET_LINUX 0 |
83 #endif | 92 #endif |
84 | 93 |
197 if (str_equal(key, "Path")) | 206 if (str_equal(key, "Path")) |
198 { | 207 { |
199 if (relative_path) | 208 if (relative_path) |
200 xasprintf(&path, "%s/%s", inifile_dirname, value); | 209 xasprintf(&path, "%s/%s", inifile_dirname, value); |
201 else | 210 else |
202 xasprintf(&path, "%s", value); /* FIXME: LOOKS STUPID! */ | 211 xasprintf(&path, "%s", value); |
203 if ((fqpath = port_realpath(path)) != NULL) | 212 if ((fqpath = port_realpath(path)) != NULL) |
204 { | 213 { |
205 DEBUGPRINTF("Found profile path: '%s'\n", fqpath); | 214 DEBUGPRINTF("Found profile path: '%s'\n", fqpath); |
206 strv_append(&dirs, fqpath, strlen(fqpath)); | 215 strv_append(&dirs, fqpath, strlen(fqpath)); |
207 free (fqpath); | 216 free (fqpath); |
292 } | 301 } |
293 return inis; | 302 return inis; |
294 } | 303 } |
295 | 304 |
296 /** | 305 /** |
306 * @brief Collect the default profile directories for mozilla software | |
307 * | |
308 * If the default directory is found but not the profiles subdirectory | |
309 * this will create the profiles subdirectory. | |
310 * | |
311 * @return NULL terminated array of strings containing the absolute path | |
312 * to the default profile directories. Needs to be freed by the caller. | |
313 */ | |
314 static char** | |
315 get_default_profile_dirs() | |
316 { | |
317 char **retval = NULL; | |
318 | |
319 const char *confdirs[] = { MOZILLA_DEFAULTS, NULL }; | |
320 | |
321 for (int i=0; confdirs[i] != NULL; i++) | |
322 { | |
323 char * realpath = port_realpath(confdirs[i]); | |
324 char * profile_dir = NULL; | |
325 if (realpath == NULL) | |
326 { | |
327 DEBUGPRINTF ("Did not find directory: '%s'\n", confdirs[i]); | |
328 continue; | |
329 } | |
330 xasprintf(&profile_dir, "%s/profile", realpath); | |
331 if (port_isdir(profile_dir)) | |
332 { | |
333 DEBUGPRINTF("Found default directory: '%s'\n", profile_dir); | |
334 /* All is well */ | |
335 strv_append (&retval, profile_dir, strlen(profile_dir)); | |
336 xfree(profile_dir); | |
337 profile_dir = NULL; | |
338 continue; | |
339 } | |
340 else | |
341 { | |
342 /* Create the directory */ | |
343 if (port_fileexits(profile_dir)) | |
344 { | |
345 DEBUGPRINTF ("Path: '%s' is not a directory but it exists. Skipping.\n", | |
346 profile_dir); | |
347 xfree(profile_dir); | |
348 profile_dir = NULL; | |
349 continue; | |
350 } | |
351 else | |
352 { | |
353 /* Lets create it */ | |
354 if (!port_mkdir(profile_dir)) | |
355 { | |
356 ERRORPRINTF ("Failed to create directory: '%s'\n", profile_dir); | |
357 xfree(profile_dir); | |
358 profile_dir = NULL; | |
359 continue; | |
360 } | |
361 strv_append (&retval, profile_dir, strlen(profile_dir)); | |
362 xfree(profile_dir); | |
363 profile_dir = NULL; | |
364 } | |
365 } | |
366 } | |
367 return retval; | |
368 } | |
369 | |
370 /** | |
297 * @brief Collect all mozilla profile directories of current user. | 371 * @brief Collect all mozilla profile directories of current user. |
298 * @return NULL terminated array of strings containing the absolute | 372 * @return NULL terminated array of strings containing the absolute |
299 * path of the profile directories. The array needs to be freed by the | 373 * path of the profile directories. The array needs to be freed by the |
300 * caller. | 374 * caller. |
301 */ | 375 */ |
302 static char** | 376 static char** |
303 get_all_nssdb_dirs() | 377 get_all_nssdb_dirs() |
304 { | 378 { |
305 char **mozinis, **pdirs; | 379 char **mozinis, **pdirs; |
306 char **alldirs = NULL; | 380 char **alldirs = NULL; |
381 | |
382 if (is_elevated()) | |
383 { | |
384 #ifndef _WIN32 | |
385 /* NSS Shared db does not exist under windows. */ | |
386 strv_append(&alldirs, NSSSHARED_GLOBAL, strlen(NSSSHARED_GLOBAL)); | |
387 #endif | |
388 pdirs = get_default_profile_dirs(); | |
389 if (pdirs != NULL) | |
390 { | |
391 for (int i=0; pdirs[i] != NULL; i++) | |
392 { | |
393 strv_append(&alldirs, pdirs[i], strlen(pdirs[i])); | |
394 } | |
395 strv_free(pdirs); | |
396 } | |
397 return alldirs; | |
398 } | |
307 /* Search Mozilla/Firefox/Thunderbird profiles */ | 399 /* Search Mozilla/Firefox/Thunderbird profiles */ |
308 if ((mozinis = get_profile_inis()) != NULL) | 400 if ((mozinis = get_profile_inis()) != NULL) |
309 { | 401 { |
310 for (int i=0; mozinis[i] != NULL; i++) | 402 for (int i=0; mozinis[i] != NULL; i++) |
311 { | 403 { |