]> andersk Git - libfaim.git/blob - aim_login.c
Added src/dest listing.
[libfaim.git] / aim_login.c
1 /*
2  *  aim_login.c
3  *
4  *  This contains all the functions needed to actually login.
5  *
6  */
7
8 #include <faim/aim.h>
9
10
11 /*
12  * FIXME: Reimplement the TIS stuff.
13  */
14 #ifdef TIS_TELNET_PROXY
15 #include "tis_telnet_proxy.h"
16 #endif
17
18 /*
19  * send_login(int socket, char *sn, char *password)
20  *  
21  * This is the initial login request packet.
22  *
23  * The password is encoded before transmition, as per
24  * encode_password().  See that function for their
25  * stupid method of doing it.
26  *
27  */
28 int aim_send_login (struct aim_session_t *sess,
29                     struct aim_conn_t *conn, 
30                     char *sn, char *password, struct client_info_s *clientinfo)
31 {
32   u_char *password_encoded = NULL;  /* to store encoded password */
33   int curbyte=0;
34
35   struct command_tx_struct newpacket;
36
37   if (conn)
38     newpacket.conn = conn;
39   else
40     newpacket.conn = aim_getconn_type(sess, AIM_CONN_TYPE_AUTH);
41
42   newpacket.commandlen = 4 + 4+strlen(sn) + 4+strlen(password) + 6;
43  
44   if (clientinfo)
45     {
46       if (strlen(clientinfo->clientstring))
47         newpacket.commandlen += 4+strlen(clientinfo->clientstring);
48       newpacket.commandlen += 6+6+6;
49       if (strlen(clientinfo->country))
50         newpacket.commandlen += 4+strlen(clientinfo->country);
51       if (strlen(clientinfo->lang))
52         newpacket.commandlen += 4+strlen(clientinfo->lang);
53     }
54   newpacket.commandlen += 6;
55
56   newpacket.data = (char *) calloc (1,  newpacket.commandlen );
57   newpacket.lock = 1;
58   newpacket.type = 0x01;
59
60   curbyte += aimutil_put16(newpacket.data+curbyte, 0x0000);
61   curbyte += aimutil_put16(newpacket.data+curbyte, 0x0001);
62   curbyte += aimutil_put16(newpacket.data+curbyte, 0x0001);
63   curbyte += aimutil_put16(newpacket.data+curbyte, strlen(sn));
64   curbyte += aimutil_putstr(newpacket.data+curbyte, sn, strlen(sn));
65
66   curbyte += aimutil_put16(newpacket.data+curbyte, 0x0002);
67   curbyte += aimutil_put16(newpacket.data+curbyte, strlen(password));
68   password_encoded = (char *) malloc(strlen(password));
69   aim_encode_password(password, password_encoded);
70   curbyte += aimutil_putstr(newpacket.data+curbyte, password_encoded, strlen(password));
71   free(password_encoded);
72   
73   curbyte += aim_puttlv_16(newpacket.data+curbyte, 0x0016, 0x0001);
74   
75   if (clientinfo)
76     {
77       if (strlen(clientinfo->clientstring))
78         {
79           curbyte += aimutil_put16(newpacket.data+curbyte, 0x0003);
80           curbyte += aimutil_put16(newpacket.data+curbyte, strlen(clientinfo->clientstring));
81           curbyte += aimutil_putstr(newpacket.data+curbyte, clientinfo->clientstring, strlen(clientinfo->clientstring));
82         }
83       curbyte += aim_puttlv_16(newpacket.data+curbyte, 0x0017, 0x0001);
84       curbyte += aim_puttlv_16(newpacket.data+curbyte, 0x0018, 0x0001);
85       curbyte += aim_puttlv_16(newpacket.data+curbyte, 0x001a, 0x0013);
86       if (strlen(clientinfo->country))
87         {
88           curbyte += aimutil_put16(newpacket.data+curbyte, 0x000e);
89           curbyte += aimutil_put16(newpacket.data+curbyte, strlen(clientinfo->country));
90           curbyte += aimutil_putstr(newpacket.data+curbyte, clientinfo->country, strlen(clientinfo->country));
91         }
92       if (strlen(clientinfo->lang))
93         {
94           curbyte += aimutil_put16(newpacket.data+curbyte, 0x000f);
95           curbyte += aimutil_put16(newpacket.data+curbyte, strlen(clientinfo->lang));
96           curbyte += aimutil_putstr(newpacket.data+curbyte, clientinfo->lang, strlen(clientinfo->lang));
97         }
98     }
99
100   curbyte += aim_puttlv_16(newpacket.data+curbyte, 0x0009, 0x0015);
101
102   newpacket.lock = 0;
103   aim_tx_enqueue(sess, &newpacket);
104
105   return 0;
106 }
107
108 /*
109  *  int encode_password(
110  *                      const char *password,
111  *                      char *encoded
112  *                      ); 
113  *
114  * This takes a const pointer to a (null terminated) string
115  * containing the unencoded password.  It also gets passed
116  * an already allocated buffer to store the encoded password.
117  * This buffer should be the exact length of the password without
118  * the null.  The encoded password buffer IS NOT NULL TERMINATED.
119  *
120  * The encoding_table seems to be a fixed set of values.  We'll
121  * hope it doesn't change over time!  
122  *
123  */
124 int aim_encode_password(const char *password, u_char *encoded)
125 {
126   u_char encoding_table[] = {
127     0xf3, 0xb3, 0x6c, 0x99,
128     0x95, 0x3f, 0xac, 0xb6,
129     0xc5, 0xfa, 0x6b, 0x63,
130     0x69, 0x6c, 0xc3, 0x9f
131   };
132
133   int i;
134   
135   for (i = 0; i < strlen(password); i++)
136       encoded[i] = (password[i] ^ encoding_table[i]);
137
138   return 0;
139 }
140
141
142
143
This page took 0.076714 seconds and 5 git commands to generate.