]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/authcmds/hello.c
Merge.
[irc/quakenet/newserv.git] / chanserv / authcmds / hello.c
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);
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.
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
24 int csa_dohello(void *source, int cargc, char **cargv) {
25 nick *sender=source;
26 reguser *rup;
27 char userhost[USERLEN+HOSTLEN+2];
28 maildomain *mdp, *smdp;
29 char *local;
30 reguser *ruh;
31 int found=0;
32 char *dupemail;
33 activeuser *aup;
34 maillock *mlp;
35 time_t t;
36
37 if (getreguserfromnick(sender))
38 return CMD_ERROR;
39
40 if (cargc<2) {
41 chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "hello");
42 return CMD_ERROR;
43 }
44
45 if (findreguserbynick(sender->nick)) {
46 chanservstdmessage(sender, QM_AUTHNAMEINUSE, sender->nick);
47 return CMD_ERROR;
48 }
49
50 if (!(aup = getactiveuserfromnick(sender)))
51 return CMD_ERROR;
52
53 if (aup->helloattempts > MAXHELLOS) {
54 chanservstdmessage(sender, QM_MAXHELLOLIMIT);
55 return CMD_ERROR;
56 }
57
58 if (strcmp(cargv[0],cargv[1])) {
59 chanservstdmessage(sender, QM_EMAILDONTMATCH);
60 cs_log(sender,"HELLO FAIL username %s email don't match (%s vs %s)",sender->nick,cargv[0],cargv[1]);
61 return CMD_ERROR;
62 }
63
64 if (csa_checkeboy(sender, cargv[0]))
65 return CMD_ERROR;
66
67 if (csa_checkaccountname(sender, sender->nick))
68 return CMD_ERROR;
69
70 for(mlp=maillocks;mlp;mlp=mlp->next) {
71 if(!match(mlp->pattern->content, cargv[0])) {
72 chanservstdmessage(sender, QM_MAILLOCKED);
73 return CMD_ERROR;
74 }
75 }
76
77 dupemail = strdup(cargv[0]);
78 local=strchr(dupemail, '@');
79 if(!local)
80 return CMD_ERROR;
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);
88 chanservstdmessage(sender, QM_MAILLOCKED);
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);
111 return CMD_ERROR;
112 }
113 }
114
115 mdp=findorcreatemaildomain(cargv[0]);
116
117 aup->helloattempts++;
118
119 t=time(NULL);
120 rup=getreguser();
121 rup->status=0;
122 rup->ID=++lastuserID;
123 strncpy(rup->username,sender->nick,NICKLEN); rup->username[NICKLEN]='\0';
124 rup->created=t;
125 rup->lastauth=0;
126 rup->lastemailchange=t;
127 rup->lastpasschange=t;
128 rup->flags=QUFLAG_NOTICE;
129 rup->languageid=0;
130 rup->suspendby=0;
131 rup->suspendexp=0;
132 rup->suspendtime=0;
133 rup->lockuntil=0;
134 rup->password[0]='\0';
135 rup->email=getsstring(cargv[0],EMAILLEN);
136 rup->lastemail=NULL;
137
138 rup->localpart=getsstring(dupemail,EMAILLEN);
139 free(dupemail);
140
141 rup->domain=mdp;
142 addregusertomaildomain(rup, rup->domain);
143 rup->info=NULL;
144 sprintf(userhost,"%s@%s",sender->ident,sender->host->name->content);
145 rup->lastuserhost=getsstring(userhost,USERLEN+HOSTLEN+1);
146 rup->suspendreason=NULL;
147 rup->comment=NULL;
148 rup->knownon=NULL;
149 rup->checkshd=NULL;
150 rup->stealcount=0;
151 rup->fakeuser=NULL;
152 addregusertohash(rup);
153 csa_createrandompw(rup->password, PASSLEN);
154 chanservstdmessage(sender, QM_NEWACCOUNT, rup->username,rup->email->content);
155 cs_log(sender,"HELLO OK created auth %s (%s)",rup->username,rup->email->content);
156 csdb_createuser(rup);
157 csdb_createmail(rup, QMAIL_NEWACCOUNT);
158
159 return CMD_OK;
160 }