Imported Upstream version 2.6.4
This commit is contained in:
parent
fad6ced6f6
commit
fefe62b2bd
257 changed files with 6020 additions and 1394 deletions
|
|
@ -2,15 +2,14 @@
|
|||
|
||||
AM_CFLAGS = -I$(top_srcdir)/include
|
||||
|
||||
../include/nut_version.h: FORCE
|
||||
(cd ../include/ && $(MAKE) $(AM_MAKEFLAGS) nut_version.h)
|
||||
|
||||
FORCE:
|
||||
|
||||
noinst_LTLIBRARIES = libparseconf.la libcommon.la
|
||||
libparseconf_la_SOURCES = parseconf.c
|
||||
|
||||
libcommon_la_SOURCES = common.c state.c upsconf.c ../include/nut_version.h
|
||||
# do not hard depend on '../include/nut_version.h', since it blocks
|
||||
# 'dist', and is only required for actual build, in which case
|
||||
# BUILT_SOURCES (in ../include) will ensure nut_version.h will
|
||||
# be built before anything else
|
||||
libcommon_la_SOURCES = common.c state.c upsconf.c
|
||||
# ensure inclusion of local implementation of missing systems functions
|
||||
# using LTLIBOBJS. Refer to configure.in -> AC_REPLACE_FUNCS
|
||||
libcommon_la_LIBADD = libparseconf.la @LTLIBOBJS@
|
||||
|
|
|
|||
|
|
@ -174,6 +174,7 @@ MKDIR_P = @MKDIR_P@
|
|||
NETLIBS = @NETLIBS@
|
||||
NM = @NM@
|
||||
NMEDIT = @NMEDIT@
|
||||
NUT_NETVERSION = @NUT_NETVERSION@
|
||||
OBJDUMP = @OBJDUMP@
|
||||
OBJEXT = @OBJEXT@
|
||||
OS_NAME = @OS_NAME@
|
||||
|
|
@ -187,6 +188,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@
|
|||
PACKAGE_URL = @PACKAGE_URL@
|
||||
PACKAGE_VERSION = @PACKAGE_VERSION@
|
||||
PATH_SEPARATOR = @PATH_SEPARATOR@
|
||||
PIDPATH = @PIDPATH@
|
||||
PKG_CONFIG = @PKG_CONFIG@
|
||||
PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
|
||||
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
|
||||
|
|
@ -194,6 +196,7 @@ PORT = @PORT@
|
|||
RANLIB = @RANLIB@
|
||||
RUN_AS_GROUP = @RUN_AS_GROUP@
|
||||
RUN_AS_USER = @RUN_AS_USER@
|
||||
SBINDIR = @SBINDIR@
|
||||
SED = @SED@
|
||||
SERLIBS = @SERLIBS@
|
||||
SET_MAKE = @SET_MAKE@
|
||||
|
|
@ -270,7 +273,12 @@ udevdir = @udevdir@
|
|||
AM_CFLAGS = -I$(top_srcdir)/include
|
||||
noinst_LTLIBRARIES = libparseconf.la libcommon.la
|
||||
libparseconf_la_SOURCES = parseconf.c
|
||||
libcommon_la_SOURCES = common.c state.c upsconf.c ../include/nut_version.h
|
||||
|
||||
# do not hard depend on '../include/nut_version.h', since it blocks
|
||||
# 'dist', and is only required for actual build, in which case
|
||||
# BUILT_SOURCES (in ../include) will ensure nut_version.h will
|
||||
# be built before anything else
|
||||
libcommon_la_SOURCES = common.c state.c upsconf.c
|
||||
# ensure inclusion of local implementation of missing systems functions
|
||||
# using LTLIBOBJS. Refer to configure.in -> AC_REPLACE_FUNCS
|
||||
libcommon_la_LIBADD = libparseconf.la @LTLIBOBJS@
|
||||
|
|
@ -562,11 +570,6 @@ uninstall-am:
|
|||
pdf pdf-am ps ps-am tags uninstall uninstall-am
|
||||
|
||||
|
||||
../include/nut_version.h: FORCE
|
||||
(cd ../include/ && $(MAKE) $(AM_MAKEFLAGS) nut_version.h)
|
||||
|
||||
FORCE:
|
||||
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
||||
|
|
|
|||
|
|
@ -527,11 +527,28 @@ char *rtrim(char *in, const char sep)
|
|||
{
|
||||
char *p;
|
||||
|
||||
p = &in[strlen(in) - 1];
|
||||
if (in) {
|
||||
p = &in[strlen(in) - 1];
|
||||
|
||||
while ((p >= in) && (*p == sep))
|
||||
*p-- = '\0';
|
||||
|
||||
while ((p >= in) && (*p == sep))
|
||||
*p-- = '\0';
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
/* modify in - strip all leading instances of <sep> */
|
||||
char* ltrim(char *in, const char sep)
|
||||
{
|
||||
char *p;
|
||||
|
||||
if (in) {
|
||||
p = in;
|
||||
|
||||
while ((*p != '\0') && (*p == sep))
|
||||
*p++ = *in++;
|
||||
|
||||
p = '\0';
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -171,6 +171,13 @@ static void addchar(PCONF_CTX_t *ctx)
|
|||
|
||||
wbuflen = strlen(ctx->wordbuf);
|
||||
|
||||
/* CVE-2012-2944: only allow the subset Ascii charset from Space to ~ */
|
||||
if ((ctx->ch < 0x20) || (ctx->ch > 0x7f)) {
|
||||
fprintf(stderr, "addchar: discarding invalid character (0x%02x)!\n",
|
||||
ctx->ch);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx->wordlen_limit != 0) {
|
||||
if (wbuflen >= ctx->wordlen_limit) {
|
||||
|
||||
|
|
@ -240,6 +247,13 @@ static int findwordstart(PCONF_CTX_t *ctx)
|
|||
|
||||
/* at this point the word just started */
|
||||
addchar(ctx);
|
||||
|
||||
/* if the first character is a '=' this is considered a whole word */
|
||||
if (ctx->ch == '=') {
|
||||
endofword(ctx);
|
||||
return STATE_FINDWORDSTART;
|
||||
}
|
||||
|
||||
return STATE_COLLECT;
|
||||
}
|
||||
|
||||
|
|
@ -326,6 +340,14 @@ static int collect(PCONF_CTX_t *ctx)
|
|||
return STATE_FINDWORDSTART;
|
||||
}
|
||||
|
||||
/* '=' means the word is done and the = is a single char word*/
|
||||
if (ctx->ch == '=') {
|
||||
endofword(ctx);
|
||||
findwordstart(ctx);
|
||||
|
||||
return STATE_FINDWORDSTART;
|
||||
}
|
||||
|
||||
/* \ = literal = accept the next char blindly */
|
||||
if (ctx->ch == '\\')
|
||||
return STATE_COLLECTLITERAL;
|
||||
|
|
|
|||
114
common/state.c
114
common/state.c
|
|
@ -3,6 +3,7 @@
|
|||
Copyright (C)
|
||||
2003 Russell Kroll <rkroll@exploits.org>
|
||||
2008 Arjen de Korte <adkorte-guest@alioth.debian.org>
|
||||
2012 Arnaud Quette <arnaud.quette@free.fr>
|
||||
|
||||
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
|
||||
|
|
@ -65,6 +66,17 @@ static void st_tree_enum_free(enum_t *list)
|
|||
free(list);
|
||||
}
|
||||
|
||||
static void st_tree_range_free(range_t *list)
|
||||
{
|
||||
if (!list) {
|
||||
return;
|
||||
}
|
||||
|
||||
st_tree_range_free(list->next);
|
||||
|
||||
free(list);
|
||||
}
|
||||
|
||||
/* free all memory associated with a node */
|
||||
static void st_tree_node_free(st_tree_t *node)
|
||||
{
|
||||
|
|
@ -77,6 +89,9 @@ static void st_tree_node_free(st_tree_t *node)
|
|||
/* blow away the list of enums */
|
||||
st_tree_enum_free(node->enum_list);
|
||||
|
||||
/* and the list of ranges */
|
||||
st_tree_range_free(node->range_list);
|
||||
|
||||
/* now finally kill the node itself */
|
||||
free(node);
|
||||
}
|
||||
|
|
@ -237,6 +252,54 @@ int state_addenum(st_tree_t *root, const char *var, const char *val)
|
|||
return st_tree_enum_add(&sttmp->enum_list, enc);
|
||||
}
|
||||
|
||||
static int st_tree_range_add(range_t **list, const int min, const int max)
|
||||
{
|
||||
range_t *item;
|
||||
|
||||
while (*list) {
|
||||
|
||||
if (((*list)->min != min) && ((*list)->max != max)) {
|
||||
list = &(*list)->next;
|
||||
continue;
|
||||
}
|
||||
|
||||
return 0; /* duplicate */
|
||||
}
|
||||
|
||||
item = xcalloc(1, sizeof(*item));
|
||||
item->min = min;
|
||||
item->max = max;
|
||||
item->next = *list;
|
||||
|
||||
/* now we're done creating it, add it to the list */
|
||||
*list = item;
|
||||
|
||||
return 1; /* added */
|
||||
}
|
||||
|
||||
int state_addrange(st_tree_t *root, const char *var, const int min, const int max)
|
||||
{
|
||||
st_tree_t *sttmp;
|
||||
|
||||
/* sanity check */
|
||||
if (min > max) {
|
||||
upslogx(LOG_ERR, "state_addrange: min is superior to max! (%i, %i)",
|
||||
min, max);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* find the tree node for var */
|
||||
sttmp = state_tree_find(root, var);
|
||||
|
||||
if (!sttmp) {
|
||||
upslogx(LOG_ERR, "state_addrange: base variable (%s) "
|
||||
"does not exist", var);
|
||||
return 0; /* failed */
|
||||
}
|
||||
|
||||
return st_tree_range_add(&sttmp->range_list, min, max);
|
||||
}
|
||||
|
||||
int state_setaux(st_tree_t *root, const char *var, const char *auxs)
|
||||
{
|
||||
st_tree_t *sttmp;
|
||||
|
|
@ -319,6 +382,20 @@ const enum_t *state_getenumlist(st_tree_t *root, const char *var)
|
|||
return sttmp->enum_list;
|
||||
}
|
||||
|
||||
const range_t *state_getrangelist(st_tree_t *root, const char *var)
|
||||
{
|
||||
st_tree_t *sttmp;
|
||||
|
||||
/* find the tree node for var */
|
||||
sttmp = state_tree_find(root, var);
|
||||
|
||||
if (!sttmp) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return sttmp->range_list;
|
||||
}
|
||||
|
||||
void state_setflags(st_tree_t *root, const char *var, int numflags, char **flag)
|
||||
{
|
||||
int i;
|
||||
|
|
@ -471,6 +548,43 @@ int state_delenum(st_tree_t *root, const char *var, const char *val)
|
|||
return st_tree_del_enum(&sttmp->enum_list, val);
|
||||
}
|
||||
|
||||
static int st_tree_del_range(range_t **list, const int min, const int max)
|
||||
{
|
||||
while (*list) {
|
||||
|
||||
range_t *item = *list;
|
||||
|
||||
/* if this is not the right value, go on to the next */
|
||||
if (((*list)->min != min) && ((*list)->max != max)) {
|
||||
list = &item->next;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* we found it! */
|
||||
*list = item->next;
|
||||
|
||||
free(item);
|
||||
|
||||
return 1; /* deleted */
|
||||
}
|
||||
|
||||
return 0; /* not found */
|
||||
}
|
||||
|
||||
int state_delrange(st_tree_t *root, const char *var, const int min, const int max)
|
||||
{
|
||||
st_tree_t *sttmp;
|
||||
|
||||
/* find the tree node for var */
|
||||
sttmp = state_tree_find(root, var);
|
||||
|
||||
if (!sttmp) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return st_tree_del_range(&sttmp->range_list, min, max);
|
||||
}
|
||||
|
||||
st_tree_t *state_tree_find(st_tree_t *node, const char *var)
|
||||
{
|
||||
while (node) {
|
||||
|
|
|
|||
|
|
@ -31,8 +31,6 @@
|
|||
/* handle arguments separated by parseconf */
|
||||
static void conf_args(int numargs, char **arg)
|
||||
{
|
||||
char *ep;
|
||||
|
||||
if (numargs < 1)
|
||||
return;
|
||||
|
||||
|
|
@ -46,15 +44,6 @@ static void conf_args(int numargs, char **arg)
|
|||
return;
|
||||
}
|
||||
|
||||
/* handle 'foo=bar' (compressed form) */
|
||||
ep = strchr(arg[0], '=');
|
||||
if (ep) {
|
||||
*ep = '\0';
|
||||
|
||||
do_upsconf_args(ups_section, arg[0], ep+1);
|
||||
return;
|
||||
}
|
||||
|
||||
/* handle 'foo' (flag) */
|
||||
if (numargs == 1) {
|
||||
do_upsconf_args(ups_section, arg[0], NULL);
|
||||
|
|
@ -64,7 +53,7 @@ static void conf_args(int numargs, char **arg)
|
|||
if (numargs < 3)
|
||||
return;
|
||||
|
||||
/* handle 'foo = bar' (split form) */
|
||||
/* handle 'foo = bar', 'foo=bar', 'foo =bar' or 'foo= bar' forms */
|
||||
if (!strcmp(arg[1], "=")) {
|
||||
do_upsconf_args(ups_section, arg[0], arg[2]);
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue