]> jfr.im git - irc/quakenet/newserv.git/blame - chanserv/authcmds/hello.c
Add lastemail field.
[irc/quakenet/newserv.git] / chanserv / authcmds / hello.c
CommitLineData
1dd6d55d 1/* Automatically generated by refactor.pl.
2 *
3 *
4 * CMDNAME: hello
5 * CMDLEVEL: QCMD_NOTAUTHED
6 * CMDARGS: 2
7 * CMDDESC: Creates a new user account.
8 * CMDFUNC: csa_dohello
9 * CMDPROTO: int csa_dohello(void *source, int cargc, char **cargv);
50cd26d6 10 * CMDHELP: Usage: HELLO <email> <email>
11 * CMDHELP: Creates a new user account for yourself. Your current nickname will be used
12 * CMDHELP: for the name of the account, and may only contain letters, numbers and
13 * CMDHELP: hyphens (-). An email containing password details will be sent to the email
14 * CMDHELP: address supplied. Where:
15 * CMDHELP: email - your email address. Must be entered the same way both times.
1dd6d55d 16 */
17
18#include "../chanserv.h"
19#include "../authlib.h"
20#include "../../lib/irc_string.h"
21#include <stdio.h>
22#include <string.h>
23
24int csa_dohello(void *source, int cargc, char **cargv) {
25 nick *sender=source;
26 reguser *rup;
27 char userhost[USERLEN+HOSTLEN+2];
e3805f60
P
28 maildomain *mdp, *smdp;
29 char *local;
bbc9e3a6
P
30 reguser *ruh;
31 int found=0;
32 char *dupemail;
bd87ef68 33 activeuser *aup;
1dd6d55d 34
35 if (getreguserfromnick(sender))
36 return CMD_ERROR;
37
38 if (cargc<2) {
39 chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "hello");
40 return CMD_ERROR;
41 }
42
43 if (findreguserbynick(sender->nick)) {
44 chanservstdmessage(sender, QM_AUTHNAMEINUSE, sender->nick);
45 return CMD_ERROR;
46 }
47
bd87ef68
CP
48 if (!(aup = getactiveuserfromnick(sender)))
49 return CMD_ERROR;
50
51 if (aup->helloattempts > MAXHELLOS) {
52 chanservstdmessage(sender, QM_MAXHELLOLIMIT);
53 return CMD_ERROR;
54 }
55
1dd6d55d 56 if (strcmp(cargv[0],cargv[1])) {
57 chanservstdmessage(sender, QM_EMAILDONTMATCH);
58 cs_log(sender,"HELLO FAIL username %s email don't match (%s vs %s)",sender->nick,cargv[0],cargv[1]);
59 return CMD_ERROR;
60 }
61
62 if (csa_checkeboy(sender, cargv[0]))
63 return CMD_ERROR;
64
dc9548f4
CP
65 if (csa_checkaccountname(sender, sender->nick))
66 return CMD_ERROR;
67
bbc9e3a6
P
68 dupemail = strdup(cargv[0]);
69 local=strchr(dupemail, '@');
96e1f81d
CP
70 if(!local)
71 return CMD_ERROR;
e3805f60 72 *(local++)='\0';
96e1f81d
CP
73
74 mdp=findnearestmaildomain(local);
75 if(mdp) {
76 for(smdp=mdp; smdp; smdp=smdp->parent) {
77 if(MDIsBanned(smdp)) {
78 free(dupemail);
79 chanservstdmessage(sender, QM_DOMAINBANNED);
80 return CMD_ERROR;
e3805f60 81 }
96e1f81d
CP
82 if((smdp->count >= smdp->limit) && (smdp->limit > 0)) {
83 free(dupemail);
84 chanservstdmessage(sender, QM_DOMAINLIMIT);
85 return CMD_ERROR;
86 }
87 }
e3805f60
P
88 }
89
96e1f81d
CP
90 mdp=findmaildomainbydomain(local);
91 if(mdp) {
92 for (ruh=mdp->users; ruh; ruh=ruh->nextbydomain) {
93 if (ruh->localpart)
94 if (!strcasecmp(dupemail, ruh->localpart->content)) {
95 found++;
96 }
97 }
98
99 if((found >= mdp->actlimit) && (mdp->actlimit > 0)) {
100 free(dupemail);
101 chanservstdmessage(sender, QM_ADDRESSLIMIT);
102 return CMD_ERROR;
103 }
e3805f60
P
104 }
105
96e1f81d
CP
106 mdp=findorcreatemaildomain(cargv[0]);
107
108 aup->helloattempts++;
109
1dd6d55d 110 rup=getreguser();
111 rup->status=0;
112 rup->ID=++lastuserID;
113 strncpy(rup->username,sender->nick,NICKLEN); rup->username[NICKLEN]='\0';
114 rup->created=time(NULL);
cf50e022 115 rup->lastauth=0;
1dd6d55d 116 rup->lastemailchange=time(NULL);
117 rup->flags=QUFLAG_NOTICE;
118 rup->languageid=0;
119 rup->suspendby=0;
120 rup->suspendexp=0;
88d191e3 121 rup->suspendtime=0;
b438f642 122 rup->lockuntil=0;
1dd6d55d 123 rup->password[0]='\0';
1dd6d55d 124 rup->email=getsstring(cargv[0],EMAILLEN);
9708f78f 125 rup->lastemail=NULL;
96e1f81d
CP
126
127 rup->localpart=getsstring(dupemail,EMAILLEN);
128 free(dupemail);
129
e3805f60
P
130 rup->domain=mdp;
131 addregusertomaildomain(rup, rup->domain);
1dd6d55d 132 rup->info=NULL;
133 sprintf(userhost,"%s@%s",sender->ident,sender->host->name->content);
134 rup->lastuserhost=getsstring(userhost,USERLEN+HOSTLEN+1);
135 rup->suspendreason=NULL;
136 rup->comment=NULL;
137 rup->knownon=NULL;
138 rup->checkshd=NULL;
139 rup->stealcount=0;
140 rup->fakeuser=NULL;
1dd6d55d 141 addregusertohash(rup);
142 csa_createrandompw(rup->password, PASSLEN);
1dd6d55d 143 chanservstdmessage(sender, QM_NEWACCOUNT, rup->username,rup->email->content);
144 cs_log(sender,"HELLO OK created auth %s (%s)",rup->username,rup->email->content);
145 csdb_createuser(rup);
146 csdb_createmail(rup, QMAIL_NEWACCOUNT);
147
148 return CMD_OK;
149}