diff --git a/ChangeLog b/ChangeLog index 0e1be23..ceb1271 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,458 @@ +2012-01-04 Arnaud Quette + + * [r3371] docs/website/news.txt: Update 2.6.3 release date + +2012-01-03 Arnaud Quette + + * [r3370] NEWS, UPGRADING, configure.in, docs/website/news.txt: + Final update for 2.6.3 release + +2012-01-03 Frederic Bohe + + * [r3369] docs/config-notes.txt: Add a note about file names with + space characters in the documentation. + +2012-01-03 Arnaud Quette + + * [r3368] drivers/dummy-ups.c: Add a comment for further processing + +2012-01-03 Frederic Bohe + + * [r3367] tools/nut-scanner/nut-scanner.c: Fix nut scanner SNMP v3 + help message. + * [r3366] docs/man/nut-scanner.txt: Fix nut scanner SNMP v3 + documentation. + +2011-12-17 Arnaud Quette + + * [r3364] drivers/blazer_usb.c: Actually apply the langid_fix + value, when calling usb_get_string (reported by Charles Lepple) + * [r3363] data/driver.list.in, docs/man/blazer.txt, + drivers/blazer_usb.c: Try to fix language ID support for USB + units from LDLC, Dynamix and no names in blazer_usb (reworked + patch, from Brian R. Smith and Aurélien Grenotton) + +2011-12-16 Arnaud Quette + + * [r3362] scripts/HP-UX: Add the generated HP-UX packaging script + (.psf) to the list of Subversion ignored files + * [r3361] drivers/eaton-mib.c, drivers/snmp-ups.c: Fix newer Eaton + ePDU OIDs declaration ordering, so that it better supports the + various models (switched or advanced monitored) + +2011-12-15 Arnaud Quette + + * [r3360] clients/upsclient.c, drivers/belkinunv.c, + drivers/etapro.c, drivers/gamatronic.c, drivers/isbmex.c, + drivers/libshut.c, drivers/metasys.c, drivers/mge-shut.c, + drivers/microdowell.c, drivers/nut-libfreeipmi.c, + drivers/rhino.c, drivers/solis.c: Fix set but not used variables + [-Wunused-but-set-variable] (including patch from Regid Ichira) + +2011-12-13 Arnaud Quette + + * [r3359] Makefile.am, configure.in, docs/man, + docs/man/Makefile.am, docs/man/nutscan_init.txt, + docs/man/nutscan_scan_avahi.txt, docs/man/nutscan_scan_ipmi.txt, + docs/man/nutscan_scan_nut.txt, docs/man/nutscan_scan_snmp.txt, + docs/man/nutscan_scan_usb.txt, + docs/man/nutscan_scan_xml_http.txt, drivers/nut-libfreeipmi.c, + m4/nut_check_libfreeipmi.m4, m4/nut_check_libltdl.m4, + tools/nut-scanner/Makefile.am, tools/nut-scanner/nut-scan.h, + tools/nut-scanner/nut-scanner.c, + tools/nut-scanner/nutscan-init.c, + tools/nut-scanner/nutscan-init.h, tools/nut-scanner/scan_avahi.c, + tools/nut-scanner/scan_ipmi.c, tools/nut-scanner/scan_nut.c, + tools/nut-scanner/scan_snmp.c, tools/nut-scanner/scan_usb.c, + tools/nut-scanner/scan_xml_http.c: Merge nut-scanner_dlopen + branch, at revision 3358. This brings weak runtime dependencies + to nut-scanner, allowing to compile with all options and to run + according to the available dependencies. It also adds IPMI scan + * [r3358] compile: Update compile script, as per the latest version + available in Automake (1.11) + +2011-12-05 Arnaud Quette + + * [r3341] data/driver.list.in, docs/man/snmp-ups.txt, + drivers/Makefile.am, drivers/cyberpower-mib.c, + drivers/cyberpower-mib.h, drivers/snmp-ups.c: Add Cyber Power + Systems with SNMP RMCARD (100, 201, 202 and 301) to the list of + snmp-ups supported models (patch from Eric Schultz) + * [r3340] drivers/snmp-ups.c: Remove the Eaton Marlin hook, for + base outlet index, since it has been fixed by a new firmware + revision + +2011-11-29 Arnaud Quette + + * [r3338] tools/nut-snmpinfo.py: Fix indentation and use open() + instead of file(), to better support Python 3 (Alioth bug + #313446, patch from Bohdan Popovych) + +2011-11-25 Arnaud Quette + + * [r3335] drivers/nut-ipmi.h: Fix wrong prototype declaration, that + was causing a compilation warning (implicit declaration of + function ‘nut_ipmi_get_sensors_status’) + +2011-11-24 Prachi Gandhi + + * [r3328] Makefile.am, configure.in, scripts/Makefile.am, + scripts/Solaris: Reverted changes made for Solaris packaging + files(revision 3326), added files in NUT_packaging branch + * [r3326] Makefile.am, configure.in, scripts/Makefile.am, + scripts/Solaris, scripts/Solaris/Makefile.am, + scripts/Solaris/makelocal.sh, scripts/Solaris/pkginfo.in, + scripts/Solaris/prototype: Solaris NUT package files added + +2011-11-15 Arnaud Quette + + * [r3321] drivers/blazer_usb.c, drivers/usb-common.h: Revert commit + r2993 and r2994. This enables again inclusion of buggy USB Device + and Vendor IDs, supported by blazer_usb, in udev rules file + (Reported by Stanislav Brabec, from Suse) + * [r3320] tools/Makefile.am: Add missing comment + +2011-11-12 Arnaud Quette + + * [r3318] drivers/mge-mib.c: Add upsmgBatteryLowCondition OID to + the status mapping (reported by Kiss Gabor (Bitman)) + +2011-11-11 Praveen Kumar + + * [r3317] scripts/HP-UX/makedepot.sh: script file to create package + (depot) for HP-UX + +2011-11-08 Arnaud Quette + + * [r3316] docs/website/web-layout.conf: Complete search keywords + * [r3315] docs/website/web-layout.conf: Final fix for the + displaying of the legend, to work on all browsers, while still + being conforming to W3C validation + +2011-11-07 Arnaud Quette + + * [r3314] docs/website/web-layout.conf: Fix displaying of the + legend + +2011-11-05 Michal Soltys + + * [r3313] docs/cables.txt, docs/man/apcsmart.txt: apcsmart.txt: + minor documentation update + + Broken diagram link and 940-0024E cable mention (reported by + Jonathan + Laventhol). + +2011-11-05 Arnaud Quette + + * [r3312] conf/upsd.conf.sample, server/upsd.c: Don't fail to start + if at least one of the listening interface is available. This is + needed on systems where either IPv4 or IPv6 is disabled, and no + explicit LISTEN directive has been specified (Reported by Pavel + Zubkou, Debian bug #598741) + +2011-11-02 Praveen Kumar + + * [r3310] configure.in, scripts/HP-UX/nut.psf.in: Adding packaging + script for HPUX + +2011-10-31 Arnaud Quette + + * [r3308] docs/download.txt, docs/website/news.txt: Publish update + jNut 0.2, along with the new jNutWebAPI (contributed by Emilien + Kia, from Eaton) + +2011-10-28 Emilien Kia + + * [r3306] scripts/java/README, scripts/java/jNutWebAPI, + scripts/java/jNutWebAPI/README, scripts/java/jNutWebAPI/pom.xml, + scripts/java/jNutWebAPI/src, scripts/java/jNutWebAPI/src/main, + scripts/java/jNutWebAPI/src/main/java, + scripts/java/jNutWebAPI/src/main/java/org, + scripts/java/jNutWebAPI/src/main/java/org/networkupstools, + scripts/java/jNutWebAPI/src/main/java/org/networkupstools/jnutwebapi, + scripts/java/jNutWebAPI/src/main/java/org/networkupstools/jnutwebapi/NutRestProvider.java, + scripts/java/jNutWebAPI/src/main/java/org/networkupstools/jnutwebapi/RestWSApplication.java, + scripts/java/jNutWebAPI/src/main/java/org/networkupstools/jnutwebapi/ScannerProvider.java, + scripts/java/jNutWebAPI/src/main/resources, + scripts/java/jNutWebAPI/src/main/webapp, + scripts/java/jNutWebAPI/src/main/webapp/WEB-INF, + scripts/java/jNutWebAPI/src/main/webapp/WEB-INF/web.xml, + scripts/java/jNutWebAPI/src/test, + scripts/java/jNutWebAPI/src/test/java, + scripts/java/jNutWebAPI/src/test/java/org, + scripts/java/jNutWebAPI/src/test/java/org/networkupstools, + scripts/java/jNutWebAPI/src/test/java/org/networkupstools/jnutwebapi: + Initial commit of jNutWebAPI. + * [r3305] scripts/java/jNut, + scripts/java/jNut/src/main/java/org/networkupstools/jnut/Scanner.java: + Fix a little bug with function namming (get instead of set). + +2011-10-27 Arnaud Quette + + * [r3304] docs/maintainer-guide.txt: Create a basic NUT maintainer + guide, to start tracking and improving maintenance workflow + * [r3303] drivers/bcmxcp_usb.c: Handle disconnection issues and + reconnection mechanism (bug reported by Rich Wrenn) + +2011-10-25 Emilien Kia + + * [r3302] + scripts/java/jNut/src/test/java/org/networkupstools/jnut/ClientTest.java: + Add licence information. + * [r3301] scripts/java/jNut/README, scripts/java/jNut/pom.xml, + scripts/java/jNut/src/main/java/org/networkupstools/jnut/Scanner.java, + scripts/java/jNut/src/test/java/org/networkupstools/jnut/ScannerTest.java: + Add nut-scanner. + +2011-10-25 Frederic Bohe + + * [r3300] tools/nut-scanner/scan_snmp.c: Add sanity checks + * [r3299] tools/nut-scanner/scan_avahi.c: Remove unused variable + +2011-10-25 Michal Soltys + + * [r3298] drivers/apcsmart.c: drivers/apcsmart.c: minor correction + + Assigning 0 directly was wrong (actually, a leftover from earlier + version of the code that was removed) - ser_set_speed() prepares + the + port initially, we only adjust certain options. + +2011-10-24 Frederic Bohe + + * [r3297] docs/man/nut-scanner.txt, + tools/nut-scanner/nut-scanner.c: Forgot to document "-q" option + (thanks to Emilien Kia for reporting this) + +2011-10-21 Frederic Bohe + + * [r3296] tools/nut-scanner/nut-scanner.c: Trivial layout + consistency + * [r3295] docs/man/nut-scanner.txt: Update man page with -V and -a + option + * [r3294] tools/nut-scanner/nut-scanner.c: Add an option to display + available bus (usefull for wrapper). + * [r3293] tools/nut-scanner/nut-scanner.c: return -1 on bad command + line option + +2011-10-19 Frederic Bohe + + * [r3292] tools/nut-scanner/nutscan-ip.c: Fix crash on 32bits + systems + * [r3291] tools/nut-scanner/nut-scanner.c: Add a switch to display + NUT version. + +2011-10-19 Charles Lepple + + * [r3290] docs/FAQ.txt: Add FAQ entry for LISTEN directive + +2011-10-18 Arnaud Quette + + * [r3289] drivers/eaton-mib.c: Fix outlets reported current, which + were off by 100 in aphel_genesisII MIB, and bump MIB version to + 0.46 (patch from Sven Nilsson) + +2011-10-14 Arnaud Quette + + * [r3288] docs/Makefile.am, docs/images/nut-logo.png, + docs/images/nut.svg, docs/website/Makefile.am, + docs/website/css/web-layout.css, docs/website/faviconut.ico, + docs/website/faviconut.png, docs/website/web-layout.conf: Add the + new NUT logo (contributed by Luc Descotils, from Eaton) + * [r3287] docs/website/web-layout.conf: Fix another W3C validator + error (there is no attribute "language" anymore for - + endif::hcl[] + + battery + battery + hald-addon-blazer_usb + ups + + @@ -506,6 +515,13 @@ + + + battery + battery + hald-addon-usbhid-ups + ups + battery @@ -571,6 +587,15 @@ ups + + + + battery + battery + hald-addon-blazer_usb + ups + + diff --git a/scripts/hotplug/Makefile.in b/scripts/hotplug/Makefile.in index 9bbde22..62bc680 100644 --- a/scripts/hotplug/Makefile.in +++ b/scripts/hotplug/Makefile.in @@ -51,6 +51,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ax_compare_version.m4 \ $(top_srcdir)/m4/nut_check_libfreeipmi.m4 \ $(top_srcdir)/m4/nut_check_libgd.m4 \ $(top_srcdir)/m4/nut_check_libhal.m4 \ + $(top_srcdir)/m4/nut_check_libltdl.m4 \ $(top_srcdir)/m4/nut_check_libneon.m4 \ $(top_srcdir)/m4/nut_check_libnetsnmp.m4 \ $(top_srcdir)/m4/nut_check_libpowerman.m4 \ @@ -117,6 +118,7 @@ CYGPATH_W = @CYGPATH_W@ DBLATEX = @DBLATEX@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ DOC_BUILD_LIST = @DOC_BUILD_LIST@ DRIVER_BUILD_LIST = @DRIVER_BUILD_LIST@ DRIVER_INSTALL_TARGET = @DRIVER_INSTALL_TARGET@ @@ -149,6 +151,8 @@ LIBHAL_CFLAGS = @LIBHAL_CFLAGS@ LIBHAL_LIBS = @LIBHAL_LIBS@ LIBIPMI_CFLAGS = @LIBIPMI_CFLAGS@ LIBIPMI_LIBS = @LIBIPMI_LIBS@ +LIBLTDL_CFLAGS = @LIBLTDL_CFLAGS@ +LIBLTDL_LIBS = @LIBLTDL_LIBS@ LIBNEON_CFLAGS = @LIBNEON_CFLAGS@ LIBNEON_LIBS = @LIBNEON_LIBS@ LIBNETSNMP_CFLAGS = @LIBNETSNMP_CFLAGS@ @@ -169,6 +173,7 @@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ NETLIBS = @NETLIBS@ NM = @NM@ @@ -200,12 +205,14 @@ SHELL = @SHELL@ STATEPATH = @STATEPATH@ STRIP = @STRIP@ SUN_LIBUSB = @SUN_LIBUSB@ +TREE_VERSION = @TREE_VERSION@ VERSION = @VERSION@ WORDS_BIGENDIAN = @WORDS_BIGENDIAN@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ @@ -241,7 +248,6 @@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ -lt_ECHO = @lt_ECHO@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ diff --git a/scripts/hotplug/libhid.usermap b/scripts/hotplug/libhid.usermap index 4eba6e3..53c1519 100644 --- a/scripts/hotplug/libhid.usermap +++ b/scripts/hotplug/libhid.usermap @@ -4,6 +4,8 @@ # libhidups 0x0003 0xVVVV 0xPPPP 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000 # # usb module match_flags idVendor idProduct bcdDevice_lo bcdDevice_hi bDeviceClass bDeviceSubClass bDeviceProtocol bInterfaceClass bInterfaceSubClass bInterfaceProtocol driver_info +# Krauler UP-M500VA +libhidups 0x0003 0x0001 0x0000 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000 # Hewlett Packard # T500 @@ -156,6 +158,8 @@ libhidups 0x0003 0x09ae 0x4007 0x0000 0x0000 0x00 libhidups 0x0003 0x09ae 0x4008 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000 # PowerCOM +# PowerCOM BNT-xxxAP +libhidups 0x0003 0x0d9f 0x0004 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000 # PowerCOM IMP - IMPERIAL Series libhidups 0x0003 0x0d9f 0x00a2 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000 # PowerCOM SKP - Smart KING Pro (all Smart series) @@ -174,3 +178,5 @@ libhidups 0x0003 0x0f03 0x0001 0x0000 0x0000 0x00 libhidups 0x0003 0x10af 0x0001 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000 # GE EP series libhidups 0x0003 0x14f0 0x00c9 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000 +# Ablerex 625L USB +libhidups 0x0003 0xffff 0x0000 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000 diff --git a/scripts/java/Makefile.in b/scripts/java/Makefile.in index 8e5a589..a10e01e 100644 --- a/scripts/java/Makefile.in +++ b/scripts/java/Makefile.in @@ -49,6 +49,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ax_compare_version.m4 \ $(top_srcdir)/m4/nut_check_libfreeipmi.m4 \ $(top_srcdir)/m4/nut_check_libgd.m4 \ $(top_srcdir)/m4/nut_check_libhal.m4 \ + $(top_srcdir)/m4/nut_check_libltdl.m4 \ $(top_srcdir)/m4/nut_check_libneon.m4 \ $(top_srcdir)/m4/nut_check_libnetsnmp.m4 \ $(top_srcdir)/m4/nut_check_libpowerman.m4 \ @@ -89,6 +90,7 @@ CYGPATH_W = @CYGPATH_W@ DBLATEX = @DBLATEX@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ DOC_BUILD_LIST = @DOC_BUILD_LIST@ DRIVER_BUILD_LIST = @DRIVER_BUILD_LIST@ DRIVER_INSTALL_TARGET = @DRIVER_INSTALL_TARGET@ @@ -121,6 +123,8 @@ LIBHAL_CFLAGS = @LIBHAL_CFLAGS@ LIBHAL_LIBS = @LIBHAL_LIBS@ LIBIPMI_CFLAGS = @LIBIPMI_CFLAGS@ LIBIPMI_LIBS = @LIBIPMI_LIBS@ +LIBLTDL_CFLAGS = @LIBLTDL_CFLAGS@ +LIBLTDL_LIBS = @LIBLTDL_LIBS@ LIBNEON_CFLAGS = @LIBNEON_CFLAGS@ LIBNEON_LIBS = @LIBNEON_LIBS@ LIBNETSNMP_CFLAGS = @LIBNETSNMP_CFLAGS@ @@ -141,6 +145,7 @@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ NETLIBS = @NETLIBS@ NM = @NM@ @@ -172,12 +177,14 @@ SHELL = @SHELL@ STATEPATH = @STATEPATH@ STRIP = @STRIP@ SUN_LIBUSB = @SUN_LIBUSB@ +TREE_VERSION = @TREE_VERSION@ VERSION = @VERSION@ WORDS_BIGENDIAN = @WORDS_BIGENDIAN@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ @@ -213,7 +220,6 @@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ -lt_ECHO = @lt_ECHO@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ diff --git a/scripts/java/README b/scripts/java/README index 95d1bee..6996f1d 100644 --- a/scripts/java/README +++ b/scripts/java/README @@ -12,3 +12,8 @@ way, without having to know the NUT protocol. * "jNutList": this directory contains maven project and source files for jNutList, a simple Java example program using jNut which connect to an UPSD, lists its ups and their variables and commands. + +* "jNutWebAPI": this directory contains maven project and source files for +jNutWebAPI, a simple Java web archive to access nut informations via REST +web services. + diff --git a/scripts/java/jNut/README b/scripts/java/jNut/README index 3c75e24..b68eef2 100644 --- a/scripts/java/jNut/README +++ b/scripts/java/jNut/README @@ -69,3 +69,9 @@ ping-pong mecanism itself. At present time, jNut do not support SSL connection. It is planned for near future. + +Changelog +^^^^^^^^^ +* "0.2": Add nut-scanner. +* "0.1": Initial version with basic dialog with UPSD. + diff --git a/scripts/java/jNut/pom.xml b/scripts/java/jNut/pom.xml index a2c0e5c..b53b426 100644 --- a/scripts/java/jNut/pom.xml +++ b/scripts/java/jNut/pom.xml @@ -4,7 +4,7 @@ org.networkupstools jNut - 0.1-SNAPSHOT + 0.2-SNAPSHOT jar jNut diff --git a/scripts/java/jNut/src/test/java/org/networkupstools/jnut/ClientTest.java b/scripts/java/jNut/src/test/java/org/networkupstools/jnut/ClientTest.java index 73f6296..e3bce72 100644 --- a/scripts/java/jNut/src/test/java/org/networkupstools/jnut/ClientTest.java +++ b/scripts/java/jNut/src/test/java/org/networkupstools/jnut/ClientTest.java @@ -1,3 +1,21 @@ +/* ClientTest.java + + Copyright (C) 2011 Eaton + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ package org.networkupstools.jnut; import junit.framework.Test; diff --git a/scripts/python/Makefile.in b/scripts/python/Makefile.in index 7f07265..4f89ab1 100644 --- a/scripts/python/Makefile.in +++ b/scripts/python/Makefile.in @@ -49,6 +49,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ax_compare_version.m4 \ $(top_srcdir)/m4/nut_check_libfreeipmi.m4 \ $(top_srcdir)/m4/nut_check_libgd.m4 \ $(top_srcdir)/m4/nut_check_libhal.m4 \ + $(top_srcdir)/m4/nut_check_libltdl.m4 \ $(top_srcdir)/m4/nut_check_libneon.m4 \ $(top_srcdir)/m4/nut_check_libnetsnmp.m4 \ $(top_srcdir)/m4/nut_check_libpowerman.m4 \ @@ -89,6 +90,7 @@ CYGPATH_W = @CYGPATH_W@ DBLATEX = @DBLATEX@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ DOC_BUILD_LIST = @DOC_BUILD_LIST@ DRIVER_BUILD_LIST = @DRIVER_BUILD_LIST@ DRIVER_INSTALL_TARGET = @DRIVER_INSTALL_TARGET@ @@ -121,6 +123,8 @@ LIBHAL_CFLAGS = @LIBHAL_CFLAGS@ LIBHAL_LIBS = @LIBHAL_LIBS@ LIBIPMI_CFLAGS = @LIBIPMI_CFLAGS@ LIBIPMI_LIBS = @LIBIPMI_LIBS@ +LIBLTDL_CFLAGS = @LIBLTDL_CFLAGS@ +LIBLTDL_LIBS = @LIBLTDL_LIBS@ LIBNEON_CFLAGS = @LIBNEON_CFLAGS@ LIBNEON_LIBS = @LIBNEON_LIBS@ LIBNETSNMP_CFLAGS = @LIBNETSNMP_CFLAGS@ @@ -141,6 +145,7 @@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ NETLIBS = @NETLIBS@ NM = @NM@ @@ -172,12 +177,14 @@ SHELL = @SHELL@ STATEPATH = @STATEPATH@ STRIP = @STRIP@ SUN_LIBUSB = @SUN_LIBUSB@ +TREE_VERSION = @TREE_VERSION@ VERSION = @VERSION@ WORDS_BIGENDIAN = @WORDS_BIGENDIAN@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ @@ -213,7 +220,6 @@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ -lt_ECHO = @lt_ECHO@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ diff --git a/scripts/systemd/Makefile.in b/scripts/systemd/Makefile.in index 9f9f633..28dc04a 100644 --- a/scripts/systemd/Makefile.in +++ b/scripts/systemd/Makefile.in @@ -52,6 +52,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ax_compare_version.m4 \ $(top_srcdir)/m4/nut_check_libfreeipmi.m4 \ $(top_srcdir)/m4/nut_check_libgd.m4 \ $(top_srcdir)/m4/nut_check_libhal.m4 \ + $(top_srcdir)/m4/nut_check_libltdl.m4 \ $(top_srcdir)/m4/nut_check_libneon.m4 \ $(top_srcdir)/m4/nut_check_libnetsnmp.m4 \ $(top_srcdir)/m4/nut_check_libpowerman.m4 \ @@ -117,6 +118,7 @@ CYGPATH_W = @CYGPATH_W@ DBLATEX = @DBLATEX@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ DOC_BUILD_LIST = @DOC_BUILD_LIST@ DRIVER_BUILD_LIST = @DRIVER_BUILD_LIST@ DRIVER_INSTALL_TARGET = @DRIVER_INSTALL_TARGET@ @@ -149,6 +151,8 @@ LIBHAL_CFLAGS = @LIBHAL_CFLAGS@ LIBHAL_LIBS = @LIBHAL_LIBS@ LIBIPMI_CFLAGS = @LIBIPMI_CFLAGS@ LIBIPMI_LIBS = @LIBIPMI_LIBS@ +LIBLTDL_CFLAGS = @LIBLTDL_CFLAGS@ +LIBLTDL_LIBS = @LIBLTDL_LIBS@ LIBNEON_CFLAGS = @LIBNEON_CFLAGS@ LIBNEON_LIBS = @LIBNEON_LIBS@ LIBNETSNMP_CFLAGS = @LIBNETSNMP_CFLAGS@ @@ -169,6 +173,7 @@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ NETLIBS = @NETLIBS@ NM = @NM@ @@ -200,12 +205,14 @@ SHELL = @SHELL@ STATEPATH = @STATEPATH@ STRIP = @STRIP@ SUN_LIBUSB = @SUN_LIBUSB@ +TREE_VERSION = @TREE_VERSION@ VERSION = @VERSION@ WORDS_BIGENDIAN = @WORDS_BIGENDIAN@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ @@ -241,7 +248,6 @@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ -lt_ECHO = @lt_ECHO@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ diff --git a/scripts/udev/Makefile.in b/scripts/udev/Makefile.in index 55c58b3..be711f3 100644 --- a/scripts/udev/Makefile.in +++ b/scripts/udev/Makefile.in @@ -51,6 +51,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ax_compare_version.m4 \ $(top_srcdir)/m4/nut_check_libfreeipmi.m4 \ $(top_srcdir)/m4/nut_check_libgd.m4 \ $(top_srcdir)/m4/nut_check_libhal.m4 \ + $(top_srcdir)/m4/nut_check_libltdl.m4 \ $(top_srcdir)/m4/nut_check_libneon.m4 \ $(top_srcdir)/m4/nut_check_libnetsnmp.m4 \ $(top_srcdir)/m4/nut_check_libpowerman.m4 \ @@ -114,6 +115,7 @@ CYGPATH_W = @CYGPATH_W@ DBLATEX = @DBLATEX@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ DOC_BUILD_LIST = @DOC_BUILD_LIST@ DRIVER_BUILD_LIST = @DRIVER_BUILD_LIST@ DRIVER_INSTALL_TARGET = @DRIVER_INSTALL_TARGET@ @@ -146,6 +148,8 @@ LIBHAL_CFLAGS = @LIBHAL_CFLAGS@ LIBHAL_LIBS = @LIBHAL_LIBS@ LIBIPMI_CFLAGS = @LIBIPMI_CFLAGS@ LIBIPMI_LIBS = @LIBIPMI_LIBS@ +LIBLTDL_CFLAGS = @LIBLTDL_CFLAGS@ +LIBLTDL_LIBS = @LIBLTDL_LIBS@ LIBNEON_CFLAGS = @LIBNEON_CFLAGS@ LIBNEON_LIBS = @LIBNEON_LIBS@ LIBNETSNMP_CFLAGS = @LIBNETSNMP_CFLAGS@ @@ -166,6 +170,7 @@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ NETLIBS = @NETLIBS@ NM = @NM@ @@ -197,12 +202,14 @@ SHELL = @SHELL@ STATEPATH = @STATEPATH@ STRIP = @STRIP@ SUN_LIBUSB = @SUN_LIBUSB@ +TREE_VERSION = @TREE_VERSION@ VERSION = @VERSION@ WORDS_BIGENDIAN = @WORDS_BIGENDIAN@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ @@ -238,7 +245,6 @@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ -lt_ECHO = @lt_ECHO@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ diff --git a/scripts/udev/nut-usbups.rules.in b/scripts/udev/nut-usbups.rules.in index 6537eec..2faf9a2 100644 --- a/scripts/udev/nut-usbups.rules.in +++ b/scripts/udev/nut-usbups.rules.in @@ -6,6 +6,8 @@ SUBSYSTEM=="usb", GOTO="nut-usbups_rules_real" SUBSYSTEM!="usb", GOTO="nut-usbups_rules_end" LABEL="nut-usbups_rules_real" +# Krauler UP-M500VA - blazer_usb +ATTR{idVendor}=="0001", ATTR{idProduct}=="0000", MODE="664", GROUP="@RUN_AS_GROUP@" # Hewlett Packard # T500 - bcmxcp_usb @@ -158,6 +160,8 @@ ATTR{idVendor}=="09ae", ATTR{idProduct}=="4007", MODE="664", GROUP="@RUN_AS_GROU ATTR{idVendor}=="09ae", ATTR{idProduct}=="4008", MODE="664", GROUP="@RUN_AS_GROUP@" # PowerCOM +# PowerCOM BNT-xxxAP - usbhid-ups +ATTR{idVendor}=="0d9f", ATTR{idProduct}=="0004", MODE="664", GROUP="@RUN_AS_GROUP@" # PowerCOM IMP - IMPERIAL Series - usbhid-ups ATTR{idVendor}=="0d9f", ATTR{idProduct}=="00a2", MODE="664", GROUP="@RUN_AS_GROUP@" # PowerCOM SKP - Smart KING Pro (all Smart series) - usbhid-ups @@ -176,5 +180,7 @@ ATTR{idVendor}=="0f03", ATTR{idProduct}=="0001", MODE="664", GROUP="@RUN_AS_GROU ATTR{idVendor}=="10af", ATTR{idProduct}=="0001", MODE="664", GROUP="@RUN_AS_GROUP@" # GE EP series - blazer_usb ATTR{idVendor}=="14f0", ATTR{idProduct}=="00c9", MODE="664", GROUP="@RUN_AS_GROUP@" +# Ablerex 625L USB - blazer_usb +ATTR{idVendor}=="ffff", ATTR{idProduct}=="0000", MODE="664", GROUP="@RUN_AS_GROUP@" LABEL="nut-usbups_rules_end" diff --git a/scripts/upower/95-upower-hid.rules b/scripts/upower/95-upower-hid.rules index 25c267d..dd9d899 100644 --- a/scripts/upower/95-upower-hid.rules +++ b/scripts/upower/95-upower-hid.rules @@ -102,6 +102,7 @@ ATTRS{idVendor}=="09ae", ATTRS{idProduct}=="4007", ENV{UPOWER_BATTERY_TYPE}="ups ATTRS{idVendor}=="09ae", ATTRS{idProduct}=="4008", ENV{UPOWER_BATTERY_TYPE}="ups" # PowerCOM +ATTRS{idVendor}=="0d9f", ATTRS{idProduct}=="0004", ENV{UPOWER_BATTERY_TYPE}="ups" ATTRS{idVendor}=="0d9f", ATTRS{idProduct}=="00a2", ENV{UPOWER_BATTERY_TYPE}="ups" ATTRS{idVendor}=="0d9f", ATTRS{idProduct}=="00a3", ENV{UPOWER_BATTERY_TYPE}="ups" ATTRS{idVendor}=="0d9f", ATTRS{idProduct}=="00a4", ENV{UPOWER_BATTERY_TYPE}="ups" diff --git a/server/Makefile.am b/server/Makefile.am index 1c9c789..5f2f679 100644 --- a/server/Makefile.am +++ b/server/Makefile.am @@ -23,7 +23,7 @@ EXTRA_PROGRAMS = sockdebug upsd_SOURCES = upsd.c user.c conf.c ssl.c sstate.c desc.c \ netget.c netmisc.c netlist.c netuser.c netset.c netinstcmd.c \ - conf.h ctype.h desc.h netcmds.h neterr.h netget.h netinstcmd.h \ + conf.h nut_ctype.h desc.h netcmds.h neterr.h netget.h netinstcmd.h \ netlist.h netmisc.h netset.h netuser.h ssl.h sstate.h stype.h upsd.h \ upstype.h user-data.h user.h diff --git a/server/Makefile.in b/server/Makefile.in index 994e64a..0c32dea 100644 --- a/server/Makefile.in +++ b/server/Makefile.in @@ -56,6 +56,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ax_compare_version.m4 \ $(top_srcdir)/m4/nut_check_libfreeipmi.m4 \ $(top_srcdir)/m4/nut_check_libgd.m4 \ $(top_srcdir)/m4/nut_check_libhal.m4 \ + $(top_srcdir)/m4/nut_check_libltdl.m4 \ $(top_srcdir)/m4/nut_check_libneon.m4 \ $(top_srcdir)/m4/nut_check_libnetsnmp.m4 \ $(top_srcdir)/m4/nut_check_libpowerman.m4 \ @@ -131,6 +132,7 @@ CYGPATH_W = @CYGPATH_W@ DBLATEX = @DBLATEX@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ DOC_BUILD_LIST = @DOC_BUILD_LIST@ DRIVER_BUILD_LIST = @DRIVER_BUILD_LIST@ DRIVER_INSTALL_TARGET = @DRIVER_INSTALL_TARGET@ @@ -163,6 +165,8 @@ LIBHAL_CFLAGS = @LIBHAL_CFLAGS@ LIBHAL_LIBS = @LIBHAL_LIBS@ LIBIPMI_CFLAGS = @LIBIPMI_CFLAGS@ LIBIPMI_LIBS = @LIBIPMI_LIBS@ +LIBLTDL_CFLAGS = @LIBLTDL_CFLAGS@ +LIBLTDL_LIBS = @LIBLTDL_LIBS@ LIBNEON_CFLAGS = @LIBNEON_CFLAGS@ LIBNEON_LIBS = @LIBNEON_LIBS@ LIBNETSNMP_CFLAGS = @LIBNETSNMP_CFLAGS@ @@ -183,6 +187,7 @@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ NETLIBS = @NETLIBS@ NM = @NM@ @@ -214,12 +219,14 @@ SHELL = @SHELL@ STATEPATH = @STATEPATH@ STRIP = @STRIP@ SUN_LIBUSB = @SUN_LIBUSB@ +TREE_VERSION = @TREE_VERSION@ VERSION = @VERSION@ WORDS_BIGENDIAN = @WORDS_BIGENDIAN@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ @@ -255,7 +262,6 @@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ -lt_ECHO = @lt_ECHO@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ @@ -288,7 +294,7 @@ LDADD = ../common/libcommon.la ../common/libparseconf.la $(NETLIBS) \ $(am__append_3) $(am__append_4) upsd_SOURCES = upsd.c user.c conf.c ssl.c sstate.c desc.c \ netget.c netmisc.c netlist.c netuser.c netset.c netinstcmd.c \ - conf.h ctype.h desc.h netcmds.h neterr.h netget.h netinstcmd.h \ + conf.h nut_ctype.h desc.h netcmds.h neterr.h netget.h netinstcmd.h \ netlist.h netmisc.h netset.h netuser.h ssl.h sstate.h stype.h upsd.h \ upstype.h user-data.h user.h diff --git a/server/netcmds.h b/server/netcmds.h index a001f70..30f5124 100644 --- a/server/netcmds.h +++ b/server/netcmds.h @@ -17,7 +17,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "ctype.h" +#include "nut_ctype.h" #include "ssl.h" #include "netget.h" @@ -31,7 +31,7 @@ struct { const char *name; - void (*func)(ctype_t *client, int numargs, const char **arg); + void (*func)(nut_ctype_t *client, int numargs, const char **arg); int flags; } netcmds[] = { { "VER", net_ver, 0 }, diff --git a/server/netget.c b/server/netget.c index a10a011..43e7370 100644 --- a/server/netget.c +++ b/server/netget.c @@ -27,7 +27,7 @@ #include "netget.h" -static void get_numlogins(ctype_t *client, const char *upsname) +static void get_numlogins(nut_ctype_t *client, const char *upsname) { const upstype_t *ups; @@ -44,7 +44,7 @@ static void get_numlogins(ctype_t *client, const char *upsname) sendback(client, "NUMLOGINS %s %d\n", upsname, ups->numlogins); } -static void get_upsdesc(ctype_t *client, const char *upsname) +static void get_upsdesc(nut_ctype_t *client, const char *upsname) { const upstype_t *ups; char esc[SMALLBUF]; @@ -69,7 +69,7 @@ static void get_upsdesc(ctype_t *client, const char *upsname) } } -static void get_desc(ctype_t *client, const char *upsname, const char *var) +static void get_desc(nut_ctype_t *client, const char *upsname, const char *var) { const upstype_t *ups; const char *desc; @@ -92,7 +92,7 @@ static void get_desc(ctype_t *client, const char *upsname, const char *var) sendback(client, "DESC %s %s \"Description unavailable\"\n", upsname, var); } -static void get_cmddesc(ctype_t *client, const char *upsname, const char *cmd) +static void get_cmddesc(nut_ctype_t *client, const char *upsname, const char *cmd) { const upstype_t *ups; const char *desc; @@ -116,7 +116,7 @@ static void get_cmddesc(ctype_t *client, const char *upsname, const char *cmd) upsname, cmd); } -static void get_type(ctype_t *client, const char *upsname, const char *var) +static void get_type(nut_ctype_t *client, const char *upsname, const char *var) { char buf[SMALLBUF]; const upstype_t *ups; @@ -159,7 +159,7 @@ static void get_type(ctype_t *client, const char *upsname, const char *var) sendback(client, "TYPE %s %s UNKNOWN\n", upsname, var); } -static void get_var_server(ctype_t *client, const char *upsname, const char *var) +static void get_var_server(nut_ctype_t *client, const char *upsname, const char *var) { if (!strcasecmp(var, "server.info")) { sendback(client, "VAR %s server.info " @@ -178,7 +178,7 @@ static void get_var_server(ctype_t *client, const char *upsname, const char *var send_err(client, NUT_ERR_VAR_NOT_SUPPORTED); } -static void get_var(ctype_t *client, const char *upsname, const char *var) +static void get_var(nut_ctype_t *client, const char *upsname, const char *var) { const upstype_t *ups; const char *val; @@ -213,7 +213,7 @@ static void get_var(ctype_t *client, const char *upsname, const char *var) sendback(client, "VAR %s %s \"%s\"\n", upsname, var, val); } -void net_get(ctype_t *client, int numarg, const char **arg) +void net_get(nut_ctype_t *client, int numarg, const char **arg) { if (numarg < 2) { send_err(client, NUT_ERR_INVALID_ARGUMENT); diff --git a/server/netget.h b/server/netget.h index 0bc8759..f1209d2 100644 --- a/server/netget.h +++ b/server/netget.h @@ -1 +1 @@ -void net_get(ctype_t *client, int numarg, const char **arg); +void net_get(nut_ctype_t *client, int numarg, const char **arg); diff --git a/server/netinstcmd.c b/server/netinstcmd.c index 7411e2b..c21d7ec 100644 --- a/server/netinstcmd.c +++ b/server/netinstcmd.c @@ -28,7 +28,7 @@ #include "netinstcmd.h" -static void send_instcmd(ctype_t *client, const char *upsname, +static void send_instcmd(nut_ctype_t *client, const char *upsname, const char *cmdname, const char *value) { int found; @@ -95,7 +95,7 @@ static void send_instcmd(ctype_t *client, const char *upsname, sendback(client, "OK\n"); } -void net_instcmd(ctype_t *client, int numarg, const char **arg) +void net_instcmd(nut_ctype_t *client, int numarg, const char **arg) { if (numarg < 2) { send_err(client, NUT_ERR_INVALID_ARGUMENT); diff --git a/server/netinstcmd.h b/server/netinstcmd.h index 58dc155..1015931 100644 --- a/server/netinstcmd.h +++ b/server/netinstcmd.h @@ -1 +1 @@ -void net_instcmd(ctype_t *client, int numarg, const char **arg); +void net_instcmd(nut_ctype_t *client, int numarg, const char **arg); diff --git a/server/netlist.c b/server/netlist.c index 104026c..ea6ee4c 100644 --- a/server/netlist.c +++ b/server/netlist.c @@ -28,7 +28,7 @@ extern upstype_t *firstups; /* for list_ups */ -static int tree_dump(st_tree_t *node, ctype_t *client, const char *ups, +static int tree_dump(st_tree_t *node, nut_ctype_t *client, const char *ups, int rw, int fsd) { int ret; @@ -78,7 +78,7 @@ static int tree_dump(st_tree_t *node, ctype_t *client, const char *ups, return 1; } -static void list_rw(ctype_t *client, const char *upsname) +static void list_rw(nut_ctype_t *client, const char *upsname) { const upstype_t *ups; @@ -101,7 +101,7 @@ static void list_rw(ctype_t *client, const char *upsname) sendback(client, "END LIST RW %s\n", upsname); } -static void list_var(ctype_t *client, const char *upsname) +static void list_var(nut_ctype_t *client, const char *upsname) { const upstype_t *ups; @@ -124,7 +124,7 @@ static void list_var(ctype_t *client, const char *upsname) sendback(client, "END LIST VAR %s\n", upsname); } -static void list_cmd(ctype_t *client, const char *upsname) +static void list_cmd(nut_ctype_t *client, const char *upsname) { const upstype_t *ups; cmdlist_t *ctmp; @@ -150,7 +150,7 @@ static void list_cmd(ctype_t *client, const char *upsname) sendback(client, "END LIST CMD %s\n", upsname); } -static void list_enum(ctype_t *client, const char *upsname, const char *var) +static void list_enum(nut_ctype_t *client, const char *upsname, const char *var) { const upstype_t *ups; const st_tree_t *node; @@ -185,7 +185,7 @@ static void list_enum(ctype_t *client, const char *upsname, const char *var) sendback(client, "END LIST ENUM %s %s\n", upsname, var); } -static void list_ups(ctype_t *client) +static void list_ups(nut_ctype_t *client) { upstype_t *utmp; char esc[SMALLBUF]; @@ -217,7 +217,7 @@ static void list_ups(ctype_t *client) sendback(client, "END LIST UPS\n"); } -void net_list(ctype_t *client, int numarg, const char **arg) +void net_list(nut_ctype_t *client, int numarg, const char **arg) { if (numarg < 1) { send_err(client, NUT_ERR_INVALID_ARGUMENT); diff --git a/server/netlist.h b/server/netlist.h index 445627e..d3b7776 100644 --- a/server/netlist.h +++ b/server/netlist.h @@ -1 +1 @@ -void net_list(ctype_t *client, int numarg, const char **arg); +void net_list(nut_ctype_t *client, int numarg, const char **arg); diff --git a/server/netmisc.c b/server/netmisc.c index 3273514..cbfb1ca 100644 --- a/server/netmisc.c +++ b/server/netmisc.c @@ -27,7 +27,7 @@ #include "netmisc.h" -void net_ver(ctype_t *client, int numarg, const char **arg) +void net_ver(nut_ctype_t *client, int numarg, const char **arg) { if (numarg != 0) { send_err(client, NUT_ERR_INVALID_ARGUMENT); @@ -38,7 +38,7 @@ void net_ver(ctype_t *client, int numarg, const char **arg) UPS_VERSION); } -void net_help(ctype_t *client, int numarg, const char **arg) +void net_help(nut_ctype_t *client, int numarg, const char **arg) { if (numarg != 0) { send_err(client, NUT_ERR_INVALID_ARGUMENT); @@ -49,7 +49,7 @@ void net_help(ctype_t *client, int numarg, const char **arg) " USERNAME PASSWORD STARTTLS\n"); } -void net_fsd(ctype_t *client, int numarg, const char **arg) +void net_fsd(nut_ctype_t *client, int numarg, const char **arg) { upstype_t *ups; diff --git a/server/netmisc.h b/server/netmisc.h index 19e7254..e1899df 100644 --- a/server/netmisc.h +++ b/server/netmisc.h @@ -1,3 +1,3 @@ -void net_ver(ctype_t *client, int numarg, const char **arg); -void net_help(ctype_t *client, int numarg, const char **arg); -void net_fsd(ctype_t *client, int numarg, const char **arg); +void net_ver(nut_ctype_t *client, int numarg, const char **arg); +void net_help(nut_ctype_t *client, int numarg, const char **arg); +void net_fsd(nut_ctype_t *client, int numarg, const char **arg); diff --git a/server/netset.c b/server/netset.c index ae5a681..145bd2f 100644 --- a/server/netset.c +++ b/server/netset.c @@ -27,7 +27,7 @@ #include "netset.h" -static void set_var(ctype_t *client, const char *upsname, const char *var, +static void set_var(nut_ctype_t *client, const char *upsname, const char *var, const char *newval) { upstype_t *ups; @@ -125,7 +125,7 @@ static void set_var(ctype_t *client, const char *upsname, const char *var, sendback(client, "OK\n"); } -void net_set(ctype_t *client, int numarg, const char **arg) +void net_set(nut_ctype_t *client, int numarg, const char **arg) { if (numarg < 4) { send_err(client, NUT_ERR_INVALID_ARGUMENT); diff --git a/server/netset.h b/server/netset.h index 0061962..81068dd 100644 --- a/server/netset.h +++ b/server/netset.h @@ -1 +1 @@ -void net_set(ctype_t *client, int numarg, const char **arg); +void net_set(nut_ctype_t *client, int numarg, const char **arg); diff --git a/server/netuser.c b/server/netuser.c index 5c1b399..29c8596 100644 --- a/server/netuser.c +++ b/server/netuser.c @@ -28,7 +28,7 @@ #include "netuser.h" /* LOGIN */ -void net_login(ctype_t *client, int numarg, const char **arg) +void net_login(nut_ctype_t *client, int numarg, const char **arg) { upstype_t *ups; @@ -65,7 +65,7 @@ void net_login(ctype_t *client, int numarg, const char **arg) sendback(client, "OK\n"); } -void net_logout(ctype_t *client, int numarg, const char **arg) +void net_logout(nut_ctype_t *client, int numarg, const char **arg) { if (numarg != 0) { send_err(client, NUT_ERR_INVALID_ARGUMENT); @@ -83,7 +83,7 @@ void net_logout(ctype_t *client, int numarg, const char **arg) } /* MASTER */ -void net_master(ctype_t *client, int numarg, const char **arg) +void net_master(nut_ctype_t *client, int numarg, const char **arg) { upstype_t *ups; @@ -110,7 +110,7 @@ void net_master(ctype_t *client, int numarg, const char **arg) } /* USERNAME */ -void net_username(ctype_t *client, int numarg, const char **arg) +void net_username(nut_ctype_t *client, int numarg, const char **arg) { if (numarg != 1) { send_err(client, NUT_ERR_INVALID_ARGUMENT); @@ -130,7 +130,7 @@ void net_username(ctype_t *client, int numarg, const char **arg) } /* PASSWORD */ -void net_password(ctype_t *client, int numarg, const char **arg) +void net_password(nut_ctype_t *client, int numarg, const char **arg) { if (numarg != 1) { send_err(client, NUT_ERR_INVALID_ARGUMENT); diff --git a/server/netuser.h b/server/netuser.h index e31fb0d..5f7e047 100644 --- a/server/netuser.h +++ b/server/netuser.h @@ -1,5 +1,5 @@ -void net_login(ctype_t *client, int numarg, const char **arg); -void net_logout(ctype_t *client, int numarg, const char **arg); -void net_master(ctype_t *client, int numarg, const char **arg); -void net_username(ctype_t *client, int numarg, const char **arg); -void net_password(ctype_t *client, int numarg, const char **arg); +void net_login(nut_ctype_t *client, int numarg, const char **arg); +void net_logout(nut_ctype_t *client, int numarg, const char **arg); +void net_master(nut_ctype_t *client, int numarg, const char **arg); +void net_username(nut_ctype_t *client, int numarg, const char **arg); +void net_password(nut_ctype_t *client, int numarg, const char **arg); diff --git a/server/ctype.h b/server/nut_ctype.h similarity index 80% rename from server/ctype.h rename to server/nut_ctype.h index dac0980..498298c 100644 --- a/server/ctype.h +++ b/server/nut_ctype.h @@ -1,8 +1,9 @@ -/* ctype.h - client data definitions for upsd +/* nut_ctype.h - client data definitions for upsd Copyright (C) 2002 Russell Kroll 2008 Arjen de Korte + 2011 Arnaud Quette This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,8 +20,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef CTYPE_H_SEEN -#define CTYPE_H_SEEN 1 +#ifndef NUT_CTYPE_H_SEEN +#define NUT_CTYPE_H_SEEN 1 #ifdef HAVE_SSL #include @@ -30,7 +31,7 @@ #include "parseconf.h" /* client structure */ -typedef struct ctype_s { +typedef struct nut_ctype_s { char *addr; int sock_fd; time_t last_heard; @@ -48,8 +49,8 @@ typedef struct ctype_s { PCONF_CTX_t ctx; /* doubly linked list */ - struct ctype_s *prev; - struct ctype_s *next; -} ctype_t; + struct nut_ctype_s *prev; + struct nut_ctype_s *next; +} nut_ctype_t; -#endif /* CTYPE_H_SEEN */ +#endif /* NUT_CTYPE_H_SEEN */ diff --git a/server/ssl.c b/server/ssl.c index 21614d9..bb95dca 100644 --- a/server/ssl.c +++ b/server/ssl.c @@ -38,19 +38,19 @@ static int ssl_initialized = 0; #ifndef HAVE_SSL /* stubs for non-ssl compiles */ -void net_starttls(ctype_t *client, int numarg, const char **arg) +void net_starttls(nut_ctype_t *client, int numarg, const char **arg) { send_err(client, NUT_ERR_FEATURE_NOT_SUPPORTED); return; } -int ssl_write(ctype_t *client, const char *buf, size_t buflen) +int ssl_write(nut_ctype_t *client, const char *buf, size_t buflen) { upslogx(LOG_ERR, "ssl_write called but SSL wasn't compiled in"); return -1; } -int ssl_read(ctype_t *client, char *buf, size_t buflen) +int ssl_read(nut_ctype_t *client, char *buf, size_t buflen) { upslogx(LOG_ERR, "ssl_read called but SSL wasn't compiled in"); return -1; @@ -61,7 +61,7 @@ void ssl_init(void) ssl_initialized = 0; /* keep gcc quiet */ } -void ssl_finish(ctype_t *client) +void ssl_finish(nut_ctype_t *client) { if (client->ssl) { upslogx(LOG_ERR, "ssl_finish found active SSL connection but SSL wasn't compiled in"); @@ -83,7 +83,7 @@ static void ssl_debug(void) } } -void net_starttls(ctype_t *client, int numarg, const char **arg) +void net_starttls(nut_ctype_t *client, int numarg, const char **arg) { if (client->ssl) { send_err(client, NUT_ERR_ALREADY_SSL_MODE); @@ -196,7 +196,7 @@ static int ssl_error(SSL *ssl, int ret) return -1; } -static int ssl_accept(ctype_t *client) +static int ssl_accept(nut_ctype_t *client) { int ret; @@ -218,7 +218,7 @@ static int ssl_accept(ctype_t *client) return -1; } -int ssl_read(ctype_t *client, char *buf, size_t buflen) +int ssl_read(nut_ctype_t *client, char *buf, size_t buflen) { int ret; @@ -237,7 +237,7 @@ int ssl_read(ctype_t *client, char *buf, size_t buflen) return ret; } -int ssl_write(ctype_t *client, const char *buf, size_t buflen) +int ssl_write(nut_ctype_t *client, const char *buf, size_t buflen) { int ret; @@ -248,7 +248,7 @@ int ssl_write(ctype_t *client, const char *buf, size_t buflen) return ret; } -void ssl_finish(ctype_t *client) +void ssl_finish(nut_ctype_t *client) { if (client->ssl) { SSL_free(client->ssl); diff --git a/server/ssl.h b/server/ssl.h index eb9826c..7f4009c 100644 --- a/server/ssl.h +++ b/server/ssl.h @@ -25,16 +25,16 @@ #include #endif -#include "ctype.h" +#include "nut_ctype.h" extern char *certfile; void ssl_init(void); -void ssl_finish(ctype_t *client); +void ssl_finish(nut_ctype_t *client); -int ssl_read(ctype_t *client, char *buf, size_t buflen); -int ssl_write(ctype_t *client, const char *buf, size_t buflen); +int ssl_read(nut_ctype_t *client, char *buf, size_t buflen); +int ssl_write(nut_ctype_t *client, const char *buf, size_t buflen); -void net_starttls(ctype_t *client, int numarg, const char **arg); +void net_starttls(nut_ctype_t *client, int numarg, const char **arg); #endif /* SSL_H_SEEN */ diff --git a/server/upsd.c b/server/upsd.c index 662284e..db200aa 100644 --- a/server/upsd.c +++ b/server/upsd.c @@ -3,6 +3,7 @@ Copyright (C) 1999 Russell Kroll 2008 Arjen de Korte + 2011 Arnaud Quette This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -32,7 +33,7 @@ #include #include "user.h" -#include "ctype.h" +#include "nut_ctype.h" #include "stype.h" #include "ssl.h" #include "sstate.h" @@ -64,8 +65,8 @@ int deny_severity = LOG_WARNING; /* everything else */ const char *progname; -static ctype_t *firstclient = NULL; -/* static ctype_t *lastclient = NULL; */ +static nut_ctype_t *firstclient = NULL; +/* static nut_ctype_t *lastclient = NULL; */ /* default is to listen on all local interfaces */ static stype_t *firstaddr = NULL; @@ -234,9 +235,10 @@ static void setuptcp(stype_t *server) freeaddrinfo(res); - /* don't fail silently */ + /* leave up to the caller, server_load(), to fail silently if there is + * no other valid LISTEN interface */ if (server->sock_fd < 0) { - fatalx(EXIT_FAILURE, "not listening on %s port %s", server->addr, server->port); + upslogx(LOG_ERR, "not listening on %s port %s", server->addr, server->port); } else { upslogx(LOG_INFO, "listening on %s port %s", server->addr, server->port); } @@ -264,7 +266,7 @@ static void declogins(const char *upsname) } /* disconnect a client connection and free all related memory */ -static void client_disconnect(ctype_t *client) +static void client_disconnect(nut_ctype_t *client) { if (!client) { return; @@ -307,7 +309,7 @@ static void client_disconnect(ctype_t *client) } /* send the buffer of length to host */ -int sendback(ctype_t *client, const char *fmt, ...) +int sendback(nut_ctype_t *client, const char *fmt, ...) { int res, len; char ans[NUT_NET_ANSWER_MAX+1]; @@ -341,7 +343,7 @@ int sendback(ctype_t *client, const char *fmt, ...) } /* just a simple wrapper for now */ -int send_err(ctype_t *client, const char *errtype) +int send_err(nut_ctype_t *client, const char *errtype) { if (!client) { return -1; @@ -355,7 +357,7 @@ int send_err(ctype_t *client, const char *errtype) /* disconnect anyone logged into this UPS */ void kick_login_clients(const char *upsname) { - ctype_t *client, *cnext; + nut_ctype_t *client, *cnext; for (client = firstclient; client; client = cnext) { @@ -374,7 +376,7 @@ void kick_login_clients(const char *upsname) } /* make sure a UPS is sane - connected, with fresh data */ -int ups_available(const upstype_t *ups, ctype_t *client) +int ups_available(const upstype_t *ups, nut_ctype_t *client) { if (ups->sock_fd < 0) { send_err(client, NUT_ERR_DRIVER_NOT_CONNECTED); @@ -391,7 +393,7 @@ int ups_available(const upstype_t *ups, ctype_t *client) } /* check flags and access for an incoming command from the network */ -static void check_command(int cmdnum, ctype_t *client, int numarg, +static void check_command(int cmdnum, nut_ctype_t *client, int numarg, const char **arg) { if (netcmds[cmdnum].flags & FLAG_USER) { @@ -426,7 +428,7 @@ static void check_command(int cmdnum, ctype_t *client, int numarg, } /* parse requests from the network */ -static void parse_net(ctype_t *client) +static void parse_net(nut_ctype_t *client) { int i; @@ -458,7 +460,7 @@ static void client_connect(stype_t *server) socklen_t clen; #endif int fd; - ctype_t *client; + nut_ctype_t *client; clen = sizeof(csock); fd = accept(server->sock_fd, (struct sockaddr *) &csock, &clen); @@ -496,7 +498,7 @@ static void client_connect(stype_t *server) } /* read tcp messages and handle them */ -static void client_readline(ctype_t *client) +static void client_readline(nut_ctype_t *client) { char buf[SMALLBUF]; int i, ret; @@ -561,6 +563,11 @@ void server_load(void) for (server = firstaddr; server; server = server->next) { setuptcp(server); } + + /* check if we have at least 1 valid LISTEN interface */ + if (firstaddr->sock_fd < 0) { + fatalx(EXIT_FAILURE, "no listening interface available"); + } } void server_free(void) @@ -585,7 +592,7 @@ void server_free(void) static void client_free(void) { - ctype_t *client, *cnext; + nut_ctype_t *client, *cnext; /* cleanup client fds */ for (client = firstclient; client; client = cnext) { @@ -663,7 +670,7 @@ static void mainloop(void) int i, ret, nfds = 0; upstype_t *ups; - ctype_t *client, *cnext; + nut_ctype_t *client, *cnext; stype_t *server; time_t now; @@ -765,7 +772,7 @@ static void mainloop(void) sstate_disconnect((upstype_t *)handler[i].data); break; case CLIENT: - client_disconnect((ctype_t *)handler[i].data); + client_disconnect((nut_ctype_t *)handler[i].data); break; case SERVER: upsdebugx(2, "%s: server disconnected", __func__); @@ -786,7 +793,7 @@ static void mainloop(void) sstate_readline((upstype_t *)handler[i].data); break; case CLIENT: - client_readline((ctype_t *)handler[i].data); + client_readline((nut_ctype_t *)handler[i].data); break; case SERVER: client_connect((stype_t *)handler[i].data); diff --git a/server/upsd.h b/server/upsd.h index c43fd67..85985fe 100644 --- a/server/upsd.h +++ b/server/upsd.h @@ -40,7 +40,7 @@ #include #include "parseconf.h" -#include "ctype.h" +#include "nut_ctype.h" #include "upstype.h" #define NUT_NET_ANSWER_MAX SMALLBUF @@ -48,14 +48,14 @@ /* prototypes from upsd.c */ upstype_t *get_ups_ptr(const char *upsname); -int ups_available(const upstype_t *ups, ctype_t *client); +int ups_available(const upstype_t *ups, nut_ctype_t *client); void listen_add(const char *addr, const char *port); void kick_login_clients(const char *upsname); -int sendback(ctype_t *client, const char *fmt, ...) +int sendback(nut_ctype_t *client, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3))); -int send_err(ctype_t *client, const char *errtype); +int send_err(nut_ctype_t *client, const char *errtype); void server_load(void); void server_free(void); diff --git a/tools/Makefile.am b/tools/Makefile.am index fbe4e34..0d9828b 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -1,3 +1,4 @@ +# TODO: remove redundancies! # Force build in ./ before nut-scanner, to have nutscan-{usb,snmp}.h # built before going into the nut-scanner sub-directory @@ -29,12 +30,13 @@ nut-scanner-deps: fi website: - @if python -c pass; then \ + @if python -c "import json,simplejson,lxml"; then \ echo "Regenerating the HTML and JSON formated HCL tables."; \ $(top_srcdir)/tools/nut-hclinfo.py; \ else \ echo "----------------------------------------------------------------------"; \ - echo "Warning: Python is not available."; \ + echo "Warning: either Python, or a required module (json, simplejson, lxml) "; \ + echo "is not available."; \ echo "Skipping the HTML and JSON formated HCL tables regeneration."; \ echo "----------------------------------------------------------------------"; \ fi @@ -42,6 +44,7 @@ website: # call the USB info script upon "make dist", and if Perl is present # call the SNMP info script upon "make dist", and if Python is present # and call both for building nut-scanner +# also generate HCL data files dist-hook: @if python -c 1; then \ echo "Regenerating the SNMP helper files."; \ @@ -63,4 +66,15 @@ dist-hook: echo "----------------------------------------------------------------------"; \ fi + @if python -c "import json,simplejson,lxml"; then \ + echo "Regenerating the HTML and JSON formated HCL tables."; \ + $(distdir)/nut-hclinfo.py; \ + else \ + echo "----------------------------------------------------------------------"; \ + echo "Warning: either Python, or a required module (json, simplejson, lxml) "; \ + echo "is not available."; \ + echo "Skipping the HTML and JSON formated HCL tables regeneration."; \ + echo "----------------------------------------------------------------------"; \ + fi + .PHONY: nut-scanner-deps nut-scanner-snmp-deps nut-scanner-usb-deps diff --git a/tools/Makefile.in b/tools/Makefile.in index 404d40b..66f35e8 100644 --- a/tools/Makefile.in +++ b/tools/Makefile.in @@ -14,6 +14,8 @@ # PARTICULAR PURPOSE. @SET_MAKE@ + +# TODO: remove redundancies! VPATH = @srcdir@ pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ @@ -47,6 +49,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ax_compare_version.m4 \ $(top_srcdir)/m4/nut_check_libfreeipmi.m4 \ $(top_srcdir)/m4/nut_check_libgd.m4 \ $(top_srcdir)/m4/nut_check_libhal.m4 \ + $(top_srcdir)/m4/nut_check_libltdl.m4 \ $(top_srcdir)/m4/nut_check_libneon.m4 \ $(top_srcdir)/m4/nut_check_libnetsnmp.m4 \ $(top_srcdir)/m4/nut_check_libpowerman.m4 \ @@ -127,6 +130,7 @@ CYGPATH_W = @CYGPATH_W@ DBLATEX = @DBLATEX@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ DOC_BUILD_LIST = @DOC_BUILD_LIST@ DRIVER_BUILD_LIST = @DRIVER_BUILD_LIST@ DRIVER_INSTALL_TARGET = @DRIVER_INSTALL_TARGET@ @@ -159,6 +163,8 @@ LIBHAL_CFLAGS = @LIBHAL_CFLAGS@ LIBHAL_LIBS = @LIBHAL_LIBS@ LIBIPMI_CFLAGS = @LIBIPMI_CFLAGS@ LIBIPMI_LIBS = @LIBIPMI_LIBS@ +LIBLTDL_CFLAGS = @LIBLTDL_CFLAGS@ +LIBLTDL_LIBS = @LIBLTDL_LIBS@ LIBNEON_CFLAGS = @LIBNEON_CFLAGS@ LIBNEON_LIBS = @LIBNEON_LIBS@ LIBNETSNMP_CFLAGS = @LIBNETSNMP_CFLAGS@ @@ -179,6 +185,7 @@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ NETLIBS = @NETLIBS@ NM = @NM@ @@ -210,12 +217,14 @@ SHELL = @SHELL@ STATEPATH = @STATEPATH@ STRIP = @STRIP@ SUN_LIBUSB = @SUN_LIBUSB@ +TREE_VERSION = @TREE_VERSION@ VERSION = @VERSION@ WORDS_BIGENDIAN = @WORDS_BIGENDIAN@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ @@ -251,7 +260,6 @@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ -lt_ECHO = @lt_ECHO@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ @@ -654,12 +662,13 @@ nut-scanner-deps: fi website: - @if python -c pass; then \ + @if python -c "import json,simplejson,lxml"; then \ echo "Regenerating the HTML and JSON formated HCL tables."; \ $(top_srcdir)/tools/nut-hclinfo.py; \ else \ echo "----------------------------------------------------------------------"; \ - echo "Warning: Python is not available."; \ + echo "Warning: either Python, or a required module (json, simplejson, lxml) "; \ + echo "is not available."; \ echo "Skipping the HTML and JSON formated HCL tables regeneration."; \ echo "----------------------------------------------------------------------"; \ fi @@ -667,6 +676,7 @@ website: # call the USB info script upon "make dist", and if Perl is present # call the SNMP info script upon "make dist", and if Python is present # and call both for building nut-scanner +# also generate HCL data files dist-hook: @if python -c 1; then \ echo "Regenerating the SNMP helper files."; \ @@ -688,6 +698,17 @@ dist-hook: echo "----------------------------------------------------------------------"; \ fi + @if python -c "import json,simplejson,lxml"; then \ + echo "Regenerating the HTML and JSON formated HCL tables."; \ + $(distdir)/nut-hclinfo.py; \ + else \ + echo "----------------------------------------------------------------------"; \ + echo "Warning: either Python, or a required module (json, simplejson, lxml) "; \ + echo "is not available."; \ + echo "Skipping the HTML and JSON formated HCL tables regeneration."; \ + echo "----------------------------------------------------------------------"; \ + fi + .PHONY: nut-scanner-deps nut-scanner-snmp-deps nut-scanner-usb-deps # Tell versions [3.59,3.63) of GNU make to not export all variables. diff --git a/tools/nut-hclinfo.py b/tools/nut-hclinfo.py index 925873f..8a7aa4e 100755 --- a/tools/nut-hclinfo.py +++ b/tools/nut-hclinfo.py @@ -29,6 +29,7 @@ except ImportError: import re import sys +import os, errno # HCL file location and name rawHCL="../data/driver.list"; @@ -238,13 +239,21 @@ def buildHTMLTable(deviceData): table.append(tbody) - return etree.tostring(table, pretty_print=True) - + +# main program deviceData = buildData(rawHCL) # Dump device data as JSON jsonData = "var UPSData = %s" % json.dumps(deviceData, encoding="utf-8") + +# First, check if target directory exists (which is not the case for 'dist') +dir = os.path.dirname(webJsonHCL) +try: + os.makedirs(dir) +except OSError: + pass + try: file = open(webJsonHCL, "w") file.write(jsonData) diff --git a/tools/nut-scanner/Makefile.am b/tools/nut-scanner/Makefile.am index 005ba0c..0656e49 100644 --- a/tools/nut-scanner/Makefile.am +++ b/tools/nut-scanner/Makefile.am @@ -3,14 +3,18 @@ BUILT_SOURCES = nutscan-usb.h nutscan-snmp.h nutscan-usb.h nutscan-snmp.h: cd ..; $(MAKE) $(AM_MAKEFLAGS) nut-scanner-deps -lib_LTLIBRARIES = libnutscan.la +# Only build nut-scanner, and its library, if libltdl was found (required!) +if WITH_LIBLTDL + bin_PROGRAMS = nut-scanner + lib_LTLIBRARIES = libnutscan.la +endif libnutscan_la_SOURCES = scan_nut.c scan_ipmi.c \ - nutscan-device.c nutscan-ip.c nutscan-display.c -libnutscan_la_LIBADD = ../../clients/libupsclient.la $(NETLIBS) + nutscan-device.c nutscan-ip.c nutscan-display.c nutscan-init.c \ + scan_usb.c scan_snmp.c scan_xml_http.c scan_avahi.c +libnutscan_la_LIBADD = ../../clients/libupsclient.la $(NETLIBS) $(LIBLTDL_LIBS) libnutscan_la_LDFLAGS = -version-info 1:0:0 -libnutscan_la_CFLAGS = -I$(top_srcdir)/clients -I$(top_srcdir)/include +libnutscan_la_CFLAGS = -I$(top_srcdir)/clients -I$(top_srcdir)/include $(LIBLTDL_CFLAGS) -bin_PROGRAMS = nut-scanner nut_scanner_SOURCES = nut-scanner.c nut_scanner_CFLAGS = -I$(top_srcdir)/clients -I$(top_srcdir)/include nut_scanner_LDADD = libnutscan.la @@ -20,27 +24,28 @@ if WITH_SSL libnutscan_la_LIBADD += $(LIBSSL_LIBS) endif if WITH_USB - libnutscan_la_SOURCES += scan_usb.c libnutscan_la_CFLAGS += $(LIBUSB_CFLAGS) - libnutscan_la_LIBADD += $(LIBUSB_LIBS) endif if WITH_SNMP - libnutscan_la_SOURCES += scan_snmp.c libnutscan_la_CFLAGS += $(LIBNETSNMP_CFLAGS) - libnutscan_la_LIBADD += $(LIBNETSNMP_LIBS) endif -if WITH_NEONXML - libnutscan_la_SOURCES += scan_xml_http.c +if WITH_NEON libnutscan_la_CFLAGS += $(LIBNEON_CFLAGS) - libnutscan_la_LIBADD += $(LIBNEON_LIBS) endif if WITH_AVAHI - libnutscan_la_SOURCES += scan_avahi.c libnutscan_la_CFLAGS += $(LIBAVAHI_CFLAGS) - libnutscan_la_LIBADD += $(LIBAVAHI_LIBS) +endif +if WITH_IPMI + libnutscan_la_CFLAGS += $(LIBIPMI_CFLAGS) endif -dist_noinst_HEADERS = nut-scan.h nutscan-usb.h nutscan-snmp.h nutscan-device.h nutscan-ip.h +dist_noinst_HEADERS = nutscan-usb.h nutscan-snmp.h + +if WITH_DEV + include_HEADERS = nut-scan.h nutscan-device.h nutscan-ip.h nutscan-init.h +else + dist_noinst_HEADERS += nut-scan.h nutscan-device.h nutscan-ip.h nutscan-init.h +endif CLEANFILES = nutscan-usb.h nutscan-snmp.h diff --git a/tools/nut-scanner/Makefile.in b/tools/nut-scanner/Makefile.in index a489329..cf53410 100644 --- a/tools/nut-scanner/Makefile.in +++ b/tools/nut-scanner/Makefile.in @@ -37,23 +37,18 @@ POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ target_triplet = @target@ -bin_PROGRAMS = nut-scanner$(EXEEXT) +@WITH_LIBLTDL_TRUE@bin_PROGRAMS = nut-scanner$(EXEEXT) @WITH_SSL_TRUE@am__append_1 = $(LIBSSL_CFLAGS) @WITH_SSL_TRUE@am__append_2 = $(LIBSSL_LIBS) -@WITH_USB_TRUE@am__append_3 = scan_usb.c -@WITH_USB_TRUE@am__append_4 = $(LIBUSB_CFLAGS) -@WITH_USB_TRUE@am__append_5 = $(LIBUSB_LIBS) -@WITH_SNMP_TRUE@am__append_6 = scan_snmp.c -@WITH_SNMP_TRUE@am__append_7 = $(LIBNETSNMP_CFLAGS) -@WITH_SNMP_TRUE@am__append_8 = $(LIBNETSNMP_LIBS) -@WITH_NEONXML_TRUE@am__append_9 = scan_xml_http.c -@WITH_NEONXML_TRUE@am__append_10 = $(LIBNEON_CFLAGS) -@WITH_NEONXML_TRUE@am__append_11 = $(LIBNEON_LIBS) -@WITH_AVAHI_TRUE@am__append_12 = scan_avahi.c -@WITH_AVAHI_TRUE@am__append_13 = $(LIBAVAHI_CFLAGS) -@WITH_AVAHI_TRUE@am__append_14 = $(LIBAVAHI_LIBS) +@WITH_USB_TRUE@am__append_3 = $(LIBUSB_CFLAGS) +@WITH_SNMP_TRUE@am__append_4 = $(LIBNETSNMP_CFLAGS) +@WITH_NEON_TRUE@am__append_5 = $(LIBNEON_CFLAGS) +@WITH_AVAHI_TRUE@am__append_6 = $(LIBAVAHI_CFLAGS) +@WITH_IPMI_TRUE@am__append_7 = $(LIBIPMI_CFLAGS) +@WITH_DEV_FALSE@am__append_8 = nut-scan.h nutscan-device.h nutscan-ip.h nutscan-init.h subdir = tools/nut-scanner -DIST_COMMON = $(dist_noinst_HEADERS) $(srcdir)/Makefile.am \ +DIST_COMMON = README $(am__dist_noinst_HEADERS_DIST) \ + $(am__include_HEADERS_DIST) $(srcdir)/Makefile.am \ $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/ax_compare_version.m4 \ @@ -66,6 +61,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ax_compare_version.m4 \ $(top_srcdir)/m4/nut_check_libfreeipmi.m4 \ $(top_srcdir)/m4/nut_check_libgd.m4 \ $(top_srcdir)/m4/nut_check_libhal.m4 \ + $(top_srcdir)/m4/nut_check_libltdl.m4 \ $(top_srcdir)/m4/nut_check_libneon.m4 \ $(top_srcdir)/m4/nut_check_libnetsnmp.m4 \ $(top_srcdir)/m4/nut_check_libpowerman.m4 \ @@ -104,34 +100,25 @@ am__nobase_list = $(am__nobase_strip_setup); \ am__base_list = \ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' -am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" +am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" \ + "$(DESTDIR)$(includedir)" LTLIBRARIES = $(lib_LTLIBRARIES) am__DEPENDENCIES_1 = @WITH_SSL_TRUE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1) -@WITH_USB_TRUE@am__DEPENDENCIES_3 = $(am__DEPENDENCIES_1) -@WITH_SNMP_TRUE@am__DEPENDENCIES_4 = $(am__DEPENDENCIES_1) -@WITH_NEONXML_TRUE@am__DEPENDENCIES_5 = $(am__DEPENDENCIES_1) -@WITH_AVAHI_TRUE@am__DEPENDENCIES_6 = $(am__DEPENDENCIES_1) libnutscan_la_DEPENDENCIES = ../../clients/libupsclient.la \ - $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \ - $(am__DEPENDENCIES_3) $(am__DEPENDENCIES_4) \ - $(am__DEPENDENCIES_5) $(am__DEPENDENCIES_6) -am__libnutscan_la_SOURCES_DIST = scan_nut.c scan_ipmi.c \ - nutscan-device.c nutscan-ip.c nutscan-display.c scan_usb.c \ - scan_snmp.c scan_xml_http.c scan_avahi.c -@WITH_USB_TRUE@am__objects_1 = libnutscan_la-scan_usb.lo -@WITH_SNMP_TRUE@am__objects_2 = libnutscan_la-scan_snmp.lo -@WITH_NEONXML_TRUE@am__objects_3 = libnutscan_la-scan_xml_http.lo -@WITH_AVAHI_TRUE@am__objects_4 = libnutscan_la-scan_avahi.lo + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_2) am_libnutscan_la_OBJECTS = libnutscan_la-scan_nut.lo \ libnutscan_la-scan_ipmi.lo libnutscan_la-nutscan-device.lo \ libnutscan_la-nutscan-ip.lo libnutscan_la-nutscan-display.lo \ - $(am__objects_1) $(am__objects_2) $(am__objects_3) \ - $(am__objects_4) + libnutscan_la-nutscan-init.lo libnutscan_la-scan_usb.lo \ + libnutscan_la-scan_snmp.lo libnutscan_la-scan_xml_http.lo \ + libnutscan_la-scan_avahi.lo libnutscan_la_OBJECTS = $(am_libnutscan_la_OBJECTS) libnutscan_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(libnutscan_la_CFLAGS) \ $(CFLAGS) $(libnutscan_la_LDFLAGS) $(LDFLAGS) -o $@ +@WITH_LIBLTDL_TRUE@am_libnutscan_la_rpath = -rpath $(libdir) PROGRAMS = $(bin_PROGRAMS) am_nut_scanner_OBJECTS = nut_scanner-nut-scanner.$(OBJEXT) nut_scanner_OBJECTS = $(am_nut_scanner_OBJECTS) @@ -153,9 +140,12 @@ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ $(LDFLAGS) -o $@ SOURCES = $(libnutscan_la_SOURCES) $(nut_scanner_SOURCES) -DIST_SOURCES = $(am__libnutscan_la_SOURCES_DIST) \ - $(nut_scanner_SOURCES) -HEADERS = $(dist_noinst_HEADERS) +DIST_SOURCES = $(libnutscan_la_SOURCES) $(nut_scanner_SOURCES) +am__dist_noinst_HEADERS_DIST = nutscan-usb.h nutscan-snmp.h nut-scan.h \ + nutscan-device.h nutscan-ip.h nutscan-init.h +am__include_HEADERS_DIST = nut-scan.h nutscan-device.h nutscan-ip.h \ + nutscan-init.h +HEADERS = $(dist_noinst_HEADERS) $(include_HEADERS) ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -179,6 +169,7 @@ CYGPATH_W = @CYGPATH_W@ DBLATEX = @DBLATEX@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ DOC_BUILD_LIST = @DOC_BUILD_LIST@ DRIVER_BUILD_LIST = @DRIVER_BUILD_LIST@ DRIVER_INSTALL_TARGET = @DRIVER_INSTALL_TARGET@ @@ -211,6 +202,8 @@ LIBHAL_CFLAGS = @LIBHAL_CFLAGS@ LIBHAL_LIBS = @LIBHAL_LIBS@ LIBIPMI_CFLAGS = @LIBIPMI_CFLAGS@ LIBIPMI_LIBS = @LIBIPMI_LIBS@ +LIBLTDL_CFLAGS = @LIBLTDL_CFLAGS@ +LIBLTDL_LIBS = @LIBLTDL_LIBS@ LIBNEON_CFLAGS = @LIBNEON_CFLAGS@ LIBNEON_LIBS = @LIBNEON_LIBS@ LIBNETSNMP_CFLAGS = @LIBNETSNMP_CFLAGS@ @@ -231,6 +224,7 @@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ NETLIBS = @NETLIBS@ NM = @NM@ @@ -262,12 +256,14 @@ SHELL = @SHELL@ STATEPATH = @STATEPATH@ STRIP = @STRIP@ SUN_LIBUSB = @SUN_LIBUSB@ +TREE_VERSION = @TREE_VERSION@ VERSION = @VERSION@ WORDS_BIGENDIAN = @WORDS_BIGENDIAN@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ @@ -303,7 +299,6 @@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ -lt_ECHO = @lt_ECHO@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ @@ -328,21 +323,23 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ udevdir = @udevdir@ BUILT_SOURCES = nutscan-usb.h nutscan-snmp.h -lib_LTLIBRARIES = libnutscan.la -libnutscan_la_SOURCES = scan_nut.c scan_ipmi.c nutscan-device.c \ - nutscan-ip.c nutscan-display.c $(am__append_3) $(am__append_6) \ - $(am__append_9) $(am__append_12) +@WITH_LIBLTDL_TRUE@lib_LTLIBRARIES = libnutscan.la +libnutscan_la_SOURCES = scan_nut.c scan_ipmi.c \ + nutscan-device.c nutscan-ip.c nutscan-display.c nutscan-init.c \ + scan_usb.c scan_snmp.c scan_xml_http.c scan_avahi.c + libnutscan_la_LIBADD = ../../clients/libupsclient.la $(NETLIBS) \ - $(am__append_2) $(am__append_5) $(am__append_8) \ - $(am__append_11) $(am__append_14) + $(LIBLTDL_LIBS) $(am__append_2) libnutscan_la_LDFLAGS = -version-info 1:0:0 libnutscan_la_CFLAGS = -I$(top_srcdir)/clients -I$(top_srcdir)/include \ - $(am__append_1) $(am__append_4) $(am__append_7) \ - $(am__append_10) $(am__append_13) + $(LIBLTDL_CFLAGS) $(am__append_1) $(am__append_3) \ + $(am__append_4) $(am__append_5) $(am__append_6) \ + $(am__append_7) nut_scanner_SOURCES = nut-scanner.c nut_scanner_CFLAGS = -I$(top_srcdir)/clients -I$(top_srcdir)/include nut_scanner_LDADD = libnutscan.la -dist_noinst_HEADERS = nut-scan.h nutscan-usb.h nutscan-snmp.h nutscan-device.h nutscan-ip.h +dist_noinst_HEADERS = nutscan-usb.h nutscan-snmp.h $(am__append_8) +@WITH_DEV_TRUE@include_HEADERS = nut-scan.h nutscan-device.h nutscan-ip.h nutscan-init.h CLEANFILES = nutscan-usb.h nutscan-snmp.h all: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) all-am @@ -411,7 +408,7 @@ clean-libLTLIBRARIES: rm -f "$${dir}/so_locations"; \ done libnutscan.la: $(libnutscan_la_OBJECTS) $(libnutscan_la_DEPENDENCIES) - $(libnutscan_la_LINK) -rpath $(libdir) $(libnutscan_la_OBJECTS) $(libnutscan_la_LIBADD) $(LIBS) + $(libnutscan_la_LINK) $(am_libnutscan_la_rpath) $(libnutscan_la_OBJECTS) $(libnutscan_la_LIBADD) $(LIBS) install-binPROGRAMS: $(bin_PROGRAMS) @$(NORMAL_INSTALL) test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)" @@ -467,6 +464,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libnutscan_la-nutscan-device.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libnutscan_la-nutscan-display.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libnutscan_la-nutscan-init.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libnutscan_la-nutscan-ip.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libnutscan_la-scan_avahi.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libnutscan_la-scan_ipmi.Plo@am__quote@ @@ -532,6 +530,13 @@ libnutscan_la-nutscan-display.lo: nutscan-display.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnutscan_la_CFLAGS) $(CFLAGS) -c -o libnutscan_la-nutscan-display.lo `test -f 'nutscan-display.c' || echo '$(srcdir)/'`nutscan-display.c +libnutscan_la-nutscan-init.lo: nutscan-init.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnutscan_la_CFLAGS) $(CFLAGS) -MT libnutscan_la-nutscan-init.lo -MD -MP -MF $(DEPDIR)/libnutscan_la-nutscan-init.Tpo -c -o libnutscan_la-nutscan-init.lo `test -f 'nutscan-init.c' || echo '$(srcdir)/'`nutscan-init.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libnutscan_la-nutscan-init.Tpo $(DEPDIR)/libnutscan_la-nutscan-init.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='nutscan-init.c' object='libnutscan_la-nutscan-init.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnutscan_la_CFLAGS) $(CFLAGS) -c -o libnutscan_la-nutscan-init.lo `test -f 'nutscan-init.c' || echo '$(srcdir)/'`nutscan-init.c + libnutscan_la-scan_usb.lo: scan_usb.c @am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnutscan_la_CFLAGS) $(CFLAGS) -MT libnutscan_la-scan_usb.lo -MD -MP -MF $(DEPDIR)/libnutscan_la-scan_usb.Tpo -c -o libnutscan_la-scan_usb.lo `test -f 'scan_usb.c' || echo '$(srcdir)/'`scan_usb.c @am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libnutscan_la-scan_usb.Tpo $(DEPDIR)/libnutscan_la-scan_usb.Plo @@ -579,6 +584,26 @@ mostlyclean-libtool: clean-libtool: -rm -rf .libs _libs +install-includeHEADERS: $(include_HEADERS) + @$(NORMAL_INSTALL) + test -z "$(includedir)" || $(MKDIR_P) "$(DESTDIR)$(includedir)" + @list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; \ + done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(includedir)'"; \ + $(INSTALL_HEADER) $$files "$(DESTDIR)$(includedir)" || exit $$?; \ + done + +uninstall-includeHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ + test -n "$$files" || exit 0; \ + echo " ( cd '$(DESTDIR)$(includedir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(includedir)" && rm -f $$files ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ @@ -669,7 +694,7 @@ all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(HEADERS) install-binPROGRAMS: install-libLTLIBRARIES installdirs: - for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)"; do \ + for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(includedir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: $(BUILT_SOURCES) @@ -723,7 +748,7 @@ info: info-am info-am: -install-data-am: +install-data-am: install-includeHEADERS install-dvi: install-dvi-am @@ -769,7 +794,8 @@ ps: ps-am ps-am: -uninstall-am: uninstall-binPROGRAMS uninstall-libLTLIBRARIES +uninstall-am: uninstall-binPROGRAMS uninstall-includeHEADERS \ + uninstall-libLTLIBRARIES .MAKE: all check install install-am install-strip @@ -780,13 +806,14 @@ uninstall-am: uninstall-binPROGRAMS uninstall-libLTLIBRARIES html-am info info-am install install-am install-binPROGRAMS \ install-data install-data-am install-dvi install-dvi-am \ install-exec install-exec-am install-html install-html-am \ - install-info install-info-am install-libLTLIBRARIES \ - install-man install-pdf install-pdf-am install-ps \ - install-ps-am install-strip installcheck installcheck-am \ - installdirs maintainer-clean maintainer-clean-generic \ - mostlyclean mostlyclean-compile mostlyclean-generic \ - mostlyclean-libtool pdf pdf-am ps ps-am tags uninstall \ - uninstall-am uninstall-binPROGRAMS uninstall-libLTLIBRARIES + install-includeHEADERS install-info install-info-am \ + install-libLTLIBRARIES install-man install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-binPROGRAMS \ + uninstall-includeHEADERS uninstall-libLTLIBRARIES nutscan-usb.h nutscan-snmp.h: diff --git a/tools/nut-scanner/README b/tools/nut-scanner/README new file mode 100644 index 0000000..d6e9d59 --- /dev/null +++ b/tools/nut-scanner/README @@ -0,0 +1,114 @@ +NUT device discovery +==================== + +Introduction +------------ + +linkman:nut-scanner[8] is available to discover supported NUT devices +(USB, SNMP, Eaton XML/HTTP and IPMI) and NUT servers (using Avahi or the +classic connection method). + +This tool actually use a library, called *libnutscan*, to perform actual +processing. + + +Client access library +~~~~~~~~~~~~~~~~~~~~~ + +The nutscan library can be linked into other programs to give access +to NUT discovery. Both static and shared versions are provided. + +linkman:nut-scanner[8] is provided as an example of how to use the nutscan +functions. + +Here is a simple example that scans for USB devices, and use its own +iteration function to display results: + + #include + #include + #include + + /* Only enable USB scan */ + #define HAVE_USB_H + + #include "nut-scan.h" + + int main() + { + nutscan_options_t * opt; + nutscan_device_t *device; + + if ((device = nutscan_scan_usb()) == NULL) { + printf("No device found\n"); + exit(EXIT_FAILURE); + } + + /* Rewind the list */ + while(device->prev != NULL) { + device = device->prev; + } + + /* Print results */ + do { + printf("USB device found\n\tdriver: \"%s\"\n\tport: \"%s\"\n", + device->driver, device->port); + + /* process options (serial number, bus, ...) */ + opt = &(device->opt); + do { + if( opt->option != NULL ) { + printf("\t%s",opt->option); + if( opt->value != NULL ) { + printf(": \"%s\"", opt->value); + } + printf("\n"); + } + opt = opt->next; + } while( opt != NULL ); + + device = device->next; + } + while( device != NULL ); + + exit(EXIT_SUCCESS); + } + + +This library file and the associated header files are not installed by +default. You must `./configure --with-lib` to enable building and +installing these files. The libraries can then be built and installed +with `make` and `make install` as usual. This must be done before +building other (non-NUT) programs which depend on them. + +For more information, refer to the linkman:nutscan[3], +manual page and the various +link:man/index.html#devscan[nutscan_*(3)] functions documentation +referenced in the same file. + + +Configuration helpers +~~~~~~~~~~~~~~~~~~~~~ + +NUT provides helper scripts to ease the configuration step of your program, by +detecting the right compilation and link flags. + +For more information, refer to a +<>. + + +Python +------ + +Python support for NUT discovery features is not yet available. + + +Perl +---- + +Perl support for NUT discovery features is not yet available. + + +Java +---- + +Java support for NUT discovery features is not yet available. diff --git a/tools/nut-scanner/nut-scan.h b/tools/nut-scanner/nut-scan.h index c5ce748..affcc77 100644 --- a/tools/nut-scanner/nut-scan.h +++ b/tools/nut-scanner/nut-scan.h @@ -19,6 +19,7 @@ #ifndef NUT_SCAN_H #define NUT_SCAN_H +#include #include #include @@ -36,29 +37,19 @@ typedef struct nutscan_snmp { } nutscan_snmp_t; /* Scanning */ -#ifdef HAVE_NET_SNMP_NET_SNMP_CONFIG_H nutscan_device_t * nutscan_scan_snmp(const char * start_ip,const char * stop_ip,long usec_timeout, nutscan_snmp_t * sec); -#endif -#ifdef HAVE_USB_H nutscan_device_t * nutscan_scan_usb(); -#endif -#ifdef WITH_NEON nutscan_device_t * nutscan_scan_xml_http(long usec_timeout); -#endif nutscan_device_t * nutscan_scan_nut(const char * startIP, const char * stopIP, const char * port, long usec_timeout); -#ifdef HAVE_AVAHI_CLIENT_CLIENT_H nutscan_device_t * nutscan_scan_avahi(long usec_timeout); -#endif -#ifdef HAVE_FREEIPMI_FREEIPMI_H nutscan_device_t * nutscan_scan_ipmi(void); -#endif -/* Displaying */ +/* Display functions */ void nutscan_display_ups_conf(nutscan_device_t * device); void nutscan_display_parsable(nutscan_device_t * device); diff --git a/tools/nut-scanner/nut-scanner.c b/tools/nut-scanner/nut-scanner.c index b42dbca..2114674 100644 --- a/tools/nut-scanner/nut-scanner.c +++ b/tools/nut-scanner/nut-scanner.c @@ -21,6 +21,7 @@ #include #include #include "common.h" +#include "nut_version.h" #include #include #ifdef HAVE_PTHREAD @@ -31,7 +32,9 @@ #define DEFAULT_TIMEOUT 5 -const char optstring[] = "?ht:s:e:c:l:u:W:X:w:x:p:CUSMOAm:NPqI"; +#define ERR_BAD_OPTION (-1) + +const char optstring[] = "?ht:s:e:c:l:u:W:X:w:x:p:CUSMOAm:NPqIVa"; #ifdef HAVE_GETOPT_LONG const struct option longopts[] = @@ -58,13 +61,14 @@ const struct option longopts[] = { "disp_parsable",no_argument,NULL,'P' }, { "quiet",no_argument,NULL,'q' }, { "help",no_argument,NULL,'h' }, + { "version",no_argument,NULL,'V' }, + { "available",no_argument,NULL,'a' }, {NULL,0,NULL,0}}; #else #define getopt_long(a,b,c,d,e) getopt(a,b,c) #endif /* HAVE_GETOPT_LONG */ static nutscan_device_t *dev[TYPE_END]; -static pthread_t thread[TYPE_END]; static long timeout = DEFAULT_TIMEOUT*1000*1000; /* in usec */ static char * start_ip = NULL; @@ -72,14 +76,13 @@ static char * end_ip = NULL; static char * port = NULL; #ifdef HAVE_PTHREAD -#ifdef HAVE_USB_H +static pthread_t thread[TYPE_END]; + static void * run_usb(void * arg) { dev[TYPE_USB] = nutscan_scan_usb(); return NULL; } -#endif -#ifdef HAVE_NET_SNMP_NET_SNMP_CONFIG_H static void * run_snmp(void * arg) { nutscan_snmp_t * sec = (nutscan_snmp_t *)arg; @@ -87,14 +90,11 @@ static void * run_snmp(void * arg) dev[TYPE_SNMP] = nutscan_scan_snmp(start_ip,end_ip,timeout,sec); return NULL; } -#endif -#ifdef WITH_NEON static void * run_xml(void * arg) { dev[TYPE_XML] = nutscan_scan_xml_http(timeout); return NULL; } -#endif static void * run_nut_old(void * arg) { @@ -102,20 +102,16 @@ static void * run_nut_old(void * arg) return NULL; } -#ifdef HAVE_AVAHI_CLIENT_CLIENT_H static void * run_avahi(void * arg) { dev[TYPE_AVAHI] = nutscan_scan_avahi(timeout); return NULL; } -#endif -#ifdef HAVE_FREEIPMI_FREEIPMI_H static void * run_ipmi(void * arg) { dev[TYPE_IPMI] = nutscan_scan_ipmi(); return NULL; } -#endif #endif /* HAVE_PTHREAD */ static int printq(int quiet,const char *fmt, ...) { @@ -147,9 +143,12 @@ int main(int argc, char *argv[]) int allow_ipmi = 0; int quiet = 0; void (*display_func)(nutscan_device_t * device); + int ret_code = EXIT_SUCCESS; memset(&sec,0,sizeof(sec)); + nutscan_init(); + display_func = nutscan_display_ups_conf; while((opt_ret = getopt_long(argc, argv, optstring, longopts, NULL))!=-1) { @@ -172,63 +171,87 @@ int main(int argc, char *argv[]) case 'm': cidr = strdup(optarg); break; -#ifdef HAVE_NET_SNMP_NET_SNMP_CONFIG_H case 'c': + if(!nutscan_avail_snmp) { + goto display_help; + } sec.community = strdup(optarg); break; case 'l': + if(!nutscan_avail_snmp) { + goto display_help; + } sec.secLevel = strdup(optarg); break; case 'u': + if(!nutscan_avail_snmp) { + goto display_help; + } sec.secName = strdup(optarg); break; case 'W': + if(!nutscan_avail_snmp) { + goto display_help; + } sec.authPassword = strdup(optarg); break; case 'X': + if(!nutscan_avail_snmp) { + goto display_help; + } sec.privPassword = strdup(optarg); break; case 'w': + if(!nutscan_avail_snmp) { + goto display_help; + } sec.authProtocol = strdup(optarg); break; case 'x': + if(!nutscan_avail_snmp) { + goto display_help; + } sec.privProtocol = strdup(optarg); break; -#endif + case 'S': + if(!nutscan_avail_snmp) { + goto display_help; + } + allow_snmp = 1; + break; case 'p': port = strdup(optarg); break; case 'C': allow_all = 1; break; -#ifdef HAVE_USB_H case 'U': + if(!nutscan_avail_usb) { + goto display_help; + } allow_usb = 1; break; -#endif -#ifdef HAVE_NET_SNMP_NET_SNMP_CONFIG_H - case 'S': - allow_snmp = 1; - break; -#endif -#ifdef WITH_NEON case 'M': + if(!nutscan_avail_xml_http) { + goto display_help; + } allow_xml = 1; break; -#endif case 'O': allow_oldnut = 1; break; -#ifdef WITH_AVAHI case 'A': + if(!nutscan_avail_avahi) { + goto display_help; + } allow_avahi = 1; break; -#endif -#ifdef HAVE_FREEIPMI_FREEIPMI_H case 'I': + if(!nutscan_avail_ipmi) { + goto display_help; + } allow_ipmi = 1; break; -#endif case 'N': display_func = nutscan_display_ups_conf; break; @@ -238,51 +261,79 @@ int main(int argc, char *argv[]) case 'q': quiet = 1; break; - case 'h': + case 'V': + printf("Network UPS Tools - %s\n", NUT_VERSION_MACRO); + exit(EXIT_SUCCESS); + case 'a': + printf("OLDNUT\n"); + if(nutscan_avail_usb) { + printf("USB\n"); + } + if(nutscan_avail_snmp) { + printf("SNMP\n"); + } + if(nutscan_avail_xml_http) { + printf("XML\n"); + } + if(nutscan_avail_avahi) { + printf("AVAHI\n"); + } + if(nutscan_avail_ipmi) { + printf("IPMI\n"); + } + exit(EXIT_SUCCESS); case '?': + ret_code = ERR_BAD_OPTION; + case 'h': default: - puts("nut-scanner : detecting available UPS.\n"); +display_help: + puts("nut-scanner : detecting available power devices.\n"); puts("OPTIONS:"); - printf(" -C, --complete_scan : Scan all available devices (default).\n"); -#ifdef HAVE_USB_H - printf(" -U, --usb_scan : Scan USB devices.\n"); -#endif -#ifdef HAVE_NET_SNMP_NET_SNMP_CONFIG_H - printf(" -S, --snmp_scan : Scan SNMP devices.\n"); -#endif -#ifdef WITH_NEON - printf(" -M, --xml_scan : Scan XML/HTTP devices.\n"); -#endif - printf(" -O, --oldnut_scan : Scan NUT devices (old method).\n"); -#ifdef WITH_AVAHI - printf(" -A, --avahi_scan : Scan NUT devices (avahi method).\n"); -#endif -#ifdef HAVE_FREEIPMI_FREEIPMI_H - printf(" -I, --ipmi_scan : Scan IPMI devices.\n"); -#endif + printf(" -C, --complete_scan: Scan all available devices (default).\n"); + if( nutscan_avail_usb ) { + printf(" -U, --usb_scan: Scan USB devices.\n"); + } + if( nutscan_avail_snmp ) { + printf(" -S, --snmp_scan: Scan SNMP devices.\n"); + } + if( nutscan_avail_xml_http ) { + printf(" -M, --xml_scan: Scan XML/HTTP devices.\n"); + } + printf(" -O, --oldnut_scan: Scan NUT devices (old method).\n"); + if( nutscan_avail_avahi ) { + printf(" -A, --avahi_scan: Scan NUT devices (avahi method).\n"); + } + if( nutscan_avail_ipmi ) { + printf(" -I, --ipmi_scan: Scan IPMI devices.\n"); + } printf(" -t, --timeout : network operation timeout (default %d).\n",DEFAULT_TIMEOUT); printf(" -s, --start_ip : First IP address to scan.\n"); printf(" -e, --end_ip : Last IP address to scan.\n"); + printf(" -m, --mask_cidr : Give a range of IP using CIDR notation.\n"); -#ifdef HAVE_NET_SNMP_NET_SNMP_CONFIG_H - printf("\nSNMP v1 specific options:\n"); - printf(" -c, --community : Set SNMP v1 community name (default = public)\n"); + if( nutscan_avail_snmp ) { + printf("\nSNMP v1 specific options:\n"); + printf(" -c, --community : Set SNMP v1 community name (default = public)\n"); - printf("\nSNMP v3 specific options:\n"); - printf(" -l, --secLevel : Set the securityLevel used for SNMPv3 messages (allowed values: noAuthNoPriv,authNoPriv,authPriv)\n"); - printf(" -u, --secName : Set the securityName used for authenticated SNMPv3 messages (mandatory if you set secLevel. No default)\n"); - printf(" -a, --authProtocol : Set the authentication protocol (MD5 or SHA) used for authenticated SNMPv3 messages (default=MD5)\n"); - printf(" -A, --authPassword : Set the authentication pass phrase used for authenticated SNMPv3 messages (mandatory if you set secLevel to authNoPriv or authPriv)\n"); - printf(" -x, --privProtocol : Set the privacy protocol (DES or AES) used for encrypted SNMPv3 messages (default=DES)\n"); - printf(" -X, --privPassword : Set the privacy pass phrase used for encrypted SNMPv3 messages (mandatory if you set secLevel to authPriv)\n"); -#endif + printf("\nSNMP v3 specific options:\n"); + printf(" -l, --secLevel : Set the securityLevel used for SNMPv3 messages (allowed values: noAuthNoPriv,authNoPriv,authPriv)\n"); + printf(" -u, --secName : Set the securityName used for authenticated SNMPv3 messages (mandatory if you set secLevel. No default)\n"); + printf(" -w, --authProtocol : Set the authentication protocol (MD5 or SHA) used for authenticated SNMPv3 messages (default=MD5)\n"); + printf(" -W, --authPassword : Set the authentication pass phrase used for authenticated SNMPv3 messages (mandatory if you set secLevel to authNoPriv or authPriv)\n"); + printf(" -x, --privProtocol : Set the privacy protocol (DES or AES) used for encrypted SNMPv3 messages (default=DES)\n"); + printf(" -X, --privPassword : Set the privacy pass phrase used for encrypted SNMPv3 messages (mandatory if you set secLevel to authPriv)\n"); + } - printf("\nNUT device specific options:\n"); - printf(" -p, --port : Port number of remote NUT devices\n"); + printf("\nNUT specific options:\n"); + printf(" -p, --port : Port number of remote NUT upsd\n"); printf("\ndisplay specific options:\n"); - printf(" -N, --disp_nut_conf : Display result in the ups.conf format\n"); - printf(" -P, --disp_parsable : Display result in a parsable format\n"); - return 0; + printf(" -N, --disp_nut_conf: Display result in the ups.conf format\n"); + printf(" -P, --disp_parsable: Display result in a parsable format\n"); + printf("\nMiscellaneous options:\n"); + printf(" -V, --version: Display NUT version\n"); + printf(" -a, --available: Display available bus that can be scanned\n"); + printf(" -q, --quiet: Display only scan result. No information on currently scanned bus is displayed.\n"); + return ret_code; } } @@ -296,120 +347,128 @@ int main(int argc, char *argv[]) allow_all = 1; } -#ifdef HAVE_USB_H - if( allow_all || allow_usb) { + if( allow_all ) { + allow_usb = 1; + allow_snmp = 1; + allow_xml = 1; + allow_oldnut = 1; + allow_avahi = 1; + allow_ipmi = 1; + } + + if( allow_usb && nutscan_avail_usb ) { printq(quiet,"Scanning USB bus.\n"); #ifdef HAVE_PTHREAD - pthread_create(&thread[TYPE_USB],NULL,run_usb,NULL); + if(pthread_create(&thread[TYPE_USB],NULL,run_usb,NULL)) { + nutscan_avail_usb = 0; + } #else dev[TYPE_USB] = nutscan_scan_usb(); -#endif +#endif /* HAVE_PTHREAD */ } -#endif /* HAVE_USB_H */ -#ifdef HAVE_NET_SNMP_NET_SNMP_CONFIG_H - if( allow_all || allow_snmp) { + if( allow_snmp && nutscan_avail_snmp ) { if( start_ip == NULL ) { printq(quiet,"No start IP, skipping SNMP\n"); } else { printq(quiet,"Scanning SNMP bus.\n"); #ifdef HAVE_PTHREAD - pthread_create(&thread[TYPE_SNMP],NULL,run_snmp,&sec); + if( pthread_create(&thread[TYPE_SNMP],NULL,run_snmp,&sec)) { + nutscan_avail_snmp = 0; + } #else dev[TYPE_SNMP] = nutscan_scan_snmp(start_ip,end_ip,timeout,&sec); -#endif +#endif /* HAVE_PTHREAD */ } } -#endif /* HAVE_NET_SNMP_NET_SNMP_CONFIG_H */ -#ifdef WITH_NEON - if( allow_all || allow_xml) { + if( allow_xml && nutscan_avail_xml_http) { printq(quiet,"Scanning XML/HTTP bus.\n"); #ifdef HAVE_PTHREAD - pthread_create(&thread[TYPE_XML],NULL,run_xml,NULL); + if(pthread_create(&thread[TYPE_XML],NULL,run_xml,NULL)) { + nutscan_avail_xml_http = 0; + } #else dev[TYPE_XML] = nutscan_scan_xml_http(timeout); -#endif +#endif /* HAVE_PTHREAD */ } -#endif - if( allow_all || allow_oldnut) { + if( allow_oldnut && nutscan_avail_nut) { if( start_ip == NULL ) { printq(quiet,"No start IP, skipping NUT bus (old connect method)\n"); } else { printq(quiet,"Scanning NUT bus (old connect method).\n"); #ifdef HAVE_PTHREAD - pthread_create(&thread[TYPE_NUT],NULL,run_nut_old,NULL); + if(pthread_create(&thread[TYPE_NUT],NULL,run_nut_old,NULL)) { + nutscan_avail_nut = 0; + } #else dev[TYPE_NUT] = nutscan_scan_nut(start_ip,end_ip,port,timeout); -#endif +#endif /* HAVE_PTHREAD */ } } -#ifdef HAVE_AVAHI_CLIENT_CLIENT_H - if( allow_all || allow_avahi) { + if( allow_avahi && nutscan_avail_avahi) { printq(quiet,"Scanning NUT bus (avahi method).\n"); #ifdef HAVE_PTHREAD - pthread_create(&thread[TYPE_AVAHI],NULL,run_avahi,NULL); + if(pthread_create(&thread[TYPE_AVAHI],NULL,run_avahi,NULL)) { + nutscan_avail_avahi = 0; + } #else - dev[TYPE_AVAHI] = nutscan_scan_avahi(); -#endif + dev[TYPE_AVAHI] = nutscan_scan_avahi(timeout); +#endif /* HAVE_PTHREAD */ } -#endif -#ifdef HAVE_FREEIPMI_FREEIPMI_H - if( allow_all || allow_ipmi) { + if( allow_ipmi && nutscan_avail_ipmi) { printq(quiet,"Scanning IPMI bus.\n"); #ifdef HAVE_PTHREAD - pthread_create(&thread[TYPE_IPMI],NULL,run_ipmi,NULL); + if(pthread_create(&thread[TYPE_IPMI],NULL,run_ipmi,NULL)) { + nutscan_avail_ipmi = 0; + } #else dev[TYPE_IPMI] = nutscan_scan_ipmi(); -#endif +#endif /* HAVE_PTHREAD */ } -#endif #ifdef HAVE_PTHREAD -#ifdef HAVE_USB_H - pthread_join(thread[TYPE_USB],NULL); -#endif -#ifdef HAVE_NET_SNMP_NET_SNMP_CONFIG_H - pthread_join(thread[TYPE_SNMP],NULL); -#endif -#ifdef WITH_NEON - pthread_join(thread[TYPE_XML],NULL); -#endif - pthread_join(thread[TYPE_NUT],NULL); -#ifdef HAVE_AVAHI_CLIENT_CLIENT_H - pthread_join(thread[TYPE_AVAHI],NULL); -#endif -#ifdef HAVE_FREEIPMI_FREEIPMI_H - pthread_join(thread[TYPE_IPMI],NULL); -#endif + if( allow_usb && nutscan_avail_usb ) { + pthread_join(thread[TYPE_USB],NULL); + } + if( allow_snmp && nutscan_avail_snmp ) { + pthread_join(thread[TYPE_SNMP],NULL); + } + if( allow_xml && nutscan_avail_xml_http ) { + pthread_join(thread[TYPE_XML],NULL); + } + if( allow_oldnut && nutscan_avail_nut ) { + pthread_join(thread[TYPE_NUT],NULL); + } + if( allow_avahi && nutscan_avail_avahi ) { + pthread_join(thread[TYPE_AVAHI],NULL); + } + if( allow_ipmi && nutscan_avail_ipmi ) { + pthread_join(thread[TYPE_IPMI],NULL); + } #endif /* HAVE_PTHREAD */ -#ifdef HAVE_USB_H display_func(dev[TYPE_USB]); nutscan_free_device(dev[TYPE_USB]); -#endif -#ifdef HAVE_NET_SNMP_NET_SNMP_CONFIG_H + display_func(dev[TYPE_SNMP]); nutscan_free_device(dev[TYPE_SNMP]); -#endif -#ifdef WITH_NEON + display_func(dev[TYPE_XML]); nutscan_free_device(dev[TYPE_XML]); -#endif + display_func(dev[TYPE_NUT]); nutscan_free_device(dev[TYPE_NUT]); -#ifdef HAVE_AVAHI_CLIENT_CLIENT_H + display_func(dev[TYPE_AVAHI]); nutscan_free_device(dev[TYPE_AVAHI]); -#endif -#ifdef HAVE_FREEIPMI_FREEIPMI_H + display_func(dev[TYPE_IPMI]); nutscan_free_device(dev[TYPE_IPMI]); -#endif return EXIT_SUCCESS; } diff --git a/tools/nut-scanner/nutscan-init.c b/tools/nut-scanner/nutscan-init.c new file mode 100644 index 0000000..f668546 --- /dev/null +++ b/tools/nut-scanner/nutscan-init.c @@ -0,0 +1,52 @@ +/* nutscan-init.c: init functions for nut scanner library + * + * Copyright (C) 2011 - Frederic Bohe + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "common.h" + +int nutscan_avail_avahi = 0; +int nutscan_avail_ipmi = 0; +int nutscan_avail_nut = 1; +int nutscan_avail_snmp = 0; +int nutscan_avail_usb = 0; +int nutscan_avail_xml_http = 0; + +int nutscan_load_usb_library(void); +int nutscan_load_snmp_library(void); +int nutscan_load_neon_library(void); +int nutscan_load_avahi_library(void); +int nutscan_load_ipmi_library(void); + +void nutscan_init(void) +{ +#ifdef WITH_USB + nutscan_avail_usb = nutscan_load_usb_library(); +#endif +#ifdef WITH_SNMP + nutscan_avail_snmp = nutscan_load_snmp_library(); +#endif +#ifdef WITH_NEON + nutscan_avail_xml_http = nutscan_load_neon_library(); +#endif +#ifdef WITH_AVAHI + nutscan_avail_avahi = nutscan_load_avahi_library(); +#endif +#ifdef WITH_FREEIPMI + nutscan_avail_ipmi = nutscan_load_ipmi_library(); +#endif +} diff --git a/tools/nut-scanner/nutscan-init.h b/tools/nut-scanner/nutscan-init.h new file mode 100644 index 0000000..e952e6c --- /dev/null +++ b/tools/nut-scanner/nutscan-init.h @@ -0,0 +1,30 @@ +/* nutscan-init.h: initialisation data + * + * Copyright (C) 2011 - Frederic Bohe + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef SCAN_INIT +#define SCAN_INIT + +extern int nutscan_avail_avahi; +extern int nutscan_avail_ipmi; +extern int nutscan_avail_nut; +extern int nutscan_avail_snmp; +extern int nutscan_avail_usb; +extern int nutscan_avail_xml_http; + +void nutscan_init(void); +#endif diff --git a/tools/nut-scanner/nutscan-ip.c b/tools/nut-scanner/nutscan-ip.c index 97fbffb..8788018 100644 --- a/tools/nut-scanner/nutscan-ip.c +++ b/tools/nut-scanner/nutscan-ip.c @@ -20,6 +20,9 @@ #include "nutscan-ip.h" #include #include "common.h" +#include +#include +#include static void increment_IPv6(struct in6_addr * addr) { @@ -42,12 +45,38 @@ static void invert_IPv6(struct in6_addr * addr1, struct in6_addr * addr2) memcpy(addr2->s6_addr,addr.s6_addr,sizeof(addr.s6_addr)); } +static int ntop( struct in_addr * ip, char * host, size_t host_size) +{ + struct sockaddr_in in; + memset(&in,0,sizeof(struct sockaddr_in)); + in.sin_addr = *ip; + in.sin_family = AF_INET; + return getnameinfo((struct sockaddr *)&in, + sizeof(struct sockaddr_in), + host,host_size,NULL,0,NI_NUMERICHOST); +} + +static int ntop6( struct in6_addr * ip, char * host, size_t host_size) +{ + struct sockaddr_in6 in6; + memset(&in6,0,sizeof(struct sockaddr_in6)); + memcpy( &in6.sin6_addr, ip, sizeof(struct in6_addr) ); + in6.sin6_family = AF_INET6; + return getnameinfo((struct sockaddr *)&in6, + sizeof(struct sockaddr_in6), + host,host_size,NULL,0,NI_NUMERICHOST); +} + /* Return the first ip or NULL if error */ char * nutscan_ip_iter_init(nutscan_ip_iter_t * ip, const char * startIP, const char * stopIP) { int addr; int i; - char buf[SMALLBUF]; + struct addrinfo hints; + struct addrinfo *res; + struct sockaddr_in * s_in; + struct sockaddr_in6 * s_in6; + char host[SMALLBUF]; if( startIP == NULL ) { return NULL; @@ -57,29 +86,51 @@ char * nutscan_ip_iter_init(nutscan_ip_iter_t * ip, const char * startIP, const stopIP = startIP; } + memset(&hints,0,sizeof(struct addrinfo)); + hints.ai_family = AF_INET; + ip->type = IPv4; /* Detecting IPv4 vs IPv6 */ - if(!inet_aton(startIP, &ip->start)) { + if(getaddrinfo(startIP,NULL,&hints,&res) != 0) { /*Try IPv6 detection */ ip->type = IPv6; - if(!inet_pton(AF_INET6, startIP, &ip->start6)){ + hints.ai_family = AF_INET6; + if(getaddrinfo(startIP,NULL,&hints,&res) != 0) { fprintf(stderr,"Invalid address : %s\n",startIP); return NULL; } + + s_in6 = (struct sockaddr_in6 *)res->ai_addr; + memcpy(&ip->start6,&s_in6->sin6_addr,sizeof(struct in6_addr)); + freeaddrinfo(res); + } + else { + s_in = (struct sockaddr_in *)res->ai_addr; + ip->start = s_in->sin_addr; + freeaddrinfo(res); } /* Compute stop IP */ if( ip->type == IPv4 ) { - if(!inet_aton(stopIP, &ip->stop)) { + hints.ai_family = AF_INET; + if(getaddrinfo(stopIP,NULL,&hints,&res) != 0) { fprintf(stderr,"Invalid address : %s\n",stopIP); return NULL; } + + s_in = (struct sockaddr_in *)res->ai_addr; + ip->stop = s_in->sin_addr; + freeaddrinfo(res); } else { - if(!inet_pton(AF_INET6, stopIP, &ip->stop6)){ + hints.ai_family = AF_INET6; + if(getaddrinfo(stopIP,NULL,&hints,&res) != 0) { fprintf(stderr,"Invalid address : %s\n",stopIP); return NULL; } + s_in6 = (struct sockaddr_in6 *)res->ai_addr; + memcpy(&ip->stop6,&s_in6->sin6_addr,sizeof(struct in6_addr)); + freeaddrinfo(res); } /* Make sure start IP is lesser than stop IP */ @@ -89,7 +140,12 @@ char * nutscan_ip_iter_init(nutscan_ip_iter_t * ip, const char * startIP, const ip->start.s_addr = ip->stop.s_addr; ip->stop.s_addr = addr; } - return strdup(inet_ntoa(ip->start)); + + if( ntop(&ip->start, host, sizeof(host)) != 0 ) { + return NULL; + } + + return strdup(host); } else { /* IPv6 */ for( i=0; i<16; i++ ) { @@ -100,7 +156,12 @@ char * nutscan_ip_iter_init(nutscan_ip_iter_t * ip, const char * startIP, const break; } } - return strdup(inet_ntop(AF_INET6,&ip->start6,buf,sizeof(buf))); + + if( ntop6(&ip->start6, host, sizeof(host)) != 0 ) { + return NULL; + } + + return strdup(host); } @@ -111,7 +172,7 @@ return NULL if there is no more IP */ char * nutscan_ip_iter_inc(nutscan_ip_iter_t * ip) { - char buf[SMALLBUF]; + char host[SMALLBUF]; if( ip->type == IPv4 ) { /* Check if this is the last address to scan */ @@ -122,7 +183,11 @@ char * nutscan_ip_iter_inc(nutscan_ip_iter_t * ip) byte order, then pass back in network byte order */ ip->start.s_addr = htonl((ntohl(ip->start.s_addr)+1)); - return strdup(inet_ntoa(ip->start)); + if( ntop(&ip->start, host, sizeof(host)) != 0 ) { + return NULL; + } + + return strdup(host); } else { /* Check if this is the last address to scan */ @@ -132,8 +197,11 @@ char * nutscan_ip_iter_inc(nutscan_ip_iter_t * ip) } increment_IPv6(&ip->start6); + if( ntop6(&ip->start6, host, sizeof(host)) != 0 ) { + return NULL; + } - return strdup(inet_ntop(AF_INET6,&ip->start6,buf,sizeof(buf))); + return strdup(host); } } @@ -146,8 +214,12 @@ int nutscan_cidr_to_ip(const char * cidr, char ** start_ip, char ** stop_ip) nutscan_ip_iter_t ip; int mask_val; int mask_byte; - long mask_bit; - char buf[SMALLBUF]; + unsigned long mask_bit; + char host[SMALLBUF]; + struct addrinfo hints; + struct addrinfo *res; + struct sockaddr_in * s_in; + struct sockaddr_in6 * s_in6; *start_ip = NULL; *stop_ip = NULL; @@ -166,15 +238,30 @@ int nutscan_cidr_to_ip(const char * cidr, char ** start_ip, char ** stop_ip) mask_val = atoi(mask); /* Detecting IPv4 vs IPv6 */ + memset(&hints,0,sizeof(struct addrinfo)); + hints.ai_family = AF_INET; + ip.type = IPv4; - if(!inet_aton(first_ip, &ip.start)) { - /*Try IPv6 detection */ - ip.type = IPv6; - if(!inet_pton(AF_INET6, first_ip, &ip.start6)){ + /* Detecting IPv4 vs IPv6 */ + if(getaddrinfo(first_ip,NULL,&hints,&res) != 0) { + /*Try IPv6 detection */ + ip.type = IPv6; + hints.ai_family = AF_INET6; + int ret; + if((ret=getaddrinfo(first_ip,NULL,&hints,&res)) != 0) { free(first_ip); - return 0; - } - } + return 0; + } + + s_in6 = (struct sockaddr_in6 *)res->ai_addr; + memcpy(&ip.start6,&s_in6->sin6_addr,sizeof(struct in6_addr)); + freeaddrinfo(res); + } + else { + s_in = (struct sockaddr_in *)res->ai_addr; + ip.start = s_in->sin_addr; + freeaddrinfo(res); + } if( ip.type == IPv4 ) { @@ -190,13 +277,31 @@ int nutscan_cidr_to_ip(const char * cidr, char ** start_ip, char ** stop_ip) ip.stop.s_addr = htonl(ntohl(ip.start.s_addr)|mask_bit); ip.start.s_addr = htonl(ntohl(ip.start.s_addr)&(~mask_bit)); - *start_ip = strdup(inet_ntoa(ip.start)); - *stop_ip = strdup(inet_ntoa(ip.stop)); + if( ntop(&ip.start, host, sizeof(host)) != 0 ) { + *start_ip = NULL; + *stop_ip = NULL; + return 0; + } + *start_ip = strdup(host); + + if( ntop(&ip.stop, host, sizeof(host)) != 0 ) { + free(*start_ip); + *start_ip = NULL; + *stop_ip = NULL; + return 0; + } + *stop_ip = strdup(host); + free(first_ip); return 1; } else { - inet_pton(AF_INET6, first_ip, &ip.stop6); + if(getaddrinfo(first_ip,NULL,&hints,&res) != 0) { + return 0; + } + s_in6 = (struct sockaddr_in6 *)res->ai_addr; + memcpy(&ip.stop6,&s_in6->sin6_addr,sizeof(struct in6_addr)); + freeaddrinfo(res); mask_byte = mask_val / 8; if( mask_byte < 16 ) { @@ -208,10 +313,20 @@ int nutscan_cidr_to_ip(const char * cidr, char ** start_ip, char ** stop_ip) ip.start6.s6_addr[mask_byte] &= (~mask_bit); } - inet_ntop(AF_INET6,&ip.start6,buf,sizeof(buf)); - *start_ip = strdup(buf); - inet_ntop(AF_INET6,&ip.stop6,buf,sizeof(buf)); - *stop_ip = strdup(buf); + if( ntop6(&ip.start6, host, sizeof(host)) != 0 ) { + *start_ip = NULL; + *stop_ip = NULL; + return 0; + } + *start_ip = strdup(host); + + if( ntop6(&ip.stop6, host, sizeof(host)) != 0 ) { + free(*start_ip); + *start_ip = NULL; + *stop_ip = NULL; + return 0; + } + *stop_ip = strdup(host); } free(first_ip); diff --git a/tools/nut-scanner/nutscan-ip.h b/tools/nut-scanner/nutscan-ip.h index 01f329f..fbae00b 100644 --- a/tools/nut-scanner/nutscan-ip.h +++ b/tools/nut-scanner/nutscan-ip.h @@ -19,9 +19,8 @@ #ifndef SCAN_IP #define SCAN_IP -#include -#include #include +#include enum network_type { IPv4, diff --git a/tools/nut-scanner/nutscan-snmp.h b/tools/nut-scanner/nutscan-snmp.h index a08a892..7af6cef 100644 --- a/tools/nut-scanner/nutscan-snmp.h +++ b/tools/nut-scanner/nutscan-snmp.h @@ -37,6 +37,7 @@ static snmp_device_id_t snmp_device_table[] = { { ".1.3.6.1.4.1.705.1.1.1.0" , "mge", ".1.3.6.1.4.1.705.1"}, { ".1.3.6.1.4.1.318.1.1.1.1.1.1.0" , "apcc", NULL}, { ".1.3.6.1.4.1.4779.1.3.5.2.1.24.1" , "baytech", NULL}, + { ".1.3.6.1.4.1.3808.1.1.1.1.1.1.0" , "cyberpower", ".1.3.6.1.4.1.3808"}, { "1.3.6.1.4.1.232.165.3.1.1.0" , "cpqpower", NULL}, { ".1.3.6.1.4.1.4555.1.1.1.1.1.1.0" , "netvision", ".1.3.6.1.4.1.4555.1.1.1"}, /* Terminating entry */ diff --git a/tools/nut-scanner/nutscan-usb.h b/tools/nut-scanner/nutscan-usb.h index 6065e33..89a39fc 100644 --- a/tools/nut-scanner/nutscan-usb.h +++ b/tools/nut-scanner/nutscan-usb.h @@ -31,6 +31,7 @@ typedef struct { /* USB IDs device table */ static usb_device_id_t usb_device_table[] = { + { 0x0001, 0x0000, "blazer_usb" }, { 0x03f0, 0x1f01, "bcmxcp_usb" }, { 0x03f0, 0x1f02, "bcmxcp_usb" }, { 0x03f0, 0x1f06, "usbhid-ups" }, @@ -96,6 +97,7 @@ static usb_device_id_t usb_device_table[] = { { 0x09ae, 0x4006, "usbhid-ups" }, { 0x09ae, 0x4007, "usbhid-ups" }, { 0x09ae, 0x4008, "usbhid-ups" }, + { 0x0d9f, 0x0004, "usbhid-ups" }, { 0x0d9f, 0x00a2, "usbhid-ups" }, { 0x0d9f, 0x00a3, "usbhid-ups" }, { 0x0d9f, 0x00a4, "usbhid-ups" }, @@ -104,6 +106,7 @@ static usb_device_id_t usb_device_table[] = { { 0x0f03, 0x0001, "blazer_usb" }, { 0x10af, 0x0001, "usbhid-ups" }, { 0x14f0, 0x00c9, "blazer_usb" }, + { 0xffff, 0x0000, "blazer_usb" }, /* Terminating entry */ { -1, -1, NULL } }; diff --git a/tools/nut-scanner/scan_avahi.c b/tools/nut-scanner/scan_avahi.c index 6c4a74e..7763b36 100644 --- a/tools/nut-scanner/scan_avahi.c +++ b/tools/nut-scanner/scan_avahi.c @@ -17,14 +17,14 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "common.h" - -#ifdef HAVE_AVAHI_CLIENT_CLIENT_H #include "nut-scan.h" +#ifdef WITH_AVAHI + #include #include #include -#include +#include "timehead.h" #include #include @@ -33,6 +33,175 @@ #include #include +#include + +/* dynamic link library stuff */ +static lt_dlhandle dl_handle = NULL; +static const char *dl_error = NULL; + +static AvahiClient* (*nut_avahi_service_browser_get_client)(AvahiServiceBrowser *); +static int (*nut_avahi_simple_poll_loop)(AvahiSimplePoll *s); +static void (*nut_avahi_client_free)(AvahiClient *client); +static int (*nut_avahi_client_errno)(AvahiClient*); +static void (*nut_avahi_free)(void *p); +static void (*nut_avahi_simple_poll_quit)(AvahiSimplePoll *s); +static AvahiClient* (*nut_avahi_client_new)( + const AvahiPoll *poll_api, + AvahiClientFlags flags, + AvahiClientCallback callback, + void *userdata, + int *error); +static void (*nut_avahi_simple_poll_free)(AvahiSimplePoll *s); +static AvahiServiceResolver * (*nut_avahi_service_resolver_new)( + AvahiClient *client, + AvahiIfIndex interface, + AvahiProtocol protocol, + const char *name, + const char *type, + const char *domain, + AvahiProtocol aprotocol, + AvahiLookupFlags flags, + AvahiServiceResolverCallback callback, + void *userdata); +static const char * (*nut_avahi_strerror)(int error); +static AvahiClient* (*nut_avahi_service_resolver_get_client)(AvahiServiceResolver *); +static AvahiServiceBrowser* (*nut_avahi_service_browser_new)( + AvahiClient *client, + AvahiIfIndex interface, + AvahiProtocol protocol, + const char *type, + const char *domain, + AvahiLookupFlags flags, + AvahiServiceBrowserCallback callback, + void *userdata); +static int (*nut_avahi_service_resolver_free)(AvahiServiceResolver *r); +static AvahiSimplePoll *(*nut_avahi_simple_poll_new)(void); +static char* (*nut_avahi_string_list_to_string)(AvahiStringList *l); +static int (*nut_avahi_service_browser_free)(AvahiServiceBrowser *); +static char * (*nut_avahi_address_snprint)(char *ret_s, size_t length, const AvahiAddress *a); +static const AvahiPoll* (*nut_avahi_simple_poll_get)(AvahiSimplePoll *s); + +/* return 0 on error */ +int nutscan_load_avahi_library() +{ + if( dl_handle != NULL ) { + /* if previous init failed */ + if( dl_handle == (void *)1 ) { + return 0; + } + /* init has already been done */ + return 1; + } + + if( lt_dlinit() != 0 ) { + fprintf(stderr, "Error initializing lt_init\n"); + return 0; + } + + dl_handle = lt_dlopenext("libavahi-client"); + if (!dl_handle) { + dl_error = lt_dlerror(); + goto err; + } + lt_dlerror(); /* Clear any existing error */ + *(void **) (&nut_avahi_service_browser_get_client) = lt_dlsym(dl_handle, "avahi_service_browser_get_client"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_avahi_simple_poll_loop) = lt_dlsym(dl_handle, "avahi_simple_poll_loop"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_avahi_client_free) = lt_dlsym(dl_handle, "avahi_client_free"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_avahi_client_errno) = lt_dlsym(dl_handle, "avahi_client_errno"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_avahi_free) = lt_dlsym(dl_handle, "avahi_free"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_avahi_simple_poll_quit) = lt_dlsym(dl_handle, "avahi_simple_poll_quit"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_avahi_client_new) = lt_dlsym(dl_handle, "avahi_client_new"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_avahi_simple_poll_free) = lt_dlsym(dl_handle, "avahi_simple_poll_free"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_avahi_service_resolver_new) = lt_dlsym(dl_handle, "avahi_service_resolver_new"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_avahi_strerror) = lt_dlsym(dl_handle, "avahi_strerror"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_avahi_service_resolver_get_client) = lt_dlsym(dl_handle, "avahi_service_resolver_get_client"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_avahi_service_browser_new) = lt_dlsym(dl_handle, "avahi_service_browser_new"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_avahi_service_resolver_free) = lt_dlsym(dl_handle, "avahi_service_resolver_free"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_avahi_simple_poll_new) = lt_dlsym(dl_handle, "avahi_simple_poll_new"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_avahi_string_list_to_string) = lt_dlsym(dl_handle, "avahi_string_list_to_string"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_avahi_service_browser_free) = lt_dlsym(dl_handle, "avahi_service_browser_free"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_avahi_address_snprint) = lt_dlsym(dl_handle, "avahi_address_snprint"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_avahi_simple_poll_get) = lt_dlsym(dl_handle, "avahi_simple_poll_get"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + return 1; +err: + fprintf(stderr, "%s\n", dl_error); + dl_handle = (void *)1; + return 0; +} +/* end of dynamic link library stuff */ + static AvahiSimplePoll *simple_poll = NULL; static nutscan_device_t * dev_ret = NULL; static long avahi_usec_timeout = 0; @@ -187,7 +356,7 @@ static void resolve_callback( switch (event) { case AVAHI_RESOLVER_FAILURE: - fprintf(stderr, "(Resolver) Failed to resolve service '%s' of type '%s' in domain '%s': %s\n", name, type, domain, avahi_strerror(avahi_client_errno(avahi_service_resolver_get_client(r)))); + fprintf(stderr, "(Resolver) Failed to resolve service '%s' of type '%s' in domain '%s': %s\n", name, type, domain, (*nut_avahi_strerror)((*nut_avahi_client_errno)((*nut_avahi_service_resolver_get_client)(r)))); break; case AVAHI_RESOLVER_FOUND: { @@ -195,8 +364,8 @@ static void resolve_callback( /* fprintf(stderr, "Service '%s' of type '%s' in domain '%s':\n", name, type, domain); */ - avahi_address_snprint(a, sizeof(a), address); - t = avahi_string_list_to_string(txt); + (*nut_avahi_address_snprint)(a, sizeof(a), address); + t = (*nut_avahi_string_list_to_string)(txt); /* fprintf(stderr, "\t%s:%u (%s)\n" @@ -217,11 +386,11 @@ static void resolve_callback( !!(flags & AVAHI_LOOKUP_RESULT_CACHED)); */ update_device(host_name,a,port,t,address->proto); - avahi_free(t); + (*nut_avahi_free)(t); } } - avahi_service_resolver_free(r); + (*nut_avahi_service_resolver_free)(r); } static void browse_callback( @@ -243,8 +412,8 @@ static void browse_callback( switch (event) { case AVAHI_BROWSER_FAILURE: - fprintf(stderr, "(Browser) %s\n", avahi_strerror(avahi_client_errno(avahi_service_browser_get_client(b)))); - avahi_simple_poll_quit(simple_poll); + fprintf(stderr, "(Browser) %s\n", (*nut_avahi_strerror)((*nut_avahi_client_errno)((*nut_avahi_service_browser_get_client)(b)))); + (*nut_avahi_simple_poll_quit)(simple_poll); return; case AVAHI_BROWSER_NEW: @@ -255,8 +424,8 @@ static void browse_callback( the callback function is called the server will free the resolver for us. */ - if (!(avahi_service_resolver_new(c, interface, protocol, name, type, domain, AVAHI_PROTO_UNSPEC, 0, resolve_callback, c))) - fprintf(stderr, "Failed to resolve service '%s': %s\n", name, avahi_strerror(avahi_client_errno(c))); + if (!((*nut_avahi_service_resolver_new)(c, interface, protocol, name, type, domain, AVAHI_PROTO_UNSPEC, 0, resolve_callback, c))) + fprintf(stderr, "Failed to resolve service '%s': %s\n", name, (*nut_avahi_strerror)((*nut_avahi_client_errno)(c))); break; @@ -265,7 +434,7 @@ static void browse_callback( break; case AVAHI_BROWSER_ALL_FOR_NOW: - avahi_simple_poll_quit(simple_poll); + (*nut_avahi_simple_poll_quit)(simple_poll); case AVAHI_BROWSER_CACHE_EXHAUSTED: /* fprintf(stderr, "(Browser) %s\n", event == AVAHI_BROWSER_CACHE_EXHAUSTED ? "CACHE_EXHAUSTED" : "ALL_FOR_NOW"); */ break; @@ -278,8 +447,8 @@ static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UN /* Called whenever the client or server state changes */ if (state == AVAHI_CLIENT_FAILURE) { - fprintf(stderr, "Server connection failure: %s\n", avahi_strerror(avahi_client_errno(c))); - avahi_simple_poll_quit(simple_poll); + fprintf(stderr, "Server connection failure: %s\n", (*nut_avahi_strerror)((*nut_avahi_client_errno)(c))); + (*nut_avahi_simple_poll_quit)(simple_poll); } } @@ -291,48 +460,55 @@ nutscan_device_t * nutscan_scan_avahi(long usec_timeout) AvahiClient *client = NULL; AvahiServiceBrowser *sb = NULL; int error; - int ret = 1; + + if( !nutscan_avail_avahi ) { + return NULL; + } avahi_usec_timeout = usec_timeout; /* Allocate main loop object */ - if (!(simple_poll = avahi_simple_poll_new())) { + if (!(simple_poll = (*nut_avahi_simple_poll_new)())) { fprintf(stderr, "Failed to create simple poll object.\n"); goto fail; } /* Allocate a new client */ - client = avahi_client_new(avahi_simple_poll_get(simple_poll), 0, client_callback, NULL, &error); + client = (*nut_avahi_client_new)((*nut_avahi_simple_poll_get)(simple_poll), 0, client_callback, NULL, &error); /* Check wether creating the client object succeeded */ if (!client) { - fprintf(stderr, "Failed to create client: %s\n", avahi_strerror(error)); + fprintf(stderr, "Failed to create client: %s\n", (*nut_avahi_strerror)(error)); goto fail; } /* Create the service browser */ - if (!(sb = avahi_service_browser_new(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_upsd._tcp", NULL, 0, browse_callback, client))) { - fprintf(stderr, "Failed to create service browser: %s\n", avahi_strerror(avahi_client_errno(client))); + if (!(sb = (*nut_avahi_service_browser_new)(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_upsd._tcp", NULL, 0, browse_callback, client))) { + fprintf(stderr, "Failed to create service browser: %s\n", (*nut_avahi_strerror)((*nut_avahi_client_errno)(client))); goto fail; } /* Run the main loop */ - avahi_simple_poll_loop(simple_poll); - - ret = 0; + (*nut_avahi_simple_poll_loop)(simple_poll); fail: /* Cleanup things */ if (sb) - avahi_service_browser_free(sb); + (*nut_avahi_service_browser_free)(sb); if (client) - avahi_client_free(client); + (*nut_avahi_client_free)(client); if (simple_poll) - avahi_simple_poll_free(simple_poll); + (*nut_avahi_simple_poll_free)(simple_poll); return dev_ret; } -#endif /* HAVE_AVAHI_CLIENT_CLIENT_H */ +#else /* WITH_AVAHI */ +/* stub function */ +nutscan_device_t * nutscan_scan_avahi(long usec_timeout) +{ + return NULL; +} +#endif /* WITH_AVAHI */ diff --git a/tools/nut-scanner/scan_ipmi.c b/tools/nut-scanner/scan_ipmi.c index 145e281..eac17c3 100644 --- a/tools/nut-scanner/scan_ipmi.c +++ b/tools/nut-scanner/scan_ipmi.c @@ -1,6 +1,6 @@ /* scan_ipmi.c: detect NUT supported Power Supply Units * - * Copyright (C) 2011 - Frederic Bohe + * Copyright (C) 2011 - Arnaud Quette * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,13 +17,321 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "common.h" - -#ifdef HAVE_FREEIPMI_FREEIPMI_H #include "nut-scan.h" -/* TODO */ +#ifdef WITH_IPMI +#include "upsclient.h" +#include +#include +#include +#include + +#define NUT_IPMI_DRV_NAME "nut-ipmipsu" + +/* dynamic link library stuff */ +static lt_dlhandle dl_handle = NULL; +static const char *dl_error = NULL; + +static int (*nut_ipmi_fru_parse_close_device_id) (ipmi_fru_parse_ctx_t ctx); +static void (*nut_ipmi_fru_parse_ctx_destroy) (ipmi_fru_parse_ctx_t ctx); +static void (*nut_ipmi_sdr_cache_ctx_destroy) (ipmi_sdr_cache_ctx_t ctx); +static void (*nut_ipmi_sdr_parse_ctx_destroy) (ipmi_sdr_parse_ctx_t ctx); +static ipmi_fru_parse_ctx_t (*nut_ipmi_fru_parse_ctx_create) (ipmi_ctx_t ipmi_ctx); +static int (*nut_ipmi_fru_parse_ctx_set_flags) (ipmi_fru_parse_ctx_t ctx, unsigned int flags); +static int (*nut_ipmi_fru_parse_open_device_id) (ipmi_fru_parse_ctx_t ctx, uint8_t fru_device_id); +static char * (*nut_ipmi_fru_parse_ctx_errormsg) (ipmi_fru_parse_ctx_t ctx); +static int (*nut_ipmi_fru_parse_read_data_area) (ipmi_fru_parse_ctx_t ctx, + unsigned int *area_type, + unsigned int *area_length, + void *areabuf, + unsigned int areabuflen); +static int (*nut_ipmi_fru_parse_next) (ipmi_fru_parse_ctx_t ctx); +static ipmi_ctx_t (*nut_ipmi_ctx_create) (void); +static int (*nut_ipmi_ctx_find_inband) (ipmi_ctx_t ctx, + ipmi_driver_type_t *driver_type, + int disable_auto_probe, + uint16_t driver_address, + uint8_t register_spacing, + const char *driver_device, + unsigned int workaround_flags, + unsigned int flags); +static char * (*nut_ipmi_ctx_errormsg) (ipmi_ctx_t ctx); +static int (*nut_ipmi_ctx_close) (ipmi_ctx_t ctx); +static void (*nut_ipmi_ctx_destroy) (ipmi_ctx_t ctx); + + +/* Return 0 on error */ +int nutscan_load_ipmi_library() +{ + if( dl_handle != NULL ) { + /* if previous init failed */ + if( dl_handle == (void *)1 ) { + return 0; + } + /* init has already been done */ + return 1; + } + + if( lt_dlinit() != 0 ) { + fprintf(stderr, "Error initializing lt_init\n"); + return 0; + } + + dl_handle = lt_dlopenext("libfreeipmi"); + if (!dl_handle) { + dl_error = lt_dlerror(); + goto err; + } + + /* Clear any existing error */ + lt_dlerror(); + + *(void **) (&nut_ipmi_fru_parse_close_device_id) = lt_dlsym(dl_handle, "ipmi_fru_parse_close_device_id"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_ipmi_fru_parse_ctx_destroy) = lt_dlsym(dl_handle, "ipmi_fru_parse_ctx_destroy"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_ipmi_sdr_cache_ctx_destroy) = lt_dlsym(dl_handle, "ipmi_sdr_cache_ctx_destroy"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_ipmi_sdr_parse_ctx_destroy) = lt_dlsym(dl_handle, "ipmi_sdr_parse_ctx_destroy"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_ipmi_fru_parse_ctx_create) = lt_dlsym(dl_handle, "ipmi_fru_parse_ctx_create"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_ipmi_fru_parse_ctx_set_flags) = lt_dlsym(dl_handle, "ipmi_fru_parse_ctx_set_flags"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_ipmi_fru_parse_open_device_id) = lt_dlsym(dl_handle, "ipmi_fru_parse_open_device_id"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_ipmi_fru_parse_ctx_errormsg) = lt_dlsym(dl_handle, "ipmi_fru_parse_ctx_errormsg"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_ipmi_fru_parse_read_data_area) = lt_dlsym(dl_handle, "ipmi_fru_parse_read_data_area"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_ipmi_fru_parse_next) = lt_dlsym(dl_handle, "ipmi_fru_parse_next"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_ipmi_ctx_create) = lt_dlsym(dl_handle, "ipmi_ctx_create"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_ipmi_ctx_find_inband) = lt_dlsym(dl_handle, "ipmi_ctx_find_inband"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_ipmi_ctx_errormsg) = lt_dlsym(dl_handle, "ipmi_ctx_errormsg"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_ipmi_ctx_close) = lt_dlsym(dl_handle, "ipmi_ctx_close"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_ipmi_ctx_destroy) = lt_dlsym(dl_handle, "ipmi_ctx_destroy"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + return 1; +err: + fprintf(stderr, "%s\n", dl_error); + dl_handle = (void *)1; + return 0; +} +/* end of dynamic link library stuff */ + +/* Cleanup IPMI contexts */ +static void nut_freeipmi_cleanup(ipmi_fru_parse_ctx_t fru_parse_ctx, + ipmi_sdr_cache_ctx_t sdr_cache_ctx, + ipmi_sdr_parse_ctx_t sdr_parse_ctx) +{ + if (fru_parse_ctx) { + (*nut_ipmi_fru_parse_close_device_id) (fru_parse_ctx); + (*nut_ipmi_fru_parse_ctx_destroy) (fru_parse_ctx); + } + + if (sdr_cache_ctx) { + (*nut_ipmi_sdr_cache_ctx_destroy) (sdr_cache_ctx); + } + + if (sdr_parse_ctx) { + (*nut_ipmi_sdr_parse_ctx_destroy) (sdr_parse_ctx); + } +} + +/* Return 1 if supported, 0 otherwise */ +int is_ipmi_device_supported(ipmi_ctx_t ipmi_ctx, int ipmi_id) +{ + int ret = -1; + unsigned int area_type = 0; + unsigned int area_length = 0; + uint8_t areabuf[IPMI_FRU_PARSE_AREA_SIZE_MAX+1]; + ipmi_fru_parse_ctx_t fru_parse_ctx = NULL; + ipmi_sdr_cache_ctx_t sdr_cache_ctx = NULL; + ipmi_sdr_parse_ctx_t sdr_parse_ctx = NULL; + + /* Parse FRU information */ + if (!(fru_parse_ctx = (*nut_ipmi_fru_parse_ctx_create) (ipmi_ctx))) + { + fprintf(stderr, "ipmi_fru_parse_ctx_create()\n"); + return 0; + } + + /* lots of motherboards calculate checksums incorrectly */ + if ((*nut_ipmi_fru_parse_ctx_set_flags) (fru_parse_ctx, IPMI_FRU_PARSE_FLAGS_SKIP_CHECKSUM_CHECKS) < 0) + { + nut_freeipmi_cleanup(fru_parse_ctx, sdr_cache_ctx, sdr_parse_ctx); + return 0; + } + + if ((*nut_ipmi_fru_parse_open_device_id) (fru_parse_ctx, ipmi_id) < 0) + { + nut_freeipmi_cleanup(fru_parse_ctx, sdr_cache_ctx, sdr_parse_ctx); + return 0; + } + + do + { + /* clear fields */ + area_type = 0; + area_length = 0; + memset (areabuf, '\0', IPMI_FRU_PARSE_AREA_SIZE_MAX + 1); + + /* parse FRU buffer */ + if ((*nut_ipmi_fru_parse_read_data_area) (fru_parse_ctx, + &area_type, + &area_length, + areabuf, + IPMI_FRU_PARSE_AREA_SIZE_MAX) < 0) + { + nut_freeipmi_cleanup(fru_parse_ctx, sdr_cache_ctx, sdr_parse_ctx); + return 0; + } + + if (area_length) + { + if (area_type == IPMI_FRU_PARSE_AREA_TYPE_MULTIRECORD_POWER_SUPPLY_INFORMATION) + { + /* Found a POWER_SUPPLY record */ + nut_freeipmi_cleanup(fru_parse_ctx, sdr_cache_ctx, sdr_parse_ctx); + return 1; + } + } + } while ((ret = (*nut_ipmi_fru_parse_next) (fru_parse_ctx)) == 1); + + /* No need for further errors checking */ + nut_freeipmi_cleanup(fru_parse_ctx, sdr_cache_ctx, sdr_parse_ctx); + return 0; +} + +/* return NULL on error */ +nutscan_device_t * nutscan_scan_ipmi() +{ + ipmi_ctx_t ipmi_ctx = NULL; + nutscan_device_t * nut_dev = NULL; + nutscan_device_t * current_nut_dev = NULL; + int ret = -1; + int ipmi_id = 0; + char port_id[10]; + + if( !nutscan_avail_ipmi ) { + return NULL; + } + + /* Initialize the FreeIPMI library. */ + if (!(ipmi_ctx = (*nut_ipmi_ctx_create) ())) + { + /* we have to force cleanup, since exit handler is not yet installed */ + fprintf(stderr, "ipmi_ctx_create\n"); + return NULL; + } + + if ((ret = (*nut_ipmi_ctx_find_inband) (ipmi_ctx, + NULL, + 0, /* don't disable auto-probe */ + 0, + 0, + NULL, + 0, /* workaround flags, none by default */ + 0 /* flags */ + )) < 0) + { + fprintf(stderr, "ipmi_ctx_find_inband: %s\n", + (*nut_ipmi_ctx_errormsg) (ipmi_ctx)); + return NULL; + } + if (!ret) + { + /* No local IPMI device detected */ + return NULL; + } + + /* Loop through all possible devices */ + for (ipmi_id = 0 ; ipmi_id <= IPMI_FRU_DEVICE_ID_MAX ; ipmi_id++) { + + if (is_ipmi_device_supported(ipmi_ctx, ipmi_id)) { + + if ( (nut_dev = nutscan_new_device()) == NULL ) { + fprintf(stderr,"Memory allocation error\n"); + nutscan_free_device(current_nut_dev); + break; + } + + /* Fill the device structure (sufficient with driver and port) */ + nut_dev->type = TYPE_IPMI; + nut_dev->driver = strdup(NUT_IPMI_DRV_NAME); + sprintf(port_id, "id%x", ipmi_id); + nut_dev->port = strdup(port_id); + + current_nut_dev = nutscan_add_device_to_device( + current_nut_dev, + nut_dev); + + memset (port_id, 0, sizeof(port_id)); + } + } + + /* Final cleanup */ + if (ipmi_ctx) { + (*nut_ipmi_ctx_close) (ipmi_ctx); + (*nut_ipmi_ctx_destroy) (ipmi_ctx); + } + + return current_nut_dev; +} +#else /* WITH_IPMI */ +/* stub function */ nutscan_device_t * nutscan_scan_ipmi() { return NULL; } -#endif /* HAVE_FREEIPMI_FREEIPMI_H */ +#endif /* WITH_IPMI */ diff --git a/tools/nut-scanner/scan_nut.c b/tools/nut-scanner/scan_nut.c index bed4d1c..5fb8b70 100644 --- a/tools/nut-scanner/scan_nut.c +++ b/tools/nut-scanner/scan_nut.c @@ -122,7 +122,6 @@ nutscan_device_t * nutscan_scan_nut(const char* startIP, const char* stopIP, con int change_action_handler = 0; int i; struct scan_nut_arg *nut_arg; - #ifdef HAVE_PTHREAD pthread_t thread; pthread_t * thread_array = NULL; @@ -131,6 +130,10 @@ nutscan_device_t * nutscan_scan_nut(const char* startIP, const char* stopIP, con pthread_mutex_init(&dev_mutex,NULL); #endif + if( !nutscan_avail_nut ) { + return NULL; + } + /* Ignore SIGPIPE if the caller hasn't set a handler for it yet */ if( sigaction(SIGPIPE, NULL, &oldact) == 0 ) { if( oldact.sa_handler == SIG_DFL ) { diff --git a/tools/nut-scanner/scan_snmp.c b/tools/nut-scanner/scan_snmp.c index e6ffc54..32b2b1f 100644 --- a/tools/nut-scanner/scan_snmp.c +++ b/tools/nut-scanner/scan_snmp.c @@ -18,15 +18,14 @@ */ #include "common.h" - -#ifdef HAVE_NET_SNMP_NET_SNMP_CONFIG_H - #include "nut-scan.h" + +#ifdef WITH_SNMP + #include -#include -#include #include #include +#include /* workaround for buggy Net-SNMP config * from drivers/snmp-ups.h */ @@ -63,18 +62,196 @@ static nutscan_device_t * dev_ret = NULL; #ifdef HAVE_PTHREAD static pthread_mutex_t dev_mutex; +static pthread_mutex_t lib_mutex; static pthread_t * thread_array = NULL; static int thread_count = 0; #endif long g_usec_timeout ; +/* dynamic link library stuff */ +static lt_dlhandle dl_handle = NULL; +static const char *dl_error = NULL; + +static void (*nut_init_snmp)(const char *type); +static void (*nut_snmp_sess_init)(netsnmp_session * session); +static void * (*nut_snmp_sess_open)(struct snmp_session *session); +static int (*nut_snmp_sess_close)(void *handle); +static struct snmp_session * (*nut_snmp_sess_session)(void *handle); +static void * (*nut_snmp_parse_oid)(const char *input, oid *objid, + size_t *objidlen); +static struct snmp_pdu * (*nut_snmp_pdu_create) (int command ); +netsnmp_variable_list * (*nut_snmp_add_null_var)(netsnmp_pdu *pdu, + const oid *objid, size_t objidlen); +static int (*nut_snmp_sess_synch_response) (void *sessp, netsnmp_pdu *pdu, + netsnmp_pdu **response); +static int (*nut_snmp_oid_compare) (const oid *in_name1, size_t len1, + const oid *in_name2, size_t len2); +static void (*nut_snmp_free_pdu) (netsnmp_pdu *pdu); +static int (*nut_generate_Ku)(const oid * hashtype, u_int hashtype_len, + u_char * P, size_t pplen, u_char * Ku, size_t * kulen); +static const char * (*nut_snmp_api_errstring) (int snmp_errnumber); +static int (*nut_snmp_errno); +static oid * (*nut_usmAESPrivProtocol); +static oid * (*nut_usmHMACMD5AuthProtocol); +static oid * (*nut_usmHMACSHA1AuthProtocol); +static oid * (*nut_usmDESPrivProtocol); + +/* return 0 on error */ +int nutscan_load_snmp_library() +{ +#ifdef HAVE_PTHREAD + pthread_mutex_lock(&lib_mutex); +#endif + + if( dl_handle != NULL ) { + /* if previous init failed */ + if( dl_handle == (void *)1 ) { + return 0; + } + /* init has already been done */ + return 1; + } + + if( lt_dlinit() != 0 ) { + fprintf(stderr, "Error initializing lt_init\n"); + return 0; + } + + dl_handle = lt_dlopenext("libnetsnmp"); + if (!dl_handle) { + dl_error = lt_dlerror(); + goto err; + } + + lt_dlerror(); /* Clear any existing error */ + *(void **) (&nut_init_snmp) = lt_dlsym(dl_handle, "init_snmp"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_snmp_sess_init) = lt_dlsym(dl_handle, + "snmp_sess_init"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_snmp_sess_open) = lt_dlsym(dl_handle, + "snmp_sess_open"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_snmp_sess_close) = lt_dlsym(dl_handle, + "snmp_sess_close"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_snmp_sess_session) = lt_dlsym(dl_handle, + "snmp_sess_session"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_snmp_parse_oid) = lt_dlsym(dl_handle, + "snmp_parse_oid"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_snmp_pdu_create) = lt_dlsym(dl_handle, + "snmp_pdu_create"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_snmp_add_null_var) = lt_dlsym(dl_handle, + "snmp_add_null_var"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_snmp_sess_synch_response) = lt_dlsym(dl_handle, + "snmp_sess_synch_response"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_snmp_oid_compare) = lt_dlsym(dl_handle, + "snmp_oid_compare"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_snmp_free_pdu) = lt_dlsym(dl_handle,"snmp_free_pdu"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_generate_Ku) = lt_dlsym(dl_handle, "generate_Ku"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_snmp_api_errstring) = lt_dlsym(dl_handle, + "snmp_api_errstring"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_snmp_errno) = lt_dlsym(dl_handle, "snmp_errno"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_usmAESPrivProtocol) = lt_dlsym(dl_handle, + "usmAESPrivProtocol"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_usmHMACMD5AuthProtocol) = lt_dlsym(dl_handle, + "usmHMACMD5AuthProtocol"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_usmHMACSHA1AuthProtocol) = lt_dlsym(dl_handle, + "usmHMACSHA1AuthProtocol"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_usmDESPrivProtocol) = lt_dlsym(dl_handle, + "usmDESPrivProtocol"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + +#ifdef HAVE_PTHREAD + pthread_mutex_unlock(&dev_mutex); +#endif + return 1; +err: + fprintf(stderr, "%s\n", dl_error); + dl_handle = (void *)1; +#ifdef HAVE_PTHREAD + pthread_mutex_unlock(&dev_mutex); +#endif + return 0; +} +/* end of dynamic link library stuff */ + static void scan_snmp_add_device(nutscan_snmp_t * sec, struct snmp_pdu *response,char * mib) { nutscan_device_t * dev = NULL; struct snmp_session * session; char * buf; - session = snmp_sess_session(sec->handle); + session = (*nut_snmp_sess_session)(sec->handle); + if(session == NULL) { + return; + } /* SNMP device found */ dev = nutscan_new_device(); dev->type = TYPE_SNMP; @@ -147,21 +324,21 @@ static struct snmp_pdu * scan_snmp_get_manufacturer(char* oid_str,void* handle) /* create and send request. */ name_len = MAX_OID_LEN; - if (!snmp_parse_oid(oid_str, name, &name_len)) { + if (!(*nut_snmp_parse_oid)(oid_str, name, &name_len)) { index++; return NULL; } - pdu = snmp_pdu_create(SNMP_MSG_GET); + pdu = (*nut_snmp_pdu_create)(SNMP_MSG_GET); if (pdu == NULL) { index++; return NULL; } - snmp_add_null_var(pdu, name, name_len); + (*nut_snmp_add_null_var)(pdu, name, name_len); - status = snmp_sess_synch_response(handle,pdu, &response); + status = (*nut_snmp_sess_synch_response)(handle,pdu, &response); if( response == NULL ) { index++; return NULL; @@ -170,11 +347,11 @@ static struct snmp_pdu * scan_snmp_get_manufacturer(char* oid_str,void* handle) if(status!=STAT_SUCCESS||response->errstat!=SNMP_ERR_NOERROR|| response->variables == NULL || response->variables->name == NULL || - snmp_oid_compare(response->variables->name, + (*nut_snmp_oid_compare)(response->variables->name, response->variables->name_length, name, name_len) != 0 || response->variables->val.string == NULL ) { - snmp_free_pdu(response); + (*nut_snmp_free_pdu)(response); index++; return NULL; } @@ -198,7 +375,7 @@ static void try_all_oid(void * arg) scan_snmp_add_device(sec,response,snmp_device_table[index].mib); - snmp_free_pdu(response); + (*nut_snmp_free_pdu)(response); response = NULL; index++; @@ -207,7 +384,7 @@ static void try_all_oid(void * arg) static int init_session(struct snmp_session * snmp_sess, nutscan_snmp_t * sec) { - snmp_sess_init(snmp_sess); + (*nut_snmp_sess_init)(snmp_sess); snmp_sess->peername = sec->peername; @@ -279,16 +456,17 @@ static int init_session(struct snmp_session * snmp_sess, nutscan_snmp_t * sec) snmp_sess->securityAuthKeyLen = USM_AUTH_KU_LEN; /* default to MD5 */ - snmp_sess->securityAuthProto = usmHMACMD5AuthProtocol; - snmp_sess->securityAuthProtoLen =sizeof(usmHMACMD5AuthProtocol)/ - sizeof(oid); + snmp_sess->securityAuthProto = (*nut_usmHMACMD5AuthProtocol); + snmp_sess->securityAuthProtoLen = + sizeof((*nut_usmHMACMD5AuthProtocol))/ + sizeof(oid); if( sec->authProtocol ) { if (strcmp(sec->authProtocol, "SHA") == 0) { snmp_sess->securityAuthProto = - usmHMACSHA1AuthProtocol; + (*nut_usmHMACSHA1AuthProtocol); snmp_sess->securityAuthProtoLen = - sizeof(usmHMACSHA1AuthProtocol)/ + sizeof((*nut_usmHMACSHA1AuthProtocol))/ sizeof(oid); } else { @@ -303,7 +481,7 @@ static int init_session(struct snmp_session * snmp_sess, nutscan_snmp_t * sec) /* set the authentication key to a MD5/SHA1 hashed version of * our passphrase (must be at least 8 characters long) */ - if (generate_Ku(snmp_sess->securityAuthProto, + if ((*nut_generate_Ku)(snmp_sess->securityAuthProto, snmp_sess->securityAuthProtoLen, (u_char *) sec->authPassword, strlen(sec->authPassword), @@ -321,15 +499,17 @@ static int init_session(struct snmp_session * snmp_sess, nutscan_snmp_t * sec) } /* default to DES */ - snmp_sess->securityPrivProto=usmDESPrivProtocol; + snmp_sess->securityPrivProto=(*nut_usmDESPrivProtocol); snmp_sess->securityPrivProtoLen = - sizeof(usmDESPrivProtocol)/sizeof(oid); + sizeof((*nut_usmDESPrivProtocol))/sizeof(oid); if( sec->privProtocol ) { if (strcmp(sec->privProtocol, "AES") == 0) { - snmp_sess->securityPrivProto=usmAESPrivProtocol; + snmp_sess->securityPrivProto= + (*nut_usmAESPrivProtocol); snmp_sess->securityPrivProtoLen = - sizeof(usmAESPrivProtocol)/sizeof(oid); + sizeof((*nut_usmAESPrivProtocol))/ + sizeof(oid); } else { if (strcmp(sec->privProtocol, "DES") != 0) { @@ -344,7 +524,7 @@ static int init_session(struct snmp_session * snmp_sess, nutscan_snmp_t * sec) /* set the private key to a MD5/SHA hashed version of * our passphrase (must be at least 8 characters long) */ snmp_sess->securityPrivKeyLen = USM_PRIV_KU_LEN; - if (generate_Ku(snmp_sess->securityAuthProto, + if ((*nut_generate_Ku)(snmp_sess->securityAuthProto, snmp_sess->securityAuthProtoLen, (u_char *) sec->privPassword, strlen(sec->privPassword), @@ -365,7 +545,7 @@ static void * try_SysOID(void * arg) { struct snmp_session snmp_sess; void * handle; - struct snmp_pdu *pdu, *response = NULL; + struct snmp_pdu *pdu, *response = NULL, *resp = NULL; oid name[MAX_OID_LEN]; size_t name_len = MAX_OID_LEN; nutscan_snmp_t * sec = (nutscan_snmp_t *)arg; @@ -381,7 +561,7 @@ static void * try_SysOID(void * arg) snmp_sess.timeout = g_usec_timeout; /* Open the session */ - handle = snmp_sess_open(&snmp_sess); /* establish the session */ + handle = (*nut_snmp_sess_open)(&snmp_sess); /* establish the session */ if (handle == NULL) { fprintf(stderr,"Failed to open SNMP session for %s.\n", sec->peername); @@ -389,24 +569,24 @@ static void * try_SysOID(void * arg) } /* create and send request. */ - if (!snmp_parse_oid(SysOID, name, &name_len)) { + if (!(*nut_snmp_parse_oid)(SysOID, name, &name_len)) { fprintf(stderr,"SNMP errors: %s\n", - snmp_api_errstring(snmp_errno)); - snmp_sess_close(handle); + (*nut_snmp_api_errstring)((*nut_snmp_errno))); + (*nut_snmp_sess_close)(handle); goto try_SysOID_free; } - pdu = snmp_pdu_create(SNMP_MSG_GET); + pdu = (*nut_snmp_pdu_create)(SNMP_MSG_GET); if (pdu == NULL) { fprintf(stderr,"Not enough memory\n"); - snmp_sess_close(handle); + (*nut_snmp_sess_close)(handle); goto try_SysOID_free; } - snmp_add_null_var(pdu, name, name_len); + (*nut_snmp_add_null_var)(pdu, name, name_len); - snmp_sess_synch_response(handle, + (*nut_snmp_sess_synch_response)(handle, pdu, &response); if (response) { @@ -424,25 +604,27 @@ static void * try_SysOID(void * arg) continue; } name_len = MAX_OID_LEN; - if (!snmp_parse_oid( + if (!(*nut_snmp_parse_oid)( snmp_device_table[index].sysoid, name, &name_len)) { index++; continue; } - if ( snmp_oid_compare( + if ( (*nut_snmp_oid_compare)( response->variables->val.objid, response->variables->val_len/sizeof(oid), name, name_len) == 0 ) { /* we have found a relevent sysoid */ - snmp_free_pdu(response); - response = scan_snmp_get_manufacturer( + resp = scan_snmp_get_manufacturer( snmp_device_table[index].oid, handle); - scan_snmp_add_device(sec,response, - snmp_device_table[index].mib); - sysoid_found = 1; + if( resp != NULL ) { + scan_snmp_add_device(sec,resp, + snmp_device_table[index].mib); + sysoid_found = 1; + (*nut_snmp_free_pdu)(resp); + } } index++; } @@ -453,11 +635,11 @@ static void * try_SysOID(void * arg) try_all_oid(sec); } - snmp_free_pdu(response); + (*nut_snmp_free_pdu)(response); response = NULL; } - snmp_sess_close(handle); + (*nut_snmp_sess_close)(handle); try_SysOID_free: if( sec->peername ) { @@ -478,12 +660,18 @@ nutscan_device_t * nutscan_scan_snmp(const char * start_ip, const char * stop_ip pthread_t thread; pthread_mutex_init(&dev_mutex,NULL); + pthread_mutex_init(&lib_mutex,NULL); #endif + if( !nutscan_avail_snmp ) { + return NULL; + } + + g_usec_timeout = usec_timeout; /* Initialize the SNMP library */ - init_snmp("nut-scanner"); + (*nut_init_snmp)("nut-scanner"); ip_str = nutscan_ip_iter_init(&ip, start_ip, stop_ip); @@ -515,6 +703,11 @@ nutscan_device_t * nutscan_scan_snmp(const char * start_ip, const char * stop_ip return dev_ret; } -#endif /* HAVE_NET_SNMP_NET_SNMP_CONFIG_H */ +#else /* WITH_SNMP */ +nutscan_device_t * nutscan_scan_snmp(const char * start_ip, const char * stop_ip,long usec_timeout, nutscan_snmp_t * sec) +{ + return NULL; +} +#endif /* WITH_SNMP */ diff --git a/tools/nut-scanner/scan_usb.c b/tools/nut-scanner/scan_usb.c index 8ce8759..3fac8a6 100644 --- a/tools/nut-scanner/scan_usb.c +++ b/tools/nut-scanner/scan_usb.c @@ -18,12 +18,99 @@ */ #include "common.h" -#ifdef HAVE_USB_H +#include "nut-scan.h" + +#ifdef WITH_USB #include "upsclient.h" #include "nutscan-usb.h" #include #include -#include "nutscan-device.h" +#include + +/* dynamic link library stuff */ +static lt_dlhandle dl_handle = NULL; +static const char *dl_error = NULL; +static int (*nut_usb_close)(usb_dev_handle *dev); +static int (*nut_usb_find_busses)(void); +static char * (*nut_usb_strerror)(void); +static void (*nut_usb_init)(void); +static int (*nut_usb_get_string_simple)(usb_dev_handle *dev, int index, + char *buf, size_t buflen); +static struct usb_bus * (*nut_usb_busses); +static usb_dev_handle * (*nut_usb_open)(struct usb_device *dev); +static int (*nut_usb_find_devices)(void); + +/* return 0 on error */ +int nutscan_load_usb_library() +{ + if( dl_handle != NULL ) { + /* if previous init failed */ + if( dl_handle == (void *)1 ) { + return 0; + } + /* init has already been done */ + return 1; + } + + if( lt_dlinit() != 0 ) { + fprintf(stderr, "Error initializing lt_init\n"); + return 0; + } + + dl_handle = lt_dlopenext("libusb"); + if (!dl_handle) { + dl_error = lt_dlerror(); + goto err; + } + lt_dlerror(); /* Clear any existing error */ + *(void **) (&nut_usb_close) = lt_dlsym(dl_handle, "usb_close"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_usb_find_busses) = lt_dlsym(dl_handle, "usb_find_busses"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_usb_strerror) = lt_dlsym(dl_handle, "usb_strerror"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_usb_init) = lt_dlsym(dl_handle, "usb_init"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_usb_get_string_simple) = lt_dlsym(dl_handle, + "usb_get_string_simple"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_usb_busses) = lt_dlsym(dl_handle, "usb_busses"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_usb_open) = lt_dlsym(dl_handle, "usb_open"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **)(&nut_usb_find_devices) = lt_dlsym(dl_handle,"usb_find_devices"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + return 1; +err: + fprintf(stderr, "%s\n", dl_error); + dl_handle = (void *)1; + return 0; +} +/* end of dynamic link library stuff */ static char* is_usb_device_supported(usb_device_id_t *usb_device_id_list, int dev_VendorID, int dev_ProductID) @@ -57,12 +144,16 @@ nutscan_device_t * nutscan_scan_usb() nutscan_device_t * nut_dev = NULL; nutscan_device_t * current_nut_dev = NULL; - /* libusb base init */ - usb_init(); - usb_find_busses(); - usb_find_devices(); + if( !nutscan_avail_usb ) { + return NULL; + } - for (bus = usb_busses; bus; bus = bus->next) { + /* libusb base init */ + (*nut_usb_init)(); + (*nut_usb_find_busses)(); + (*nut_usb_find_devices)(); + + for (bus = (*nut_usb_busses); bus; bus = bus->next) { for (dev = bus->devices; dev; dev = dev->next) { if ((driver_name = is_usb_device_supported(usb_device_table, @@ -70,17 +161,17 @@ nutscan_device_t * nutscan_scan_usb() dev->descriptor.idProduct)) != NULL) { /* open the device */ - udev = usb_open(dev); + udev = (*nut_usb_open)(dev); if (!udev) { fprintf(stderr,"Failed to open device, \ skipping. (%s)\n", - usb_strerror()); + (*nut_usb_strerror)()); continue; } /* get serial number */ if (dev->descriptor.iSerialNumber) { - ret = usb_get_string_simple(udev, + ret = (*nut_usb_get_string_simple)(udev, dev->descriptor.iSerialNumber, string, sizeof(string)); if (ret > 0) { @@ -89,7 +180,7 @@ nutscan_device_t * nutscan_scan_usb() } /* get product name */ if (dev->descriptor.iProduct) { - ret = usb_get_string_simple(udev, + ret = (*nut_usb_get_string_simple)(udev, dev->descriptor.iProduct, string, sizeof(string)); if (ret > 0) { @@ -99,7 +190,7 @@ nutscan_device_t * nutscan_scan_usb() /* get vendor name */ if (dev->descriptor.iManufacturer) { - ret = usb_get_string_simple(udev, + ret = (*nut_usb_get_string_simple)(udev, dev->descriptor.iManufacturer, string, sizeof(string)); if (ret > 0) { @@ -157,12 +248,17 @@ nutscan_device_t * nutscan_scan_usb() memset (string, 0, sizeof(string)); - usb_close(udev); + (*nut_usb_close)(udev); } } } return current_nut_dev; } -#endif /* HAVE_USB_H */ +#else /* WITH_USB */ +nutscan_device_t * nutscan_scan_usb() +{ + return NULL; +} +#endif /* WITH_USB */ diff --git a/tools/nut-scanner/scan_xml_http.c b/tools/nut-scanner/scan_xml_http.c index 7c68a65..b66f42f 100644 --- a/tools/nut-scanner/scan_xml_http.c +++ b/tools/nut-scanner/scan_xml_http.c @@ -18,16 +18,85 @@ */ #include "common.h" +#include "nut-scan.h" #ifdef WITH_NEON -#include +#include #include +#include +#include +#include #include #include #include #include -#include #include -#include "nutscan-device.h" +#include + +/* dynamic link library stuff */ +static lt_dlhandle dl_handle = NULL; +static const char *dl_error = NULL; + +static void (*nut_ne_xml_push_handler)(ne_xml_parser *p, + ne_xml_startelm_cb *startelm, + ne_xml_cdata_cb *cdata, + ne_xml_endelm_cb *endelm, + void *userdata); +static void (*nut_ne_xml_destroy)(ne_xml_parser *p); +static ne_xml_parser * (*nut_ne_xml_create)(void); +static int (*nut_ne_xml_parse)(ne_xml_parser *p, const char *block, size_t len); + +/* return 0 on error */ +int nutscan_load_neon_library() +{ + + if( dl_handle != NULL ) { + /* if previous init failed */ + if( dl_handle == (void *)1 ) { + return 0; + } + /* init has already been done */ + return 1; + } + + if( lt_dlinit() != 0 ) { + fprintf(stderr, "Error initializing lt_init\n"); + return 0; + } + + dl_handle = lt_dlopenext("libneon"); + if (!dl_handle) { + dl_error = lt_dlerror(); + goto err; + } + + lt_dlerror(); /* Clear any existing error */ + *(void **) (&nut_ne_xml_push_handler) = lt_dlsym(dl_handle, + "ne_xml_push_handler"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_ne_xml_destroy) = lt_dlsym(dl_handle,"ne_xml_destroy"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_ne_xml_create) = lt_dlsym(dl_handle,"ne_xml_create"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + *(void **) (&nut_ne_xml_parse) = lt_dlsym(dl_handle,"ne_xml_parse"); + if ((dl_error = lt_dlerror()) != NULL) { + goto err; + } + + return 1; +err: + fprintf(stderr, "%s\n", dl_error); + dl_handle = (void *)1; + return 0; +} static int startelm_cb(void *userdata, int parent, const char *nspace, const char *name, const char **atts) { nutscan_device_t * dev = (nutscan_device_t *)userdata; @@ -63,6 +132,9 @@ nutscan_device_t * nutscan_scan_xml_http(long usec_timeout) nutscan_device_t * nut_dev = NULL; nutscan_device_t * current_nut_dev = NULL; + if( !nutscan_avail_xml_http ) { + return NULL; + } if((peerSocket = socket(AF_INET, SOCK_DGRAM, 0)) != -1) { @@ -114,10 +186,12 @@ nutscan_device_t * nutscan_scan_xml_http(long usec_timeout) continue; } + if( getnameinfo( + (struct sockaddr *)&sockAddress, + sizeof(struct sockaddr_in),string, + sizeof(string),NULL,0, + NI_NUMERICHOST) != 0) { - if( inet_ntop(AF_INET, - &(sockAddress.sin_addr), - string,sizeof(buf)) == NULL ) { fprintf(stderr, "Error converting IP address \ : %d\n",errno); @@ -133,11 +207,11 @@ nutscan_device_t * nutscan_scan_xml_http(long usec_timeout) nut_dev->type = TYPE_XML; /* Try to read device type */ - ne_xml_parser *parser = ne_xml_create(); - ne_xml_push_handler(parser, startelm_cb, NULL, - NULL, nut_dev); - ne_xml_parse(parser, buf, strlen(buf)); - ne_xml_destroy(parser); + ne_xml_parser *parser = (*nut_ne_xml_create)(); + (*nut_ne_xml_push_handler)(parser, startelm_cb, + NULL, NULL, nut_dev); + (*nut_ne_xml_parse)(parser, buf, strlen(buf)); + (*nut_ne_xml_destroy)(parser); nut_dev->driver = strdup("netxml-ups"); sprintf(buf,"http://%s",string); @@ -157,4 +231,9 @@ nutscan_device_t * nutscan_scan_xml_http(long usec_timeout) return current_nut_dev; } +#else /* WITH_NEON */ +nutscan_device_t * nutscan_scan_xml_http(long usec_timeout) +{ + return NULL; +} #endif /* WITH_NEON */ diff --git a/tools/nut-snmpinfo.py b/tools/nut-snmpinfo.py index 8489db1..89cc359 100755 --- a/tools/nut-snmpinfo.py +++ b/tools/nut-snmpinfo.py @@ -79,7 +79,7 @@ output_file.write( "/* SNMP IDs device table */\n" ) output_file.write( "static snmp_device_id_t snmp_device_table[] = {\n" ) for filename in glob.glob('../drivers/*-mib.c'): - list_of_line = file(filename,'r').read().split(';') + list_of_line = open(filename,'r').read().split(';') for line in list_of_line: if "mib2nut_info_t" in line: #clean up line @@ -116,7 +116,7 @@ for filename in glob.glob('../drivers/*-mib.c'): line = line.rstrip(" ") line2 = line.split(" ") - sysoid = "" + sysoid = "" for elem in line2: if elem[0] == "\"": clean_elem = re.sub("\"", "", elem)