Mercurial > trustbridge
annotate cinst/mozilla.c @ 270:9d2ac9b6a5b0
Merged
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Wed, 02 Apr 2014 10:31:08 +0200 |
parents | f7471604bb31 |
children | ea9c5bbc6496 |
rev | line source |
---|---|
121
4bb5f295987b
Fix doxygen documentation.
Sascha Wilde <wilde@intevation.de>
parents:
119
diff
changeset
|
1 /** |
4bb5f295987b
Fix doxygen documentation.
Sascha Wilde <wilde@intevation.de>
parents:
119
diff
changeset
|
2 * @file |
4bb5f295987b
Fix doxygen documentation.
Sascha Wilde <wilde@intevation.de>
parents:
119
diff
changeset
|
3 * @brief Mozilla installation process |
99
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
4 * |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
5 * Reads from stdin a list of instructions in the form: |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
6 * |
238
dd417a2ff9cd
Specifiy unspecified behavior if there is an install and
Andre Heinecke <aheinecke@intevation.de>
parents:
235
diff
changeset
|
7 * I:<base64 DER econded certificate> |
dd417a2ff9cd
Specifiy unspecified behavior if there is an install and
Andre Heinecke <aheinecke@intevation.de>
parents:
235
diff
changeset
|
8 * R:<base64 DER econded certificate> |
99
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
9 * ... |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
10 * |
238
dd417a2ff9cd
Specifiy unspecified behavior if there is an install and
Andre Heinecke <aheinecke@intevation.de>
parents:
235
diff
changeset
|
11 * 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
|
12 * 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
|
13 * |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
14 * 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
|
15 * 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
|
16 * the databases. |
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 * 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
|
19 * 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
|
20 * |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
21 * 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
|
22 * 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
|
23 * executed. |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
24 * |
238
dd417a2ff9cd
Specifiy unspecified behavior if there is an install and
Andre Heinecke <aheinecke@intevation.de>
parents:
235
diff
changeset
|
25 * 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
|
26 * 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
|
27 * may lead to errors. |
dd417a2ff9cd
Specifiy unspecified behavior if there is an install and
Andre Heinecke <aheinecke@intevation.de>
parents:
235
diff
changeset
|
28 * |
99
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
29 * 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
|
30 * as defined in errorcodes.h otherwise. |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
31 * |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
32 * 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
|
33 * 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
|
34 * with the profile name that it modified. |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
35 * |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
36 */ |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
37 |
235
0c4d65a7cd14
Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents:
232
diff
changeset
|
38 /** |
0c4d65a7cd14
Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents:
232
diff
changeset
|
39 * @brief Needs to eb defined to get strnlen() |
0c4d65a7cd14
Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents:
232
diff
changeset
|
40 */ |
0c4d65a7cd14
Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents:
232
diff
changeset
|
41 #define _POSIX_C_SOURCE 200809L |
0c4d65a7cd14
Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents:
232
diff
changeset
|
42 |
0c4d65a7cd14
Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents:
232
diff
changeset
|
43 /* REMOVEME: */ |
0c4d65a7cd14
Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents:
232
diff
changeset
|
44 #include <unistd.h> |
0c4d65a7cd14
Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents:
232
diff
changeset
|
45 |
269
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
46 #include <cert.h> |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
47 #include <certdb.h> |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
48 #include <certt.h> |
173
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
49 #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
|
50 #include <nss.h> |
689b94dd89a9
Wrote FindNSS to build against nss without pkg-config support (Windows).
Sascha Wilde <wilde@intevation.de>
parents:
223
diff
changeset
|
51 #include <pk11pub.h> |
119
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
52 #include <stdbool.h> |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
53 #include <stdio.h> |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
54 #include <stdlib.h> |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
55 #include <string.h> |
173
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
56 #include <sys/types.h> |
119
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
57 |
230
92b1e5ed2d5f
Cleanup and documentation in debugging macros.
Sascha Wilde <wilde@intevation.de>
parents:
229
diff
changeset
|
58 #define DEBUGPREFIX "MOZ-" |
252
bd7fb50078b4
Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
246
diff
changeset
|
59 #include "logging.h" |
230
92b1e5ed2d5f
Cleanup and documentation in debugging macros.
Sascha Wilde <wilde@intevation.de>
parents:
229
diff
changeset
|
60 |
261
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
61 #include "certhelp.h" |
226
d7788db3bdde
Make locale includes distinguishable from system includes.
Sascha Wilde <wilde@intevation.de>
parents:
224
diff
changeset
|
62 #include "errorcodes.h" |
d7788db3bdde
Make locale includes distinguishable from system includes.
Sascha Wilde <wilde@intevation.de>
parents:
224
diff
changeset
|
63 #include "portpath.h" |
d7788db3bdde
Make locale includes distinguishable from system includes.
Sascha Wilde <wilde@intevation.de>
parents:
224
diff
changeset
|
64 #include "strhelp.h" |
244
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
65 #include "nss-secitemlist.h" |
228
19de529ce7fb
Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents:
227
diff
changeset
|
66 |
113
02ad0922c01f
Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents:
110
diff
changeset
|
67 #ifndef _WIN32 |
197
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
68 #define CONFDIRS ".mozilla", ".thunderbird" |
223
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
69 #define TARGET_LINUX 1 |
113
02ad0922c01f
Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents:
110
diff
changeset
|
70 #else |
197
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
71 #define CONFDIRS "Mozilla", "Thunderbird" |
223
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
72 #define TARGET_LINUX 0 |
113
02ad0922c01f
Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents:
110
diff
changeset
|
73 #endif |
02ad0922c01f
Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents:
110
diff
changeset
|
74 |
229 | 75 /** |
76 * @brief Length of string buffers used | |
77 * | |
78 * The maximal length of input is defined as 9999 (+ terminating \0). | |
79 * We use it for other other input puffers besides the IPC input, too. | |
80 * (One size fits all). | |
81 */ | |
82 #define LINEBUFLEN 10000 | |
147
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
83 |
119
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
84 /** |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
85 * @brief Global Return Code |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
86 * |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
87 * 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
|
88 * 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
|
89 * 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
|
90 * ORed together. |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
91 */ |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
92 int return_code = 0; |
44
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
93 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
94 /** |
194
d4e97c9b199f
Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents:
181
diff
changeset
|
95 * @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
|
96 * @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
|
97 * 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
|
98 * and thunderbird. |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
99 */ |
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
100 static char * |
194
d4e97c9b199f
Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents:
181
diff
changeset
|
101 get_conf_basedir() |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
102 { |
194
d4e97c9b199f
Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents:
181
diff
changeset
|
103 char *cdir, *envvar; |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
104 |
223
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
105 if (TARGET_LINUX) |
194
d4e97c9b199f
Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents:
181
diff
changeset
|
106 envvar = "HOME" ; |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
107 else |
194
d4e97c9b199f
Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents:
181
diff
changeset
|
108 envvar = "APPDATA"; |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
109 |
194
d4e97c9b199f
Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents:
181
diff
changeset
|
110 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
|
111 return cdir; |
d4e97c9b199f
Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents:
181
diff
changeset
|
112 else |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
113 { |
228
19de529ce7fb
Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents:
227
diff
changeset
|
114 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
|
115 exit(ERR_MOZ_HOMELESS); |
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
116 } |
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
117 } |
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
118 |
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
119 /** |
119
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
120 * @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
|
121 * |
232 | 122 * Parse the profiles.ini and extract all profile paths from that. |
123 * The expected data is in the form: | |
124 * | |
125 * [Profile99] | |
126 * IsRelative=1 | |
127 * Path=Example/fooo.bar | |
128 * | |
129 * or | |
130 * [Profile0] | |
131 * IsRelative=0 | |
132 * Path=c:\foo\bar\baz | |
133 * | |
134 * Mozilla also accepts the ini file on Windows even if it is UTF-16 | |
135 * encoded but never writes UTF-16 on its own. So currently we ignore | |
136 * this special case. | |
44
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
137 * |
121
4bb5f295987b
Fix doxygen documentation.
Sascha Wilde <wilde@intevation.de>
parents:
119
diff
changeset
|
138 * @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
|
139 * @return NULL terminated array of strings containing containing the |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
140 * 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
|
141 * be freed by the caller. |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
142 */ |
119
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
143 static char ** |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
144 get_profile_dirs (char *inifile_name) |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
145 { |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
146 char **dirs = NULL; |
147
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
147 char *inifile_dirname; |
119
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
148 FILE *inifile; |
147
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
149 char line[LINEBUFLEN]; |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
150 char *key; |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
151 char *value; |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
152 char path[LINEBUFLEN]; |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
153 char *fqpath; |
119
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
154 bool inprofile = false; |
147
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
155 bool relative_path = false; |
44
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
156 |
119
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
157 if ((inifile = fopen(inifile_name, "r")) != NULL) |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
158 { |
228
19de529ce7fb
Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents:
227
diff
changeset
|
159 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
|
160 |
147
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
161 inifile_dirname = port_dirname(inifile_name); |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
162 while (fgets(line, LINEBUFLEN, inifile) != NULL) |
119
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
163 { |
147
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
164 /* Determine if we are in an profile section */ |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
165 if (str_starts_with(line, "[Profile")) |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
166 { |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
167 relative_path = false; |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
168 inprofile = true; |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
169 } |
119
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
170 else if (line[0] == '[') |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
171 inprofile = false; |
147
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
172 |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
173 /* If we are in a profile parse path related stuff */ |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
174 if (inprofile) |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
175 { |
157
a46a4b443410
Use strtok instead of strsep for portability.
Sascha Wilde <wilde@intevation.de>
parents:
147
diff
changeset
|
176 key = strtok(line, "="); |
a46a4b443410
Use strtok instead of strsep for portability.
Sascha Wilde <wilde@intevation.de>
parents:
147
diff
changeset
|
177 value = strtok(NULL, "="); |
147
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
178 str_trim(&value); |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
179 if (str_equal(key, "Path")) |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
180 { |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
181 if (relative_path) |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
182 snprintf(path, LINEBUFLEN, "%s/%s", inifile_dirname, value); |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
183 else |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
184 strncpy(path, value, LINEBUFLEN); |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
185 if ((fqpath = port_realpath(path)) != NULL) |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
186 { |
228
19de529ce7fb
Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents:
227
diff
changeset
|
187 DEBUGPRINTF("Found profile path: '%s'\n", fqpath); |
147
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
188 strv_append(&dirs, fqpath, strlen(fqpath)); |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
189 free (fqpath); |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
190 } |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
191 else |
175
6fa0e12ae1d2
Added more debug output.
Sascha Wilde <wilde@intevation.de>
parents:
174
diff
changeset
|
192 { |
228
19de529ce7fb
Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents:
227
diff
changeset
|
193 DEBUGPRINTF("WARN! Non existent profile path: '%s'\n", path); |
175
6fa0e12ae1d2
Added more debug output.
Sascha Wilde <wilde@intevation.de>
parents:
174
diff
changeset
|
194 return_code |= WARN_MOZ_PROFILE_DOES_NOT_EXIST; |
6fa0e12ae1d2
Added more debug output.
Sascha Wilde <wilde@intevation.de>
parents:
174
diff
changeset
|
195 } |
147
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
196 } |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
197 else if (str_equal(key, "IsRelative") && |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
198 str_starts_with(value, "1")) |
fc9af77b06b9
Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents:
130
diff
changeset
|
199 relative_path = 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 } |
179
8fafd0fc2173
get_profile_dirs(): close filedescriptor again. (found by cppcheck)
Bernhard Reiter <bernhard@intevation.de>
parents:
177
diff
changeset
|
202 fclose(inifile); |
119
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
203 } |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
204 else |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
205 { |
228
19de529ce7fb
Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents:
227
diff
changeset
|
206 DEBUGPRINTF("WARN! Could not open ini file: '%s'\n", inifile_name); |
119
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
207 return_code |= WARN_MOZ_FAILED_TO_OPEN_INI; |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
208 } |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
209 return dirs; |
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
210 } |
44
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
211 |
173
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
212 /** |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
213 * @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
|
214 * |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
215 * 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
|
216 * 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
|
217 * |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
218 * @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
|
219 * 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
|
220 * caller. |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
221 */ |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
222 static char ** |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
223 get_profile_inis () |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
224 { |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
225 char **inis = NULL; |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
226 char path[LINEBUFLEN]; |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
227 char *fqpath; |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
228 DIR *mozdir; |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
229 struct dirent *mozdirent; |
194
d4e97c9b199f
Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents:
181
diff
changeset
|
230 char *confbase = get_conf_basedir(); |
197
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
231 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
|
232 |
197
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
233 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
|
234 { |
197
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
235 snprintf(path, LINEBUFLEN, "%s/%s", |
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
236 confbase, |
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
237 confdirs[i]); |
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
238 if ((mozdir = opendir(path)) != NULL) |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
239 { |
197
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
240 while ((mozdirent = readdir(mozdir)) != NULL) |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
241 { |
197
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
242 snprintf(path, LINEBUFLEN, "%s/%s/%s", |
194
d4e97c9b199f
Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents:
181
diff
changeset
|
243 confbase, |
197
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
244 confdirs[i], |
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
245 mozdirent->d_name); |
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
246 if (port_isdir(path) |
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
247 && (strcmp(mozdirent->d_name, "..") != 0)) |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
248 { |
197
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
249 snprintf(path, LINEBUFLEN, "%s/%s/%s/%s", |
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
250 confbase, |
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
251 confdirs[i], |
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
252 mozdirent->d_name, |
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
253 "profiles.ini"); |
228
19de529ce7fb
Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents:
227
diff
changeset
|
254 DEBUGPRINTF("checking for %s...\n", path); |
197
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
255 if ((fqpath = port_realpath(path)) != NULL) |
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
256 { |
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
257 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
|
258 DEBUGPRINTF("Found mozilla ini file: '%s'\n", fqpath); |
197
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
259 free(fqpath); |
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
260 } |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
261 } |
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
262 } |
197
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
263 closedir(mozdir); |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
264 } |
197
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
265 else |
5d380b662198
Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents:
195
diff
changeset
|
266 { |
228
19de529ce7fb
Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents:
227
diff
changeset
|
267 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
|
268 } |
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 if (inis == NULL) |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
271 { |
228
19de529ce7fb
Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents:
227
diff
changeset
|
272 DEBUGPRINTF("No ini files found - will do nothing!\n"); |
180
344b8a79ad2e
Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents:
177
diff
changeset
|
273 exit(WARN_MOZ_NO_PROFILES); |
173
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
274 } |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
275 return inis; |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
276 } |
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
277 |
223
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
278 /** |
231 | 279 * @brief Collect all mozilla profile directories of current user. |
280 * @return NULL terminated array of strings containing the absolute | |
281 * path of the profile directories. The array needs to be freed by the | |
282 * caller. | |
283 */ | |
284 static char** | |
285 get_all_profile_dirs() | |
286 { | |
287 char **mozinis, **pdirs; | |
288 char **alldirs = NULL; | |
289 if ((mozinis = get_profile_inis()) != NULL) | |
290 { | |
291 for (int i=0; mozinis[i] != NULL; i++) | |
292 { | |
293 pdirs = | |
294 get_profile_dirs(mozinis[i]); | |
295 if (pdirs != NULL) | |
296 { | |
297 for (int i=0; pdirs[i] != NULL; i++) | |
298 { | |
299 strv_append(&alldirs, pdirs[i], strlen(pdirs[i])); | |
300 } | |
301 strv_free(pdirs); | |
302 } | |
303 } | |
304 strv_free(mozinis); | |
305 } | |
306 return alldirs; | |
307 } | |
308 | |
309 /** | |
223
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
310 * @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
|
311 * @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
|
312 */ |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
313 static void |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
314 nss_list_certs (char *confdir) |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
315 { |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
316 CERTCertList *list; |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
317 CERTCertListNode *node; |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
318 char *name; |
224
689b94dd89a9
Wrote FindNSS to build against nss without pkg-config support (Windows).
Sascha Wilde <wilde@intevation.de>
parents:
223
diff
changeset
|
319 |
223
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
320 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
|
321 == SECSuccess) |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
322 { |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
323 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
|
324 for (node = CERT_LIST_HEAD(list); !CERT_LIST_END(node, list); |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
325 node = CERT_LIST_NEXT(node)) { |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
326 name = node->appData; |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
327 |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
328 printf ("Found certificate \"%s\"\n", name); |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
329 } |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
330 CERT_DestroyCertList(list); |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
331 NSS_Shutdown(); |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
332 } |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
333 else |
263
1fa607af6332
Next baby step: we can import certificates!
Sascha Wilde <wilde@intevation.de>
parents:
261
diff
changeset
|
334 DEBUGPRINTF("Could not open nss certificate store 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
|
335 } |
d29997e09177
NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents:
197
diff
changeset
|
336 |
261
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
337 /** |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
338 * @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
|
339 * |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
340 * Should be freed by caller. |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
341 * @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
|
342 * @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
|
343 */ |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
344 static char * |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
345 nss_cert_name(SECItem *secitemp) |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
346 { char *cn_str, *o_str, *name; |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
347 size_t name_len; |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
348 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
|
349 o_str = x509_parse_subject(secitemp->data, secitemp->len, CERT_OID_O); |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
350 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
|
351 name = (char *)xmalloc(name_len); |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
352 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
|
353 free(cn_str); |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
354 free(o_str); |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
355 return name; |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
356 } |
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
357 |
244
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
358 static bool |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
359 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
|
360 { |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
361 unsigned char *dercert = NULL; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
362 size_t dercertlen; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
363 |
245
fbd74e2370de
Error out, when base64 decode results in empty data.
Sascha Wilde <wilde@intevation.de>
parents:
244
diff
changeset
|
364 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
|
365 b64, b64len) == 0) && |
fbd74e2370de
Error out, when base64 decode results in empty data.
Sascha Wilde <wilde@intevation.de>
parents:
244
diff
changeset
|
366 (dercertlen > 0)) |
244
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
367 { |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
368 secitem->data = dercert; |
246
1efe494c3d2b
Explicit tyoe cast to fix warning on 64bit Jessie.
Sascha Wilde <wilde@intevation.de>
parents:
245
diff
changeset
|
369 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
|
370 return true; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
371 } |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
372 else |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
373 DEBUGPRINTF("Base64 decode failed for: %s\n", b64); |
261
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
374 return false; |
244
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
375 } |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
376 |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
377 /** |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
378 * @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
|
379 * |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
380 * 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
|
381 * 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
|
382 * certificates in DER format. |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
383 * @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
|
384 * @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
|
385 */ |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
386 static void |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
387 parse_commands (seciteml_t **install_list, seciteml_t **remove_list) |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
388 { |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
389 char inpl[LINEBUFLEN]; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
390 size_t inpllen; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
391 bool parserr = true; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
392 SECItem secitem; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
393 |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
394 while ( fgets(inpl, LINEBUFLEN, stdin) != NULL ) |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
395 { |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
396 inpllen = strnlen(inpl, LINEBUFLEN); |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
397 /* Validate input line: |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
398 * - 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
|
399 * - must start with "*:" |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
400 */ |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
401 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
|
402 /* Now parse Input */ |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
403 switch(inpl[0]) |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
404 { |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
405 case 'R': |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
406 parserr = true; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
407 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
|
408 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
|
409 { |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
410 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
|
411 parserr = false; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
412 } |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
413 break; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
414 case 'I': |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
415 parserr = true; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
416 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
|
417 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
|
418 { |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
419 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
|
420 parserr = false; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
421 } |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
422 break; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
423 default: |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
424 parserr = true; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
425 } |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
426 else |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
427 { |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
428 parserr = true; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
429 } |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
430 |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
431 if (parserr) |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
432 { |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
433 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
|
434 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
|
435 } |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
436 } |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
437 } |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
438 |
173
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
439 |
113
02ad0922c01f
Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents:
110
diff
changeset
|
440 int |
173
a9e4454dee97
Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents:
157
diff
changeset
|
441 main () |
113
02ad0922c01f
Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents:
110
diff
changeset
|
442 { |
231 | 443 char **pdirs; |
244
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
444 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
|
445 seciteml_t *certs_to_add = NULL; |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
446 SECItem *secitemp; |
263
1fa607af6332
Next baby step: we can import certificates!
Sascha Wilde <wilde@intevation.de>
parents:
261
diff
changeset
|
447 SECStatus rv; |
1fa607af6332
Next baby step: we can import certificates!
Sascha Wilde <wilde@intevation.de>
parents:
261
diff
changeset
|
448 PK11SlotInfo *pk11slot = NULL; |
261
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
449 char *cert_name; |
269
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
450 CERTCertificate *cert = NULL; |
244
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
451 |
231 | 452 pdirs = |
453 get_all_profile_dirs(); | |
235
0c4d65a7cd14
Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents:
232
diff
changeset
|
454 |
231 | 455 if (pdirs != NULL) |
456 { | |
244
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
457 parse_commands(&certs_to_add, &certs_to_remove); |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
458 |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
459 while ((secitemp = seciteml_pop(&certs_to_remove)) != NULL) |
235
0c4d65a7cd14
Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents:
232
diff
changeset
|
460 { |
261
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
461 cert_name = nss_cert_name(secitemp); |
269
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
462 for (int i=0; pdirs[i] != NULL; i++) |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
463 { |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
464 puts(pdirs[i]); |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
465 nss_list_certs(pdirs[i]); |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
466 |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
467 printf("Will now DELETE cert: '%s' from %s\n", cert_name, pdirs[i]); |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
468 if (NSS_Initialize(pdirs[i], "", "", "secmod.db", 0) |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
469 == SECSuccess) |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
470 { |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
471 pk11slot = PK11_GetInternalKeySlot(); |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
472 cert = PK11_FindCertFromDERCertItem(pk11slot, |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
473 secitemp, NULL); |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
474 if (cert != NULL) |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
475 { |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
476 rv = SEC_DeletePermCertificate(cert); |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
477 if (rv != SECSuccess) |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
478 { |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
479 DEBUGPRINTF("Failed to remove certificate '%s' from '%s'!\n", cert_name, pdirs[i]); |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
480 DEBUGPRINTF("Error was %d\n", rv); |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
481 } |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
482 } |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
483 else |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
484 { |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
485 DEBUGPRINTF("Could not find Certificate %s in store.\n", cert_name); |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
486 } |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
487 CERT_DestroyCertificate(cert); |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
488 PK11_FreeSlot(pk11slot); |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
489 NSS_Shutdown(); |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
490 } |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
491 puts("List new:"); |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
492 nss_list_certs(pdirs[i]); |
f7471604bb31
Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents:
268
diff
changeset
|
493 } |
261
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
494 free(cert_name); |
244
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
495 free(secitemp->data); |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
496 free(secitemp); |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
497 } |
263
1fa607af6332
Next baby step: we can import certificates!
Sascha Wilde <wilde@intevation.de>
parents:
261
diff
changeset
|
498 |
244
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
499 while ((secitemp = seciteml_pop(&certs_to_add)) != NULL) |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
500 { |
261
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
501 cert_name = nss_cert_name(secitemp); |
263
1fa607af6332
Next baby step: we can import certificates!
Sascha Wilde <wilde@intevation.de>
parents:
261
diff
changeset
|
502 for (int i=0; pdirs[i] != NULL; i++) |
1fa607af6332
Next baby step: we can import certificates!
Sascha Wilde <wilde@intevation.de>
parents:
261
diff
changeset
|
503 { |
1fa607af6332
Next baby step: we can import certificates!
Sascha Wilde <wilde@intevation.de>
parents:
261
diff
changeset
|
504 puts(pdirs[i]); |
1fa607af6332
Next baby step: we can import certificates!
Sascha Wilde <wilde@intevation.de>
parents:
261
diff
changeset
|
505 nss_list_certs(pdirs[i]); |
1fa607af6332
Next baby step: we can import certificates!
Sascha Wilde <wilde@intevation.de>
parents:
261
diff
changeset
|
506 |
1fa607af6332
Next baby step: we can import certificates!
Sascha Wilde <wilde@intevation.de>
parents:
261
diff
changeset
|
507 printf("Will now ADD cert: '%s' to %s\n", cert_name, pdirs[i]); |
1fa607af6332
Next baby step: we can import certificates!
Sascha Wilde <wilde@intevation.de>
parents:
261
diff
changeset
|
508 if (NSS_Initialize(pdirs[i], "", "", "secmod.db", 0) |
1fa607af6332
Next baby step: we can import certificates!
Sascha Wilde <wilde@intevation.de>
parents:
261
diff
changeset
|
509 == SECSuccess) |
1fa607af6332
Next baby step: we can import certificates!
Sascha Wilde <wilde@intevation.de>
parents:
261
diff
changeset
|
510 { |
1fa607af6332
Next baby step: we can import certificates!
Sascha Wilde <wilde@intevation.de>
parents:
261
diff
changeset
|
511 pk11slot = PK11_GetInternalKeySlot(); |
268
a7c6a21aba38
Simplification, import DER cert directly to store.
Sascha Wilde <wilde@intevation.de>
parents:
263
diff
changeset
|
512 rv = PK11_ImportDERCert(pk11slot, secitemp, CK_INVALID_HANDLE, cert_name, PR_FALSE); |
263
1fa607af6332
Next baby step: we can import certificates!
Sascha Wilde <wilde@intevation.de>
parents:
261
diff
changeset
|
513 if (rv != SECSuccess) { |
1fa607af6332
Next baby step: we can import certificates!
Sascha Wilde <wilde@intevation.de>
parents:
261
diff
changeset
|
514 DEBUGPRINTF("Failed to install certificate '%s' to '%s'!\n", cert_name, pdirs[i]); |
1fa607af6332
Next baby step: we can import certificates!
Sascha Wilde <wilde@intevation.de>
parents:
261
diff
changeset
|
515 DEBUGPRINTF("Error was %d\n", rv); |
1fa607af6332
Next baby step: we can import certificates!
Sascha Wilde <wilde@intevation.de>
parents:
261
diff
changeset
|
516 } |
1fa607af6332
Next baby step: we can import certificates!
Sascha Wilde <wilde@intevation.de>
parents:
261
diff
changeset
|
517 PK11_FreeSlot(pk11slot); |
1fa607af6332
Next baby step: we can import certificates!
Sascha Wilde <wilde@intevation.de>
parents:
261
diff
changeset
|
518 NSS_Shutdown(); |
1fa607af6332
Next baby step: we can import certificates!
Sascha Wilde <wilde@intevation.de>
parents:
261
diff
changeset
|
519 } |
1fa607af6332
Next baby step: we can import certificates!
Sascha Wilde <wilde@intevation.de>
parents:
261
diff
changeset
|
520 puts("List new:"); |
1fa607af6332
Next baby step: we can import certificates!
Sascha Wilde <wilde@intevation.de>
parents:
261
diff
changeset
|
521 nss_list_certs(pdirs[i]); |
1fa607af6332
Next baby step: we can import certificates!
Sascha Wilde <wilde@intevation.de>
parents:
261
diff
changeset
|
522 } |
261
7707191ddb01
New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents:
252
diff
changeset
|
523 free(cert_name); |
244
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
524 free(secitemp->data); |
0145d2401f46
Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents:
243
diff
changeset
|
525 free(secitemp); |
235
0c4d65a7cd14
Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents:
232
diff
changeset
|
526 } |
231 | 527 strv_free(pdirs); |
528 } | |
119
24ca8e2ceecf
First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents:
113
diff
changeset
|
529 exit(return_code); |
44
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
530 } |