Mercurial > trustbridge
comparison cinst/mozilla.c @ 99:bc1e6732f43c
Add specification and some cleanups
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Fri, 21 Mar 2014 11:54:35 +0000 |
parents | b3e8e047bc2c |
children | 0c8ea71a89cd |
comparison
equal
deleted
inserted
replaced
98:6090e673c707 | 99:bc1e6732f43c |
---|---|
4 #include <sys/stat.h> | 4 #include <sys/stat.h> |
5 #include <unistd.h> | 5 #include <unistd.h> |
6 #include <string.h> | 6 #include <string.h> |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 | |
10 /* @file Mozilla installation process | |
11 * | |
12 * Reads from stdin a list of instructions in the form: | |
13 * | |
14 * I:<base64 DER econded certificate>\r\n | |
15 * R:<base64 DER econded certificate>\r\n | |
16 * ... | |
17 * | |
18 * The maximum size of an input line is 1000 characters | |
19 * (including the \r\n) at the end of the line. | |
20 * | |
21 * Certificates marked with I: will be installed and the ones | |
22 * marked with R: will be searched and if available removed from | |
23 * the databases. | |
24 * | |
25 * This tool tries to find all NSS databases the user has | |
26 * access to and to execute the instructions on all of them. | |
27 * | |
28 * If there are other processes accessing the databases the caller | |
29 * has to ensure that those are terminated before this process is | |
30 * executed. | |
31 * | |
32 * Returns 0 on success (Even when no stores where found) an error value | |
33 * as defined in errorcodes.h otherwise. | |
34 * | |
35 * Success messages are written to stdout. Errors to stderr. For logging | |
36 * purposes each installation / removal of a certificate will be reported | |
37 * with the profile name that it modified. | |
38 * | |
39 */ | |
9 | 40 |
10 /* @brief IniParser for mozilla profiles.ini | 41 /* @brief IniParser for mozilla profiles.ini |
11 * | 42 * |
12 * Parse data to find values formed in | 43 * Parse data to find values formed in |
13 * | 44 * |
42 #define RAF_TOOLARGE -4 | 73 #define RAF_TOOLARGE -4 |
43 #define RAF_OUTOFCORE -5 | 74 #define RAF_OUTOFCORE -5 |
44 int readFile(const char *fileName, char **data, size_t *size, | 75 int readFile(const char *fileName, char **data, size_t *size, |
45 const size_t maxSize) | 76 const size_t maxSize) |
46 { | 77 { |
78 /* TODO | |
79 * split out the read file from common/listutil.c and use that. */ | |
47 int fd = -1; | 80 int fd = -1; |
48 struct stat fileStat; | 81 struct stat fileStat; |
49 int rc = 0; | 82 int rc = 0; |
50 ssize_t bRead = 0; | 83 ssize_t bRead = 0; |
51 int retval = -1; | 84 int retval = -1; |
52 | 85 |
53 memset(&fileStat, 0, sizeof(fileStat)); | 86 memset(&fileStat, 0, sizeof(fileStat)); |
54 | 87 |
55 fd = open(fileName, O_RDONLY); | 88 fd = open(fileName, O_RDONLY); |
56 if (fd == -1) { | 89 if (fd == -1) { |
57 printf("Error: %s \n", strerror(errno)); | |
58 retval = RAF_UNREADABLE; | 90 retval = RAF_UNREADABLE; |
59 goto cleanup; | 91 goto cleanup; |
60 } | 92 } |
61 | 93 |
62 rc = fstat(fd, &fileStat); | 94 rc = fstat(fd, &fileStat); |
63 if (rc < 0) { | 95 if (rc < 0) { |
64 printf ("Stat failed with rc: %i\n", rc); | |
65 retval = RAF_STATFAILED; | 96 retval = RAF_STATFAILED; |
66 goto cleanup; | 97 goto cleanup; |
67 } | 98 } |
68 | 99 |
69 // Check the size of the file | 100 // Check the size of the file |
70 if (!fileStat.st_size) { | 101 if (!fileStat.st_size) { |
71 printf("Size zero\n"); | |
72 retval = RAF_STATFAILED; | 102 retval = RAF_STATFAILED; |
73 goto cleanup; | 103 goto cleanup; |
74 } | 104 } |
75 | 105 |
76 if (fileStat.st_size > maxSize && | 106 if (fileStat.st_size > maxSize && |
77 fileStat.st_size > 0) { | 107 fileStat.st_size > 0) { |
78 printf("File too large\n"); | |
79 retval = RAF_TOOLARGE; | 108 retval = RAF_TOOLARGE; |
80 goto cleanup; | 109 goto cleanup; |
81 } | 110 } |
82 | 111 |
83 *size = (size_t) fileStat.st_size; | 112 *size = (size_t) fileStat.st_size; |
90 } | 119 } |
91 | 120 |
92 bRead = read(fd, *data, *size); | 121 bRead = read(fd, *data, *size); |
93 | 122 |
94 if (bRead < 0 || (size_t) bRead != *size) { | 123 if (bRead < 0 || (size_t) bRead != *size) { |
95 printf("Read failed\n"); | |
96 if (bRead == -1) { | 124 if (bRead == -1) { |
97 printf("Error: %s \n", strerror(errno)); | 125 printf("Error: %s \n", strerror(errno)); |
98 } | 126 } |
99 retval = RAF_UNKNOWN; | 127 retval = RAF_UNKNOWN; |
100 *size = 0; | 128 *size = 0; |
101 if (*data) { | 129 if (*data) { |
102 free(*data); | 130 free(*data); |
103 printf("Nulling data\n"); | |
104 *data = NULL; | 131 *data = NULL; |
105 } | 132 } |
106 goto cleanup; | 133 goto cleanup; |
107 } | 134 } |
108 | 135 |