Mercurial > trustbridge
changeset 1060:317ee9dc4684
(issue46) Make debug output optional in cinst and mozilla and propagate its setting.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Tue, 09 Sep 2014 18:49:02 +0200 |
parents | f638eb1f3b0f |
children | db831a204a6b |
files | cinst/main.c cinst/mozilla.c cinst/nssstore_linux.c cinst/nssstore_win.c common/logging.h ui/installwrapper.cpp ui/tests/binverifytest.cpp ui/tests/cinstprocesstest.cpp ui/tests/createcertlisttest.cpp ui/tests/nsstest.cpp ui/tests/windowsstoretest.cpp |
diffstat | 11 files changed, 75 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/cinst/main.c Tue Sep 09 18:00:37 2014 +0200 +++ b/cinst/main.c Tue Sep 09 18:49:02 2014 +0200 @@ -35,6 +35,8 @@ * to remove all certificates (Even those marked with I) that * are part of the list. * + * For more verbose debug output add --debug to the call. + * **/ #include <stdio.h> #include <stdlib.h> @@ -199,6 +201,7 @@ return 0; } +bool g_debug = false; int main (int argc, char **argv) @@ -219,18 +222,24 @@ /* Some very static argument parsing. list= and choices= is only added to make it more transparent how this programm is called if a user looks at the detailed uac dialog. */ - if (argc != 3 || strncmp(argv[1], "list=", 5) != 0 || + if ((argc != 3 && argc != 4) || strncmp(argv[1], "list=", 5) != 0 || strncmp(argv[2], "choices=", 8) != 0) { ERRORPRINTF ("Invalid arguments.\n" "Expected arguments: list=<certificate_list> \n" - " choices=<choices_file>|uninstall\n"); + " choices=<choices_file>|uninstall\n" + "Optional: --debug\n"); return ERR_INVALID_PARAMS; } certificate_file_name = strchr(argv[1], '=') + 1; choices_file_name = strchr(argv[2], '=') + 1; + if (argc == 4 && strncmp(argv[3], "--debug", 7) == 0) + { + g_debug = true; + } + if (!certificate_file_name || !choices_file_name) { ERRORPRINTF ("Invalid arguments.\n"
--- a/cinst/mozilla.c Tue Sep 09 18:00:37 2014 +0200 +++ b/cinst/mozilla.c Tue Sep 09 18:49:02 2014 +0200 @@ -45,6 +45,9 @@ * purposes each installation / removal of a certificate will be reported * with the profile name that it modified. * + * To get more verbose output add the --debug parameter + * as the last parameter on the command line. + * */ /** @@ -142,7 +145,7 @@ return cdir; else { - DEBUGPRINTF("FATAL! No %s in environment.\n", envvar); + ERRORPRINTF("FATAL! No %s in environment.\n", envvar); exit(ERR_MOZ_HOMELESS); } } @@ -560,7 +563,7 @@ o_str = x509_parse_subject(secitemp->data, secitemp->len, CERT_OID_O); if (!cn_str || !o_str) { - DEBUGPRINTF("FATAL: Could not parse certificate!"); + ERRORPRINTF("FATAL: Could not parse certificate!"); exit(ERR_INVALID_CERT); } name_len = strlen(cn_str) + strlen(o_str) + 4; @@ -826,12 +829,14 @@ if (parserr) { - DEBUGPRINTF("FATAL: Invalid input: %s\n", inpl); + ERRORPRINTF("FATAL: Invalid input: %s\n", inpl); exit(ERR_MOZ_INVALID_INPUT); } } } +bool g_debug = false; + int main (int argc, char **argv) { @@ -847,17 +852,29 @@ input_stream = stdin; break; case 2: + if (strcmp(argv[1], "--debug") == 0) + { + g_debug = true; + DEBUGPRINTF("Opening STDIN for input...\n"); + input_stream = stdin; + break; + } + case 3: DEBUGPRINTF("Opening %s for input...\n", argv[1]); if ((input_stream = fopen(argv[1], "r")) == NULL) { - DEBUGPRINTF("FATAL: Could not open %s for reading!\n", - argv[1]); + ERRORPRINTF ("FATAL: Could not open %s for reading!\n", + argv[1]); exit_code = ERR_MOZ_FAILED_TO_OPEN_INPUT; goto exit; } + if (argc == 3 && strcmp(argv[2], "--debug") == 0) + { + g_debug = true; + } break; default: - DEBUGPRINTF("FATAL: Wrong number of arguments!\n"); + ERRORPRINTF("FATAL: Wrong number of arguments!\n"); exit_code = ERR_MOZ_WRONG_ARGC; goto exit; }
--- a/cinst/nssstore_linux.c Tue Sep 09 18:00:37 2014 +0200 +++ b/cinst/nssstore_linux.c Tue Sep 09 18:49:02 2014 +0200 @@ -49,7 +49,7 @@ { int pipe_fd[2]; pid_t pid = 0; - char *argv[2] = {NULL, NULL}, + char *argv[3] = {NULL, NULL, NULL}, *envp[2] = {NULL, NULL}, *inst_dir = NULL; size_t homedir_len = 0, @@ -92,6 +92,11 @@ exe_path_len = strlen(inst_dir) + strlen(NSS_PROCESS_NAME); argv[0] = xmalloc (exe_path_len + 1); + if (g_debug) + { + argv[1] = "--debug"; + } + ret = snprintf(argv[0], exe_path_len + 1, "%s%s", inst_dir, NSS_PROCESS_NAME); xfree (inst_dir); if (ret < 0 || (size_t) ret != exe_path_len)
--- a/cinst/nssstore_win.c Tue Sep 09 18:00:37 2014 +0200 +++ b/cinst/nssstore_win.c Tue Sep 09 18:49:02 2014 +0200 @@ -415,6 +415,11 @@ + NULL */ cmd_line_len = wcslen (w_inst_dir) + 1 + 2 + wcslen (NSS_APP_NAME) + + 1 + 2 + wcslen(selection_file) + 1; + if (g_debug) + { + /* Add space for whitespace and --debug*/ + cmd_line_len += 8; + } retval = xmalloc (cmd_line_len * sizeof(wchar_t)); wcscpy_s (retval, cmd_line_len, L"\""); @@ -425,6 +430,11 @@ wcscat_s (retval, cmd_line_len, selection_file); wcscat_s (retval, cmd_line_len, L"\""); + if (g_debug) + { + wcscat_s (retval, cmd_line_len, L" --debug"); + } + return retval; }
--- a/common/logging.h Tue Sep 09 18:00:37 2014 +0200 +++ b/common/logging.h Tue Sep 09 18:49:02 2014 +0200 @@ -70,9 +70,10 @@ */ #ifdef DEBUGOUTPUT # ifndef WIN32 -# define DEBUGPRINTF(fmt, ...) fprintf(stderr, DEBUGPREFIX "DEBUG: " fmt, ##__VA_ARGS__); +# define DEBUGPRINTF(fmt, ...) if (g_debug) fprintf(stderr, DEBUGPREFIX "DEBUG: " fmt, ##__VA_ARGS__); # else /* WIN32 */ # define DEBUGPRINTF(fmt, ...) \ + if (g_debug) \ { \ char buf[512]; \ snprintf(buf, 511, "DEBUG: " fmt, ##__VA_ARGS__); \ @@ -113,8 +114,8 @@ if (my_error) { \ ERRORPRINTF(msg" : %s\n", my_error); \ free (my_error); \ - } \ - ERRORPRINTF ("Failed to get error information\n"); + } else \ + ERRORPRINTF ("Failed to get error information\n"); /**
--- a/ui/installwrapper.cpp Tue Sep 09 18:00:37 2014 +0200 +++ b/ui/installwrapper.cpp Tue Sep 09 18:49:02 2014 +0200 @@ -94,6 +94,10 @@ QString parameters = "\"list=" + mCertListFile + "\" \"choices=" + choicesFile.fileName() + "\""; + if (g_debug) { + parameters += " --debug"; + } + shExecInfo.cbSize = sizeof(SHELLEXECUTEINFOW); shExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; if (!is_system_install()) { @@ -155,6 +159,10 @@ choicesFile.setAutoRemove(false); parameters << "list=" + mCertListFile << "choices=" + choicesFile.fileName(); + if (g_debug) { + parameters << "--debug"; + } + bool sudo_started = false; bool use_sudo = is_admin() && is_system_install(); if (use_sudo) {
--- a/ui/tests/binverifytest.cpp Tue Sep 09 18:00:37 2014 +0200 +++ b/ui/tests/binverifytest.cpp Tue Sep 09 18:49:02 2014 +0200 @@ -98,5 +98,6 @@ QVERIFY(VerifyValid == verify_binary (outfile.fileName().toUtf8().constData(), outfile.fileName().toUtf8().size())); } +bool g_debug = true; QTEST_MAIN (BinVerifyTest);
--- a/ui/tests/cinstprocesstest.cpp Tue Sep 09 18:00:37 2014 +0200 +++ b/ui/tests/cinstprocesstest.cpp Tue Sep 09 18:49:02 2014 +0200 @@ -32,8 +32,11 @@ } } + QStringList newArgs = args; + newArgs << "--debug"; + QProcess *installerProcess = new QProcess(); - installerProcess->setArguments(args); + installerProcess->setArguments(newArgs); installerProcess->setProgram(processPath); installerProcess->start(); installerProcess->waitForStarted();
--- a/ui/tests/createcertlisttest.cpp Tue Sep 09 18:00:37 2014 +0200 +++ b/ui/tests/createcertlisttest.cpp Tue Sep 09 18:49:02 2014 +0200 @@ -84,4 +84,6 @@ QVERIFY(signature.toBase64() == QByteArray("KMOni98NWbt6SWd13H0JlGA1B7hBlXWH84e883s7gMrWeCCj0fUyHmdsNCyY0rmosu+o9mo2K847S3CdnxFPPJcjbfcmILZWRw0hHMtUYta1i9jypHJbz4oznuDctgXz59L4SQzzliCNUzItNoe6UpUznkS5gja4ZHbzqIj3qDVX3H86Z+qOdLICw+LXKlTs5ghsq+SdhZRAFFpHnt+URICWHjEIQKRlmIGEUIh1NgEHInHB/teFLqNGJMu1khi0MTsWDzesAEF5LQTM7Fo3fKmVxEUSbHKupluZrX1XSfnp5w3MaxBQK/t5nFvkVVdFrdEWvb68FIkMt21XqCvjyCPG2oWNh9jjfx3/R+eQ8kFbXzgUIhlZNxbB7bOCVDe2fYNxlXhy+HAqfHsIDP8qegHU+ngLck7tJHScC5dZwTCBDL6sxAvaeGyb3m6FraqaipNI+SGLii63ou9H7PlH5xWOTY9JvJDXGpfjN9U0UrZ6X5hPutOa/llT7s0pmoQb")); } +bool g_debug = true; + QTEST_GUILESS_MAIN (CreateCertListTest);