[b7d3cc34] | 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 | |
---|
[5ebff60] | 30 | if ((type == 0x0011) || (type == 0x0004)) { |
---|
[b7d3cc34] | 31 | str = 1; |
---|
[5ebff60] | 32 | } |
---|
[b7d3cc34] | 33 | |
---|
[5ebff60] | 34 | if (str) { |
---|
| 35 | val = (guint8 *) aimbs_getstr(bs, len); |
---|
| 36 | } else { |
---|
[b7d3cc34] | 37 | val = aimbs_getraw(bs, len); |
---|
[5ebff60] | 38 | } |
---|
[b7d3cc34] | 39 | |
---|
| 40 | /* XXX fix so its only called once for the entire packet */ |
---|
[5ebff60] | 41 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) { |
---|
[b7d3cc34] | 42 | userfunc(sess, rx, (snac->subtype == 0x0005) ? 1 : 0, perms, type, len, val, str); |
---|
[5ebff60] | 43 | } |
---|
[b7d3cc34] | 44 | |
---|
| 45 | g_free(val); |
---|
| 46 | |
---|
| 47 | tlvcount--; |
---|
| 48 | } |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | return 1; |
---|
| 52 | } |
---|
| 53 | |
---|
[5ebff60] | 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) |
---|
[b7d3cc34] | 56 | { |
---|
| 57 | aim_rxcallback_t userfunc; |
---|
| 58 | guint16 status; |
---|
| 59 | |
---|
| 60 | status = aimbs_get16(bs); |
---|
| 61 | |
---|
[5ebff60] | 62 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) { |
---|
[b7d3cc34] | 63 | return userfunc(sess, rx, status); |
---|
[5ebff60] | 64 | } |
---|
[b7d3cc34] | 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 | |
---|
[5ebff60] | 72 | if ((snac->subtype == 0x0003) || (snac->subtype == 0x0005)) { |
---|
[b7d3cc34] | 73 | return infochange(sess, mod, rx, snac, bs); |
---|
[5ebff60] | 74 | } else if (snac->subtype == 0x0007) { |
---|
[b7d3cc34] | 75 | return accountconfirm(sess, mod, rx, snac, bs); |
---|
[5ebff60] | 76 | } |
---|
[b7d3cc34] | 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; |
---|
[5ebff60] | 87 | mod->toolversion = 0x0629; |
---|
[b7d3cc34] | 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 | |
---|
[5ebff60] | 101 | if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + strlen(curpw) + 4 + strlen(newpw)))) { |
---|
[b7d3cc34] | 102 | return -ENOMEM; |
---|
[5ebff60] | 103 | } |
---|
[b7d3cc34] | 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) */ |
---|
[5ebff60] | 109 | aim_addtlvtochain_raw(&tl, 0x0002, strlen(newpw), (guint8 *) newpw); |
---|
[b7d3cc34] | 110 | |
---|
| 111 | /* current password TLV t(0012) */ |
---|
[5ebff60] | 112 | aim_addtlvtochain_raw(&tl, 0x0012, strlen(curpw), (guint8 *) curpw); |
---|
[b7d3cc34] | 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 | /* |
---|
[5ebff60] | 123 | * Request account confirmation. |
---|
[b7d3cc34] | 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 | * |
---|
[5ebff60] | 140 | */ |
---|
[b7d3cc34] | 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 | |
---|
[5ebff60] | 146 | if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 14))) { |
---|
[b7d3cc34] | 147 | return -ENOMEM; |
---|
[5ebff60] | 148 | } |
---|
[b7d3cc34] | 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 | |
---|
[5ebff60] | 167 | if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 2 + 2 + strlen(newemail)))) { |
---|
[b7d3cc34] | 168 | return -ENOMEM; |
---|
[5ebff60] | 169 | } |
---|
[b7d3cc34] | 170 | |
---|
| 171 | snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0); |
---|
| 172 | aim_putsnac(&tx->data, 0x0007, 0x0004, 0x0000, snacid); |
---|
| 173 | |
---|
[5ebff60] | 174 | aim_addtlvtochain_raw(&tl, 0x0011, strlen(newemail), (guint8 *) newemail); |
---|
| 175 | |
---|
[b7d3cc34] | 176 | aim_writetlvchain(&tx->data, &tl); |
---|
| 177 | aim_freetlvchain(&tl); |
---|
[5ebff60] | 178 | |
---|
[b7d3cc34] | 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 | |
---|
[5ebff60] | 190 | if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 2 + 2 + strlen(newnick)))) { |
---|
[b7d3cc34] | 191 | return -ENOMEM; |
---|
[5ebff60] | 192 | } |
---|
[b7d3cc34] | 193 | |
---|
| 194 | snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0); |
---|
| 195 | aim_putsnac(&tx->data, 0x0007, 0x0004, 0x0000, snacid); |
---|
| 196 | |
---|
[5ebff60] | 197 | aim_addtlvtochain_raw(&tl, 0x0001, strlen(newnick), (guint8 *) newnick); |
---|
| 198 | |
---|
[b7d3cc34] | 199 | aim_writetlvchain(&tx->data, &tl); |
---|
| 200 | aim_freetlvchain(&tl); |
---|
[5ebff60] | 201 | |
---|
[b7d3cc34] | 202 | aim_tx_enqueue(sess, tx); |
---|
| 203 | |
---|
| 204 | |
---|
| 205 | return 0; |
---|
| 206 | } |
---|