]> andersk Git - libfaim.git/blame - src/auth.c
- Sun Oct 14 19:45:54 PDT 2001
[libfaim.git] / src / auth.c
CommitLineData
9de3ca7e 1/*
d410cf58 2 * aim_auth.c
3 *
4 * Deals with the authorizer.
5 *
9de3ca7e 6 */
7
37ee990e 8#define FAIM_INTERNAL
dd60ff8b 9#include <aim.h>
9de3ca7e 10
11/* this just pushes the passed cookie onto the passed connection -- NO SNAC! */
d410cf58 12faim_export int aim_auth_sendcookie(aim_session_t *sess, aim_conn_t *conn, const fu8_t *chipsahoy)
9de3ca7e 13{
d410cf58 14 aim_frame_t *fr;
15 aim_tlvlist_t *tl = NULL;
16
17 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x0001, 4+2+2+AIM_COOKIELEN)))
18 return -ENOMEM;
9de3ca7e 19
d410cf58 20 aimbs_put32(&fr->data, 0x00000001);
21 aim_addtlvtochain_raw(&tl, 0x0006, AIM_COOKIELEN, chipsahoy);
22 aim_writetlvchain(&fr->data, &tl);
23 aim_freetlvchain(&tl);
9de3ca7e 24
d410cf58 25 aim_tx_enqueue(sess, fr);
9de3ca7e 26
d410cf58 27 return 0;
9de3ca7e 28}
29
9f1a4013 30/*
31 * This is sent back as a general response to the login command.
32 * It can be either an error or a success, depending on the
33 * precense of certain TLVs.
34 *
35 * The client should check the value passed as errorcode. If
36 * its nonzero, there was an error.
37 *
38 */
d410cf58 39static int parse(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
9de3ca7e 40{
d410cf58 41 aim_tlvlist_t *tlvlist;
42 int ret = 0;
43 aim_rxcallback_t userfunc;
44 char *sn = NULL, *bosip = NULL, *errurl = NULL, *email = NULL;
45 unsigned char *cookie = NULL;
46 int errorcode = 0, regstatus = 0;
47 int latestbuild = 0, latestbetabuild = 0;
48 char *latestrelease = NULL, *latestbeta = NULL;
49 char *latestreleaseurl = NULL, *latestbetaurl = NULL;
50 char *latestreleaseinfo = NULL, *latestbetainfo = NULL;
51
52 /*
53 * Read block of TLVs. All further data is derived
54 * from what is parsed here.
55 */
56 tlvlist = aim_readtlvchain(bs);
57
58 /*
59 * No matter what, we should have a screen name.
60 */
61 memset(sess->sn, 0, sizeof(sess->sn));
62 if (aim_gettlv(tlvlist, 0x0001, 1)) {
63 sn = aim_gettlv_str(tlvlist, 0x0001, 1);
64 strncpy(sess->sn, sn, sizeof(sess->sn));
65 }
66
67 /*
68 * Check for an error code. If so, we should also
69 * have an error url.
70 */
71 if (aim_gettlv(tlvlist, 0x0008, 1))
72 errorcode = aim_gettlv16(tlvlist, 0x0008, 1);
73 if (aim_gettlv(tlvlist, 0x0004, 1))
74 errurl = aim_gettlv_str(tlvlist, 0x0004, 1);
75
76 /*
77 * BOS server address.
78 */
79 if (aim_gettlv(tlvlist, 0x0005, 1))
80 bosip = aim_gettlv_str(tlvlist, 0x0005, 1);
81
82 /*
83 * Authorization cookie.
84 */
85 if (aim_gettlv(tlvlist, 0x0006, 1)) {
86 aim_tlv_t *tmptlv;
87
88 tmptlv = aim_gettlv(tlvlist, 0x0006, 1);
89
90 if ((cookie = malloc(tmptlv->length)))
91 memcpy(cookie, tmptlv->value, tmptlv->length);
92 }
93
94 /*
95 * The email address attached to this account
96 * Not available for ICQ logins.
97 */
98 if (aim_gettlv(tlvlist, 0x0011, 1))
99 email = aim_gettlv_str(tlvlist, 0x0011, 1);
100
101 /*
102 * The registration status. (Not real sure what it means.)
103 * Not available for ICQ logins.
104 *
105 * 1 = No disclosure
106 * 2 = Limited disclosure
107 * 3 = Full disclosure
108 *
109 * This has to do with whether your email address is available
110 * to other users or not. AFAIK, this feature is no longer used.
111 *
112 */
113 if (aim_gettlv(tlvlist, 0x0013, 1))
114 regstatus = aim_gettlv16(tlvlist, 0x0013, 1);
115
116 if (aim_gettlv(tlvlist, 0x0040, 1))
117 latestbetabuild = aim_gettlv32(tlvlist, 0x0040, 1);
118 if (aim_gettlv(tlvlist, 0x0041, 1))
119 latestbetaurl = aim_gettlv_str(tlvlist, 0x0041, 1);
120 if (aim_gettlv(tlvlist, 0x0042, 1))
121 latestbetainfo = aim_gettlv_str(tlvlist, 0x0042, 1);
122 if (aim_gettlv(tlvlist, 0x0043, 1))
123 latestbeta = aim_gettlv_str(tlvlist, 0x0043, 1);
124 if (aim_gettlv(tlvlist, 0x0048, 1))
125 ; /* no idea what this is */
126
127 if (aim_gettlv(tlvlist, 0x0044, 1))
128 latestbuild = aim_gettlv32(tlvlist, 0x0044, 1);
129 if (aim_gettlv(tlvlist, 0x0045, 1))
130 latestreleaseurl = aim_gettlv_str(tlvlist, 0x0045, 1);
131 if (aim_gettlv(tlvlist, 0x0046, 1))
132 latestreleaseinfo = aim_gettlv_str(tlvlist, 0x0046, 1);
133 if (aim_gettlv(tlvlist, 0x0047, 1))
134 latestrelease = aim_gettlv_str(tlvlist, 0x0047, 1);
135 if (aim_gettlv(tlvlist, 0x0049, 1))
136 ; /* no idea what this is */
137
138
139 if ((userfunc = aim_callhandler(sess, rx->conn, snac ? snac->family : 0x0017, snac ? snac->subtype : 0x0003))) {
140 /* XXX return as a struct? */
141 ret = userfunc(sess, rx, sn, errorcode, errurl, regstatus, email, bosip, cookie, latestrelease, latestbuild, latestreleaseurl, latestreleaseinfo, latestbeta, latestbetabuild, latestbetaurl, latestbetainfo);
142 }
143
144 free(sn);
145 free(bosip);
146 free(errurl);
147 free(email);
148 free(cookie);
149 free(latestrelease);
150 free(latestreleaseurl);
151 free(latestbeta);
152 free(latestbetaurl);
153 free(latestreleaseinfo);
154 free(latestbetainfo);
155
156 aim_freetlvchain(&tlvlist);
157
158 return ret;
64c78745 159}
160
161/*
9f1a4013 162 * Middle handler for 0017/0007 SNACs. Contains the auth key prefixed
163 * by only its length in a two byte word.
64c78745 164 *
9f1a4013 165 * Calls the client, which should then use the value to call aim_send_login.
64c78745 166 *
167 */
d410cf58 168static int keyparse(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
64c78745 169{
d410cf58 170 int keylen, ret = 1;
171 aim_rxcallback_t userfunc;
172 char *keystr;
173
174 keylen = aimbs_get16(bs);
175 keystr = aimbs_getstr(bs, keylen);
176
177 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
178 ret = userfunc(sess, rx, keystr);
179
180 free(keystr);
181
182 return ret;
9f1a4013 183}
64c78745 184
d410cf58 185static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
9f1a4013 186{
64c78745 187
d410cf58 188 if (snac->subtype == 0x0003)
189 return parse(sess, mod, rx, snac, bs);
190 else if (snac->subtype == 0x0007)
191 return keyparse(sess, mod, rx, snac, bs);
64c78745 192
d410cf58 193 return 0;
64c78745 194}
195
d410cf58 196faim_internal int auth_modfirst(aim_session_t *sess, aim_module_t *mod)
64c78745 197{
64c78745 198
d410cf58 199 mod->family = 0x0017;
200 mod->version = 0x0000;
201 mod->flags = 0;
202 strncpy(mod->name, "auth", sizeof(mod->name));
203 mod->snachandler = snachandler;
9de3ca7e 204
d410cf58 205 return 0;
9de3ca7e 206}
d410cf58 207
This page took 0.123119 seconds and 5 git commands to generate.