=== modified file 'plugins.d/mandos-client.c' --- plugins.d/mandos-client.c 2011-11-14 18:32:54 +0000 +++ plugins.d/mandos-client.c 2011-11-14 19:10:50 +0000 @@ -261,16 +261,14 @@ rc = gpgme_data_new_from_fd(&pgp_data, fd); if(rc != GPG_ERR_NO_ERROR){ - fprintf(stderr, "Mandos plugin mandos-client: " - "bad gpgme_data_new_from_fd: %s: %s\n", + fprintf_plus(stderr, "bad gpgme_data_new_from_fd: %s: %s\n", gpgme_strsource(rc), gpgme_strerror(rc)); return false; } rc = gpgme_op_import(mc.ctx, pgp_data); if(rc != GPG_ERR_NO_ERROR){ - fprintf(stderr, "Mandos plugin mandos-client: " - "bad gpgme_op_import: %s: %s\n", + fprintf_plus(stderr, "bad gpgme_op_import: %s: %s\n", gpgme_strsource(rc), gpgme_strerror(rc)); return false; } @@ -284,16 +282,14 @@ } if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Initializing GPGME\n"); + fprintf_plus(stderr, "Initializing GPGME\n"); } /* Init GPGME */ gpgme_check_version(NULL); rc = gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP); if(rc != GPG_ERR_NO_ERROR){ - fprintf(stderr, "Mandos plugin mandos-client: " - "bad gpgme_engine_check_version: %s: %s\n", + fprintf_plus(stderr, "bad gpgme_engine_check_version: %s: %s\n", gpgme_strsource(rc), gpgme_strerror(rc)); return false; } @@ -301,8 +297,7 @@ /* Set GPGME home directory for the OpenPGP engine only */ rc = gpgme_get_engine_info(&engine_info); if(rc != GPG_ERR_NO_ERROR){ - fprintf(stderr, "Mandos plugin mandos-client: " - "bad gpgme_get_engine_info: %s: %s\n", + fprintf_plus(stderr, "bad gpgme_get_engine_info: %s: %s\n", gpgme_strsource(rc), gpgme_strerror(rc)); return false; } @@ -315,15 +310,14 @@ engine_info = engine_info->next; } if(engine_info == NULL){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Could not set GPGME home dir to %s\n", tempdir); + fprintf_plus(stderr, "Could not set GPGME home dir to %s\n", tempdir); return false; } /* Create new GPGME "context" */ rc = gpgme_new(&(mc.ctx)); if(rc != GPG_ERR_NO_ERROR){ - fprintf(stderr, "Mandos plugin mandos-client: " + fprintf_plus(stderr, "Mandos plugin mandos-client: " "bad gpgme_new: %s: %s\n", gpgme_strsource(rc), gpgme_strerror(rc)); return false; @@ -350,16 +344,14 @@ ssize_t plaintext_length = 0; if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Trying to decrypt OpenPGP data\n"); + fprintf_plus(stderr, "Trying to decrypt OpenPGP data\n"); } /* Create new GPGME data buffer from memory cryptotext */ rc = gpgme_data_new_from_mem(&dh_crypto, cryptotext, crypto_size, 0); if(rc != GPG_ERR_NO_ERROR){ - fprintf(stderr, "Mandos plugin mandos-client: " - "bad gpgme_data_new_from_mem: %s: %s\n", + fprintf_plus(stderr, "bad gpgme_data_new_from_mem: %s: %s\n", gpgme_strsource(rc), gpgme_strerror(rc)); return -1; } @@ -367,7 +359,7 @@ /* Create new empty GPGME data buffer for the plaintext */ rc = gpgme_data_new(&dh_plain); if(rc != GPG_ERR_NO_ERROR){ - fprintf(stderr, "Mandos plugin mandos-client: " + fprintf_plus(stderr, "Mandos plugin mandos-client: " "bad gpgme_data_new: %s: %s\n", gpgme_strsource(rc), gpgme_strerror(rc)); gpgme_data_release(dh_crypto); @@ -378,37 +370,29 @@ data buffer */ rc = gpgme_op_decrypt(mc.ctx, dh_crypto, dh_plain); if(rc != GPG_ERR_NO_ERROR){ - fprintf(stderr, "Mandos plugin mandos-client: " - "bad gpgme_op_decrypt: %s: %s\n", + fprintf_plus(stderr, "bad gpgme_op_decrypt: %s: %s\n", gpgme_strsource(rc), gpgme_strerror(rc)); plaintext_length = -1; if(debug){ gpgme_decrypt_result_t result; result = gpgme_op_decrypt_result(mc.ctx); if(result == NULL){ - fprintf(stderr, "Mandos plugin mandos-client: " - "gpgme_op_decrypt_result failed\n"); + fprintf_plus(stderr, "gpgme_op_decrypt_result failed\n"); } else { - fprintf(stderr, "Mandos plugin mandos-client: " - "Unsupported algorithm: %s\n", + fprintf_plus(stderr, "Unsupported algorithm: %s\n", result->unsupported_algorithm); - fprintf(stderr, "Mandos plugin mandos-client: " - "Wrong key usage: %u\n", + fprintf_plus(stderr, "Wrong key usage: %u\n", result->wrong_key_usage); if(result->file_name != NULL){ - fprintf(stderr, "Mandos plugin mandos-client: " - "File name: %s\n", result->file_name); + fprintf_plus(stderr, "File name: %s\n", result->file_name); } gpgme_recipient_t recipient; recipient = result->recipients; while(recipient != NULL){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Public key algorithm: %s\n", + fprintf_plus(stderr, "Public key algorithm: %s\n", gpgme_pubkey_algo_name(recipient->pubkey_algo)); - fprintf(stderr, "Mandos plugin mandos-client: " - "Key ID: %s\n", recipient->keyid); - fprintf(stderr, "Mandos plugin mandos-client: " - "Secret key available: %s\n", + fprintf_plus(stderr, "Key ID: %s\n", recipient->keyid); + fprintf_plus(stderr, "Secret key available: %s\n", recipient->status == GPG_ERR_NO_SECKEY ? "No" : "Yes"); recipient = recipient->next; @@ -419,8 +403,7 @@ } if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Decryption of OpenPGP data succeeded\n"); + fprintf_plus(stderr, "Decryption of OpenPGP data succeeded\n"); } /* Seek back to the beginning of the GPGME plaintext data buffer */ @@ -457,8 +440,7 @@ } if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Decrypted password is: "); + fprintf_plus(stderr, "Decrypted password is: "); for(ssize_t i = 0; i < plaintext_length; i++){ fprintf(stderr, "%02hhX ", (*plaintext)[i]); } @@ -486,7 +468,7 @@ /* GnuTLS log function callback */ static void debuggnutls(__attribute__((unused)) int level, const char* string){ - fprintf(stderr, "Mandos plugin mandos-client: GnuTLS: %s", string); + fprintf_plus(stderr, "GnuTLS: %s", string); } static int init_gnutls_global(const char *pubkeyfilename, @@ -494,14 +476,12 @@ int ret; if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Initializing GnuTLS\n"); + fprintf_plus(stderr, "Initializing GnuTLS\n"); } ret = gnutls_global_init(); if(ret != GNUTLS_E_SUCCESS){ - fprintf(stderr, "Mandos plugin mandos-client: " - "GnuTLS global_init: %s\n", safer_gnutls_strerror(ret)); + fprintf_plus(stderr, "GnuTLS global_init: %s\n", safer_gnutls_strerror(ret)); return -1; } @@ -516,15 +496,13 @@ /* OpenPGP credentials */ ret = gnutls_certificate_allocate_credentials(&mc.cred); if(ret != GNUTLS_E_SUCCESS){ - fprintf(stderr, "Mandos plugin mandos-client: " - "GnuTLS memory error: %s\n", safer_gnutls_strerror(ret)); + fprintf_plus(stderr, "GnuTLS memory error: %s\n", safer_gnutls_strerror(ret)); gnutls_global_deinit(); return -1; } if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Attempting to use OpenPGP public key %s and" + fprintf_plus(stderr, "Attempting to use OpenPGP public key %s and" " secret key %s as GnuTLS credentials\n", pubkeyfilename, seckeyfilename); } @@ -533,27 +511,23 @@ (mc.cred, pubkeyfilename, seckeyfilename, GNUTLS_OPENPGP_FMT_BASE64); if(ret != GNUTLS_E_SUCCESS){ - fprintf(stderr, - "Mandos plugin mandos-client: " - "Error[%d] while reading the OpenPGP key pair ('%s'," - " '%s')\n", ret, pubkeyfilename, seckeyfilename); - fprintf(stderr, "Mandos plugin mandos-client: " - "The GnuTLS error is: %s\n", safer_gnutls_strerror(ret)); + fprintf_plus(stderr, + "Error[%d] while reading the OpenPGP key pair ('%s'," + " '%s')\n", ret, pubkeyfilename, seckeyfilename); + fprintf_plus(stderr, "The GnuTLS error is: %s\n", safer_gnutls_strerror(ret)); goto globalfail; } /* GnuTLS server initialization */ ret = gnutls_dh_params_init(&mc.dh_params); if(ret != GNUTLS_E_SUCCESS){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Error in GnuTLS DH parameter initialization:" + fprintf_plus(stderr, "Error in GnuTLS DH parameter initialization:" " %s\n", safer_gnutls_strerror(ret)); goto globalfail; } ret = gnutls_dh_params_generate2(mc.dh_params, mc.dh_bits); if(ret != GNUTLS_E_SUCCESS){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Error in GnuTLS prime generation: %s\n", + fprintf_plus(stderr, "Error in GnuTLS prime generation: %s\n", safer_gnutls_strerror(ret)); goto globalfail; } @@ -580,8 +554,7 @@ } } while(ret == GNUTLS_E_INTERRUPTED or ret == GNUTLS_E_AGAIN); if(ret != GNUTLS_E_SUCCESS){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Error in GnuTLS session initialization: %s\n", + fprintf_plus(stderr, "Error in GnuTLS session initialization: %s\n", safer_gnutls_strerror(ret)); } @@ -595,10 +568,8 @@ } } while(ret == GNUTLS_E_INTERRUPTED or ret == GNUTLS_E_AGAIN); if(ret != GNUTLS_E_SUCCESS){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Syntax error at: %s\n", err); - fprintf(stderr, "Mandos plugin mandos-client: " - "GnuTLS error: %s\n", safer_gnutls_strerror(ret)); + fprintf_plus(stderr, "Syntax error at: %s\n", err); + fprintf_plus(stderr, "GnuTLS error: %s\n", safer_gnutls_strerror(ret)); gnutls_deinit(*session); return -1; } @@ -613,8 +584,7 @@ } } while(ret == GNUTLS_E_INTERRUPTED or ret == GNUTLS_E_AGAIN); if(ret != GNUTLS_E_SUCCESS){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Error setting GnuTLS credentials: %s\n", + fprintf_plus(stderr, "Error setting GnuTLS credentials: %s\n", safer_gnutls_strerror(ret)); gnutls_deinit(*session); return -1; @@ -666,8 +636,7 @@ pf = PF_INET; break; default: - fprintf(stderr, "Mandos plugin mandos-client: " - "Bad address family: %d\n", af); + fprintf_plus(stderr, "Bad address family: %d\n", af); errno = EINVAL; return -1; } @@ -678,8 +647,7 @@ } if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Setting up a TCP connection to %s, port %" PRIu16 + fprintf_plus(stderr, "Setting up a TCP connection to %s, port %" PRIu16 "\n", ip, port); } @@ -712,8 +680,7 @@ } if(ret == 0){ int e = errno; - fprintf(stderr, "Mandos plugin mandos-client: " - "Bad address: %s\n", ip); + fprintf_plus(stderr, "Bad address: %s\n", ip); errno = e; goto mandos_end; } @@ -726,8 +693,7 @@ (&to.in6.sin6_addr)){ /* -Wstrict-aliasing=2 or lower and -Wunreachable-code*/ if(if_index == AVAHI_IF_UNSPEC){ - fprintf(stderr, "Mandos plugin mandos-client: " - "An IPv6 link-local address is incomplete" + fprintf_plus(stderr, "An IPv6 link-local address is incomplete" " without a network interface\n"); errno = EINVAL; goto mandos_end; @@ -752,13 +718,11 @@ if(if_indextoname((unsigned int)if_index, interface) == NULL){ perror_plus("if_indextoname"); } else { - fprintf(stderr, "Mandos plugin mandos-client: " - "Connection to: %s%%%s, port %" PRIu16 "\n", + fprintf_plus(stderr, "Connection to: %s%%%s, port %" PRIu16 "\n", ip, interface, port); } } else { - fprintf(stderr, "Mandos plugin mandos-client: " - "Connection to: %s, port %" PRIu16 "\n", ip, port); + fprintf_plus(stderr, "Connection to: %s, port %" PRIu16 "\n", ip, port); } char addrstr[(INET_ADDRSTRLEN > INET6_ADDRSTRLEN) ? INET_ADDRSTRLEN : INET6_ADDRSTRLEN] = ""; @@ -774,8 +738,7 @@ perror_plus("inet_ntop"); } else { if(strcmp(addrstr, ip) != 0){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Canonical address form: %s\n", addrstr); + fprintf_plus(stderr, "Canonical address form: %s\n", addrstr); } } } @@ -835,8 +798,7 @@ } if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Establishing TLS session with %s\n", ip); + fprintf_plus(stderr, "Establishing TLS session with %s\n", ip); } if(quit_now){ @@ -862,8 +824,7 @@ if(ret != GNUTLS_E_SUCCESS){ if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "*** GnuTLS Handshake failed ***\n"); + fprintf_plus(stderr, "*** GnuTLS Handshake failed ***\n"); gnutls_perror(ret); } errno = EPROTO; @@ -873,8 +834,7 @@ /* Read OpenPGP packet that contains the wanted password */ if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Retrieving OpenPGP encrypted password from %s\n", ip); + fprintf_plus(stderr, "Retrieving OpenPGP encrypted password from %s\n", ip); } while(true){ @@ -918,16 +878,14 @@ } } while(ret == GNUTLS_E_AGAIN or ret == GNUTLS_E_INTERRUPTED); if(ret < 0){ - fprintf(stderr, "Mandos plugin mandos-client: " - "*** GnuTLS Re-handshake failed ***\n"); + fprintf_plus(stderr, "*** GnuTLS Re-handshake failed ***\n"); gnutls_perror(ret); errno = EPROTO; goto mandos_end; } break; default: - fprintf(stderr, "Mandos plugin mandos-client: " - "Unknown error while reading data from" + fprintf_plus(stderr, "Unknown error while reading data from" " encrypted session with Mandos server\n"); gnutls_bye(session, GNUTLS_SHUT_RDWR); errno = EIO; @@ -939,8 +897,7 @@ } if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Closing TLS session\n"); + fprintf_plus(stderr, "Closing TLS session\n"); } if(quit_now){ @@ -975,8 +932,7 @@ if(ret == 0 and ferror(stdout)){ int e = errno; if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Error writing encrypted data: %s\n", + fprintf_plus(stderr, "Error writing encrypted data: %s\n", strerror(errno)); } errno = e; @@ -1040,8 +996,7 @@ switch(event){ default: case AVAHI_RESOLVER_FAILURE: - fprintf(stderr, "Mandos plugin mandos-client: " - "(Avahi Resolver) Failed to resolve service '%s'" + fprintf_plus(stderr, "(Avahi Resolver) Failed to resolve service '%s'" " of type '%s' in domain '%s': %s\n", name, type, domain, avahi_strerror(avahi_server_errno(mc.server))); break; @@ -1051,8 +1006,7 @@ char ip[AVAHI_ADDRESS_STR_MAX]; avahi_address_snprint(ip, sizeof(ip), address); if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Mandos server \"%s\" found on %s (%s, %" + fprintf_plus(stderr, "Mandos server \"%s\" found on %s (%s, %" PRIdMAX ") on port %" PRIu16 "\n", name, host_name, ip, (intmax_t)interface, port); } @@ -1092,8 +1046,7 @@ default: case AVAHI_BROWSER_FAILURE: - fprintf(stderr, "Mandos plugin mandos-client: " - "(Avahi browser) %s\n", + fprintf_plus(stderr, "(Avahi browser) %s\n", avahi_strerror(avahi_server_errno(mc.server))); avahi_simple_poll_quit(mc.simple_poll); return; @@ -1107,8 +1060,7 @@ if(avahi_s_service_resolver_new(mc.server, interface, protocol, name, type, domain, protocol, 0, resolve_callback, NULL) == NULL) - fprintf(stderr, "Mandos plugin mandos-client: " - "Avahi: Failed to resolve service '%s': %s\n", + fprintf_plus(stderr, "Avahi: Failed to resolve service '%s': %s\n", name, avahi_strerror(avahi_server_errno(mc.server))); break; @@ -1118,8 +1070,7 @@ case AVAHI_BROWSER_ALL_FOR_NOW: case AVAHI_BROWSER_CACHE_EXHAUSTED: if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "No Mandos server found, still searching...\n"); + fprintf_plus(stderr, "No Mandos server found, still searching...\n"); } break; } @@ -1164,40 +1115,35 @@ /* Reject the loopback device */ if(ifr->ifr_flags & IFF_LOOPBACK){ if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Rejecting loopback interface \"%s\"\n", ifname); + fprintf_plus(stderr, "Rejecting loopback interface \"%s\"\n", ifname); } return false; } /* Accept point-to-point devices only if connect_to is specified */ if(connect_to != NULL and (ifr->ifr_flags & IFF_POINTOPOINT)){ if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Accepting point-to-point interface \"%s\"\n", ifname); + fprintf_plus(stderr, "Accepting point-to-point interface \"%s\"\n", ifname); } return true; } /* Otherwise, reject non-broadcast-capable devices */ if(not (ifr->ifr_flags & IFF_BROADCAST)){ if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Rejecting non-broadcast interface \"%s\"\n", ifname); + fprintf_plus(stderr, "Rejecting non-broadcast interface \"%s\"\n", ifname); } return false; } /* Reject non-ARP interfaces (including dummy interfaces) */ if(ifr->ifr_flags & IFF_NOARP){ if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Rejecting non-ARP interface \"%s\"\n", ifname); + fprintf_plus(stderr, "Rejecting non-ARP interface \"%s\"\n", ifname); } return false; } /* Accept this device */ if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Interface \"%s\" is good\n", ifname); + fprintf_plus(stderr, "Interface \"%s\" is good\n", ifname); } return true; } @@ -1215,8 +1161,7 @@ struct ifreq ifr; if(not get_flags(if_entry->d_name, &ifr)){ if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Failed to get flags for interface \"%s\"\n", + fprintf_plus(stderr, "Failed to get flags for interface \"%s\"\n", if_entry->d_name); } return 0; @@ -1241,8 +1186,7 @@ struct ifreq ifr; if(not get_flags(if_entry->d_name, &ifr)){ if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Failed to get flags for interface \"%s\"\n", + fprintf_plus(stderr, "Failed to get flags for interface \"%s\"\n", if_entry->d_name); } return 0; @@ -1251,8 +1195,7 @@ /* Reject down interfaces */ if(not (ifr.ifr_flags & IFF_UP)){ if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Rejecting down interface \"%s\"\n", + fprintf_plus(stderr, "Rejecting down interface \"%s\"\n", if_entry->d_name); } return 0; @@ -1261,8 +1204,7 @@ /* Reject non-running interfaces */ if(not (ifr.ifr_flags & IFF_RUNNING)){ if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Rejecting non-running interface \"%s\"\n", + fprintf_plus(stderr, "Rejecting non-running interface \"%s\"\n", if_entry->d_name); } return 0; @@ -1303,8 +1245,7 @@ if((direntry->d_name)[sret] != '\0'){ /* Contains non-allowed characters */ if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Ignoring hook \"%s\" with bad name\n", + fprintf_plus(stderr, "Ignoring hook \"%s\" with bad name\n", direntry->d_name); } return 0; @@ -1327,8 +1268,7 @@ if(not (S_ISREG(st.st_mode))){ /* Not a regular file */ if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Ignoring hook \"%s\" - not a file\n", + fprintf_plus(stderr, "Ignoring hook \"%s\" - not a file\n", direntry->d_name); } return 0; @@ -1336,8 +1276,7 @@ if(not (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))){ /* Not executable */ if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Ignoring hook \"%s\" - not executable\n", + fprintf_plus(stderr, "Ignoring hook \"%s\" - not executable\n", direntry->d_name); } return 0; @@ -1354,14 +1293,12 @@ while(true){ if(mc.current_server == NULL){ if (debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Wait until first server is found. No timeout!\n"); + fprintf_plus(stderr, "Wait until first server is found. No timeout!\n"); } ret = avahi_simple_poll_iterate(s, -1); } else { if (debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Check current_server if we should run it," + fprintf_plus(stderr, "Check current_server if we should run it," " or wait\n"); } /* the current time */ @@ -1384,8 +1321,7 @@ - ((intmax_t)waited_time.tv_nsec / 1000000)); if (debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Blocking for %" PRIdMAX " ms\n", block_time); + fprintf_plus(stderr, "Blocking for %" PRIdMAX " ms\n", block_time); } if(block_time <= 0){ @@ -1581,8 +1517,8 @@ argp_state_help(state, state->out_stream, ARGP_HELP_USAGE | ARGP_HELP_EXIT_ERR); case 'V': /* --version */ - fprintf(state->out_stream, "Mandos plugin mandos-client: "); - fprintf(state->out_stream, "%s\n", argp_program_version); + fprintf_plus(state->out_stream, "Mandos plugin mandos-client: "); + fprintf_plus(state->out_stream, "%s\n", argp_program_version); exit(argp_err_exit_status); break; default: @@ -1740,23 +1676,20 @@ } if(WIFEXITED(status)){ if(WEXITSTATUS(status) != 0){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Warning: network hook \"%s\" exited" + fprintf_plus(stderr, "Warning: network hook \"%s\" exited" " with status %d\n", direntry->d_name, WEXITSTATUS(status)); free(fullname); continue; } } else if(WIFSIGNALED(status)){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Warning: network hook \"%s\" died by" + fprintf_plus(stderr, "Warning: network hook \"%s\" died by" " signal %d\n", direntry->d_name, WTERMSIG(status)); free(fullname); continue; } else { - fprintf(stderr, "Mandos plugin mandos-client: " - "Warning: network hook \"%s\" crashed\n", + fprintf_plus(stderr, "Warning: network hook \"%s\" crashed\n", direntry->d_name); free(fullname); continue; @@ -1790,8 +1723,7 @@ /* Pick the first interface returned */ interface = strdup(direntries[0]->d_name); if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Using interface \"%s\"\n", interface); + fprintf_plus(stderr, "Using interface \"%s\"\n", interface); } if(interface == NULL){ perror_plus("malloc"); @@ -1802,8 +1734,7 @@ free(direntries); } else { free(direntries); - fprintf(stderr, "Mandos plugin mandos-client: " - "Could not find a network interface\n"); + fprintf_plus(stderr, "Could not find a network interface\n"); exitcode = EXIT_FAILURE; goto end; } @@ -1815,8 +1746,7 @@ srand((unsigned int) time(NULL)); mc.simple_poll = avahi_simple_poll_new(); if(mc.simple_poll == NULL){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Avahi: Failed to create simple poll object.\n"); + fprintf_plus(stderr, "Avahi: Failed to create simple poll object.\n"); exitcode = EX_UNAVAILABLE; goto end; } @@ -1888,8 +1818,7 @@ if(strcmp(interface, "none") != 0){ if_index = (AvahiIfIndex) if_nametoindex(interface); if(if_index == 0){ - fprintf(stderr, "Mandos plugin mandos-client: " - "No such interface: \"%s\"\n", interface); + fprintf_plus(stderr, "No such interface: \"%s\"\n", interface); exitcode = EX_UNAVAILABLE; goto end; } @@ -2036,8 +1965,7 @@ ret = init_gnutls_global(pubkey, seckey); if(ret == -1){ - fprintf(stderr, "Mandos plugin mandos-client: " - "init_gnutls_global failed\n"); + fprintf_plus(stderr, "init_gnutls_global failed\n"); exitcode = EX_UNAVAILABLE; goto end; } else { @@ -2059,8 +1987,7 @@ } if(not init_gpgme(pubkey, seckey, tempdir)){ - fprintf(stderr, "Mandos plugin mandos-client: " - "init_gpgme failed\n"); + fprintf_plus(stderr, "init_gpgme failed\n"); exitcode = EX_UNAVAILABLE; goto end; } else { @@ -2076,8 +2003,7 @@ /* (Mainly meant for debugging) */ char *address = strrchr(connect_to, ':'); if(address == NULL){ - fprintf(stderr, "Mandos plugin mandos-client: " - "No colon in address\n"); + fprintf_plus(stderr, "No colon in address\n"); exitcode = EX_USAGE; goto end; } @@ -2091,8 +2017,7 @@ tmpmax = strtoimax(address+1, &tmp, 10); if(errno != 0 or tmp == address+1 or *tmp != '\0' or tmpmax != (uint16_t)tmpmax){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Bad port number\n"); + fprintf_plus(stderr, "Bad port number\n"); exitcode = EX_USAGE; goto end; } @@ -2128,8 +2053,7 @@ break; } if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Retrying in %d seconds\n", (int)retry_interval); + fprintf_plus(stderr, "Retrying in %d seconds\n", (int)retry_interval); } sleep((int)retry_interval); } @@ -2165,8 +2089,7 @@ /* Check if creating the Avahi server object succeeded */ if(mc.server == NULL){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Failed to create Avahi server: %s\n", + fprintf_plus(stderr, "Failed to create Avahi server: %s\n", avahi_strerror(error)); exitcode = EX_UNAVAILABLE; goto end; @@ -2181,8 +2104,7 @@ AVAHI_PROTO_UNSPEC, "_mandos._tcp", NULL, 0, browse_callback, NULL); if(sb == NULL){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Failed to create service browser: %s\n", + fprintf_plus(stderr, "Failed to create service browser: %s\n", avahi_strerror(avahi_server_errno(mc.server))); exitcode = EX_UNAVAILABLE; goto end; @@ -2195,23 +2117,20 @@ /* Run the main loop */ if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Starting Avahi loop search\n"); + fprintf_plus(stderr, "Starting Avahi loop search\n"); } ret = avahi_loop_with_timeout(mc.simple_poll, (int)(retry_interval * 1000)); if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "avahi_loop_with_timeout exited %s\n", + fprintf_plus(stderr, "avahi_loop_with_timeout exited %s\n", (ret == 0) ? "successfully" : "with error"); } end: if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "%s exiting\n", argv[0]); + fprintf_plus(stderr, "%s exiting\n", argv[0]); } /* Cleanup things */ @@ -2297,8 +2216,7 @@ } ret = remove(fullname); if(ret == -1){ - fprintf(stderr, "Mandos plugin mandos-client: " - "remove(\"%s\"): %s\n", fullname, strerror(errno)); + fprintf_plus(stderr, "remove(\"%s\"): %s\n", fullname, strerror(errno)); } free(fullname); }