4 * This contains all the functions needed to actually login.
12 * FIXME: Reimplement the TIS stuff.
14 #ifdef TIS_TELNET_PROXY
15 #include "tis_telnet_proxy.h"
18 int aim_sendconnack(struct aim_session_t *sess,
19 struct aim_conn_t *conn)
23 struct command_tx_struct newpacket;
26 newpacket.conn = conn;
30 newpacket.commandlen = 2+2;
31 newpacket.data = (u_char *) calloc (1, newpacket.commandlen );
33 newpacket.type = 0x01;
35 curbyte += aimutil_put16(newpacket.data+curbyte, 0x0000);
36 curbyte += aimutil_put16(newpacket.data+curbyte, 0x0001);
39 aim_tx_enqueue(sess, &newpacket);
46 * In AIM 3.5 protocol, the first stage of login is to request
47 * login from the Authorizer, passing it the screen name
48 * for verification. If the name is invalid, a 0017/0003
49 * is spit back, with the standard error contents. If valid,
50 * a 0017/0007 comes back, which is the signal to send
51 * it the main login command (0017/0002).
53 int aim_request_login(struct aim_session_t *sess,
54 struct aim_conn_t *conn,
59 struct command_tx_struct newpacket;
62 newpacket.conn = conn;
64 newpacket.conn = aim_getconn_type(sess, AIM_CONN_TYPE_AUTH);
66 newpacket.commandlen = 10+2+2+strlen(sn);
67 newpacket.data = (u_char *) calloc (1, newpacket.commandlen );
69 newpacket.type = 0x02;
71 curbyte += aim_putsnac(newpacket.data+curbyte, 0x0017, 0x0006, 0x0000, 0x00010000);
72 curbyte += aim_puttlv_str(newpacket.data+curbyte, 0x0001, strlen(sn), sn);
75 aim_tx_enqueue(sess, &newpacket);
79 #endif /* SNACLOGIN */
82 * send_login(int socket, char *sn, char *password)
84 * This is the initial login request packet.
86 * The password is encoded before transmition, as per
87 * encode_password(). See that function for their
88 * stupid method of doing it.
91 int aim_send_login (struct aim_session_t *sess,
92 struct aim_conn_t *conn,
93 char *sn, char *password, struct client_info_s *clientinfo)
95 u_char *password_encoded = NULL; /* to store encoded password */
98 struct command_tx_struct newpacket;
100 if (!clientinfo || !sn || !password)
104 newpacket.conn = conn;
106 newpacket.conn = aim_getconn_type(sess, AIM_CONN_TYPE_AUTH);
109 newpacket.commandlen = 10;
110 newpacket.commandlen += 2 + 2 + strlen(sn);
111 newpacket.commandlen += 2 + 2 + strlen(password);
112 newpacket.commandlen += 2 + 2 + strlen(clientinfo->clientstring);
113 newpacket.commandlen += 56;
115 newpacket.data = (u_char *) calloc (1, newpacket.commandlen );
117 newpacket.type = 0x02;
119 curbyte = aim_putsnac(newpacket.data+curbyte, 0x0017, 0x0002, 0x0000, 0x00010000);
120 curbyte+= aim_puttlv_str(newpacket.data+curbyte, 0x0001, strlen(sn), sn);
121 password_encoded = (u_char *) malloc(strlen(password));
122 aim_encode_password(password, password_encoded);
123 curbyte+= aim_puttlv_str(newpacket.data+curbyte, 0x0002, strlen(password), password_encoded);
124 curbyte+= aim_puttlv_str(newpacket.data+curbyte, 0x0003,
125 strlen(clientinfo->clientstring),
126 clientinfo->clientstring);
127 /* XXX: should use clientinfo provided version info */
128 curbyte+= aim_puttlv_16(newpacket.data+curbyte, 0x0016, 0x0004);
129 curbyte+= aim_puttlv_16(newpacket.data+curbyte, 0x0017, 0x0003);
130 curbyte+= aim_puttlv_16(newpacket.data+curbyte, 0x0018, 0x0005);
131 curbyte+= aim_puttlv_16(newpacket.data+curbyte, 0x0019, 0x0000);
132 curbyte+= aim_puttlv_16(newpacket.data+curbyte, 0x001a, 0x0686);
133 curbyte+= aim_puttlv_str(newpacket.data+curbyte, 0x0001, 0x0002, clientinfo->country);
134 curbyte+= aim_puttlv_str(newpacket.data+curbyte, 0x0001, 0x0002, clientinfo->lang);
135 curbyte+= aim_puttlv_32(newpacket.data+curbyte, 0x0014, 0x0000002a);
136 curbyte+= aim_puttlv_16(newpacket.data+curbyte, 0x0009, 0x0015);
139 newpacket.commandlen = 4 + 4+strlen(sn) + 4+strlen(password) + 6;
143 if (strlen(clientinfo->clientstring))
144 newpacket.commandlen += 4+strlen(clientinfo->clientstring);
145 newpacket.commandlen += 6+6+6+6;
146 if (strlen(clientinfo->country))
147 newpacket.commandlen += 4+strlen(clientinfo->country);
148 if (strlen(clientinfo->lang))
149 newpacket.commandlen += 4+strlen(clientinfo->lang);
151 newpacket.commandlen += 6;
153 newpacket.data = (char *) calloc (1, newpacket.commandlen );
155 newpacket.type = 0x01;
157 curbyte += aimutil_put16(newpacket.data+curbyte, 0x0000);
158 curbyte += aimutil_put16(newpacket.data+curbyte, 0x0001);
159 curbyte += aimutil_put16(newpacket.data+curbyte, 0x0001);
160 curbyte += aimutil_put16(newpacket.data+curbyte, strlen(sn));
161 curbyte += aimutil_putstr(newpacket.data+curbyte, sn, strlen(sn));
163 curbyte += aimutil_put16(newpacket.data+curbyte, 0x0002);
164 curbyte += aimutil_put16(newpacket.data+curbyte, strlen(password));
165 password_encoded = (char *) malloc(strlen(password));
166 aim_encode_password(password, password_encoded);
167 curbyte += aimutil_putstr(newpacket.data+curbyte, password_encoded, strlen(password));
168 free(password_encoded);
170 curbyte += aim_puttlv_16(newpacket.data+curbyte, 0x0016, 0x0004);
174 if (strlen(clientinfo->clientstring))
176 curbyte += aimutil_put16(newpacket.data+curbyte, 0x0003);
177 curbyte += aimutil_put16(newpacket.data+curbyte, strlen(clientinfo->clientstring));
178 curbyte += aimutil_putstr(newpacket.data+curbyte, clientinfo->clientstring, strlen(clientinfo->clientstring));
180 curbyte += aim_puttlv_16(newpacket.data+curbyte, 0x0017, clientinfo->major /*0x0001*/);
181 curbyte += aim_puttlv_16(newpacket.data+curbyte, 0x0018, clientinfo->minor /*0x0001*/);
182 curbyte += aim_puttlv_16(newpacket.data+curbyte, 0x0019, 0x0000);
183 curbyte += aim_puttlv_16(newpacket.data+curbyte, 0x001a, clientinfo->build /*0x0013*/);
184 if (strlen(clientinfo->country))
186 curbyte += aimutil_put16(newpacket.data+curbyte, 0x000e);
187 curbyte += aimutil_put16(newpacket.data+curbyte, strlen(clientinfo->country));
188 curbyte += aimutil_putstr(newpacket.data+curbyte, clientinfo->country, strlen(clientinfo->country));
190 if (strlen(clientinfo->lang))
192 curbyte += aimutil_put16(newpacket.data+curbyte, 0x000f);
193 curbyte += aimutil_put16(newpacket.data+curbyte, strlen(clientinfo->lang));
194 curbyte += aimutil_putstr(newpacket.data+curbyte, clientinfo->lang, strlen(clientinfo->lang));
198 curbyte += aim_puttlv_16(newpacket.data+curbyte, 0x0009, 0x0015);
202 aim_tx_enqueue(sess, &newpacket);
208 * int encode_password(
209 * const char *password,
213 * This takes a const pointer to a (null terminated) string
214 * containing the unencoded password. It also gets passed
215 * an already allocated buffer to store the encoded password.
216 * This buffer should be the exact length of the password without
217 * the null. The encoded password buffer IS NOT NULL TERMINATED.
219 * The encoding_table seems to be a fixed set of values. We'll
220 * hope it doesn't change over time!
223 int aim_encode_password(const char *password, u_char *encoded)
225 u_char encoding_table[] = {
226 0xf3, 0xb3, 0x6c, 0x99,
227 0x95, 0x3f, 0xac, 0xb6,
228 0xc5, 0xfa, 0x6b, 0x63,
229 0x69, 0x6c, 0xc3, 0x9f
234 for (i = 0; i < strlen(password); i++)
235 encoded[i] = (password[i] ^ encoding_table[i]);
241 * This is sent back as a general response to the login command.
242 * It can be either an error or a success, depending on the
243 * precense of certain TLVs.
245 * The client should check the value of logininfo->errorcode. If
246 * its nonzero, there was an error.
249 int aim_authparse(struct aim_session_t *sess,
250 struct command_rx_struct *command)
252 struct aim_tlvlist_t *tlvlist;
255 rxcallback_t userfunc = NULL;
257 memset(&sess->logininfo, 0x00, sizeof(sess->logininfo));
260 * Read block of TLVs. All further data is derived
261 * from what is parsed here.
264 tlvlist = aim_readtlvchain(command->data+10, command->commandlen-10);
266 tlvlist = aim_readtlvchain(command->data, command->commandlen);
269 * No matter what, we should have a screen name.
271 sn = aim_gettlv_str(tlvlist, 0x0001, 1);
272 memcpy(sess->logininfo.screen_name, sn, strlen(sn));
273 sn[(strlen(sn))] = '\0';
276 * Check for an error code. If so, we should also
279 if (aim_gettlv(tlvlist, 0x0008, 1))
281 struct aim_tlv_t *errtlv;
282 errtlv = aim_gettlv(tlvlist, 0x0008, 1);
283 sess->logininfo.errorcode = aimutil_get16(errtlv->value);
284 sess->logininfo.errorurl = aim_gettlv_str(tlvlist, 0x0004, 1);
287 * If we have both an IP number (0x0005) and a cookie (0x0006),
288 * then the login was successful.
290 else if (aim_gettlv(tlvlist, 0x0005, 1) && aim_gettlv(tlvlist, 0x0006, 1))
292 struct aim_tlv_t *tmptlv;
295 * IP address of BOS server.
297 sess->logininfo.BOSIP = aim_gettlv_str(tlvlist, 0x0005, 1);
300 * Authorization Cookie
302 tmptlv = aim_gettlv(tlvlist, 0x0006, 1);
303 memcpy(sess->logininfo.cookie, tmptlv->value, AIM_COOKIELEN);
306 * The email address attached to this account
308 sess->logininfo.email = aim_gettlv_str(tlvlist, 0x0011, 1);
311 * The registration status. (Not real sure what it means.)
313 tmptlv = aim_gettlv(tlvlist, 0x0013, 1);
314 sess->logininfo.regstatus = aimutil_get16(tmptlv->value);
319 userfunc = aim_callhandler(command->conn, 0x0017, 0x0003);
321 userfunc = aim_callhandler(command->conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_AUTHSUCCESS);
324 ret = userfunc(sess, command);
326 aim_freetlvchain(&tlvlist);
328 /* These have been clobbered by the freetlvchain */
329 sess->logininfo.BOSIP = NULL;
330 sess->logininfo.email = NULL;
331 sess->logininfo.errorurl = NULL;