]> jfr.im git - irc/quakenet/newserv.git/blobdiff - chanserv/authcmds/hello.c
Merge pull request #2 from meeb/meeb
[irc/quakenet/newserv.git] / chanserv / authcmds / hello.c
index 7485a7631e4e25ee6f67f9e558cc01d1f5353d4e..cc567b0674e5bbb1057c8ba0cb5f66e1988046f9 100644 (file)
@@ -7,6 +7,12 @@
  * CMDDESC: Creates a new user account.
  * CMDFUNC: csa_dohello
  * CMDPROTO: int csa_dohello(void *source, int cargc, char **cargv);
+ * CMDHELP: Usage: HELLO <email> <email>
+ * CMDHELP: Creates a new user account for yourself.  Your current nickname will be used
+ * CMDHELP: for the name of the account, and may only contain letters, numbers and 
+ * CMDHELP: hyphens (-).  An email containing password details will be sent to the email
+ * CMDHELP: address supplied.  Where:
+ * CMDHELP: email    - your email address.  Must be entered the same way both times.
  */
 
 #include "../chanserv.h"
@@ -24,6 +30,8 @@ int csa_dohello(void *source, int cargc, char **cargv) {
   reguser *ruh;
   int found=0;
   char *dupemail;
+  activeuser *aup;
+  maillock *mlp;
 
   if (getreguserfromnick(sender))
     return CMD_ERROR;
@@ -38,6 +46,14 @@ int csa_dohello(void *source, int cargc, char **cargv) {
     return CMD_ERROR;
   }
 
+  if (!(aup = getactiveuserfromnick(sender)))
+    return CMD_ERROR;
+
+  if (aup->helloattempts > MAXHELLOS) {
+    chanservstdmessage(sender, QM_MAXHELLOLIMIT);
+    return CMD_ERROR;
+  }
+
   if (strcmp(cargv[0],cargv[1])) {
     chanservstdmessage(sender, QM_EMAILDONTMATCH);
     cs_log(sender,"HELLO FAIL username %s email don't match (%s vs %s)",sender->nick,cargv[0],cargv[1]);
@@ -47,61 +63,69 @@ int csa_dohello(void *source, int cargc, char **cargv) {
   if (csa_checkeboy(sender, cargv[0]))
     return CMD_ERROR;
 
-  mdp=findorcreatemaildomain(cargv[0]);
-  for(smdp=mdp; smdp; smdp=smdp->parent) {
-    if((smdp->count >= smdp->limit) && (smdp->limit > 0)) {
-      chanservstdmessage(sender, QM_DOMAINLIMIT);
+  if (csa_checkaccountname(sender, sender->nick))
+    return CMD_ERROR;
+
+  for(mlp=maillocks;mlp;mlp=mlp->next) {
+    if(!match(mlp->pattern->content, cargv[0])) {
+      chanservstdmessage(sender, QM_MAILLOCKED);
       return CMD_ERROR;
     }
   }
 
   dupemail = strdup(cargv[0]);
   local=strchr(dupemail, '@');
+  if(!local) {
+    free(dupemail);
+    return CMD_ERROR;
+  }
   *(local++)='\0';
-  for (ruh=mdp->users; ruh; ruh=ruh->nextbydomain) {
-    if (ruh->localpart)
-      if (!match(local, ruh->localpart->content)) {
-        found++;
+
+  mdp=findnearestmaildomain(local);
+  if(mdp) {
+    for(smdp=mdp; smdp; smdp=smdp->parent) {
+      if(MDIsBanned(smdp)) {
+        free(dupemail);
+        chanservstdmessage(sender, QM_MAILLOCKED);
+        return CMD_ERROR;
       }
+      if((smdp->count >= smdp->limit) && (smdp->limit > 0)) {
+        free(dupemail);
+        chanservstdmessage(sender, QM_DOMAINLIMIT);
+        return CMD_ERROR;
+      }
+    }
   }
-  free(dupemail);
 
-  if((found > mdp->actlimit) && (mdp->actlimit > 0)) {
-    chanservstdmessage(sender, QM_DOMAINLIMIT);
-    return CMD_ERROR;
+  mdp=findmaildomainbydomain(local);
+  if(mdp) {
+    for (ruh=mdp->users; ruh; ruh=ruh->nextbydomain) {
+      if (ruh->localpart)
+        if (!strcasecmp(dupemail, ruh->localpart->content)) {
+          found++;
+        }
+    }
+
+    if((found >= mdp->actlimit) && (mdp->actlimit > 0)) {
+      free(dupemail);
+      chanservstdmessage(sender, QM_ADDRESSLIMIT);
+      return CMD_ERROR;
+    }
   }
 
-  rup=getreguser();
-  rup->status=0;
-  rup->ID=++lastuserID;
-  strncpy(rup->username,sender->nick,NICKLEN); rup->username[NICKLEN]='\0';
-  rup->created=time(NULL);
-  rup->lastauth=0;
-  rup->lastemailchange=time(NULL);
-  rup->flags=QUFLAG_NOTICE;
-  rup->languageid=0;
-  rup->suspendby=0;
-  rup->suspendexp=0;
-  rup->password[0]='\0';
-  rup->email=getsstring(cargv[0],EMAILLEN);
-  rup->localpart=getsstring(local,EMAILLEN);
-  rup->domain=mdp;
-  addregusertomaildomain(rup, rup->domain);
-  rup->info=NULL;
+  free(dupemail);
+
+  aup->helloattempts++;
+
+  rup=csa_createaccount(sender->nick,"", cargv[0]);
+  csa_createrandompw(rup->password, PASSLEN);
   sprintf(userhost,"%s@%s",sender->ident,sender->host->name->content);
   rup->lastuserhost=getsstring(userhost,USERLEN+HOSTLEN+1);
-  rup->suspendreason=NULL;
-  rup->comment=NULL;
-  rup->knownon=NULL;
-  rup->checkshd=NULL;
-  rup->stealcount=0;
-  rup->fakeuser=NULL;
-  addregusertohash(rup);
-  csa_createrandompw(rup->password, PASSLEN);
+
   chanservstdmessage(sender, QM_NEWACCOUNT, rup->username,rup->email->content);
   cs_log(sender,"HELLO OK created auth %s (%s)",rup->username,rup->email->content); 
   csdb_createuser(rup);
   csdb_createmail(rup, QMAIL_NEWACCOUNT);
+
   return CMD_OK;
 }