]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/authcmds/login.c
Merge.
[irc/quakenet/newserv.git] / chanserv / authcmds / login.c
1 /* Automatically generated by refactor.pl.
2 *
3 *
4 * CMDNAME: login
5 * CMDLEVEL: QCMD_SECURE | QCMD_NOTAUTHED
6 * CMDARGS: 2
7 * CMDDESC: Authenticates you on the bot.
8 * CMDFUNC: csa_doauth
9 * CMDPROTO: int csa_doauth(void *source, int cargc, char **cargv);
10 */
11
12 #include "../chanserv.h"
13 #include "../authlib.h"
14 #include "../../lib/irc_string.h"
15 #include <stdio.h>
16 #include <string.h>
17
18 int csa_auth(void *source, int cargc, char **cargv, CRAlgorithm alg) {
19 reguser *rup;
20 activeuser* aup;
21 nick *sender=source;
22 nicklist *nl = NULL;
23 char userhost[USERLEN+HOSTLEN+2];
24 int ucount=0;
25 int challenge=0;
26 char *authtype = "AUTH";
27
28 if (alg) {
29 challenge=1;
30 authtype = "CHALLENGEAUTH";
31 } else if (cargc<2) {
32 chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "auth");
33 return CMD_ERROR;
34 }
35
36 if (!(aup = getactiveuserfromnick(sender)))
37 return CMD_ERROR;
38
39 aup->authattempts++;
40 if (aup->authattempts > MAXAUTHATTEMPT) {
41 if ((aup->authattempts % 100) == 0)
42 chanservwallmessage("Warning: User %s!%s@%s attempted to auth %d times. Last attempt: %s %s %s",
43 nl->np->nick, nl->np->ident, nl->np->host->name->content, authtype, cargv[0], cargv[1]);
44 chanservstdmessage(sender, QM_AUTHFAIL);
45 cs_log(sender,"%s FAIL too many auth attempts (last attempt: %s %s %s)", authtype, authtype, cargv[0], cargv[1]);
46 return CMD_ERROR;
47 }
48
49 if (!(rup=findreguserbynick(cargv[0]))) {
50 chanservstdmessage(sender, QM_AUTHFAIL);
51 cs_log(sender,"%s FAIL bad username %s",authtype,cargv[0]);
52 return CMD_ERROR;
53 }
54
55 if (!challenge) {
56 if (!checkpassword(rup, cargv[1])) {
57 chanservstdmessage(sender, QM_AUTHFAIL);
58 cs_log(sender,"%s FAIL username %s bad password %s",authtype,rup->username,cargv[1]);
59 return CMD_ERROR;
60 }
61 } else {
62 if (!checkresponse(rup, aup->entropy, cargv[1], alg)) {
63 chanservstdmessage(sender, QM_AUTHFAIL);
64 cs_log(sender,"%s FAIL username %s bad response",authtype,rup->username);
65 return CMD_ERROR;
66 }
67 }
68
69 rup->lastauth=time(NULL);
70 sprintf(userhost,"%s@%s",sender->ident,sender->host->name->content);
71 if (rup->lastuserhost)
72 freesstring(rup->lastuserhost);
73 rup->lastuserhost=getsstring(userhost,USERLEN+HOSTLEN+1);
74
75 if (UHasSuspension(rup) && rup->suspendexp && (time(0) >= rup->suspendexp)) {
76 /* suspension has expired, remove it */
77 rup->flags&=(~(QUFLAG_SUSPENDED|QUFLAG_GLINE|QUFLAG_DELAYEDGLINE));
78 rup->suspendby=0;
79 rup->suspendexp=0;
80 freesstring(rup->suspendreason);
81 rup->suspendreason=0;
82 }
83
84 if (UIsNeedAuth(rup))
85 rup->flags&=~(QUFLAG_NEEDAUTH);
86 csdb_updateuser(rup);
87
88 if (UIsDelayedGline(rup)) {
89 /* delayed-gline - schedule the user's squelching */
90 deleteschedule(NULL, &chanservdgline, (void*)rup); /* icky, but necessary unless we stick more stuff in reguser structure */
91 scheduleoneshot(time(NULL)+rand()%900, &chanservdgline, (void*)rup);
92 }
93 else if (UIsGline(rup)) {
94 /* instant-gline - lets be lazy and set a schedule expiring now :) */
95 deleteschedule(NULL, &chanservdgline, (void*)rup); /* icky, but necessary unless we stick more stuff in reguser structure */
96 scheduleoneshot(time(NULL), &chanservdgline, (void*)rup);
97 }
98 else if (UIsSuspended(rup)) {
99 /* plain suspend */
100 chanservstdmessage(sender, QM_AUTHSUSPENDED);
101 if(rup->suspendreason)
102 chanservstdmessage(sender, QM_REASON, rup->suspendreason->content);
103 if (rup->suspendexp) {
104 struct tm* tmp;
105 char buf[200];
106
107 tmp=gmtime(&(rup->suspendexp));
108 strftime(buf, 15, "%d/%m/%y %H:%M", tmp);
109 chanservstdmessage(sender, QM_EXPIRES, buf);
110 }
111 return CMD_ERROR;
112 }
113
114 if (!UHasHelperPriv(rup) && !UIsNoAuthLimit(rup)) {
115 for (nl=rup->nicks; nl; nl=nl->next)
116 ucount++;
117
118 if (ucount >= MAXAUTHCOUNT) {
119 chanservstdmessage(sender, QM_TOOMANYAUTHS);
120 return CMD_ERROR;
121 }
122 }
123
124 chanservstdmessage(sender, QM_AUTHOK, rup->username);
125
126 cs_log(sender,"%s OK username %s", authtype,rup->username);
127 localusersetaccount(sender, rup->username);
128
129 return CMD_OK;
130 }
131
132 int csa_doauth(void *source, int cargc, char **cargv) {
133 return csa_auth(source, cargc, cargv, NULL);
134 }