/[LeafOK_CVS]/pvpgn-1.7.4/src/bnetd/handle_telnet.c
ViewVC logotype

Contents of /pvpgn-1.7.4/src/bnetd/handle_telnet.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (vendor branch)
Tue Jun 6 03:41:37 2006 UTC (19 years, 9 months ago) by sysadm
Branch: GNU, MAIN
CVS Tags: pvpgn_1-7-4-0_MIL, arelease, HEAD
Changes since 1.1: +0 -0 lines
Content type: text/x-csrc
Error occurred while calculating annotation data.
no message

1 /*
2 * Copyright (C) 2001 Ross Combs (rocombs@cs.nmsu.edu)
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18 #include "common/setup_before.h"
19 #ifdef HAVE_STDDEF_H
20 # include <stddef.h>
21 #else
22 # ifndef NULL
23 # define NULL ((void *)0)
24 # endif
25 #endif
26 #ifdef STDC_HEADERS
27 # include <stdlib.h>
28 #endif
29 #ifdef HAVE_STRING_H
30 # include <string.h>
31 #else
32 # ifdef HAVE_STRINGS_H
33 # include <strings.h>
34 # endif
35 # ifdef HAVE_MEMORY_H
36 # include <memory.h>
37 # endif
38 #endif
39 #include "compat/strdup.h"
40 #include <ctype.h>
41 #include "common/packet.h"
42 #include "common/tag.h"
43 #include "message.h"
44 #include "common/eventlog.h"
45 #include "command.h"
46 #include "account.h"
47 #include "account_wrap.h"
48 #include "connection.h"
49 #include "channel.h"
50 #include "common/queue.h"
51 #include "common/bnethash.h"
52 #include "common/bnethashconv.h"
53 #include "common/bn_type.h"
54 #include "common/field_sizes.h"
55 #include "common/list.h"
56 #include "common/xalloc.h"
57 #include "handle_telnet.h"
58 #include "common/setup_after.h"
59
60
61 extern int handle_telnet_packet(t_connection * c, t_packet const * const packet)
62 {
63 t_packet * rpacket;
64
65 if (!c)
66 {
67 eventlog(eventlog_level_error,__FUNCTION__,"[%d] got NULL connection",conn_get_socket(c));
68 return -1;
69 }
70 if (!packet)
71 {
72 eventlog(eventlog_level_error,__FUNCTION__,"[%d] got NULL packet",conn_get_socket(c));
73 return -1;
74 }
75 if (packet_get_class(packet)!=packet_class_raw)
76 {
77 eventlog(eventlog_level_error,__FUNCTION__,"[%d] got bad packet (class %d)",conn_get_socket(c),(int)packet_get_class(packet));
78 return -1;
79 }
80
81 {
82 char const * const linestr=packet_get_str_const(packet,0,MAX_MESSAGE_LEN);
83
84 if (packet_get_size(packet)<2) /* empty line */
85 return 0;
86 if (!linestr)
87 {
88 eventlog(eventlog_level_warn,__FUNCTION__,"[%d] line too long",conn_get_socket(c));
89 return 0;
90 }
91
92 switch (conn_get_state(c))
93 {
94 case conn_state_connected:
95 conn_add_flags(c,MF_PLUG);
96 conn_set_clienttag(c,CLIENTTAG_BNCHATBOT_UINT);
97
98 {
99 char const * temp=linestr;
100
101 if (temp[0]=='\004') /* FIXME: no echo, ignore for now (we always do no echo) */
102 temp = &temp[1];
103
104 if (temp[0]=='\0') /* empty line */
105 {
106 conn_set_state(c,conn_state_bot_username); /* don't look for ^D or reset tag and flags */
107 break;
108 }
109
110 conn_set_state(c,conn_state_bot_password);
111
112 if (conn_set_loggeduser(c,temp)<0)
113 eventlog(eventlog_level_error,__FUNCTION__,"[%d] could not set username to \"%s\"",conn_get_socket(c),temp);
114
115 {
116 char const * const msg="\r\nPassword: ";
117
118 if (!(rpacket = packet_create(packet_class_raw)))
119 {
120 eventlog(eventlog_level_error,__FUNCTION__,"[%d] could not create rpacket",conn_get_socket(c));
121 break;
122 }
123 #if 0 /* don't echo */
124 packet_append_ntstring(rpacket,conn_get_loggeduser(c));
125 #endif
126 packet_append_ntstring(rpacket,msg);
127 conn_push_outqueue(c,rpacket);
128 packet_del_ref(rpacket);
129 }
130 }
131 break;
132
133 case conn_state_bot_username:
134 conn_set_state(c,conn_state_bot_password);
135
136 if (conn_set_loggeduser(c,linestr)<0)
137 eventlog(eventlog_level_error,__FUNCTION__,"[%d] could not set username to \"%s\"",conn_get_socket(c),linestr);
138
139 {
140 char const * const temp="\r\nPassword: ";
141
142 if (!(rpacket = packet_create(packet_class_raw)))
143 {
144 eventlog(eventlog_level_error,__FUNCTION__,"[%d] could not create rpacket",conn_get_socket(c));
145 break;
146 }
147 #if 0 /* don't echo */
148 packet_append_ntstring(rpacket,linestr);
149 #endif
150 packet_append_ntstring(rpacket,temp);
151 conn_push_outqueue(c,rpacket);
152 packet_del_ref(rpacket);
153 }
154 break;
155
156 case conn_state_bot_password:
157 {
158 char const * const tempa="\r\nLogin failed.\r\n\r\nUsername: ";
159 char const * const tempb="\r\nAccount has no bot access.\r\n\r\nUsername: ";
160 char const * const loggeduser=conn_get_loggeduser(c);
161 t_account * account;
162 char const * oldstrhash1;
163 t_hash trypasshash1;
164 t_hash oldpasshash1;
165 char * testpass;
166
167 if (!loggeduser) /* error earlier in login */
168 {
169 /* no log message... */
170 conn_set_state(c,conn_state_bot_username);
171
172 if (!(rpacket = packet_create(packet_class_raw)))
173 {
174 eventlog(eventlog_level_error,__FUNCTION__,"[%d] could not create rpacket",conn_get_socket(c));
175 break;
176 }
177
178 packet_append_ntstring(rpacket,tempa);
179 conn_push_outqueue(c,rpacket);
180 packet_del_ref(rpacket);
181 break;
182 }
183 if (connlist_find_connection_by_accountname(loggeduser))
184 {
185 eventlog(eventlog_level_info,__FUNCTION__,"[%d] bot login for \"%s\" refused (already logged in)",conn_get_socket(c),loggeduser);
186 conn_set_state(c,conn_state_bot_username);
187
188 if (!(rpacket = packet_create(packet_class_raw)))
189 {
190 eventlog(eventlog_level_error,__FUNCTION__,"[%d] could not create rpacket",conn_get_socket(c));
191 break;
192 }
193
194 packet_append_ntstring(rpacket,tempa);
195 conn_push_outqueue(c,rpacket);
196 packet_del_ref(rpacket);
197 break;
198 }
199 if (!(account = accountlist_find_account(loggeduser)))
200 {
201 eventlog(eventlog_level_info,__FUNCTION__,"[%d] bot login for \"%s\" refused (bad account)",conn_get_socket(c),loggeduser);
202 conn_set_state(c,conn_state_bot_username);
203
204 if (!(rpacket = packet_create(packet_class_raw)))
205 {
206 eventlog(eventlog_level_error,__FUNCTION__,"[%d] could not create rpacket",conn_get_socket(c));
207 break;
208 }
209
210 packet_append_ntstring(rpacket,tempa);
211 conn_push_outqueue(c,rpacket);
212 packet_del_ref(rpacket);
213 break;
214 }
215 if ((oldstrhash1 = account_get_pass(account)))
216 {
217 if (hash_set_str(&oldpasshash1,oldstrhash1)<0)
218 {
219 eventlog(eventlog_level_info,__FUNCTION__,"[%d] bot login for \"%s\" refused (corrupted passhash1?)",conn_get_socket(c),account_get_name(account));
220 conn_set_state(c,conn_state_bot_username);
221
222 if (!(rpacket = packet_create(packet_class_raw)))
223 {
224 eventlog(eventlog_level_error,__FUNCTION__,"[%d] could not create rpacket",conn_get_socket(c));
225 break;
226 }
227
228 packet_append_ntstring(rpacket,tempa);
229 conn_push_outqueue(c,rpacket);
230 packet_del_ref(rpacket);
231 break;
232 }
233
234 testpass = xstrdup(linestr);
235 {
236 unsigned int i;
237
238 for (i=0; i<strlen(testpass); i++)
239 if (isupper((int)testpass[i]))
240 testpass[i] = tolower((int)testpass[i]);
241 }
242 if (bnet_hash(&trypasshash1,strlen(testpass),testpass)<0) /* FIXME: force to lowercase */
243 {
244 eventlog(eventlog_level_info,__FUNCTION__,"[%d] bot login for \"%s\" refused (unable to hash password)",conn_get_socket(c),account_get_name(account));
245 xfree(testpass);
246
247 conn_set_state(c,conn_state_bot_username);
248
249 if (!(rpacket = packet_create(packet_class_raw)))
250 {
251 eventlog(eventlog_level_error,__FUNCTION__,"[%d] could not create rpacket",conn_get_socket(c));
252 break;
253 }
254
255 packet_append_ntstring(rpacket,tempa);
256 conn_push_outqueue(c,rpacket);
257 packet_del_ref(rpacket);
258 break;
259 }
260 xfree(testpass);
261 if (hash_eq(trypasshash1,oldpasshash1)!=1)
262 {
263 eventlog(eventlog_level_info,__FUNCTION__,"[%d] bot login for \"%s\" refused (wrong password)",conn_get_socket(c),account_get_name(account));
264 conn_set_state(c,conn_state_bot_username);
265
266 if (!(rpacket = packet_create(packet_class_raw)))
267 {
268 eventlog(eventlog_level_error,__FUNCTION__,"[%d] could not create rpacket",conn_get_socket(c));
269 break;
270 }
271
272 packet_append_ntstring(rpacket,tempa);
273 conn_push_outqueue(c,rpacket);
274 packet_del_ref(rpacket);
275 break;
276 }
277
278
279 if (account_get_auth_botlogin(account)!=1) /* default to false */
280 {
281 eventlog(eventlog_level_info,__FUNCTION__,"[%d] bot login for \"%s\" refused (no bot access)",conn_get_socket(c),account_get_name(account));
282 conn_set_state(c,conn_state_bot_username);
283
284 if (!(rpacket = packet_create(packet_class_raw)))
285 {
286 eventlog(eventlog_level_error,__FUNCTION__,"[%d] could not create rpacket",conn_get_socket(c));
287 break;
288 }
289
290 packet_append_ntstring(rpacket,tempb);
291 conn_push_outqueue(c,rpacket);
292 packet_del_ref(rpacket);
293 break;
294 }
295 else if (account_get_auth_lock(account)==1) /* default to false */
296 {
297 eventlog(eventlog_level_info,__FUNCTION__,"[%d] bot login for \"%s\" refused (this account is locked)",conn_get_socket(c),account_get_name(account));
298 conn_set_state(c,conn_state_bot_username);
299
300 if (!(rpacket = packet_create(packet_class_raw)))
301 {
302 eventlog(eventlog_level_error,__FUNCTION__,"[%d] could not create rpacket",conn_get_socket(c));
303 break;
304 }
305
306 packet_append_ntstring(rpacket,tempb);
307 conn_push_outqueue(c,rpacket);
308 packet_del_ref(rpacket);
309 break;
310 }
311
312 eventlog(eventlog_level_info,__FUNCTION__,"[%d] \"%s\" bot logged in (correct password)",conn_get_socket(c),account_get_name(account));
313 }
314 else
315 eventlog(eventlog_level_info,__FUNCTION__,"[%d] \"%s\" bot logged in (no password)",conn_get_socket(c),account_get_name(account));
316
317 if (!(rpacket = packet_create(packet_class_raw))) /* if we got this far, let them log in even if this fails */
318 eventlog(eventlog_level_error,__FUNCTION__,"[%d] could not create rpacket",conn_get_socket(c));
319 else
320 {
321 packet_append_ntstring(rpacket,"\r\n");
322 conn_push_outqueue(c,rpacket);
323 packet_del_ref(rpacket);
324 }
325 message_send_text(c,message_type_uniqueid,c,account_get_name(account));
326
327 conn_login(c,account,loggeduser);
328
329 if (conn_set_channel(c,CHANNEL_NAME_CHAT)<0)
330 conn_set_channel(c,CHANNEL_NAME_BANNED); /* should not fail */
331 }
332 break;
333
334 case conn_state_loggedin:
335 {
336 t_channel const * channel;
337
338 conn_set_idletime(c);
339
340 if ((channel = conn_get_channel(c)))
341 channel_message_log(channel,c,1,linestr);
342 /* we don't log game commands currently */
343
344 if (linestr[0]=='/')
345 handle_command(c,linestr);
346 else
347 if (channel && !conn_quota_exceeded(c,linestr))
348 channel_message_send(channel,message_type_talk,c,linestr);
349 /* else discard */
350 }
351 break;
352
353 default:
354 eventlog(eventlog_level_error,__FUNCTION__,"[%d] unknown telnet connection state %d",conn_get_socket(c),(int)conn_get_state(c));
355 }
356 }
357
358 return 0;
359 }

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1