summaryrefslogtreecommitdiff
path: root/util/ipmicmd.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/ipmicmd.c')
-rw-r--r--util/ipmicmd.c129
1 files changed, 71 insertions, 58 deletions
diff --git a/util/ipmicmd.c b/util/ipmicmd.c
index dd2268b..8501359 100644
--- a/util/ipmicmd.c
+++ b/util/ipmicmd.c
@@ -260,21 +260,22 @@ int fjustpass = 0;
FILE *fperr = NULL;
FILE *fpdbg = NULL;
FILE *fplog = NULL;
+int fauth_type_set = 0;
+char fdebug = 0;
char log_name[60] = {'\0'}; /*log_name global*/
-char *gnode = "localhost"; /* used for IPMI LAN, specified with option -N */
-char *guser = NULL;
-char *gpswd = NULL;
-char gnodename[SZGNODE] = {0}; /*the node name returned after a connection */
-int gcipher_suite = 3; /*used in ipmilanplus.c*/
-int gshutdown = 0;
-int fauth_type_set = 0;
-int gauth_type = IPMI_SESSION_AUTHTYPE_MD5; /*if 0, use any: MD5, MD2, etc.*/
-int gpriv_level = IPMI_PRIV_LEVEL_USER; /*or IPMI_PRIV_LEVEL_ADMIN */
-int gaddr_len = 0;
-uchar gaddr[128]; /* sizeof(struct sockaddr_storage) = 128 */
- /* struct sockaddr_in/_in6 gaddr; _in6=28, _in=16 bytes */
uchar my_devid[20] = {0,0,0,0,0,0,0,0}; /*saved devid, only needs 16 bytes*/
-char fdebug = 0;
+int gshutdown = 0; /* see ipmilan.c ipmilanplus.c */
+
+LAN_OPT lanp = { "localhost","","", IPMI_SESSION_AUTHTYPE_MD5,
+ IPMI_PRIV_LEVEL_USER, 3, "", 0 };
+static char *gnode = lanp.node;
+//char *guser = lanp.user;
+//char *gpswd = lanp.pswd;
+//uchar *gaddr = lanp.addr;
+//int gaddr_len = 0;
+//int gcipher_suite = 3; /*used in ipmilanplus.c*/
+//int gauth_type = IPMI_SESSION_AUTHTYPE_MD5; /*if 0, use any: MD5, MD2, etc.*/
+//int gpriv_level = IPMI_PRIV_LEVEL_USER;
typedef struct {
uchar adrtype;
@@ -525,7 +526,7 @@ int set_driver_type(char *tag)
if (fDriverTyp == DRV_HP) { /*LAN2 HP ++++*/
set_iana(VENDOR_HP);
fDriverTyp = DRV_LAN2;
- gauth_type = IPMI_SESSION_AUTHTYPE_NONE; /*HP default*/
+ lanp.auth_type = IPMI_SESSION_AUTHTYPE_NONE; /*HP default*/
}
break;
}
@@ -654,13 +655,13 @@ int ipmi_open(char fdebugcmd)
/* first time, so try each */
if (fipmi_lan) {
/* Try IPMI LAN 1.5 first */
- rc = ipmi_open_lan(gnode,guser,gpswd,fdebugcmd);
+ rc = ipmi_open_lan(gnode,lanp.user,lanp.pswd,fdebugcmd);
fDriverTyp = DRV_LAN;
if (rc == LAN_ERR_V2) {
/* Use IPMI LAN 2.0 if BMC said it only supports LAN2 */
/* This is a violation of IPMI 2.0 Spec section 13.4,
* but some HP firmware behaves this way, so handle it. */
- rc = ipmi_open_lan2(gnode,guser,gpswd,fdebugcmd);
+ rc = ipmi_open_lan2(gnode,lanp.user,lanp.pswd,fdebugcmd);
fDriverTyp = DRV_LAN2;
}
} else { /* local, not lan */
@@ -1283,14 +1284,14 @@ int get_lan_options(char *node, char *user, char *pswd, int *auth, int *priv,
int *cipher, void *addr, int *addr_len)
{
if (fipmi_lan == 0) return(-1);
- if (node != NULL) strcpy(node,gnode);
- if (user != NULL) strcpy(user,guser);
- if (pswd != NULL) strcpy(pswd,gpswd);
- if (auth != NULL) *auth = gauth_type;
- if (priv != NULL) *priv = gpriv_level;
- if (cipher != NULL) *cipher = gcipher_suite;
- if (addr != NULL && gaddr_len != 0) memcpy(addr,gaddr,gaddr_len);
- if (addr_len != NULL) *addr_len = gaddr_len;
+ if (node != NULL) strcpy(node,lanp.node);
+ if (user != NULL) strcpy(user,lanp.user);
+ if (pswd != NULL) strcpy(pswd,lanp.pswd);
+ if (auth != NULL) *auth = lanp.auth_type;
+ if (priv != NULL) *priv = lanp.priv;
+ if (cipher != NULL) *cipher = lanp.cipher;
+ if (addr != NULL && lanp.addr_len != 0) memcpy(addr,lanp.addr,lanp.addr_len);
+ if (addr_len != NULL) *addr_len = lanp.addr_len;
return(0);
}
@@ -1298,18 +1299,29 @@ int set_lan_options(char *node, char *user, char *pswd, int auth, int priv,
int cipher, void *addr, int addr_len)
{
int rv = 0;
- if (node != NULL) { gnode = strdup_(node); fipmi_lan = 1; }
- if (user != NULL) guser = strdup_(user);
- if (pswd != NULL) gpswd = strdup_(pswd);
- if (auth > 0 && auth <= 5) gauth_type = auth;
+ if (node != NULL) {
+ strncpy(lanp.node,node,SZGNODE);
+ lanp.node[SZGNODE] = '\0';
+ gnode = lanp.node;
+ fipmi_lan = 1;
+ }
+ if (user != NULL) {
+ strncpy(lanp.user,user,SZGNODE);
+ lanp.user[SZGNODE] = '\0';
+ }
+ if (pswd != NULL) {
+ strncpy(lanp.pswd,pswd,PSW_MAX);
+ lanp.pswd[PSW_MAX] = '\0';
+ }
+ if (auth > 0 && auth <= 5) { lanp.auth_type = auth; }
else rv = ERR_BAD_PARAM;
- if (priv > 0 && priv <= 5) gpriv_level = priv;
+ if (priv > 0 && priv <= 5) { lanp.priv = priv; }
else rv = ERR_BAD_PARAM;
- if (cipher >= 0 && cipher <= 17) gcipher_suite = cipher;
+ if (cipher >= 0 && cipher <= 17) { lanp.cipher = cipher; }
else rv = ERR_BAD_PARAM;
- if ((addr != NULL) && (addr_len > 15) && (addr_len <= sizeof(gaddr))) {
- memcpy(gaddr,addr,addr_len);
- gaddr_len = addr_len;
+ if ((addr != NULL) && (addr_len > 15) && (addr_len <= sizeof(lanp.addr))) {
+ memcpy(lanp.addr,addr,addr_len);
+ lanp.addr_len = addr_len;
}
ipmi_flush_lan(gnode);
return(rv);
@@ -1324,6 +1336,7 @@ void parse_lan_options(int c, char *popt, char fdebugcmd)
size_t len;
static int fset_dtype = 0;
uchar sa;
+ char *p = NULL;
switch(c)
{
@@ -1333,52 +1346,52 @@ void parse_lan_options(int c, char *popt, char fdebugcmd)
break;
case 'T': /* auth type */
i = atoi(popt);
- if (i >= 0 && i <= 5) gauth_type = i;
+ if (i >= 0 && i <= 5) lanp.auth_type = i;
fauth_type_set = 1;
break;
case 'V': /* priv level */
i = atoi(popt);
- if (i > 0 && i <= 5) gpriv_level = i;
+ if (i > 0 && i <= 5) lanp.priv = i;
break;
case 'J':
i = atoi(popt);
- if (i >= 0 && i <= 17) gcipher_suite = i;
+ if (i >= 0 && i <= 17) lanp.cipher = i;
else printf("-J cipher suite %d > 17, defaults to %d\n",
- i,gcipher_suite);
+ i,lanp.cipher);
if (fset_dtype == 0) i = set_driver_type("lan2");
break;
- case 'N': gnode = popt; /* nodename */
- fipmi_lan = 1;
- break;
+ case 'N':
+ strncpy(lanp.node,popt,SZGNODE); /*remote nodename */
+ lanp.node[SZGNODE] = '\0';
+ fipmi_lan = 1;
+ break;
case 'U':
- guser = strdup_(popt); /*remote username */
- if (!guser) perror("strdup_");
- else { /* Hide username from 'ps' */
- memset(popt, ' ', strlen(popt));
- }
+ strncpy(lanp.user,popt,SZGNODE); /*remote username */
+ lanp.user[SZGNODE] = '\0';
+ /* Hide username from 'ps' */
+ memset(popt, ' ', strlen(popt));
break;
case 'R':
case 'P':
- gpswd = strdup_(popt); /*remote password */
- if (!gpswd) perror("strdup_");
- else { /* Hide password from 'ps' */
- len = strlen(popt);
- memset(popt, ' ', len);
- if (len > PSW_MAX) gpswd[PSW_MAX] = '\0';
- }
+ strncpy(lanp.pswd,popt,PSW_MAX); /*remote password */
+ lanp.pswd[PSW_MAX] = '\0';
+ /* Hide password from 'ps' */
+ memset(popt, ' ', strlen(popt));
break;
case 'E': /* get password from IPMI_PASSWORD environment var */
- gpswd = getenv("IPMI_PASSWORD");
- if (gpswd == NULL) perror("getenv(IPMI_PASSWORD)");
+ p = getenv("IPMI_PASSWORD");
+ if (p == NULL) perror("getenv(IPMI_PASSWORD)");
else {
- if (strlen(gpswd) > PSW_MAX) gpswd[PSW_MAX] = '\0';
+ strncpy(lanp.pswd,p,PSW_MAX); /*remote password */
+ if (strlen(p) > PSW_MAX) lanp.pswd[PSW_MAX] = '\0';
if (fdebugcmd) printf("using IPMI_PASSWORD\n");
}
break;
case 'Y': /* prompt for remote password */
- gpswd = getline_wipe("Enter IPMI LAN Password: ");
- if (gpswd != NULL) {
- if (strlen(gpswd) > PSW_MAX) gpswd[PSW_MAX] = '\0';
+ p = getline_wipe("Enter IPMI LAN Password: ");
+ if (p != NULL) {
+ strncpy(lanp.pswd,p,PSW_MAX); /*remote password */
+ if (strlen(p) > PSW_MAX) lanp.pswd[PSW_MAX] = '\0';
}
break;
case 'Z': /* set local MC address */