remove isol,

remove signal handler function as it was not used,
clean up error handling in ipmi_open_file
change min define to __min to avoid conflicts
This commit is contained in:
Duncan Laurie 2005-01-06 19:09:05 +00:00
parent 4db9739e17
commit e23dde507e
10 changed files with 73 additions and 269 deletions

View File

@ -51,18 +51,19 @@ unsigned short buf2short(unsigned char * buf);
uint32_t buf2long(unsigned char * buf);
const char * buf2str(unsigned char * buf, int len);
void printbuf(const unsigned char * buf, int len, const char * desc);
void signal_handler(int sig, void * handler);
unsigned char ipmi_csum(unsigned char * d, int s);
FILE * ipmi_open_file(const char * file, int flags);
FILE * ipmi_open_file(const char * file, int rw);
#define ipmi_open_file_read(file) ipmi_open_file(file, 0)
#define ipmi_open_file_write(file) ipmi_open_file(file, 1)
#define SIG_IGNORE(s) ((void)signal((s), SIG_IGN))
#define SIG_DEFAULT(s) ((void)signal((s), SIG_DFL))
#define SIG_HANDLE(s,h) ((void)signal_handler((s), (h)))
#define min(a, b) ((a) < (b) ? (a) : (b))
#ifndef __min
# define __min(a, b) ((a) < (b) ? (a) : (b))
#endif
#endif /* IPMI_HELPER_H */

View File

@ -1,55 +0,0 @@
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
* SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE
* FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
* OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
* SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
* OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
* 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.
*
* You acknowledge that this software is not designed or intended for use
* in the design, construction, operation or maintenance of any nuclear
* facility.
*/
#ifndef IPMI_ISOL_H
#define IPMI_ISOL_H
#include <ipmitool/ipmi.h>
#define ACTIVATE_ISOL 0x01
#define SET_ISOL_CONFIG 0x03
#define GET_ISOL_CONFIG 0x04
#define ISOL_ENABLE_PARAM 0x01
#define ISOL_AUTHENTICATION_PARAM 0x02
#define ISOL_ENABLE_FLAG 0x01
#define ISOL_PRIVILEGE_LEVEL_USER 0x02
#define ISOL_BAUD_RATE_PARAM 0x05
#define ISOL_PREFERRED_BAUD_RATE 0x07
int ipmi_isol_main(struct ipmi_intf *, int, char **);
#endif /* IPMI_SOL_H */

View File

@ -36,11 +36,10 @@ INCLUDES = -I$(top_srcdir)/include
MAINTAINERCLEANFILES = Makefile.in
noinst_LTLIBRARIES = libipmitool.la
libipmitool_la_SOURCES = helper.c ipmi_sdr.c ipmi_sel.c ipmi_sol.c ipmi_isol.c \
libipmitool_la_SOURCES = helper.c ipmi_sdr.c ipmi_sel.c ipmi_sol.c ipmi_pef.c \
ipmi_lanp.c ipmi_fru.c ipmi_chassis.c ipmi_mc.c log.c \
dimm_spd.c ipmi_sensor.c ipmi_channel.c ipmi_event.c \
ipmi_session.c ipmi_strings.c ipmi_user.c ipmi_raw.c \
ipmi_pef.c
ipmi_session.c ipmi_strings.c ipmi_user.c ipmi_raw.c
libipmitool_la_LDFLAGS = -export-dynamic
libipmitool_la_LIBADD = -lm
libipmitool_la_DEPENDENCIES =

View File

@ -46,6 +46,7 @@
#include <errno.h>
#include <ipmitool/helper.h>
#include <ipmitool/log.h>
extern int verbose;
@ -64,7 +65,7 @@ const char * buf2str(unsigned char * buf, int len)
static char str[1024];
int i;
if (!len || len > 1024)
if (len <= 0 || len > 1024)
return NULL;
memset(str, 0, 1024);
@ -101,7 +102,7 @@ const char * val2str(unsigned short val, const struct valstr *vs)
static char un_str[16];
int i = 0;
while (vs[i].str) {
while (vs[i].str != NULL) {
if (vs[i].val == val)
return vs[i].str;
i++;
@ -117,7 +118,7 @@ unsigned short str2val(const char *str, const struct valstr *vs)
{
int i = 0;
while (vs[i].str) {
while (vs[i].str != NULL) {
if (!strncasecmp(vs[i].str, str, strlen(str)))
return vs[i].val;
i++;
@ -126,29 +127,13 @@ unsigned short str2val(const char *str, const struct valstr *vs)
return 0;
}
void signal_handler(int sig, void * handler)
{
struct sigaction act;
if (!sig || !handler)
return;
memset(&act, 0, sizeof(act));
act.sa_handler = handler;
act.sa_flags = 0;
if (sigemptyset(&act.sa_mask) < 0) {
psignal(sig, "unable to empty signal set");
return;
}
if (sigaction(sig, &act, NULL) < 0) {
psignal(sig, "unable to register handler");
return;
}
}
unsigned char ipmi_csum(unsigned char * d, int s)
/* ipmi_csum - calculate an ipmi checksum
*
* @d: buffer to check
* @s: position in buffer to start checksum from
*/
unsigned char
ipmi_csum(unsigned char * d, int s)
{
unsigned char c = 0;
for (; s > 0; s--, d++)
@ -156,11 +141,16 @@ unsigned char ipmi_csum(unsigned char * d, int s)
return -c;
}
/* safely open a file for reading or writing
* file: filename
* rw: read-write flag, 1=write
/* ipmi_open_file - safely open a file for reading or writing
*
* @file: filename
* @rw: read-write flag, 1=write
*
* returns pointer to file handler on success
* returns NULL on error
*/
FILE * ipmi_open_file(const char * file, int rw)
FILE *
ipmi_open_file(const char * file, int rw)
{
struct stat st1, st2;
FILE * fp;
@ -170,51 +160,66 @@ FILE * ipmi_open_file(const char * file, int rw)
if (rw) {
/* does not exist, ok to create */
fp = fopen(file, "w");
if (!fp) {
printf("ERROR: Unable to open file %s for write: %s\n",
file, strerror(errno));
if (fp == NULL) {
lperror(LOG_ERR, "Unable to open file %s "
"for write", file);
return NULL;
}
/* created ok, now return the descriptor */
return fp;
} else {
printf("ERROR: File %s does not exist\n", file);
lprintf(LOG_ERR, "File %s does not exist", file);
return NULL;
}
}
/* it exists - only regular files, not links */
if (!S_ISREG(st1.st_mode)) {
printf("ERROR: File %s has invalid mode: %d\n", file, st1.st_mode);
if (S_ISREG(st1.st_mode) == 0) {
lprintf(LOG_ERR, "File %s has invalid mode: %d",
file, st1.st_mode);
return NULL;
}
/* allow only files with 1 link (itself) */
if (st1.st_nlink != 1) {
printf("ERROR: File %s has invalid link count: %d != 1\n",
lprintf(LOG_ERR, "File %s has invalid link count: %d != 1",
file, (int)st1.st_nlink);
return NULL;
}
fp = fopen(file, rw ? "w+" : "r");
if (!fp) {
printf("ERROR: Unable to open file %s: %s\n",
file, strerror(errno));
if (fp == NULL) {
lperror(LOG_ERR, "Unable to open file %s", file);
return NULL;
}
/* stat again */
if (fstat(fileno(fp), &st2) < 0) {
printf("ERROR: Unable to stat file %s: %s\n",
file, strerror(errno));
lperror(LOG_ERR, "Unable to stat file %s", file);
fclose(fp);
return NULL;
}
/* verify inode, owner, link count */
if (st2.st_ino != st1.st_ino ||
st2.st_uid != st1.st_uid ||
st2.st_nlink != 1) {
printf("ERROR: Unable to verify file %s\n", file);
/* verify inode */
if (st1.st_ino != st2.st_ino) {
lprintf(LOG_ERR, "File %s has invalid inode: %d != %d",
file, st1.st_ino, st2.st_ino);
fclose(fp);
return NULL;
}
/* verify owner */
if (st1.st_uid != st2.st_uid) {
lprintf(LOG_ERR, "File %s has invalid user id: %d != %d",
file, st1.st_uid, st2.st_uid);
fclose(fp);
return NULL;
}
/* verify inode */
if (st2.st_nlink != 1) {
lprintf(LOG_ERR, "File %s has invalid link count: %d != 1",
file, st2.st_nlink);
fclose(fp);
return NULL;
}

View File

@ -1,144 +0,0 @@
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
* SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE
* FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
* OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
* SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
* OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
* 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.
*
* You acknowledge that this software is not designed or intended for use
* in the design, construction, operation or maintenance of any nuclear
* facility.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ipmitool/helper.h>
#include <ipmitool/ipmi.h>
#include <ipmitool/ipmi_intf.h>
#include <ipmitool/ipmi_isol.h>
extern int verbose;
static int ipmi_isol_setup(struct ipmi_intf * intf)
{
struct ipmi_rs * rsp;
struct ipmi_rq req;
unsigned char data[6];
/* TEST FOR AVAILABILITY */
memset(data, 0, 6);
data[0] = 0x00;
data[1] = ISOL_ENABLE_PARAM;
data[2] = ISOL_ENABLE_FLAG;
memset(&req, 0, sizeof(req));
req.msg.netfn = IPMI_NETFN_ISOL;
req.msg.cmd = SET_ISOL_CONFIG;
req.msg.data = data;
req.msg.data_len = 3;
rsp = intf->sendrecv(intf, &req);
if (!rsp) {
printf("Error in Set ISOL Config Command\n");
return -1;
}
if (rsp->ccode == 0xc1) {
printf("Serial Over Lan not supported!\n");
return -1;
}
if (rsp->ccode) {
printf("Set Serial Over Lan Config returned %x\n", rsp->ccode);
return -1;
}
/* GET ISOL CONFIG */
memset(data, 0, 6);
data[0] = 0x00;
data[1] = ISOL_AUTHENTICATION_PARAM;
data[2] = 0x00; /* block */
data[3] = 0x00; /* selector */
req.msg.cmd = GET_ISOL_CONFIG;
req.msg.data_len = 4;
rsp = intf->sendrecv(intf, &req);
if (!rsp || rsp->ccode) {
printf("Error:%x in Get ISOL Config command\n", rsp?rsp->ccode:0);
return -1;
}
if (verbose > 1)
printbuf(rsp->data, rsp->data_len, "ISOL Config");
/* SET ISOL CONFIG - AUTHENTICATION */
memset(data, 0, 6);
data[0] = 0x00;
data[1] = ISOL_AUTHENTICATION_PARAM;
data[2] = ISOL_PRIVILEGE_LEVEL_USER | (rsp->data[1] & 0x80);
req.msg.cmd = SET_ISOL_CONFIG;
req.msg.data_len = 3;
rsp = intf->sendrecv(intf, &req);
if (!rsp || rsp->ccode) {
printf("Error:%x in Set ISOL Config (Authentication) command\n", rsp?rsp->ccode:0);
return -1;
}
/* SET ISOL CONFIG - BAUD RATE */
memset(data, 0, 6);
data[0] = 0x00;
data[1] = ISOL_BAUD_RATE_PARAM;
data[2] = ISOL_PREFERRED_BAUD_RATE;
req.msg.cmd = SET_ISOL_CONFIG;
req.msg.data_len = 3;
rsp = intf->sendrecv(intf, &req);
if (!rsp || rsp->ccode) {
printf("Error:%x in Set ISOL Config (Baud Rate) command\n", rsp?rsp->ccode:0);
return -1;
}
return 0;
}
int ipmi_isol_main(struct ipmi_intf * intf, int argc, char ** argv)
{
if (!argc || !strncmp(argv[0], "help", 4)) {
printf("ISOL Commands: setup\n");
return 0;
}
else if (!strncmp(argv[0], "setup", 5)) {
ipmi_isol_setup(intf);
}
return 0;
}

View File

@ -498,7 +498,7 @@ ipmi_lan_set_password(struct ipmi_intf * intf,
data[1] = 0x02; /* set password */
if (password != NULL)
memcpy(data+2, password, min(strlen(password), 16));
memcpy(data+2, password, __min(strlen(password), 16));
memset(&req, 0, sizeof(req));
req.msg.netfn = IPMI_NETFN_APP;
@ -809,7 +809,7 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
if (argc < 3 || (strncmp(argv[2], "help", 4) == 0)) {
lprintf(LOG_NOTICE, "lan set <channel> snmp <community string>");
} else {
memcpy(data, argv[2], min(strlen(argv[2]), 18));
memcpy(data, argv[2], __min(strlen(argv[2]), 18));
printf("Setting LAN %s to %s\n",
ipmi_lan_params[IPMI_LANP_SNMP_STRING].desc, data);
rc = set_lan_param(intf, chan, IPMI_LANP_SNMP_STRING, data, 18);

View File

@ -1943,7 +1943,7 @@ ipmi_sdr_get_info(struct ipmi_intf * intf,
memcpy(sdr_repository_info,
rsp->data,
min(sizeof(struct get_sdr_repository_info_rsp),rsp->data_len));
__min(sizeof(struct get_sdr_repository_info_rsp),rsp->data_len));
return 0;
}

View File

@ -86,19 +86,19 @@ static void daemonize(void)
sigaddset(&sighup, SIGHUP);
if (sigprocmask(SIG_UNBLOCK, &sighup, NULL) < 0)
fprintf(stderr, "ERROR: could not unblock SIGHUP signal\n");
SIG_IGNORE(SIGHUP);
signal(SIGHUP, SIG_IGN);
#endif
#ifdef SIGTTOU
SIG_IGNORE(SIGTTOU);
signal(SIGTTOU, SIG_IGN);
#endif
#ifdef SIGTTIN
SIG_IGNORE(SIGTTIN);
signal(SIGTTIN, SIG_IGN);
#endif
#ifdef SIGQUIT
SIG_IGNORE(SIGQUIT);
signal(SIGQUIT, SIG_IGN);
#endif
#ifdef SIGTSTP
SIG_IGNORE(SIGTSTP);
signal(SIGTSTP, SIG_IGN);
#endif
pid = (pid_t) fork();

View File

@ -54,7 +54,6 @@
#include <ipmitool/ipmi_sdr.h>
#include <ipmitool/ipmi_sel.h>
#include <ipmitool/ipmi_fru.h>
#include <ipmitool/ipmi_isol.h>
#include <ipmitool/ipmi_sol.h>
#include <ipmitool/ipmi_lanp.h>
#include <ipmitool/ipmi_chassis.h>
@ -104,7 +103,6 @@ struct ipmi_cmd {
{ ipmi_sel_main, "sel", "Print System Event Log (SEL)" },
{ ipmi_pef_main, "pef", "Configure Platform Event Filtering (PEF)" },
{ ipmi_sol_main, "sol", "Configure IPMIv2.0 Serial-over-LAN" },
{ ipmi_isol_main, "isol", "Configure Intel IPMIv1.5 Serial-over-LAN" },
{ ipmi_user_main, "user", "Configure Management Controller users" },
{ ipmi_channel_main, "channel", "Configure Management Controller channels" },
{ ipmi_session_main, "session", "Print session information" },

View File

@ -154,7 +154,7 @@ ipmi_intf_session_set_hostname(struct ipmi_intf * intf, char * hostname)
if (hostname != NULL) {
memcpy(intf->session->hostname, hostname,
min(strlen(hostname), 64));
__min(strlen(hostname), 64));
}
}
@ -169,7 +169,7 @@ ipmi_intf_session_set_username(struct ipmi_intf * intf, char * username)
if (username == NULL)
return;
memcpy(intf->session->username, username, min(strlen(username), 16));
memcpy(intf->session->username, username, __min(strlen(username), 16));
}
void
@ -187,7 +187,7 @@ ipmi_intf_session_set_password(struct ipmi_intf * intf, char * password)
intf->session->password = 1;
memcpy(intf->session->authcode, password,
min(strlen(password), IPMI_AUTHCODE_BUFFER_SIZE));
__min(strlen(password), IPMI_AUTHCODE_BUFFER_SIZE));
}
void