diff -urN ./plugins/check_snmp.c ../plugins/plugins/check_snmp.c --- ./plugins/check_snmp.c 2005-01-24 08:29:54.000000000 +0100 +++ ../plugins/plugins/check_snmp.c 2005-02-17 16:53:58.000000000 +0100 @@ -36,6 +36,7 @@ #define DEFAULT_AUTH_PROTOCOL "MD5" #define DEFAULT_DELIMITER "=" #define DEFAULT_OUTPUT_DELIMITER " " +#define DEFAULT_SEC_LEVEL "noAuthNoPriv" #define mark(a) ((a)!=0?"*":"") @@ -88,12 +89,12 @@ #endif char *server_address = NULL; -char *community = NULL; +char *community = DEFAULT_COMMUNITY; char *authpriv = NULL; -char *proto = NULL; -char *seclevel = NULL; +char *proto = DEFAULT_PROTOCOL; +char *seclevel = DEFAULT_SEC_LEVEL; char *secname = NULL; -char *authproto = NULL; +char *authproto = DEFAULT_AUTH_PROTOCOL; char *authpasswd = NULL; char *privpasswd = NULL; char *oid; @@ -147,15 +148,15 @@ eval_method[i] = CHECK_UNDEF; i = 0; - oid = strdup (""); - label = strdup ("SNMP"); - units = strdup (""); - port = strdup (DEFAULT_PORT); - outbuff = strdup (""); - output = strdup (""); - delimiter = strdup (DEFAULT_DELIMITER); - output_delim = strdup (DEFAULT_OUTPUT_DELIMITER); - miblist = strdup (DEFAULT_MIBLIST); + oid = ""; + label = "SNMP"; + units = ""; + port = DEFAULT_PORT; + outbuff = ""; + output = ""; + delimiter = DEFAULT_DELIMITER; + output_delim = DEFAULT_OUTPUT_DELIMITER; + miblist = DEFAULT_MIBLIST; timeout_interval = DEFAULT_TIMEOUT; retries = DEFAULT_RETRIES; @@ -598,9 +599,6 @@ if (server_address == NULL) server_address = argv[optind]; - if (community == NULL) - community = strdup (DEFAULT_COMMUNITY); - return validate_arguments (); } @@ -631,30 +629,28 @@ validate_arguments () { - /* Need better checks to verify seclevel and authproto choices */ - - if (seclevel == NULL) - asprintf (&seclevel, "noAuthNoPriv"); + /* Need checks to verify seclevel and authproto choices */ + /* default protocol is set in variable declaraion, so this can't + * possibly be NULL any-more. It can, however, be a zero length string + * (if a check_command is specified that can use either v1 or v2c, the + * $ARGx$ macro is quote-escaped and not given in service-description) + * in which case we don't fuss much about it but just set it to default */ + if (!strlen(proto)) + proto = DEFAULT_PROTOCOL; - if (authproto == NULL ) - asprintf(&authproto, DEFAULT_AUTH_PROTOCOL); - - - - if (proto == NULL || (strcmp(proto,DEFAULT_PROTOCOL) == 0) ) { /* default protocol version */ - asprintf(&proto, DEFAULT_PROTOCOL); + if (proto[0] == '1' || proto[0] == '2') { /* community based access */ asprintf(&authpriv, "%s%s", "-c ", community); } else if ( strcmp (proto, "3") == 0 ) { /* snmpv3 args */ - asprintf(&proto, "%s", "3"); - + proto = "3"; + if ( (strcmp(seclevel, "noAuthNoPriv") == 0) || seclevel == NULL ) { - asprintf(&authpriv, "%s", "-l noAuthNoPriv" ); + asprintf(&authpriv, "%s %s", "-l", DEFAULT_SEC_LEVEL); } else if ( strcmp(seclevel, "authNoPriv") == 0 ) { if ( secname == NULL || authpasswd == NULL) { - printf (_("Missing secname (%s) or authpassword (%s) ! \n"),secname, authpasswd ); + printf (_("Missing secname or authpassword!\n")); print_usage (); exit (STATE_UNKNOWN); } @@ -662,7 +658,7 @@ } else if ( strcmp(seclevel, "authPriv") == 0 ) { if ( secname == NULL || authpasswd == NULL || privpasswd == NULL ) { - printf (_("Missing secname (%s), authpassword (%s), or privpasswd (%s)! \n"),secname, authpasswd,privpasswd ); + printf (_("Missing secname, authpassword or privpasswd!\n")); print_usage (); exit (STATE_UNKNOWN); }