Mercurial > trustbridge
comparison cinst/mozilla.c @ 223:d29997e09177
NSS first Blood. Added code to list certs in found stores.
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Thu, 27 Mar 2014 12:46:46 +0100 |
parents | 5d380b662198 |
children | 689b94dd89a9 |
comparison
equal
deleted
inserted
replaced
220:e6c5c70a67b0 | 223:d29997e09177 |
---|---|
47 * Mozilla also accepts the ini file on Windows even if it is UTF-16 | 47 * Mozilla also accepts the ini file on Windows even if it is UTF-16 |
48 * encoded. | 48 * encoded. |
49 * */ | 49 * */ |
50 | 50 |
51 #include <dirent.h> | 51 #include <dirent.h> |
52 #include <nss/cert.h> | |
53 #include <nss/certt.h> | |
54 #include <nss/nss.h> | |
55 #include <nss/pk11pub.h> | |
52 #include <stdbool.h> | 56 #include <stdbool.h> |
53 #include <stdio.h> | 57 #include <stdio.h> |
54 #include <stdlib.h> | 58 #include <stdlib.h> |
55 #include <string.h> | 59 #include <string.h> |
56 #include <sys/types.h> | 60 #include <sys/types.h> |
60 #include <portpath.h> | 64 #include <portpath.h> |
61 #include <strhelp.h> | 65 #include <strhelp.h> |
62 | 66 |
63 #ifndef _WIN32 | 67 #ifndef _WIN32 |
64 #define CONFDIRS ".mozilla", ".thunderbird" | 68 #define CONFDIRS ".mozilla", ".thunderbird" |
65 #define LINUX 1 | 69 #define TARGET_LINUX 1 |
66 #else | 70 #else |
67 #define CONFDIRS "Mozilla", "Thunderbird" | 71 #define CONFDIRS "Mozilla", "Thunderbird" |
68 #define LINUX 0 | 72 #define TARGET_LINUX 0 |
69 #endif | 73 #endif |
70 | 74 |
71 #define LINEBUFLEN 1000 | 75 #define LINEBUFLEN 1000 |
72 | 76 |
73 /** | 77 /** |
89 static char * | 93 static char * |
90 get_conf_basedir() | 94 get_conf_basedir() |
91 { | 95 { |
92 char *cdir, *envvar; | 96 char *cdir, *envvar; |
93 | 97 |
94 if (LINUX) | 98 if (TARGET_LINUX) |
95 envvar = "HOME" ; | 99 envvar = "HOME" ; |
96 else | 100 else |
97 envvar = "APPDATA"; | 101 envvar = "APPDATA"; |
98 | 102 |
99 if ((cdir = getenv(envvar)) != NULL) | 103 if ((cdir = getenv(envvar)) != NULL) |
248 exit(WARN_MOZ_NO_PROFILES); | 252 exit(WARN_MOZ_NO_PROFILES); |
249 } | 253 } |
250 return inis; | 254 return inis; |
251 } | 255 } |
252 | 256 |
257 /** | |
258 * @brief list certificates from nss certificate store | |
259 * @param[in] confdir the directory with the certificate store | |
260 */ | |
261 static void | |
262 nss_list_certs (char *confdir) | |
263 { | |
264 CERTCertList *list; | |
265 CERTCertListNode *node; | |
266 char *name; | |
267 | |
268 if (NSS_Initialize(confdir, "", "", "secmod.db", NSS_INIT_READONLY) | |
269 == SECSuccess) | |
270 { | |
271 list = PK11_ListCerts(PK11CertListAll, NULL); | |
272 for (node = CERT_LIST_HEAD(list); !CERT_LIST_END(node, list); | |
273 node = CERT_LIST_NEXT(node)) { | |
274 name = node->appData; | |
275 | |
276 printf ("Found certificate \"%s\"\n", name); | |
277 } | |
278 CERT_DestroyCertList(list); | |
279 NSS_Shutdown(); | |
280 } | |
281 else | |
282 DEBUGFPRINT("Could not open nss cer store in %s!", confdir); | |
283 } | |
284 | |
253 | 285 |
254 int | 286 int |
255 main () | 287 main () |
256 { | 288 { |
257 int x = 0; | |
258 int y = 0; | 289 int y = 0; |
259 char **mozinis, **pdirs; | 290 char **mozinis, **pdirs; |
260 if ((mozinis = get_profile_inis()) != NULL) | 291 if ((mozinis = get_profile_inis()) != NULL) |
261 while (mozinis[y] != NULL) | 292 while (mozinis[y] != NULL) |
262 { | 293 { |
263 pdirs = | 294 pdirs = |
264 get_profile_dirs(mozinis[y++]); | 295 get_profile_dirs(mozinis[y++]); |
265 if (pdirs != NULL) | 296 if (pdirs != NULL) |
266 { | 297 { |
267 x = 0; | 298 for (int x=0; pdirs[x] != NULL; x++) |
268 while (pdirs[x] != NULL) | 299 { |
269 puts(pdirs[x++]); | 300 puts(pdirs[x]); |
301 nss_list_certs(pdirs[x]); | |
302 } | |
270 strv_free(pdirs); | 303 strv_free(pdirs); |
271 } | 304 } |
272 } | 305 } |
273 exit(return_code); | 306 exit(return_code); |
274 } | 307 } |