Mercurial > trustbridge
annotate cinst/mozilla.c @ 50:a7b8cb29f1f6
Rename random files to garbage to clarify what they contain
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Mon, 17 Mar 2014 11:36:42 +0000 |
parents | b3e8e047bc2c |
children | bc1e6732f43c |
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 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
10 /* @brief IniParser for mozilla profiles.ini |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
11 * |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
12 * Parse data to find values formed in |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
13 * |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
14 * [Profile99] |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
15 * IsRelative=1 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
16 * Path=Profiles/fooo.bar |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
17 * |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
18 * or |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
19 * [Profile0] |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
20 * IsRelative=0 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
21 * Path=c:\foo\bar\baz |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
22 * |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
23 * 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
|
24 * encoded. |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
25 * */ |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
26 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
27 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
28 /** |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
29 * @brief Read a file into memory. |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
30 * |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
31 * @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
|
32 * @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
|
33 * @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
|
34 * @param[in] maxSize the maximum size to read. |
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 * @return 0 on success an error code otherwise. |
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 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
39 #define RAF_UNKNOWN -1 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
40 #define RAF_UNREADABLE -2 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
41 #define RAF_STATFAILED -3 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
42 #define RAF_TOOLARGE -4 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
43 #define RAF_OUTOFCORE -5 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
44 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
|
45 const size_t maxSize) |
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 int fd = -1; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
48 struct stat fileStat; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
49 int rc = 0; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
50 ssize_t bRead = 0; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
51 int retval = -1; |
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 memset(&fileStat, 0, sizeof(fileStat)); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
54 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
55 fd = open(fileName, O_RDONLY); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
56 if (fd == -1) { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
57 printf("Error: %s \n", strerror(errno)); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
58 retval = RAF_UNREADABLE; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
59 goto cleanup; |
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 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
62 rc = fstat(fd, &fileStat); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
63 if (rc < 0) { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
64 printf ("Stat failed with rc: %i\n", rc); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
65 retval = RAF_STATFAILED; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
66 goto cleanup; |
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 // Check the size of the file |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
70 if (!fileStat.st_size) { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
71 printf("Size zero\n"); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
72 retval = RAF_STATFAILED; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
73 goto cleanup; |
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 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
76 if (fileStat.st_size > maxSize && |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
77 fileStat.st_size > 0) { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
78 printf("File too large\n"); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
79 retval = RAF_TOOLARGE; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
80 goto cleanup; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
81 } |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
82 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
83 *size = (size_t) fileStat.st_size; |
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 *data = (char*) malloc(*size); |
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 if (*data == NULL) { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
88 retval = RAF_OUTOFCORE; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
89 goto cleanup; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
90 } |
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 bRead = read(fd, *data, *size); |
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 if (bRead < 0 || (size_t) bRead != *size) { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
95 printf("Read failed\n"); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
96 if (bRead == -1) { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
97 printf("Error: %s \n", strerror(errno)); |
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 retval = RAF_UNKNOWN; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
100 *size = 0; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
101 if (*data) { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
102 free(*data); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
103 printf("Nulling data\n"); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
104 *data = NULL; |
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 goto cleanup; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
107 } |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
108 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
109 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 if (fd && fd != -1) { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
112 close(fd); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
113 fd = -1; |
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 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
116 return retval; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
117 } |
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 #ifndef _WIN32 |
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 #define INI_LOCATIONS { \ |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
123 "/.mozilla/firefox/profiles.ini", \ |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
124 "/.mozilla/thunderbird/profiles.ini", \ |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
125 NULL } |
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 /** |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
128 * @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
|
129 * |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
130 * 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
|
131 * |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
132 * @return NULL terminated array of strings containing containing the |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
133 * 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
|
134 * be freed by the caller. |
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 char **getProfilePaths() { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
137 char *homedir = NULL, |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
138 **retval = NULL; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
139 const char* const iniLocations[] = INI_LOCATIONS; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
140 int i = 0; |
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 homedir = getenv ("HOME"); |
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 if (!homedir) { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
145 printf ("Could not get HOME\n"); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
146 return NULL; |
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 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
149 for (i = 0; iniLocations[i] != NULL; i++) { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
150 char *candidate[MAX_PATH_LEN], |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
151 *fileContent = NULL; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
152 const size_t needed = strnlen (homedir, MAX_PATH_LEN) + |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
153 strnlen (iniLocations[i], MAX_PATH_LEN); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
154 fileSize = 0; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
155 int err = 0; |
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 memset (candidate, 0, MAX_PATH_LEN); |
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 /* Verify that addition of strlen did not overflow and |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
160 * that the buffer is large enough */ |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
161 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
|
162 printf ("Error invalid HOME environment variable"); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
163 return NULL; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
164 } |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
165 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
166 strncpy (candidate, homedir, MAX_PATH_LEN); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
167 /* Environment might have been modified */ |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
168 if (candidate[MAX_PATH_LEN - 1] != '\0') { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
169 printf ("Error invalid HOME"); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
170 return NULL; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
171 } |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
172 strncat (candidate, iniLocations[i], MAX_PATH_LEN - strnlen(candidate, |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
173 MAX_PATH_LEN) - 1); |
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 rc = readFile (candidate, &fileContent, &fileSize, MAX_FILESIZE); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
176 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
177 if (err) { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
178 printf ("Failed to read file.\n"); |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
179 continue; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
180 } |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
181 parseIni (fileContent, &retval); |
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 } |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
184 #else /* _WIN32 */ |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
185 char **getProfilePaths() { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
186 return NULL; |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
187 } |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
188 #endif |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
189 |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
190 int main(int argc, char *argv) { |
b3e8e047bc2c
Commit first scratch of mozilla installer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
191 } |