diff --git a/smmapdfw/smmapd/smmapd.c b/smmapdfw/smmapd/smmapd.c index 3171714..6eadae0 100644 --- a/smmapdfw/smmapd/smmapd.c +++ b/smmapdfw/smmapd/smmapd.c @@ -76,6 +76,7 @@ #define CFG_SECTION_GLOBAL "global" #define CFG_NAME_ADDRESS "address" #define CFG_NAME_PORT "port" +#define CFG_NETSTRING_DISABLED "netstring_disabled" #define DEFAULT_PORT "8888" @@ -108,6 +109,8 @@ count_t thread_counter; cfg_t *cfg; +int netstring_disabled = 0; + #if ENABLE_STATS==1 void * statser(void * arg) { int stdout_nice = atoi(findcfgx(cfg, "stats", "stdout_nice", "0")); @@ -190,22 +193,29 @@ void * networker(void * arg) { else buffer[cnt] = '\0'; - len = strtol(buffer, &input, 10); - if ((0 == len) && (buffer == input)) { - syslog(LOG_DEBUG, "networker: netstring unparsable, no length found: %s", buffer); - dispatcher_result = SMM_NETSTRING_UNPARSABLE; - } else if (*input++ != ':') { - syslog(LOG_DEBUG, "networker: netstring unparsable, no colon found: %s", buffer); - dispatcher_result = SMM_NETSTRING_UNPARSABLE; - } else if (strlen(input)-1 != len) { - syslog(LOG_DEBUG, "networker: netstring unparsable, length does not match: %s", buffer); - dispatcher_result = SMM_NETSTRING_UNPARSABLE; - } else if (input[strlen(input)-1] != ',') { - syslog(LOG_DEBUG, "networker: netstring unparsable, no terminating comma: %s", buffer); - dispatcher_result = SMM_NETSTRING_UNPARSABLE; + dispatcher_result = 0; + if (netstring_disabled) { + input = buffer; } else { - input[strlen(input)-1] = '\0'; /* strip off the comma */ - + len = strtol(buffer, &input, 10); + if ((0 == len) && (buffer == input)) { + syslog(LOG_DEBUG, "networker: netstring unparsable, no length found: %s", buffer); + dispatcher_result = SMM_NETSTRING_UNPARSABLE; + } else if (*input++ != ':') { + syslog(LOG_DEBUG, "networker: netstring unparsable, no colon found: %s", buffer); + dispatcher_result = SMM_NETSTRING_UNPARSABLE; + } else if (strlen(input)-1 != len) { + syslog(LOG_DEBUG, "networker: netstring unparsable, length does not match: %s", buffer); + dispatcher_result = SMM_NETSTRING_UNPARSABLE; + } else if (input[strlen(input)-1] != ',') { + syslog(LOG_DEBUG, "networker: netstring unparsable, no terminating comma: %s", buffer); + dispatcher_result = SMM_NETSTRING_UNPARSABLE; + } else { + input[strlen(input)-1] = '\0'; /* strip off the comma */ + } + } + + if (!dispatcher_result) { answer[0] = '\0'; dispatcher_result = containers_dispatcher(container_handle, input, answer); syslog(LOG_DEBUG, "networker: dispatcher result: %d, answer: %s", dispatcher_result, answer); @@ -224,11 +234,15 @@ void * networker(void * arg) { if (NULL == answer_ptr) answer_ptr = answer; - snprintf(output, OUTPUT_BUFSIZE, "%d:%s%s%s,", - strlen(result_text) + strlen(answer_ptr) + ((strlen(answer_ptr) > 0) ? 1 : 0), - result_text, - (strlen(answer_ptr) > 0) ? " " : "", - answer_ptr); + if (netstring_disabled) { + snprintf(output, OUTPUT_BUFSIZE, "%s\n", answer_ptr); + } else { + snprintf(output, OUTPUT_BUFSIZE, "%d:%s%s%s,", + strlen(result_text) + strlen(answer_ptr) + ((strlen(answer_ptr) > 0) ? 1 : 0), + result_text, + (strlen(answer_ptr) > 0) ? " " : "", + answer_ptr); + } safe_write(thread->clientSock, output, strlen(output)); } @@ -259,6 +273,9 @@ int server() { char *cfg_address, *cfg_port; + netstring_disabled = atoi(findcfgx(cfg, CFG_SECTION_GLOBAL, CFG_NETSTRING_DISABLED, "0")); + + serverSock = socket(AF_INET, SOCK_STREAM, 0); if (-1 == serverSock) { syslog(LOG_ERR, "server: failure when creating server socket"); diff --git a/smmapdfw/smmapd/smmapd.ini b/smmapdfw/smmapd/smmapd.ini index 38d5a9d..6b63195 100644 --- a/smmapdfw/smmapd/smmapd.ini +++ b/smmapdfw/smmapd/smmapd.ini @@ -9,6 +9,10 @@ plugins = verifier enable_stats = 0 enable_snmp = 1 +; disables the netstring codec, only for debugging in the development +; phase, sendmail is unable to talk to smmapd if the codec is disabled +; netstring_disabled = 1 + [snmp] agentx_socket = /var/agentx/master