Imported Upstream version 2.7.1

This commit is contained in:
Laurent Bigonville 2013-11-24 16:00:12 +01:00
parent a1fa151fc7
commit 0121794af9
451 changed files with 41339 additions and 10887 deletions

View file

@ -35,13 +35,14 @@
#define ERR_BAD_OPTION (-1)
const char optstring[] = "?ht:s:e:c:l:u:W:X:w:x:p:CUSMOAm:NPqIVa";
const char optstring[] = "?ht:s:e:E:c:l:u:W:X:w:x:p:b:B:d:D:CUSMOAm:NPqIVa";
#ifdef HAVE_GETOPT_LONG
const struct option longopts[] =
{{ "timeout",required_argument,NULL,'t' },
{ "start_ip",required_argument,NULL,'s' },
{ "end_ip",required_argument,NULL,'e' },
{ "eaton_serial",required_argument,NULL,'E' },
{ "mask_cidr",required_argument,NULL,'m' },
{ "community",required_argument,NULL,'c' },
{ "secLevel",required_argument,NULL,'l' },
@ -50,6 +51,10 @@ const struct option longopts[] =
{ "privPassword",required_argument,NULL,'X' },
{ "authProtocol",required_argument,NULL,'w' },
{ "privProtocol",required_argument,NULL,'x' },
{ "username",required_argument,NULL,'b' },
{ "password",required_argument,NULL,'B' },
{ "authType",required_argument,NULL,'d' },
{ "cipher_suite_id",required_argument,NULL,'D' },
{ "port",required_argument,NULL,'p' },
{ "complete_scan",no_argument,NULL,'C' },
{ "usb_scan",no_argument,NULL,'U' },
@ -75,6 +80,7 @@ static long timeout = DEFAULT_TIMEOUT*1000*1000; /* in usec */
static char * start_ip = NULL;
static char * end_ip = NULL;
static char * port = NULL;
static char * serial_ports = NULL;
#ifdef HAVE_PTHREAD
static pthread_t thread[TYPE_END];
@ -110,11 +116,20 @@ static void * run_avahi(void * arg)
}
static void * run_ipmi(void * arg)
{
dev[TYPE_IPMI] = nutscan_scan_ipmi();
nutscan_ipmi_t * sec = (nutscan_ipmi_t *)arg;
dev[TYPE_IPMI] = nutscan_scan_ipmi(start_ip,end_ip,sec);
return NULL;
}
static void * run_eaton_serial(void * arg)
{
dev[TYPE_EATON_SERIAL] = nutscan_scan_eaton_serial (serial_ports);
return NULL;
}
#endif /* HAVE_PTHREAD */
static int printq(int quiet,const char *fmt, ...)
int printq(int quiet,const char *fmt, ...)
{
va_list ap;
int ret;
@ -133,6 +148,7 @@ static int printq(int quiet,const char *fmt, ...)
int main(int argc, char *argv[])
{
nutscan_snmp_t snmp_sec;
nutscan_ipmi_t ipmi_sec;
int opt_ret;
char * cidr = NULL;
int allow_all = 0;
@ -142,11 +158,18 @@ int main(int argc, char *argv[])
int allow_oldnut = 0;
int allow_avahi = 0;
int allow_ipmi = 0;
int allow_eaton_serial = 0; /* MUST be requested explicitely! */
int quiet = 0;
void (*display_func)(nutscan_device_t * device);
int ret_code = EXIT_SUCCESS;
memset(&snmp_sec, 0, sizeof(snmp_sec));
memset(&ipmi_sec, 0, sizeof(ipmi_sec));
/* Set the default values for IPMI */
ipmi_sec.authentication_type = IPMI_AUTHENTICATION_TYPE_MD5;
ipmi_sec.ipmi_version = IPMI_1_5; /* default to IPMI 1.5, if not otherwise specified */
ipmi_sec.cipher_suite_id = 3; /* default to HMAC-SHA1; HMAC-SHA1-96; AES-CBC-128 */
ipmi_sec.privilege_level = IPMI_PRIVILEGE_LEVEL_ADMIN; /* should be sufficient */
nutscan_init();
@ -169,6 +192,10 @@ int main(int argc, char *argv[])
case 'e':
end_ip = strdup(optarg);
break;
case 'E':
serial_ports = strdup(optarg);
allow_eaton_serial = 1;
break;
case 'm':
cidr = strdup(optarg);
break;
@ -220,6 +247,46 @@ int main(int argc, char *argv[])
}
allow_snmp = 1;
break;
case 'b':
if(!nutscan_avail_ipmi) {
goto display_help;
}
ipmi_sec.username = strdup(optarg);
break;
case 'B':
if(!nutscan_avail_ipmi) {
goto display_help;
}
ipmi_sec.password = strdup(optarg);
break;
case 'd':
if(!nutscan_avail_ipmi) {
goto display_help;
}
if (!strcmp(optarg, "NONE")) {
ipmi_sec.authentication_type = IPMI_AUTHENTICATION_TYPE_NONE;
}
else if (!strcmp(optarg, "STRAIGHT_PASSWORD_KEY")) {
ipmi_sec.authentication_type = IPMI_AUTHENTICATION_TYPE_STRAIGHT_PASSWORD_KEY;
}
else if (!strcmp(optarg, "MD2")) {
ipmi_sec.authentication_type = IPMI_AUTHENTICATION_TYPE_MD2;
}
else if (!strcmp(optarg, "MD5")) {
ipmi_sec.authentication_type = IPMI_AUTHENTICATION_TYPE_MD5;
}
else {
fprintf(stderr,"Unknown authentication type (%s). Defaulting to MD5\n", optarg);
}
break;
case 'D':
if(!nutscan_avail_ipmi) {
goto display_help;
}
ipmi_sec.cipher_suite_id = atoi(optarg);
/* Force IPMI 2.0! */
ipmi_sec.ipmi_version = IPMI_2_0;
break;
case 'p':
port = strdup(optarg);
break;
@ -280,8 +347,9 @@ int main(int argc, char *argv[])
printf("AVAHI\n");
}
if(nutscan_avail_ipmi) {
printf("IPMI\n");
printf("IPMI\n");
}
printf("EATON_SERIAL\n");
exit(EXIT_SUCCESS);
case '?':
ret_code = ERR_BAD_OPTION;
@ -307,6 +375,10 @@ display_help:
if( nutscan_avail_ipmi ) {
printf(" -I, --ipmi_scan: Scan IPMI devices.\n");
}
printf(" -E, --eaton_serial <serial ports list>: Scan serial Eaton devices (XCP, SHUT and Q1).\n");
printf("\nNetwork specific options:\n");
printf(" -t, --timeout <timeout in seconds>: network operation timeout (default %d).\n",DEFAULT_TIMEOUT);
printf(" -s, --start_ip <IP address>: First IP address to scan.\n");
printf(" -e, --end_ip <IP address>: Last IP address to scan.\n");
@ -325,6 +397,18 @@ display_help:
printf(" -X, --privPassword <privacy pass phrase>: Set the privacy pass phrase used for encrypted SNMPv3 messages (mandatory if you set secLevel to authPriv)\n");
}
if( nutscan_avail_ipmi ) {
printf("\nIPMI over LAN specific options:\n");
printf(" -b, --username <username>: Set the username used for authenticating IPMI over LAN connections (mandatory for IPMI over LAN. No default)\n");
/* Specify the username to use when authenticating with the remote host. If not specified, a null (i.e. anonymous) username is assumed. The user must have
* at least ADMIN privileges in order for this tool to operate fully. */
printf(" -B, --password <password>: Specify the password to use when authenticationg with the remote host (mandatory for IPMI over LAN. No default)\n");
/* Specify the password to use when authenticationg with the remote host. If not specified, a null password is assumed. Maximum password length is 16 for IPMI
* 1.5 and 20 for IPMI 2.0. */
printf(" -d, --authType <authentication type>: Specify the IPMI 1.5 authentication type to use (NONE, STRAIGHT_PASSWORD_KEY, MD2, and MD5) with the remote host (default=MD5)\n");
printf(" -D, --cipher_suite_id <cipher suite id>: Specify the IPMI 2.0 cipher suite ID to use, for authentication, integrity, and confidentiality (default=3)\n");
}
printf("\nNUT specific options:\n");
printf(" -p, --port <port number>: Port number of remote NUT upsd\n");
printf("\ndisplay specific options:\n");
@ -344,7 +428,7 @@ display_help:
}
if( !allow_usb && !allow_snmp && !allow_xml && !allow_oldnut &&
!allow_avahi && !allow_ipmi ) {
!allow_avahi && !allow_ipmi && !allow_eaton_serial) {
allow_all = 1;
}
@ -355,6 +439,7 @@ display_help:
allow_oldnut = 1;
allow_avahi = 1;
allow_ipmi = 1;
/* BEWARE: allow_all does not include allow_eaton_serial! */
}
if( allow_usb && nutscan_avail_usb ) {
@ -371,6 +456,7 @@ display_help:
if( allow_snmp && nutscan_avail_snmp ) {
if( start_ip == NULL ) {
printq(quiet,"No start IP, skipping SNMP\n");
nutscan_avail_snmp = 0;
}
else {
printq(quiet,"Scanning SNMP bus.\n");
@ -398,6 +484,7 @@ display_help:
if( allow_oldnut && nutscan_avail_nut) {
if( start_ip == NULL ) {
printq(quiet,"No start IP, skipping NUT bus (old connect method)\n");
nutscan_avail_nut = 0;
}
else {
printq(quiet,"Scanning NUT bus (old connect method).\n");
@ -425,11 +512,22 @@ display_help:
if( allow_ipmi && nutscan_avail_ipmi) {
printq(quiet,"Scanning IPMI bus.\n");
#ifdef HAVE_PTHREAD
if(pthread_create(&thread[TYPE_IPMI],NULL,run_ipmi,NULL)) {
if(pthread_create(&thread[TYPE_IPMI],NULL,run_ipmi,&ipmi_sec)) {
nutscan_avail_ipmi = 0;
}
#else
dev[TYPE_IPMI] = nutscan_scan_ipmi();
dev[TYPE_IPMI] = nutscan_scan_ipmi(start_ip,end_ip,&ipmi_sec);
#endif /* HAVE_PTHREAD */
}
/* Eaton serial scan */
if (allow_eaton_serial) {
printq(quiet,"Scanning serial bus for Eaton devices.\n");
#ifdef HAVE_PTHREAD
pthread_create(&thread[TYPE_EATON_SERIAL], NULL, run_eaton_serial, serial_ports);
/* FIXME: check return code */
#else
dev[TYPE_EATON_SERIAL] = nutscan_scan_eaton_serial (serial_ports);
#endif /* HAVE_PTHREAD */
}
@ -452,6 +550,9 @@ display_help:
if( allow_ipmi && nutscan_avail_ipmi ) {
pthread_join(thread[TYPE_IPMI],NULL);
}
if (allow_eaton_serial) {
pthread_join(thread[TYPE_EATON_SERIAL],NULL);
}
#endif /* HAVE_PTHREAD */
display_func(dev[TYPE_USB]);
@ -472,6 +573,9 @@ display_help:
display_func(dev[TYPE_IPMI]);
nutscan_free_device(dev[TYPE_IPMI]);
display_func(dev[TYPE_EATON_SERIAL]);
nutscan_free_device(dev[TYPE_EATON_SERIAL]);
nutscan_free();
return EXIT_SUCCESS;