annotate cinst/mozilla.c @ 241:74d6e33c7d38

Added missing free().
author Sascha Wilde <wilde@intevation.de>
date Fri, 28 Mar 2014 13:33:58 +0100
parents 0c4d65a7cd14
children 4b67cc2d4dad
rev   line source
121
4bb5f295987b Fix doxygen documentation.
Sascha Wilde <wilde@intevation.de>
parents: 119
diff changeset
1 /**
4bb5f295987b Fix doxygen documentation.
Sascha Wilde <wilde@intevation.de>
parents: 119
diff changeset
2 * @file
4bb5f295987b Fix doxygen documentation.
Sascha Wilde <wilde@intevation.de>
parents: 119
diff changeset
3 * @brief Mozilla installation process
99
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
4 *
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
5 * Reads from stdin a list of instructions in the form:
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
6 *
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
7 * I:<base64 DER econded certificate>\r\n
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
8 * R:<base64 DER econded certificate>\r\n
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
9 * ...
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
10 *
130
ffb20e76e7d0 Fix max line length documentation
Andre Heinecke <aheinecke@intevation.de>
parents: 121
diff changeset
11 * The maximum size of an input line is 9999 characters
99
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
12 * (including the \r\n) at the end of the line.
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
13 *
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
14 * Certificates marked with I: will be installed and the ones
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
15 * marked with R: will be searched and if available removed from
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
16 * the databases.
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
17 *
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
18 * This tool tries to find all NSS databases the user has
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
19 * access to and to execute the instructions on all of them.
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
20 *
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
21 * If there are other processes accessing the databases the caller
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
22 * has to ensure that those are terminated before this process is
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
23 * executed.
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
24 *
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
25 * 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
26 * as defined in errorcodes.h otherwise.
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
27 *
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
28 * 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
29 * 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
30 * with the profile name that it modified.
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
31 *
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
32 */
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
33
235
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
34 /**
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
35 * @brief Needs to eb defined to get strnlen()
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
36 */
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
37 #define _POSIX_C_SOURCE 200809L
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
38
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
39 /* REMOVEME: */
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
40 #include <unistd.h>
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
41
173
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
42 #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
43 #include <cert.h>
689b94dd89a9 Wrote FindNSS to build against nss without pkg-config support (Windows).
Sascha Wilde <wilde@intevation.de>
parents: 223
diff changeset
44 #include <certt.h>
689b94dd89a9 Wrote FindNSS to build against nss without pkg-config support (Windows).
Sascha Wilde <wilde@intevation.de>
parents: 223
diff changeset
45 #include <nss.h>
689b94dd89a9 Wrote FindNSS to build against nss without pkg-config support (Windows).
Sascha Wilde <wilde@intevation.de>
parents: 223
diff changeset
46 #include <pk11pub.h>
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
47 #include <stdbool.h>
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
48 #include <stdio.h>
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
49 #include <stdlib.h>
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
50 #include <string.h>
173
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
51 #include <sys/types.h>
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
52
230
92b1e5ed2d5f Cleanup and documentation in debugging macros.
Sascha Wilde <wilde@intevation.de>
parents: 229
diff changeset
53 #define DEBUGPREFIX "MOZ-"
226
d7788db3bdde Make locale includes distinguishable from system includes.
Sascha Wilde <wilde@intevation.de>
parents: 224
diff changeset
54 #include "debug.h"
230
92b1e5ed2d5f Cleanup and documentation in debugging macros.
Sascha Wilde <wilde@intevation.de>
parents: 229
diff changeset
55
226
d7788db3bdde Make locale includes distinguishable from system includes.
Sascha Wilde <wilde@intevation.de>
parents: 224
diff changeset
56 #include "errorcodes.h"
d7788db3bdde Make locale includes distinguishable from system includes.
Sascha Wilde <wilde@intevation.de>
parents: 224
diff changeset
57 #include "portpath.h"
d7788db3bdde Make locale includes distinguishable from system includes.
Sascha Wilde <wilde@intevation.de>
parents: 224
diff changeset
58 #include "strhelp.h"
113
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
59
228
19de529ce7fb Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents: 227
diff changeset
60
113
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
61 #ifndef _WIN32
197
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
62 #define CONFDIRS ".mozilla", ".thunderbird"
223
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
63 #define TARGET_LINUX 1
113
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
64 #else
197
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
65 #define CONFDIRS "Mozilla", "Thunderbird"
223
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
66 #define TARGET_LINUX 0
113
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
67 #endif
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
68
229
e99e39d72af2 Adjusted LINEBUFLEN.
Sascha Wilde <wilde@intevation.de>
parents: 228
diff changeset
69 /**
e99e39d72af2 Adjusted LINEBUFLEN.
Sascha Wilde <wilde@intevation.de>
parents: 228
diff changeset
70 * @brief Length of string buffers used
e99e39d72af2 Adjusted LINEBUFLEN.
Sascha Wilde <wilde@intevation.de>
parents: 228
diff changeset
71 *
e99e39d72af2 Adjusted LINEBUFLEN.
Sascha Wilde <wilde@intevation.de>
parents: 228
diff changeset
72 * The maximal length of input is defined as 9999 (+ terminating \0).
e99e39d72af2 Adjusted LINEBUFLEN.
Sascha Wilde <wilde@intevation.de>
parents: 228
diff changeset
73 * 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
74 * (One size fits all).
e99e39d72af2 Adjusted LINEBUFLEN.
Sascha Wilde <wilde@intevation.de>
parents: 228
diff changeset
75 */
e99e39d72af2 Adjusted LINEBUFLEN.
Sascha Wilde <wilde@intevation.de>
parents: 228
diff changeset
76 #define LINEBUFLEN 10000
147
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
77
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
78 /**
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
79 * @brief Global Return Code
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
80 *
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
81 * 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
82 * 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
83 * 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
84 * ORed together.
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
85 */
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
86 int return_code = 0;
44
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
87
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
88 /**
194
d4e97c9b199f Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents: 181
diff changeset
89 * @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
90 * @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
91 * 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
92 * and thunderbird.
180
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
93 */
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
94 static char *
194
d4e97c9b199f Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents: 181
diff changeset
95 get_conf_basedir()
180
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
96 {
194
d4e97c9b199f Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents: 181
diff changeset
97 char *cdir, *envvar;
180
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
98
223
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
99 if (TARGET_LINUX)
194
d4e97c9b199f Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents: 181
diff changeset
100 envvar = "HOME" ;
180
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
101 else
194
d4e97c9b199f Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents: 181
diff changeset
102 envvar = "APPDATA";
180
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
103
194
d4e97c9b199f Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents: 181
diff changeset
104 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
105 return cdir;
d4e97c9b199f Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents: 181
diff changeset
106 else
180
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
107 {
228
19de529ce7fb Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents: 227
diff changeset
108 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
109 exit(ERR_MOZ_HOMELESS);
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
110 }
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
111 }
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
112
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
113 /**
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
114 * @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
115 *
232
774e944c395b Cleand up doku.
Sascha Wilde <wilde@intevation.de>
parents: 231
diff changeset
116 * Parse the profiles.ini and extract all profile paths from that.
774e944c395b Cleand up doku.
Sascha Wilde <wilde@intevation.de>
parents: 231
diff changeset
117 * The expected data is in the form:
774e944c395b Cleand up doku.
Sascha Wilde <wilde@intevation.de>
parents: 231
diff changeset
118 *
774e944c395b Cleand up doku.
Sascha Wilde <wilde@intevation.de>
parents: 231
diff changeset
119 * [Profile99]
774e944c395b Cleand up doku.
Sascha Wilde <wilde@intevation.de>
parents: 231
diff changeset
120 * IsRelative=1
774e944c395b Cleand up doku.
Sascha Wilde <wilde@intevation.de>
parents: 231
diff changeset
121 * Path=Example/fooo.bar
774e944c395b Cleand up doku.
Sascha Wilde <wilde@intevation.de>
parents: 231
diff changeset
122 *
774e944c395b Cleand up doku.
Sascha Wilde <wilde@intevation.de>
parents: 231
diff changeset
123 * or
774e944c395b Cleand up doku.
Sascha Wilde <wilde@intevation.de>
parents: 231
diff changeset
124 * [Profile0]
774e944c395b Cleand up doku.
Sascha Wilde <wilde@intevation.de>
parents: 231
diff changeset
125 * IsRelative=0
774e944c395b Cleand up doku.
Sascha Wilde <wilde@intevation.de>
parents: 231
diff changeset
126 * Path=c:\foo\bar\baz
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 * 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
129 * 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
130 * this special case.
44
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
131 *
121
4bb5f295987b Fix doxygen documentation.
Sascha Wilde <wilde@intevation.de>
parents: 119
diff changeset
132 * @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
133 * @return NULL terminated array of strings containing containing the
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
134 * 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
135 * be freed by the caller.
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
136 */
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
137 static char **
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
138 get_profile_dirs (char *inifile_name)
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
139 {
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
140 char **dirs = NULL;
147
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
141 char *inifile_dirname;
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
142 FILE *inifile;
147
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
143 char line[LINEBUFLEN];
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
144 char *key;
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
145 char *value;
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
146 char path[LINEBUFLEN];
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
147 char *fqpath;
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
148 bool inprofile = false;
147
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
149 bool relative_path = false;
44
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
150
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
151 if ((inifile = fopen(inifile_name, "r")) != NULL)
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
152 {
228
19de529ce7fb Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents: 227
diff changeset
153 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
154
147
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
155 inifile_dirname = port_dirname(inifile_name);
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
156 while (fgets(line, LINEBUFLEN, inifile) != NULL)
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
157 {
147
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
158 /* Determine if we are in an profile section */
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
159 if (str_starts_with(line, "[Profile"))
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
160 {
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
161 relative_path = false;
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
162 inprofile = true;
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
163 }
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
164 else if (line[0] == '[')
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
165 inprofile = false;
147
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
166
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
167 /* If we are in a profile parse path related stuff */
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
168 if (inprofile)
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
169 {
157
a46a4b443410 Use strtok instead of strsep for portability.
Sascha Wilde <wilde@intevation.de>
parents: 147
diff changeset
170 key = strtok(line, "=");
a46a4b443410 Use strtok instead of strsep for portability.
Sascha Wilde <wilde@intevation.de>
parents: 147
diff changeset
171 value = strtok(NULL, "=");
147
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
172 str_trim(&value);
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
173 if (str_equal(key, "Path"))
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
174 {
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
175 if (relative_path)
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
176 snprintf(path, LINEBUFLEN, "%s/%s", inifile_dirname, value);
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
177 else
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
178 strncpy(path, value, LINEBUFLEN);
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
179 if ((fqpath = port_realpath(path)) != NULL)
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
180 {
228
19de529ce7fb Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents: 227
diff changeset
181 DEBUGPRINTF("Found profile path: '%s'\n", fqpath);
147
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
182 strv_append(&dirs, fqpath, strlen(fqpath));
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
183 free (fqpath);
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
184 }
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
185 else
175
6fa0e12ae1d2 Added more debug output.
Sascha Wilde <wilde@intevation.de>
parents: 174
diff changeset
186 {
228
19de529ce7fb Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents: 227
diff changeset
187 DEBUGPRINTF("WARN! Non existent profile path: '%s'\n", path);
175
6fa0e12ae1d2 Added more debug output.
Sascha Wilde <wilde@intevation.de>
parents: 174
diff changeset
188 return_code |= WARN_MOZ_PROFILE_DOES_NOT_EXIST;
6fa0e12ae1d2 Added more debug output.
Sascha Wilde <wilde@intevation.de>
parents: 174
diff changeset
189 }
147
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
190 }
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
191 else if (str_equal(key, "IsRelative") &&
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
192 str_starts_with(value, "1"))
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
193 relative_path = true;
fc9af77b06b9 Completed profile.ini parser.
Sascha Wilde <wilde@intevation.de>
parents: 130
diff changeset
194 }
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
195 }
179
8fafd0fc2173 get_profile_dirs(): close filedescriptor again. (found by cppcheck)
Bernhard Reiter <bernhard@intevation.de>
parents: 177
diff changeset
196 fclose(inifile);
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
197 }
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
198 else
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
199 {
228
19de529ce7fb Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents: 227
diff changeset
200 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
201 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
202 }
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
203 return dirs;
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
204 }
44
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
205
173
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
206 /**
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
207 * @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
208 *
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
209 * 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
210 * 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
211 *
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
212 * @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
213 * 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
214 * caller.
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 static char **
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
217 get_profile_inis ()
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
218 {
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
219 char **inis = NULL;
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
220 char path[LINEBUFLEN];
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
221 char *fqpath;
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
222 DIR *mozdir;
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
223 struct dirent *mozdirent;
194
d4e97c9b199f Use %APPDATA% as config bse dir on windows. Much simpler.
Sascha Wilde <wilde@intevation.de>
parents: 181
diff changeset
224 char *confbase = get_conf_basedir();
197
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
225 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
226
197
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
227 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
228 {
197
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
229 snprintf(path, LINEBUFLEN, "%s/%s",
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
230 confbase,
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
231 confdirs[i]);
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
232 if ((mozdir = opendir(path)) != NULL)
180
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
233 {
197
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
234 while ((mozdirent = readdir(mozdir)) != NULL)
180
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
235 {
197
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
236 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
237 confbase,
197
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
238 confdirs[i],
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
239 mozdirent->d_name);
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
240 if (port_isdir(path)
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
241 && (strcmp(mozdirent->d_name, "..") != 0))
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 snprintf(path, LINEBUFLEN, "%s/%s/%s/%s",
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
244 confbase,
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
245 confdirs[i],
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
246 mozdirent->d_name,
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
247 "profiles.ini");
228
19de529ce7fb Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents: 227
diff changeset
248 DEBUGPRINTF("checking for %s...\n", path);
197
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
249 if ((fqpath = port_realpath(path)) != NULL)
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
250 {
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
251 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
252 DEBUGPRINTF("Found mozilla ini file: '%s'\n", fqpath);
197
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
253 free(fqpath);
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
254 }
180
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
255 }
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
256 }
197
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
257 closedir(mozdir);
180
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
258 }
197
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
259 else
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
260 {
228
19de529ce7fb Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents: 227
diff changeset
261 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
262 }
180
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
263 }
197
5d380b662198 Search for thunderbird profiles, too.
Sascha Wilde <wilde@intevation.de>
parents: 195
diff changeset
264 if (inis == NULL)
180
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
265 {
228
19de529ce7fb Moved debug prefix to macro and added component specific prefix.
Sascha Wilde <wilde@intevation.de>
parents: 227
diff changeset
266 DEBUGPRINTF("No ini files found - will do nothing!\n");
180
344b8a79ad2e Implemented detection profile paths for Windows Vista/7.
Sascha Wilde <wilde@intevation.de>
parents: 177
diff changeset
267 exit(WARN_MOZ_NO_PROFILES);
173
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
268 }
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
269 return inis;
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
270 }
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
271
223
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
272 /**
231
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
273 * @brief Collect all mozilla profile directories of current user.
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
274 * @return NULL terminated array of strings containing the absolute
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
275 * path of the profile directories. The array needs to be freed by the
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
276 * caller.
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
277 */
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
278 static char**
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
279 get_all_profile_dirs()
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
280 {
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
281 char **mozinis, **pdirs;
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
282 char **alldirs = NULL;
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
283 if ((mozinis = get_profile_inis()) != NULL)
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
284 {
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
285 for (int i=0; mozinis[i] != NULL; i++)
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
286 {
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
287 pdirs =
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
288 get_profile_dirs(mozinis[i]);
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
289 if (pdirs != NULL)
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
290 {
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
291 for (int i=0; pdirs[i] != NULL; i++)
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
292 {
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
293 strv_append(&alldirs, pdirs[i], strlen(pdirs[i]));
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
294 }
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
295 strv_free(pdirs);
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
296 }
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
297 }
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
298 strv_free(mozinis);
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
299 }
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
300 return alldirs;
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
301 }
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
302
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
303 /**
223
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
304 * @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
305 * @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
306 */
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
307 static void
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
308 nss_list_certs (char *confdir)
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
309 {
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
310 CERTCertList *list;
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
311 CERTCertListNode *node;
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
312 char *name;
224
689b94dd89a9 Wrote FindNSS to build against nss without pkg-config support (Windows).
Sascha Wilde <wilde@intevation.de>
parents: 223
diff changeset
313
223
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
314 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
315 == SECSuccess)
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
316 {
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
317 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
318 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
319 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
320 name = node->appData;
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
321
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
322 printf ("Found certificate \"%s\"\n", name);
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
323 }
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
324 CERT_DestroyCertList(list);
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
325 NSS_Shutdown();
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
326 }
d29997e09177 NSS first Blood. Added code to list certs in found stores.
Sascha Wilde <wilde@intevation.de>
parents: 197
diff changeset
327 else
227
29467940b07b Fixed naming of debugging print macro.
Sascha Wilde <wilde@intevation.de>
parents: 226
diff changeset
328 DEBUGPRINTF("Could not open nss cer store in %s!", confdir);
223
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
173
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
331
113
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
332 int
173
a9e4454dee97 Implemented searching $HOME/.mozilla for profiles.ini on Linux.
Sascha Wilde <wilde@intevation.de>
parents: 157
diff changeset
333 main ()
113
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
334 {
235
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
335 char inpl[LINEBUFLEN];
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
336 size_t inpllen;
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
337 char *dercert;
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
338 size_t dercertlen;
231
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
339 char **pdirs;
235
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
340 bool parserr = true;
231
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
341 pdirs =
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
342 get_all_profile_dirs();
235
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
343
231
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
344 if (pdirs != NULL)
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
345 {
235
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
346 while ( fgets(inpl, LINEBUFLEN, stdin) != NULL )
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
347 {
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
348 inpllen = strnlen(inpl, LINEBUFLEN);
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
349 /* Validate input line:
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
350 * - must be (much) longer than 3 characters
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
351 * - must start with "*:"
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
352 */
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
353 if ((inpllen > 3) && (inpl[1] == ':'))
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
354 /* Now parse Input */
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
355 switch(inpl[0])
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
356 {
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
357 case 'R':
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
358 parserr = true;
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
359 DEBUGPRINTF("Removing Certificate: %s", &inpl[2]);
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
360 if ( str_base64_decode(&dercert, &dercertlen,
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
361 &inpl[2], inpllen-2) == 0 )
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
362 {
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
363 DEBUGPRINTF("Successfully b64 decoded cert: '");
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
364 write(2, dercert, dercertlen);
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
365 fprintf(stderr,"'\n");
241
74d6e33c7d38 Added missing free().
Sascha Wilde <wilde@intevation.de>
parents: 235
diff changeset
366 free(dercert);
235
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
367 parserr = false;
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
368 }
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
369 else
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
370 DEBUGPRINTF("Base64 decoded failed!\n'");
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
371 break;
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
372 case 'I':
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
373 DEBUGPRINTF("Installing Certificate: %s", &inpl[2]);
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
374 parserr = false;
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
375 break;
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
376 default:
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
377 parserr = true;
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
378 }
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
379 else
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
380 {
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
381 parserr = true;
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
382 }
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
383
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
384 if (parserr)
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
385 {
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
386 DEBUGPRINTF("FATAL: Invalid input: %s\n", inpl);
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
387 exit(ERR_MOZ_INVALID_INPUT);
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
388 }
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
389 }
0c4d65a7cd14 Started to write input parser.
Sascha Wilde <wilde@intevation.de>
parents: 232
diff changeset
390
231
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
391 for (int i=0; pdirs[i] != NULL; i++)
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
392 {
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
393 puts(pdirs[i]);
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
394 nss_list_certs(pdirs[i]);
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
395 }
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
396 strv_free(pdirs);
c342b93c5bd1 Refactoring.
Sascha Wilde <wilde@intevation.de>
parents: 230
diff changeset
397 }
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
398 exit(return_code);
44
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
399 }

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