[BACK]Return to snmpc.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / snmp

Diff for /src/usr.bin/snmp/snmpc.c between version 1.9 and 1.10

version 1.9, 2019/09/18 09:48:14 version 1.10, 2019/09/18 09:52:47
Line 23 
Line 23 
 #include <sys/un.h>  #include <sys/un.h>
   
 #include <arpa/inet.h>  #include <arpa/inet.h>
   #include <openssl/evp.h>
   
 #include <ber.h>  #include <ber.h>
 #include <ctype.h>  #include <ctype.h>
Line 41 
Line 42 
 #include "snmp.h"  #include "snmp.h"
 #include "usm.h"  #include "usm.h"
   
 #define GETOPT_COMMON           "c:E:e:n:O:r:t:u:v:Z:"  #define GETOPT_COMMON           "A:a:c:E:e:k:l:n:O:r:t:u:v:Z:"
   
 int snmpc_get(int, char *[]);  int snmpc_get(int, char *[]);
 int snmpc_walk(int, char *[]);  int snmpc_walk(int, char *[]);
Line 96 
Line 97 
 int  int
 main(int argc, char *argv[])  main(int argc, char *argv[])
 {  {
           const EVP_MD *md = NULL;
         struct snmp_sec *sec;          struct snmp_sec *sec;
         char *user = NULL;          char *user = NULL;
           enum usm_key_level authkeylevel;
           char *authkey = NULL;
           size_t authkeylen = 0;
         int seclevel = SNMP_MSGFLAG_REPORT;          int seclevel = SNMP_MSGFLAG_REPORT;
         char *ctxname = NULL;          char *ctxname = NULL;
         char *ctxengineid = NULL, *secengineid = NULL;          char *ctxengineid = NULL, *secengineid = NULL;
Line 143 
Line 148 
   
         while ((ch = getopt(argc, argv, optstr)) != -1) {          while ((ch = getopt(argc, argv, optstr)) != -1) {
                 switch (ch) {                  switch (ch) {
                   case 'A':
                           authkey = optarg;
                           authkeylen = strlen(authkey);
                           authkeylevel = USM_KEY_PASSWORD;
                           break;
                   case 'a':
                           if (strcasecmp(optarg, "MD5") == 0)
                                   md = EVP_md5();
                           else if (strcasecmp(optarg, "SHA") == 0)
                                   md = EVP_sha1();
                           else if (strcasecmp(optarg, "SHA-224") == 0)
                                   md = EVP_sha224();
                           else if (strcasecmp(optarg, "SHA-256") == 0)
                                   md = EVP_sha256();
                           else if (strcasecmp(optarg, "SHA-384") == 0)
                                   md = EVP_sha384();
                           else if (strcasecmp(optarg, "SHA-512") == 0)
                                   md = EVP_sha512();
                           else
                                   errx(1, "Invalid authentication protocol "
                                       "specified after -a flag: %s", optarg);
                           break;
                 case 'c':                  case 'c':
                         community = optarg;                          community = optarg;
                         break;                          break;
Line 166 
Line 193 
                                 err(1, "-3e");                                  err(1, "-3e");
                         }                          }
                         break;                          break;
                   case 'k':
                           authkey = snmpc_hex2bin(optarg, &authkeylen);
                           if (authkey == NULL) {
                                   if (errno == EINVAL)
                                           errx(1, "Bad key value after -k flag.");
                                   err(1, "-k");
                           }
                           authkeylevel = USM_KEY_LOCALIZED;
                           break;
                   case 'l':
                           if (strcasecmp(optarg, "noAuthNoPriv") == 0)
                                   seclevel = SNMP_MSGFLAG_REPORT;
                           else if (strcasecmp(optarg, "authNoPriv") == 0)
                                   seclevel = SNMP_MSGFLAG_AUTH |
                                       SNMP_MSGFLAG_REPORT;
                           else
                                   errx(1, "Invalid security level specified "
                                       "after -l flag: %s", optarg);
                           break;
                 case 'n':                  case 'n':
                         ctxname = optarg;                          ctxname = optarg;
                         break;                          break;
Line 348 
Line 394 
                         errx(1, "No securityName specified");                          errx(1, "No securityName specified");
                 if ((sec = usm_init(user, strlen(user))) == NULL)                  if ((sec = usm_init(user, strlen(user))) == NULL)
                         err(1, "usm_init");                          err(1, "usm_init");
                   if (seclevel & SNMP_MSGFLAG_AUTH) {
                           if (md == NULL)
                                   md = EVP_md5();
                           if (authkey == NULL)
                                   errx(1, "No authKey or authPassword specified");
                           if (usm_setauth(sec, md, authkey, authkeylen,
                               authkeylevel) == -1)
                                   err(1, "Can't set authkey");
                   }
                 if (secengineid != NULL) {                  if (secengineid != NULL) {
                         if (usm_setengineid(sec, secengineid,                          if (usm_setengineid(sec, secengineid,
                             secengineidlen) == -1)                              secengineidlen) == -1)
Line 1031 
Line 1086 
                 fprintf(stderr, "usage: snmp %s%s%s\n",                  fprintf(stderr, "usage: snmp %s%s%s\n",
                     snmp_app->name,                      snmp_app->name,
                     snmp_app->usecommonopt ?                      snmp_app->usecommonopt ?
                     " [-c community] [-e secengineid] [-E ctxengineid] [-n ctxname]\n"                      " [-A authpass] [-a digest] [-c community] [-e secengineid]\n"
                       "            [-E ctxengineid] [-k localauth] [-l seclevel] [-n ctxname]\n"
                     "            [-O afnqvxSQ] [-r retries] [-t timeout] [-u user] [-v version]\n"                      "            [-O afnqvxSQ] [-r retries] [-t timeout] [-u user] [-v version]\n"
                     "            [-Z boots,time]\n"                      "            [-Z boots,time]\n"
                     "            " : "",                      "            " : "",

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10