From d5b598c93daab9d6fe13321aa5c4f79e8c90417e Mon Sep 17 00:00:00 2001 From: Duncan Laurie Date: Fri, 27 Aug 2004 16:29:07 +0000 Subject: [PATCH] all interfaces are static now --- ipmitool/src/plugins/ipmi_intf.c | 202 ++++++++++----------- ipmitool/src/plugins/ipmi_intf_static.c.in | 49 ----- 2 files changed, 95 insertions(+), 156 deletions(-) delete mode 100644 ipmitool/src/plugins/ipmi_intf_static.c.in diff --git a/ipmitool/src/plugins/ipmi_intf.c b/ipmitool/src/plugins/ipmi_intf.c index a3510bb..e43fc49 100644 --- a/ipmitool/src/plugins/ipmi_intf.c +++ b/ipmitool/src/plugins/ipmi_intf.c @@ -36,141 +36,129 @@ #include #include -#include #include #include #include -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; } diff --git a/ipmitool/src/plugins/ipmi_intf_static.c.in b/ipmitool/src/plugins/ipmi_intf_static.c.in deleted file mode 100644 index 2a784fa..0000000 --- a/ipmitool/src/plugins/ipmi_intf_static.c.in +++ /dev/null @@ -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 -#include - -#include -#include -#include - -@STATIC_INTF_EXT@ - -struct static_intf static_intf_list[] = { - @STATIC_INTF@ - { 0, 0 } -};