version 1.10, 2019/09/18 09:52:47 |
version 1.11, 2019/09/18 09:54:36 |
|
|
#include "snmp.h" |
#include "snmp.h" |
#include "usm.h" |
#include "usm.h" |
|
|
#define GETOPT_COMMON "A:a:c:E:e:k:l:n:O:r:t:u:v:Z:" |
#define GETOPT_COMMON "A:a:c:E:e:K:k:l:n:O:r:t:u:v:X:x:Z:" |
|
|
int snmpc_get(int, char *[]); |
int snmpc_get(int, char *[]); |
int snmpc_walk(int, char *[]); |
int snmpc_walk(int, char *[]); |
|
|
main(int argc, char *argv[]) |
main(int argc, char *argv[]) |
{ |
{ |
const EVP_MD *md = NULL; |
const EVP_MD *md = NULL; |
|
const EVP_CIPHER *cipher = NULL; |
struct snmp_sec *sec; |
struct snmp_sec *sec; |
char *user = NULL; |
char *user = NULL; |
enum usm_key_level authkeylevel; |
enum usm_key_level authkeylevel; |
char *authkey = NULL; |
char *authkey = NULL; |
size_t authkeylen = 0; |
size_t authkeylen = 0; |
|
enum usm_key_level privkeylevel; |
|
char *privkey = NULL; |
|
size_t privkeylen = 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; |
|
|
err(1, "-3e"); |
err(1, "-3e"); |
} |
} |
break; |
break; |
|
case 'K': |
|
privkey = snmpc_hex2bin(optarg, &privkeylen); |
|
if (privkey == NULL) { |
|
if (errno == EINVAL) |
|
errx(1, "Bad key value after " |
|
"-3K flag."); |
|
errx(1, "-3K"); |
|
} |
|
privkeylevel = USM_KEY_LOCALIZED; |
|
break; |
case 'k': |
case 'k': |
authkey = snmpc_hex2bin(optarg, &authkeylen); |
authkey = snmpc_hex2bin(optarg, &authkeylen); |
if (authkey == NULL) { |
if (authkey == NULL) { |
|
|
else if (strcasecmp(optarg, "authNoPriv") == 0) |
else if (strcasecmp(optarg, "authNoPriv") == 0) |
seclevel = SNMP_MSGFLAG_AUTH | |
seclevel = SNMP_MSGFLAG_AUTH | |
SNMP_MSGFLAG_REPORT; |
SNMP_MSGFLAG_REPORT; |
|
else if (strcasecmp(optarg, "authPriv") == 0) |
|
seclevel = SNMP_MSGFLAG_AUTH | |
|
SNMP_MSGFLAG_PRIV | SNMP_MSGFLAG_REPORT; |
else |
else |
errx(1, "Invalid security level specified " |
errx(1, "Invalid security level specified " |
"after -l flag: %s", optarg); |
"after -l flag: %s", optarg); |
|
|
} |
} |
} |
} |
break; |
break; |
|
case 'X': |
|
privkey = optarg; |
|
privkeylen = strlen(privkey); |
|
privkeylevel = USM_KEY_PASSWORD; |
|
break; |
|
case 'x': |
|
if (strcasecmp(optarg, "DES") == 0) |
|
cipher = EVP_des_cbc(); |
|
else if (strcasecmp(optarg, "AES") == 0) |
|
cipher = EVP_aes_128_cfb128(); |
|
else |
|
errx(1, "Invalid privacy protocol " |
|
"specified after -3x flag: %s", |
|
optarg); |
|
break; |
case 'Z': |
case 'Z': |
boots = strtoll(optarg, &strtolp, 10); |
boots = strtoll(optarg, &strtolp, 10); |
if (boots < 0 || strtolp == optarg || strtolp[0] != ',') |
if (boots < 0 || strtolp == optarg || strtolp[0] != ',') |
|
|
authkeylevel) == -1) |
authkeylevel) == -1) |
err(1, "Can't set authkey"); |
err(1, "Can't set authkey"); |
} |
} |
|
if (seclevel & SNMP_MSGFLAG_PRIV) { |
|
if (cipher == NULL) |
|
cipher = EVP_des_cbc(); |
|
if (privkey == NULL) |
|
errx(1, "No privKey or privPassword specified"); |
|
if (usm_setpriv(sec, cipher, privkey, privkeylen, |
|
privkeylevel) == -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) |
|
|
snmp_app->name, |
snmp_app->name, |
snmp_app->usecommonopt ? |
snmp_app->usecommonopt ? |
" [-A authpass] [-a digest] [-c community] [-e secengineid]\n" |
" [-A authpass] [-a digest] [-c community] [-e secengineid]\n" |
" [-E ctxengineid] [-k localauth] [-l seclevel] [-n ctxname]\n" |
" [-E ctxengineid] [-K localpriv] [-k localauth] [-l seclevel]\n" |
" [-O afnqvxSQ] [-r retries] [-t timeout] [-u user] [-v version]\n" |
" [-n ctxname] [-O afnqvxSQ] [-r retries] [-t timeout] [-u user]\n" |
" [-Z boots,time]\n" |
" [-v version] [-X privpass] [-x cipher] [-Z boots,time]\n" |
" " : "", |
" " : "", |
snmp_app->usage == NULL ? "" : snmp_app->usage); |
snmp_app->usage == NULL ? "" : snmp_app->usage); |
exit(1); |
exit(1); |