]>
Commit | Line | Data |
---|---|---|
1dd6d55d | 1 | /* Automatically generated by refactor.pl. |
1dd6d55d | 2 | * |
3 | * CMDNAME: email | |
bace4964 | 4 | * CMDLEVEL: QCMD_SECURE | QCMD_AUTHED |
1dd6d55d | 5 | * CMDARGS: 3 |
6 | * CMDDESC: Change your email address. | |
7 | * CMDFUNC: csa_doemail | |
8 | * CMDPROTO: int csa_doemail(void *source, int cargc, char **cargv); | |
50cd26d6 | 9 | * CMDHELP: Usage: EMAIL <password> <email> <email> |
10 | * CMDHELP: Changes your register email address. Confirmation of the change will be sent | |
11 | * CMDHELP: both old and new addresses. Where: | |
12 | * CMDHELP: password - your password | |
13 | * CMDHELP: email - new email address. Must be entered exactly the same way twice to avoid | |
14 | * CMDHELP: mistakes. | |
15 | * CMDHELP: Note: due to the sensitive nature of this command, you must send the message | |
16 | * CMDHELP: to Q@CServe.quakenet.org when using it. | |
1dd6d55d | 17 | */ |
18 | ||
19 | #include "../chanserv.h" | |
20 | #include "../authlib.h" | |
21 | #include "../../lib/irc_string.h" | |
22 | #include <stdio.h> | |
23 | #include <string.h> | |
24 | ||
25 | int csa_doemail(void *source, int cargc, char **cargv) { | |
96e1f81d | 26 | reguser *rup, *ruh; |
1dd6d55d | 27 | nick *sender=source; |
e3805f60 P |
28 | maildomain *mdp, *smdp; |
29 | char *local; | |
bbc9e3a6 | 30 | char *dupemail; |
96e1f81d | 31 | int found = 0; |
30a66d6c | 32 | time_t t = time(NULL); |
97390b65 | 33 | maillock *mlp; |
1dd6d55d | 34 | |
35 | if (cargc<3) { | |
36 | chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "email"); | |
37 | return CMD_ERROR; | |
38 | } | |
39 | ||
40 | if (!(rup=getreguserfromnick(sender))) | |
41 | return CMD_ERROR; | |
42 | ||
2271ea8c | 43 | if (!checkpassword(rup, cargv[0])) { |
1dd6d55d | 44 | chanservstdmessage(sender, QM_AUTHFAIL); |
2271ea8c | 45 | cs_log(sender,"EMAIL FAIL username %s bad password %s",rup->username,cargv[0]); |
1dd6d55d | 46 | return CMD_ERROR; |
47 | } | |
48 | ||
49 | if (strcmp(cargv[1],cargv[2])) { | |
50 | chanservstdmessage(sender, QM_EMAILDONTMATCH); | |
51 | cs_log(sender,"EMAIL FAIL username %s email don't match (%s vs %s)",rup->username,cargv[1],cargv[2]); | |
52 | return CMD_ERROR; | |
53 | } | |
54 | ||
372e4f1d | 55 | if(!UHasStaffPriv(rup) && (rup->lockuntil && rup->lockuntil > t)) { |
79313d98 | 56 | chanservstdmessage(sender, QM_ACCOUNTLOCKED, rup->lockuntil); |
30a66d6c CP |
57 | return CMD_ERROR; |
58 | } | |
59 | ||
e2792f61 CP |
60 | if(rup->email && !strcasecmp(cargv[1], rup->email->content)) { |
61 | chanservstdmessage(sender, QM_EMAILMATCHESOLD); | |
62 | return CMD_ERROR; | |
63 | } | |
64 | ||
1dd6d55d | 65 | if (csa_checkeboy(sender, cargv[1])) |
66 | return CMD_ERROR; | |
67 | ||
97390b65 CP |
68 | for(mlp=maillocks;mlp;mlp=mlp->next) { |
69 | if(!match(mlp->pattern->content, cargv[1])) { | |
70 | chanservstdmessage(sender, QM_MAILLOCKED); | |
71 | return CMD_ERROR; | |
72 | } | |
73 | } | |
74 | ||
96e1f81d CP |
75 | dupemail = strdup(cargv[1]); |
76 | local=strchr(dupemail, '@'); | |
a0ec3e1a CP |
77 | if(!local) { |
78 | free(dupemail); | |
96e1f81d | 79 | return CMD_ERROR; |
a0ec3e1a | 80 | } |
96e1f81d CP |
81 | *(local++)='\0'; |
82 | ||
83 | mdp=findnearestmaildomain(local); | |
84 | if(mdp) { | |
85 | for(smdp=mdp; smdp; smdp=smdp->parent) { | |
86 | if(MDIsBanned(smdp)) { | |
87 | free(dupemail); | |
e81781a3 | 88 | chanservstdmessage(sender, QM_MAILLOCKED); |
96e1f81d CP |
89 | return CMD_ERROR; |
90 | } | |
91 | if((smdp->count >= smdp->limit) && (smdp->limit > 0)) { | |
92 | free(dupemail); | |
93 | chanservstdmessage(sender, QM_DOMAINLIMIT); | |
94 | return CMD_ERROR; | |
95 | } | |
96 | } | |
97 | } | |
98 | ||
99 | mdp=findmaildomainbydomain(local); | |
100 | if(mdp) { | |
101 | for (ruh=mdp->users; ruh; ruh=ruh->nextbydomain) { | |
102 | if (ruh->localpart) | |
103 | if (!strcasecmp(dupemail, ruh->localpart->content)) { | |
104 | found++; | |
105 | } | |
106 | } | |
107 | ||
108 | if((found >= mdp->actlimit) && (mdp->actlimit > 0)) { | |
109 | free(dupemail); | |
110 | chanservstdmessage(sender, QM_ADDRESSLIMIT); | |
e3805f60 P |
111 | return CMD_ERROR; |
112 | } | |
113 | } | |
1dd6d55d | 114 | |
ea4a0a50 | 115 | (void) findorcreatemaildomain(cargv[1]); |
96e1f81d | 116 | |
1dd6d55d | 117 | csdb_createmail(rup, QMAIL_NEWEMAIL); |
0f32b411 | 118 | csdb_accounthistory_insert(sender, NULL, NULL, rup->email?rup->email->content:NULL, cargv[1]); |
e3805f60 | 119 | delreguserfrommaildomain(rup,rup->domain); |
30a66d6c CP |
120 | |
121 | if(rup->lastemail) | |
122 | freesstring(rup->lastemail); | |
123 | rup->lastemail=rup->email; | |
1dd6d55d | 124 | rup->email=getsstring(cargv[1],EMAILLEN); |
30a66d6c | 125 | rup->lastemailchange=t; |
e3805f60 | 126 | rup->domain=findorcreatemaildomain(rup->email->content); |
372e4f1d | 127 | if(!UHasStaffPriv(rup)) { |
59687380 | 128 | rup->lockuntil=t+7*24*3600; |
039e298c CP |
129 | } else { |
130 | rup->lockuntil=0; | |
131 | } | |
e3805f60 | 132 | addregusertomaildomain(rup, rup->domain); |
96e1f81d CP |
133 | |
134 | if(local) { | |
135 | rup->localpart=getsstring(dupemail,EMAILLEN); | |
e3805f60 P |
136 | } else { |
137 | rup->localpart=NULL; | |
138 | } | |
c7970ab7 P |
139 | free(dupemail); |
140 | ||
1dd6d55d | 141 | chanservstdmessage(sender, QM_EMAILCHANGED, cargv[1]); |
142 | cs_log(sender,"EMAIL OK username %s",rup->username); | |
e9f49ea9 CP |
143 | |
144 | #ifdef AUTHGATE_WARNINGS | |
c90a3f1f CP |
145 | if(UHasOperPriv(rup)) |
146 | chanservsendmessage(sender, "WARNING FOR PRIVILEGED USERS: you MUST go to https://auth.quakenet.org and login successfully to update the cache."); | |
e9f49ea9 CP |
147 | #endif |
148 | ||
1dd6d55d | 149 | csdb_updateuser(rup); |
150 | ||
151 | return CMD_OK; | |
152 | } |