remove compile-time option to get configuration from LDAP
This commit is contained in:
@@ -38,6 +38,7 @@ v.0.5dev (ongoing development)
|
||||
+ new ConnectionType pertelian in hd44780 driver (Matteo Pillon)
|
||||
+ new ConnectionType lcd2usb in hd44780 driver
|
||||
+ make LCDd's GoodBye message configurable
|
||||
- remove compile-time option to read configuration from LDAP
|
||||
|
||||
v.0.5.1
|
||||
+ config file support in lcdproc client (Andrew Foss)
|
||||
|
||||
@@ -41,9 +41,6 @@ need some additional programs or libraries installed:
|
||||
http://cyberelk.net/tim/xmlto/ and
|
||||
http://www.stack.nl/~dimitri/doxygen/
|
||||
|
||||
* OpenLDAP if you --enable-ldap, see http://www.openldap.org/software/
|
||||
Please note that OpenlDAP support is currently very experimental.
|
||||
|
||||
* libusb if you --enable-libusb, see http://libusb.sourceforge.net/
|
||||
|
||||
* G15daemon, libg15 and libg15render (>= 1.1.1) for use with the 'g15' driver,
|
||||
|
||||
@@ -6,7 +6,7 @@ bin_PROGRAMS = lcdexec
|
||||
|
||||
lcdexec_SOURCES = lcdexec.c menu.c menu.h
|
||||
|
||||
lcdexec_LDADD = ../../shared/libLCDstuff.a @ldap_libs@
|
||||
lcdexec_LDADD = ../../shared/libLCDstuff.a
|
||||
|
||||
AM_CPPFLAGS = -I$(top_srcdir) -DSYSCONFDIR=\"$(sysconfdir)\"
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ bin_PROGRAMS = lcdproc
|
||||
|
||||
lcdproc_SOURCES = main.c main.h mode.c mode.h batt.c batt.h chrono.c chrono.h cpu.c cpu.h cpu_smp.c cpu_smp.h disk.c disk.h load.c load.h mem.c mem.h eyebox.c eyebox.h machine.h machine_Linux.c machine_OpenBSD.c machine_FreeBSD.c machine_NetBSD.c machine_Darwin.c machine_SunOS.c util.c util.h iface.c iface.h
|
||||
|
||||
lcdproc_LDADD = ../../shared/libLCDstuff.a @ldap_libs@
|
||||
lcdproc_LDADD = ../../shared/libLCDstuff.a
|
||||
|
||||
if DARWIN
|
||||
AM_LDFLAGS = -framework CoreFoundation -framework IOKit
|
||||
|
||||
@@ -6,7 +6,7 @@ bin_PROGRAMS = lcdvc
|
||||
|
||||
lcdvc_SOURCES = lcdvc.c lcdvc.h lcd_link.c lcd_link.h vc_link.c vc_link.h
|
||||
|
||||
lcdvc_LDADD = ../../shared/libLCDstuff.a @ldap_libs@
|
||||
lcdvc_LDADD = ../../shared/libLCDstuff.a
|
||||
|
||||
if DARWIN
|
||||
AM_LDFLAGS = -framework CoreFoundation -framework IOKit
|
||||
|
||||
-177
@@ -327,183 +327,6 @@ else
|
||||
fi
|
||||
|
||||
|
||||
dnl ######################################################################
|
||||
dnl Open LDAP
|
||||
dnl based on code from perdition http://www.vergenet.net/linux/perdition/
|
||||
dnl
|
||||
dnl not all options have effect at the moment
|
||||
|
||||
AC_SUBST(ldap_libs)
|
||||
AC_SUBST(ldap_includes)
|
||||
AC_SUBST(ldap_schemadir)
|
||||
|
||||
AC_MSG_CHECKING([if LDAP support has been enabled]);
|
||||
AC_ARG_ENABLE(
|
||||
ldap,
|
||||
[ --enable-ldap compile with LDAP support. ],
|
||||
[
|
||||
if test "$enable_ldap" = "yes"; then
|
||||
AC_MSG_RESULT(yes)
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
],
|
||||
[
|
||||
enable_ldap="no";
|
||||
AC_MSG_RESULT(no)
|
||||
]
|
||||
)
|
||||
|
||||
if test "$enable_ldap" = "yes"; then
|
||||
AC_ARG_WITH(
|
||||
ldap-includes,
|
||||
[ --with-ldap-includes=DIR
|
||||
Open LDAP include files are in DIR. ],
|
||||
[
|
||||
if test "$withval" = "no"; then
|
||||
ldap_build_dir="";
|
||||
else
|
||||
ldap_includepath="$withval"
|
||||
fi
|
||||
],
|
||||
[
|
||||
AC_MSG_CHECKING(OpenLDAP include path)
|
||||
for ldap_includepath in /usr/openldap/include /usr/local/openldap/include \
|
||||
/usr/include/openldap /usr/local/include/openldap \
|
||||
/usr/include /usr/local/include; do
|
||||
if test -f "${ldap_includepath}/ldap.h"; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
AC_MSG_RESULT($ldap_includepath)
|
||||
]
|
||||
)
|
||||
fi
|
||||
|
||||
ldap_includes="-I$ldap_includepath"
|
||||
|
||||
if test "$enable_ldap" = "yes"; then
|
||||
AC_ARG_WITH(
|
||||
ldap-libraries,
|
||||
[ --with-ldap-libraries=DIR
|
||||
Open LDAP library files are in DIR. ],
|
||||
[
|
||||
if test "$withval" = "no"; then
|
||||
ldap_build_dir="";
|
||||
else
|
||||
ldap_libpath="$withval"
|
||||
fi
|
||||
],
|
||||
[
|
||||
AC_MSG_CHECKING(OpenLDAP library path)
|
||||
for ldap_libpath in /usr/openldap/lib /usr/local/openldap/lib \
|
||||
/usr/lib/openldap /usr/local/lib/openldap \
|
||||
/usr/lib /usr/local/lib; do
|
||||
if test -f "${ldap_libpath}/libldap.a" \
|
||||
-o -f "${ldap_libpath}/libldap.so"; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
AC_MSG_RESULT($ldap_libpath)
|
||||
]
|
||||
)
|
||||
fi
|
||||
|
||||
ldap_libs="-L$ldap_libpath -lldap -llber"
|
||||
|
||||
if test "$enable_ldap" = "yes"; then
|
||||
AC_CHECK_FILE(
|
||||
$ldap_includepath/ldap.h,
|
||||
[ : ] ,
|
||||
[ enable_ldap="no" ]
|
||||
)
|
||||
fi
|
||||
|
||||
if test "$enable_ldap" = "yes"; then
|
||||
AC_CHECK_LIB(
|
||||
ldap,
|
||||
ldap_url_parse,
|
||||
[ : ],
|
||||
[ enable_ldap="no" ],
|
||||
$ldap_libs
|
||||
)
|
||||
fi
|
||||
|
||||
if test "$enable_ldap" = "yes"; then
|
||||
AC_MSG_CHECKING(OpenLDAP lud_exts in LDAPURLDesc)
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>
|
||||
#include <lber.h>
|
||||
#include <ldap.h>]], [[LDAPURLDesc ludp;
|
||||
ludp.lud_exts[0] = NULL;]])],[AC_MSG_RESULT(yes)
|
||||
AC_DEFINE(WITH_LDAP_LUD_EXTS, 1, Compile with LDAP lud_exts)],[AC_MSG_RESULT(no)
|
||||
AC_MSG_WARN(
|
||||
""
|
||||
"************************************************************"
|
||||
"* Password and Username support will not be built in the"
|
||||
"* LDAP module. For Password and Username support compile"
|
||||
"* openldap2. Available from openldap.org"
|
||||
"************************************************************"
|
||||
)
|
||||
])
|
||||
fi
|
||||
|
||||
if test "$enable_ldap" = "yes"; then
|
||||
AC_CHECK_LIB(ldap, ldap_set_option,
|
||||
AC_DEFINE(WITH_LDAP_SET_OPTION, 1, Compile with LDAP set_option),
|
||||
AC_MSG_WARN(
|
||||
""
|
||||
"************************************************************"
|
||||
"* Cannot expicitly set network timeout or ldap protocol"
|
||||
"* version. For ldap_set_option support please use openlap2."
|
||||
"* Available from openldap.org"
|
||||
"************************************************************"
|
||||
),)
|
||||
fi
|
||||
|
||||
if test "$enable_ldap" = "yes"; then
|
||||
AC_ARG_WITH(
|
||||
ldap-schema-directory,
|
||||
[ --with-ldap-schema-directory=DIR
|
||||
Open LDAP schema files are in DIR. ],
|
||||
[
|
||||
if test "$withval" = "no"; then
|
||||
ldap_schemadir="";
|
||||
else
|
||||
ldap_schemadir="$withval"
|
||||
fi
|
||||
],
|
||||
[
|
||||
AC_MSG_CHECKING(OpenLDAP schema path)
|
||||
for ldap_schemadir in /etc/openldap/schema /etc/ldap/schema \
|
||||
/usr/local/openldap/etc/schema; do
|
||||
if test -f "${ldap_schemadir}/openldap.schema"; then
|
||||
break
|
||||
fi
|
||||
ldap_schemadir="Not found"
|
||||
done
|
||||
AC_MSG_RESULT($ldap_schemadir)
|
||||
if test "$ldap_schemadir" = "Not found"; then
|
||||
AC_MSG_WARN(
|
||||
""
|
||||
"************************************************************"
|
||||
"* Could not find OpenLDAP schema directory."
|
||||
"* lcdproc.schema will not be installed"
|
||||
"************************************************************"
|
||||
)
|
||||
ldap_schemadir=""
|
||||
fi
|
||||
]
|
||||
)
|
||||
fi
|
||||
|
||||
if test "$enable_ldap" = "yes"; then
|
||||
AC_DEFINE(WITH_LDAP_SUPPORT, 1, Compile in LDAP support)
|
||||
else
|
||||
ldap_libs="";
|
||||
ldap_includes="";
|
||||
fi
|
||||
|
||||
|
||||
dnl Select drivers to build
|
||||
LCD_DRIVERS_SELECT
|
||||
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ sbin_PROGRAMS=LCDd
|
||||
|
||||
LCDd_SOURCES= client.c client.h clients.c clients.h input.c input.h main.c main.h menuitem.c menuitem.h menu.c menu.h menuscreens.c menuscreens.h parse.c parse.h render.c render.h screen.c screen.h screenlist.c screenlist.h serverscreens.c serverscreens.h sock.c sock.h widget.c widget.h drivers.c drivers.h driver.c driver.h
|
||||
|
||||
LDADD = ../shared/libLCDstuff.a commands/libLCDcommands.a @ldap_libs@
|
||||
LDADD = ../shared/libLCDstuff.a commands/libLCDcommands.a
|
||||
|
||||
if !DARWIN
|
||||
AM_LDFLAGS = -rdynamic -uget_args
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ libLCDstuff_a_SOURCES = LL.c LL.h sockets.c sockets.h str.c str.h configfile.c c
|
||||
|
||||
libLCDstuff_a_LIBADD = @LIBOBJS@
|
||||
|
||||
AM_CPPFLAGS = @ldap_includes@ -I$(top_srcdir)
|
||||
AM_CPPFLAGS = -I$(top_srcdir)
|
||||
|
||||
EXTRA_DIST = Makefile.in
|
||||
|
||||
|
||||
+64
-256
@@ -1,16 +1,16 @@
|
||||
/*
|
||||
* configfile.c
|
||||
* This file is part of LCDd, the lcdproc server.
|
||||
/** \file configfile.c
|
||||
* Define routines to read INI-file like files.
|
||||
*/
|
||||
|
||||
/* This file is part of LCDd, the lcdproc server.
|
||||
*
|
||||
* This file is released under the GNU General Public License. Refer to the
|
||||
* COPYING file distributed with this package.
|
||||
*
|
||||
* Copyright(c) 2001, Joris Robijn
|
||||
* (c) 2003, Rene Wagner
|
||||
* (c) 2006,2007 Peter Marschall
|
||||
*
|
||||
*
|
||||
* Defines routines to read ini-file-like files.
|
||||
* Optionally retrieves settings from an LDAP directory(OpenLDAP 2.1.x)
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
@@ -20,10 +20,6 @@
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef WITH_LDAP_SUPPORT
|
||||
# include <ldap.h>
|
||||
#endif /* WITH_LDAP_SUPPORT */
|
||||
|
||||
#include "shared/report.h"
|
||||
|
||||
|
||||
@@ -56,28 +52,12 @@ static int process_config(section **current_section, const char *source_descr, F
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef WITH_LDAP_SUPPORT
|
||||
static int connect_to_ldap(void);
|
||||
|
||||
static LDAP *ld = NULL;
|
||||
int use_ldap = 0;
|
||||
|
||||
static char *ldap_host = NULL, *ldap_base_dn = NULL;
|
||||
int ldap_port;
|
||||
|
||||
/* not supported for now
|
||||
* char ldap_user[255] = "",
|
||||
* ldap_pwd[255] = "";
|
||||
*/
|
||||
#endif /* WITH_LDAP_SUPPORT */
|
||||
|
||||
|
||||
/**** PUBLIC FUNCTIONS ****/
|
||||
|
||||
/** Parse configuration from INI-file style config file into memory.
|
||||
* \param filename Name of the config file.
|
||||
* \returns 0 : config successfully parsed
|
||||
* \returns <0 : error occurred
|
||||
* \retval 0 config successfully parsed
|
||||
* \retval <0 error occurred
|
||||
*/
|
||||
int config_read_file(const char *filename)
|
||||
{
|
||||
@@ -85,41 +65,8 @@ int config_read_file(const char *filename)
|
||||
section *curr_section = NULL;
|
||||
int result = 0;
|
||||
|
||||
#ifdef WITH_LDAP_SUPPORT
|
||||
LDAPURLDesc *url = NULL;
|
||||
int retval;
|
||||
#endif /* WITH_LDAP_SUPPORT */
|
||||
|
||||
report(RPT_NOTICE, "Using Configuration File: %s", filename);
|
||||
|
||||
#ifdef WITH_LDAP_SUPPORT
|
||||
if (ldap_is_ldap_url(filename)) {
|
||||
use_ldap = 1;
|
||||
|
||||
if (0 != (retval = ldap_url_parse(filename, &url))) {
|
||||
report(RPT_ERR, "Errors parsing LDAP URL %s: %s", filename, ldap_err2string(retval));
|
||||
ldap_free_urldesc(url);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
ldap_host = strdup(url->lud_host);
|
||||
ldap_port = url->lud_port;
|
||||
report(RPT_INFO, "Using LDAP server: %s:%d", ldap_host, ldap_port);
|
||||
|
||||
ldap_base_dn = strdup(url->lud_dn);
|
||||
report(RPT_INFO, "Using LDAP base DN: %s", ldap_base_dn);
|
||||
|
||||
ldap_free_urldesc(url);
|
||||
|
||||
if (connect_to_ldap() < 0) {
|
||||
debug(RPT_DEBUG, "connect_to_ldap returned errors.");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* WITH_LDAP_SUPPORT */
|
||||
|
||||
f = fopen(filename, "r");
|
||||
if (f == NULL) {
|
||||
return -1;
|
||||
@@ -158,11 +105,40 @@ int config_read_string(const char *sectionname, const char *str)
|
||||
|
||||
|
||||
/** Get string from configuration in memory.
|
||||
*
|
||||
* The strings returned are always NUL-terminated.
|
||||
* They should never be modified, and used only short-term.
|
||||
* In successive calls this function can re-use the data space !
|
||||
*
|
||||
* You can do some things with the returned string:
|
||||
* \li Scan or parse it:
|
||||
* \code
|
||||
* s = config_get_string(...);
|
||||
* sscanf(s, "%dx%d", &w, &h); // scan format like: 20x4
|
||||
* \endcode
|
||||
* ...and check the w and h values...
|
||||
* \li Copy it to a preallocated buffer like \c device[256]:
|
||||
* \code
|
||||
* s = config_get_string(...);
|
||||
* strncpy(device, s, sizeof(device));
|
||||
* device[sizeof(device)-1] = '\0'; // make sure it is terminated
|
||||
* \endcode
|
||||
* \li Copy it to a newly allocated space in \c char \c *device:
|
||||
* \code
|
||||
* s = config_get_string(...);
|
||||
* device = malloc(strlen(s)+1);
|
||||
* if (device == NULL) return -5; // or whatever < 0
|
||||
* strcpy( device, s );
|
||||
* \endcode
|
||||
*
|
||||
* \param sectionname Name of the section where the key is sought.
|
||||
* \param keyname Name of the key to look for.
|
||||
* \param skip Number of values to skip/ignore before returning the value.
|
||||
* \param default_value Default value if section/key is not found.
|
||||
* \return Value found / default value
|
||||
* This is used to iterate through the values of a multi-valued key:
|
||||
* \c 0 for the first value, \c 1 for the 2nd, ... and \c -1 for the last.
|
||||
* \param default_value Default value if section/key is not found
|
||||
* or \c skip exceeds the number of values of the key.
|
||||
* \return Value found / \c default_value
|
||||
*/
|
||||
const char *config_get_string(const char *sectionname, const char *keyname,
|
||||
int skip, const char *default_value)
|
||||
@@ -187,11 +163,19 @@ const char *config_get_string(const char *sectionname, const char *keyname,
|
||||
|
||||
|
||||
/** Get boolean value from configuration in memory.
|
||||
*
|
||||
* Legal boolean values are:
|
||||
* \li \c 0 , \c false , \c off , \c no or \c n for FALSE.
|
||||
* \li \c 1 , \c true , \c on , \c yes or \c y for TRUE
|
||||
*
|
||||
* \param sectionname Name of the section where the key is sought.
|
||||
* \param keyname Name of the key to look for.
|
||||
* \param skip Number of values to skip/ignore before returning the value.
|
||||
* \param default_value Default value if section/key is not found or value is no legal boolean.
|
||||
* \return Value found / default value
|
||||
* This is used to iterate through the values of a multi-valued key:
|
||||
* \c 0 for the first value, \c 1 for the 2nd, ... and \c -1 for the last.
|
||||
* \param default_value Default value if section/key is not found, value is no legal boolean,
|
||||
* or \c skip exceeds the number of values of the key.
|
||||
* \return Value found / \c default_value
|
||||
*/
|
||||
short config_get_bool(const char *sectionname, const char *keyname,
|
||||
int skip, short default_value)
|
||||
@@ -219,8 +203,11 @@ short config_get_bool(const char *sectionname, const char *keyname,
|
||||
* \param sectionname Name of the section where the key is sought.
|
||||
* \param keyname Name of the key to look for.
|
||||
* \param skip Number of values to skip/ignore before returning the value.
|
||||
* \param default_value Default value if section/key is not found or value is no integer.
|
||||
* \return Value found / default value
|
||||
* This is used to iterate through the values of a multi-valued key:
|
||||
* \c 0 for the first value, \c 1 for the 2nd, ... and \c -1 for the last.
|
||||
* \param default_value Default value if section/key is not found, value is no integer,
|
||||
* or \c skip exceeds the number of values of the key.
|
||||
* \return Value found / \c default_value
|
||||
*/
|
||||
long int config_get_int(const char *sectionname, const char *keyname,
|
||||
int skip, long int default_value)
|
||||
@@ -243,8 +230,11 @@ long int config_get_int(const char *sectionname, const char *keyname,
|
||||
* \param sectionname Name of the section where the key is sought.
|
||||
* \param keyname Name of the key to look for.
|
||||
* \param skip Number of values to skip/ignore before returning the value.
|
||||
* \param default_value Default value if section/key is not found or value is no floating point number.
|
||||
* \return Value found / default value
|
||||
* This is used to iterate through the values of a multi-valued key:
|
||||
* \c 0 for the first value, \c 1 for the 2nd, ... and \c -1 for the last.
|
||||
* \param default_value Default value if section/key is not found, value is no floating point number
|
||||
* or \c skip exceeds the number of values of the key.
|
||||
* \return Value found / \c default_value
|
||||
*/
|
||||
double config_get_float(const char *sectionname, const char *keyname,
|
||||
int skip, double default_value)
|
||||
@@ -265,7 +255,8 @@ double config_get_float(const char *sectionname, const char *keyname,
|
||||
|
||||
/** Test whether the configuration containis a specific section.
|
||||
* \param sectionname Name of the section to look for.
|
||||
* \return 0 = section not in config; 1 = section in config
|
||||
* \retval 0 section not in config
|
||||
* \retval 1 section in config
|
||||
*/
|
||||
int config_has_section(const char *sectionname)
|
||||
{
|
||||
@@ -276,7 +267,8 @@ int config_has_section(const char *sectionname)
|
||||
/** Test whether the configuration contains a specific key in a specfic section.
|
||||
* \param sectionname Name of the section where the key is sought.
|
||||
* \param keyname Name of the key to look for.
|
||||
* \return 0 = key or section not found; n = key found with n values
|
||||
* \retval 0 key or section not found
|
||||
* \retval n key found with \c n values (\c n > 0)
|
||||
*/
|
||||
int config_has_key(const char *sectionname, const char *keyname)
|
||||
{
|
||||
@@ -297,7 +289,7 @@ int config_has_key(const char *sectionname, const char *keyname)
|
||||
|
||||
|
||||
/** Clear configuration. */
|
||||
void config_clear()
|
||||
void config_clear(void)
|
||||
{
|
||||
section *s;
|
||||
section *next_s;
|
||||
@@ -328,97 +320,10 @@ void config_clear()
|
||||
|
||||
/**** INTERNAL FUNCTIONS ****/
|
||||
|
||||
#ifdef WITH_LDAP_SUPPORT
|
||||
static int
|
||||
connect_to_ldap(void)
|
||||
{
|
||||
int retval;
|
||||
LDAPMessage *res;
|
||||
|
||||
debug(RPT_INFO, "Connecting to LDAP server: %s:%d", ldap_host, ldap_port);
|
||||
|
||||
if (!(ld = ldap_init(ldap_host, ldap_port))) {
|
||||
report(RPT_ERR, "LDAP session could not be initialized.");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/*****************************************************
|
||||
* disabled unless you really have a DN/pwd to bind to
|
||||
* WARNING: LCDd should not have LDAP write access!!
|
||||
*
|
||||
* if (LDAP_SUCCESS != (retval = ldap_simple_bind_s(ld, ldap_user, ldap_pwd))) {
|
||||
* report(RPT_ERR, "LDAP login on %s:%d failed: %s", ldap_host, ldap_port, ldap_err2string(retval));
|
||||
* ldap_unbind(ld);
|
||||
* ld = NULL;
|
||||
*
|
||||
* return(-1);
|
||||
* }
|
||||
* fprintf(stderr, "LDAP login successful on %s:%d\n", ldap_host, ldap_port);
|
||||
********************************************************/
|
||||
|
||||
/* check for the existence of the config object... */
|
||||
if (LDAP_SUCCESS != (retval = ldap_search_s(ld, ldap_base_dn, LDAP_SCOPE_BASE, "objectClass=lcdprocConfig", NULL, 0, &res))) {
|
||||
report(RPT_ERR, "Could not access LDAP server on %s:%d", ldap_host, ldap_port);
|
||||
return(-1);
|
||||
}
|
||||
if (0 == ldap_count_entries(ld, res)) {
|
||||
report(RPT_ERR, "No configuration object found in LDAP at: %s", ldap_base_dn);
|
||||
return(-1);
|
||||
}
|
||||
debug(RPT_DEBUG, "Configuration LDAP object found.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define BUFSIZE 255
|
||||
#endif /* WITH_LDAP_SUPPORT */
|
||||
|
||||
|
||||
static section *find_section(const char *sectionname)
|
||||
{
|
||||
section *s;
|
||||
|
||||
#ifdef WITH_LDAP_SUPPORT
|
||||
LDAPMessage *res;
|
||||
int retval;
|
||||
char *filter = NULL;
|
||||
|
||||
if (use_ldap) {
|
||||
debug(RPT_DEBUG, "Searching LDAP for section [%s]", sectionname);
|
||||
if (NULL == (filter = malloc(BUFSIZE))){
|
||||
report(RPT_ERR, "Could not allocate memory in find_section()");
|
||||
return NULL;
|
||||
}
|
||||
strcpy(filter, "cn=");
|
||||
strncat(filter, sectionname, BUFSIZE);
|
||||
if (LDAP_SUCCESS != (retval = ldap_search_s(ld, ldap_base_dn, LDAP_SCOPE_ONELEVEL, filter, NULL, 0, &res))) {
|
||||
if (NULL != filter) {
|
||||
free(filter);
|
||||
filter = NULL;
|
||||
}
|
||||
ldap_msgfree(res);
|
||||
report(RPT_ERR, "Could not access LDAP server on %s:%d", ldap_host, ldap_port);
|
||||
return NULL;
|
||||
}
|
||||
if (NULL != filter) {
|
||||
free(filter);
|
||||
filter = NULL;
|
||||
}
|
||||
if (0 == ldap_count_entries(ld, res)) {
|
||||
debug(RPT_DEBUG, "Section [%s] not found in LDAP.", sectionname);
|
||||
return NULL;
|
||||
}
|
||||
ldap_msgfree(res);
|
||||
debug(RPT_DEBUG, "Found section [%s] in LDAP", sectionname);
|
||||
s = (section*) malloc(sizeof(section));
|
||||
if (s != NULL) {
|
||||
s->name = strdup(sectionname);
|
||||
s->first_key = NULL;
|
||||
s->next_section = NULL;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
#endif /* WITH_LDAP_SUPPORT */
|
||||
|
||||
for (s = first_section; s != NULL; s = s->next_section) {
|
||||
if (strcasecmp(s->name, sectionname) == 0) {
|
||||
return s;
|
||||
@@ -453,107 +358,10 @@ static key *find_key(section *s, const char *keyname, int skip)
|
||||
int count = 0;
|
||||
key *last_key = NULL;
|
||||
|
||||
#ifdef WITH_LDAP_SUPPORT
|
||||
LDAPMessage *res;
|
||||
LDAPMessage *entry;
|
||||
int retval;
|
||||
char *buf = NULL;
|
||||
char **vals;
|
||||
#endif /* WITH_LDAP_SUPPORT */
|
||||
|
||||
/* Check for NULL section*/
|
||||
if (s == NULL)
|
||||
return NULL;
|
||||
|
||||
#ifdef WITH_LDAP_SUPPORT
|
||||
if (use_ldap) {
|
||||
debug(RPT_DEBUG, "Searching LDAP for key '%s' in section [%s] skipping %d entries.", keyname, s->name, skip);
|
||||
|
||||
if (NULL == (buf = malloc(BUFSIZE))){
|
||||
report(RPT_ERR, "Could not allocate memory in find_key().");
|
||||
}
|
||||
strcpy(buf, "cn=");
|
||||
strncat(buf, s->name, BUFSIZE);
|
||||
if (LDAP_SUCCESS != (retval = ldap_search_s(ld, ldap_base_dn, LDAP_SCOPE_ONELEVEL, buf, NULL, 0, &res))) {
|
||||
if (NULL != buf) {
|
||||
free(buf);
|
||||
buf=NULL;
|
||||
}
|
||||
ldap_msgfree(res);
|
||||
report(RPT_ERR, "Could not access LDAP server on %s:%d", ldap_host, ldap_port);
|
||||
return NULL;
|
||||
}
|
||||
if (NULL == (entry = ldap_first_entry(ld, res))) {
|
||||
debug(RPT_DEBUG, "Section [%s] not found in LDAP.", s->name);
|
||||
if (NULL != buf) {
|
||||
free(buf);
|
||||
buf = NULL;
|
||||
}
|
||||
/* DON'T enable the following
|
||||
* ldap_msgfree(entry);
|
||||
* ldap_msgfree below does that already
|
||||
*/
|
||||
ldap_msgfree(res);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
strcpy(buf, "lcdproc");
|
||||
strncat(buf, keyname, BUFSIZE);
|
||||
/* debug(RPT_DEBUG, "Key name translated to attribute name: %s", buf); */
|
||||
vals = ldap_get_values(ld, entry, buf);
|
||||
|
||||
if (skip+1 > ldap_count_values(vals)) {
|
||||
debug(RPT_DEBUG, "No such entry found.");
|
||||
if (NULL != buf) {
|
||||
free(buf);
|
||||
buf = NULL;
|
||||
}
|
||||
ldap_value_free(vals);
|
||||
/* DON'T enable the following
|
||||
* ldap_msgfree(entry);
|
||||
* ldap_msgfree below does that already
|
||||
*/
|
||||
ldap_msgfree(res);
|
||||
return NULL;
|
||||
}
|
||||
/* DON'T enable the following
|
||||
* ldap_msgfree(entry);
|
||||
* ldap_msgfree below does that already
|
||||
*/
|
||||
ldap_msgfree(res);
|
||||
if (vals && vals[skip]) {
|
||||
if (NULL != buf) {
|
||||
free(buf);
|
||||
buf = NULL;
|
||||
}
|
||||
buf=strdup(vals[skip]);
|
||||
debug(RPT_DEBUG, "Entry found. Value is: %s", buf);
|
||||
ldap_value_free(vals);
|
||||
|
||||
k = (key *) malloc(sizeof(key));
|
||||
if ( k != NULL) {
|
||||
k->name = strdup(keyname);
|
||||
k->value = strdup(buf);
|
||||
k->next_key = NULL;
|
||||
}
|
||||
|
||||
if (NULL != buf) {
|
||||
free(buf);
|
||||
buf = NULL;
|
||||
}
|
||||
return k;
|
||||
}
|
||||
report(RPT_ERR, "LDAP server encountered errors.");
|
||||
ldap_value_free(vals);
|
||||
if (NULL != buf) {
|
||||
free(buf);
|
||||
buf = NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
#endif /* WITH_LDAP_SUPPORT */
|
||||
|
||||
for (k = s->first_key; k != NULL; k = k->next_key) {
|
||||
|
||||
/* Did we find the right key ?*/
|
||||
|
||||
+30
-34
@@ -1,14 +1,14 @@
|
||||
/*
|
||||
* configfile.h
|
||||
* This file is part of LCDd, the lcdproc server.
|
||||
/** \file configfile.h
|
||||
* Declares routines to read INI-file like files.
|
||||
*/
|
||||
|
||||
/* This file is part of LCDd, the lcdproc server.
|
||||
*
|
||||
* This file is released under the GNU General Public License. Refer to the
|
||||
* COPYING file distributed with this package.
|
||||
*
|
||||
* Copyright (c) 2001, Joris Robijn
|
||||
*
|
||||
*
|
||||
* Defines routines to read ini-file-like files.
|
||||
* (c) 2006,2007 Peter Marschall
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -19,52 +19,47 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
int config_read_file(const char *filename);
|
||||
/* Opens the specified file and reads everything into memory.
|
||||
* Returns -1 on parsing errors.
|
||||
* Returns -2 if the file could not be opened or a read error occured.
|
||||
* Returns -16 if a malloc went wrong.
|
||||
* Returns 0 when config file was successfully parsed
|
||||
* Returns <0 on errors
|
||||
*/
|
||||
int config_read_file(const char *filename);
|
||||
|
||||
int config_read_string(const char *sectionname, const char *str);
|
||||
#if defined(LCDPROC_CONFIG_READ_STRING)
|
||||
/* Reads everything in the string into memory.
|
||||
* Returns -1 on parsing errors.
|
||||
* Returns -16 if a malloc went wrong.
|
||||
* Returns 0 when config file was successfully parsed
|
||||
* Returns <0 on errors
|
||||
*/
|
||||
int config_read_string(const char *sectionname, const char *str);
|
||||
#endif
|
||||
|
||||
short config_get_bool(const char *sectionname, const char *keyname,
|
||||
int skip, short default_value);
|
||||
/* Tries to interpret a value in the config file as a boolean.
|
||||
* 0, false, no, n = false
|
||||
* 1, true, yes, y = true
|
||||
* 0, false, off, no, n = false
|
||||
* 1, true, on, yes, y = true
|
||||
* If the key is not found or cannot be interpreted, the given default value is
|
||||
* returned.
|
||||
* The skip value can be used to iterate over multiple values with the same
|
||||
* key. Should be 0 to get the first one, 1 for the second etc. and -1 for the
|
||||
* last.
|
||||
*/
|
||||
short config_get_bool(const char *sectionname, const char *keyname,
|
||||
int skip, short default_value);
|
||||
|
||||
/* Tries to interpret a value in the config file as an integer.*/
|
||||
long int config_get_int(const char *sectionname, const char *keyname,
|
||||
int skip, long int default_value);
|
||||
/* Tries to interpret a value in the config file as an integer.*/
|
||||
|
||||
/* Tries to interpret a value in the config file as a float.*/
|
||||
double config_get_float(const char *sectionname, const char *keyname,
|
||||
int skip, double default_value);
|
||||
/* Tries to interpret a value in the config file as a float.*/
|
||||
|
||||
const char *config_get_string(const char *sectionname, const char *keyname,
|
||||
int skip, const char *default_value);
|
||||
/* Returns a pointer to the string associated with the specified key.
|
||||
* The string should never be modified, and used only short-term. You can
|
||||
* for example scan it or copy it. In successive calls this function can
|
||||
* re-use the data space !
|
||||
* The strings returned are always NUL-terminated.
|
||||
* The string should never be modified, and used only short-term.
|
||||
* In successive calls this function can * re-use the data space !
|
||||
*
|
||||
* found in a mail from Joris:
|
||||
*
|
||||
* The strings it returns are always terminated.
|
||||
*
|
||||
* You can do some things with them:
|
||||
* 1. Scan them:
|
||||
* You can do some things with the returned string:
|
||||
* 1. Scan or parse it:
|
||||
* s = config_get_string(...);
|
||||
* sscanf( s, "%dx%d", &w, &h ); // scan format like: 20x4
|
||||
* ...and check the w and h values...
|
||||
@@ -77,22 +72,23 @@ const char *config_get_string(const char *sectionname, const char *keyname,
|
||||
* device = malloc(strlen(s)+1);
|
||||
* if( device == NULL ) return -5; // or whatever < 0
|
||||
* strcpy( device, s );
|
||||
*
|
||||
*/
|
||||
const char *config_get_string(const char *sectionname, const char *keyname,
|
||||
int skip, const char *default_value);
|
||||
|
||||
int config_has_section(const char *sectionname);
|
||||
/* Checks if a specified section exists.
|
||||
* Returns whether it exists.
|
||||
*/
|
||||
int config_has_section(const char *sectionname);
|
||||
|
||||
int config_has_key(const char *sectionname, const char *keyname);
|
||||
/* Checks if a specified key within the specified section exists.
|
||||
* Returns the number of times the key exists.
|
||||
*/
|
||||
int config_has_key(const char *sectionname, const char *keyname);
|
||||
|
||||
void config_clear();
|
||||
/* Clears all data stored by the config_read_* functions.
|
||||
* Should be called if the config should be reread.
|
||||
*/
|
||||
void config_clear(void);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user