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