]> andersk Git - libfaim.git/blobdiff - src/auth.c
- Mon Sep 3 18:48:26 PDT 2001
[libfaim.git] / src / auth.c
index 621c269c84594264f0dfc7fcd0489a9ab4686c99..ff1ad08a4c0d9dc98f2c83e11599a7a1e0d6b3e5 100644 (file)
 /*
-  aim_auth.c
-
-  Deals with the authorizer.
-
 aim_auth.c
+ *
* Deals with the authorizer.
+ *
  */
 
 #define FAIM_INTERNAL
 #include <aim.h> 
 
 /* this just pushes the passed cookie onto the passed connection -- NO SNAC! */
-faim_export int aim_auth_sendcookie(struct aim_session_t *sess, 
-                                   struct aim_conn_t *conn, 
-                                   unsigned char *chipsahoy)
-{
-  struct command_tx_struct *newpacket;
-  int curbyte=0;
-  
-  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0001, 4+2+2+AIM_COOKIELEN)))
-    return -1;
-
-  newpacket->lock = 1;
-
-  curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
-  curbyte += aimutil_put16(newpacket->data+curbyte, 0x0001);
-  curbyte += aimutil_put16(newpacket->data+curbyte, 0x0006);
-  curbyte += aimutil_put16(newpacket->data+curbyte, AIM_COOKIELEN);
-  memcpy(newpacket->data+curbyte, chipsahoy, AIM_COOKIELEN);
-
-  return aim_tx_enqueue(sess, newpacket);
-}
-
-faim_export unsigned long aim_auth_clientready(struct aim_session_t *sess,
-                                              struct aim_conn_t *conn)
-{
-  struct aim_tool_version tools[] = {
-    {0x0001, 0x0003,    AIM_TOOL_NEWWIN, 0x0361},
-    {0x0007, 0x0001,    AIM_TOOL_NEWWIN, 0x0361},
-  };
-  int i,j;
-  struct command_tx_struct *newpacket;
-  int toolcount = sizeof(tools)/sizeof(struct aim_tool_version);
-
-  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 1152)))
-    return -1;
-
-  newpacket->lock = 1;
-
-  i = aim_putsnac(newpacket->data, 0x0001, 0x0002, 0x0000, sess->snac_nextid);
-  aim_cachesnac(sess, 0x0001, 0x0002, 0x0000, NULL, 0);
-
-  for (j = 0; j < toolcount; j++) {
-    i += aimutil_put16(newpacket->data+i, tools[j].group);
-    i += aimutil_put16(newpacket->data+i, tools[j].version);
-    i += aimutil_put16(newpacket->data+i, tools[j].tool);
-    i += aimutil_put16(newpacket->data+i, tools[j].toolversion);
-  }
-
-  newpacket->commandlen = i;
-  newpacket->lock = 0;
-
-  aim_tx_enqueue(sess, newpacket);
-
-  return sess->snac_nextid;
-}
-
-faim_export unsigned long aim_auth_changepasswd(struct aim_session_t *sess,
-                                               struct aim_conn_t *conn, 
-                                               char *new, char *current)
+faim_export int aim_auth_sendcookie(aim_session_t *sess, aim_conn_t *conn, const fu8_t *chipsahoy)
 {
-  struct command_tx_struct *newpacket;
-  int i;
+       aim_frame_t *fr;
+       aim_tlvlist_t *tl = NULL;
 
-  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+4+strlen(current)+4+strlen(new))))
-    return -1;
+       if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x0001, 4+2+2+AIM_COOKIELEN)))
+               return -ENOMEM;
 
-  newpacket->lock = 1;
+       aimbs_put32(&fr->data, 0x00000001);
+       aim_addtlvtochain_raw(&tl, 0x0006, AIM_COOKIELEN, chipsahoy);   
+       aim_writetlvchain(&fr->data, &tl);
+       aim_freetlvchain(&tl);
 
-  i = aim_putsnac(newpacket->data, 0x0007, 0x0004, 0x0000, sess->snac_nextid);
-  aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0);
+       aim_tx_enqueue(sess, fr);
 
-  /* new password TLV t(0002) */
-  i += aim_puttlv_str(newpacket->data+i, 0x0002, strlen(new), new);
-
-  /* current password TLV t(0012) */
-  i += aim_puttlv_str(newpacket->data+i, 0x0012, strlen(current), current);
-
-  aim_tx_enqueue(sess, newpacket);
-
-  return sess->snac_nextid;
-}
-
-faim_export unsigned long aim_auth_setversions(struct aim_session_t *sess,
-                                              struct aim_conn_t *conn)
-{
-  struct command_tx_struct *newpacket;
-  int i;
-
-  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10 + (4*2))))
-    return -1;
-
-  newpacket->lock = 1;
-
-  i = aim_putsnac(newpacket->data, 0x0001, 0x0017, 0x0000, sess->snac_nextid);
-  aim_cachesnac(sess, 0x0001, 0x0017, 0x0000, NULL, 0);
-
-  i += aimutil_put16(newpacket->data+i, 0x0001);
-  i += aimutil_put16(newpacket->data+i, 0x0003);
-
-  i += aimutil_put16(newpacket->data+i, 0x0007);
-  i += aimutil_put16(newpacket->data+i, 0x0001);
-
-  newpacket->commandlen = i;
-  newpacket->lock = 0;
-  aim_tx_enqueue(sess, newpacket);
-
-  return sess->snac_nextid;
+       return 0;
 }
 
 /*
- * Request account confirmation. 
+ * This is sent back as a general response to the login command.
+ * It can be either an error or a success, depending on the
+ * precense of certain TLVs.  
  *
- * This will cause an email to be sent to the address associated with
- * the account.  By following the instructions in the mail, you can
- * get the TRIAL flag removed from your account.
+ * The client should check the value passed as errorcode. If
+ * its nonzero, there was an error.
  *
  */
-faim_export unsigned long aim_auth_reqconfirm(struct aim_session_t *sess,
-                                             struct aim_conn_t *conn)
+static int parse(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
 {
-  return aim_genericreq_n(sess, conn, 0x0007, 0x0006);
+       aim_tlvlist_t *tlvlist;
+       int ret = 0;
+       aim_rxcallback_t userfunc;
+       char *sn = NULL, *bosip = NULL, *errurl = NULL, *email = NULL;
+       unsigned char *cookie = NULL;
+       int errorcode = 0, regstatus = 0;
+       int latestbuild = 0, latestbetabuild = 0;
+       char *latestrelease = NULL, *latestbeta = NULL;
+       char *latestreleaseurl = NULL, *latestbetaurl = NULL;
+       char *latestreleaseinfo = NULL, *latestbetainfo = NULL;
+
+       /*
+        * Read block of TLVs.  All further data is derived
+        * from what is parsed here.
+        */
+       tlvlist = aim_readtlvchain(bs);
+
+       /*
+        * No matter what, we should have a screen name.
+        */
+       memset(sess->sn, 0, sizeof(sess->sn));
+       if (aim_gettlv(tlvlist, 0x0001, 1)) {
+               sn = aim_gettlv_str(tlvlist, 0x0001, 1);
+               strncpy(sess->sn, sn, sizeof(sess->sn));
+       }
+
+       /*
+        * Check for an error code.  If so, we should also
+        * have an error url.
+        */
+       if (aim_gettlv(tlvlist, 0x0008, 1)) 
+               errorcode = aim_gettlv16(tlvlist, 0x0008, 1);
+       if (aim_gettlv(tlvlist, 0x0004, 1))
+               errurl = aim_gettlv_str(tlvlist, 0x0004, 1);
+
+       /*
+        * BOS server address.
+        */
+       if (aim_gettlv(tlvlist, 0x0005, 1))
+               bosip = aim_gettlv_str(tlvlist, 0x0005, 1);
+
+       /*
+        * Authorization cookie.
+        */
+       if (aim_gettlv(tlvlist, 0x0006, 1)) {
+               aim_tlv_t *tmptlv;
+
+               tmptlv = aim_gettlv(tlvlist, 0x0006, 1);
+
+               if ((cookie = malloc(tmptlv->length)))
+                       memcpy(cookie, tmptlv->value, tmptlv->length);
+       }
+
+       /*
+        * The email address attached to this account
+        *   Not available for ICQ logins.
+        */
+       if (aim_gettlv(tlvlist, 0x0011, 1))
+               email = aim_gettlv_str(tlvlist, 0x0011, 1);
+
+       /*
+        * The registration status.  (Not real sure what it means.)
+        *   Not available for ICQ logins.
+        *
+        *   1 = No disclosure
+        *   2 = Limited disclosure
+        *   3 = Full disclosure
+        *
+        * This has to do with whether your email address is available
+        * to other users or not.  AFAIK, this feature is no longer used.
+        *
+        */
+       if (aim_gettlv(tlvlist, 0x0013, 1))
+               regstatus = aim_gettlv16(tlvlist, 0x0013, 1);
+
+       if (aim_gettlv(tlvlist, 0x0040, 1))
+               latestbetabuild = aim_gettlv32(tlvlist, 0x0040, 1);
+       if (aim_gettlv(tlvlist, 0x0041, 1))
+               latestbetaurl = aim_gettlv_str(tlvlist, 0x0041, 1);
+       if (aim_gettlv(tlvlist, 0x0042, 1))
+               latestbetainfo = aim_gettlv_str(tlvlist, 0x0042, 1);
+       if (aim_gettlv(tlvlist, 0x0043, 1))
+               latestbeta = aim_gettlv_str(tlvlist, 0x0043, 1);
+       if (aim_gettlv(tlvlist, 0x0048, 1))
+               ; /* no idea what this is */
+
+       if (aim_gettlv(tlvlist, 0x0044, 1))
+               latestbuild = aim_gettlv32(tlvlist, 0x0044, 1);
+       if (aim_gettlv(tlvlist, 0x0045, 1))
+               latestreleaseurl = aim_gettlv_str(tlvlist, 0x0045, 1);
+       if (aim_gettlv(tlvlist, 0x0046, 1))
+               latestreleaseinfo = aim_gettlv_str(tlvlist, 0x0046, 1);
+       if (aim_gettlv(tlvlist, 0x0047, 1))
+               latestrelease = aim_gettlv_str(tlvlist, 0x0047, 1);
+       if (aim_gettlv(tlvlist, 0x0049, 1))
+               ; /* no idea what this is */
+
+
+       if ((userfunc = aim_callhandler(sess, rx->conn, snac ? snac->family : 0x0017, snac ? snac->subtype : 0x0003))) {
+               /* XXX return as a struct? */
+               ret = userfunc(sess, rx, sn, errorcode, errurl, regstatus, email, bosip, cookie, latestrelease, latestbuild, latestreleaseurl, latestreleaseinfo, latestbeta, latestbetabuild, latestbetaurl, latestbetainfo);
+       }
+
+       free(sn);
+       free(bosip);
+       free(errurl);
+       free(email);
+       free(cookie);
+       free(latestrelease);
+       free(latestreleaseurl);
+       free(latestbeta);
+       free(latestbetaurl);
+       free(latestreleaseinfo);
+       free(latestbetainfo);
+
+       aim_freetlvchain(&tlvlist);
+
+       return ret;
 }
 
 /*
- * Request a bit of account info.
+ * Middle handler for 0017/0007 SNACs.  Contains the auth key prefixed
+ * by only its length in a two byte word.
  *
- * The only known valid tag is 0x0011 (email address).
+ * Calls the client, which should then use the value to call aim_send_login.
  *
- */ 
-faim_export unsigned long aim_auth_getinfo(struct aim_session_t *sess,
-                                          struct aim_conn_t *conn,
-                                          unsigned short info)
+ */
+static int keyparse(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
 {
-  struct command_tx_struct *newpacket;
-  int i;
-
-  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10 + 4)))
-    return -1;
+       int keylen, ret = 1;
+       aim_rxcallback_t userfunc;
+       char *keystr;
 
-  newpacket->lock = 1;
+       keylen = aimbs_get16(bs);
+       keystr = aimbs_getstr(bs, keylen);
 
-  i = aim_putsnac(newpacket->data, 0x0007, 0x0002, 0x0000, sess->snac_nextid);
-  aim_cachesnac(sess, 0x0002, 0x0002, 0x0000, NULL, 0);
+       if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
+               ret = userfunc(sess, rx, keystr);
 
-  i += aimutil_put16(newpacket->data+i, info);
-  i += aimutil_put16(newpacket->data+i, 0x0000);
+       free(keystr); 
 
-  newpacket->commandlen = i;
-  newpacket->lock = 0;
-  aim_tx_enqueue(sess, newpacket);
-
-  return sess->snac_nextid;
+       return ret;
 }
 
-faim_export unsigned long aim_auth_setemail(struct aim_session_t *sess,
-                                           struct aim_conn_t *conn, 
-                                           char *newemail)
+static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
 {
-  struct command_tx_struct *newpacket;
-  int i;
-
-  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+2+2+strlen(newemail))))
-    return -1;
 
-  newpacket->lock = 1;
+       if (snac->subtype == 0x0003)
+               return parse(sess, mod, rx, snac, bs);
+       else if (snac->subtype == 0x0007)
+               return keyparse(sess, mod, rx, snac, bs);
 
-  i = aim_putsnac(newpacket->data, 0x0007, 0x0004, 0x0000, sess->snac_nextid);
-  aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0);
+       return 0;
+}
 
-  i += aim_puttlv_str(newpacket->data+i, 0x0011, strlen(newemail), newemail);
+faim_internal int auth_modfirst(aim_session_t *sess, aim_module_t *mod)
+{
 
-  aim_tx_enqueue(sess, newpacket);
+       mod->family = 0x0017;
+       mod->version = 0x0000;
+       mod->flags = 0;
+       strncpy(mod->name, "auth", sizeof(mod->name));
+       mod->snachandler = snachandler;
 
-  return sess->snac_nextid;
+       return 0;
 }
+
This page took 0.071508 seconds and 4 git commands to generate.