Mercurial > trustbridge
annotate cinst/mozilla.c @ 111:36ac0697339e
Merged
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Fri, 21 Mar 2014 15:59:46 +0100 |
parents | 0c8ea71a89cd |
children | 02ad0922c01f |
rev | line source |
---|---|
44
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
1 #include <stdio.h> |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
2 #include <stdlib.h> |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
3 #include <sys/stat.h> |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
4 #include <unistd.h> |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
5 #include <string.h> |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
6 #include <fcntl.h> |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
7 #include <errno.h> |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
8 |
99
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
9 /* @file Mozilla installation process |
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 * 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
|
12 * |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
13 * I:<base64 DER econded certificate>\r\n |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
14 * R:<base64 DER econded certificate>\r\n |
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 * |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
17 * 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
|
18 * (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
|
19 * |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
20 * 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
|
21 * 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
|
22 * the databases. |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
23 * |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
24 * 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
|
25 * 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
|
26 * |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
27 * 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
|
28 * 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
|
29 * executed. |
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 * 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
|
32 * as defined in errorcodes.h otherwise. |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
33 * |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
34 * 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
|
35 * 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
|
36 * with the profile name that it modified. |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
37 * |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
38 */ |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
39 |
44
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
40 /* @brief IniParser for mozilla profiles.ini |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
41 * |
110 | 42 * Parse data to find values formed in |
44
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
43 * |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
44 * [Profile99] |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
45 * IsRelative=1 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
46 * Path=Profiles/fooo.bar |
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 * or |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
49 * [Profile0] |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
50 * IsRelative=0 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
51 * Path=c:\foo\bar\baz |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
52 * |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
53 * 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
|
54 * encoded. |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
55 * */ |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
56 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
57 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
58 /** |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
59 * @brief Read a file into memory. |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
60 * |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
61 * @param[in] fileName Name of the file (UTF-8 encoded). |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
62 * @param[out] data Newly allocated pointer to the file content. |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
63 * @param[out] size Size in Bytes of the file content. |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
64 * @param[in] maxSize the maximum size to read. |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
65 * |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
66 * @return 0 on success an error code otherwise. |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
67 */ |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
68 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
69 #define RAF_UNKNOWN -1 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
70 #define RAF_UNREADABLE -2 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
71 #define RAF_STATFAILED -3 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
72 #define RAF_TOOLARGE -4 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
73 #define RAF_OUTOFCORE -5 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
74 int readFile(const char *fileName, char **data, size_t *size, |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
75 const size_t maxSize) |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
76 { |
99
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
77 /* TODO |
bc1e6732f43c
Add specification and some cleanups
Andre Heinecke <aheinecke@intevation.de>
parents:
44
diff
changeset
|
78 * split out the read file from common/listutil.c and use that. */ |
44
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
79 int fd = -1; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
80 struct stat fileStat; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
81 int rc = 0; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
82 ssize_t bRead = 0; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
83 int retval = -1; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
84 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
85 memset(&fileStat, 0, sizeof(fileStat)); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
86 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
87 fd = open(fileName, O_RDONLY); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
88 if (fd == -1) { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
89 retval = RAF_UNREADABLE; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
90 goto cleanup; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
91 } |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
92 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
93 rc = fstat(fd, &fileStat); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
94 if (rc < 0) { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
95 retval = RAF_STATFAILED; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
96 goto cleanup; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
97 } |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
98 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
99 // Check the size of the file |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
100 if (!fileStat.st_size) { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
101 retval = RAF_STATFAILED; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
102 goto cleanup; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
103 } |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
104 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
105 if (fileStat.st_size > maxSize && |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
106 fileStat.st_size > 0) { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
107 retval = RAF_TOOLARGE; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
108 goto cleanup; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
109 } |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
110 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
111 *size = (size_t) fileStat.st_size; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
112 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
113 *data = (char*) malloc(*size); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
114 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
115 if (*data == NULL) { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
116 retval = RAF_OUTOFCORE; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
117 goto cleanup; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
118 } |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
119 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
120 bRead = read(fd, *data, *size); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
121 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
122 if (bRead < 0 || (size_t) bRead != *size) { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
123 if (bRead == -1) { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
124 printf("Error: %s \n", strerror(errno)); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
125 } |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
126 retval = RAF_UNKNOWN; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
127 *size = 0; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
128 if (*data) { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
129 free(*data); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
130 *data = NULL; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
131 } |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
132 goto cleanup; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
133 } |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
134 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
135 cleanup: |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
136 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
137 if (fd && fd != -1) { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
138 close(fd); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
139 fd = -1; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
140 } |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
141 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
142 return retval; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
143 } |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
144 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
145 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
146 #ifndef _WIN32 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
147 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
148 #define INI_LOCATIONS { \ |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
149 "/.mozilla/firefox/profiles.ini", \ |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
150 "/.mozilla/thunderbird/profiles.ini", \ |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
151 NULL } |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
152 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
153 /** |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
154 * @brief Get a list of all mozilla profile directories for this user |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
155 * |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
156 * 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
|
157 * |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
158 * @return NULL terminated array of strings containing containing the |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
159 * 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
|
160 * be freed by the caller. |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
161 */ |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
162 char **getProfilePaths() { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
163 char *homedir = NULL, |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
164 **retval = NULL; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
165 const char* const iniLocations[] = INI_LOCATIONS; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
166 int i = 0; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
167 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
168 homedir = getenv ("HOME"); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
169 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
170 if (!homedir) { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
171 printf ("Could not get HOME\n"); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
172 return NULL; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
173 } |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
174 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
175 for (i = 0; iniLocations[i] != NULL; i++) { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
176 char *candidate[MAX_PATH_LEN], |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
177 *fileContent = NULL; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
178 const size_t needed = strnlen (homedir, MAX_PATH_LEN) + |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
179 strnlen (iniLocations[i], MAX_PATH_LEN); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
180 fileSize = 0; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
181 int err = 0; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
182 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
183 memset (candidate, 0, MAX_PATH_LEN); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
184 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
185 /* Verify that addition of strlen did not overflow and |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
186 * that the buffer is large enough */ |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
187 if (needed < strnlen (homedir, MAX_PATH_LEN_LEN) || needed >= MAX_PATH - 1) { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
188 printf ("Error invalid HOME environment variable"); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
189 return NULL; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
190 } |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
191 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
192 strncpy (candidate, homedir, MAX_PATH_LEN); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
193 /* Environment might have been modified */ |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
194 if (candidate[MAX_PATH_LEN - 1] != '\0') { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
195 printf ("Error invalid HOME"); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
196 return NULL; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
197 } |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
198 strncat (candidate, iniLocations[i], MAX_PATH_LEN - strnlen(candidate, |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
199 MAX_PATH_LEN) - 1); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
200 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
201 rc = readFile (candidate, &fileContent, &fileSize, MAX_FILESIZE); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
202 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
203 if (err) { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
204 printf ("Failed to read file.\n"); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
205 continue; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
206 } |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
207 parseIni (fileContent, &retval); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
208 } |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
209 } |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
210 #else /* _WIN32 */ |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
211 char **getProfilePaths() { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
212 return NULL; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
213 } |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
214 #endif |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
215 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
216 int main(int argc, char *argv) { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
217 } |