[862371b] | 1 | /* |
---|
| 2 | * Family 0x0007 - Account Administration. |
---|
| 3 | * |
---|
| 4 | * Used for stuff like changing the formating of your screen name, changing your |
---|
| 5 | * email address, requesting an account confirmation email, getting account info, |
---|
[e374dee] | 6 | * |
---|
[862371b] | 7 | */ |
---|
[5e53c4a] | 8 | |
---|
| 9 | #define FAIM_INTERNAL |
---|
| 10 | #include <aim.h> |
---|
| 11 | |
---|
[862371b] | 12 | /* |
---|
| 13 | * Subtype 0x0002 - Request a bit of account info. |
---|
| 14 | * |
---|
| 15 | * Info should be one of the following: |
---|
| 16 | * 0x0001 - Screen name formatting |
---|
| 17 | * 0x0011 - Email address |
---|
| 18 | * 0x0013 - Unknown |
---|
| 19 | * |
---|
| 20 | */ |
---|
| 21 | faim_export int aim_admin_getinfo(aim_session_t *sess, aim_conn_t *conn, fu16_t info) |
---|
[5e53c4a] | 22 | { |
---|
[862371b] | 23 | aim_frame_t *fr; |
---|
| 24 | aim_snacid_t snacid; |
---|
[5e53c4a] | 25 | |
---|
[862371b] | 26 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 14))) |
---|
| 27 | return -ENOMEM; |
---|
[5e53c4a] | 28 | |
---|
[862371b] | 29 | snacid = aim_cachesnac(sess, 0x0007, 0x0002, 0x0000, NULL, 0); |
---|
| 30 | aim_putsnac(&fr->data, 0x0007, 0x0002, 0x0000, snacid); |
---|
[5e53c4a] | 31 | |
---|
[862371b] | 32 | aimbs_put16(&fr->data, info); |
---|
| 33 | aimbs_put16(&fr->data, 0x0000); |
---|
[5e53c4a] | 34 | |
---|
[862371b] | 35 | aim_tx_enqueue(sess, fr); |
---|
[5e53c4a] | 36 | |
---|
[862371b] | 37 | return 0; |
---|
[5e53c4a] | 38 | } |
---|
| 39 | |
---|
[862371b] | 40 | /* |
---|
| 41 | * Subtypes 0x0003 and 0x0005 - Parse account info. |
---|
| 42 | * |
---|
| 43 | * Called in reply to both an information request (subtype 0x0002) and |
---|
| 44 | * an information change (subtype 0x0004). |
---|
| 45 | * |
---|
| 46 | */ |
---|
| 47 | static int infochange(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
[5e53c4a] | 48 | { |
---|
| 49 | aim_rxcallback_t userfunc; |
---|
[862371b] | 50 | char *url=NULL, *sn=NULL, *email=NULL; |
---|
| 51 | fu16_t perms, tlvcount, err=0; |
---|
| 52 | |
---|
| 53 | perms = aimbs_get16(bs); |
---|
| 54 | tlvcount = aimbs_get16(bs); |
---|
| 55 | |
---|
| 56 | while (tlvcount && aim_bstream_empty(bs)) { |
---|
| 57 | fu16_t type, length; |
---|
| 58 | |
---|
| 59 | type = aimbs_get16(bs); |
---|
| 60 | length = aimbs_get16(bs); |
---|
| 61 | |
---|
| 62 | switch (type) { |
---|
| 63 | case 0x0001: { |
---|
| 64 | sn = aimbs_getstr(bs, length); |
---|
| 65 | } break; |
---|
| 66 | |
---|
| 67 | case 0x0004: { |
---|
| 68 | url = aimbs_getstr(bs, length); |
---|
| 69 | } break; |
---|
| 70 | |
---|
| 71 | case 0x0008: { |
---|
| 72 | err = aimbs_get16(bs); |
---|
| 73 | } break; |
---|
| 74 | |
---|
| 75 | case 0x0011: { |
---|
| 76 | if (length == 0) { |
---|
| 77 | email = (char*)malloc(13*sizeof(char)); |
---|
| 78 | strcpy(email, "*suppressed*"); |
---|
| 79 | } else |
---|
| 80 | email = aimbs_getstr(bs, length); |
---|
| 81 | } break; |
---|
| 82 | } |
---|
[5e53c4a] | 83 | |
---|
[862371b] | 84 | tlvcount--; |
---|
| 85 | } |
---|
[5e53c4a] | 86 | |
---|
| 87 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
---|
[862371b] | 88 | userfunc(sess, rx, (snac->subtype == 0x0005) ? 1 : 0, perms, err, url, sn, email); |
---|
[5e53c4a] | 89 | |
---|
[862371b] | 90 | if (sn) free(sn); |
---|
| 91 | if (url) free(url); |
---|
| 92 | if (email) free(email); |
---|
| 93 | |
---|
| 94 | return 1; |
---|
[5e53c4a] | 95 | } |
---|
| 96 | |
---|
[862371b] | 97 | /* |
---|
| 98 | * Subtype 0x0004 - Set screenname formatting. |
---|
| 99 | * |
---|
| 100 | */ |
---|
| 101 | faim_export int aim_admin_setnick(aim_session_t *sess, aim_conn_t *conn, const char *newnick) |
---|
[5e53c4a] | 102 | { |
---|
[862371b] | 103 | aim_frame_t *fr; |
---|
| 104 | aim_snacid_t snacid; |
---|
| 105 | aim_tlvlist_t *tl = NULL; |
---|
[5e53c4a] | 106 | |
---|
[862371b] | 107 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+2+strlen(newnick)))) |
---|
| 108 | return -ENOMEM; |
---|
[5e53c4a] | 109 | |
---|
[862371b] | 110 | snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0); |
---|
| 111 | aim_putsnac(&fr->data, 0x0007, 0x0004, 0x0000, snacid); |
---|
[5e53c4a] | 112 | |
---|
[cf02dd6] | 113 | aim_tlvlist_add_raw(&tl, 0x0001, strlen(newnick), newnick); |
---|
[862371b] | 114 | |
---|
[cf02dd6] | 115 | aim_tlvlist_write(&fr->data, &tl); |
---|
| 116 | aim_tlvlist_free(&tl); |
---|
[862371b] | 117 | |
---|
| 118 | aim_tx_enqueue(sess, fr); |
---|
[5e53c4a] | 119 | |
---|
| 120 | |
---|
| 121 | return 0; |
---|
| 122 | } |
---|
| 123 | |
---|
[862371b] | 124 | /* |
---|
| 125 | * Subtype 0x0004 - Change password. |
---|
| 126 | * |
---|
| 127 | */ |
---|
[5e53c4a] | 128 | faim_export int aim_admin_changepasswd(aim_session_t *sess, aim_conn_t *conn, const char *newpw, const char *curpw) |
---|
| 129 | { |
---|
[862371b] | 130 | aim_frame_t *fr; |
---|
[5e53c4a] | 131 | aim_tlvlist_t *tl = NULL; |
---|
| 132 | aim_snacid_t snacid; |
---|
| 133 | |
---|
[862371b] | 134 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+4+strlen(curpw)+4+strlen(newpw)))) |
---|
[5e53c4a] | 135 | return -ENOMEM; |
---|
| 136 | |
---|
| 137 | snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0); |
---|
[862371b] | 138 | aim_putsnac(&fr->data, 0x0007, 0x0004, 0x0000, snacid); |
---|
[5e53c4a] | 139 | |
---|
| 140 | /* new password TLV t(0002) */ |
---|
[cf02dd6] | 141 | aim_tlvlist_add_raw(&tl, 0x0002, strlen(newpw), newpw); |
---|
[5e53c4a] | 142 | |
---|
| 143 | /* current password TLV t(0012) */ |
---|
[cf02dd6] | 144 | aim_tlvlist_add_raw(&tl, 0x0012, strlen(curpw), curpw); |
---|
[5e53c4a] | 145 | |
---|
[cf02dd6] | 146 | aim_tlvlist_write(&fr->data, &tl); |
---|
| 147 | aim_tlvlist_free(&tl); |
---|
[5e53c4a] | 148 | |
---|
[862371b] | 149 | aim_tx_enqueue(sess, fr); |
---|
| 150 | |
---|
| 151 | return 0; |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | /* |
---|
| 155 | * Subtype 0x0004 - Change email address. |
---|
| 156 | * |
---|
| 157 | */ |
---|
| 158 | faim_export int aim_admin_setemail(aim_session_t *sess, aim_conn_t *conn, const char *newemail) |
---|
| 159 | { |
---|
| 160 | aim_frame_t *fr; |
---|
| 161 | aim_snacid_t snacid; |
---|
| 162 | aim_tlvlist_t *tl = NULL; |
---|
| 163 | |
---|
| 164 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+2+strlen(newemail)))) |
---|
| 165 | return -ENOMEM; |
---|
| 166 | |
---|
| 167 | snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0); |
---|
| 168 | aim_putsnac(&fr->data, 0x0007, 0x0004, 0x0000, snacid); |
---|
| 169 | |
---|
[cf02dd6] | 170 | aim_tlvlist_add_raw(&tl, 0x0011, strlen(newemail), newemail); |
---|
[862371b] | 171 | |
---|
[cf02dd6] | 172 | aim_tlvlist_write(&fr->data, &tl); |
---|
| 173 | aim_tlvlist_free(&tl); |
---|
[862371b] | 174 | |
---|
| 175 | aim_tx_enqueue(sess, fr); |
---|
[5e53c4a] | 176 | |
---|
| 177 | return 0; |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | /* |
---|
[862371b] | 181 | * Subtype 0x0006 - Request account confirmation. |
---|
[5e53c4a] | 182 | * |
---|
| 183 | * This will cause an email to be sent to the address associated with |
---|
| 184 | * the account. By following the instructions in the mail, you can |
---|
| 185 | * get the TRIAL flag removed from your account. |
---|
| 186 | * |
---|
| 187 | */ |
---|
| 188 | faim_export int aim_admin_reqconfirm(aim_session_t *sess, aim_conn_t *conn) |
---|
| 189 | { |
---|
| 190 | return aim_genericreq_n(sess, conn, 0x0007, 0x0006); |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | /* |
---|
[862371b] | 194 | * Subtype 0x0007 - Account confirmation request acknowledgement. |
---|
[5e53c4a] | 195 | * |
---|
[862371b] | 196 | */ |
---|
| 197 | static int accountconfirm(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
[5e53c4a] | 198 | { |
---|
[e374dee] | 199 | int ret = 0; |
---|
[862371b] | 200 | aim_rxcallback_t userfunc; |
---|
| 201 | fu16_t status; |
---|
| 202 | aim_tlvlist_t *tl; |
---|
[5e53c4a] | 203 | |
---|
[862371b] | 204 | status = aimbs_get16(bs); |
---|
| 205 | /* This is 0x0013 if unable to confirm at this time */ |
---|
[5e53c4a] | 206 | |
---|
[cf02dd6] | 207 | tl = aim_tlvlist_read(bs); |
---|
[5e53c4a] | 208 | |
---|
[862371b] | 209 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
---|
[e374dee] | 210 | ret = userfunc(sess, rx, status); |
---|
[5e53c4a] | 211 | |
---|
[e374dee] | 212 | return ret; |
---|
[5e53c4a] | 213 | } |
---|
| 214 | |
---|
[862371b] | 215 | static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
[5e53c4a] | 216 | { |
---|
| 217 | |
---|
[862371b] | 218 | if ((snac->subtype == 0x0003) || (snac->subtype == 0x0005)) |
---|
| 219 | return infochange(sess, mod, rx, snac, bs); |
---|
| 220 | else if (snac->subtype == 0x0007) |
---|
| 221 | return accountconfirm(sess, mod, rx, snac, bs); |
---|
[5e53c4a] | 222 | |
---|
| 223 | return 0; |
---|
| 224 | } |
---|
| 225 | |
---|
[862371b] | 226 | faim_internal int admin_modfirst(aim_session_t *sess, aim_module_t *mod) |
---|
[5e53c4a] | 227 | { |
---|
| 228 | |
---|
[862371b] | 229 | mod->family = 0x0007; |
---|
| 230 | mod->version = 0x0001; |
---|
[e374dee] | 231 | mod->toolid = 0x0010; |
---|
| 232 | mod->toolversion = 0x0629; |
---|
[862371b] | 233 | mod->flags = 0; |
---|
| 234 | strncpy(mod->name, "admin", sizeof(mod->name)); |
---|
| 235 | mod->snachandler = snachandler; |
---|
[5e53c4a] | 236 | |
---|
| 237 | return 0; |
---|
| 238 | } |
---|