]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/authcmds/login.c
1 /* Automatically generated by refactor.pl.
5 * CMDLEVEL: QCMD_SECURE | QCMD_NOTAUTHED
7 * CMDDESC: Authenticates you on the bot.
9 * CMDPROTO: int csa_doauth(void *source, int cargc, char **cargv);
12 #include "../chanserv.h"
13 #include "../authlib.h"
14 #include "../../lib/irc_string.h"
18 int csa_auth(void *source
, int cargc
, char **cargv
, CRAlgorithm alg
) {
23 char userhost
[USERLEN
+HOSTLEN
+2];
26 char *authtype
= "AUTH";
30 authtype
= "CHALLENGEAUTH";
32 chanservstdmessage(sender
, QM_NOTENOUGHPARAMS
, "auth");
36 if (!(aup
= getactiveuserfromnick(sender
)))
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]);
49 if (!(rup
=findreguserbynick(cargv
[0]))) {
50 chanservstdmessage(sender
, QM_AUTHFAIL
);
51 cs_log(sender
,"%s FAIL bad username %s",authtype
,cargv
[0]);
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]);
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
);
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);
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
));
80 freesstring(rup
->suspendreason
);
85 rup
->flags
&=~(QUFLAG_NEEDAUTH
);
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
);
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
);
98 else if (UIsSuspended(rup
)) {
100 chanservstdmessage(sender
, QM_AUTHSUSPENDED
);
101 if(rup
->suspendreason
)
102 chanservstdmessage(sender
, QM_REASON
, rup
->suspendreason
->content
);
103 if (rup
->suspendexp
) {
107 tmp
=gmtime(&(rup
->suspendexp
));
108 strftime(buf
, 15, "%d/%m/%y %H:%M", tmp
);
109 chanservstdmessage(sender
, QM_EXPIRES
, buf
);
114 if (!UHasHelperPriv(rup
) && !UIsNoAuthLimit(rup
)) {
115 for (nl
=rup
->nicks
; nl
; nl
=nl
->next
)
118 if (ucount
>= MAXAUTHCOUNT
) {
119 chanservstdmessage(sender
, QM_TOOMANYAUTHS
);
124 chanservstdmessage(sender
, QM_AUTHOK
, rup
->username
);
126 cs_log(sender
,"%s OK username %s", authtype
,rup
->username
);
127 localusersetaccount(sender
, rup
->username
);
132 int csa_doauth(void *source
, int cargc
, char **cargv
) {
133 return csa_auth(source
, cargc
, cargv
, NULL
);