ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_help.c
Revision: 2657
Committed: Thu Dec 12 19:04:53 2013 UTC (11 years, 8 months ago) by michael
Content type: text/x-csrc
File size: 4280 byte(s)
Log Message:
- m_help.c:sendhelpfile(): fixed fd leak

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 "client.h"
27 #include "ircd.h"
28 #include "numeric.h"
29 #include "send.h"
30 #include "conf.h"
31 #include "parse.h"
32 #include "modules.h"
33 #include "irc_string.h"
34
35 #define HELPLEN 400
36
37
38 static void
39 sendhelpfile(struct Client *source_p, const char *path, const char *topic)
40 {
41 FILE *file = NULL;
42 char line[HELPLEN] = { '\0' };
43
44 if ((file = fopen(path, "r")) == NULL)
45 {
46 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
47 me.name, source_p->name, topic);
48 return;
49 }
50
51 if (fgets(line, sizeof(line), file) == NULL)
52 {
53 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
54 me.name, source_p->name, topic);
55 fclose(file);
56 return;
57 }
58
59 line[strlen(line) - 1] = '\0';
60 sendto_one(source_p, form_str(RPL_HELPSTART),
61 me.name, source_p->name, topic, line);
62
63 while (fgets(line, sizeof(line), file))
64 {
65 line[strlen(line) - 1] = '\0';
66
67 sendto_one(source_p, form_str(RPL_HELPTXT),
68 me.name, source_p->name, topic, line);
69 }
70
71 fclose(file);
72 sendto_one(source_p, form_str(RPL_ENDOFHELP),
73 me.name, source_p->name, topic);
74 }
75
76 static void
77 dohelp(struct Client *source_p, char *topic)
78 {
79 char *p = topic;
80 char h_index[] = "index";
81 char path[HYB_PATH_MAX + 1];
82 struct stat sb;
83
84 if (EmptyString(topic))
85 topic = h_index;
86 else
87 for (; *p; ++p)
88 *p = ToLower(*p);
89
90 if (strpbrk(topic, "/\\"))
91 {
92 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
93 me.name, source_p->name, topic);
94 return;
95 }
96
97 if (strlen(HPATH) + strlen(topic) + 1 > HYB_PATH_MAX)
98 {
99 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
100 me.name, source_p->name, topic);
101 return;
102 }
103
104 snprintf(path, sizeof(path), "%s/%s", HPATH, topic);
105
106 if (stat(path, &sb) < 0)
107 {
108 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
109 me.name, source_p->name, topic);
110 return;
111 }
112
113 if (!S_ISREG(sb.st_mode))
114 {
115 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
116 me.name, source_p->name, topic);
117 return;
118 }
119
120 sendhelpfile(source_p, path, topic);
121 }
122
123 /*
124 * m_help - HELP message handler
125 * parv[0] = sender prefix
126 */
127 static void
128 m_help(struct Client *client_p, struct Client *source_p,
129 int parc, char *parv[])
130 {
131 static time_t last_used = 0;
132
133 /* HELP is always local */
134 if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime)
135 {
136 /* safe enough to give this on a local connect only */
137 sendto_one(source_p,form_str(RPL_LOAD2HI),
138 me.name, source_p->name);
139 return;
140 }
141
142 last_used = CurrentTime;
143
144 dohelp(source_p, parv[1]);
145 }
146
147 /*
148 * mo_help - HELP message handler
149 * parv[0] = sender prefix
150 */
151 static void
152 mo_help(struct Client *client_p, struct Client *source_p,
153 int parc, char *parv[])
154 {
155 dohelp(source_p, parv[1]);
156 }
157
158 static struct Message help_msgtab = {
159 "HELP", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
160 {m_unregistered, m_help, m_ignore, m_ignore, mo_help, m_ignore}
161 };
162
163 static void
164 module_init(void)
165 {
166 mod_add_cmd(&help_msgtab);
167 }
168
169 static void
170 module_exit(void)
171 {
172 mod_del_cmd(&help_msgtab);
173 }
174
175 struct module module_entry = {
176 .node = { NULL, NULL, NULL },
177 .name = NULL,
178 .version = "$Revision$",
179 .handle = NULL,
180 .modinit = module_init,
181 .modexit = module_exit,
182 .flags = 0
183 };

Properties

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