Mercurial > trustbridge
annotate cinst/mozilla.c @ 1010:1c1964c27b39 runafterinstall
(issue54) commit work in progress on start after installation
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Tue, 02 Sep 2014 14:25:40 +0200 |
parents | 1cd1bfe82fc2 |
children | a80abef948fa |
rev | line source |
---|---|
404 | 1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU GPL (v>=2) | |
5 * and comes with ABSOLUTELY NO WARRANTY! | |
6 * See LICENSE.txt for details. | |
7 */ | |
121
4bb5f295987b
Fix doxygen documentation.
Sascha Wilde <wilde@intevation.de>
parents:
119
diff
changeset
|
8 /** |
4bb5f295987b
Fix doxygen documentation.
Sascha Wilde <wilde@intevation.de>
parents:
119
diff
changeset
|
9 * @file |
4bb5f295987b
Fix doxygen documentation.
Sascha Wilde <wilde@intevation.de>
parents:
119
diff
changeset
|
10 * @brief Mozilla installation process |
99
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
11 * |
315
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
12 * Reads from a file given on command line or stdin a list of |
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
13 * instructions in the form: |
99
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
14 * |
238
dd417a2ff9cd
Specifiy unspecified behavior if there is an install and
Andre Heinecke <aheinecke@intevation.de>
parents:
235
diff
changeset
|
15 * I:<base64 DER econded certificate> |
dd417a2ff9cd
Specifiy unspecified behavior if there is an install and
Andre Heinecke <aheinecke@intevation.de>
parents:
235
diff
changeset
|
16 * R:<base64 DER econded certificate> |
99
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
17 * ... |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
18 * |
238
dd417a2ff9cd
Specifiy unspecified behavior if there is an install and
Andre Heinecke <aheinecke@intevation.de>
parents:
235
diff
changeset
|
19 * With one instruction per line. the maximum size of an input |
dd417a2ff9cd
Specifiy unspecified behavior if there is an install and
Andre Heinecke <aheinecke@intevation.de>
parents:
235
diff
changeset
|
20 * line is 9999 characters (including the \r\n) at the end of the line. |
99
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
21 * |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
22 * Certificates marked with I: will be installed and the ones |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
23 * marked with R: will be searched and if available removed from |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
24 * the databases. |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
25 * |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
26 * This tool tries to find all NSS databases the user has |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
27 * access to and to execute the instructions on all of them. |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
28 * |
975
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
29 * If the tool is executed with a UID of 0 or with admin privileges under |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
30 * windows it will not look into the user directories but instead try |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
31 * to write the system wide defaults. |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
32 * |
99
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
33 * If there are other processes accessing the databases the caller |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
34 * has to ensure that those are terminated before this process is |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
35 * executed. |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
36 * |
238
dd417a2ff9cd
Specifiy unspecified behavior if there is an install and
Andre Heinecke <aheinecke@intevation.de>
parents:
235
diff
changeset
|
37 * If the same certificate is marked to be installed and to be removed |
dd417a2ff9cd
Specifiy unspecified behavior if there is an install and
Andre Heinecke <aheinecke@intevation.de>
parents:
235
diff
changeset
|
38 * in one call the behavior is undefined. This should be avoided and |
dd417a2ff9cd
Specifiy unspecified behavior if there is an install and
Andre Heinecke <aheinecke@intevation.de>
parents:
235
diff
changeset
|
39 * may lead to errors. |
dd417a2ff9cd
Specifiy unspecified behavior if there is an install and
Andre Heinecke <aheinecke@intevation.de>
parents:
235
diff
changeset
|
40 * |
99
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
41 * Returns 0 on success (Even when no stores where found) an error value |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
42 * as defined in errorcodes.h otherwise. |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
43 * |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
44 * Success messages are written to stdout. Errors to stderr. For logging |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
45 * purposes each installation / removal of a certificate will be reported |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
46 * with the profile name that it modified. |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
47 * |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
48 */ |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
49 |
235
0c4d65a7cd14
Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents:
232
diff
changeset
|
50 /** |
975
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
51 * @brief Needs to be defined to get strnlen() |
235
0c4d65a7cd14
Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents:
232
diff
changeset
|
52 */ |
0c4d65a7cd14
Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents:
232
diff
changeset
|
53 #define _POSIX_C_SOURCE 200809L |
0c4d65a7cd14
Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents:
232
diff
changeset
|
54 |
0c4d65a7cd14
Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents:
232
diff
changeset
|
55 /* REMOVEME: */ |
0c4d65a7cd14
Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents:
232
diff
changeset
|
56 #include <unistd.h> |
0c4d65a7cd14
Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents:
232
diff
changeset
|
57 |
269
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
58 #include <cert.h> |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
59 #include <certdb.h> |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
60 #include <certt.h> |
173
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
61 #include <dirent.h> |
224
689b94dd89a9
Wrote FindNSS to build against nss without pkg-config support (Windows).
Sascha Wilde <wilde@intevation.de>
parents:
223
diff
changeset
|
62 #include <nss.h> |
689b94dd89a9
Wrote FindNSS to build against nss without pkg-config support (Windows).
Sascha Wilde <wilde@intevation.de>
parents:
223
diff
changeset
|
63 #include <pk11pub.h> |
119
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
64 #include <stdbool.h> |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
65 #include <stdio.h> |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
66 #include <stdlib.h> |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
67 #include <string.h> |
173
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
68 #include <sys/types.h> |
989
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
69 #include <sys/stat.h> |
119
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
70 |
230
92b1e5ed2d5f
Cleanup and documentation in debugging macros.
Sascha Wilde <wilde@intevation.de>
parents:
229
diff
changeset
|
71 #define DEBUGPREFIX "MOZ-" |
252
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
246
diff
changeset
|
72 #include "logging.h" |
230
92b1e5ed2d5f
Cleanup and documentation in debugging macros.
Sascha Wilde <wilde@intevation.de>
parents:
229
diff
changeset
|
73 |
261
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
74 #include "certhelp.h" |
226
d7788db3bdde
Make locale includes distinguishable from system includes.
Sascha Wilde <wilde@intevation.de>
parents:
224
diff
changeset
|
75 #include "errorcodes.h" |
d7788db3bdde
Make locale includes distinguishable from system includes.
Sascha Wilde <wilde@intevation.de>
parents:
224
diff
changeset
|
76 #include "portpath.h" |
d7788db3bdde
Make locale includes distinguishable from system includes.
Sascha Wilde <wilde@intevation.de>
parents:
224
diff
changeset
|
77 #include "strhelp.h" |
244
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
78 #include "nss-secitemlist.h" |
975
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
79 #include "util.h" |
228
19de529ce7fb
Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents:
227
diff
changeset
|
80 |
113
02ad0922c01f
Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents:
110
diff
changeset
|
81 #ifndef _WIN32 |
197
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
82 #define CONFDIRS ".mozilla", ".thunderbird" |
975
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
83 /* Default installation directory of ubuntu 14.4 is respected */ |
989
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
84 #define MOZILLA_DEFAULTS "/usr/lib/thunderbird/defaults", "/usr/lib/firefox/browser/defaults" |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
85 #define MOZILLA_DBNAMES "cert8.db", "key3.db", "secmod.db" |
308
ab69d268b5c8
Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents:
284
diff
changeset
|
86 #define NSSSHARED ".pki/nssdb" |
988
ca89cf228a5b
(issue86) Write nss shared db defaults into /etc/skel
Andre Heinecke <andre.heinecke@intevation.de>
parents:
986
diff
changeset
|
87 #define NSSSHARED_GLOBAL "/etc/skel/.pki/nssdb" |
223
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
88 #define TARGET_LINUX 1 |
985
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
89 #define DIRSEP "/" |
113
02ad0922c01f
Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents:
110
diff
changeset
|
90 #else |
985
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
91 #define MOZILLA_DEFAULTS "Mozilla Firefox\\browser\\defaults", "Mozilla Thunderbird\\defaults" |
989
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
92 #define MOZILLA_DBNAMES NULL |
197
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
93 #define CONFDIRS "Mozilla", "Thunderbird" |
311 | 94 #define NSSSHARED "" |
989
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
95 #define TARGET_LINUX NULL |
985
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
96 #define DIRSEP "\\" |
113
02ad0922c01f
Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents:
110
diff
changeset
|
97 #endif |
02ad0922c01f
Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents:
110
diff
changeset
|
98 |
229 | 99 /** |
100 * @brief Length of string buffers used | |
101 * | |
102 * The maximal length of input is defined as 9999 (+ terminating \0). | |
103 * We use it for other other input puffers besides the IPC input, too. | |
104 * (One size fits all). | |
105 */ | |
106 #define LINEBUFLEN 10000 | |
147
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
107 |
909
18e3ad073b38
Use strtok_r/strtok_s instead of strtok.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
905
diff
changeset
|
108 #ifdef _WIN32 |
18e3ad073b38
Use strtok_r/strtok_s instead of strtok.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
905
diff
changeset
|
109 #define STRTOK_R strtok_s |
18e3ad073b38
Use strtok_r/strtok_s instead of strtok.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
905
diff
changeset
|
110 #else |
18e3ad073b38
Use strtok_r/strtok_s instead of strtok.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
905
diff
changeset
|
111 #define STRTOK_R strtok_r |
18e3ad073b38
Use strtok_r/strtok_s instead of strtok.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
905
diff
changeset
|
112 #endif |
18e3ad073b38
Use strtok_r/strtok_s instead of strtok.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
905
diff
changeset
|
113 |
119
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
114 /** |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
115 * @brief Global Return Code |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
116 * |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
117 * This will be retuned by the programm and might be set to an |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
118 * error code on fatal errors and to and warning code on non-fatal |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
119 * errors. In case of mor than one warning the warning codes will be |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
120 * ORed together. |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
121 */ |
317
46fd11699646
Renamed exit code from return_code to exit_code.
Sascha Wilde <wilde@intevation.de>
parents:
315
diff
changeset
|
122 int exit_code = 0; |
44
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
123 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
124 /** |
194
d4e97c9b199f
Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents:
181
diff
changeset
|
125 * @brief Return configuration base directory. |
d4e97c9b199f
Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents:
181
diff
changeset
|
126 * @returns A pointer to a string containing the path to the base |
d4e97c9b199f
Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents:
181
diff
changeset
|
127 * directory holding the configuration directories for e.g. mozilla |
d4e97c9b199f
Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents:
181
diff
changeset
|
128 * and thunderbird. |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
129 */ |
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
130 static char * |
194
d4e97c9b199f
Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents:
181
diff
changeset
|
131 get_conf_basedir() |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
132 { |
194
d4e97c9b199f
Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents:
181
diff
changeset
|
133 char *cdir, *envvar; |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
134 |
223
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
135 if (TARGET_LINUX) |
194
d4e97c9b199f
Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents:
181
diff
changeset
|
136 envvar = "HOME" ; |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
137 else |
194
d4e97c9b199f
Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents:
181
diff
changeset
|
138 envvar = "APPDATA"; |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
139 |
194
d4e97c9b199f
Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents:
181
diff
changeset
|
140 if ((cdir = getenv(envvar)) != NULL) |
d4e97c9b199f
Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents:
181
diff
changeset
|
141 return cdir; |
d4e97c9b199f
Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents:
181
diff
changeset
|
142 else |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
143 { |
228
19de529ce7fb
Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents:
227
diff
changeset
|
144 DEBUGPRINTF("FATAL! No %s in environment.\n", envvar); |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
145 exit(ERR_MOZ_HOMELESS); |
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
146 } |
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
147 } |
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
148 |
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
149 /** |
119
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
150 * @brief Get a list of all mozilla profile directories |
44
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
151 * |
232 | 152 * Parse the profiles.ini and extract all profile paths from that. |
153 * The expected data is in the form: | |
154 * | |
155 * [Profile99] | |
156 * IsRelative=1 | |
157 * Path=Example/fooo.bar | |
158 * | |
159 * or | |
160 * [Profile0] | |
161 * IsRelative=0 | |
162 * Path=c:\foo\bar\baz | |
163 * | |
164 * Mozilla also accepts the ini file on Windows even if it is UTF-16 | |
165 * encoded but never writes UTF-16 on its own. So currently we ignore | |
166 * this special case. | |
44
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
167 * |
121
4bb5f295987b
Fix doxygen documentation.
Sascha Wilde <wilde@intevation.de>
parents:
119
diff
changeset
|
168 * @param[in] inifile_name path of the profile.ini to read. |
44
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
169 * @return NULL terminated array of strings containing containing the |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
170 * absolute path of the profile directories. The array needs to |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
171 * be freed by the caller. |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
172 */ |
119
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
173 static char ** |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
174 get_profile_dirs (char *inifile_name) |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
175 { |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
176 char **dirs = NULL; |
147
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
177 char *inifile_dirname; |
119
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
178 FILE *inifile; |
147
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
179 char line[LINEBUFLEN]; |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
180 char *key; |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
181 char *value; |
320
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
182 char *path = NULL; |
147
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
183 char *fqpath; |
119
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
184 bool inprofile = false; |
147
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
185 bool relative_path = false; |
909
18e3ad073b38
Use strtok_r/strtok_s instead of strtok.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
905
diff
changeset
|
186 char *saveptr; |
44
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
187 |
119
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
188 if ((inifile = fopen(inifile_name, "r")) != NULL) |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
189 { |
228
19de529ce7fb
Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents:
227
diff
changeset
|
190 DEBUGPRINTF("Searching for profile paths in: '%s'\n", inifile_name); |
175
6fa0e12ae1d2
Added more debug output.
Sascha Wilde <wilde@intevation.de>
parents:
174
diff
changeset
|
191 |
147
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
192 inifile_dirname = port_dirname(inifile_name); |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
193 while (fgets(line, LINEBUFLEN, inifile) != NULL) |
119
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
194 { |
147
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
195 /* Determine if we are in an profile section */ |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
196 if (str_starts_with(line, "[Profile")) |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
197 { |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
198 relative_path = false; |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
199 inprofile = true; |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
200 } |
119
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
201 else if (line[0] == '[') |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
202 inprofile = false; |
147
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
203 |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
204 /* If we are in a profile parse path related stuff */ |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
205 if (inprofile) |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
206 { |
909
18e3ad073b38
Use strtok_r/strtok_s instead of strtok.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
905
diff
changeset
|
207 saveptr = NULL; |
18e3ad073b38
Use strtok_r/strtok_s instead of strtok.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
905
diff
changeset
|
208 key = STRTOK_R(line, "=", &saveptr); |
18e3ad073b38
Use strtok_r/strtok_s instead of strtok.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
905
diff
changeset
|
209 value = STRTOK_R(NULL, "=", &saveptr); |
147
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
210 str_trim(&value); |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
211 if (str_equal(key, "Path")) |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
212 { |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
213 if (relative_path) |
320
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
214 xasprintf(&path, "%s/%s", inifile_dirname, value); |
147
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
215 else |
975
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
216 xasprintf(&path, "%s", value); |
147
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
217 if ((fqpath = port_realpath(path)) != NULL) |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
218 { |
228
19de529ce7fb
Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents:
227
diff
changeset
|
219 DEBUGPRINTF("Found profile path: '%s'\n", fqpath); |
147
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
220 strv_append(&dirs, fqpath, strlen(fqpath)); |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
221 free (fqpath); |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
222 } |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
223 else |
175
6fa0e12ae1d2
Added more debug output.
Sascha Wilde <wilde@intevation.de>
parents:
174
diff
changeset
|
224 { |
228
19de529ce7fb
Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents:
227
diff
changeset
|
225 DEBUGPRINTF("WARN! Non existent profile path: '%s'\n", path); |
317
46fd11699646
Renamed exit code from return_code to exit_code.
Sascha Wilde <wilde@intevation.de>
parents:
315
diff
changeset
|
226 exit_code |= WARN_MOZ_PROFILE_DOES_NOT_EXIST; |
175
6fa0e12ae1d2
Added more debug output.
Sascha Wilde <wilde@intevation.de>
parents:
174
diff
changeset
|
227 } |
320
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
228 free(path); |
147
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
229 } |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
230 else if (str_equal(key, "IsRelative") && |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
231 str_starts_with(value, "1")) |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
232 relative_path = true; |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
233 } |
119
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
234 } |
179
8fafd0fc2173
get_profile_dirs(): close filedescriptor again. (found by cppcheck)
Bernhard Reiter <bernhard@intevation.de>
parents:
177
diff
changeset
|
235 fclose(inifile); |
119
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
236 } |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
237 else |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
238 { |
228
19de529ce7fb
Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents:
227
diff
changeset
|
239 DEBUGPRINTF("WARN! Could not open ini file: '%s'\n", inifile_name); |
317
46fd11699646
Renamed exit code from return_code to exit_code.
Sascha Wilde <wilde@intevation.de>
parents:
315
diff
changeset
|
240 exit_code |= WARN_MOZ_FAILED_TO_OPEN_INI; |
119
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
241 } |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
242 return dirs; |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
243 } |
44
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
244 |
173
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
245 /** |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
246 * @brief Search for mozilla profiles.ini files |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
247 * |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
248 * Use well known paths and heuristics to find the current users |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
249 * profiles.ini files on GNU/Linux and Windows systems. |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
250 * |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
251 * @return NULL terminated array of strings containing the absolute |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
252 * path of the profiles.ini files. The array needs to be freed by the |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
253 * caller. |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
254 */ |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
255 static char ** |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
256 get_profile_inis () |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
257 { |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
258 char **inis = NULL; |
320
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
259 char *mozpath, *fqpath, *subpath, *ppath; |
173
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
260 DIR *mozdir; |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
261 struct dirent *mozdirent; |
194
d4e97c9b199f
Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents:
181
diff
changeset
|
262 char *confbase = get_conf_basedir(); |
197
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
263 const char *confdirs[] = { CONFDIRS, NULL }; |
173
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
264 |
197
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
265 for (int i=0; confdirs[i] != NULL; i++) |
173
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
266 { |
320
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
267 xasprintf(&mozpath,"%s/%s", confbase, confdirs[i]); |
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
268 if ((mozdir = opendir(mozpath)) != NULL) |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
269 { |
197
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
270 while ((mozdirent = readdir(mozdir)) != NULL) |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
271 { |
320
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
272 xasprintf(&subpath, "%s/%s/%s", |
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
273 confbase, |
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
274 confdirs[i], |
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
275 mozdirent->d_name); |
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
276 if (port_isdir(subpath) |
197
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
277 && (strcmp(mozdirent->d_name, "..") != 0)) |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
278 { |
320
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
279 xasprintf(&ppath, "%s/%s/%s/%s", |
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
280 confbase, |
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
281 confdirs[i], |
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
282 mozdirent->d_name, |
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
283 "profiles.ini"); |
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
284 DEBUGPRINTF("checking for %s...\n", ppath); |
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
285 if ((fqpath = port_realpath(ppath)) != NULL) |
197
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
286 { |
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
287 strv_append(&inis, fqpath, strlen(fqpath)); |
228
19de529ce7fb
Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents:
227
diff
changeset
|
288 DEBUGPRINTF("Found mozilla ini file: '%s'\n", fqpath); |
197
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
289 free(fqpath); |
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
290 } |
320
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
291 free(ppath); |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
292 } |
320
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
293 free(subpath); |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
294 } |
197
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
295 closedir(mozdir); |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
296 } |
197
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
297 else |
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
298 { |
228
19de529ce7fb
Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents:
227
diff
changeset
|
299 DEBUGPRINTF("Could not open %s/%s\n", confbase, confdirs[i]); |
197
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
300 } |
320
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
301 free(mozpath); |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
302 } |
197
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
303 if (inis == NULL) |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
304 { |
228
19de529ce7fb
Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents:
227
diff
changeset
|
305 DEBUGPRINTF("No ini files found - will do nothing!\n"); |
173
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
306 } |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
307 return inis; |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
308 } |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
309 |
989
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
310 |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
311 /** @brief make the default nss databases readable. |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
312 * |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
313 * This uses the static paths definied in this code to ensure |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
314 * that only the defaults are touched. |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
315 * |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
316 */ |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
317 #ifndef WIN32 |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
318 static void |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
319 make_defaults_readable() |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
320 { |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
321 const char *confdirs[] = { MOZILLA_DEFAULTS, NULL }; |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
322 const char *filenames[] = { MOZILLA_DBNAMES, NULL }; |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
323 |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
324 mode_t access_mask = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
325 |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
326 for (int i=0; confdirs[i] != NULL; i++) |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
327 { |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
328 for (int j=0; filenames[j] != NULL; j++) |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
329 { |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
330 char *realpath = NULL, |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
331 *path = NULL; |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
332 xasprintf (&path, "%s/profile/%s", confdirs[i], filenames[j]); |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
333 realpath = port_realpath(path); |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
334 xfree(path); |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
335 if (!realpath) |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
336 { |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
337 syslog_error_printf("Failed to find %s \n", realpath); |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
338 continue; |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
339 } |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
340 if (chmod(realpath, access_mask)) |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
341 { |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
342 syslog_error_printf("Failed to set access_mask on file.\n"); |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
343 } |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
344 xfree (realpath); |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
345 } |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
346 } |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
347 } |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
348 #endif |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
349 |
223
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
350 /** |
975
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
351 * @brief Collect the default profile directories for mozilla software |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
352 * |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
353 * If the default directory is found but not the profiles subdirectory |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
354 * this will create the profiles subdirectory. |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
355 * |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
356 * @return NULL terminated array of strings containing the absolute path |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
357 * to the default profile directories. Needs to be freed by the caller. |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
358 */ |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
359 static char** |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
360 get_default_profile_dirs() |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
361 { |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
362 char **retval = NULL; |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
363 |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
364 const char *confdirs[] = { MOZILLA_DEFAULTS, NULL }; |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
365 |
985
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
366 #ifdef _WIN32 |
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
367 char *program_files = get_program_files_folder(); |
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
368 if (!program_files) |
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
369 { |
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
370 ERRORPRINTF ("Failed to look up program files folder.\n"); |
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
371 return NULL; |
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
372 } |
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
373 #endif |
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
374 |
975
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
375 for (int i=0; confdirs[i] != NULL; i++) |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
376 { |
985
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
377 char *realpath = NULL, |
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
378 *profile_dir = NULL; |
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
379 #ifndef _WIN32 |
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
380 realpath = port_realpath(confdirs[i]); |
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
381 #else |
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
382 /* As on linux we only respect the default installation directory |
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
383 mozilla firefox and thunderbird change their registry key with |
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
384 each version as the key includes the version number. It would |
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
385 be error prone to search the system for every instance. So we |
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
386 only check the default installation directories. */ |
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
387 xasprintf(&realpath, "%s" DIRSEP "%s", program_files, confdirs[i]); |
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
388 #endif |
975
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
389 if (realpath == NULL) |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
390 { |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
391 DEBUGPRINTF ("Did not find directory: '%s'\n", confdirs[i]); |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
392 continue; |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
393 } |
985
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
394 xasprintf(&profile_dir, "%s" DIRSEP "profile", realpath); |
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
395 xfree(realpath); |
975
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
396 if (port_isdir(profile_dir)) |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
397 { |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
398 DEBUGPRINTF("Found default directory: '%s'\n", profile_dir); |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
399 /* All is well */ |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
400 strv_append (&retval, profile_dir, strlen(profile_dir)); |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
401 xfree(profile_dir); |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
402 profile_dir = NULL; |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
403 continue; |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
404 } |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
405 else |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
406 { |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
407 /* Create the directory */ |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
408 if (port_fileexits(profile_dir)) |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
409 { |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
410 DEBUGPRINTF ("Path: '%s' is not a directory but it exists. Skipping.\n", |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
411 profile_dir); |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
412 xfree(profile_dir); |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
413 profile_dir = NULL; |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
414 continue; |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
415 } |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
416 else |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
417 { |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
418 /* Lets create it */ |
985
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
419 if (!port_mkdir_p(profile_dir)) |
975
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
420 { |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
421 ERRORPRINTF ("Failed to create directory: '%s'\n", profile_dir); |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
422 xfree(profile_dir); |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
423 profile_dir = NULL; |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
424 continue; |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
425 } |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
426 strv_append (&retval, profile_dir, strlen(profile_dir)); |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
427 xfree(profile_dir); |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
428 profile_dir = NULL; |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
429 } |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
430 } |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
431 } |
986
66f6361fba1b
Fix linux build
Andre Heinecke <andre.heinecke@intevation.de>
parents:
985
diff
changeset
|
432 #ifdef WIN32 |
985
1743895b39b8
(issue86) Install into default profile folders on windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
975
diff
changeset
|
433 xfree (program_files); |
986
66f6361fba1b
Fix linux build
Andre Heinecke <andre.heinecke@intevation.de>
parents:
985
diff
changeset
|
434 #endif |
975
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
435 return retval; |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
436 } |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
437 |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
438 /** |
231 | 439 * @brief Collect all mozilla profile directories of current user. |
440 * @return NULL terminated array of strings containing the absolute | |
441 * path of the profile directories. The array needs to be freed by the | |
442 * caller. | |
443 */ | |
444 static char** | |
308
ab69d268b5c8
Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents:
284
diff
changeset
|
445 get_all_nssdb_dirs() |
231 | 446 { |
447 char **mozinis, **pdirs; | |
448 char **alldirs = NULL; | |
975
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
449 |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
450 if (is_elevated()) |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
451 { |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
452 #ifndef _WIN32 |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
453 /* NSS Shared db does not exist under windows. */ |
988
ca89cf228a5b
(issue86) Write nss shared db defaults into /etc/skel
Andre Heinecke <andre.heinecke@intevation.de>
parents:
986
diff
changeset
|
454 if (!port_mkdir_p(NSSSHARED_GLOBAL)) |
ca89cf228a5b
(issue86) Write nss shared db defaults into /etc/skel
Andre Heinecke <andre.heinecke@intevation.de>
parents:
986
diff
changeset
|
455 { |
ca89cf228a5b
(issue86) Write nss shared db defaults into /etc/skel
Andre Heinecke <andre.heinecke@intevation.de>
parents:
986
diff
changeset
|
456 ERRORPRINTF("Failed to create nssshared skeleton directory. \n"); |
ca89cf228a5b
(issue86) Write nss shared db defaults into /etc/skel
Andre Heinecke <andre.heinecke@intevation.de>
parents:
986
diff
changeset
|
457 } |
ca89cf228a5b
(issue86) Write nss shared db defaults into /etc/skel
Andre Heinecke <andre.heinecke@intevation.de>
parents:
986
diff
changeset
|
458 else |
ca89cf228a5b
(issue86) Write nss shared db defaults into /etc/skel
Andre Heinecke <andre.heinecke@intevation.de>
parents:
986
diff
changeset
|
459 { |
ca89cf228a5b
(issue86) Write nss shared db defaults into /etc/skel
Andre Heinecke <andre.heinecke@intevation.de>
parents:
986
diff
changeset
|
460 strv_append(&alldirs, "sql:" NSSSHARED_GLOBAL, strlen("sql:" NSSSHARED_GLOBAL)); |
ca89cf228a5b
(issue86) Write nss shared db defaults into /etc/skel
Andre Heinecke <andre.heinecke@intevation.de>
parents:
986
diff
changeset
|
461 } |
975
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
462 #endif |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
463 pdirs = get_default_profile_dirs(); |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
464 if (pdirs != NULL) |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
465 { |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
466 for (int i=0; pdirs[i] != NULL; i++) |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
467 { |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
468 strv_append(&alldirs, pdirs[i], strlen(pdirs[i])); |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
469 } |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
470 strv_free(pdirs); |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
471 } |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
472 return alldirs; |
b3695a3399de
(issue86) Install into default directories on Linux
Andre Heinecke <andre.heinecke@intevation.de>
parents:
945
diff
changeset
|
473 } |
308
ab69d268b5c8
Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents:
284
diff
changeset
|
474 /* Search Mozilla/Firefox/Thunderbird profiles */ |
231 | 475 if ((mozinis = get_profile_inis()) != NULL) |
476 { | |
477 for (int i=0; mozinis[i] != NULL; i++) | |
478 { | |
479 pdirs = | |
480 get_profile_dirs(mozinis[i]); | |
481 if (pdirs != NULL) | |
482 { | |
483 for (int i=0; pdirs[i] != NULL; i++) | |
484 { | |
485 strv_append(&alldirs, pdirs[i], strlen(pdirs[i])); | |
486 } | |
487 strv_free(pdirs); | |
488 } | |
489 } | |
490 strv_free(mozinis); | |
491 } | |
308
ab69d268b5c8
Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents:
284
diff
changeset
|
492 /* Search for NSS shared DB (used by Chrome/Chromium on GNU/Linux) */ |
ab69d268b5c8
Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents:
284
diff
changeset
|
493 if (TARGET_LINUX) |
ab69d268b5c8
Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents:
284
diff
changeset
|
494 { |
320
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
495 char *path, *fqpath, *sqlpath; |
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
496 xasprintf(&path, "%s/%s", get_conf_basedir(), NSSSHARED); |
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
497 if ((fqpath = port_realpath(path)) != NULL) |
308
ab69d268b5c8
Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents:
284
diff
changeset
|
498 { |
320
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
499 xasprintf(&sqlpath, "sql:%s", fqpath); |
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
500 strv_append(&alldirs, sqlpath, strlen(sqlpath)); |
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
501 free(sqlpath); |
308
ab69d268b5c8
Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents:
284
diff
changeset
|
502 free(fqpath); |
ab69d268b5c8
Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents:
284
diff
changeset
|
503 } |
320
1628615d904e
Replaced snprintf and static buffers with xasprintf.
Sascha Wilde <wilde@intevation.de>
parents:
317
diff
changeset
|
504 free(path); |
308
ab69d268b5c8
Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents:
284
diff
changeset
|
505 } |
231 | 506 return alldirs; |
507 } | |
508 | |
281
0f73fe4230c1
Fixed and optimized production build.
Sascha Wilde <wilde@intevation.de>
parents:
280
diff
changeset
|
509 #ifdef DEBUGOUTPUT |
231 | 510 /** |
223
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
511 * @brief list certificates from nss certificate store |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
512 * @param[in] confdir the directory with the certificate store |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
513 */ |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
514 static void |
281
0f73fe4230c1
Fixed and optimized production build.
Sascha Wilde <wilde@intevation.de>
parents:
280
diff
changeset
|
515 DEBUG_nss_list_certs (char *confdir) |
223
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
516 { |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
517 CERTCertList *list; |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
518 CERTCertListNode *node; |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
519 char *name; |
224
689b94dd89a9
Wrote FindNSS to build against nss without pkg-config support (Windows).
Sascha Wilde <wilde@intevation.de>
parents:
223
diff
changeset
|
520 |
223
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
521 if (NSS_Initialize(confdir, "", "", "secmod.db", NSS_INIT_READONLY) |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
522 == SECSuccess) |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
523 { |
283
fb9e14f4b4c9
Show which store is listed in debug certificate listings.
Sascha Wilde <wilde@intevation.de>
parents:
281
diff
changeset
|
524 DEBUGPRINTF("Listing certs in \"%s\"\n", confdir); |
223
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
525 list = PK11_ListCerts(PK11CertListAll, NULL); |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
526 for (node = CERT_LIST_HEAD(list); !CERT_LIST_END(node, list); |
905
698b6a9bd75e
Fix coding style for C code
Andre Heinecke <andre.heinecke@intevation.de>
parents:
625
diff
changeset
|
527 node = CERT_LIST_NEXT(node)) |
698b6a9bd75e
Fix coding style for C code
Andre Heinecke <andre.heinecke@intevation.de>
parents:
625
diff
changeset
|
528 { |
698b6a9bd75e
Fix coding style for C code
Andre Heinecke <andre.heinecke@intevation.de>
parents:
625
diff
changeset
|
529 name = node->appData; |
223
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
530 |
905
698b6a9bd75e
Fix coding style for C code
Andre Heinecke <andre.heinecke@intevation.de>
parents:
625
diff
changeset
|
531 DEBUGPRINTF("Found certificate \"%s\"\n", name); |
698b6a9bd75e
Fix coding style for C code
Andre Heinecke <andre.heinecke@intevation.de>
parents:
625
diff
changeset
|
532 } |
945
56ca8f2fd433
Add comment about a leak in NSS
Andre Heinecke <andre.heinecke@intevation.de>
parents:
909
diff
changeset
|
533 /* According to valgrind this leaks memory in the list. |
56ca8f2fd433
Add comment about a leak in NSS
Andre Heinecke <andre.heinecke@intevation.de>
parents:
909
diff
changeset
|
534 We could not find API documentation to better free this |
56ca8f2fd433
Add comment about a leak in NSS
Andre Heinecke <andre.heinecke@intevation.de>
parents:
909
diff
changeset
|
535 so we accept the leakage here in case of debug. */ |
223
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
536 CERT_DestroyCertList(list); |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
537 NSS_Shutdown(); |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
538 } |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
539 else |
281
0f73fe4230c1
Fixed and optimized production build.
Sascha Wilde <wilde@intevation.de>
parents:
280
diff
changeset
|
540 { |
0f73fe4230c1
Fixed and optimized production build.
Sascha Wilde <wilde@intevation.de>
parents:
280
diff
changeset
|
541 DEBUGPRINTF("Could not open nss certificate store in %s!\n", confdir); |
0f73fe4230c1
Fixed and optimized production build.
Sascha Wilde <wilde@intevation.de>
parents:
280
diff
changeset
|
542 } |
223
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
543 } |
281
0f73fe4230c1
Fixed and optimized production build.
Sascha Wilde <wilde@intevation.de>
parents:
280
diff
changeset
|
544 #endif |
223
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
545 |
261
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
546 /** |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
547 * @brief Create a string with the name for cert in SECItem. |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
548 * |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
549 * Should be freed by caller. |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
550 * @param[in] secitemp ponts to an SECItem holding the DER certificate. |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
551 * @retruns a string of the from "CN of Subject - O of Subject" |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
552 */ |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
553 static char * |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
554 nss_cert_name(SECItem *secitemp) |
390
eab288779e07
Added debug output in NSS_cert_name on failure
Andre Heinecke <andre.heinecke@intevation.de>
parents:
332
diff
changeset
|
555 { |
eab288779e07
Added debug output in NSS_cert_name on failure
Andre Heinecke <andre.heinecke@intevation.de>
parents:
332
diff
changeset
|
556 char *cn_str, *o_str, *name; |
261
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
557 size_t name_len; |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
558 cn_str = x509_parse_subject(secitemp->data, secitemp->len, CERT_OID_CN); |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
559 o_str = x509_parse_subject(secitemp->data, secitemp->len, CERT_OID_O); |
332
81a205fc651e
Do not exit on error
Andre Heinecke <aheinecke@intevation.de>
parents:
322
diff
changeset
|
560 if (!cn_str || !o_str) |
81a205fc651e
Do not exit on error
Andre Heinecke <aheinecke@intevation.de>
parents:
322
diff
changeset
|
561 { |
81a205fc651e
Do not exit on error
Andre Heinecke <aheinecke@intevation.de>
parents:
322
diff
changeset
|
562 DEBUGPRINTF("FATAL: Could not parse certificate!"); |
81a205fc651e
Do not exit on error
Andre Heinecke <aheinecke@intevation.de>
parents:
322
diff
changeset
|
563 exit(ERR_INVALID_CERT); |
81a205fc651e
Do not exit on error
Andre Heinecke <aheinecke@intevation.de>
parents:
322
diff
changeset
|
564 } |
261
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
565 name_len = strlen(cn_str) + strlen(o_str) + 4; |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
566 name = (char *)xmalloc(name_len); |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
567 snprintf(name, name_len, "%s - %s", cn_str, o_str); |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
568 free(cn_str); |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
569 free(o_str); |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
570 return name; |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
571 } |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
572 |
276
ea9c5bbc6496
Added missing function documentation.
Sascha Wilde <wilde@intevation.de>
parents:
269
diff
changeset
|
573 /** |
ea9c5bbc6496
Added missing function documentation.
Sascha Wilde <wilde@intevation.de>
parents:
269
diff
changeset
|
574 * @brief Convert a base64 encoded DER certificate to SECItem |
ea9c5bbc6496
Added missing function documentation.
Sascha Wilde <wilde@intevation.de>
parents:
269
diff
changeset
|
575 * @param[in] b64 pointer to the base64 encoded certificate |
ea9c5bbc6496
Added missing function documentation.
Sascha Wilde <wilde@intevation.de>
parents:
269
diff
changeset
|
576 * @param[in] b64len length of the base64 encoded certificate |
ea9c5bbc6496
Added missing function documentation.
Sascha Wilde <wilde@intevation.de>
parents:
269
diff
changeset
|
577 * @param[out] secitem pointer to the SECItem in which to store the |
ea9c5bbc6496
Added missing function documentation.
Sascha Wilde <wilde@intevation.de>
parents:
269
diff
changeset
|
578 * raw DER certifiacte. |
ea9c5bbc6496
Added missing function documentation.
Sascha Wilde <wilde@intevation.de>
parents:
269
diff
changeset
|
579 * @returns true on success and false on failure |
ea9c5bbc6496
Added missing function documentation.
Sascha Wilde <wilde@intevation.de>
parents:
269
diff
changeset
|
580 */ |
244
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
581 static bool |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
582 base64_to_secitem(char *b64, size_t b64len, SECItem *secitem) |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
583 { |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
584 unsigned char *dercert = NULL; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
585 size_t dercertlen; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
586 |
245
fbd74e2370de
Error out, when base64 decode results in empty data.
Sascha Wilde <wilde@intevation.de>
parents:
244
diff
changeset
|
587 if ((str_base64_decode((char **)(&dercert), &dercertlen, |
fbd74e2370de
Error out, when base64 decode results in empty data.
Sascha Wilde <wilde@intevation.de>
parents:
244
diff
changeset
|
588 b64, b64len) == 0) && |
fbd74e2370de
Error out, when base64 decode results in empty data.
Sascha Wilde <wilde@intevation.de>
parents:
244
diff
changeset
|
589 (dercertlen > 0)) |
244
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
590 { |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
591 secitem->data = dercert; |
246
1efe494c3d2b
Explicit tyoe cast to fix warning on 64bit Jessie.
Sascha Wilde <wilde@intevation.de>
parents:
245
diff
changeset
|
592 secitem->len = (unsigned int) dercertlen; |
244
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
593 return true; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
594 } |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
595 else |
281
0f73fe4230c1
Fixed and optimized production build.
Sascha Wilde <wilde@intevation.de>
parents:
280
diff
changeset
|
596 { |
0f73fe4230c1
Fixed and optimized production build.
Sascha Wilde <wilde@intevation.de>
parents:
280
diff
changeset
|
597 DEBUGPRINTF("Base64 decode failed for: %s\n", b64); |
0f73fe4230c1
Fixed and optimized production build.
Sascha Wilde <wilde@intevation.de>
parents:
280
diff
changeset
|
598 } |
261
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
599 return false; |
244
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
600 } |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
601 |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
602 /** |
277
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
603 * @brief Store DER certificate in mozilla store. |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
604 * @param[in] pdir the mozilla profile directory with the certificate |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
605 * store to manipulate. |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
606 * @param[in] dercert pointer to a SECItem holding the DER certificate |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
607 * to install |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
608 * @returns true on success and false on failure |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
609 */ |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
610 static bool |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
611 import_cert(char *pdir, SECItem *dercert) |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
612 { |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
613 PK11SlotInfo *pk11slot = NULL; |
309
fa37384b86b6
Add trust "Trusted CA to issue server certificates" to certs on install.
Sascha Wilde <wilde@intevation.de>
parents:
308
diff
changeset
|
614 CERTCertTrust *trust = NULL; |
fa37384b86b6
Add trust "Trusted CA to issue server certificates" to certs on install.
Sascha Wilde <wilde@intevation.de>
parents:
308
diff
changeset
|
615 CERTCertificate *cert = NULL; |
277
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
616 bool success = false; |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
617 char *cert_name = nss_cert_name(dercert); |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
618 |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
619 DEBUGPRINTF("INSTALLING cert: '%s' to: %s\n", cert_name, pdir); |
493
48d7b956bd98
Change loop order of installation to only call NSS_Initialize once per db
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
620 pk11slot = PK11_GetInternalKeySlot(); |
48d7b956bd98
Change loop order of installation to only call NSS_Initialize once per db
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
621 cert = CERT_DecodeCertFromPackage((char *)dercert->data, |
48d7b956bd98
Change loop order of installation to only call NSS_Initialize once per db
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
622 (int)dercert->len); |
48d7b956bd98
Change loop order of installation to only call NSS_Initialize once per db
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
623 trust = (CERTCertTrust *)xmalloc(sizeof(CERTCertTrust)); |
595
2c4eb4435a40
Set trust also for S/MIME and Codesigning
Andre Heinecke <aheinecke@intevation.de>
parents:
564
diff
changeset
|
624 CERT_DecodeTrustString(trust, "C,C,C"); |
493
48d7b956bd98
Change loop order of installation to only call NSS_Initialize once per db
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
625 if ((PK11_ImportCert(pk11slot, cert, CK_INVALID_HANDLE, |
48d7b956bd98
Change loop order of installation to only call NSS_Initialize once per db
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
626 cert_name, PR_FALSE) |
48d7b956bd98
Change loop order of installation to only call NSS_Initialize once per db
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
627 == SECSuccess) && |
48d7b956bd98
Change loop order of installation to only call NSS_Initialize once per db
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
628 (CERT_ChangeCertTrust(CERT_GetDefaultCertDB(), cert, trust) |
48d7b956bd98
Change loop order of installation to only call NSS_Initialize once per db
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
629 == SECSuccess)) |
277
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
630 { |
625
2303caf56dbb
Add logging function for der data and add logging to NSS installation
Andre Heinecke <andre.heinecke@intevation.de>
parents:
595
diff
changeset
|
631 log_certificate_der (pdir, dercert->data, dercert->len, true); |
493
48d7b956bd98
Change loop order of installation to only call NSS_Initialize once per db
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
632 success = true; |
277
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
633 } |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
634 else |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
635 { |
493
48d7b956bd98
Change loop order of installation to only call NSS_Initialize once per db
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
636 DEBUGPRINTF("Failed to install certificate '%s' to '%s'!\n", cert_name, pdir); |
48d7b956bd98
Change loop order of installation to only call NSS_Initialize once per db
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
637 ERRORPRINTF("Error installing certificate err: %i\n", PORT_GetError()); |
277
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
638 } |
493
48d7b956bd98
Change loop order of installation to only call NSS_Initialize once per db
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
639 CERT_DestroyCertificate (cert); |
48d7b956bd98
Change loop order of installation to only call NSS_Initialize once per db
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
640 free(trust); |
48d7b956bd98
Change loop order of installation to only call NSS_Initialize once per db
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
641 PK11_FreeSlot(pk11slot); |
277
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
642 |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
643 free(cert_name); |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
644 return success; |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
645 } |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
646 |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
647 /** |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
648 * @brief Remove DER certificate from mozilla store. |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
649 * @param[in] pdir the mozilla profile directory with the certificate |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
650 * store to manipulate. |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
651 * @param[in] dercert pointer to a SECItem holding the DER certificate |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
652 * to remove |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
653 * @returns true on success and false on failure |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
654 */ |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
655 static bool |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
656 remove_cert(char *pdir, SECItem *dercert) |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
657 { |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
658 PK11SlotInfo *pk11slot = NULL; |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
659 bool success = false; |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
660 char *cert_name = nss_cert_name(dercert); |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
661 CERTCertificate *cert = NULL; |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
662 |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
663 DEBUGPRINTF("REMOVING cert: '%s' from: %s\n", cert_name, pdir); |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
664 if (NSS_Initialize(pdir, "", "", "secmod.db", 0) == SECSuccess) |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
665 { |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
666 pk11slot = PK11_GetInternalKeySlot(); |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
667 cert = PK11_FindCertFromDERCertItem(pk11slot, |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
668 dercert, NULL); |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
669 if (cert != NULL) |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
670 { |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
671 if (SEC_DeletePermCertificate(cert) == SECSuccess) |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
672 { |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
673 success = true; |
625
2303caf56dbb
Add logging function for der data and add logging to NSS installation
Andre Heinecke <andre.heinecke@intevation.de>
parents:
595
diff
changeset
|
674 log_certificate_der (pdir, dercert->data, dercert->len, false); |
277
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
675 } |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
676 else |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
677 { |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
678 DEBUGPRINTF("Failed to remove certificate '%s' from '%s'!\n", cert_name, pdir); |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
679 } |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
680 CERT_DestroyCertificate(cert); |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
681 } |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
682 else |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
683 { |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
684 DEBUGPRINTF("Could not find Certificate '%s' in store '%s'.\n", cert_name, pdir); |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
685 } |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
686 PK11_FreeSlot(pk11slot); |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
687 NSS_Shutdown(); |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
688 } |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
689 else |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
690 { |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
691 DEBUGPRINTF("Could not open nss certificate store in %s!\n", pdir); |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
692 } |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
693 free(cert_name); |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
694 return success; |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
695 } |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
696 |
22408d797c92
Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents:
276
diff
changeset
|
697 /** |
279
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
698 * @brief Apply a function to a list of certificates and profiles |
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
699 * |
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
700 * The function must have the signature: |
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
701 * |
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
702 * bool function(char *pdir, SECItem der_cert) |
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
703 * |
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
704 * where pdir is the path of an profile and der_cert is an raw DER |
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
705 * formatted certificate. The function must return true on success |
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
706 * and false on failure. |
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
707 * |
625
2303caf56dbb
Add logging function for der data and add logging to NSS installation
Andre Heinecke <andre.heinecke@intevation.de>
parents:
595
diff
changeset
|
708 * This function is intended for use with the import_cert and |
279
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
709 * remove_cert functions. |
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
710 * |
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
711 * @param[in] fn the function to apply |
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
712 * @param[inout] certs a secitem list holding the certificates |
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
713 * the list will be change (emptied)! |
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
714 * @param[in] pdirs the NULL terminated list of profile directories |
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
715 * @returns true on success and false on failure |
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
716 */ |
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
717 bool |
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
718 apply_to_certs_and_profiles(bool fn(char *, SECItem *), |
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
719 seciteml_t **certs, char **pdirs) |
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
720 { |
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
721 bool success = true; |
280 | 722 |
493
48d7b956bd98
Change loop order of installation to only call NSS_Initialize once per db
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
723 for (int i=0; pdirs[i] != NULL; i++) |
279
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
724 { |
493
48d7b956bd98
Change loop order of installation to only call NSS_Initialize once per db
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
725 seciteml_t *iter = *certs; |
48d7b956bd98
Change loop order of installation to only call NSS_Initialize once per db
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
726 if (NSS_Initialize(pdirs[i], "", "", "secmod.db", 0) != SECSuccess) |
279
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
727 { |
493
48d7b956bd98
Change loop order of installation to only call NSS_Initialize once per db
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
728 DEBUGPRINTF("Could not open nss certificate store in %s!\n", pdirs[i]); |
48d7b956bd98
Change loop order of installation to only call NSS_Initialize once per db
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
729 continue; |
48d7b956bd98
Change loop order of installation to only call NSS_Initialize once per db
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
730 } |
48d7b956bd98
Change loop order of installation to only call NSS_Initialize once per db
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
731 |
48d7b956bd98
Change loop order of installation to only call NSS_Initialize once per db
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
732 while (iter != NULL && iter->item != NULL) |
48d7b956bd98
Change loop order of installation to only call NSS_Initialize once per db
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
733 { |
48d7b956bd98
Change loop order of installation to only call NSS_Initialize once per db
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
734 SECItem *cert = iter->item; |
279
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
735 if (! (*fn)(pdirs[i], cert)) |
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
736 success = false; |
493
48d7b956bd98
Change loop order of installation to only call NSS_Initialize once per db
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
737 iter = iter->next; |
279
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
738 } |
493
48d7b956bd98
Change loop order of installation to only call NSS_Initialize once per db
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
739 NSS_Shutdown(); |
279
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
740 } |
280 | 741 |
564
f115da3645d5
Free secitem list after usage.
Andre Heinecke <aheinecke@intevation.de>
parents:
493
diff
changeset
|
742 seciteml_free(certs); |
f115da3645d5
Free secitem list after usage.
Andre Heinecke <aheinecke@intevation.de>
parents:
493
diff
changeset
|
743 |
279
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
744 return success; |
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
745 } |
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
746 |
cb5f082e90c5
Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents:
278
diff
changeset
|
747 /** |
244
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
748 * @brief Parse IPC commands from standard input. |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
749 * |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
750 * Reads command lines (R: and I:) from standard input and puts the |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
751 * certificates to process in two SECItem lists holding the |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
752 * certificates in DER format. |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
753 * @param[inout] install_list list of SECItems with certifiactes to install |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
754 * @param[inout] remove_list list of SECItems with certifiactes to remove |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
755 */ |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
756 static void |
315
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
757 parse_commands (FILE *stream, |
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
758 seciteml_t **install_list, seciteml_t **remove_list) |
244
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
759 { |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
760 char inpl[LINEBUFLEN]; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
761 size_t inpllen; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
762 bool parserr = true; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
763 SECItem secitem; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
764 |
315
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
765 while ( fgets(inpl, LINEBUFLEN, stream) != NULL ) |
244
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
766 { |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
767 inpllen = strnlen(inpl, LINEBUFLEN); |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
768 /* Validate input line: |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
769 * - must be (much) longer than 3 characters |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
770 * - must start with "*:" |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
771 */ |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
772 if ((inpllen > 3) && (inpl[1] == ':')) |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
773 /* Now parse Input */ |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
774 switch(inpl[0]) |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
775 { |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
776 case 'R': |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
777 parserr = true; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
778 DEBUGPRINTF("Request to remove certificate: %s\n", &inpl[2]); |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
779 if (base64_to_secitem(&inpl[2], inpllen - 2, &secitem)) |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
780 { |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
781 seciteml_push(remove_list, &secitem); |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
782 parserr = false; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
783 } |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
784 break; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
785 case 'I': |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
786 parserr = true; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
787 DEBUGPRINTF("Request to install certificate: %s\n", &inpl[2]); |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
788 if (base64_to_secitem(&inpl[2], inpllen - 2, &secitem)) |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
789 { |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
790 seciteml_push(install_list, &secitem); |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
791 parserr = false; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
792 } |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
793 break; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
794 default: |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
795 parserr = true; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
796 } |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
797 else |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
798 { |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
799 parserr = true; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
800 } |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
801 |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
802 if (parserr) |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
803 { |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
804 DEBUGPRINTF("FATAL: Invalid input: %s\n", inpl); |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
805 exit(ERR_MOZ_INVALID_INPUT); |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
806 } |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
807 } |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
808 } |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
809 |
113
02ad0922c01f
Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents:
110
diff
changeset
|
810 int |
315
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
811 main (int argc, char **argv) |
113
02ad0922c01f
Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents:
110
diff
changeset
|
812 { |
308
ab69d268b5c8
Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents:
284
diff
changeset
|
813 char **dbdirs; |
244
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
814 seciteml_t *certs_to_remove = NULL; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
815 seciteml_t *certs_to_add = NULL; |
315
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
816 FILE *input_stream; |
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
817 |
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
818 switch (argc) |
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
819 { |
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
820 case 1: |
322 | 821 DEBUGPRINTF("Opening STDIN for input...\n"); |
315
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
822 input_stream = stdin; |
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
823 break; |
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
824 case 2: |
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
825 DEBUGPRINTF("Opening %s for input...\n", argv[1]); |
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
826 if ((input_stream = fopen(argv[1], "r")) == NULL) |
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
827 { |
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
828 DEBUGPRINTF("FATAL: Could not open %s for reading!\n", |
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
829 argv[1]); |
317
46fd11699646
Renamed exit code from return_code to exit_code.
Sascha Wilde <wilde@intevation.de>
parents:
315
diff
changeset
|
830 exit_code = ERR_MOZ_FAILED_TO_OPEN_INPUT; |
315
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
831 goto exit; |
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
832 } |
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
833 break; |
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
834 default: |
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
835 DEBUGPRINTF("FATAL: Wrong number of arguments!\n"); |
317
46fd11699646
Renamed exit code from return_code to exit_code.
Sascha Wilde <wilde@intevation.de>
parents:
315
diff
changeset
|
836 exit_code = ERR_MOZ_WRONG_ARGC; |
315
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
837 goto exit; |
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
838 } |
244
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
839 |
308
ab69d268b5c8
Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents:
284
diff
changeset
|
840 dbdirs = |
ab69d268b5c8
Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents:
284
diff
changeset
|
841 get_all_nssdb_dirs(); |
235
0c4d65a7cd14
Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents:
232
diff
changeset
|
842 |
308
ab69d268b5c8
Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents:
284
diff
changeset
|
843 if (dbdirs != NULL) |
231 | 844 { |
315
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
845 parse_commands(input_stream, &certs_to_add, &certs_to_remove); |
244
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
846 |
281
0f73fe4230c1
Fixed and optimized production build.
Sascha Wilde <wilde@intevation.de>
parents:
280
diff
changeset
|
847 #ifdef DEBUGOUTPUT |
284
a0c5eba8eb41
Added missing line breaks in debug output.
Sascha Wilde <wilde@intevation.de>
parents:
283
diff
changeset
|
848 DEBUGPRINTF("OLD List of installed certs:\n"); |
308
ab69d268b5c8
Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents:
284
diff
changeset
|
849 for (int i=0; dbdirs[i] != NULL; i++) |
ab69d268b5c8
Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents:
284
diff
changeset
|
850 DEBUG_nss_list_certs(dbdirs[i]); |
281
0f73fe4230c1
Fixed and optimized production build.
Sascha Wilde <wilde@intevation.de>
parents:
280
diff
changeset
|
851 #endif |
263
1fa607af6332
Next baby step: we can import certificates!
Sascha Wilde <wilde@intevation.de>
parents:
261
diff
changeset
|
852 |
308
ab69d268b5c8
Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents:
284
diff
changeset
|
853 if (! apply_to_certs_and_profiles(remove_cert, &certs_to_remove, dbdirs)) |
317
46fd11699646
Renamed exit code from return_code to exit_code.
Sascha Wilde <wilde@intevation.de>
parents:
315
diff
changeset
|
854 exit_code |= WARN_MOZ_COULD_NOT_REMOVE_CERT; |
280 | 855 |
308
ab69d268b5c8
Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents:
284
diff
changeset
|
856 if (! apply_to_certs_and_profiles(import_cert, &certs_to_add, dbdirs)) |
317
46fd11699646
Renamed exit code from return_code to exit_code.
Sascha Wilde <wilde@intevation.de>
parents:
315
diff
changeset
|
857 exit_code |= WARN_MOZ_COULD_NOT_ADD_CERT; |
280 | 858 |
281
0f73fe4230c1
Fixed and optimized production build.
Sascha Wilde <wilde@intevation.de>
parents:
280
diff
changeset
|
859 #ifdef DEBUGOUTPUT |
284
a0c5eba8eb41
Added missing line breaks in debug output.
Sascha Wilde <wilde@intevation.de>
parents:
283
diff
changeset
|
860 DEBUGPRINTF("NEW List of installed certs:\n"); |
308
ab69d268b5c8
Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents:
284
diff
changeset
|
861 for (int i=0; dbdirs[i] != NULL; i++) |
ab69d268b5c8
Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents:
284
diff
changeset
|
862 DEBUG_nss_list_certs(dbdirs[i]); |
281
0f73fe4230c1
Fixed and optimized production build.
Sascha Wilde <wilde@intevation.de>
parents:
280
diff
changeset
|
863 #endif |
280 | 864 |
989
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
865 #ifndef WIN32 |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
866 if (is_elevated()) |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
867 { |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
868 make_defaults_readable(); |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
869 } |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
870 #endif |
1cd1bfe82fc2
(issue86) Fix Firefox / Thunderbird default profile path and make created files readable.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
988
diff
changeset
|
871 |
308
ab69d268b5c8
Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents:
284
diff
changeset
|
872 strv_free(dbdirs); |
231 | 873 } |
315
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
874 |
905
698b6a9bd75e
Fix coding style for C code
Andre Heinecke <andre.heinecke@intevation.de>
parents:
625
diff
changeset
|
875 fclose(input_stream); |
315
b832231640ab
Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents:
312
diff
changeset
|
876 |
905
698b6a9bd75e
Fix coding style for C code
Andre Heinecke <andre.heinecke@intevation.de>
parents:
625
diff
changeset
|
877 exit: |
317
46fd11699646
Renamed exit code from return_code to exit_code.
Sascha Wilde <wilde@intevation.de>
parents:
315
diff
changeset
|
878 exit(exit_code); |
44
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
879 } |