drivers/usbhid-ups.c: upsdrv_initups(): update comments about logical progression...
[networkupstools.git] / server / netmisc.c
blobfbf8e0eb31c20ecf9a3597a03e4ca804f67b6a2a
1 /* netmisc.c - miscellaneous network handlers for upsd (VER, HELP, FSD)
3 Copyright (C)
4 2003 Russell Kroll <rkroll@exploits.org>
5 2012 Arnaud Quette <arnaud.quette.free.fr>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "common.h"
24 #include "upsd.h"
25 #include "sstate.h"
26 #include "state.h"
27 #include "user.h" /* for user_checkaction */
28 #include "neterr.h"
30 #include "netmisc.h"
32 void net_ver(nut_ctype_t *client, size_t numarg, const char **arg)
34 int pkgurlHasNutOrg = 0;
35 NUT_UNUSED_VARIABLE(arg);
37 if (numarg != 0) {
38 send_err(client, NUT_ERR_INVALID_ARGUMENT);
39 return;
42 #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE
43 #pragma GCC diagnostic push
44 #endif
45 #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE
46 #pragma GCC diagnostic ignored "-Wunreachable-code"
47 #endif
48 #ifdef __clang__
49 #pragma clang diagnostic push
50 #pragma clang diagnostic ignored "-Wunreachable-code"
51 #endif
52 if (PACKAGE_URL && strstr(PACKAGE_URL, "networkupstools.org")) {
53 pkgurlHasNutOrg = 1;
54 } else {
55 upsdebugx(1, "%s: WARNING: PACKAGE_URL of this build does not point to networkupstools.org!", __func__);
58 /* NOTE: Some compilers deduce that macro-based decisions about
59 * NUT_VERSION_IS_RELEASE make one of codepaths unreachable in
60 * a particular build. So we pragmatically handwave this away.
62 sendback(client, "Network UPS Tools upsd %s - %s%s%s\n",
63 UPS_VERSION,
64 PACKAGE_URL ? PACKAGE_URL : "",
65 (PACKAGE_URL && !pkgurlHasNutOrg) ? " or " : "",
66 pkgurlHasNutOrg ? "" : "https://www.networkupstools.org/"
68 #ifdef __clang__
69 #pragma clang diagnostic pop
70 #endif
71 #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE
72 #pragma GCC diagnostic pop
73 #endif
76 void net_netver(nut_ctype_t *client, size_t numarg, const char **arg)
78 NUT_UNUSED_VARIABLE(arg);
79 if (numarg != 0) {
80 send_err(client, NUT_ERR_INVALID_ARGUMENT);
81 return;
84 sendback(client, "%s\n", NUT_NETVERSION);
87 void net_help(nut_ctype_t *client, size_t numarg, const char **arg)
89 NUT_UNUSED_VARIABLE(arg);
90 if (numarg != 0) {
91 send_err(client, NUT_ERR_INVALID_ARGUMENT);
92 return;
95 sendback(client, "Commands: HELP VER PROTVER GET LIST SET INSTCMD"
96 " LOGIN LOGOUT USERNAME PASSWORD STARTTLS\n");
97 /* Not exposed: PRIMARY/MASTER FSD */
100 void net_fsd(nut_ctype_t *client, size_t numarg, const char **arg)
102 upstype_t *ups;
104 if (numarg != 1) {
105 send_err(client, NUT_ERR_INVALID_ARGUMENT);
106 return;
109 ups = get_ups_ptr(arg[0]);
111 if (!ups) {
112 send_err(client, NUT_ERR_UNKNOWN_UPS);
113 return;
116 /* make sure this user is allowed to do FSD */
117 if (!user_checkaction(client->username, client->password, "FSD")) {
118 send_err(client, NUT_ERR_ACCESS_DENIED);
119 return;
122 upslogx(LOG_INFO, "Client %s@%s set FSD on UPS [%s]",
123 client->username, client->addr, ups->name);
125 ups->fsd = 1;
126 sendback(client, "OK FSD-SET\n");