1 | #include <aim.h> |
---|
2 | #include "admin.h" |
---|
3 | |
---|
4 | /* called for both reply and change-reply */ |
---|
5 | static int infochange(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
6 | { |
---|
7 | |
---|
8 | /* |
---|
9 | * struct { |
---|
10 | * guint16 perms; |
---|
11 | * guint16 tlvcount; |
---|
12 | * aim_tlv_t tlvs[tlvcount]; |
---|
13 | * } admin_info[n]; |
---|
14 | */ |
---|
15 | while (aim_bstream_empty(bs)) { |
---|
16 | guint16 perms, tlvcount; |
---|
17 | |
---|
18 | perms = aimbs_get16(bs); |
---|
19 | tlvcount = aimbs_get16(bs); |
---|
20 | |
---|
21 | while (tlvcount && aim_bstream_empty(bs)) { |
---|
22 | aim_rxcallback_t userfunc; |
---|
23 | guint16 type, len; |
---|
24 | guint8 *val; |
---|
25 | int str = 0; |
---|
26 | |
---|
27 | type = aimbs_get16(bs); |
---|
28 | len = aimbs_get16(bs); |
---|
29 | |
---|
30 | if ((type == 0x0011) || (type == 0x0004)) { |
---|
31 | str = 1; |
---|
32 | } |
---|
33 | |
---|
34 | if (str) { |
---|
35 | val = (guint8 *) aimbs_getstr(bs, len); |
---|
36 | } else { |
---|
37 | val = aimbs_getraw(bs, len); |
---|
38 | } |
---|
39 | |
---|
40 | /* XXX fix so its only called once for the entire packet */ |
---|
41 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) { |
---|
42 | userfunc(sess, rx, (snac->subtype == 0x0005) ? 1 : 0, perms, type, len, val, str); |
---|
43 | } |
---|
44 | |
---|
45 | g_free(val); |
---|
46 | |
---|
47 | tlvcount--; |
---|
48 | } |
---|
49 | } |
---|
50 | |
---|
51 | return 1; |
---|
52 | } |
---|
53 | |
---|
54 | static int accountconfirm(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, |
---|
55 | aim_bstream_t *bs) |
---|
56 | { |
---|
57 | aim_rxcallback_t userfunc; |
---|
58 | guint16 status; |
---|
59 | |
---|
60 | status = aimbs_get16(bs); |
---|
61 | |
---|
62 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) { |
---|
63 | return userfunc(sess, rx, status); |
---|
64 | } |
---|
65 | |
---|
66 | return 0; |
---|
67 | } |
---|
68 | |
---|
69 | static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
70 | { |
---|
71 | |
---|
72 | if ((snac->subtype == 0x0003) || (snac->subtype == 0x0005)) { |
---|
73 | return infochange(sess, mod, rx, snac, bs); |
---|
74 | } else if (snac->subtype == 0x0007) { |
---|
75 | return accountconfirm(sess, mod, rx, snac, bs); |
---|
76 | } |
---|
77 | |
---|
78 | return 0; |
---|
79 | } |
---|
80 | |
---|
81 | int admin_modfirst(aim_session_t *sess, aim_module_t *mod) |
---|
82 | { |
---|
83 | |
---|
84 | mod->family = AIM_CB_FAM_ADM; |
---|
85 | mod->version = 0x0001; |
---|
86 | mod->toolid = AIM_TOOL_NEWWIN; |
---|
87 | mod->toolversion = 0x0629; |
---|
88 | mod->flags = 0; |
---|
89 | strncpy(mod->name, "admin", sizeof(mod->name)); |
---|
90 | mod->snachandler = snachandler; |
---|
91 | |
---|
92 | return 0; |
---|
93 | } |
---|
94 | |
---|
95 | int aim_admin_changepasswd(aim_session_t *sess, aim_conn_t *conn, const char *newpw, const char *curpw) |
---|
96 | { |
---|
97 | aim_frame_t *tx; |
---|
98 | aim_tlvlist_t *tl = NULL; |
---|
99 | aim_snacid_t snacid; |
---|
100 | |
---|
101 | if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + strlen(curpw) + 4 + strlen(newpw)))) { |
---|
102 | return -ENOMEM; |
---|
103 | } |
---|
104 | |
---|
105 | snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0); |
---|
106 | aim_putsnac(&tx->data, 0x0007, 0x0004, 0x0000, snacid); |
---|
107 | |
---|
108 | /* new password TLV t(0002) */ |
---|
109 | aim_addtlvtochain_raw(&tl, 0x0002, strlen(newpw), (guint8 *) newpw); |
---|
110 | |
---|
111 | /* current password TLV t(0012) */ |
---|
112 | aim_addtlvtochain_raw(&tl, 0x0012, strlen(curpw), (guint8 *) curpw); |
---|
113 | |
---|
114 | aim_writetlvchain(&tx->data, &tl); |
---|
115 | aim_freetlvchain(&tl); |
---|
116 | |
---|
117 | aim_tx_enqueue(sess, tx); |
---|
118 | |
---|
119 | return 0; |
---|
120 | } |
---|
121 | |
---|
122 | /* |
---|
123 | * Request account confirmation. |
---|
124 | * |
---|
125 | * This will cause an email to be sent to the address associated with |
---|
126 | * the account. By following the instructions in the mail, you can |
---|
127 | * get the TRIAL flag removed from your account. |
---|
128 | * |
---|
129 | */ |
---|
130 | int aim_admin_reqconfirm(aim_session_t *sess, aim_conn_t *conn) |
---|
131 | { |
---|
132 | return aim_genericreq_n(sess, conn, 0x0007, 0x0006); |
---|
133 | } |
---|
134 | |
---|
135 | /* |
---|
136 | * Request a bit of account info. |
---|
137 | * |
---|
138 | * The only known valid tag is 0x0011 (email address). |
---|
139 | * |
---|
140 | */ |
---|
141 | int aim_admin_getinfo(aim_session_t *sess, aim_conn_t *conn, guint16 info) |
---|
142 | { |
---|
143 | aim_frame_t *tx; |
---|
144 | aim_snacid_t snacid; |
---|
145 | |
---|
146 | if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 14))) { |
---|
147 | return -ENOMEM; |
---|
148 | } |
---|
149 | |
---|
150 | snacid = aim_cachesnac(sess, 0x0002, 0x0002, 0x0000, NULL, 0); |
---|
151 | aim_putsnac(&tx->data, 0x0007, 0x0002, 0x0000, snacid); |
---|
152 | |
---|
153 | aimbs_put16(&tx->data, info); |
---|
154 | aimbs_put16(&tx->data, 0x0000); |
---|
155 | |
---|
156 | aim_tx_enqueue(sess, tx); |
---|
157 | |
---|
158 | return 0; |
---|
159 | } |
---|
160 | |
---|
161 | int aim_admin_setemail(aim_session_t *sess, aim_conn_t *conn, const char *newemail) |
---|
162 | { |
---|
163 | aim_frame_t *tx; |
---|
164 | aim_snacid_t snacid; |
---|
165 | aim_tlvlist_t *tl = NULL; |
---|
166 | |
---|
167 | if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 2 + 2 + strlen(newemail)))) { |
---|
168 | return -ENOMEM; |
---|
169 | } |
---|
170 | |
---|
171 | snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0); |
---|
172 | aim_putsnac(&tx->data, 0x0007, 0x0004, 0x0000, snacid); |
---|
173 | |
---|
174 | aim_addtlvtochain_raw(&tl, 0x0011, strlen(newemail), (guint8 *) newemail); |
---|
175 | |
---|
176 | aim_writetlvchain(&tx->data, &tl); |
---|
177 | aim_freetlvchain(&tl); |
---|
178 | |
---|
179 | aim_tx_enqueue(sess, tx); |
---|
180 | |
---|
181 | return 0; |
---|
182 | } |
---|
183 | |
---|
184 | int aim_admin_setnick(aim_session_t *sess, aim_conn_t *conn, const char *newnick) |
---|
185 | { |
---|
186 | aim_frame_t *tx; |
---|
187 | aim_snacid_t snacid; |
---|
188 | aim_tlvlist_t *tl = NULL; |
---|
189 | |
---|
190 | if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 2 + 2 + strlen(newnick)))) { |
---|
191 | return -ENOMEM; |
---|
192 | } |
---|
193 | |
---|
194 | snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0); |
---|
195 | aim_putsnac(&tx->data, 0x0007, 0x0004, 0x0000, snacid); |
---|
196 | |
---|
197 | aim_addtlvtochain_raw(&tl, 0x0001, strlen(newnick), (guint8 *) newnick); |
---|
198 | |
---|
199 | aim_writetlvchain(&tx->data, &tl); |
---|
200 | aim_freetlvchain(&tl); |
---|
201 | |
---|
202 | aim_tx_enqueue(sess, tx); |
---|
203 | |
---|
204 | |
---|
205 | return 0; |
---|
206 | } |
---|