all interfaces are static now

This commit is contained in:
Duncan Laurie 2004-08-27 16:29:07 +00:00
parent c452979e74
commit d5b598c93d
2 changed files with 95 additions and 156 deletions

View File

@ -36,141 +36,129 @@
#include <stdio.h>
#include <stdlib.h>
#include <ltdl.h>
#include <config.h>
#include <ipmitool/ipmi_intf.h>
#include <ipmitool/ipmi.h>
extern struct static_intf static_intf_list[];
#ifdef IPMI_INTF_OPEN
extern struct ipmi_intf ipmi_open_intf;
#endif
#ifdef IPMI_INTF_IMB
extern struct ipmi_intf ipmi_imb_intf;
#endif
#ifdef IPMI_INTF_LIPMI
extern struct ipmi_intf ipmi_lipmi_intf;
#endif
#ifdef IPMI_INTF_LAN
extern struct ipmi_intf ipmi_lan_intf;
#endif
#ifdef IPMI_INTF_LANPLUS
extern struct ipmi_intf ipmi_lanplus_intf;
#endif
/* ipmi_intf_init
* initialize dynamic plugin interface
*/
int ipmi_intf_init(void)
struct ipmi_intf * ipmi_intf_table[] = {
#ifdef IPMI_INTF_OPEN
&ipmi_open_intf,
#endif
#ifdef IPMI_INTF_IMB
&ipmi_imb_intf,
#endif
#ifdef IPMI_INTF_LIPMI
&ipmi_lipmi_intf,
#endif
#ifdef IPMI_INTF_LAN
&ipmi_lan_intf,
#endif
#ifdef IPMI_INTF_LANPLUS
&ipmi_lanplus_intf,
#endif
NULL
};
char * ipmi_intf_print(void)
{
if (lt_dlinit() < 0) {
printf("ERROR: Unable to initialize ltdl: %s\n",
lt_dlerror());
return -1;
}
struct ipmi_intf ** intf;
int def = 1;
if (lt_dlsetsearchpath(PLUGIN_PATH) < 0) {
printf("ERROR: Unable to set ltdl plugin path to %s: %s\n",
PLUGIN_PATH, lt_dlerror());
lt_dlexit();
return -1;
for (intf = ipmi_intf_table; intf && *intf; intf++) {
printf("\t%-12s %s", (*intf)->name, (*intf)->desc);
if (def) {
printf(" [default]");
def = 0;
}
printf("\n");
}
return 0;
}
/* ipmi_intf_exit
* close dynamic plugin interface
*/
void ipmi_intf_exit(void)
{
if (lt_dlexit() < 0)
printf("ERROR: Unable to cleanly exit ltdl: %s\n",
lt_dlerror());
}
/* ipmi_intf_load
* name: interface plugin name to load
/* Load an interface from the interface table above
* If no interface name is given return first entry
*/
struct ipmi_intf * ipmi_intf_load(char * name)
{
lt_dlhandle handle;
struct ipmi_intf * intf;
int (*setup)(struct ipmi_intf ** intf);
struct static_intf *i = static_intf_list;
char libname[16];
struct ipmi_intf ** intf;
struct ipmi_intf * i;
while (i->name) {
if (!strcmp(name, i->name)) {
if (i->setup(&intf) < 0) {
printf("ERROR: Unable to setup static interface %s\n", name);
if (!name) {
i = ipmi_intf_table[0];
if (i->setup && (i->setup(i) < 0)) {
printf("ERROR: Unable to setup interface %s\n", name);
return NULL;
}
return i;
}
for (intf = ipmi_intf_table; intf && *intf ; intf++) {
i = *intf;
if (!strncmp(name, i->name, strlen(name))) {
if (i->setup && (i->setup(i) < 0)) {
printf("ERROR: Unable to setup interface %s\n", name);
return NULL;
}
return intf;
return i;
}
i++;
}
if (ipmi_intf_init() < 0)
return NULL;
memset(libname, 0, 16);
if (snprintf(libname, sizeof(libname), "lib%s", name) <= 0) {
printf("ERROR: Unable to find plugin '%s' in '%s'\n",
name, PLUGIN_PATH);
return NULL;
}
handle = lt_dlopenext(libname);
if (handle == NULL) {
printf("ERROR: Unable to find plugin '%s' in '%s': %s\n",
libname, PLUGIN_PATH, lt_dlerror());
return NULL;
}
setup = lt_dlsym(handle, "intf_setup");
if (!setup) {
printf("ERROR: Unable to find interface setup symbol "
"in plugin %s: %s\n", name,
lt_dlerror());
lt_dlclose(handle);
return NULL;
}
if (setup(&intf) < 0) {
printf("ERROR: Unable to run interface setup for plugin %s\n", name);
lt_dlclose(handle);
return NULL;
}
return intf;
return NULL;
}
int ipmi_intf_session_set_hostname(struct ipmi_intf * intf, char * hostname)
void ipmi_intf_session_set_hostname(struct ipmi_intf * intf, char * hostname)
{
if (!intf || !intf->session)
return -1;
memset(intf->session->hostname, 0, 16);
memcpy(intf->session->hostname, hostname, min(strlen(hostname), 64));
}
int ipmi_intf_session_set_username(struct ipmi_intf * intf, char * username)
{
if (!intf || !intf->session)
return -1;
memset(intf->session->username, 0, 16);
memcpy(intf->session->username, username, min(strlen(username), 16));
}
int ipmi_intf_session_set_password(struct ipmi_intf * intf, char * password)
{
if (!intf || !intf->session)
return -1;
memset(intf->session->authcode, 0, 16);
if (password) {
intf->session->password = 1;
memcpy(intf->session->authcode, password, min(strlen(password), 16));
if (intf && intf->session) {
memset(intf->session->hostname, 0, 16);
if (hostname)
memcpy(intf->session->hostname, hostname, min(strlen(hostname), 64));
}
}
int ipmi_intf_session_set_privlvl(struct ipmi_intf * intf, unsigned char level)
void ipmi_intf_session_set_username(struct ipmi_intf * intf, char * username)
{
if (!intf || !intf->session)
return -1;
if (!intf->session->privlvl)
if (intf && intf->session) {
memset(intf->session->username, 0, 16);
if (username)
memcpy(intf->session->username, username, min(strlen(username), 16));
}
}
void ipmi_intf_session_set_password(struct ipmi_intf * intf, char * password)
{
if (intf && intf->session) {
memset(intf->session->authcode, 0, 16);
intf->session->password = 0;
if (password) {
intf->session->password = 1;
memcpy(intf->session->authcode, password, min(strlen(password), 16));
}
}
}
void ipmi_intf_session_set_privlvl(struct ipmi_intf * intf, unsigned char level)
{
if (intf && intf->session)
intf->session->privlvl = level;
}
int ipmi_intf_session_set_port(struct ipmi_intf * intf, int port)
void ipmi_intf_session_set_port(struct ipmi_intf * intf, int port)
{
if (!intf || !intf->session)
return -1;
intf->session->port = port;
if (intf && intf->session)
intf->session->port = port;
}

View File

@ -1,49 +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 <stdio.h>
#include <stdlib.h>
#include <config.h>
#include <ipmitool/ipmi_intf.h>
#include <ipmitool/ipmi.h>
@STATIC_INTF_EXT@
struct static_intf static_intf_list[] = {
@STATIC_INTF@
{ 0, 0 }
};