annotate cinst/mozilla.c @ 119:24ca8e2ceecf

First step of simple mozilla ini parser extracts profile path configuration lines and prints them to stdout for debugging..
author Sascha Wilde <wilde@intevation.de>
date Sat, 22 Mar 2014 17:46:12 +0100
parents 02ad0922c01f
children 4bb5f295987b
rev   line source
99
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
1 /* @file Mozilla installation process
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
2 *
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
3 * 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
4 *
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
5 * I:<base64 DER econded certificate>\r\n
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
6 * R:<base64 DER econded certificate>\r\n
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
7 * ...
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
8 *
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
9 * The maximum size of an input line is 1000 characters
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
10 * (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
11 *
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
12 * 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
13 * 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
14 * the databases.
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
15 *
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
16 * 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
17 * 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
18 *
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
19 * 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
20 * 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
21 * executed.
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
22 *
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
23 * 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
24 * as defined in errorcodes.h otherwise.
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
25 *
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
26 * 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
27 * 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
28 * with the profile name that it modified.
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
29 *
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
30 */
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
31
44
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
32 /* @brief IniParser for mozilla profiles.ini
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
33 *
110
0c8ea71a89cd fixed whitespace.
Sascha Wilde <wilde@intevation.de>
parents: 99
diff changeset
34 * Parse data to find values formed in
44
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
35 *
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
36 * [Profile99]
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
37 * IsRelative=1
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
38 * Path=Profiles/fooo.bar
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
39 *
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
40 * or
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
41 * [Profile0]
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
42 * IsRelative=0
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
43 * Path=c:\foo\bar\baz
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
44 *
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
45 * Mozilla also accepts the ini file on Windows even if it is UTF-16
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
46 * encoded.
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
47 * */
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
48
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
49 #include <stdbool.h>
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
50 #include <stdio.h>
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
51 #include <stdlib.h>
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
52 #include <string.h>
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
53
113
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
54 #include <errorcodes.h>
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
55 #include <strhelp.h>
113
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
56
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
57 #ifndef _WIN32
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
58 #define UNIX 1
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
59 #else
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
60 #define UNIX 0
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
61 #endif
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
62
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
63 /**
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
64 * @brief Global Return Code
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
65 *
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
66 * 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
67 * 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
68 * 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
69 * ORed together.
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
70 */
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
71 int return_code = 0;
44
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
72
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
73 /**
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
74 * @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
75 *
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
76 * Read the profiles.ini and extract all profile paths from that.
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
77 *
113
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
78 * @param[inifile] path of the profile.ini to read.
44
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
79 * @return NULL terminated array of strings containing containing the
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
80 * 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
81 * be freed by the caller.
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
82 */
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
83 static char **
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
84 get_profile_dirs (char *inifile_name)
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 char **dirs = NULL;
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
87 FILE *inifile;
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
88 char line[1000];
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
89 bool inprofile = false;
44
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
90
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
91 if ((inifile = fopen(inifile_name, "r")) != NULL)
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
92 {
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
93 while (fgets(line, 1000, inifile) != NULL)
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 if (strncmp(line, "[Profile", 8) == 0)
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
96 inprofile = true;
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
97 else if (line[0] == '[')
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
98 inprofile = false;
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
99 if (inprofile &&
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
100 (strncmp(line, "Path=", 5) == 0))
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
101 strv_append(&dirs, line, strlen(line));
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
102 }
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
103 }
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
104 else
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
105 {
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
106 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
107 }
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
108
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
109 return dirs;
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
110 }
44
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
111
113
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
112 int
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
113 main ()
113
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
114 {
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
115 int x = 0;
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
116 char **pdirs =
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
117 get_profile_dirs("/home/wilde/.mozilla/firefox/profiles.ini");
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
118 while (pdirs[x] != NULL)
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
119 puts(pdirs[x++]);
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
120 strv_free(pdirs);
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
121 exit(return_code);
44
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
122 }

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