1
/* netuser.c - LOGIN/LOGOUT/USERNAME/PASSWORD/MASTER handlers 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
26
#include "user.h" /* for user_checkaction */
31
void net_login(ctype *client, int numarg, const char **arg)
36
send_err(client, NUT_ERR_INVALID_ARGUMENT);
40
if (client->loginups != NULL) {
43
upslogx(LOG_INFO, "Client %s@%s tried to login twice",
44
client->username, client->addr);
46
upslogx(LOG_INFO, "Client on %s tried to login twice",
49
send_err(client, NUT_ERR_ALREADY_LOGGED_IN);
53
/* make sure we got a valid UPS name */
54
ups = get_ups_ptr(arg[0]);
57
send_err(client, NUT_ERR_UNKNOWN_UPS);
62
client->loginups = xstrdup(ups->name);
64
upslogx(LOG_INFO, "Client %s@%s logged into UPS [%s]%s",
65
client->username, client->addr, client->loginups,
66
client->ssl ? " (SSL)" : "");
68
sendback(client, "OK\n");
71
void net_logout(ctype *client, int numarg, const char **arg)
74
send_err(client, NUT_ERR_INVALID_ARGUMENT);
79
upslogx(LOG_INFO, "Client %s@%s logged out",
80
client->username, client->addr);
82
upslogx(LOG_INFO, "Client on %s logged out", client->addr);
84
sendback(client, "OK Goodbye\n");
88
/* MASTER <upsname> */
89
void net_master(ctype *client, int numarg, const char **arg)
94
send_err(client, NUT_ERR_INVALID_ARGUMENT);
98
ups = get_ups_ptr(arg[0]);
101
send_err(client, NUT_ERR_UNKNOWN_UPS);
105
/* make sure this user is allowed to do MASTER */
106
if (!user_checkaction(&client->sock, client->username,
107
client->password, "MASTER")) {
109
send_err(client, NUT_ERR_ACCESS_DENIED);
113
/* this is just an access level check */
114
sendback(client, "OK MASTER-GRANTED\n");
117
/* USERNAME <username> */
118
void net_username(ctype *client, int numarg, const char **arg)
121
send_err(client, NUT_ERR_INVALID_ARGUMENT);
125
if (client->username != NULL) {
126
upslogx(LOG_INFO, "Client %s@%s tried to set a username twice",
127
client->username, client->addr);
129
send_err(client, NUT_ERR_ALREADY_SET_USERNAME);
133
client->username = xstrdup(arg[0]);
134
sendback(client, "OK\n");
137
/* PASSWORD <password> */
138
void net_password(ctype *client, int numarg, const char **arg)
141
send_err(client, NUT_ERR_INVALID_ARGUMENT);
145
if (client->password != NULL) {
146
if (client->username)
147
upslogx(LOG_INFO, "Client %s@%s tried to set a password twice",
148
client->username, client->addr);
150
upslogx(LOG_INFO, "Client on %s tried to set a password twice",
153
send_err(client, NUT_ERR_ALREADY_SET_PASSWORD);
157
client->password = xstrdup(arg[0]);
158
sendback(client, "OK\n");