]> 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
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
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
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
65 if (csa_checkaccountname(sender, sender->nick))
66 return CMD_ERROR;
67
68 mdp=findorcreatemaildomain(cargv[0]);
69 for(smdp=mdp; smdp; smdp=smdp->parent) {
70 if((smdp->count >= smdp->limit) && (smdp->limit > 0)) {
71 chanservstdmessage(sender, QM_DOMAINLIMIT);
72 return CMD_ERROR;
73 }
74 }
75
76 aup->helloattempts++;
77
78 dupemail = strdup(cargv[0]);
79 local=strchr(dupemail, '@');
80 *(local++)='\0';
81 for (ruh=mdp->users; ruh; ruh=ruh->nextbydomain) {
82 if (ruh->localpart)
83 if (!match(local, ruh->localpart->content)) {
84 found++;
85 }
86 }
87 free(dupemail);
88
89 if((found > mdp->actlimit) && (mdp->actlimit > 0)) {
90 chanservstdmessage(sender, QM_DOMAINLIMIT);
91 return CMD_ERROR;
92 }
93
94 rup=getreguser();
95 rup->status=0;
96 rup->ID=++lastuserID;
97 strncpy(rup->username,sender->nick,NICKLEN); rup->username[NICKLEN]='\0';
98 rup->created=time(NULL);
99 rup->lastauth=0;
100 rup->lastemailchange=time(NULL);
101 rup->flags=QUFLAG_NOTICE;
102 rup->languageid=0;
103 rup->suspendby=0;
104 rup->suspendexp=0;
105 rup->password[0]='\0';
106 rup->email=getsstring(cargv[0],EMAILLEN);
107 rup->localpart=getsstring(local,EMAILLEN);
108 rup->domain=mdp;
109 addregusertomaildomain(rup, rup->domain);
110 rup->info=NULL;
111 sprintf(userhost,"%s@%s",sender->ident,sender->host->name->content);
112 rup->lastuserhost=getsstring(userhost,USERLEN+HOSTLEN+1);
113 rup->suspendreason=NULL;
114 rup->comment=NULL;
115 rup->knownon=NULL;
116 rup->checkshd=NULL;
117 rup->stealcount=0;
118 rup->fakeuser=NULL;
119 addregusertohash(rup);
120 csa_createrandompw(rup->password, PASSLEN);
121 chanservstdmessage(sender, QM_NEWACCOUNT, rup->username,rup->email->content);
122 cs_log(sender,"HELLO OK created auth %s (%s)",rup->username,rup->email->content);
123 csdb_createuser(rup);
124 csdb_createmail(rup, QMAIL_NEWACCOUNT);
125
126 return CMD_OK;
127 }