-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.c
98 lines (80 loc) · 2.73 KB
/
commands.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* Routines for looking up commands in a *Serv command list.
*
* Services is copyright (c) 1996-1999 Andrew Church.
* E-mail: <achurch@dragonfire.net>
* Services is copyright (c) 1999-2000 Andrew Kempe.
* E-mail: <theshadow@shadowfire.org>
* This program is free but copyrighted software; see the file COPYING for
* details.
*/
#include "services.h"
#include "commands.h"
#include "language.h"
/*************************************************************************/
/* Return the Command corresponding to the given name, or NULL if no such
* command exists.
*/
Command *lookup_cmd(Command *list, const char *cmd)
{
Command *c;
for (c = list; c->name; c++) {
if (stricmp(c->name, cmd) == 0)
return c;
}
return NULL;
}
/*************************************************************************/
/* Run the routine for the given command, if it exists and the user has
* privilege to do so; if not, print an appropriate error message.
*/
void run_cmd(const char *service, User *u, Command *list, const char *cmd)
{
Command *c = lookup_cmd(list, cmd);
if (c && c->routine) {
if ((c->has_priv == NULL) || c->has_priv(u))
c->routine(u);
else
notice_lang(service, u, ACCESS_DENIED);
} else {
notice_lang(service, u, UNKNOWN_COMMAND_HELP, cmd, service);
}
}
/*************************************************************************/
/* Print a help message for the given command. */
void help_cmd(const char *service, User *u, Command *list, const char *cmd)
{
Command *c = lookup_cmd(list, cmd);
if (c) {
const char *p1 = c->help_param1,
*p2 = c->help_param2,
*p3 = c->help_param3,
*p4 = c->help_param4;
if (c->helpmsg_all >= 0) {
notice_help(service, u, c->helpmsg_all, p1, p2, p3, p4);
}
if (is_services_root(u)) {
if (c->helpmsg_root >= 0)
notice_help(service, u, c->helpmsg_root, p1, p2, p3, p4);
else if (c->helpmsg_all < 0)
notice_lang(service, u, NO_HELP_AVAILABLE, cmd);
} else if (is_services_admin(u)) {
if (c->helpmsg_admin >= 0)
notice_help(service, u, c->helpmsg_admin, p1, p2, p3, p4);
else if (c->helpmsg_all < 0)
notice_lang(service, u, NO_HELP_AVAILABLE, cmd);
} else if (is_services_oper(u)) {
if (c->helpmsg_oper >= 0)
notice_help(service, u, c->helpmsg_oper, p1, p2, p3, p4);
else if (c->helpmsg_all < 0)
notice_lang(service, u, NO_HELP_AVAILABLE, cmd);
} else {
if (c->helpmsg_reg >= 0)
notice_help(service, u, c->helpmsg_reg, p1, p2, p3, p4);
else if (c->helpmsg_all < 0)
notice_lang(service, u, NO_HELP_AVAILABLE, cmd);
}
} else {
notice_lang(service, u, NO_HELP_AVAILABLE, cmd);
}
}
/*************************************************************************/