From e6b05d80e34b2ae185bb0249f4147f25e05100e5 Mon Sep 17 00:00:00 2001 From: mid Date: Mon, 20 Mar 2000 05:32:28 +0000 Subject: [PATCH] - Mon Mar 20 05:30:59 UTC 2000 - Added some server-only functions for login - Added aim_counttlvchain() - Added aim_sncmp() and aim_snlen() --- CHANGES | 5 ++ aim_conn.c | 8 ++- aim_im.c | 3 ++ aim_login.c | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++++ aim_tlv.c | 18 ++++++- aim_util.c | 71 ++++++++++++++++++++++++++ faim/aim.h | 21 ++++++-- 7 files changed, 264 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index b70fa8a..17068a9 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,11 @@ No release numbers ------------------ + - Mon Mar 20 05:30:59 UTC 2000 + - Added some server-only functions for login + - Added aim_counttlvchain() + - Added aim_sncmp() and aim_snlen() + - Sun Mar 19 06:07:52 UTC 2000 - Added a parameter to aim_select to return event type - REQUIRES CLIENT CHANGES. diff --git a/aim_conn.c b/aim_conn.c index 75ad013..5cb4a79 100644 --- a/aim_conn.c +++ b/aim_conn.c @@ -80,11 +80,17 @@ struct aim_conn_t *aim_newconn(struct aim_session_t *sess, char *host = NULL; int i=0; - if (!dest || ((connstruct=aim_conn_getnext(sess))==NULL)) + if ((connstruct=aim_conn_getnext(sess))==NULL) return NULL; connstruct->type = type; + if (!dest) { /* just allocate a struct */ + connstruct->fd = -1; + connstruct->status = 0; + return connstruct; + } + /* * As of 23 Jul 1999, AOL now sends the port number, preceded by a * colon, in the BOS redirect. This fatally breaks all previous diff --git a/aim_im.c b/aim_im.c index 867750b..3a777fa 100644 --- a/aim_im.c +++ b/aim_im.c @@ -286,6 +286,7 @@ int aim_parse_incoming_im_middle(struct aim_session_t *sess, { printf("faim: icbm: major error! no message block TLV found!\n"); aim_freetlvchain(&tlvlist); + return 1; } /* @@ -556,3 +557,5 @@ int aim_parse_msgerror_middle(struct aim_session_t *sess, return ret; } + + diff --git a/aim_login.c b/aim_login.c index 61992a1..2c75d64 100644 --- a/aim_login.c +++ b/aim_login.c @@ -332,3 +332,147 @@ int aim_authparse(struct aim_session_t *sess, return ret; } + +/* + * Generate an authorization response. + * + * You probably don't want this unless you're writing an AIM server. + * + */ +unsigned long aim_sendauthresp(struct aim_session_t *sess, + struct aim_conn_t *conn, + char *sn, char *bosip, + char *cookie, char *email, + int regstatus) +{ + struct command_tx_struct tx; + struct aim_tlvlist_t *tlvlist = NULL; + + tx.conn = conn; + + tx.commandlen = 1152; /* arbitrarily large */ + tx.data = malloc(tx.commandlen); + memset(tx.data, 0x00, tx.commandlen); + + tx.lock = 1; + tx.type = 0x01; /* XXX: right? */ + + if (sn) + aim_addtlvtochain_str(&tlvlist, 0x0001, sn, strlen(sn)); + else + aim_addtlvtochain_str(&tlvlist, 0x0001, sess->logininfo.screen_name, strlen(sess->logininfo.screen_name)); + + if (sess->logininfo.errorcode) { + aim_addtlvtochain16(&tlvlist, 0x0008, sess->logininfo.errorcode); + aim_addtlvtochain_str(&tlvlist, 0x0004, sess->logininfo.errorurl, strlen(sess->logininfo.errorurl)); + } else { + aim_addtlvtochain_str(&tlvlist, 0x0005, bosip, strlen(bosip)); + aim_addtlvtochain_str(&tlvlist, 0x0006, cookie, AIM_COOKIELEN); + aim_addtlvtochain_str(&tlvlist, 0x0011, email, strlen(email)); + aim_addtlvtochain16(&tlvlist, 0x0013, regstatus); + } + + tx.commandlen = aim_writetlvchain(tx.data, tx.commandlen, &tlvlist); + tx.lock = 0; + aim_tx_enqueue(sess, &tx); + + return 0; +} + +/* + * Generate a random cookie. (Non-client use only) + */ +int aim_gencookie(unsigned char *buf) +{ + int i; + + srand(time(NULL)); + + for (i=0; i < AIM_COOKIELEN; i++) + buf[i] = 1+(int) (256.0*rand()/(RAND_MAX+0.0)); + + return i; +} + +/* + * Send Server Ready. (Non-client) + */ +int aim_sendserverready(struct aim_session_t *sess, struct aim_conn_t *conn) +{ + struct command_tx_struct tx; + int i = 0; + + tx.conn = conn; + + tx.commandlen = 10 + 0x20; + tx.data = malloc(tx.commandlen); + memset(tx.data, 0x00, tx.commandlen); + + tx.lock = 1; + tx.type = 0x02; + + i += aimutil_put16(tx.data+i, 0x0001); + i += aimutil_put16(tx.data+i, 0x0003); + i += aimutil_put16(tx.data+i, 0x0000); + i += aimutil_put16(tx.data+i, 0x0000); + i += aimutil_put16(tx.data+i, 0x0000); + + i += aimutil_put16(tx.data+i, 0x0001); + i += aimutil_put16(tx.data+i, 0x0002); + i += aimutil_put16(tx.data+i, 0x0003); + i += aimutil_put16(tx.data+i, 0x0004); + i += aimutil_put16(tx.data+i, 0x0006); + i += aimutil_put16(tx.data+i, 0x0008); + i += aimutil_put16(tx.data+i, 0x0009); + i += aimutil_put16(tx.data+i, 0x000a); + i += aimutil_put16(tx.data+i, 0x000b); + i += aimutil_put16(tx.data+i, 0x000c); + + tx.lock = 0; + + aim_tx_enqueue(sess, &tx); + + return 0; +} + + +/* + * Send service redirect. (Non-Client) + */ +unsigned long aim_sendredirect(struct aim_session_t *sess, + struct aim_conn_t *conn, + unsigned short servid, + char *ip, + char *cookie) +{ + struct command_tx_struct tx; + struct aim_tlvlist_t *tlvlist = NULL; + int i = 0; + + tx.conn = conn; + + tx.commandlen = 1152; /* arbitrarily large */ + tx.data = malloc(tx.commandlen); + memset(tx.data, 0x00, tx.commandlen); + + tx.lock = 1; + tx.type = 0x02; + + i += aimutil_put16(tx.data+i, 0x0001); + i += aimutil_put16(tx.data+i, 0x0005); + i += aimutil_put16(tx.data+i, 0x0000); + i += aimutil_put16(tx.data+i, 0x0000); + i += aimutil_put16(tx.data+i, 0x0000); + + aim_addtlvtochain16(&tlvlist, 0x000d, servid); + aim_addtlvtochain_str(&tlvlist, 0x0005, ip, strlen(ip)); + aim_addtlvtochain_str(&tlvlist, 0x0006, cookie, AIM_COOKIELEN); + + tx.commandlen = aim_writetlvchain(tx.data+i, tx.commandlen-i, &tlvlist)+i; + aim_freetlvchain(&tlvlist); + + tx.lock = 0; + aim_tx_enqueue(sess, &tx); + + return 0; +} diff --git a/aim_tlv.c b/aim_tlv.c index 06f1f7a..42d3602 100644 --- a/aim_tlv.c +++ b/aim_tlv.c @@ -67,7 +67,21 @@ void aim_freetlvchain(struct aim_tlvlist_t **list) return; } -int aim_addtlvtochain_str(struct aim_tlvlist_t **list, unsigned short type, char *str) +int aim_counttlvchain(struct aim_tlvlist_t **list) +{ + struct aim_tlvlist_t *cur; + int count = 0; + + if (!list || !(*list)) + return 0; + + for (cur = *list; cur; cur = cur->next) + count++; + + return count; +} + +int aim_addtlvtochain_str(struct aim_tlvlist_t **list, unsigned short type, char *str, int len) { struct aim_tlvlist_t *new; struct aim_tlvlist_t *cur; @@ -80,7 +94,7 @@ int aim_addtlvtochain_str(struct aim_tlvlist_t **list, unsigned short type, char new->tlv = aim_createtlv(); new->tlv->type = type; - new->tlv->length = strlen(str); + new->tlv->length = len; new->tlv->value = (u_char *)malloc(new->tlv->length*sizeof(u_char)); memcpy(new->tlv->value, str, new->tlv->length); diff --git a/aim_util.c b/aim_util.c index f7cb012..0fa8427 100644 --- a/aim_util.c +++ b/aim_util.c @@ -5,6 +5,7 @@ */ #include +#include int aimutil_put8(u_char *buf, u_char data) { @@ -155,3 +156,73 @@ char *aimutil_itemidx(char *toSearch, int index, char dl) } return toReturn; } + +/* + * int snlen(const char *) + * + * This takes a screen name and returns its length without + * spaces. If there are no spaces in the SN, then the + * return is equal to that of strlen(). + * + */ +int aim_snlen(const char *sn) +{ + int i = 0; + const char *curPtr = NULL; + + if (!sn) + return 0; + + curPtr = sn; + while ( (*curPtr) != (char) NULL) + { + if ((*curPtr) != ' ') + i++; + curPtr++; + } + + return i; +} + +/* + * int sncmp(const char *, const char *) + * + * This takes two screen names and compares them using the rules + * on screen names for AIM/AOL. Mainly, this means case and space + * insensitivity (all case differences and spacing differences are + * ignored). + * + * Return: 0 if equal + * non-0 if different + * + */ + +int aim_sncmp(const char *sn1, const char *sn2) +{ + const char *curPtr1 = NULL, *curPtr2 = NULL; + + if (aim_snlen(sn1) != aim_snlen(sn2)) + return 1; + + curPtr1 = sn1; + curPtr2 = sn2; + while ( (*curPtr1 != (char) NULL) && (*curPtr2 != (char) NULL) ) + { + if ( (*curPtr1 == ' ') || (*curPtr2 == ' ') ) + { + if (*curPtr1 == ' ') + curPtr1++; + if (*curPtr2 == ' ') + curPtr2++; + } + else + { + if ( toupper(*curPtr1) != toupper(*curPtr2)) + return 1; + curPtr1++; + curPtr2++; + } + } + + return 0; +} diff --git a/faim/aim.h b/faim/aim.h index 96b2059..f67bbb8 100644 --- a/faim/aim.h +++ b/faim/aim.h @@ -254,7 +254,9 @@ int aim_puttlv_32(u_char *, u_short, u_long); int aim_puttlv_str(u_char *buf, u_short t, u_short l, u_char *v); int aim_writetlvchain(u_char *buf, int buflen, struct aim_tlvlist_t **list); int aim_addtlvtochain16(struct aim_tlvlist_t **list, unsigned short type, unsigned short val); -int aim_addtlvtochain_str(struct aim_tlvlist_t **list, unsigned short type, char *str); +int aim_addtlvtochain32(struct aim_tlvlist_t **list, unsigned short type, unsigned long val); +int aim_addtlvtochain_str(struct aim_tlvlist_t **list, unsigned short type, char *str, int len); +int aim_counttlvchain(struct aim_tlvlist_t **list); /* * Get command from connections / Dispatch commands @@ -278,8 +280,18 @@ int aim_sendconnack(struct aim_session_t *sess, struct aim_conn_t *conn); int aim_request_login (struct aim_session_t *sess, struct aim_conn_t *conn, char *sn); int aim_send_login (struct aim_session_t *, struct aim_conn_t *, char *, char *, struct client_info_s *); int aim_encode_password(const char *, u_char *); - - +unsigned long aim_sendauthresp(struct aim_session_t *sess, + struct aim_conn_t *conn, + char *sn, char *bosip, + char *cookie, char *email, + int regstatus); +int aim_gencookie(unsigned char *buf); +int aim_sendserverready(struct aim_session_t *sess, struct aim_conn_t *conn); +unsigned long aim_sendredirect(struct aim_session_t *sess, + struct aim_conn_t *conn, + unsigned short servid, + char *ip, + char *cookie); void aim_purge_rxqueue(struct aim_session_t *); @@ -445,5 +457,8 @@ int aimutil_tokslen(char *toSearch, int index, char dl); int aimutil_itemcnt(char *toSearch, char dl); char *aimutil_itemidx(char *toSearch, int index, char dl); +int aim_snlen(const char *sn); +int aim_sncmp(const char *sn1, const char *sn2); + #endif /* __AIM_H__ */ -- 2.45.2