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