]>
Commit | Line | Data |
---|---|---|
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 |
a25832e6 | 9 | #include <faim/aim.h> |
9de3ca7e | 10 | |
b5bc2a8c | 11 | #include "md5.h" |
12 | ||
13 | static int aim_encode_password_md5(const char *password, const char *key, md5_byte_t *digest); | |
5daacaa3 | 14 | static int aim_encode_password(const char *password, unsigned char *encoded); |
9de3ca7e | 15 | |
16 | /* | |
17 | * FIXME: Reimplement the TIS stuff. | |
18 | */ | |
19 | #ifdef TIS_TELNET_PROXY | |
20 | #include "tis_telnet_proxy.h" | |
21 | #endif | |
22 | ||
78b3fb13 | 23 | faim_export int aim_sendconnack(struct aim_session_t *sess, |
24 | struct aim_conn_t *conn) | |
01b59e1e | 25 | { |
26 | int curbyte=0; | |
27 | ||
5b79dc93 | 28 | struct command_tx_struct *newpacket; |
01b59e1e | 29 | |
b69540e3 | 30 | if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0001, conn, 4))) |
01b59e1e | 31 | return -1; |
32 | ||
5b79dc93 | 33 | newpacket->lock = 1; |
01b59e1e | 34 | |
5b79dc93 | 35 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000); |
36 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0001); | |
01b59e1e | 37 | |
5b79dc93 | 38 | newpacket->lock = 0; |
39 | return aim_tx_enqueue(sess, newpacket); | |
01b59e1e | 40 | } |
41 | ||
01b59e1e | 42 | /* |
43 | * In AIM 3.5 protocol, the first stage of login is to request | |
44 | * login from the Authorizer, passing it the screen name | |
45 | * for verification. If the name is invalid, a 0017/0003 | |
46 | * is spit back, with the standard error contents. If valid, | |
47 | * a 0017/0007 comes back, which is the signal to send | |
48 | * it the main login command (0017/0002). | |
49 | */ | |
78b3fb13 | 50 | faim_export int aim_request_login(struct aim_session_t *sess, |
51 | struct aim_conn_t *conn, | |
52 | char *sn) | |
01b59e1e | 53 | { |
5daacaa3 | 54 | int curbyte; |
5b79dc93 | 55 | struct command_tx_struct *newpacket; |
01b59e1e | 56 | |
5daacaa3 | 57 | if (!sess || !conn || !sn) |
58 | return -1; | |
59 | ||
60 | /* | |
61 | * For ICQ, we enable the ancient horrible login and stuff | |
62 | * a key packet into the queue to make it look like we got | |
63 | * a reply back. This is so the client doesn't know we're | |
64 | * really not doing MD5 login. | |
65 | * | |
66 | * This may sound stupid, but I'm not in the best of moods and | |
67 | * I don't plan to keep support for this crap around much longer. | |
68 | * Its all AOL's fault anyway, really. I hate AOL. Really. They | |
69 | * always seem to be able to piss me off by doing the dumbest little | |
70 | * things. Like disabling MD5 logins for ICQ UINs, or adding purposefully | |
71 | * wrong TLV lengths, or adding superfluous information to host strings, | |
72 | * or... I'll stop. | |
73 | * | |
74 | */ | |
75 | if ((sn[0] >= '0') && (sn[0] <= '9')) { | |
76 | struct command_rx_struct *newrx; | |
77 | int i; | |
78 | ||
79 | if (!(newrx = (struct command_rx_struct *)malloc(sizeof(struct command_rx_struct)))) | |
80 | return -1; | |
81 | memset(newrx, 0x00, sizeof(struct command_rx_struct)); | |
82 | newrx->lock = 1; | |
83 | newrx->hdrtype = AIM_FRAMETYPE_OSCAR; | |
84 | newrx->hdr.oscar.type = 0x02; | |
85 | newrx->hdr.oscar.seqnum = 0; | |
86 | newrx->commandlen = 10+2+1; | |
87 | newrx->nofree = 0; | |
88 | if (!(newrx->data = malloc(newrx->commandlen))) { | |
89 | free(newrx); | |
90 | return -1; | |
91 | } | |
92 | ||
93 | i = aim_putsnac(newrx->data, 0x0017, 0x0007, 0x0000, 0x0000); | |
94 | i += aimutil_put16(newrx->data+i, 0x01); | |
95 | i += aimutil_putstr(newrx->data+i, "0", 1); | |
96 | ||
97 | newrx->conn = conn; | |
98 | ||
99 | newrx->next = sess->queue_incoming; | |
100 | sess->queue_incoming = newrx; | |
101 | ||
102 | newrx->lock = 0; | |
103 | ||
22517493 | 104 | sess->flags &= ~AIM_SESS_FLAGS_SNACLOGIN; |
105 | ||
5daacaa3 | 106 | return 0; |
107 | } | |
108 | ||
22517493 | 109 | sess->flags |= AIM_SESS_FLAGS_SNACLOGIN; |
5daacaa3 | 110 | |
111 | aim_sendconnack(sess, conn); | |
112 | ||
b69540e3 | 113 | if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+2+2+strlen(sn)))) |
5b79dc93 | 114 | return -1; |
01b59e1e | 115 | |
5b79dc93 | 116 | newpacket->lock = 1; |
01b59e1e | 117 | |
5daacaa3 | 118 | curbyte = aim_putsnac(newpacket->data, 0x0017, 0x0006, 0x0000, 0x00010000); |
5b79dc93 | 119 | curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x0001, strlen(sn), sn); |
01b59e1e | 120 | |
5daacaa3 | 121 | newpacket->commandlen = curbyte; |
5b79dc93 | 122 | newpacket->lock = 0; |
5daacaa3 | 123 | |
5b79dc93 | 124 | return aim_tx_enqueue(sess, newpacket); |
01b59e1e | 125 | } |
01b59e1e | 126 | |
9de3ca7e | 127 | /* |
24286d93 | 128 | * send_login(int socket, char *sn, char *password) |
9de3ca7e | 129 | * |
130 | * This is the initial login request packet. | |
131 | * | |
132 | * The password is encoded before transmition, as per | |
133 | * encode_password(). See that function for their | |
134 | * stupid method of doing it. | |
135 | * | |
355982c5 | 136 | * Latest WinAIM: |
137 | * clientstring = "AOL Instant Messenger (SM), version 4.3.2188/WIN32" | |
138 | * major2 = 0x0109 | |
139 | * major = 0x0400 | |
140 | * minor = 0x0003 | |
141 | * minor2 = 0x0000 | |
142 | * build = 0x088c | |
143 | * unknown = 0x00000086 | |
144 | * lang = "en" | |
145 | * country = "us" | |
146 | * unknown4a = 0x01 | |
9de3ca7e | 147 | */ |
78b3fb13 | 148 | faim_export int aim_send_login (struct aim_session_t *sess, |
149 | struct aim_conn_t *conn, | |
150 | char *sn, char *password, | |
151 | struct client_info_s *clientinfo, | |
152 | char *key) | |
9de3ca7e | 153 | { |
9de3ca7e | 154 | int curbyte=0; |
5b79dc93 | 155 | struct command_tx_struct *newpacket; |
9de3ca7e | 156 | |
01b59e1e | 157 | if (!clientinfo || !sn || !password) |
158 | return -1; | |
159 | ||
b69540e3 | 160 | if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 1152))) |
5b79dc93 | 161 | return -1; |
9de3ca7e | 162 | |
5b79dc93 | 163 | newpacket->lock = 1; |
01b59e1e | 164 | |
22517493 | 165 | newpacket->hdr.oscar.type = (sess->flags & AIM_SESS_FLAGS_SNACLOGIN)?0x02:0x01; |
b5bc2a8c | 166 | |
22517493 | 167 | if (sess->flags & AIM_SESS_FLAGS_SNACLOGIN) |
5daacaa3 | 168 | curbyte = aim_putsnac(newpacket->data, 0x0017, 0x0002, 0x0000, 0x00010000); |
169 | else { | |
170 | curbyte = aimutil_put16(newpacket->data, 0x0000); | |
171 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0001); | |
172 | } | |
b5bc2a8c | 173 | |
5daacaa3 | 174 | curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x0001, strlen(sn), sn); |
9de3ca7e | 175 | |
22517493 | 176 | if (sess->flags & AIM_SESS_FLAGS_SNACLOGIN) { |
5daacaa3 | 177 | md5_byte_t digest[16]; |
178 | ||
179 | aim_encode_password_md5(password, key, digest); | |
180 | curbyte+= aim_puttlv_str(newpacket->data+curbyte, 0x0025, 16, (char *)digest); | |
181 | } else { | |
182 | char *password_encoded; | |
183 | ||
184 | password_encoded = (char *) malloc(strlen(password)); | |
185 | aim_encode_password(password, password_encoded); | |
186 | curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x0002, strlen(password), password_encoded); | |
187 | free(password_encoded); | |
188 | } | |
189 | ||
13ebc4c4 | 190 | /* XXX is clientstring required by oscar? */ |
191 | if (strlen(clientinfo->clientstring)) | |
192 | curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x0003, strlen(clientinfo->clientstring), clientinfo->clientstring); | |
193 | ||
22517493 | 194 | if (sess->flags & AIM_SESS_FLAGS_SNACLOGIN) { |
5daacaa3 | 195 | curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0016, (unsigned short)clientinfo->major2); |
196 | curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0017, (unsigned short)clientinfo->major); | |
197 | curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0018, (unsigned short)clientinfo->minor); | |
198 | curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0019, (unsigned short)clientinfo->minor2); | |
199 | curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x001a, (unsigned short)clientinfo->build); | |
b5bc2a8c | 200 | |
5daacaa3 | 201 | curbyte += aim_puttlv_32(newpacket->data+curbyte, 0x0014, clientinfo->unknown); |
202 | curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0009, 0x0015); | |
ee49b735 | 203 | curbyte += aim_puttlv_8(newpacket->data+curbyte, 0x004a, 0x00); |
5daacaa3 | 204 | } else { |
355982c5 | 205 | /* Use very specific version numbers, to further indicate the hack. */ |
5daacaa3 | 206 | curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0016, 0x010a); |
207 | curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0017, 0x0004); | |
208 | curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0018, 0x003c); | |
209 | curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0019, 0x0001); | |
210 | curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x001a, 0x0cce); | |
211 | curbyte += aim_puttlv_32(newpacket->data+curbyte, 0x0014, 0x00000055); | |
212 | } | |
9de3ca7e | 213 | |
13ebc4c4 | 214 | if (strlen(clientinfo->country)) |
215 | curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x000e, strlen(clientinfo->country), clientinfo->country); | |
216 | else | |
217 | curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x000e, 2, "us"); | |
218 | ||
219 | if (strlen(clientinfo->lang)) | |
220 | curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x000f, strlen(clientinfo->lang), clientinfo->lang); | |
221 | else | |
222 | curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x000f, 2, "en"); | |
223 | ||
224 | newpacket->commandlen = curbyte; | |
9de3ca7e | 225 | |
5b79dc93 | 226 | newpacket->lock = 0; |
227 | return aim_tx_enqueue(sess, newpacket); | |
9de3ca7e | 228 | } |
9de3ca7e | 229 | |
b5bc2a8c | 230 | static int aim_encode_password_md5(const char *password, const char *key, md5_byte_t *digest) |
231 | { | |
232 | md5_state_t state; | |
233 | ||
234 | md5_init(&state); | |
235 | md5_append(&state, (const md5_byte_t *)key, strlen(key)); | |
236 | md5_append(&state, (const md5_byte_t *)password, strlen(password)); | |
237 | md5_append(&state, (const md5_byte_t *)AIM_MD5_STRING, strlen(AIM_MD5_STRING)); | |
238 | md5_finish(&state, (md5_byte_t *)digest); | |
239 | ||
240 | return 0; | |
241 | } | |
242 | ||
5daacaa3 | 243 | /** |
244 | * aim_encode_password - Encode a password using old XOR method | |
245 | * @password: incoming password | |
246 | * @encoded: buffer to put encoded password | |
9de3ca7e | 247 | * |
248 | * This takes a const pointer to a (null terminated) string | |
249 | * containing the unencoded password. It also gets passed | |
250 | * an already allocated buffer to store the encoded password. | |
251 | * This buffer should be the exact length of the password without | |
5daacaa3 | 252 | * the null. The encoded password buffer /is not %NULL terminated/. |
9de3ca7e | 253 | * |
254 | * The encoding_table seems to be a fixed set of values. We'll | |
255 | * hope it doesn't change over time! | |
256 | * | |
5daacaa3 | 257 | * This is only used for the XOR method, not the better MD5 method. |
b5bc2a8c | 258 | * |
9de3ca7e | 259 | */ |
b5bc2a8c | 260 | static int aim_encode_password(const char *password, unsigned char *encoded) |
9de3ca7e | 261 | { |
262 | u_char encoding_table[] = { | |
b69540e3 | 263 | #if 0 /* old v1 table */ |
9de3ca7e | 264 | 0xf3, 0xb3, 0x6c, 0x99, |
265 | 0x95, 0x3f, 0xac, 0xb6, | |
266 | 0xc5, 0xfa, 0x6b, 0x63, | |
267 | 0x69, 0x6c, 0xc3, 0x9f | |
b69540e3 | 268 | #else /* v2.1 table, also works for ICQ */ |
5e02cf44 | 269 | 0xf3, 0x26, 0x81, 0xc4, |
b69540e3 | 270 | 0x39, 0x86, 0xdb, 0x92, |
271 | 0x71, 0xa3, 0xb9, 0xe6, | |
272 | 0x53, 0x7a, 0x95, 0x7c | |
273 | #endif | |
5e02cf44 | 274 | }; |
275 | ||
276 | int i; | |
b69540e3 | 277 | |
5e02cf44 | 278 | for (i = 0; i < strlen(password); i++) |
279 | encoded[i] = (password[i] ^ encoding_table[i]); | |
280 | ||
281 | return 0; | |
282 | } | |
283 | ||
01b59e1e | 284 | /* |
285 | * This is sent back as a general response to the login command. | |
286 | * It can be either an error or a success, depending on the | |
287 | * precense of certain TLVs. | |
288 | * | |
355982c5 | 289 | * The client should check the value passed as errorcode. If |
01b59e1e | 290 | * its nonzero, there was an error. |
291 | * | |
292 | */ | |
78b3fb13 | 293 | faim_internal int aim_authparse(struct aim_session_t *sess, |
294 | struct command_rx_struct *command) | |
01b59e1e | 295 | { |
296 | struct aim_tlvlist_t *tlvlist; | |
297 | int ret = 1; | |
01b59e1e | 298 | rxcallback_t userfunc = NULL; |
355982c5 | 299 | char *sn = NULL, *bosip = NULL, *errurl = NULL, *email = NULL; |
300 | unsigned char *cookie = NULL; | |
301 | int errorcode = 0, regstatus = 0; | |
89bce177 | 302 | int latestbuild = 0, latestbetabuild = 0; |
303 | char *latestrelease = NULL, *latestbeta = NULL; | |
304 | char *latestreleaseurl = NULL, *latestbetaurl = NULL; | |
305 | char *latestreleaseinfo = NULL, *latestbetainfo = NULL; | |
01b59e1e | 306 | |
307 | /* | |
308 | * Read block of TLVs. All further data is derived | |
309 | * from what is parsed here. | |
b5bc2a8c | 310 | * |
311 | * For SNAC login, there's a 17/3 SNAC header in front. | |
312 | * | |
01b59e1e | 313 | */ |
22517493 | 314 | if (sess->flags & AIM_SESS_FLAGS_SNACLOGIN) |
5daacaa3 | 315 | tlvlist = aim_readtlvchain(command->data+10, command->commandlen-10); |
316 | else | |
317 | tlvlist = aim_readtlvchain(command->data, command->commandlen); | |
b5bc2a8c | 318 | |
01b59e1e | 319 | /* |
320 | * No matter what, we should have a screen name. | |
321 | */ | |
355982c5 | 322 | memset(sess->sn, 0, sizeof(sess->sn)); |
323 | if (aim_gettlv(tlvlist, 0x0001, 1)) { | |
324 | sn = aim_gettlv_str(tlvlist, 0x0001, 1); | |
325 | strncpy(sess->sn, sn, sizeof(sess->sn)); | |
326 | } | |
b13c9e13 | 327 | |
01b59e1e | 328 | /* |
329 | * Check for an error code. If so, we should also | |
330 | * have an error url. | |
331 | */ | |
355982c5 | 332 | if (aim_gettlv(tlvlist, 0x0008, 1)) |
333 | errorcode = aim_gettlv16(tlvlist, 0x0008, 1); | |
334 | if (aim_gettlv(tlvlist, 0x0004, 1)) | |
335 | errurl = aim_gettlv_str(tlvlist, 0x0004, 1); | |
336 | ||
337 | /* | |
338 | * BOS server address. | |
01b59e1e | 339 | */ |
355982c5 | 340 | if (aim_gettlv(tlvlist, 0x0005, 1)) |
341 | bosip = aim_gettlv_str(tlvlist, 0x0005, 1); | |
342 | ||
343 | /* | |
344 | * Authorization cookie. | |
345 | */ | |
346 | if (aim_gettlv(tlvlist, 0x0006, 1)) { | |
5e02cf44 | 347 | struct aim_tlv_t *tmptlv; |
348 | ||
5e02cf44 | 349 | tmptlv = aim_gettlv(tlvlist, 0x0006, 1); |
355982c5 | 350 | |
351 | if ((cookie = malloc(tmptlv->length))) | |
352 | memcpy(cookie, tmptlv->value, tmptlv->length); | |
5e02cf44 | 353 | } |
01b59e1e | 354 | |
355982c5 | 355 | /* |
356 | * The email address attached to this account | |
357 | * Not available for ICQ logins. | |
358 | */ | |
359 | if (aim_gettlv(tlvlist, 0x0011, 1)) | |
360 | email = aim_gettlv_str(tlvlist, 0x0011, 1); | |
361 | ||
362 | /* | |
363 | * The registration status. (Not real sure what it means.) | |
364 | * Not available for ICQ logins. | |
d6c9fcf0 | 365 | * |
366 | * 1 = No disclosure | |
367 | * 2 = Limited disclosure | |
368 | * 3 = Full disclosure | |
369 | * | |
370 | * This has to do with whether your email address is available | |
371 | * to other users or not. AFAIK, this feature is no longer used. | |
372 | * | |
355982c5 | 373 | */ |
374 | if (aim_gettlv(tlvlist, 0x0013, 1)) | |
375 | regstatus = aim_gettlv16(tlvlist, 0x0013, 1); | |
b5bc2a8c | 376 | |
89bce177 | 377 | if (aim_gettlv(tlvlist, 0x0040, 1)) |
378 | latestbetabuild = aim_gettlv32(tlvlist, 0x0040, 1); | |
379 | if (aim_gettlv(tlvlist, 0x0041, 1)) | |
380 | latestbetaurl = aim_gettlv_str(tlvlist, 0x0041, 1); | |
381 | if (aim_gettlv(tlvlist, 0x0042, 1)) | |
382 | latestbetainfo = aim_gettlv_str(tlvlist, 0x0042, 1); | |
383 | if (aim_gettlv(tlvlist, 0x0043, 1)) | |
384 | latestbeta = aim_gettlv_str(tlvlist, 0x0043, 1); | |
385 | if (aim_gettlv(tlvlist, 0x0048, 1)) | |
386 | ; /* no idea what this is */ | |
387 | ||
388 | if (aim_gettlv(tlvlist, 0x0044, 1)) | |
389 | latestbuild = aim_gettlv32(tlvlist, 0x0044, 1); | |
390 | if (aim_gettlv(tlvlist, 0x0045, 1)) | |
391 | latestreleaseurl = aim_gettlv_str(tlvlist, 0x0045, 1); | |
392 | if (aim_gettlv(tlvlist, 0x0046, 1)) | |
393 | latestreleaseinfo = aim_gettlv_str(tlvlist, 0x0046, 1); | |
394 | if (aim_gettlv(tlvlist, 0x0047, 1)) | |
395 | latestrelease = aim_gettlv_str(tlvlist, 0x0047, 1); | |
396 | if (aim_gettlv(tlvlist, 0x0049, 1)) | |
397 | ; /* no idea what this is */ | |
398 | ||
01b59e1e | 399 | |
355982c5 | 400 | if ((userfunc = aim_callhandler(command->conn, 0x0017, 0x0003))) |
89bce177 | 401 | ret = userfunc(sess, command, sn, errorcode, errurl, regstatus, email, bosip, cookie, latestrelease, latestbuild, latestreleaseurl, latestreleaseinfo, latestbeta, latestbetabuild, latestbetaurl, latestbetainfo); |
01b59e1e | 402 | |
355982c5 | 403 | |
404 | if (sn) | |
405 | free(sn); | |
406 | if (bosip) | |
407 | free(bosip); | |
408 | if (errurl) | |
409 | free(errurl); | |
410 | if (email) | |
411 | free(email); | |
412 | if (cookie) | |
413 | free(cookie); | |
89bce177 | 414 | if (latestrelease) |
415 | free(latestrelease); | |
416 | if (latestreleaseurl) | |
417 | free(latestreleaseurl); | |
418 | if (latestbeta) | |
419 | free(latestbeta); | |
420 | if (latestbetaurl) | |
421 | free(latestbetaurl); | |
422 | if (latestreleaseinfo) | |
423 | free(latestreleaseinfo); | |
424 | if (latestbetainfo) | |
425 | free(latestbetainfo); | |
426 | ||
355982c5 | 427 | aim_freetlvchain(&tlvlist); |
01b59e1e | 428 | |
429 | return ret; | |
430 | } | |
e6b05d80 | 431 | |
b5bc2a8c | 432 | /* |
433 | * Middle handler for 0017/0007 SNACs. Contains the auth key prefixed | |
434 | * by only its length in a two byte word. | |
435 | * | |
436 | * Calls the client, which should then use the value to call aim_send_login. | |
437 | * | |
438 | */ | |
78b3fb13 | 439 | faim_internal int aim_authkeyparse(struct aim_session_t *sess, struct command_rx_struct *command) |
b5bc2a8c | 440 | { |
441 | unsigned char *key; | |
442 | int keylen; | |
443 | int ret = 1; | |
444 | rxcallback_t userfunc; | |
445 | ||
446 | keylen = aimutil_get16(command->data+10); | |
98c88242 | 447 | if (!(key = malloc(keylen+1))) |
448 | return ret; | |
b5bc2a8c | 449 | memcpy(key, command->data+12, keylen); |
450 | key[keylen] = '\0'; | |
451 | ||
452 | if ((userfunc = aim_callhandler(command->conn, 0x0017, 0x0007))) | |
78b3fb13 | 453 | ret = userfunc(sess, command, (char *)key); |
b5bc2a8c | 454 | |
455 | free(key); | |
456 | ||
457 | return ret; | |
458 | } | |
459 | ||
e6b05d80 | 460 | /* |
461 | * Generate an authorization response. | |
462 | * | |
463 | * You probably don't want this unless you're writing an AIM server. | |
464 | * | |
465 | */ | |
78b3fb13 | 466 | faim_export unsigned long aim_sendauthresp(struct aim_session_t *sess, |
467 | struct aim_conn_t *conn, | |
355982c5 | 468 | char *sn, int errorcode, |
469 | char *errorurl, char *bosip, | |
78b3fb13 | 470 | char *cookie, char *email, |
471 | int regstatus) | |
e6b05d80 | 472 | { |
5b79dc93 | 473 | struct command_tx_struct *tx; |
e6b05d80 | 474 | struct aim_tlvlist_t *tlvlist = NULL; |
475 | ||
b69540e3 | 476 | if (!(tx = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0004, conn, 1152))) |
5b79dc93 | 477 | return -1; |
e6b05d80 | 478 | |
5b79dc93 | 479 | tx->lock = 1; |
e6b05d80 | 480 | |
481 | if (sn) | |
482 | aim_addtlvtochain_str(&tlvlist, 0x0001, sn, strlen(sn)); | |
483 | else | |
355982c5 | 484 | aim_addtlvtochain_str(&tlvlist, 0x0001, sess->sn, strlen(sess->sn)); |
e6b05d80 | 485 | |
355982c5 | 486 | if (errorcode) { |
487 | aim_addtlvtochain16(&tlvlist, 0x0008, errorcode); | |
488 | aim_addtlvtochain_str(&tlvlist, 0x0004, errorurl, strlen(errorurl)); | |
e6b05d80 | 489 | } else { |
490 | aim_addtlvtochain_str(&tlvlist, 0x0005, bosip, strlen(bosip)); | |
491 | aim_addtlvtochain_str(&tlvlist, 0x0006, cookie, AIM_COOKIELEN); | |
492 | aim_addtlvtochain_str(&tlvlist, 0x0011, email, strlen(email)); | |
5ac21963 | 493 | aim_addtlvtochain16(&tlvlist, 0x0013, (unsigned short)regstatus); |
e6b05d80 | 494 | } |
495 | ||
5b79dc93 | 496 | tx->commandlen = aim_writetlvchain(tx->data, tx->commandlen, &tlvlist); |
497 | tx->lock = 0; | |
355982c5 | 498 | |
5b79dc93 | 499 | return aim_tx_enqueue(sess, tx); |
e6b05d80 | 500 | } |
501 | ||
502 | /* | |
503 | * Generate a random cookie. (Non-client use only) | |
504 | */ | |
78b3fb13 | 505 | faim_export int aim_gencookie(unsigned char *buf) |
e6b05d80 | 506 | { |
507 | int i; | |
508 | ||
509 | srand(time(NULL)); | |
510 | ||
511 | for (i=0; i < AIM_COOKIELEN; i++) | |
512 | buf[i] = 1+(int) (256.0*rand()/(RAND_MAX+0.0)); | |
513 | ||
514 | return i; | |
515 | } | |
516 | ||
517 | /* | |
518 | * Send Server Ready. (Non-client) | |
519 | */ | |
78b3fb13 | 520 | faim_export int aim_sendserverready(struct aim_session_t *sess, struct aim_conn_t *conn) |
e6b05d80 | 521 | { |
5b79dc93 | 522 | struct command_tx_struct *tx; |
e6b05d80 | 523 | int i = 0; |
524 | ||
b69540e3 | 525 | if (!(tx = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+0x22))) |
5b79dc93 | 526 | return -1; |
e6b05d80 | 527 | |
5b79dc93 | 528 | tx->lock = 1; |
e6b05d80 | 529 | |
67c0bb2f | 530 | i += aim_putsnac(tx->data, 0x0001, 0x0003, 0x0000, sess->snac_nextid++); |
5b79dc93 | 531 | |
532 | i += aimutil_put16(tx->data+i, 0x0001); | |
533 | i += aimutil_put16(tx->data+i, 0x0002); | |
534 | i += aimutil_put16(tx->data+i, 0x0003); | |
535 | i += aimutil_put16(tx->data+i, 0x0004); | |
536 | i += aimutil_put16(tx->data+i, 0x0006); | |
537 | i += aimutil_put16(tx->data+i, 0x0008); | |
538 | i += aimutil_put16(tx->data+i, 0x0009); | |
539 | i += aimutil_put16(tx->data+i, 0x000a); | |
540 | i += aimutil_put16(tx->data+i, 0x000b); | |
541 | i += aimutil_put16(tx->data+i, 0x000c); | |
67c0bb2f | 542 | i += aimutil_put16(tx->data+i, 0x0013); |
543 | i += aimutil_put16(tx->data+i, 0x0015); | |
5b79dc93 | 544 | |
67c0bb2f | 545 | tx->commandlen = i; |
5b79dc93 | 546 | tx->lock = 0; |
5b79dc93 | 547 | return aim_tx_enqueue(sess, tx); |
e6b05d80 | 548 | } |
549 | ||
550 | ||
551 | /* | |
552 | * Send service redirect. (Non-Client) | |
553 | */ | |
78b3fb13 | 554 | faim_export unsigned long aim_sendredirect(struct aim_session_t *sess, |
555 | struct aim_conn_t *conn, | |
556 | unsigned short servid, | |
557 | char *ip, | |
558 | char *cookie) | |
e6b05d80 | 559 | { |
5b79dc93 | 560 | struct command_tx_struct *tx; |
e6b05d80 | 561 | struct aim_tlvlist_t *tlvlist = NULL; |
562 | int i = 0; | |
563 | ||
b69540e3 | 564 | if (!(tx = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 1152))) |
5b79dc93 | 565 | return -1; |
566 | ||
567 | tx->lock = 1; | |
e6b05d80 | 568 | |
13ebc4c4 | 569 | i += aim_putsnac(tx->data+i, 0x0001, 0x0005, 0x0000, 0x00000000); |
e6b05d80 | 570 | |
571 | aim_addtlvtochain16(&tlvlist, 0x000d, servid); | |
572 | aim_addtlvtochain_str(&tlvlist, 0x0005, ip, strlen(ip)); | |
573 | aim_addtlvtochain_str(&tlvlist, 0x0006, cookie, AIM_COOKIELEN); | |
574 | ||
5b79dc93 | 575 | tx->commandlen = aim_writetlvchain(tx->data+i, tx->commandlen-i, &tlvlist)+i; |
e6b05d80 | 576 | aim_freetlvchain(&tlvlist); |
577 | ||
5b79dc93 | 578 | tx->lock = 0; |
579 | return aim_tx_enqueue(sess, tx); | |
e6b05d80 | 580 | } |