summaryrefslogtreecommitdiff
path: root/lib/ipmi_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ipmi_main.c')
-rw-r--r--lib/ipmi_main.c207
1 files changed, 115 insertions, 92 deletions
diff --git a/lib/ipmi_main.c b/lib/ipmi_main.c
index 65f1ac4..a673a30 100644
--- a/lib/ipmi_main.c
+++ b/lib/ipmi_main.c
@@ -29,12 +29,6 @@
* LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
-#define _XOPEN_SOURCE 700
-#define _BSD_SOURCE || \
- (_XOPEN_SOURCE >= 500 || \
- _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) && \
- !(_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600)
-#define _DEFAULT_SOURCE
#include <stdlib.h>
#include <stdio.h>
@@ -48,6 +42,7 @@
#include <fcntl.h>
#include <errno.h>
#include <ctype.h>
+#include <locale.h>
#include <ipmitool/helper.h>
#include <ipmitool/log.h>
@@ -71,18 +66,20 @@
#include <ipmitool/ipmi_user.h>
#include <ipmitool/ipmi_raw.h>
#include <ipmitool/ipmi_pef.h>
+#include <ipmitool/ipmi_time.h>
#include <ipmitool/ipmi_oem.h>
#include <ipmitool/ipmi_ekanalyzer.h>
#include <ipmitool/ipmi_picmg.h>
#include <ipmitool/ipmi_kontronoem.h>
#include <ipmitool/ipmi_vita.h>
+#include <ipmitool/ipmi_quantaoem.h>
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef ENABLE_ALL_OPTIONS
-# define OPTION_STRING "I:46hVvcgsEKYao:H:d:P:f:U:p:C:L:A:t:T:m:z:S:l:b:B:e:k:y:O:R:N:D:"
+# define OPTION_STRING "I:46hVvcgsEKYao:H:d:P:f:U:p:C:L:A:t:T:m:z:S:l:b:B:e:k:y:O:R:N:D:Z"
#else
# define OPTION_STRING "I:46hVvcH:f:U:p:d:S:D:"
#endif
@@ -91,8 +88,6 @@
void
ipmi_intf_set_max_request_data_size(struct ipmi_intf * intf, uint16_t size);
-extern int verbose;
-extern int csv_output;
extern const struct valstr ipmi_privlvl_vals[];
extern const struct valstr ipmi_authtype_session_vals[];
@@ -114,14 +109,14 @@ ipmi_password_file_read(char * filename)
int l;
pass = malloc(21);
- if (pass == NULL) {
+ if (!pass) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return NULL;
}
memset(pass, 0, 21);
fp = ipmi_open_file_read((const char *)filename);
- if (fp == NULL) {
+ if (!fp) {
lprintf(LOG_ERR, "Unable to open password file %s",
filename);
free(pass);
@@ -129,7 +124,7 @@ ipmi_password_file_read(char * filename)
}
/* read in id */
- if (fgets(pass, 21, fp) == NULL) {
+ if (!fgets(pass, 21, fp)) {
lprintf(LOG_ERR, "Unable to read password from file %s",
filename);
free(pass);
@@ -158,10 +153,10 @@ ipmi_cmd_print(struct ipmi_cmd * cmdlist)
struct ipmi_cmd * cmd;
int hdr = 0;
- if (cmdlist == NULL)
+ if (!cmdlist)
return;
- for (cmd=cmdlist; cmd->func != NULL; cmd++) {
- if (cmd->desc == NULL)
+ for (cmd=cmdlist; cmd->func; cmd++) {
+ if (!cmd->desc)
continue;
if (hdr == 0) {
lprintf(LOG_NOTICE, "Commands:");
@@ -183,7 +178,7 @@ ipmi_cmd_print(struct ipmi_cmd * cmdlist)
* @argc: command argument count
* @argv: command argument list
*
- * returns value from func() of that commnad if found
+ * returns value from func() of that command if found
* returns -1 if command is not found
*/
int
@@ -192,25 +187,25 @@ ipmi_cmd_run(struct ipmi_intf * intf, char * name, int argc, char ** argv)
struct ipmi_cmd * cmd = intf->cmdlist;
/* hook to run a default command if nothing specified */
- if (name == NULL) {
- if (cmd->func == NULL || cmd->name == NULL)
+ if (!name) {
+ if (!cmd->func || !cmd->name)
return -1;
- else if (strncmp(cmd->name, "default", 7) == 0)
+
+ if (!strcmp(cmd->name, "default"))
return cmd->func(intf, 0, NULL);
- else {
- lprintf(LOG_ERR, "No command provided!");
- ipmi_cmd_print(intf->cmdlist);
- return -1;
- }
+
+ lprintf(LOG_ERR, "No command provided!");
+ ipmi_cmd_print(intf->cmdlist);
+ return -1;
}
- for (cmd=intf->cmdlist; cmd->func != NULL; cmd++) {
- if (strncmp(name, cmd->name, __maxlen(cmd->name, name)) == 0)
+ for (cmd=intf->cmdlist; cmd->func; cmd++) {
+ if (!strcmp(name, cmd->name))
break;
}
- if (cmd->func == NULL) {
+ if (!cmd->func) {
cmd = intf->cmdlist;
- if (strncmp(cmd->name, "default", 7) == 0)
+ if (!strcmp(cmd->name, "default"))
return cmd->func(intf, argc+1, argv-1);
lprintf(LOG_ERR, "Invalid command: %s", name);
@@ -264,12 +259,13 @@ ipmi_option_usage(const char * progname, struct ipmi_cmd * cmdlist, struct ipmi_
lprintf(LOG_NOTICE, " -O seloem Use file for OEM SEL event descriptions");
lprintf(LOG_NOTICE, " -N seconds Specify timeout for lan [default=2] / lanplus [default=1] interface");
lprintf(LOG_NOTICE, " -R retry Set the number of retries for lan/lanplus interface [default=4]");
+ lprintf(LOG_NOTICE, " -Z Display all dates in UTC");
#endif
lprintf(LOG_NOTICE, "");
ipmi_intf_print(intflist);
- if (cmdlist != NULL)
+ if (cmdlist)
ipmi_cmd_print(cmdlist);
}
/* ipmi_catch_sigint - Handle the interrupt signal (Ctrl-C), close the
@@ -282,7 +278,7 @@ ipmi_option_usage(const char * progname, struct ipmi_cmd * cmdlist, struct ipmi_
*/
void ipmi_catch_sigint()
{
- if (ipmi_main_intf != NULL) {
+ if (ipmi_main_intf) {
printf("\nSIGN INT: Close Interface %s\n",ipmi_main_intf->desc);
/* reduce retry count to a single retry */
ipmi_main_intf->ssn_params.retry = 1;
@@ -324,6 +320,7 @@ ipmi_main(int argc, char ** argv,
uint8_t target_addr = 0;
uint8_t target_channel = 0;
+ uint8_t u8tmp = 0;
uint8_t transit_addr = 0;
uint8_t transit_channel = 0;
uint8_t target_lun = 0;
@@ -348,19 +345,29 @@ ipmi_main(int argc, char ** argv,
char * seloem = NULL;
int port = 0;
int devnum = 0;
- int cipher_suite_id = 3; /* See table 22-19 of the IPMIv2 spec */
+#ifdef IPMI_INTF_LANPLUS
+ /* lookup best cipher suite available */
+ enum cipher_suite_ids cipher_suite_id = IPMI_LANPLUS_CIPHER_SUITE_RESERVED;
+#endif /* IPMI_INTF_LANPLUS */
int argflag, i, found;
int rc = -1;
int ai_family = AF_UNSPEC;
char sol_escape_char = SOL_ESCAPE_CHARACTER_DEFAULT;
char * devfile = NULL;
+ /* Set program locale according to system settings */
+ setlocale(LC_ALL, "");
+
+
/* save program name */
progname = strrchr(argv[0], '/');
- progname = ((progname == NULL) ? argv[0] : progname+1);
+ progname = ((!progname) ? argv[0] : progname+1);
signal(SIGINT, ipmi_catch_sigint);
memset(kgkey, 0, sizeof(kgkey));
+ /* setup log */
+ log_init(progname, 0, 0);
+
while ((argflag = getopt(argc, (char **)argv, OPTION_STRING)) != -1)
{
switch (argflag) {
@@ -370,17 +377,18 @@ ipmi_main(int argc, char ** argv,
intfname = NULL;
}
intfname = strdup(optarg);
- if (intfname == NULL) {
+ if (!intfname) {
lprintf(LOG_ERR, "%s: malloc failure", progname);
goto out_free;
}
- if (intflist != NULL) {
+ if (intflist) {
found = 0;
- for (sup=intflist; sup->name != NULL; sup++) {
- if (strncmp(sup->name, intfname, strlen(intfname)) == 0 &&
- strncmp(sup->name, intfname, strlen(sup->name)) == 0 &&
- sup->supported == 1)
+ for (sup=intflist; sup->name; sup++) {
+ if (!strcmp(sup->name, intfname)
+ && sup->supported)
+ {
found = 1;
+ }
}
if (!found) {
lprintf(LOG_ERR, "Interface %s not supported", intfname);
@@ -426,21 +434,24 @@ ipmi_main(int argc, char ** argv,
goto out_free;
}
break;
+#ifdef IPMI_INTF_LANPLUS
case 'C':
- if (str2int(optarg, &cipher_suite_id) != 0) {
- lprintf(LOG_ERR, "Invalid parameter given or out of range for '-C'.");
- rc = -1;
- goto out_free;
- }
- /* add check Cipher is -gt 0 */
- if (cipher_suite_id < 0) {
- lprintf(LOG_ERR, "Cipher suite ID %i is invalid.", cipher_suite_id);
+ /* Cipher Suite ID is a byte as per IPMI specification */
+ if (str2uchar(optarg, &u8tmp) != 0) {
+ lprintf(LOG_ERR, "Invalid parameter given or out of "
+ "range [0-255] for '-C'.");
rc = -1;
goto out_free;
}
+ cipher_suite_id = u8tmp;
break;
+#endif /* IPMI_INTF_LANPLUS */
case 'v':
- verbose++;
+ log_level_set(++verbose);
+ if (verbose == 2) {
+ /* add version info to debug output */
+ lprintf(LOG_DEBUG, "%s version %s\n", progname, VERSION);
+ }
break;
case 'c':
csv_output = 1;
@@ -451,7 +462,7 @@ ipmi_main(int argc, char ** argv,
hostname = NULL;
}
hostname = strdup(optarg);
- if (hostname == NULL) {
+ if (!hostname) {
lprintf(LOG_ERR, "%s: malloc failure", progname);
goto out_free;
}
@@ -462,7 +473,7 @@ ipmi_main(int argc, char ** argv,
password = NULL;
}
password = ipmi_password_file_read(optarg);
- if (password == NULL)
+ if (!password)
lprintf(LOG_ERR, "Unable to read password "
"from file %s", optarg);
break;
@@ -472,14 +483,14 @@ ipmi_main(int argc, char ** argv,
#else
tmp_pass = getpass("Password: ");
#endif
- if (tmp_pass != NULL) {
+ if (tmp_pass) {
if (password) {
free(password);
password = NULL;
}
password = strdup(tmp_pass);
tmp_pass = NULL;
- if (password == NULL) {
+ if (!password) {
lprintf(LOG_ERR, "%s: malloc failure", progname);
goto out_free;
}
@@ -519,7 +530,7 @@ ipmi_main(int argc, char ** argv,
#else
tmp_pass = getpass("Key: ");
#endif
- if (tmp_pass != NULL) {
+ if (tmp_pass) {
memset(kgkey, 0, sizeof(kgkey));
strncpy((char *)kgkey, tmp_pass,
sizeof(kgkey) - 1);
@@ -536,7 +547,7 @@ ipmi_main(int argc, char ** argv,
goto out_free;
}
username = strdup(optarg);
- if (username == NULL) {
+ if (!username) {
lprintf(LOG_ERR, "%s: malloc failure", progname);
goto out_free;
}
@@ -547,7 +558,7 @@ ipmi_main(int argc, char ** argv,
sdrcache = NULL;
}
sdrcache = strdup(optarg);
- if (sdrcache == NULL) {
+ if (!sdrcache) {
lprintf(LOG_ERR, "%s: malloc failure", progname);
goto out_free;
}
@@ -559,7 +570,7 @@ ipmi_main(int argc, char ** argv,
free(devfile);
}
devfile = strdup(optarg);
- if (devfile == NULL) {
+ if (!devfile) {
lprintf(LOG_ERR, "%s: malloc failure", progname);
goto out_free;
}
@@ -603,12 +614,13 @@ ipmi_main(int argc, char ** argv,
oemtype = NULL;
}
oemtype = strdup(optarg);
- if (oemtype == NULL) {
+ if (!oemtype) {
lprintf(LOG_ERR, "%s: malloc failure", progname);
goto out_free;
}
- if (strncmp(oemtype, "list", 4) == 0 ||
- strncmp(oemtype, "help", 4) == 0) {
+ if (!strcmp(oemtype, "list")
+ || !strcmp(oemtype, "help"))
+ {
ipmi_oem_print();
rc = 0;
goto out_free;
@@ -636,7 +648,7 @@ ipmi_main(int argc, char ** argv,
password = NULL;
}
password = strdup(optarg);
- if (password == NULL) {
+ if (!password) {
lprintf(LOG_ERR, "%s: malloc failure", progname);
goto out_free;
}
@@ -652,7 +664,7 @@ ipmi_main(int argc, char ** argv,
password = NULL;
}
password = strdup(tmp_env);
- if (password == NULL) {
+ if (!password) {
lprintf(LOG_ERR, "%s: malloc failure", progname);
goto out_free;
}
@@ -663,7 +675,7 @@ ipmi_main(int argc, char ** argv,
password = NULL;
}
password = strdup(tmp_env);
- if (password == NULL) {
+ if (!password) {
lprintf(LOG_ERR, "%s: malloc failure", progname);
goto out_free;
}
@@ -737,7 +749,7 @@ ipmi_main(int argc, char ** argv,
seloem = NULL;
}
seloem = strdup(optarg);
- if (seloem == NULL) {
+ if (!seloem) {
lprintf(LOG_ERR, "%s: malloc failure", progname);
goto out_free;
}
@@ -764,6 +776,9 @@ ipmi_main(int argc, char ** argv,
goto out_free;
}
break;
+ case 'Z':
+ time_in_utc = 1;
+ break;
#endif
default:
ipmi_option_usage(progname, cmdlist, intflist);
@@ -772,8 +787,9 @@ ipmi_main(int argc, char ** argv,
}
/* check for command before doing anything */
- if (argc-optind > 0 &&
- strncmp(argv[optind], "help", 4) == 0) {
+ if (argc-optind > 0
+ && !strcmp(argv[optind], "help"))
+ {
ipmi_cmd_print(cmdlist);
rc = 0;
goto out_free;
@@ -787,17 +803,17 @@ ipmi_main(int argc, char ** argv,
* and the authtype was not explicitly set to NONE
* then prompt the user.
*/
- if (hostname != NULL && password == NULL &&
+ if (hostname && !password &&
(authtype != IPMI_SESSION_AUTHTYPE_NONE || authtype < 0)) {
#ifdef HAVE_GETPASSPHRASE
tmp_pass = getpassphrase("Password: ");
#else
tmp_pass = getpass("Password: ");
#endif
- if (tmp_pass != NULL) {
+ if (tmp_pass) {
password = strdup(tmp_pass);
tmp_pass = NULL;
- if (password == NULL) {
+ if (!password) {
lprintf(LOG_ERR, "%s: malloc failure", progname);
goto out_free;
}
@@ -809,49 +825,52 @@ ipmi_main(int argc, char ** argv,
* otherwise the default is hardcoded
* to use the first entry in the list
*/
- if (intfname == NULL && hostname != NULL) {
+ if (!intfname && hostname) {
intfname = strdup("lan");
- if (intfname == NULL) {
+ if (!intfname) {
lprintf(LOG_ERR, "%s: malloc failure", progname);
goto out_free;
}
}
- if (password != NULL && intfname != NULL) {
- if (strcmp(intfname, "lan") == 0 && strlen(password) > 16) {
+ if (password && intfname) {
+ if (!strcmp(intfname, "lan") && strlen(password) > 16) {
lprintf(LOG_ERR, "%s: password is longer than 16 bytes.", intfname);
rc = -1;
goto out_free;
- } else if (strcmp(intfname, "lanplus") == 0 && strlen(password) > 20) {
+ } else if (!strcmp(intfname, "lanplus") && strlen(password) > 20) {
lprintf(LOG_ERR, "%s: password is longer than 20 bytes.", intfname);
rc = -1;
goto out_free;
}
- } /* if (password != NULL && intfname != NULL) */
+ }
/* load interface */
ipmi_main_intf = ipmi_intf_load(intfname);
- if (ipmi_main_intf == NULL) {
+ if (!ipmi_main_intf) {
lprintf(LOG_ERR, "Error loading interface %s", intfname);
goto out_free;
}
- /* setup log */
- log_init(progname, 0, verbose);
+ /* load the IANA PEN registry */
+ if (ipmi_oem_info_init()) {
+ lprintf(LOG_ERR, "Failed to initialize the OEM info dictionary");
+ goto out_free;
+ }
/* run OEM setup if found */
- if (oemtype != NULL &&
+ if (oemtype &&
ipmi_oem_setup(ipmi_main_intf, oemtype) < 0) {
lprintf(LOG_ERR, "OEM setup for \"%s\" failed", oemtype);
goto out_free;
}
/* set session variables */
- if (hostname != NULL)
+ if (hostname)
ipmi_intf_session_set_hostname(ipmi_main_intf, hostname);
- if (username != NULL)
+ if (username)
ipmi_intf_session_set_username(ipmi_main_intf, username);
- if (password != NULL)
+ if (password)
ipmi_intf_session_set_password(ipmi_main_intf, password);
ipmi_intf_session_set_kgkey(ipmi_main_intf, kgkey);
if (port > 0)
@@ -871,7 +890,9 @@ ipmi_main(int argc, char ** argv,
ipmi_intf_session_set_lookupbit(ipmi_main_intf, lookupbit);
ipmi_intf_session_set_sol_escape_char(ipmi_main_intf, sol_escape_char);
+#ifdef IPMI_INTF_LANPLUS
ipmi_intf_session_set_cipher_suite_id(ipmi_main_intf, cipher_suite_id);
+#endif /* IPMI_INTF_LANPLUS */
ipmi_main_intf->devnum = devnum;
@@ -881,7 +902,7 @@ ipmi_main(int argc, char ** argv,
ipmi_main_intf->ai_family = ai_family;
/* Open the interface with the specified or default IPMB address */
ipmi_main_intf->my_addr = arg_addr ? arg_addr : IPMI_BMC_SLAVE_ADDR;
- if (ipmi_main_intf->open != NULL) {
+ if (ipmi_main_intf->open) {
if (ipmi_main_intf->open(ipmi_main_intf) < 0) {
goto out_free;
}
@@ -976,11 +997,11 @@ ipmi_main(int argc, char ** argv,
ipmi_main_intf->target_ipmb_addr);
/* parse local SDR cache if given */
- if (sdrcache != NULL) {
- ipmi_sdr_list_cache_fromfile(ipmi_main_intf, sdrcache);
+ if (sdrcache) {
+ ipmi_sdr_list_cache_fromfile(sdrcache);
}
/* Parse SEL OEM file if given */
- if (seloem != NULL) {
+ if (seloem) {
ipmi_sel_oem_init(seloem);
}
@@ -1017,37 +1038,37 @@ ipmi_main(int argc, char ** argv,
ipmi_cleanup(ipmi_main_intf);
/* call interface close function if available */
- if (ipmi_main_intf->opened > 0 && ipmi_main_intf->close != NULL)
+ if (ipmi_main_intf->opened && ipmi_main_intf->close)
ipmi_main_intf->close(ipmi_main_intf);
out_free:
log_halt();
- if (intfname != NULL) {
+ if (intfname) {
free(intfname);
intfname = NULL;
}
- if (hostname != NULL) {
+ if (hostname) {
free(hostname);
hostname = NULL;
}
- if (username != NULL) {
+ if (username) {
free(username);
username = NULL;
}
- if (password != NULL) {
+ if (password) {
free(password);
password = NULL;
}
- if (oemtype != NULL) {
+ if (oemtype) {
free(oemtype);
oemtype = NULL;
}
- if (seloem != NULL) {
+ if (seloem) {
free(seloem);
seloem = NULL;
}
- if (sdrcache != NULL) {
+ if (sdrcache) {
free(sdrcache);
sdrcache = NULL;
}
@@ -1056,6 +1077,8 @@ ipmi_main(int argc, char ** argv,
devfile = NULL;
}
+ ipmi_oem_info_free();
+
return rc;
}