1
/* netinstcmd.c - INSTCMD handler for upsd
3
Copyright (C) 2003 Russell Kroll <rkroll@exploits.org>
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
#include "user.h" /* for user_checkinstcmd */
30
static void send_instcmd(ctype *client, const char *upsname,
35
const struct cmdlist_t *ctmp;
36
char sockcmd[SMALLBUF];
38
ups = get_ups_ptr(upsname);
41
send_err(client, NUT_ERR_UNKNOWN_UPS);
45
if (!ups_available(ups, client))
48
ctmp = sstate_getcmdlist(ups);
53
if (!strcasecmp(ctmp->name, cmdname)) {
62
send_err(client, NUT_ERR_CMD_NOT_SUPPORTED);
66
/* see if this user is allowed to do this command */
67
if (!user_checkinstcmd(&client->sock, client->username,
68
client->password, cmdname)) {
70
send_err(client, NUT_ERR_ACCESS_DENIED);
74
upslogx(LOG_INFO, "Instant command: %s@%s did %s on %s",
75
client->username, client->addr, cmdname,
78
snprintf(sockcmd, sizeof(sockcmd), "INSTCMD %s\n", cmdname);
80
if (!sstate_sendline(ups, sockcmd)) {
81
upslogx(LOG_INFO, "Set command send failed");
82
send_err(client, NUT_ERR_INSTCMD_FAILED);
86
sendback(client, "OK\n");
89
int net_instcmd(ctype *client, int numarg, char **arg)
93
/* can't do this until 2.0 - backwards compatibilty */
94
/* send_err(client, NUT_ERR_INVALID_ARGUMENT); */
96
return 0; /* not handled - fall through */
99
/* the old way only had one arg, so 2 args is for us */
101
send_instcmd(client, arg[0], arg[1]);
102
return 1; /* handled */