1 /* netmisc.c - miscellaneous network handlers for upsd (VER, HELP, FSD)
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
27 #include "user.h" /* for user_checkaction */
32 void net_ver(nut_ctype_t
*client
, size_t numarg
, const char **arg
)
34 int pkgurlHasNutOrg
= 0;
35 NUT_UNUSED_VARIABLE(arg
);
38 send_err(client
, NUT_ERR_INVALID_ARGUMENT
);
42 #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE
43 #pragma GCC diagnostic push
45 #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE
46 #pragma GCC diagnostic ignored "-Wunreachable-code"
49 #pragma clang diagnostic push
50 #pragma clang diagnostic ignored "-Wunreachable-code"
52 if (PACKAGE_URL
&& strstr(PACKAGE_URL
, "networkupstools.org")) {
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",
64 PACKAGE_URL
? PACKAGE_URL
: "",
65 (PACKAGE_URL
&& !pkgurlHasNutOrg
) ? " or " : "",
66 pkgurlHasNutOrg
? "" : "https://www.networkupstools.org/"
69 #pragma clang diagnostic pop
71 #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE
72 #pragma GCC diagnostic pop
76 void net_netver(nut_ctype_t
*client
, size_t numarg
, const char **arg
)
78 NUT_UNUSED_VARIABLE(arg
);
80 send_err(client
, NUT_ERR_INVALID_ARGUMENT
);
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
);
91 send_err(client
, NUT_ERR_INVALID_ARGUMENT
);
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
)
105 send_err(client
, NUT_ERR_INVALID_ARGUMENT
);
109 ups
= get_ups_ptr(arg
[0]);
112 send_err(client
, NUT_ERR_UNKNOWN_UPS
);
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
);
122 upslogx(LOG_INFO
, "Client %s@%s set FSD on UPS [%s]",
123 client
->username
, client
->addr
, ups
->name
);
126 sendback(client
, "OK FSD-SET\n");