]> andersk Git - libfaim.git/blame - src/login.c
- Sun Oct 14 19:45:54 PDT 2001
[libfaim.git] / src / login.c
CommitLineData
9de3ca7e 1/*
2 * aim_login.c
3 *
4 * This contains all the functions needed to actually login.
5 *
6 */
7
37ee990e 8#define FAIM_INTERNAL
dd60ff8b 9#include <aim.h>
9de3ca7e 10
b5bc2a8c 11#include "md5.h"
12
5daacaa3 13static int aim_encode_password(const char *password, unsigned char *encoded);
9de3ca7e 14
d410cf58 15faim_export int aim_sendflapver(aim_session_t *sess, aim_conn_t *conn)
01b59e1e 16{
d410cf58 17 aim_frame_t *fr;
01b59e1e 18
d410cf58 19 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x01, 4)))
355229fe 20 return -ENOMEM;
01b59e1e 21
d410cf58 22 aimbs_put32(&fr->data, 0x00000001);
355229fe 23
d410cf58 24 aim_tx_enqueue(sess, fr);
355229fe 25
d410cf58 26 return 0;
01b59e1e 27}
28
3e9e6e14 29/*
30 * This is a bit confusing.
31 *
32 * Normal SNAC login goes like this:
33 * - connect
34 * - server sends flap version
35 * - client sends flap version
36 * - client sends screen name (17/6)
37 * - server sends hash key (17/7)
38 * - client sends auth request (17/2 -- aim_send_login)
39 * - server yells
40 *
41 * XOR login (for ICQ) goes like this:
42 * - connect
43 * - server sends flap version
44 * - client sends auth request which contains flap version (aim_send_login)
45 * - server yells
46 *
47 * For the client API, we make them implement the most complicated version,
48 * and for the simpler version, we fake it and make it look like the more
49 * complicated process.
50 *
51 * This is done by giving the client a faked key, just so we can convince
52 * them to call aim_send_login right away, which will detect the session
53 * flag that says this is XOR login and ignore the key, sending an ICQ
54 * login request instead of the normal SNAC one.
55 *
56 * As soon as AOL makes ICQ log in the same way as AIM, this is /gone/.
57 *
58 * XXX This may cause problems if the client relies on callbacks only
59 * being called from the context of aim_rxdispatch()...
60 *
61 */
62static int goddamnicq(aim_session_t *sess, aim_conn_t *conn, const char *sn)
63{
64 aim_frame_t fr;
65 aim_rxcallback_t userfunc;
66
67 sess->flags &= ~AIM_SESS_FLAGS_SNACLOGIN;
68 sess->flags |= AIM_SESS_FLAGS_XORLOGIN;
69
70 fr.conn = conn;
71
72 if ((userfunc = aim_callhandler(sess, conn, 0x0017, 0x0007)))
73 userfunc(sess, &fr, "");
74
75 return 0;
76}
77
01b59e1e 78/*
d410cf58 79 * In AIM 3.5 protocol, the first stage of login is to request login from the
80 * Authorizer, passing it the screen name for verification. If the name is
81 * invalid, a 0017/0003 is spit back, with the standard error contents. If
82 * valid, a 0017/0007 comes back, which is the signal to send it the main
83 * login command (0017/0002).
84 *
01b59e1e 85 */
d410cf58 86faim_export int aim_request_login(aim_session_t *sess, aim_conn_t *conn, const char *sn)
01b59e1e 87{
d410cf58 88 aim_frame_t *fr;
89 aim_snacid_t snacid;
90 aim_tlvlist_t *tl = NULL;
91
355229fe 92 if (!sess || !conn || !sn)
93 return -EINVAL;
94
25aaf30e 95 if ((sn[0] >= '0') && (sn[0] <= '9'))
3e9e6e14 96 return goddamnicq(sess, conn, sn);
97
355229fe 98 sess->flags |= AIM_SESS_FLAGS_SNACLOGIN;
99
100 aim_sendflapver(sess, conn);
101
d410cf58 102 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+2+strlen(sn))))
355229fe 103 return -ENOMEM;
104
d410cf58 105 snacid = aim_cachesnac(sess, 0x0017, 0x0006, 0x0000, NULL, 0);
106 aim_putsnac(&fr->data, 0x0017, 0x0006, 0x0000, snacid);
355229fe 107
d410cf58 108 aim_addtlvtochain_raw(&tl, 0x0001, strlen(sn), sn);
109 aim_writetlvchain(&fr->data, &tl);
110 aim_freetlvchain(&tl);
355229fe 111
d410cf58 112 aim_tx_enqueue(sess, fr);
355229fe 113
d410cf58 114 return 0;
01b59e1e 115}
01b59e1e 116
3e9e6e14 117/*
118 * Part two of the ICQ hack. Note the ignoring of the key and clientinfo.
119 */
120static int goddamnicq2(aim_session_t *sess, aim_conn_t *conn, const char *sn, const char *password)
121{
122 static const char clientstr[] = {"ICQ Inc. - Product of ICQ (TM) 2000b.4.65.1.3281.85"};
123 static const char lang[] = {"en"};
124 static const char country[] = {"us"};
125 aim_frame_t *fr;
126 aim_tlvlist_t *tl = NULL;
127 char *password_encoded;
128
129 if (!(password_encoded = (char *) malloc(strlen(password))))
130 return -ENOMEM;
131
132 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x01, 1152))) {
133 free(password_encoded);
134 return -ENOMEM;
135 }
136
137 aim_encode_password(password, password_encoded);
138
139 aimbs_put32(&fr->data, 0x00000001);
140 aim_addtlvtochain_raw(&tl, 0x0001, strlen(sn), sn);
141 aim_addtlvtochain_raw(&tl, 0x0002, strlen(password), password_encoded);
142 aim_addtlvtochain_raw(&tl, 0x0003, strlen(clientstr), clientstr);
143 aim_addtlvtochain16(&tl, 0x0016, 0x010a);
144 aim_addtlvtochain16(&tl, 0x0017, 0x0004);
145 aim_addtlvtochain16(&tl, 0x0018, 0x0041);
146 aim_addtlvtochain16(&tl, 0x0019, 0x0001);
147 aim_addtlvtochain16(&tl, 0x001a, 0x0cd1);
148 aim_addtlvtochain32(&tl, 0x0014, 0x00000055);
149 aim_addtlvtochain_raw(&tl, 0x000f, strlen(lang), lang);
150 aim_addtlvtochain_raw(&tl, 0x000e, strlen(country), country);
151
152 aim_writetlvchain(&fr->data, &tl);
153
154 free(password_encoded);
155 aim_freetlvchain(&tl);
156
157 aim_tx_enqueue(sess, fr);
158
159 return 0;
160}
161
9de3ca7e 162/*
24286d93 163 * send_login(int socket, char *sn, char *password)
9de3ca7e 164 *
165 * This is the initial login request packet.
166 *
b1eac25a 167 * NOTE!! If you want/need to make use of the aim_sendmemblock() function,
168 * then the client information you send here must exactly match the
169 * executable that you're pulling the data from.
9de3ca7e 170 *
355982c5 171 * Latest WinAIM:
172 * clientstring = "AOL Instant Messenger (SM), version 4.3.2188/WIN32"
173 * major2 = 0x0109
174 * major = 0x0400
175 * minor = 0x0003
176 * minor2 = 0x0000
177 * build = 0x088c
178 * unknown = 0x00000086
179 * lang = "en"
180 * country = "us"
181 * unknown4a = 0x01
154b4093 182 *
183 * Latest WinAIM that libfaim can emulate without server-side buddylists:
b1eac25a 184 * clientstring = "AOL Instant Messenger (SM), version 4.1.2010/WIN32"
185 * major2 = 0x0004
186 * major = 0x0004
187 * minor = 0x0001
188 * minor2 = 0x0000
189 * build = 0x07da
190 * unknown= 0x0000004b
191 *
192 * WinAIM 3.5.1670:
154b4093 193 * clientstring = "AOL Instant Messenger (SM), version 3.5.1670/WIN32"
194 * major2 = 0x0004
195 * major = 0x0003
196 * minor = 0x0005
197 * minor2 = 0x0000
198 * build = 0x0686
199 * unknown =0x0000002a
200 *
d32954e7 201 * Java AIM 1.1.19:
202 * clientstring = "AOL Instant Messenger (TM) version 1.1.19 for Java built 03/24/98, freeMem 215871 totalMem 1048567, i686, Linus, #2 SMP Sun Feb 11 03:41:17 UTC 2001 2.4.1-ac9, IBM Corporation, 1.1.8, 45.3, Tue Mar 27 12:09:17 PST 2001"
203 * major2 = 0x0001
204 * major = 0x0001
205 * minor = 0x0001
206 * minor2 = (not sent)
207 * build = 0x0013
208 * unknown= (not sent)
209 *
210 * AIM for Linux 1.1.112:
211 * clientstring = "AOL Instant Messenger (SM)"
212 * major2 = 0x1d09
213 * major = 0x0001
214 * minor = 0x0001
215 * minor2 = 0x0001
216 * build = 0x0070
217 * unknown= 0x0000008b
218 * serverstore = 0x01
219 *
9de3ca7e 220 */
d410cf58 221faim_export int aim_send_login(aim_session_t *sess, aim_conn_t *conn, const char *sn, const char *password, struct client_info_s *clientinfo, const char *key)
9de3ca7e 222{
d410cf58 223 aim_frame_t *fr;
224 aim_tlvlist_t *tl = NULL;
3e9e6e14 225 fu8_t digest[16];
226 aim_snacid_t snacid;
355229fe 227
228 if (!clientinfo || !sn || !password)
229 return -EINVAL;
230
3e9e6e14 231 if (sess->flags & AIM_SESS_FLAGS_XORLOGIN)
232 return goddamnicq2(sess, conn, sn, password);
233
d410cf58 234 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152)))
355229fe 235 return -ENOMEM;
236
d410cf58 237 if (sess->flags & AIM_SESS_FLAGS_XORLOGIN) {
238 fr->hdr.flap.type = 0x01;
355229fe 239
d410cf58 240 /* Use very specific version numbers to further indicate hack */
241 clientinfo->major2 = 0x010a;
242 clientinfo->major = 0x0004;
243 clientinfo->minor = 0x003c;
244 clientinfo->minor2 = 0x0001;
245 clientinfo->build = 0x0cce;
246 clientinfo->unknown = 0x00000055;
247 }
355229fe 248
3e9e6e14 249 snacid = aim_cachesnac(sess, 0x0017, 0x0002, 0x0000, NULL, 0);
250 aim_putsnac(&fr->data, 0x0017, 0x0002, 0x0000, snacid);
355229fe 251
d410cf58 252 aim_addtlvtochain_raw(&tl, 0x0001, strlen(sn), sn);
355229fe 253
3e9e6e14 254 aim_encode_password_md5(password, key, digest);
255 aim_addtlvtochain_raw(&tl, 0x0025, 16, digest);
355229fe 256
d410cf58 257 aim_addtlvtochain_raw(&tl, 0x0003, strlen(clientinfo->clientstring), clientinfo->clientstring);
d410cf58 258 aim_addtlvtochain16(&tl, 0x0016, (fu16_t)clientinfo->major2);
259 aim_addtlvtochain16(&tl, 0x0017, (fu16_t)clientinfo->major);
260 aim_addtlvtochain16(&tl, 0x0018, (fu16_t)clientinfo->minor);
261 aim_addtlvtochain16(&tl, 0x0019, (fu16_t)clientinfo->minor2);
262 aim_addtlvtochain16(&tl, 0x001a, (fu16_t)clientinfo->build);
d410cf58 263 aim_addtlvtochain_raw(&tl, 0x000e, strlen(clientinfo->country), clientinfo->country);
264 aim_addtlvtochain_raw(&tl, 0x000f, strlen(clientinfo->lang), clientinfo->lang);
3e9e6e14 265 aim_addtlvtochain16(&tl, 0x0009, 0x0015);
355229fe 266
d410cf58 267 aim_writetlvchain(&fr->data, &tl);
355229fe 268
d410cf58 269 aim_freetlvchain(&tl);
270
271 aim_tx_enqueue(sess, fr);
355229fe 272
d410cf58 273 return 0;
9de3ca7e 274}
9de3ca7e 275
d410cf58 276faim_export int aim_encode_password_md5(const char *password, const char *key, fu8_t *digest)
b5bc2a8c 277{
355229fe 278 md5_state_t state;
b5bc2a8c 279
355229fe 280 md5_init(&state);
281 md5_append(&state, (const md5_byte_t *)key, strlen(key));
282 md5_append(&state, (const md5_byte_t *)password, strlen(password));
283 md5_append(&state, (const md5_byte_t *)AIM_MD5_STRING, strlen(AIM_MD5_STRING));
284 md5_finish(&state, (md5_byte_t *)digest);
b5bc2a8c 285
355229fe 286 return 0;
b5bc2a8c 287}
288
5daacaa3 289/**
290 * aim_encode_password - Encode a password using old XOR method
291 * @password: incoming password
292 * @encoded: buffer to put encoded password
9de3ca7e 293 *
294 * This takes a const pointer to a (null terminated) string
295 * containing the unencoded password. It also gets passed
296 * an already allocated buffer to store the encoded password.
297 * This buffer should be the exact length of the password without
5daacaa3 298 * the null. The encoded password buffer /is not %NULL terminated/.
9de3ca7e 299 *
300 * The encoding_table seems to be a fixed set of values. We'll
301 * hope it doesn't change over time!
302 *
5daacaa3 303 * This is only used for the XOR method, not the better MD5 method.
b5bc2a8c 304 *
9de3ca7e 305 */
d410cf58 306static int aim_encode_password(const char *password, fu8_t *encoded)
9de3ca7e 307{
d410cf58 308 fu8_t encoding_table[] = {
b69540e3 309#if 0 /* old v1 table */
355229fe 310 0xf3, 0xb3, 0x6c, 0x99,
311 0x95, 0x3f, 0xac, 0xb6,
312 0xc5, 0xfa, 0x6b, 0x63,
313 0x69, 0x6c, 0xc3, 0x9f
b69540e3 314#else /* v2.1 table, also works for ICQ */
355229fe 315 0xf3, 0x26, 0x81, 0xc4,
316 0x39, 0x86, 0xdb, 0x92,
317 0x71, 0xa3, 0xb9, 0xe6,
318 0x53, 0x7a, 0x95, 0x7c
b69540e3 319#endif
355229fe 320 };
321 int i;
5e02cf44 322
355229fe 323 for (i = 0; i < strlen(password); i++)
324 encoded[i] = (password[i] ^ encoding_table[i]);
5e02cf44 325
355229fe 326 return 0;
5e02cf44 327}
328
e6b05d80 329/*
330 * Generate an authorization response.
331 *
d410cf58 332 * You probably don't want this unless you're writing an AIM server. Which
333 * I hope you're not doing. Because it's far more difficult than it looks.
e6b05d80 334 *
335 */
d410cf58 336faim_export int aim_sendauthresp(aim_session_t *sess, aim_conn_t *conn, const char *sn, int errorcode, const char *errorurl, const char *bosip, const char *cookie, const char *email, int regstatus)
e6b05d80 337{
d410cf58 338 aim_tlvlist_t *tlvlist = NULL;
339 aim_frame_t *fr;
355229fe 340
d410cf58 341 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x04, 1152)))
355229fe 342 return -ENOMEM;
343
355229fe 344 if (sn)
d410cf58 345 aim_addtlvtochain_raw(&tlvlist, 0x0001, strlen(sn), sn);
355229fe 346 else
d410cf58 347 aim_addtlvtochain_raw(&tlvlist, 0x0001, strlen(sess->sn), sess->sn);
355229fe 348
349 if (errorcode) {
350 aim_addtlvtochain16(&tlvlist, 0x0008, errorcode);
d410cf58 351 aim_addtlvtochain_raw(&tlvlist, 0x0004, strlen(errorurl), errorurl);
355229fe 352 } else {
d410cf58 353 aim_addtlvtochain_raw(&tlvlist, 0x0005, strlen(bosip), bosip);
354 aim_addtlvtochain_raw(&tlvlist, 0x0006, AIM_COOKIELEN, cookie);
355 aim_addtlvtochain_raw(&tlvlist, 0x0011, strlen(email), email);
356 aim_addtlvtochain16(&tlvlist, 0x0013, (fu16_t)regstatus);
355229fe 357 }
358
d410cf58 359 aim_writetlvchain(&fr->data, &tlvlist);
360 aim_freetlvchain(&tlvlist);
361
362 aim_tx_enqueue(sess, fr);
355229fe 363
d410cf58 364 return 0;
e6b05d80 365}
366
367/*
368 * Generate a random cookie. (Non-client use only)
369 */
d410cf58 370faim_export int aim_gencookie(fu8_t *buf)
e6b05d80 371{
355229fe 372 int i;
e6b05d80 373
355229fe 374 srand(time(NULL));
e6b05d80 375
d410cf58 376 for (i = 0; i < AIM_COOKIELEN; i++)
355229fe 377 buf[i] = 1+(int) (256.0*rand()/(RAND_MAX+0.0));
e6b05d80 378
355229fe 379 return i;
e6b05d80 380}
381
382/*
383 * Send Server Ready. (Non-client)
031c2fb3 384 *
385 * XXX If anyone cares, this should be made to use the conn-stored group
386 * system.
387 *
e6b05d80 388 */
d410cf58 389faim_export int aim_sendserverready(aim_session_t *sess, aim_conn_t *conn)
e6b05d80 390{
d410cf58 391 aim_frame_t *fr;
392 aim_snacid_t snacid;
355229fe 393
d410cf58 394 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+0x22)))
355229fe 395 return -ENOMEM;
396
d410cf58 397 snacid = aim_cachesnac(sess, 0x0001, 0x0003, 0x0000, NULL, 0);
355229fe 398
d410cf58 399 aim_putsnac(&fr->data, 0x0001, 0x0003, 0x0000, snacid);
400 aimbs_put16(&fr->data, 0x0001);
401 aimbs_put16(&fr->data, 0x0002);
402 aimbs_put16(&fr->data, 0x0003);
403 aimbs_put16(&fr->data, 0x0004);
404 aimbs_put16(&fr->data, 0x0006);
405 aimbs_put16(&fr->data, 0x0008);
406 aimbs_put16(&fr->data, 0x0009);
407 aimbs_put16(&fr->data, 0x000a);
408 aimbs_put16(&fr->data, 0x000b);
409 aimbs_put16(&fr->data, 0x000c);
410 aimbs_put16(&fr->data, 0x0013);
411 aimbs_put16(&fr->data, 0x0015);
355229fe 412
d410cf58 413 aim_tx_enqueue(sess, fr);
355229fe 414
d410cf58 415 return 0;
e6b05d80 416}
417
e6b05d80 418/*
419 * Send service redirect. (Non-Client)
420 */
d410cf58 421faim_export int aim_sendredirect(aim_session_t *sess, aim_conn_t *conn, fu16_t servid, const char *ip, const char *cookie)
e6b05d80 422{
d410cf58 423 aim_tlvlist_t *tlvlist = NULL;
424 aim_frame_t *fr;
425 aim_snacid_t snacid;
355229fe 426
d410cf58 427 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152)))
355229fe 428 return -ENOMEM;
e6b05d80 429
d410cf58 430 snacid = aim_cachesnac(sess, 0x0001, 0x0005, 0x0000, NULL, 0);
431 aim_putsnac(&fr->data, 0x0001, 0x0005, 0x0000, snacid);
e6b05d80 432
355229fe 433 aim_addtlvtochain16(&tlvlist, 0x000d, servid);
d410cf58 434 aim_addtlvtochain_raw(&tlvlist, 0x0005, strlen(ip), ip);
435 aim_addtlvtochain_raw(&tlvlist, 0x0006, AIM_COOKIELEN, cookie);
e6b05d80 436
d410cf58 437 aim_writetlvchain(&fr->data, &tlvlist);
355229fe 438 aim_freetlvchain(&tlvlist);
e6b05d80 439
d410cf58 440 aim_tx_enqueue(sess, fr);
355229fe 441
d410cf58 442 return 0;
e6b05d80 443}
00ef5271 444
031c2fb3 445/*
446 * See comments in conn.c about how the group associations are supposed
447 * to work, and how they really work.
448 *
449 * This info probably doesn't even need to make it to the client.
450 *
451 */
d410cf58 452static int hostonline(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
00ef5271 453{
355229fe 454 aim_rxcallback_t userfunc;
455 int ret = 0;
d410cf58 456 fu16_t *families;
457 int famcount;
00ef5271 458
d410cf58 459 if (!(families = malloc(aim_bstream_empty(bs))))
355229fe 460 return 0;
00ef5271 461
031c2fb3 462 for (famcount = 0; aim_bstream_empty(bs); famcount++) {
d410cf58 463 families[famcount] = aimbs_get16(bs);
031c2fb3 464 aim_conn_addgroup(rx->conn, families[famcount]);
465 }
00ef5271 466
355229fe 467 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
468 ret = userfunc(sess, rx, famcount, families);
00ef5271 469
355229fe 470 free(families);
00ef5271 471
d410cf58 472 return ret;
00ef5271 473}
474
d410cf58 475static int redirect(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
00ef5271 476{
355229fe 477 int serviceid;
d410cf58 478 fu8_t *cookie;
355229fe 479 char *ip;
480 aim_rxcallback_t userfunc;
d410cf58 481 aim_tlvlist_t *tlvlist;
355229fe 482 char *chathack = NULL;
483 int chathackex = 0;
484 int ret = 0;
485
d410cf58 486 tlvlist = aim_readtlvchain(bs);
355229fe 487
488 if (!aim_gettlv(tlvlist, 0x000d, 1) ||
489 !aim_gettlv(tlvlist, 0x0005, 1) ||
490 !aim_gettlv(tlvlist, 0x0006, 1)) {
491 aim_freetlvchain(&tlvlist);
492 return 0;
493 }
494
495 serviceid = aim_gettlv16(tlvlist, 0x000d, 1);
496 ip = aim_gettlv_str(tlvlist, 0x0005, 1);
497 cookie = aim_gettlv_str(tlvlist, 0x0006, 1);
498
499 /*
500 * Chat hack.
501 */
502 if ((serviceid == AIM_CONN_TYPE_CHAT) && sess->pendingjoin) {
503 chathack = sess->pendingjoin;
504 chathackex = sess->pendingjoinexchange;
505 sess->pendingjoin = NULL;
506 sess->pendingjoinexchange = 0;
507 }
508
509 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
510 ret = userfunc(sess, rx, serviceid, ip, cookie, chathack, chathackex);
511
512 free(ip);
513 free(cookie);
514 free(chathack);
515
516 aim_freetlvchain(&tlvlist);
517
518 return ret;
00ef5271 519}
520
521/*
522 * The Rate Limiting System, An Abridged Guide to Nonsense.
523 *
524 * OSCAR defines several 'rate classes'. Each class has seperate
525 * rate limiting properties (limit level, alert level, disconnect
526 * level, etc), and a set of SNAC family/type pairs associated with
527 * it. The rate classes, their limiting properties, and the definitions
528 * of which SNACs are belong to which class, are defined in the
529 * Rate Response packet at login to each host.
530 *
531 * Logically, all rate offenses within one class count against further
532 * offenses for other SNACs in the same class (ie, sending messages
533 * too fast will limit the number of user info requests you can send,
534 * since those two SNACs are in the same rate class).
535 *
536 * Since the rate classes are defined dynamically at login, the values
537 * below may change. But they seem to be fairly constant.
538 *
539 * Currently, BOS defines five rate classes, with the commonly used
540 * members as follows...
541 *
542 * Rate class 0x0001:
543 * - Everything thats not in any of the other classes
544 *
545 * Rate class 0x0002:
546 * - Buddy list add/remove
547 * - Permit list add/remove
548 * - Deny list add/remove
549 *
550 * Rate class 0x0003:
551 * - User information requests
552 * - Outgoing ICBMs
553 *
554 * Rate class 0x0004:
555 * - A few unknowns: 2/9, 2/b, and f/2
556 *
557 * Rate class 0x0005:
558 * - Chat room create
559 * - Outgoing chat ICBMs
560 *
561 * The only other thing of note is that class 5 (chat) has slightly looser
562 * limiting properties than class 3 (normal messages). But thats just a
563 * small bit of trivia for you.
564 *
565 * The last thing that needs to be learned about the rate limiting
566 * system is how the actual numbers relate to the passing of time. This
567 * seems to be a big mystery.
568 *
569 */
570
571/* XXX parse this */
d410cf58 572static int rateresp(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
00ef5271 573{
355229fe 574 aim_rxcallback_t userfunc;
00ef5271 575
355229fe 576 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
577 return userfunc(sess, rx);
00ef5271 578
355229fe 579 return 0;
00ef5271 580}
581
d410cf58 582static int ratechange(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
00ef5271 583{
355229fe 584 aim_rxcallback_t userfunc;
d410cf58 585 fu16_t code, rateclass;
586 fu32_t currentavg, maxavg, windowsize, clear, alert, limit, disconnect;
587
588 code = aimbs_get16(bs);
589 rateclass = aimbs_get16(bs);
590
591 windowsize = aimbs_get32(bs);
592 clear = aimbs_get32(bs);
593 alert = aimbs_get32(bs);
594 limit = aimbs_get32(bs);
595 disconnect = aimbs_get32(bs);
596 currentavg = aimbs_get32(bs);
597 maxavg = aimbs_get32(bs);
355229fe 598
599 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
600 return userfunc(sess, rx, code, rateclass, windowsize, clear, alert, limit, disconnect, currentavg, maxavg);
601
602 return 0;
00ef5271 603}
604
d410cf58 605static int selfinfo(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
00ef5271 606{
355229fe 607 aim_rxcallback_t userfunc;
c9f9223f 608 aim_userinfo_t userinfo;
609
610 aim_extractuserinfo(sess, bs, &userinfo);
00ef5271 611
355229fe 612 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
c9f9223f 613 return userfunc(sess, rx, &userinfo);
00ef5271 614
355229fe 615 return 0;
00ef5271 616}
617
d410cf58 618static int evilnotify(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
00ef5271 619{
d410cf58 620 aim_rxcallback_t userfunc;
621 fu16_t newevil;
7b0bc7f2 622 aim_userinfo_t userinfo;
355229fe 623
7b0bc7f2 624 memset(&userinfo, 0, sizeof(aim_userinfo_t));
d410cf58 625
626 newevil = aimbs_get16(bs);
00ef5271 627
d410cf58 628 if (aim_bstream_empty(bs))
629 aim_extractuserinfo(sess, bs, &userinfo);
00ef5271 630
355229fe 631 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
632 return userfunc(sess, rx, newevil, &userinfo);
00ef5271 633
355229fe 634 return 0;
00ef5271 635}
636
031c2fb3 637/*
638 * How Migrations work.
639 *
640 * The server sends a Server Pause message, which the client should respond to
641 * with a Server Pause Ack, which contains the families it needs on this
642 * connection. The server will send a Migration Notice with an IP address, and
643 * then disconnect. Next the client should open the connection and send the
644 * cookie. Repeat the normal login process and pretend this never happened.
645 *
646 * The Server Pause contains no data.
647 *
648 */
649static int serverpause(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
650{
651 aim_rxcallback_t userfunc;
652
653 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
654 return userfunc(sess, rx);
655
656 return 0;
657}
658
659/*
660 * It is rather important that aim_sendpauseack() gets called for the exact
661 * same connection that the Server Pause callback was called for, since
662 * libfaim extracts the data for the SNAC from the connection structure.
663 *
664 * Of course, if you don't do that, more bad things happen than just what
665 * libfaim can cause.
666 *
667 */
668faim_export int aim_sendpauseack(aim_session_t *sess, aim_conn_t *conn)
669{
670 aim_frame_t *fr;
671 aim_snacid_t snacid;
672 aim_conn_inside_t *ins = (aim_conn_inside_t *)conn->inside;
673 struct snacgroup *sg;
674
675 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1024)))
676 return -ENOMEM;
677
678 snacid = aim_cachesnac(sess, 0x0001, 0x000c, 0x0000, NULL, 0);
679 aim_putsnac(&fr->data, 0x0001, 0x000c, 0x0000, snacid);
680
681 /*
682 * This list should have all the groups that the original
683 * Host Online / Server Ready said this host supports. And
684 * we want them all back after the migration.
685 */
686 for (sg = ins->groups; sg; sg = sg->next)
687 aimbs_put16(&fr->data, sg->group);
688
689 aim_tx_enqueue(sess, fr);
690
691 return 0;
692}
693
694/*
695 * This is the final SNAC sent on the original connection during a migration.
696 * It contains the IP and cookie used to connect to the new server, and
697 * optionally a list of the SNAC groups being migrated.
698 *
699 */
700static int migrate(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
701{
702 aim_rxcallback_t userfunc;
703 int ret = 0;
704 fu16_t groupcount, i;
705 aim_tlvlist_t *tl;
706 char *ip = NULL;
707 aim_tlv_t *cktlv;
708
709 /*
710 * Apparently there's some fun stuff that can happen right here. The
711 * migration can actually be quite selective about what groups it
712 * moves to the new server. When not all the groups for a connection
713 * are migrated, or they are all migrated but some groups are moved
714 * to a different server than others, it is called a bifurcated
715 * migration.
716 *
717 * Let's play dumb and not support that.
718 *
719 */
720 groupcount = aimbs_get16(bs);
721 for (i = 0; i < groupcount; i++) {
722 fu16_t group;
723
724 group = aimbs_get16(bs);
725
726 faimdprintf(sess, 0, "bifurcated migration unsupported -- group 0x%04x\n", group);
727 }
728
729 tl = aim_readtlvchain(bs);
730
731 if (aim_gettlv(tl, 0x0005, 1))
732 ip = aim_gettlv_str(tl, 0x0005, 1);
733
734 cktlv = aim_gettlv(tl, 0x0006, 1);
735
736 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
737 ret = userfunc(sess, rx, ip, cktlv ? cktlv->value : NULL);
738
739 aim_freetlvchain(&tl);
740 free(ip);
741
742 return ret;
743}
744
d410cf58 745static int motd(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
00ef5271 746{
355229fe 747 aim_rxcallback_t userfunc;
748 char *msg = NULL;
749 int ret = 0;
d410cf58 750 aim_tlvlist_t *tlvlist;
751 fu16_t id;
355229fe 752
753 /*
754 * Code.
755 *
756 * Valid values:
757 * 1 Mandatory upgrade
758 * 2 Advisory upgrade
759 * 3 System bulletin
760 * 4 Nothing's wrong ("top o the world" -- normal)
25aaf30e 761 * 5 Lets-break-something.
355229fe 762 *
763 */
d410cf58 764 id = aimbs_get16(bs);
355229fe 765
766 /*
767 * TLVs follow
768 */
d410cf58 769 tlvlist = aim_readtlvchain(bs);
770
771 msg = aim_gettlv_str(tlvlist, 0x000b, 1);
355229fe 772
773 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
774 ret = userfunc(sess, rx, id, msg);
775
776 free(msg);
777
778 aim_freetlvchain(&tlvlist);
779
780 return ret;
00ef5271 781}
782
d410cf58 783static int hostversions(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
00ef5271 784{
355229fe 785 aim_rxcallback_t userfunc;
786 int vercount;
d410cf58 787 fu8_t *versions;
1b0f0322 788 int ret = 0;
00ef5271 789
d410cf58 790 vercount = aim_bstream_empty(bs)/4;
791 versions = aimbs_getraw(bs, aim_bstream_empty(bs));
00ef5271 792
355229fe 793 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
1b0f0322 794 ret = userfunc(sess, rx, vercount, versions);
d410cf58 795
796 free(versions);
355229fe 797
1b0f0322 798 return ret;
00ef5271 799}
b1eac25a 800
d32954e7 801/*
b1eac25a 802 * Starting this past week (26 Mar 2001, say), AOL has started sending
803 * this nice little extra SNAC. AFAIK, it has never been used until now.
804 *
805 * The request contains eight bytes. The first four are an offset, the
806 * second four are a length.
d32954e7 807 *
b1eac25a 808 * The offset is an offset into aim.exe when it is mapped during execution
809 * on Win32. So far, AOL has only been requesting bytes in static regions
810 * of memory. (I won't put it past them to start requesting data in
811 * less static regions -- regions that are initialized at run time, but still
812 * before the client recieves this request.)
813 *
814 * When the client recieves the request, it adds it to the current ds
815 * (0x00400000) and dereferences it, copying the data into a buffer which
816 * it then runs directly through the MD5 hasher. The 16 byte output of
817 * the hash is then sent back to the server.
818 *
819 * If the client does not send any data back, or the data does not match
820 * the data that the specific client should have, the client will get the
821 * following message from "AOL Instant Messenger":
822 * "You have been disconnected from the AOL Instant Message Service (SM)
823 * for accessing the AOL network using unauthorized software. You can
824 * download a FREE, fully featured, and authorized client, here
825 * http://www.aol.com/aim/download2.html"
826 * The connection is then closed, recieving disconnect code 1, URL
827 * http://www.aim.aol.com/errors/USER_LOGGED_OFF_NEW_LOGIN.html.
828 *
829 * Note, however, that numerous inconsistencies can cause the above error,
830 * not just sending back a bad hash. Do not immediatly suspect this code
831 * if you get disconnected. AOL and the open/free software community have
832 * played this game for a couple years now, generating the above message
833 * on numerous ocassions.
834 *
835 * Anyway, neener. We win again.
d32954e7 836 *
837 */
d410cf58 838static int memrequest(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
d32954e7 839{
355229fe 840 aim_rxcallback_t userfunc;
d410cf58 841 fu32_t offset, len;
842 aim_tlvlist_t *list;
843 char *modname;
b1eac25a 844
d410cf58 845 offset = aimbs_get32(bs);
846 len = aimbs_get32(bs);
847 list = aim_readtlvchain(bs);
328837f7 848
d410cf58 849 modname = aim_gettlv_str(list, 0x0001, 1);
5ac961d5 850
355229fe 851 faimdprintf(sess, 1, "data at 0x%08lx (%d bytes) of requested\n", offset, len, modname ? modname : "aim.exe");
b1eac25a 852
355229fe 853 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
854 return userfunc(sess, rx, offset, len, modname);
b1eac25a 855
355229fe 856 free(modname);
857 aim_freetlvchain(&list);
5ac961d5 858
355229fe 859 return 0;
b1eac25a 860}
861
d410cf58 862#if 0
863static void dumpbox(aim_session_t *sess, unsigned char *buf, int len)
001c9b80 864{
355229fe 865 int i;
866
867 if (!sess || !buf || !len)
868 return;
001c9b80 869
355229fe 870 faimdprintf(sess, 1, "\nDump of %d bytes at %p:", len, buf);
001c9b80 871
355229fe 872 for (i = 0; i < len; i++) {
873 if ((i % 8) == 0)
874 faimdprintf(sess, 1, "\n\t");
001c9b80 875
355229fe 876 faimdprintf(sess, 1, "0x%2x ", buf[i]);
877 }
001c9b80 878
355229fe 879 faimdprintf(sess, 1, "\n\n");
001c9b80 880
355229fe 881 return;
001c9b80 882}
d410cf58 883#endif
001c9b80 884
d410cf58 885faim_export int aim_sendmemblock(aim_session_t *sess, aim_conn_t *conn, fu32_t offset, fu32_t len, const fu8_t *buf, fu8_t flag)
b1eac25a 886{
d410cf58 887 aim_frame_t *fr;
888 aim_snacid_t snacid;
b1eac25a 889
355229fe 890 if (!sess || !conn)
891 return -EINVAL;
b1eac25a 892
d410cf58 893 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+16)))
355229fe 894 return -ENOMEM;
b1eac25a 895
d410cf58 896 snacid = aim_cachesnac(sess, 0x0001, 0x0020, 0x0000, NULL, 0);
b1eac25a 897
d410cf58 898 aim_putsnac(&fr->data, 0x0001, 0x0020, 0x0000, snacid);
899 aimbs_put16(&fr->data, 0x0010); /* md5 is always 16 bytes */
b1eac25a 900
355229fe 901 if ((flag == AIM_SENDMEMBLOCK_FLAG_ISHASH) && buf && (len == 0x10)) { /* we're getting a hash */
d2698e03 902
d410cf58 903 aimbs_putraw(&fr->data, buf, 0x10);
d2698e03 904
355229fe 905 } else if (buf && (len > 0)) { /* use input buffer */
906 md5_state_t state;
d410cf58 907 md5_byte_t digest[0x10];
b1eac25a 908
355229fe 909 md5_init(&state);
910 md5_append(&state, (const md5_byte_t *)buf, len);
d410cf58 911 md5_finish(&state, digest);
912
913 aimbs_putraw(&fr->data, (fu8_t *)digest, 0x10);
b1eac25a 914
355229fe 915 } else if (len == 0) { /* no length, just hash NULL (buf is optional) */
916 md5_state_t state;
d410cf58 917 fu8_t nil = '\0';
918 md5_byte_t digest[0x10];
001c9b80 919
355229fe 920 /*
921 * These MD5 routines are stupid in that you have to have
922 * at least one append. So thats why this doesn't look
923 * real logical.
924 */
925 md5_init(&state);
926 md5_append(&state, (const md5_byte_t *)&nil, 0);
d410cf58 927 md5_finish(&state, digest);
928
929 aimbs_putraw(&fr->data, (fu8_t *)digest, 0x10);
001c9b80 930
355229fe 931 } else {
b1eac25a 932
355229fe 933 /*
934 * This data is correct for AIM 3.5.1670.
935 *
936 * Using these blocks is as close to "legal" as you can get
937 * without using an AIM binary.
938 *
939 */
940 if ((offset == 0x03ffffff) && (len == 0x03ffffff)) {
fa358732 941
942#if 1 /* with "AnrbnrAqhfzcd" */
d410cf58 943 aimbs_put32(&fr->data, 0x44a95d26);
944 aimbs_put32(&fr->data, 0xd2490423);
945 aimbs_put32(&fr->data, 0x93b8821f);
946 aimbs_put32(&fr->data, 0x51c54b01);
fa358732 947#else /* no filename */
d410cf58 948 aimbs_put32(&fr->data, 0x1df8cbae);
949 aimbs_put32(&fr->data, 0x5523b839);
950 aimbs_put32(&fr->data, 0xa0e10db3);
951 aimbs_put32(&fr->data, 0xa46d3b39);
fa358732 952#endif
953
355229fe 954 } else if ((offset == 0x00001000) && (len == 0x00000000)) {
fa358732 955
d410cf58 956 aimbs_put32(&fr->data, 0xd41d8cd9);
957 aimbs_put32(&fr->data, 0x8f00b204);
958 aimbs_put32(&fr->data, 0xe9800998);
959 aimbs_put32(&fr->data, 0xecf8427e);
fa358732 960
355229fe 961 } else
962 faimdprintf(sess, 0, "sendmemblock: WARNING: unknown hash request\n");
b1eac25a 963
355229fe 964 }
b1eac25a 965
d410cf58 966 aim_tx_enqueue(sess, fr);
b1eac25a 967
355229fe 968 return 0;
d32954e7 969}
00ef5271 970
d410cf58 971static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
00ef5271 972{
973
355229fe 974 if (snac->subtype == 0x0003)
d410cf58 975 return hostonline(sess, mod, rx, snac, bs);
355229fe 976 else if (snac->subtype == 0x0005)
d410cf58 977 return redirect(sess, mod, rx, snac, bs);
355229fe 978 else if (snac->subtype == 0x0007)
d410cf58 979 return rateresp(sess, mod, rx, snac, bs);
355229fe 980 else if (snac->subtype == 0x000a)
d410cf58 981 return ratechange(sess, mod, rx, snac, bs);
031c2fb3 982 else if (snac->subtype == 0x000b)
983 return serverpause(sess, mod, rx, snac, bs);
355229fe 984 else if (snac->subtype == 0x000f)
d410cf58 985 return selfinfo(sess, mod, rx, snac, bs);
355229fe 986 else if (snac->subtype == 0x0010)
d410cf58 987 return evilnotify(sess, mod, rx, snac, bs);
031c2fb3 988 else if (snac->subtype == 0x0012)
989 return migrate(sess, mod, rx, snac, bs);
355229fe 990 else if (snac->subtype == 0x0013)
d410cf58 991 return motd(sess, mod, rx, snac, bs);
355229fe 992 else if (snac->subtype == 0x0018)
d410cf58 993 return hostversions(sess, mod, rx, snac, bs);
355229fe 994 else if (snac->subtype == 0x001f)
d410cf58 995 return memrequest(sess, mod, rx, snac, bs);
355229fe 996
997 return 0;
00ef5271 998}
999
d410cf58 1000faim_internal int general_modfirst(aim_session_t *sess, aim_module_t *mod)
00ef5271 1001{
1002
355229fe 1003 mod->family = 0x0001;
1004 mod->version = 0x0000;
1005 mod->flags = 0;
1006 strncpy(mod->name, "general", sizeof(mod->name));
1007 mod->snachandler = snachandler;
00ef5271 1008
355229fe 1009 return 0;
00ef5271 1010}
355229fe 1011
This page took 2.548015 seconds and 5 git commands to generate.