ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_help.c
Revision: 1054
Committed: Thu Jan 28 09:03:11 2010 UTC (14 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 5562 byte(s)
Log Message:
- m_help.c: logging unfound help-topics that are triggered by simple HELP
  requests is just stupid, as this can be easily abused.

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * m_help.c: Provides help information to a user/operator.
4 *
5 * Copyright (C) 2002 by the past and present ircd coders, and others.
6 *
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.
11 *
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.
16 *
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
20 * USA
21 *
22 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "handlers.h"
27 #include "client.h"
28 #include "ircd.h"
29 #include "ircd_handler.h"
30 #include "msg.h"
31 #include "numeric.h"
32 #include "send.h"
33 #include "s_conf.h"
34 #include "s_log.h"
35 #include "parse.h"
36 #include "modules.h"
37 #include "irc_string.h"
38
39 #define HELPLEN 400
40
41 static void m_help(struct Client *, struct Client *, int, char *[]);
42 static void mo_help(struct Client *, struct Client *, int, char *[]);
43 static void mo_uhelp(struct Client *, struct Client *, int, char *[]);
44 static void dohelp(struct Client *, const char *, char *);
45 static void sendhelpfile(struct Client *, const char *, const char *);
46
47 struct Message help_msgtab = {
48 "HELP", 0, 0, 0, 0, MFLG_SLOW, 0,
49 {m_unregistered, m_help, m_ignore, m_ignore, mo_help, m_ignore}
50 };
51
52 struct Message uhelp_msgtab = {
53 "UHELP", 0, 0, 0, 0, MFLG_SLOW, 0,
54 {m_unregistered, m_help, m_ignore, m_ignore, mo_uhelp, m_ignore}
55 };
56
57 #ifndef STATIC_MODULES
58 void
59 _modinit(void)
60 {
61 mod_add_cmd(&help_msgtab);
62 mod_add_cmd(&uhelp_msgtab);
63 }
64
65 void
66 _moddeinit(void)
67 {
68 mod_del_cmd(&help_msgtab);
69 mod_del_cmd(&uhelp_msgtab);
70 }
71
72 const char *_version = "$Revision$";
73 #endif
74
75 /*
76 * m_help - HELP message handler
77 * parv[0] = sender prefix
78 */
79 static void
80 m_help(struct Client *client_p, struct Client *source_p,
81 int parc, char *parv[])
82 {
83 static time_t last_used = 0;
84
85 /* HELP is always local */
86 if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime)
87 {
88 /* safe enough to give this on a local connect only */
89 sendto_one(source_p,form_str(RPL_LOAD2HI),
90 me.name, source_p->name);
91 return;
92 }
93
94 last_used = CurrentTime;
95
96 dohelp(source_p, UHPATH, parv[1]);
97 }
98
99 /*
100 * mo_help - HELP message handler
101 * parv[0] = sender prefix
102 */
103 static void
104 mo_help(struct Client *client_p, struct Client *source_p,
105 int parc, char *parv[])
106 {
107 dohelp(source_p, HPATH, parv[1]);
108 }
109
110 /*
111 * mo_uhelp - HELP message handler
112 * This is used so that opers can view the user help file without deopering
113 * parv[0] = sender prefix
114 */
115 static void
116 mo_uhelp(struct Client *client_p, struct Client *source_p,
117 int parc, char *parv[])
118 {
119 dohelp(source_p, UHPATH, parv[1]);
120 }
121
122 static void
123 dohelp(struct Client *source_p, const char *hpath, char *topic)
124 {
125 char h_index[] = "index";
126 char path[PATH_MAX + 1];
127 struct stat sb;
128 int i;
129
130 if (topic != NULL)
131 {
132 if (*topic == '\0')
133 topic = h_index;
134 else
135 {
136 /* convert to lower case */
137 for (i = 0; topic[i] != '\0'; ++i)
138 topic[i] = ToLower(topic[i]);
139 }
140 }
141 else
142 topic = h_index; /* list available help topics */
143
144 if (strpbrk(topic, "/\\"))
145 {
146 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
147 me.name, source_p->name, topic);
148 return;
149 }
150
151 if (strlen(hpath) + strlen(topic) + 1 > PATH_MAX)
152 {
153 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
154 me.name, source_p->name, topic);
155 return;
156 }
157
158 snprintf(path, sizeof(path), "%s/%s", hpath, topic);
159
160 if (stat(path, &sb) < 0)
161 {
162 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
163 me.name, source_p->name, topic);
164 return;
165 }
166
167 if (!S_ISREG(sb.st_mode))
168 {
169 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
170 me.name, source_p->name, topic);
171 return;
172 }
173
174 sendhelpfile(source_p, path, topic);
175 }
176
177 static void
178 sendhelpfile(struct Client *source_p, const char *path, const char *topic)
179 {
180 FBFILE *file;
181 char line[HELPLEN];
182 char started = 0;
183 int type;
184
185 if ((file = fbopen(path, "r")) == NULL)
186 {
187 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
188 me.name, source_p->name, topic);
189 return;
190 }
191
192 if (fbgets(line, sizeof(line), file) == NULL)
193 {
194 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
195 me.name, source_p->name, topic);
196 return;
197 }
198
199 else if (line[0] != '#')
200 {
201 line[strlen(line) - 1] = '\0';
202 sendto_one(source_p, form_str(RPL_HELPSTART),
203 me.name, source_p->name, topic, line);
204 started = 1;
205 }
206
207 while (fbgets(line, sizeof(line), file))
208 {
209 line[strlen(line) - 1] = '\0';
210 if (line[0] != '#')
211 {
212 if (!started)
213 {
214 type = RPL_HELPSTART;
215 started = 1;
216 }
217 else
218 type = RPL_HELPTXT;
219
220 sendto_one(source_p, form_str(RPL_HELPTXT),
221 me.name, source_p->name, topic, line);
222 }
223 }
224
225 fbclose(file);
226 sendto_one(source_p, form_str(RPL_HELPTXT),
227 me.name, source_p->name, topic, "");
228 sendto_one(source_p, form_str(RPL_ENDOFHELP),
229 me.name, source_p->name, topic);
230 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision