=== modified file 'plugins.d/mandos-client.c' --- plugins.d/mandos-client.c 2011-11-14 20:11:42 +0000 +++ plugins.d/mandos-client.c 2011-11-14 20:55:32 +0000 @@ -174,6 +174,15 @@ perror(print_text); } +int fprintf_plus(FILE *stream, const char *format, ...){ + va_list ap; + va_start (ap, format); + + TEMP_FAILURE_RETRY(fprintf(stream, "Mandos plugin %s: ", + program_invocation_short_name)); + return TEMP_FAILURE_RETRY(vfprintf(stream, format, ap)); +} + /* * Make additional room in "buffer" for at least BUFFER_SIZE more * bytes. "buffer_capacity" is how much is currently allocated, @@ -253,17 +262,15 @@ 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", - gpgme_strsource(rc), gpgme_strerror(rc)); + 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", - gpgme_strsource(rc), gpgme_strerror(rc)); + fprintf_plus(stderr, "bad gpgme_op_import: %s: %s\n", + gpgme_strsource(rc), gpgme_strerror(rc)); return false; } @@ -276,26 +283,23 @@ } 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", - gpgme_strsource(rc), gpgme_strerror(rc)); + fprintf_plus(stderr, "bad gpgme_engine_check_version: %s: %s\n", + gpgme_strsource(rc), gpgme_strerror(rc)); return false; } /* 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", - gpgme_strsource(rc), gpgme_strerror(rc)); + fprintf_plus(stderr, "bad gpgme_get_engine_info: %s: %s\n", + gpgme_strsource(rc), gpgme_strerror(rc)); return false; } while(engine_info != NULL){ @@ -307,17 +311,17 @@ 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: " - "bad gpgme_new: %s: %s\n", gpgme_strsource(rc), - gpgme_strerror(rc)); + fprintf_plus(stderr, "Mandos plugin mandos-client: " + "bad gpgme_new: %s: %s\n", gpgme_strsource(rc), + gpgme_strerror(rc)); return false; } @@ -342,26 +346,24 @@ 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", - gpgme_strsource(rc), gpgme_strerror(rc)); + fprintf_plus(stderr, "bad gpgme_data_new_from_mem: %s: %s\n", + gpgme_strsource(rc), gpgme_strerror(rc)); return -1; } /* 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: " - "bad gpgme_data_new: %s: %s\n", - gpgme_strsource(rc), gpgme_strerror(rc)); + 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); return -1; } @@ -370,39 +372,32 @@ 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", - gpgme_strsource(rc), gpgme_strerror(rc)); + 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", - result->unsupported_algorithm); - fprintf(stderr, "Mandos plugin mandos-client: " - "Wrong key usage: %u\n", - result->wrong_key_usage); + fprintf_plus(stderr, "Unsupported algorithm: %s\n", + result->unsupported_algorithm); + 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", - 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", - recipient->status == GPG_ERR_NO_SECKEY - ? "No" : "Yes"); + fprintf_plus(stderr, "Public key algorithm: %s\n", + gpgme_pubkey_algo_name + (recipient->pubkey_algo)); + 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; } } @@ -411,8 +406,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 */ @@ -449,8 +443,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]); } @@ -478,7 +471,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, @@ -486,14 +479,13 @@ 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; } @@ -508,45 +500,43 @@ /* 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" - " secret key %s as GnuTLS credentials\n", pubkeyfilename, - seckeyfilename); + fprintf_plus(stderr, "Attempting to use OpenPGP public key %s and" + " secret key %s as GnuTLS credentials\n", + pubkeyfilename, + seckeyfilename); } ret = gnutls_certificate_set_openpgp_key_file (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:" - " %s\n", safer_gnutls_strerror(ret)); + 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", - safer_gnutls_strerror(ret)); + fprintf_plus(stderr, "Error in GnuTLS prime generation: %s\n", + safer_gnutls_strerror(ret)); goto globalfail; } @@ -572,9 +562,9 @@ } } 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", - safer_gnutls_strerror(ret)); + fprintf_plus(stderr, + "Error in GnuTLS session initialization: %s\n", + safer_gnutls_strerror(ret)); } { @@ -587,10 +577,9 @@ } } 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; } @@ -605,9 +594,8 @@ } } 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", - safer_gnutls_strerror(ret)); + fprintf_plus(stderr, "Error setting GnuTLS credentials: %s\n", + safer_gnutls_strerror(ret)); gnutls_deinit(*session); return -1; } @@ -658,8 +646,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; } @@ -670,9 +657,8 @@ } if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Setting up a TCP connection to %s, port %" PRIu16 - "\n", ip, port); + fprintf_plus(stderr, "Setting up a TCP connection to %s, port %" + PRIu16 "\n", ip, port); } tcp_sd = socket(pf, SOCK_STREAM, 0); @@ -704,8 +690,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; } @@ -718,9 +703,8 @@ (&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" - " without a network interface\n"); + fprintf_plus(stderr, "An IPv6 link-local address is" + " incomplete without a network interface\n"); errno = EINVAL; goto mandos_end; } @@ -744,13 +728,12 @@ 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", - ip, interface, port); + 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] = ""; @@ -766,8 +749,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); } } } @@ -827,8 +809,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){ @@ -854,8 +835,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; @@ -865,8 +845,8 @@ /* 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){ @@ -910,17 +890,16 @@ } } 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" - " encrypted session with Mandos server\n"); + fprintf_plus(stderr, "Unknown error while reading data from" + " encrypted session with Mandos server\n"); gnutls_bye(session, GNUTLS_SHUT_RDWR); errno = EIO; goto mandos_end; @@ -931,8 +910,7 @@ } if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Closing TLS session\n"); + fprintf_plus(stderr, "Closing TLS session\n"); } if(quit_now){ @@ -967,9 +945,8 @@ if(ret == 0 and ferror(stdout)){ int e = errno; if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Error writing encrypted data: %s\n", - strerror(errno)); + fprintf_plus(stderr, "Error writing encrypted data: %s\n", + strerror(errno)); } errno = e; goto mandos_end; @@ -1032,10 +1009,10 @@ switch(event){ default: case AVAHI_RESOLVER_FAILURE: - fprintf(stderr, "Mandos plugin mandos-client: " - "(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))); + 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; case AVAHI_RESOLVER_FOUND: @@ -1043,10 +1020,9 @@ 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, %" - PRIdMAX ") on port %" PRIu16 "\n", name, host_name, - ip, (intmax_t)interface, port); + fprintf_plus(stderr, "Mandos server \"%s\" found on %s (%s, %" + PRIdMAX ") on port %" PRIu16 "\n", name, + host_name, ip, (intmax_t)interface, port); } int ret = start_mandos_communication(ip, port, interface, avahi_proto_to_af(proto)); @@ -1084,9 +1060,8 @@ default: case AVAHI_BROWSER_FAILURE: - fprintf(stderr, "Mandos plugin mandos-client: " - "(Avahi browser) %s\n", - avahi_strerror(avahi_server_errno(mc.server))); + fprintf_plus(stderr, "(Avahi browser) %s\n", + avahi_strerror(avahi_server_errno(mc.server))); avahi_simple_poll_quit(mc.simple_poll); return; @@ -1099,9 +1074,9 @@ 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", - name, avahi_strerror(avahi_server_errno(mc.server))); + fprintf_plus(stderr, "Avahi: Failed to resolve service '%s':" + " %s\n", name, + avahi_strerror(avahi_server_errno(mc.server))); break; case AVAHI_BROWSER_REMOVE: @@ -1110,8 +1085,8 @@ 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; } @@ -1156,40 +1131,39 @@ /* 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; } @@ -1207,9 +1181,8 @@ 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", - if_entry->d_name); + fprintf_plus(stderr, "Failed to get flags for interface " + "\"%s\"\n", if_entry->d_name); } return 0; } @@ -1233,9 +1206,8 @@ 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", - if_entry->d_name); + fprintf_plus(stderr, "Failed to get flags for interface " + "\"%s\"\n", if_entry->d_name); } return 0; } @@ -1243,9 +1215,8 @@ /* Reject down interfaces */ if(not (ifr.ifr_flags & IFF_UP)){ if(debug){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Rejecting down interface \"%s\"\n", - if_entry->d_name); + fprintf_plus(stderr, "Rejecting down interface \"%s\"\n", + if_entry->d_name); } return 0; } @@ -1253,9 +1224,8 @@ /* 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", - if_entry->d_name); + fprintf_plus(stderr, "Rejecting non-running interface \"%s\"\n", + if_entry->d_name); } return 0; } @@ -1295,9 +1265,8 @@ 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", - direntry->d_name); + fprintf_plus(stderr, "Ignoring hook \"%s\" with bad name\n", + direntry->d_name); } return 0; } @@ -1319,18 +1288,16 @@ 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", - direntry->d_name); + fprintf_plus(stderr, "Ignoring hook \"%s\" - not a file\n", + direntry->d_name); } return 0; } 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", - direntry->d_name); + fprintf_plus(stderr, "Ignoring hook \"%s\" - not executable\n", + direntry->d_name); } return 0; } @@ -1346,15 +1313,14 @@ 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," - " or wait\n"); + fprintf_plus(stderr, "Check current_server if we should run" + " it, or wait\n"); } /* the current time */ ret = clock_gettime(CLOCK_MONOTONIC, &now); @@ -1376,8 +1342,8 @@ - ((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){ @@ -1479,24 +1445,21 @@ } if(WIFEXITED(status)){ if(WEXITSTATUS(status) != 0){ - fprintf(stderr, "Mandos plugin mandos-client: " - "Warning: network hook \"%s\" exited" - " with status %d\n", direntry->d_name, - WEXITSTATUS(status)); + 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" - " signal %d\n", direntry->d_name, - WTERMSIG(status)); + 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", - direntry->d_name); + fprintf_plus(stderr, "Warning: network hook \"%s\"" + " crashed\n", direntry->d_name); free(fullname); continue; } @@ -1674,8 +1637,9 @@ 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: @@ -1726,7 +1690,8 @@ if(ret == -1){ perror_plus("fstat"); } else { - if(S_ISREG(st.st_mode) and st.st_uid == 0 and st.st_gid == 0){ + if(S_ISREG(st.st_mode) + and st.st_uid == 0 and st.st_gid == 0){ ret = fchown(seckey_fd, uid, gid); if(ret == -1){ perror_plus("fchown"); @@ -1746,7 +1711,8 @@ if(ret == -1){ perror_plus("fstat"); } else { - if(S_ISREG(st.st_mode) and st.st_uid == 0 and st.st_gid == 0){ + if(S_ISREG(st.st_mode) + and st.st_uid == 0 and st.st_gid == 0){ ret = fchown(pubkey_fd, uid, gid); if(ret == -1){ perror_plus("fchown"); @@ -1803,8 +1769,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"); @@ -1815,8 +1780,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; } @@ -1828,8 +1792,8 @@ 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; } @@ -1901,8 +1865,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; } @@ -2041,8 +2004,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 { @@ -2064,8 +2026,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 { @@ -2081,8 +2042,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; } @@ -2096,8 +2056,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; } @@ -2133,8 +2092,8 @@ 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); } @@ -2170,9 +2129,8 @@ /* 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", - avahi_strerror(error)); + fprintf_plus(stderr, "Failed to create Avahi server: %s\n", + avahi_strerror(error)); exitcode = EX_UNAVAILABLE; goto end; } @@ -2186,9 +2144,8 @@ 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", - avahi_strerror(avahi_server_errno(mc.server))); + fprintf_plus(stderr, "Failed to create service browser: %s\n", + avahi_strerror(avahi_server_errno(mc.server))); exitcode = EX_UNAVAILABLE; goto end; } @@ -2200,23 +2157,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", - (ret == 0) ? "successfully" : "with error"); + 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 */ @@ -2305,8 +2259,8 @@ } 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); }