annotate cinst/mozilla.c @ 315:b832231640ab

Read from file instead of stdin, if given.
author Sascha Wilde <wilde@intevation.de>
date Fri, 04 Apr 2014 13:34:15 +0200
parents 4033c16beb04
children 46fd11699646
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 *
315
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
5 * 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
6 * instructions in the form:
99
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
7 *
238
dd417a2ff9cd Specifiy unspecified behavior if there is an install and
Andre Heinecke <aheinecke@intevation.de>
parents: 235
diff changeset
8 * I:<base64 DER econded certificate>
dd417a2ff9cd Specifiy unspecified behavior if there is an install and
Andre Heinecke <aheinecke@intevation.de>
parents: 235
diff changeset
9 * R:<base64 DER econded certificate>
99
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
10 * ...
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
11 *
238
dd417a2ff9cd Specifiy unspecified behavior if there is an install and
Andre Heinecke <aheinecke@intevation.de>
parents: 235
diff changeset
12 * 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
13 * 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
14 *
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
15 * 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
16 * 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
17 * the databases.
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
18 *
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
19 * 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
20 * 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
21 *
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
22 * 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
23 * 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
24 * executed.
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
25 *
238
dd417a2ff9cd Specifiy unspecified behavior if there is an install and
Andre Heinecke <aheinecke@intevation.de>
parents: 235
diff changeset
26 * 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
27 * 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
28 * may lead to errors.
dd417a2ff9cd Specifiy unspecified behavior if there is an install and
Andre Heinecke <aheinecke@intevation.de>
parents: 235
diff changeset
29 *
99
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
30 * 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
31 * as defined in errorcodes.h otherwise.
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
32 *
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
33 * 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
34 * 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
35 * with the profile name that it modified.
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 */
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
38
235
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
39 /**
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
40 * @brief Needs to eb defined to get strnlen()
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
41 */
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
42 #define _POSIX_C_SOURCE 200809L
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
43
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
44 /* REMOVEME: */
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
45 #include <unistd.h>
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
46
269
f7471604bb31 Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents: 268
diff changeset
47 #include <cert.h>
f7471604bb31 Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents: 268
diff changeset
48 #include <certdb.h>
f7471604bb31 Deletion of certificates implemented.
Sascha Wilde <wilde@intevation.de>
parents: 268
diff changeset
49 #include <certt.h>
173
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
50 #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
51 #include <nss.h>
689b94dd89a9 Wrote FindNSS to build against nss without pkg-config support (Windows).
Sascha Wilde <wilde@intevation.de>
parents: 223
diff changeset
52 #include <pk11pub.h>
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
53 #include <stdbool.h>
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
54 #include <stdio.h>
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
55 #include <stdlib.h>
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
56 #include <string.h>
173
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
57 #include <sys/types.h>
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
58
230
92b1e5ed2d5f Cleanup and documentation in debugging macros.
Sascha Wilde <wilde@intevation.de>
parents: 229
diff changeset
59 #define DEBUGPREFIX "MOZ-"
252
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents: 246
diff changeset
60 #include "logging.h"
230
92b1e5ed2d5f Cleanup and documentation in debugging macros.
Sascha Wilde <wilde@intevation.de>
parents: 229
diff changeset
61
261
7707191ddb01 New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents: 252
diff changeset
62 #include "certhelp.h"
226
d7788db3bdde Make locale includes distinguishable from system includes.
Sascha Wilde <wilde@intevation.de>
parents: 224
diff changeset
63 #include "errorcodes.h"
d7788db3bdde Make locale includes distinguishable from system includes.
Sascha Wilde <wilde@intevation.de>
parents: 224
diff changeset
64 #include "portpath.h"
d7788db3bdde Make locale includes distinguishable from system includes.
Sascha Wilde <wilde@intevation.de>
parents: 224
diff changeset
65 #include "strhelp.h"
244
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
66 #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
67
113
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
68 #ifndef _WIN32
197
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
69 #define CONFDIRS ".mozilla", ".thunderbird"
308
ab69d268b5c8 Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents: 284
diff changeset
70 #define NSSSHARED ".pki/nssdb"
223
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
71 #define TARGET_LINUX 1
113
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
72 #else
197
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
73 #define CONFDIRS "Mozilla", "Thunderbird"
311
4ffc9f31b61a Fixed windows build.
Sascha Wilde <wilde@intevation.de>
parents: 309
diff changeset
74 #define NSSSHARED ""
223
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
75 #define TARGET_LINUX 0
113
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
76 #endif
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
77
229
e99e39d72af2 Adjusted LINEBUFLEN.
Sascha Wilde <wilde@intevation.de>
parents: 228
diff changeset
78 /**
e99e39d72af2 Adjusted LINEBUFLEN.
Sascha Wilde <wilde@intevation.de>
parents: 228
diff changeset
79 * @brief Length of string buffers used
e99e39d72af2 Adjusted LINEBUFLEN.
Sascha Wilde <wilde@intevation.de>
parents: 228
diff changeset
80 *
e99e39d72af2 Adjusted LINEBUFLEN.
Sascha Wilde <wilde@intevation.de>
parents: 228
diff changeset
81 * The maximal length of input is defined as 9999 (+ terminating \0).
e99e39d72af2 Adjusted LINEBUFLEN.
Sascha Wilde <wilde@intevation.de>
parents: 228
diff changeset
82 * We use it for other other input puffers besides the IPC input, too.
e99e39d72af2 Adjusted LINEBUFLEN.
Sascha Wilde <wilde@intevation.de>
parents: 228
diff changeset
83 * (One size fits all).
e99e39d72af2 Adjusted LINEBUFLEN.
Sascha Wilde <wilde@intevation.de>
parents: 228
diff changeset
84 */
e99e39d72af2 Adjusted LINEBUFLEN.
Sascha Wilde <wilde@intevation.de>
parents: 228
diff changeset
85 #define LINEBUFLEN 10000
147
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
86
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
87 /**
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
88 * @brief Global Return Code
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
89 *
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
90 * 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
91 * 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
92 * 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
93 * ORed together.
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
94 */
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
95 int return_code = 0;
44
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
96
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
97 /**
194
d4e97c9b199f Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents: 181
diff changeset
98 * @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
99 * @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
100 * 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
101 * and thunderbird.
180
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
102 */
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
103 static char *
194
d4e97c9b199f Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents: 181
diff changeset
104 get_conf_basedir()
180
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
105 {
194
d4e97c9b199f Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents: 181
diff changeset
106 char *cdir, *envvar;
180
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
107
223
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
108 if (TARGET_LINUX)
194
d4e97c9b199f Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents: 181
diff changeset
109 envvar = "HOME" ;
180
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
110 else
194
d4e97c9b199f Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents: 181
diff changeset
111 envvar = "APPDATA";
180
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
112
194
d4e97c9b199f Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents: 181
diff changeset
113 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
114 return cdir;
d4e97c9b199f Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents: 181
diff changeset
115 else
180
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
116 {
228
19de529ce7fb Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents: 227
diff changeset
117 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
118 exit(ERR_MOZ_HOMELESS);
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
119 }
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
120 }
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
121
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
122 /**
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
123 * @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
124 *
232
774e944c395b Cleand up doku.
Sascha Wilde <wilde@intevation.de>
parents: 231
diff changeset
125 * Parse the profiles.ini and extract all profile paths from that.
774e944c395b Cleand up doku.
Sascha Wilde <wilde@intevation.de>
parents: 231
diff changeset
126 * The expected data is in the form:
774e944c395b Cleand up doku.
Sascha Wilde <wilde@intevation.de>
parents: 231
diff changeset
127 *
774e944c395b Cleand up doku.
Sascha Wilde <wilde@intevation.de>
parents: 231
diff changeset
128 * [Profile99]
774e944c395b Cleand up doku.
Sascha Wilde <wilde@intevation.de>
parents: 231
diff changeset
129 * IsRelative=1
774e944c395b Cleand up doku.
Sascha Wilde <wilde@intevation.de>
parents: 231
diff changeset
130 * Path=Example/fooo.bar
774e944c395b Cleand up doku.
Sascha Wilde <wilde@intevation.de>
parents: 231
diff changeset
131 *
774e944c395b Cleand up doku.
Sascha Wilde <wilde@intevation.de>
parents: 231
diff changeset
132 * or
774e944c395b Cleand up doku.
Sascha Wilde <wilde@intevation.de>
parents: 231
diff changeset
133 * [Profile0]
774e944c395b Cleand up doku.
Sascha Wilde <wilde@intevation.de>
parents: 231
diff changeset
134 * IsRelative=0
774e944c395b Cleand up doku.
Sascha Wilde <wilde@intevation.de>
parents: 231
diff changeset
135 * Path=c:\foo\bar\baz
774e944c395b Cleand up doku.
Sascha Wilde <wilde@intevation.de>
parents: 231
diff changeset
136 *
774e944c395b Cleand up doku.
Sascha Wilde <wilde@intevation.de>
parents: 231
diff changeset
137 * Mozilla also accepts the ini file on Windows even if it is UTF-16
774e944c395b Cleand up doku.
Sascha Wilde <wilde@intevation.de>
parents: 231
diff changeset
138 * encoded but never writes UTF-16 on its own. So currently we ignore
774e944c395b Cleand up doku.
Sascha Wilde <wilde@intevation.de>
parents: 231
diff changeset
139 * this special case.
44
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
140 *
121
4bb5f295987b Fix doxygen documentation.
Sascha Wilde <wilde@intevation.de>
parents: 119
diff changeset
141 * @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
142 * @return NULL terminated array of strings containing containing the
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
143 * 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
144 * be freed by the caller.
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
145 */
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
146 static char **
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
147 get_profile_dirs (char *inifile_name)
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
148 {
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
149 char **dirs = NULL;
147
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
150 char *inifile_dirname;
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
151 FILE *inifile;
147
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
152 char line[LINEBUFLEN];
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
153 char *key;
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
154 char *value;
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
155 char path[LINEBUFLEN];
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
156 char *fqpath;
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
157 bool inprofile = false;
147
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
158 bool relative_path = false;
44
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
159
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
160 if ((inifile = fopen(inifile_name, "r")) != NULL)
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
161 {
228
19de529ce7fb Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents: 227
diff changeset
162 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
163
147
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
164 inifile_dirname = port_dirname(inifile_name);
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
165 while (fgets(line, LINEBUFLEN, inifile) != NULL)
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
166 {
147
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
167 /* Determine if we are in an profile section */
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
168 if (str_starts_with(line, "[Profile"))
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
169 {
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
170 relative_path = false;
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
171 inprofile = true;
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
172 }
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
173 else if (line[0] == '[')
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
174 inprofile = false;
147
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
175
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
176 /* If we are in a profile parse path related stuff */
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
177 if (inprofile)
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
178 {
157
a46a4b443410 Use strtok instead of strsep for portability.
Sascha Wilde <wilde@intevation.de>
parents: 147
diff changeset
179 key = strtok(line, "=");
a46a4b443410 Use strtok instead of strsep for portability.
Sascha Wilde <wilde@intevation.de>
parents: 147
diff changeset
180 value = strtok(NULL, "=");
147
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
181 str_trim(&value);
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
182 if (str_equal(key, "Path"))
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
183 {
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
184 if (relative_path)
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
185 snprintf(path, LINEBUFLEN, "%s/%s", inifile_dirname, value);
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
186 else
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
187 strncpy(path, value, LINEBUFLEN);
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
188 if ((fqpath = port_realpath(path)) != NULL)
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
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("Found profile path: '%s'\n", fqpath);
147
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
191 strv_append(&dirs, fqpath, strlen(fqpath));
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
192 free (fqpath);
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
193 }
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
194 else
175
6fa0e12ae1d2 Added more debug output.
Sascha Wilde <wilde@intevation.de>
parents: 174
diff changeset
195 {
228
19de529ce7fb Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents: 227
diff changeset
196 DEBUGPRINTF("WARN! Non existent profile path: '%s'\n", path);
175
6fa0e12ae1d2 Added more debug output.
Sascha Wilde <wilde@intevation.de>
parents: 174
diff changeset
197 return_code |= WARN_MOZ_PROFILE_DOES_NOT_EXIST;
6fa0e12ae1d2 Added more debug output.
Sascha Wilde <wilde@intevation.de>
parents: 174
diff changeset
198 }
147
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
199 }
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
200 else if (str_equal(key, "IsRelative") &&
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
201 str_starts_with(value, "1"))
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
202 relative_path = true;
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
203 }
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
204 }
179
8fafd0fc2173 get_profile_dirs(): close filedescriptor again. (found by cppcheck)
Bernhard Reiter <bernhard@intevation.de>
parents: 177
diff changeset
205 fclose(inifile);
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
206 }
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
207 else
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
208 {
228
19de529ce7fb Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents: 227
diff changeset
209 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
210 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
211 }
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
212 return dirs;
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
213 }
44
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
214
173
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
215 /**
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
216 * @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
217 *
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
218 * 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
219 * 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
220 *
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
221 * @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
222 * 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
223 * caller.
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 static char **
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
226 get_profile_inis ()
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
227 {
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
228 char **inis = NULL;
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
229 char path[LINEBUFLEN];
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
230 char *fqpath;
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
231 DIR *mozdir;
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
232 struct dirent *mozdirent;
194
d4e97c9b199f Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents: 181
diff changeset
233 char *confbase = get_conf_basedir();
197
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
234 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
235
197
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
236 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
237 {
197
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
238 snprintf(path, LINEBUFLEN, "%s/%s",
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
239 confbase,
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
240 confdirs[i]);
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
241 if ((mozdir = opendir(path)) != NULL)
180
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
242 {
197
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
243 while ((mozdirent = readdir(mozdir)) != NULL)
180
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
244 {
197
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
245 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
246 confbase,
197
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
247 confdirs[i],
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
248 mozdirent->d_name);
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
249 if (port_isdir(path)
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
250 && (strcmp(mozdirent->d_name, "..") != 0))
180
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
251 {
197
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
252 snprintf(path, LINEBUFLEN, "%s/%s/%s/%s",
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
253 confbase,
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
254 confdirs[i],
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
255 mozdirent->d_name,
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
256 "profiles.ini");
228
19de529ce7fb Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents: 227
diff changeset
257 DEBUGPRINTF("checking for %s...\n", path);
197
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
258 if ((fqpath = port_realpath(path)) != NULL)
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
259 {
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
260 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
261 DEBUGPRINTF("Found mozilla ini file: '%s'\n", fqpath);
197
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
262 free(fqpath);
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
263 }
180
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
264 }
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
265 }
197
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
266 closedir(mozdir);
180
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
267 }
197
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
268 else
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
269 {
228
19de529ce7fb Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents: 227
diff changeset
270 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
271 }
180
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
272 }
197
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
273 if (inis == NULL)
180
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
274 {
228
19de529ce7fb Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents: 227
diff changeset
275 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
276 }
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
277 return inis;
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
278 }
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
279
223
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
280 /**
231
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
281 * @brief Collect all mozilla profile directories of current user.
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
282 * @return NULL terminated array of strings containing the absolute
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
283 * path of the profile directories. The array needs to be freed by the
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
284 * caller.
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
285 */
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
286 static char**
308
ab69d268b5c8 Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents: 284
diff changeset
287 get_all_nssdb_dirs()
231
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
288 {
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
289 char **mozinis, **pdirs;
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
290 char **alldirs = NULL;
308
ab69d268b5c8 Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents: 284
diff changeset
291 /* Search Mozilla/Firefox/Thunderbird profiles */
231
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
292 if ((mozinis = get_profile_inis()) != NULL)
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
293 {
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
294 for (int i=0; mozinis[i] != NULL; i++)
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
295 {
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
296 pdirs =
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
297 get_profile_dirs(mozinis[i]);
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
298 if (pdirs != NULL)
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
299 {
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
300 for (int i=0; pdirs[i] != NULL; i++)
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
301 {
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
302 strv_append(&alldirs, pdirs[i], strlen(pdirs[i]));
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
303 }
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
304 strv_free(pdirs);
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
305 }
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
306 }
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
307 strv_free(mozinis);
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
308 }
308
ab69d268b5c8 Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents: 284
diff changeset
309 /* 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
310 if (TARGET_LINUX)
ab69d268b5c8 Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents: 284
diff changeset
311 {
ab69d268b5c8 Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents: 284
diff changeset
312 char buf[LINEBUFLEN], *fqpath;
ab69d268b5c8 Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents: 284
diff changeset
313 snprintf(buf, LINEBUFLEN, "%s/%s",
ab69d268b5c8 Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents: 284
diff changeset
314 get_conf_basedir(), NSSSHARED);
ab69d268b5c8 Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents: 284
diff changeset
315 if ((fqpath = port_realpath(buf)) != NULL)
ab69d268b5c8 Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents: 284
diff changeset
316 {
ab69d268b5c8 Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents: 284
diff changeset
317 snprintf(buf, LINEBUFLEN, "sql:%s", fqpath);
ab69d268b5c8 Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents: 284
diff changeset
318 strv_append(&alldirs, buf, strlen(buf));
ab69d268b5c8 Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents: 284
diff changeset
319 free(fqpath);
ab69d268b5c8 Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents: 284
diff changeset
320 }
ab69d268b5c8 Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents: 284
diff changeset
321 }
231
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
322 return alldirs;
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
323 }
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
324
281
0f73fe4230c1 Fixed and optimized production build.
Sascha Wilde <wilde@intevation.de>
parents: 280
diff changeset
325 #ifdef DEBUGOUTPUT
231
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
326 /**
223
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
327 * @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
328 * @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
329 */
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
330 static void
281
0f73fe4230c1 Fixed and optimized production build.
Sascha Wilde <wilde@intevation.de>
parents: 280
diff changeset
331 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
332 {
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
333 CERTCertList *list;
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
334 CERTCertListNode *node;
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
335 char *name;
224
689b94dd89a9 Wrote FindNSS to build against nss without pkg-config support (Windows).
Sascha Wilde <wilde@intevation.de>
parents: 223
diff changeset
336
223
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
337 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
338 == SECSuccess)
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
339 {
283
fb9e14f4b4c9 Show which store is listed in debug certificate listings.
Sascha Wilde <wilde@intevation.de>
parents: 281
diff changeset
340 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
341 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
342 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
343 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
344 name = node->appData;
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
345
281
0f73fe4230c1 Fixed and optimized production build.
Sascha Wilde <wilde@intevation.de>
parents: 280
diff changeset
346 DEBUGPRINTF("Found certificate \"%s\"\n", name);
223
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
347 }
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
348 CERT_DestroyCertList(list);
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
349 NSS_Shutdown();
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
350 }
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
351 else
281
0f73fe4230c1 Fixed and optimized production build.
Sascha Wilde <wilde@intevation.de>
parents: 280
diff changeset
352 {
0f73fe4230c1 Fixed and optimized production build.
Sascha Wilde <wilde@intevation.de>
parents: 280
diff changeset
353 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
354 }
223
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
355 }
281
0f73fe4230c1 Fixed and optimized production build.
Sascha Wilde <wilde@intevation.de>
parents: 280
diff changeset
356 #endif
223
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
357
261
7707191ddb01 New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents: 252
diff changeset
358 /**
7707191ddb01 New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents: 252
diff changeset
359 * @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
360 *
7707191ddb01 New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents: 252
diff changeset
361 * Should be freed by caller.
7707191ddb01 New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents: 252
diff changeset
362 * @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
363 * @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
364 */
7707191ddb01 New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents: 252
diff changeset
365 static char *
7707191ddb01 New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents: 252
diff changeset
366 nss_cert_name(SECItem *secitemp)
7707191ddb01 New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents: 252
diff changeset
367 { char *cn_str, *o_str, *name;
7707191ddb01 New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents: 252
diff changeset
368 size_t name_len;
7707191ddb01 New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents: 252
diff changeset
369 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
370 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
371 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
372 name = (char *)xmalloc(name_len);
7707191ddb01 New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents: 252
diff changeset
373 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
374 free(cn_str);
7707191ddb01 New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents: 252
diff changeset
375 free(o_str);
7707191ddb01 New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents: 252
diff changeset
376 return name;
7707191ddb01 New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents: 252
diff changeset
377 }
7707191ddb01 New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents: 252
diff changeset
378
276
ea9c5bbc6496 Added missing function documentation.
Sascha Wilde <wilde@intevation.de>
parents: 269
diff changeset
379 /**
ea9c5bbc6496 Added missing function documentation.
Sascha Wilde <wilde@intevation.de>
parents: 269
diff changeset
380 * @brief Convert a base64 encoded DER certificate to SECItem
ea9c5bbc6496 Added missing function documentation.
Sascha Wilde <wilde@intevation.de>
parents: 269
diff changeset
381 * @param[in] b64 pointer to the base64 encoded certificate
ea9c5bbc6496 Added missing function documentation.
Sascha Wilde <wilde@intevation.de>
parents: 269
diff changeset
382 * @param[in] b64len length of the base64 encoded certificate
ea9c5bbc6496 Added missing function documentation.
Sascha Wilde <wilde@intevation.de>
parents: 269
diff changeset
383 * @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
384 * raw DER certifiacte.
ea9c5bbc6496 Added missing function documentation.
Sascha Wilde <wilde@intevation.de>
parents: 269
diff changeset
385 * @returns true on success and false on failure
ea9c5bbc6496 Added missing function documentation.
Sascha Wilde <wilde@intevation.de>
parents: 269
diff changeset
386 */
244
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
387 static bool
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
388 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
389 {
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
390 unsigned char *dercert = NULL;
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
391 size_t dercertlen;
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
392
245
fbd74e2370de Error out, when base64 decode results in empty data.
Sascha Wilde <wilde@intevation.de>
parents: 244
diff changeset
393 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
394 b64, b64len) == 0) &&
fbd74e2370de Error out, when base64 decode results in empty data.
Sascha Wilde <wilde@intevation.de>
parents: 244
diff changeset
395 (dercertlen > 0))
244
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
396 {
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
397 secitem->data = dercert;
246
1efe494c3d2b Explicit tyoe cast to fix warning on 64bit Jessie.
Sascha Wilde <wilde@intevation.de>
parents: 245
diff changeset
398 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
399 return true;
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 else
281
0f73fe4230c1 Fixed and optimized production build.
Sascha Wilde <wilde@intevation.de>
parents: 280
diff changeset
402 {
0f73fe4230c1 Fixed and optimized production build.
Sascha Wilde <wilde@intevation.de>
parents: 280
diff changeset
403 DEBUGPRINTF("Base64 decode failed for: %s\n", b64);
0f73fe4230c1 Fixed and optimized production build.
Sascha Wilde <wilde@intevation.de>
parents: 280
diff changeset
404 }
261
7707191ddb01 New function to generate certificate name.
Sascha Wilde <wilde@intevation.de>
parents: 252
diff changeset
405 return false;
244
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
406 }
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
407
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
408 /**
277
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
409 * @brief Store DER certificate in mozilla store.
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
410 * @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
411 * store to manipulate.
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
412 * @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
413 * to install
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
414 * @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
415 */
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
416 static bool
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
417 import_cert(char *pdir, SECItem *dercert)
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
418 {
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
419 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
420 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
421 CERTCertificate *cert = NULL;
277
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
422 bool success = false;
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
423 char *cert_name = nss_cert_name(dercert);
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
424
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
425 DEBUGPRINTF("INSTALLING cert: '%s' to: %s\n", cert_name, pdir);
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
426 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
427 {
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
428 pk11slot = PK11_GetInternalKeySlot();
309
fa37384b86b6 Add trust "Trusted CA to issue server certificates" to certs on install.
Sascha Wilde <wilde@intevation.de>
parents: 308
diff changeset
429 cert = CERT_DecodeCertFromPackage((char *)dercert->data,
fa37384b86b6 Add trust "Trusted CA to issue server certificates" to certs on install.
Sascha Wilde <wilde@intevation.de>
parents: 308
diff changeset
430 (int)dercert->len);
fa37384b86b6 Add trust "Trusted CA to issue server certificates" to certs on install.
Sascha Wilde <wilde@intevation.de>
parents: 308
diff changeset
431 trust = (CERTCertTrust *)xmalloc(sizeof(CERTCertTrust));
fa37384b86b6 Add trust "Trusted CA to issue server certificates" to certs on install.
Sascha Wilde <wilde@intevation.de>
parents: 308
diff changeset
432 CERT_DecodeTrustString(trust, "C");
fa37384b86b6 Add trust "Trusted CA to issue server certificates" to certs on install.
Sascha Wilde <wilde@intevation.de>
parents: 308
diff changeset
433 if ((PK11_ImportCert(pk11slot, cert, CK_INVALID_HANDLE,
fa37384b86b6 Add trust "Trusted CA to issue server certificates" to certs on install.
Sascha Wilde <wilde@intevation.de>
parents: 308
diff changeset
434 cert_name, PR_FALSE)
fa37384b86b6 Add trust "Trusted CA to issue server certificates" to certs on install.
Sascha Wilde <wilde@intevation.de>
parents: 308
diff changeset
435 == SECSuccess) &&
fa37384b86b6 Add trust "Trusted CA to issue server certificates" to certs on install.
Sascha Wilde <wilde@intevation.de>
parents: 308
diff changeset
436 (CERT_ChangeCertTrust(CERT_GetDefaultCertDB(), cert, trust)
fa37384b86b6 Add trust "Trusted CA to issue server certificates" to certs on install.
Sascha Wilde <wilde@intevation.de>
parents: 308
diff changeset
437 == SECSuccess))
277
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
438 {
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
439 success = true;
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
440 }
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
441 else
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
442 {
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
443 DEBUGPRINTF("Failed to install certificate '%s' to '%s'!\n", cert_name, pdir);
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
444 }
309
fa37384b86b6 Add trust "Trusted CA to issue server certificates" to certs on install.
Sascha Wilde <wilde@intevation.de>
parents: 308
diff changeset
445 CERT_DestroyCertificate (cert);
312
4033c16beb04 Removed accidental use of nss PORT_Free.
Sascha Wilde <wilde@intevation.de>
parents: 311
diff changeset
446 free(trust);
277
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
447 PK11_FreeSlot(pk11slot);
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
448 NSS_Shutdown();
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
449 }
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
450 else
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
451 {
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
452 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
453 }
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
454
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
455 free(cert_name);
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
456 return success;
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
457 }
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
458
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
459 /**
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
460 * @brief Remove DER certificate from mozilla store.
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
461 * @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
462 * store to manipulate.
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
463 * @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
464 * to remove
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
465 * @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
466 */
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
467 static bool
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
468 remove_cert(char *pdir, SECItem *dercert)
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
469 {
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
470 PK11SlotInfo *pk11slot = NULL;
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
471 bool success = false;
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
472 char *cert_name = nss_cert_name(dercert);
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
473 CERTCertificate *cert = NULL;
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
474
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
475 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
476 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
477 {
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
478 pk11slot = PK11_GetInternalKeySlot();
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
479 cert = PK11_FindCertFromDERCertItem(pk11slot,
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
480 dercert, NULL);
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
481 if (cert != NULL)
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
482 {
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
483 if (SEC_DeletePermCertificate(cert) == SECSuccess)
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
484 {
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
485 success = true;
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
486 }
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
487 else
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
488 {
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
489 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
490 }
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
491 CERT_DestroyCertificate(cert);
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
492 }
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
493 else
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
494 {
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
495 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
496 }
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
497 PK11_FreeSlot(pk11slot);
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
498 NSS_Shutdown();
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
499 }
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
500 else
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
501 {
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
502 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
503 }
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
504 free(cert_name);
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
505 return success;
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
506 }
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
507
22408d797c92 Factor out functions for cert install/remove.
Sascha Wilde <wilde@intevation.de>
parents: 276
diff changeset
508 /**
279
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
509 * @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
510 *
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
511 * The function must have the signature:
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
512 *
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
513 * 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
514 *
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
515 * 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
516 * 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
517 * and false on failure.
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
518 *
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
519 * This function is intended wor use with the import_cert and
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
520 * remove_cert functions.
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
521 *
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
522 * @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
523 * @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
524 * the list will be change (emptied)!
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
525 * @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
526 * @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
527 */
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
528 bool
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
529 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
530 seciteml_t **certs, char **pdirs)
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
531 {
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
532 SECItem *cert;
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
533 bool success = true;
280
6c4b3ff4a356 Fixed white space.
Sascha Wilde <wilde@intevation.de>
parents: 279
diff changeset
534
279
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
535 while ((cert = seciteml_pop(certs)) != NULL)
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
536 {
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
537 for (int i=0; pdirs[i] != NULL; i++)
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
538 {
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
539 if (! (*fn)(pdirs[i], cert))
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
540 success = false;
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
541 }
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
542 free(cert->data);
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
543 free(cert);
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
544 }
280
6c4b3ff4a356 Fixed white space.
Sascha Wilde <wilde@intevation.de>
parents: 279
diff changeset
545
279
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
546 return success;
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
547 }
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
548
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
549 /**
244
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
550 * @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
551 *
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
552 * 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
553 * 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
554 * certificates in DER format.
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
555 * @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
556 * @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
557 */
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
558 static void
315
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
559 parse_commands (FILE *stream,
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
560 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
561 {
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
562 char inpl[LINEBUFLEN];
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
563 size_t inpllen;
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
564 bool parserr = true;
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
565 SECItem secitem;
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
566
315
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
567 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
568 {
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
569 inpllen = strnlen(inpl, LINEBUFLEN);
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
570 /* Validate input line:
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
571 * - 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
572 * - must start with "*:"
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
573 */
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
574 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
575 /* Now parse Input */
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
576 switch(inpl[0])
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
577 {
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
578 case 'R':
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
579 parserr = true;
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
580 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
581 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
582 {
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
583 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
584 parserr = false;
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
585 }
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
586 break;
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
587 case 'I':
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
588 parserr = true;
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
589 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
590 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
591 {
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
592 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
593 parserr = false;
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 break;
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
596 default:
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
597 parserr = true;
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
598 }
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
599 else
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 parserr = true;
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
602 }
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
603
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
604 if (parserr)
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
605 {
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
606 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
607 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
608 }
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
609 }
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
610 }
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
611
173
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
612
113
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
613 int
315
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
614 main (int argc, char **argv)
113
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
615 {
308
ab69d268b5c8 Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents: 284
diff changeset
616 char **dbdirs;
244
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
617 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
618 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
619 FILE *input_stream;
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
620
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
621 switch (argc)
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
622 {
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
623 case 1:
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
624 DEBUGPRINTF("Opening STDIN for input..\n.");
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
625 input_stream = stdin;
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
626 break;
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
627 case 2:
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
628 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
629 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
630 {
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
631 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
632 argv[1]);
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
633 return_code = ERR_MOZ_FAILED_TO_OPEN_INPUT;
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
634 goto exit;
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
635 }
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
636 break;
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
637 default:
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
638 DEBUGPRINTF("FATAL: Wrong number of arguments!\n");
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
639 return_code = ERR_MOZ_WRONG_ARGC;
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
640 goto exit;
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
641 }
244
0145d2401f46 Input parser works. Added debug output for collected cert data.
Sascha Wilde <wilde@intevation.de>
parents: 243
diff changeset
642
308
ab69d268b5c8 Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents: 284
diff changeset
643 dbdirs =
ab69d268b5c8 Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents: 284
diff changeset
644 get_all_nssdb_dirs();
235
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
645
308
ab69d268b5c8 Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents: 284
diff changeset
646 if (dbdirs != NULL)
231
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
647 {
315
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
648 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
649
281
0f73fe4230c1 Fixed and optimized production build.
Sascha Wilde <wilde@intevation.de>
parents: 280
diff changeset
650 #ifdef DEBUGOUTPUT
284
a0c5eba8eb41 Added missing line breaks in debug output.
Sascha Wilde <wilde@intevation.de>
parents: 283
diff changeset
651 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
652 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
653 DEBUG_nss_list_certs(dbdirs[i]);
281
0f73fe4230c1 Fixed and optimized production build.
Sascha Wilde <wilde@intevation.de>
parents: 280
diff changeset
654 #endif
263
1fa607af6332 Next baby step: we can import certificates!
Sascha Wilde <wilde@intevation.de>
parents: 261
diff changeset
655
308
ab69d268b5c8 Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents: 284
diff changeset
656 if (! apply_to_certs_and_profiles(remove_cert, &certs_to_remove, dbdirs))
279
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
657 return_code |= WARN_MOZ_COULD_NOT_REMOVE_CERT;
280
6c4b3ff4a356 Fixed white space.
Sascha Wilde <wilde@intevation.de>
parents: 279
diff changeset
658
308
ab69d268b5c8 Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents: 284
diff changeset
659 if (! apply_to_certs_and_profiles(import_cert, &certs_to_add, dbdirs))
279
cb5f082e90c5 Factor out the iteration over profiles and certs.
Sascha Wilde <wilde@intevation.de>
parents: 278
diff changeset
660 return_code |= WARN_MOZ_COULD_NOT_ADD_CERT;
280
6c4b3ff4a356 Fixed white space.
Sascha Wilde <wilde@intevation.de>
parents: 279
diff changeset
661
281
0f73fe4230c1 Fixed and optimized production build.
Sascha Wilde <wilde@intevation.de>
parents: 280
diff changeset
662 #ifdef DEBUGOUTPUT
284
a0c5eba8eb41 Added missing line breaks in debug output.
Sascha Wilde <wilde@intevation.de>
parents: 283
diff changeset
663 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
664 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
665 DEBUG_nss_list_certs(dbdirs[i]);
281
0f73fe4230c1 Fixed and optimized production build.
Sascha Wilde <wilde@intevation.de>
parents: 280
diff changeset
666 #endif
280
6c4b3ff4a356 Fixed white space.
Sascha Wilde <wilde@intevation.de>
parents: 279
diff changeset
667
308
ab69d268b5c8 Add NSS shared DB on Linux to stores operated on.
Sascha Wilde <wilde@intevation.de>
parents: 284
diff changeset
668 strv_free(dbdirs);
231
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
669 }
315
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
670
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
671 fclose(input_stream);
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
672
b832231640ab Read from file instead of stdin, if given.
Sascha Wilde <wilde@intevation.de>
parents: 312
diff changeset
673 exit:
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
674 exit(return_code);
44
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
675 }

http://wald.intevation.org/projects/trustbridge/