Imported Upstream version 2.6.4
This commit is contained in:
parent
fad6ced6f6
commit
fefe62b2bd
257 changed files with 6020 additions and 1394 deletions
|
@ -192,6 +192,7 @@ MKDIR_P = @MKDIR_P@
|
|||
NETLIBS = @NETLIBS@
|
||||
NM = @NM@
|
||||
NMEDIT = @NMEDIT@
|
||||
NUT_NETVERSION = @NUT_NETVERSION@
|
||||
OBJDUMP = @OBJDUMP@
|
||||
OBJEXT = @OBJEXT@
|
||||
OS_NAME = @OS_NAME@
|
||||
|
@ -205,6 +206,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@
|
||||
|
@ -212,6 +214,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@
|
||||
|
|
|
@ -35,6 +35,7 @@ struct {
|
|||
int flags;
|
||||
} netcmds[] = {
|
||||
{ "VER", net_ver, 0 },
|
||||
{ "NETVER", net_netver, 0 },
|
||||
{ "HELP", net_help, 0 },
|
||||
{ "STARTTLS", net_starttls, 0 },
|
||||
|
||||
|
|
|
@ -56,9 +56,6 @@ static void get_upsdesc(nut_ctype_t *client, const char *upsname)
|
|||
return;
|
||||
}
|
||||
|
||||
if (!ups_available(ups, client))
|
||||
return;
|
||||
|
||||
if (ups->desc) {
|
||||
pconf_encode(ups->desc, esc, sizeof(esc));
|
||||
sendback(client, "UPSDESC %s \"%s\"\n", upsname, esc);
|
||||
|
@ -149,6 +146,11 @@ static void get_type(nut_ctype_t *client, const char *upsname, const char *var)
|
|||
return;
|
||||
}
|
||||
|
||||
if (node->range_list) {
|
||||
sendback(client, "%s RANGE\n", buf);
|
||||
return;
|
||||
}
|
||||
|
||||
if (node->flags & ST_FLAG_STRING) {
|
||||
sendback(client, "%s STRING:%d\n", buf, node->aux);
|
||||
return;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
/* netlist.c - LIST handlers for upsd
|
||||
|
||||
Copyright (C) 2003 Russell Kroll <rkroll@exploits.org>
|
||||
Copyright (C)
|
||||
2003 Russell Kroll <rkroll@exploits.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
|
||||
|
@ -26,7 +28,8 @@
|
|||
|
||||
#include "netlist.h"
|
||||
|
||||
extern upstype_t *firstups; /* for list_ups */
|
||||
extern upstype_t *firstups; /* for list_ups */
|
||||
extern nut_ctype_t *firstclient; /* for list_clients */
|
||||
|
||||
static int tree_dump(st_tree_t *node, nut_ctype_t *client, const char *ups,
|
||||
int rw, int fsd)
|
||||
|
@ -185,6 +188,41 @@ static void list_enum(nut_ctype_t *client, const char *upsname, const char *var)
|
|||
sendback(client, "END LIST ENUM %s %s\n", upsname, var);
|
||||
}
|
||||
|
||||
static void list_range(nut_ctype_t *client, const char *upsname, const char *var)
|
||||
{
|
||||
const upstype_t *ups;
|
||||
const st_tree_t *node;
|
||||
const range_t *rtmp;
|
||||
|
||||
ups = get_ups_ptr(upsname);
|
||||
|
||||
if (!ups) {
|
||||
send_err(client, NUT_ERR_UNKNOWN_UPS);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ups_available(ups, client))
|
||||
return;
|
||||
|
||||
node = sstate_getnode(ups, var);
|
||||
|
||||
if (!node) {
|
||||
send_err(client, NUT_ERR_VAR_NOT_SUPPORTED);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!sendback(client, "BEGIN LIST RANGE %s %s\n", upsname, var))
|
||||
return;
|
||||
|
||||
for (rtmp = node->range_list; rtmp != NULL; rtmp = rtmp->next) {
|
||||
if (!sendback(client, "RANGE %s %s \"%i\" \"%i\"\n",
|
||||
upsname, var, rtmp->min, rtmp->max))
|
||||
return;
|
||||
}
|
||||
|
||||
sendback(client, "END LIST ENUM %s %s\n", upsname, var);
|
||||
}
|
||||
|
||||
static void list_ups(nut_ctype_t *client)
|
||||
{
|
||||
upstype_t *utmp;
|
||||
|
@ -217,6 +255,36 @@ static void list_ups(nut_ctype_t *client)
|
|||
sendback(client, "END LIST UPS\n");
|
||||
}
|
||||
|
||||
static void list_clients(nut_ctype_t *client, const char *upsname)
|
||||
{
|
||||
const upstype_t *ups;
|
||||
nut_ctype_t *c, *cnext;
|
||||
|
||||
ups = get_ups_ptr(upsname);
|
||||
|
||||
if (!ups) {
|
||||
send_err(client, NUT_ERR_UNKNOWN_UPS);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!sendback(client, "BEGIN LIST CLIENT %s\n", upsname))
|
||||
return;
|
||||
|
||||
if (firstclient) {
|
||||
int ret;
|
||||
/* show connected clients */
|
||||
for (c = firstclient; c; c = cnext) {
|
||||
if (c->loginups && (!ups || !strcasecmp(c->loginups, ups->name))) {
|
||||
ret = sendback(client, "CLIENT %s %s\n", c->loginups, c->addr);
|
||||
if (!ret)
|
||||
return;
|
||||
}
|
||||
cnext = c->next;
|
||||
}
|
||||
}
|
||||
sendback(client, "END LIST CLIENT %s\n", upsname);
|
||||
}
|
||||
|
||||
void net_list(nut_ctype_t *client, int numarg, const char **arg)
|
||||
{
|
||||
if (numarg < 1) {
|
||||
|
@ -253,6 +321,12 @@ void net_list(nut_ctype_t *client, int numarg, const char **arg)
|
|||
return;
|
||||
}
|
||||
|
||||
/* LIST CLIENT UPS */
|
||||
if (!strcasecmp(arg[0], "CLIENT")) {
|
||||
list_clients(client, arg[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (numarg < 3) {
|
||||
send_err(client, NUT_ERR_INVALID_ARGUMENT);
|
||||
return;
|
||||
|
@ -264,5 +338,11 @@ void net_list(nut_ctype_t *client, int numarg, const char **arg)
|
|||
return;
|
||||
}
|
||||
|
||||
/* LIST RANGE UPS VARNAME */
|
||||
if (!strcasecmp(arg[0], "RANGE")) {
|
||||
list_range(client, arg[1], arg[2]);
|
||||
return;
|
||||
}
|
||||
|
||||
send_err(client, NUT_ERR_INVALID_ARGUMENT);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
/* netmisc.c - miscellaneous network handlers for upsd (VER, HELP, FSD)
|
||||
|
||||
Copyright (C) 2003 Russell Kroll <rkroll@exploits.org>
|
||||
Copyright (C)
|
||||
2003 Russell Kroll <rkroll@exploits.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
|
||||
|
@ -38,6 +40,16 @@ void net_ver(nut_ctype_t *client, int numarg, const char **arg)
|
|||
UPS_VERSION);
|
||||
}
|
||||
|
||||
void net_netver(nut_ctype_t *client, int numarg, const char **arg)
|
||||
{
|
||||
if (numarg != 0) {
|
||||
send_err(client, NUT_ERR_INVALID_ARGUMENT);
|
||||
return;
|
||||
}
|
||||
|
||||
sendback(client, "%s\n", NUT_NETVERSION);
|
||||
}
|
||||
|
||||
void net_help(nut_ctype_t *client, int numarg, const char **arg)
|
||||
{
|
||||
if (numarg != 0) {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
void net_ver(nut_ctype_t *client, int numarg, const char **arg);
|
||||
void net_netver(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);
|
||||
|
|
|
@ -33,6 +33,7 @@ static void set_var(nut_ctype_t *client, const char *upsname, const char *var,
|
|||
upstype_t *ups;
|
||||
const char *val;
|
||||
const enum_t *etmp;
|
||||
const range_t *rtmp;
|
||||
char cmd[SMALLBUF], esc[SMALLBUF];
|
||||
|
||||
ups = get_ups_ptr(upsname);
|
||||
|
@ -108,6 +109,29 @@ static void set_var(nut_ctype_t *client, const char *upsname, const char *var,
|
|||
}
|
||||
}
|
||||
|
||||
/* or if it's within a range */
|
||||
|
||||
rtmp = sstate_getrangelist(ups, var);
|
||||
|
||||
if (rtmp) {
|
||||
int found = 0;
|
||||
int inewval = atoi(newval);
|
||||
|
||||
while (rtmp) {
|
||||
if ((inewval >= rtmp->min) && (inewval <= rtmp->max)) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
rtmp = rtmp->next;
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
send_err(client, NUT_ERR_INVALID_VALUE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* must be OK now */
|
||||
|
||||
upslogx(LOG_INFO, "Set variable: %s@%s set %s on %s to %s",
|
||||
|
|
|
@ -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
|
||||
|
@ -63,6 +64,7 @@ static int parse_args(upstype_t *ups, int numargs, char **arg)
|
|||
if (numargs < 2)
|
||||
return 0;
|
||||
|
||||
/* FIXME: all these should return their state_...() value! */
|
||||
/* ADDCMD <cmdname> */
|
||||
if (!strcasecmp(arg[0], "ADDCMD")) {
|
||||
state_addcmd(&ups->cmdlist, arg[1]);
|
||||
|
@ -88,7 +90,7 @@ static int parse_args(upstype_t *ups, int numargs, char **arg)
|
|||
if (!strcasecmp(arg[0], "SETFLAGS")) {
|
||||
state_setflags(ups->inforoot, arg[1], numargs - 2, &arg[2]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* SETINFO <varname> <value> */
|
||||
if (!strcasecmp(arg[0], "SETINFO")) {
|
||||
|
@ -102,12 +104,24 @@ static int parse_args(upstype_t *ups, int numargs, char **arg)
|
|||
return 1;
|
||||
}
|
||||
|
||||
/* ADDRANGE <varname> <minvalue> <maxvalue> */
|
||||
if (!strcasecmp(arg[0], "ADDRANGE")) {
|
||||
state_addrange(ups->inforoot, arg[1], atoi(arg[2]), atoi(arg[3]));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* DELENUM <varname> <enumval> */
|
||||
if (!strcasecmp(arg[0], "DELENUM")) {
|
||||
state_delenum(ups->inforoot, arg[1], arg[2]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* DELRANGE <varname> <minvalue> <maxvalue> */
|
||||
if (!strcasecmp(arg[0], "DELRANGE")) {
|
||||
state_delrange(ups->inforoot, arg[1], atoi(arg[2]), atoi(arg[3]));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* SETAUX <varname> <auxval> */
|
||||
if (!strcasecmp(arg[0], "SETAUX")) {
|
||||
state_setaux(ups->inforoot, arg[1], arg[2]);
|
||||
|
@ -301,6 +315,11 @@ const enum_t *sstate_getenumlist(const upstype_t *ups, const char *var)
|
|||
return state_getenumlist(ups->inforoot, var);
|
||||
}
|
||||
|
||||
const range_t *sstate_getrangelist(const upstype_t *ups, const char *var)
|
||||
{
|
||||
return state_getrangelist(ups->inforoot, var);
|
||||
}
|
||||
|
||||
const cmdlist_t *sstate_getcmdlist(const upstype_t *ups)
|
||||
{
|
||||
return ups->cmdlist;
|
||||
|
|
|
@ -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
|
||||
|
@ -35,6 +36,7 @@ const char *sstate_getinfo(const upstype_t *ups, const char *var);
|
|||
int sstate_getflags(const upstype_t *ups, const char *var);
|
||||
int sstate_getaux(const upstype_t *ups, const char *var);
|
||||
const enum_t *sstate_getenumlist(const upstype_t *ups, const char *var);
|
||||
const range_t *sstate_getrangelist(const upstype_t *ups, const char *var);
|
||||
const cmdlist_t *sstate_getcmdlist(const upstype_t *ups);
|
||||
void sstate_makeinfolist(const upstype_t *ups, char *buf, size_t bufsize);
|
||||
void sstate_makerwlist(const upstype_t *ups, char *buf, size_t bufsize);
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
/* upsd.c - watches ups state files and answers queries
|
||||
|
||||
Copyright (C)
|
||||
1999 Russell Kroll <rkroll@exploits.org>
|
||||
2008 Arjen de Korte <adkorte-guest@alioth.debian.org>
|
||||
2011 Arnaud Quette <arnaud.quette.free.fr>
|
||||
1999 Russell Kroll <rkroll@exploits.org>
|
||||
2008 Arjen de Korte <adkorte-guest@alioth.debian.org>
|
||||
2011 - 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,7 +65,7 @@ int deny_severity = LOG_WARNING;
|
|||
/* everything else */
|
||||
const char *progname;
|
||||
|
||||
static nut_ctype_t *firstclient = NULL;
|
||||
nut_ctype_t *firstclient = NULL;
|
||||
/* static nut_ctype_t *lastclient = NULL; */
|
||||
|
||||
/* default is to listen on all local interfaces */
|
||||
|
@ -955,6 +955,15 @@ int main(int argc, char **argv)
|
|||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
/* otherwise, we are being asked to start.
|
||||
* so check if a previous instance is running by sending signal '0'
|
||||
* (Ie 'kill <pid> 0') */
|
||||
if (sendsignalfn(pidfn, 0) == 0) {
|
||||
printf("Fatal error: A previous upsd instance is already running!\n");
|
||||
printf("Either stop the previous instance first, or use the 'reload' command.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
|
|
|
@ -67,6 +67,7 @@ void check_perms(const char *fn);
|
|||
extern int maxage, maxconn;
|
||||
extern char *statepath, *datapath;
|
||||
extern upstype_t *firstups;
|
||||
extern nut_ctype_t *firstclient;
|
||||
|
||||
/* map commands onto signals */
|
||||
|
||||
|
|
|
@ -111,6 +111,9 @@ static void user_add_instcmd(const char *cmd)
|
|||
}
|
||||
}
|
||||
|
||||
upsdebugx(2, "user_add_instcmd: adding '%s' for %s",
|
||||
cmd, curr_user->username);
|
||||
|
||||
tmp = xcalloc(1, sizeof(*tmp));
|
||||
|
||||
tmp->cmd = xstrdup(cmd);
|
||||
|
@ -155,6 +158,9 @@ static void user_add_action(const char *act)
|
|||
return;
|
||||
}
|
||||
|
||||
upsdebugx(2, "user_add_action: adding '%s' for %s",
|
||||
act, curr_user->username);
|
||||
|
||||
curr_user->firstaction = addaction(curr_user->firstaction, act);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue