annotate cinst/mozilla.c @ 101:7e2d08555112

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

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