]> andersk Git - libfaim.git/blob - src/auth.c
- Sun Oct 14 19:45:54 PDT 2001
[libfaim.git] / src / auth.c
1 /*
2  *  aim_auth.c
3  *
4  * Deals with the authorizer.
5  *
6  */
7
8 #define FAIM_INTERNAL
9 #include <aim.h> 
10
11 /* this just pushes the passed cookie onto the passed connection -- NO SNAC! */
12 faim_export int aim_auth_sendcookie(aim_session_t *sess, aim_conn_t *conn, const fu8_t *chipsahoy)
13 {
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;
19
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);
24
25         aim_tx_enqueue(sess, fr);
26
27         return 0;
28 }
29
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  */
39 static int parse(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
40 {
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;
159 }
160
161 /*
162  * Middle handler for 0017/0007 SNACs.  Contains the auth key prefixed
163  * by only its length in a two byte word.
164  *
165  * Calls the client, which should then use the value to call aim_send_login.
166  *
167  */
168 static int keyparse(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
169 {
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;
183 }
184
185 static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
186 {
187
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);
192
193         return 0;
194 }
195
196 faim_internal int auth_modfirst(aim_session_t *sess, aim_module_t *mod)
197 {
198
199         mod->family = 0x0017;
200         mod->version = 0x0000;
201         mod->flags = 0;
202         strncpy(mod->name, "auth", sizeof(mod->name));
203         mod->snachandler = snachandler;
204
205         return 0;
206 }
207
This page took 0.048317 seconds and 5 git commands to generate.