From b18f5bf2db0fba2e7e539f68645836036d940d26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Wed, 29 Apr 2015 15:44:44 +0200 Subject: Imported Upstream version 2.9.6 --- util/ipmilan.c | 67 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 31 deletions(-) (limited to 'util/ipmilan.c') diff --git a/util/ipmilan.c b/util/ipmilan.c index 64b6425..814092e 100644 --- a/util/ipmilan.c +++ b/util/ipmilan.c @@ -215,14 +215,14 @@ extern char * get_iana_str(int mfg); /*subs.c*/ #define dbg_dump dump_buf extern FILE *fperr; /*defined in ipmicmd.c, usu stderr */ extern FILE *fpdbg; /*defined in ipmicmd.c, usu stdout */ -extern int gshutdown; /* from ipmicmd.c */ -extern char gnodename[]; /* from ipmicmd.c */ -extern char *gnode; /* from ipmicmd.c */ -extern char *guser; /* from ipmicmd.c */ -extern char *gpswd; /* from ipmicmd.c */ +extern int gshutdown; /* from ipmicmd.c, usu =0 */ extern int fauth_type_set; /* from ipmicmd.c */ -extern int gauth_type; /* from ipmicmd.c */ -extern int gpriv_level; /* from ipmicmd.c */ +extern LAN_OPT lanp; /* from ipmicmd.c */ +//extern char *gnode; /* from ipmicmd.c */ +//extern char *guser; /* from ipmicmd.c */ +//extern char *gpswd; /* from ipmicmd.c */ +//extern int gauth_type; /* from ipmicmd.c */ +//extern int gpriv_level; /* from ipmicmd.c */ extern ipmi_cmd_t ipmi_cmds[NCMDS]; static IPMI_HDR ipmi_hdr = { 0x06, 0, 0xFF, 0x07, 0x00, 0, 0, @@ -236,7 +236,7 @@ static int vend_id = 0; static int prod_id = 0; #if defined(DOS) || defined(EFI) -int ipmi_open_lan(char *node, char *user, char *pswd, int fdebugcmd) +int ipmi_open_lan(char *node, char *user, int port, char *pswd, int fdebugcmd) { printf("IPMI LAN is not supported under DOS.\n"); return(-1); @@ -294,6 +294,7 @@ typedef struct { // static uchar fMsgAuth = 1; static uchar auth_type = AUTHTYPE_INIT; /*initial value, not set*/ static char nodename[SZGNODE+1] = ""; + static char gnodename[SZGNODE+1] = ""; /*nodename returned after connection*/ #if defined(AI_NUMERICSERV) static int my_ai_flags = AI_NUMERICSERV; /*0x0400 Dont use name resolution NEW*/ // static int my_ai_flags = AI_NUMERICHOST; /*0x0004 Dont use name resolution*/ @@ -519,9 +520,9 @@ void close_sockfd(SockType sfd) pconn->sockfd = 0; /*set global to zero */ } -int open_sockfd(char *node, SockType *sfd, SOCKADDR_T *daddr, +int open_sockfd(char *node, int port, SockType *sfd, SOCKADDR_T *daddr, int *daddr_len, int foutput); -int open_sockfd(char *node, SockType *sfd, SOCKADDR_T *daddr, +int open_sockfd(char *node, int port, SockType *sfd, SOCKADDR_T *daddr, int *daddr_len, int foutput) { int rv = 0; @@ -559,7 +560,7 @@ int open_sockfd(char *node, SockType *sfd, SOCKADDR_T *daddr, #ifdef HAVE_IPV6 memset(&_srcaddr, 0, sizeof(_srcaddr)); memset(daddr, 0, sizeof(_destaddr)); - sprintf(service, "%d", RMCP_PRI_RMCP_PORT); + sprintf(service, "%d", port); /* Obtain address(es) matching host/port */ memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */ @@ -579,11 +580,11 @@ int open_sockfd(char *node, SockType *sfd, SOCKADDR_T *daddr, * and) try the next address. */ for (res0 = res; res0 != NULL; res0 = res0->ai_next) { + /* valid protocols are IPPROTO_UDP, IPPROTO_IPV6 */ + if (res0->ai_protocol == IPPROTO_TCP) continue; /*IPMI != TCP*/ s = socket(res0->ai_family, res0->ai_socktype, res0->ai_protocol); if (s == SockInvalid) continue; else _sockfd = s; - /* valid protocols are IPPROTO_UDP, IPPROTO_IPV6 */ - if (res0->ai_protocol == IPPROTO_TCP) continue; /*IPMI != TCP*/ pconn->connect_state = CONN_STATE_SOCK; rv = connect(_sockfd, res0->ai_addr, res0->ai_addrlen); if (fdebuglan) printf("socket(%d,%d,%d), connect(%d) rv = %d\n", @@ -622,7 +623,7 @@ int open_sockfd(char *node, SockType *sfd, SOCKADDR_T *daddr, memset(daddr, 0, sizeof(SOCKADDR_T)); daddr->sin_family = AF_INET; - daddr->sin_port = htons(RMCP_PRI_RMCP_PORT); /*0x26f = 623.*/ + daddr->sin_port = htons(port); /*RMCP_PRI_RMCP_PORT 0x26f = 623.*/ if (StrIsIp(node)) { /* the node string is an IP address */ uchar in_ip[4]; atoip(in_ip,node); @@ -737,12 +738,12 @@ static void h2net(uint h, uchar *net, int n) return; } -static void net2h(uint *h, uchar *net, int n) +static void net2h(uint32 *h, uchar *net, int n) { - uint v; + uint32 v; v = (net[1] << 8) | net[0]; if (n == 2) { *h = v; return; } - v |= (net[3] << 24) | (net[2] << 16); + v |= (uint32)(net[3] << 24) | (net[2] << 16); *h = v; return; } @@ -1065,7 +1066,7 @@ static int _send_lan_cmd(SockType s, uchar *pcmd, int scmd, uchar *presp, memcpy(&pdata[5],&sess_id_tmp,4); if (fdebuglan > 2) dbglog("auth_type=%x/%x fdoauth=%d hlen=%d seq_num=%x\n", /*SOL*/ - phdr->auth_type,gauth_type,fdoauth,hlen,phdr->seq_num); + phdr->auth_type,lanp.auth_type,fdoauth,hlen,phdr->seq_num); if (fdoauth) { psessid = (uchar *)&sess_id_tmp; do_hash(phdr->password, psessid, &cbuf[hlen],msglen, @@ -1434,7 +1435,7 @@ static int ipmilan_open_session(SockType sfd, struct sockaddr *destaddr, else pconn->fMsgAuth = 0; /*no auth support*/ iauthcap = rbuf[2] & 0x3f; if (fauth_type_set) { - iauthtype = (uchar)gauth_type; // set by user + iauthtype = (uchar)lanp.auth_type; // set by user auth_type = iauthtype; } else { iauthtype = AUTHTYPE_INIT; /*initial value, not set*/ @@ -1644,7 +1645,7 @@ int ping_bmc(char *node, int fdebugcmd) SockType sfd; int rv; - rv = open_sockfd(node,&sfd, &toaddr, &toaddr_len, fdebugcmd); + rv = open_sockfd(node, RMCP_PRI_RMCP_PORT, &sfd, &toaddr, &toaddr_len, fdebugcmd); if (rv != 0) return(rv); rv = rmcp_ping(sfd, (struct sockaddr *)&toaddr,toaddr_len, fdebugcmd); @@ -1675,7 +1676,7 @@ static int get_rand(void *data, int len) /* * ipmi_open_lan */ -int ipmi_open_lan(char *node, char *user, char *pswd, int fdebugcmd) +int ipmi_open_lan(char *node, int port, char *user, char *pswd, int fdebugcmd) { char *username; uchar priv_level; @@ -1696,21 +1697,21 @@ int ipmi_open_lan(char *node, char *user, char *pswd, int fdebugcmd) goto EXIT; } else { - if ((gshutdown==0) || fdebugcmd) + if (fdebugcmd) fprintf(fpdbg,"Opening lan connection to node %s ...\n",node); /* save nodename for sig_abort later */ if (strlen(node) > SZGNODE) { strncpy(nodename, node, SZGNODE); nodename[SZGNODE] = 0; } else strcpy(nodename, node); - - rv = open_sockfd(node, &(pconn->sockfd), &_destaddr, &_destaddr_len, 1); + rv = open_sockfd(node, port, &(pconn->sockfd), &_destaddr, &_destaddr_len, 1); if (fdebugcmd) printf("open_sockfd returned %d, fd=%d\n", rv, pconn->sockfd); if (rv != 0) goto EXIT; #ifdef HAVE_IPV6 strcpy(gnodename,nodename); - fprintf(fpdbg,"Connecting to node %s\n",gnodename); + if (fdebugcmd) + fprintf(fpdbg,"Connecting to node %s\n",gnodename); #else #ifdef WIN32 /* check for ws2_32.lib(getnameinfo) resolution */ @@ -1769,8 +1770,8 @@ int ipmi_open_lan(char *node, char *user, char *pswd, int fdebugcmd) } { - auth_type = (uchar)gauth_type; - priv_level = (uchar)gpriv_level; + auth_type = (uchar)lanp.auth_type; + priv_level = (uchar)lanp.priv; username = user; authcode = pswd; authcode_len = (pswd) ? strlen_(authcode) : 0; @@ -1834,6 +1835,8 @@ int ipmi_close_lan(char *node) int rv = 0; /* could match node via pconn = find_conn(node); */ + if (fdebuglan) fprintf(fpdbg,"ipmi_close_lan(%s) entry, sockfd=%d\n", + node,pconn->sockfd); if (!nodeislocal(node)) { /* ipmilan, need to close & cleanup */ if (pconn->sockfd != 0) { /* socket is open */ if (gshutdown) pconn->session_id = 0; @@ -1856,6 +1859,8 @@ int ipmi_close_lan(char *node) signal(SIGALRM,SIG_DFL); #endif } /* endif */ + if (fdebuglan) fprintf(fpdbg,"ipmi_close_lan(%s) rv=%d sockfd=%d\n", + node,rv,pconn->sockfd); return (rv); } @@ -1899,7 +1904,7 @@ int ipmicmd_lan(char *node, if (pconn->sockfd == 0) { /* closed, do re-open */ if (fdebugcmd) fprintf(fpdbg,"sockfd==0, node %s needs re-open\n",node); - rv = ipmi_open_lan(gnode, guser, gpswd, fdebugcmd); + rv = ipmi_open_lan(lanp.node, lanp.port, lanp.user, lanp.pswd, fdebugcmd); if (rv != 0) goto EXIT; } if (fdebugcmd) { @@ -2057,7 +2062,7 @@ void lan_get_sol_data(uchar fEnc, uchar seed_cnt, uint32 *seed) sol_seed_cnt = seed_cnt; pconn->start_out_seq = ipmi_hdr.seq_num; sol_snd_seq = (uchar)pconn->start_out_seq; - sol15_cipherinit(sol_seed_cnt, gpswd, pconn->start_out_seq); + sol15_cipherinit(sol_seed_cnt, lanp.pswd, pconn->start_out_seq); *seed = g_Seed[sol_seed_cnt]; if (fdebuglan > 2) dbglog("lan_get_sol_data: %02x %02x %02x\n", /*SOL*/ @@ -2084,7 +2089,7 @@ void lan_set_sol_data(uchar fenc, uchar auth, uchar seed_cnt, if (seed_cnt != sol_seed_cnt && (seed_cnt < 16)) { /* if seed count changed, re-init the cipher. */ sol_seed_cnt = seed_cnt; - sol15_cipherinit(sol_seed_cnt, gpswd, pconn->start_out_seq); + sol15_cipherinit(sol_seed_cnt, lanp.pswd, pconn->start_out_seq); } } @@ -2150,7 +2155,7 @@ int lan_send_sol( uchar *buffer, int len, SOL_RSP_PKT *rsp) if (fdebuglan > 2) { /*SOL*/ dbg_dump("lan_send_sol input", buffer,len,1); dbglog("auth_type=%x/%x fdoauth=%d hlen=%d seq_num=%x enc=%d\n", - phdr->auth_type,gauth_type,fdoauth,hlen,phdr->seq_num, + phdr->auth_type,lanp.auth_type,fdoauth,hlen,phdr->seq_num, sol_Encryption); dbg_dump("send_sol buf", pdata,msglen,1); } -- cgit v1.2.3