4 Deals with the authorizer.
11 /* this just pushes the passed cookie onto the passed connection -- NO SNAC! */
12 faim_export int aim_auth_sendcookie(struct aim_session_t *sess,
13 struct aim_conn_t *conn,
14 unsigned char *chipsahoy)
16 struct command_tx_struct *newpacket;
19 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0001, 4+2+2+AIM_COOKIELEN)))
24 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
25 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0001);
26 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0006);
27 curbyte += aimutil_put16(newpacket->data+curbyte, AIM_COOKIELEN);
28 memcpy(newpacket->data+curbyte, chipsahoy, AIM_COOKIELEN);
30 return aim_tx_enqueue(sess, newpacket);
34 * This is sent back as a general response to the login command.
35 * It can be either an error or a success, depending on the
36 * precense of certain TLVs.
38 * The client should check the value passed as errorcode. If
39 * its nonzero, there was an error.
42 static int parse(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
44 struct aim_tlvlist_t *tlvlist;
46 aim_rxcallback_t userfunc;
47 char *sn = NULL, *bosip = NULL, *errurl = NULL, *email = NULL;
48 unsigned char *cookie = NULL;
49 int errorcode = 0, regstatus = 0;
50 int latestbuild = 0, latestbetabuild = 0;
51 char *latestrelease = NULL, *latestbeta = NULL;
52 char *latestreleaseurl = NULL, *latestbetaurl = NULL;
53 char *latestreleaseinfo = NULL, *latestbetainfo = NULL;
56 * Read block of TLVs. All further data is derived
57 * from what is parsed here.
60 tlvlist = aim_readtlvchain(data, datalen);
63 * No matter what, we should have a screen name.
65 memset(sess->sn, 0, sizeof(sess->sn));
66 if (aim_gettlv(tlvlist, 0x0001, 1)) {
67 sn = aim_gettlv_str(tlvlist, 0x0001, 1);
68 strncpy(sess->sn, sn, sizeof(sess->sn));
72 * Check for an error code. If so, we should also
75 if (aim_gettlv(tlvlist, 0x0008, 1))
76 errorcode = aim_gettlv16(tlvlist, 0x0008, 1);
77 if (aim_gettlv(tlvlist, 0x0004, 1))
78 errurl = aim_gettlv_str(tlvlist, 0x0004, 1);
83 if (aim_gettlv(tlvlist, 0x0005, 1))
84 bosip = aim_gettlv_str(tlvlist, 0x0005, 1);
87 * Authorization cookie.
89 if (aim_gettlv(tlvlist, 0x0006, 1)) {
90 struct aim_tlv_t *tmptlv;
92 tmptlv = aim_gettlv(tlvlist, 0x0006, 1);
94 if ((cookie = malloc(tmptlv->length)))
95 memcpy(cookie, tmptlv->value, tmptlv->length);
99 * The email address attached to this account
100 * Not available for ICQ logins.
102 if (aim_gettlv(tlvlist, 0x0011, 1))
103 email = aim_gettlv_str(tlvlist, 0x0011, 1);
106 * The registration status. (Not real sure what it means.)
107 * Not available for ICQ logins.
110 * 2 = Limited disclosure
111 * 3 = Full disclosure
113 * This has to do with whether your email address is available
114 * to other users or not. AFAIK, this feature is no longer used.
117 if (aim_gettlv(tlvlist, 0x0013, 1))
118 regstatus = aim_gettlv16(tlvlist, 0x0013, 1);
120 if (aim_gettlv(tlvlist, 0x0040, 1))
121 latestbetabuild = aim_gettlv32(tlvlist, 0x0040, 1);
122 if (aim_gettlv(tlvlist, 0x0041, 1))
123 latestbetaurl = aim_gettlv_str(tlvlist, 0x0041, 1);
124 if (aim_gettlv(tlvlist, 0x0042, 1))
125 latestbetainfo = aim_gettlv_str(tlvlist, 0x0042, 1);
126 if (aim_gettlv(tlvlist, 0x0043, 1))
127 latestbeta = aim_gettlv_str(tlvlist, 0x0043, 1);
128 if (aim_gettlv(tlvlist, 0x0048, 1))
129 ; /* no idea what this is */
131 if (aim_gettlv(tlvlist, 0x0044, 1))
132 latestbuild = aim_gettlv32(tlvlist, 0x0044, 1);
133 if (aim_gettlv(tlvlist, 0x0045, 1))
134 latestreleaseurl = aim_gettlv_str(tlvlist, 0x0045, 1);
135 if (aim_gettlv(tlvlist, 0x0046, 1))
136 latestreleaseinfo = aim_gettlv_str(tlvlist, 0x0046, 1);
137 if (aim_gettlv(tlvlist, 0x0047, 1))
138 latestrelease = aim_gettlv_str(tlvlist, 0x0047, 1);
139 if (aim_gettlv(tlvlist, 0x0049, 1))
140 ; /* no idea what this is */
143 if ((userfunc = aim_callhandler(sess, rx->conn, snac?snac->family:0x0017, snac?snac->subtype:0x0003)))
144 ret = userfunc(sess, rx, sn, errorcode, errurl, regstatus, email, bosip, cookie, latestrelease, latestbuild, latestreleaseurl, latestreleaseinfo, latestbeta, latestbetabuild, latestbetaurl, latestbetainfo);
159 if (latestreleaseurl)
160 free(latestreleaseurl);
165 if (latestreleaseinfo)
166 free(latestreleaseinfo);
168 free(latestbetainfo);
170 aim_freetlvchain(&tlvlist);
176 * Middle handler for 0017/0007 SNACs. Contains the auth key prefixed
177 * by only its length in a two byte word.
179 * Calls the client, which should then use the value to call aim_send_login.
182 static int keyparse(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
187 aim_rxcallback_t userfunc;
189 keylen = aimutil_get16(data);
190 if (!(key = malloc(keylen+1)))
192 memcpy(key, data+2, keylen);
195 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
196 ret = userfunc(sess, rx, (char *)key);
203 static int snachandler(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
206 if (snac->subtype == 0x0003)
207 return parse(sess, mod, rx, snac, data, datalen);
208 else if (snac->subtype == 0x0007)
209 return keyparse(sess, mod, rx, snac, data, datalen);
214 faim_internal int auth_modfirst(struct aim_session_t *sess, aim_module_t *mod)
217 mod->family = 0x0017;
218 mod->version = 0x0000;
220 strncpy(mod->name, "auth", sizeof(mod->name));
221 mod->snachandler = snachandler;