annotate cinst/mozilla.c @ 124:2d50ff378367

Add install targets
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 24 Mar 2014 10:06:45 +0000
parents 4bb5f295987b
children ffb20e76e7d0
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 *
bc1e6732f43c Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents: 44
diff changeset
11 * 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
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
44
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
34 /* @brief IniParser for mozilla profiles.ini
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
35 *
110
0c8ea71a89cd fixed whitespace.
Sascha Wilde <wilde@intevation.de>
parents: 99
diff changeset
36 * Parse data to find values formed in
44
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
37 *
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
38 * [Profile99]
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
39 * IsRelative=1
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
40 * Path=Profiles/fooo.bar
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
41 *
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
42 * or
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
43 * [Profile0]
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
44 * IsRelative=0
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
45 * Path=c:\foo\bar\baz
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
46 *
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
47 * 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
48 * encoded.
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
49 * */
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
50
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
51 #include <stdbool.h>
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
52 #include <stdio.h>
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
53 #include <stdlib.h>
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
54 #include <string.h>
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
55
113
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
56 #include <errorcodes.h>
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
57 #include <strhelp.h>
113
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
58
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
59 #ifndef _WIN32
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
60 #define UNIX 1
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
61 #else
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
62 #define UNIX 0
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
63 #endif
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
64
119
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 * @brief Global Return Code
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
67 *
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
68 * 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
69 * 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
70 * 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
71 * ORed together.
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
72 */
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
73 int return_code = 0;
44
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
74
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
75 /**
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
76 * @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
77 *
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
78 * 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
79 *
121
4bb5f295987b Fix doxygen documentation.
Sascha Wilde <wilde@intevation.de>
parents: 119
diff changeset
80 * @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
81 * @return NULL terminated array of strings containing containing the
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
82 * 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
83 * be freed by the caller.
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
84 */
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
85 static char **
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
86 get_profile_dirs (char *inifile_name)
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 char **dirs = NULL;
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
89 FILE *inifile;
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
90 char line[1000];
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
91 bool inprofile = false;
44
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
92
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
93 if ((inifile = fopen(inifile_name, "r")) != 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 while (fgets(line, 1000, inifile) != NULL)
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
96 {
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
97 if (strncmp(line, "[Profile", 8) == 0)
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
98 inprofile = true;
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
99 else if (line[0] == '[')
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
100 inprofile = false;
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
101 if (inprofile &&
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
102 (strncmp(line, "Path=", 5) == 0))
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
103 strv_append(&dirs, line, strlen(line));
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
104 }
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 else
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 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
109 }
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
110
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
111 return dirs;
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
112 }
44
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
113
113
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
114 int
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
115 main ()
113
02ad0922c01f Start over (only leave comments).
Sascha Wilde <wilde@intevation.de>
parents: 110
diff changeset
116 {
119
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
117 int x = 0;
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
118 char **pdirs =
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
119 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
120 while (pdirs[x] != NULL)
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
121 puts(pdirs[x++]);
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
122 strv_free(pdirs);
24ca8e2ceecf First step of simple mozilla ini parser
Sascha Wilde <wilde@intevation.de>
parents: 113
diff changeset
123 exit(return_code);
44
b3e8e047bc2c Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
124 }

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