]>
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_doauth(void *source
, int cargc
, char **cargv
) {
23 char userhost
[USERLEN
+HOSTLEN
+2];
27 chanservstdmessage(sender
, QM_NOTENOUGHPARAMS
, "auth");
31 if (!(aup
= getactiveuserfromnick(sender
)))
35 if (aup
->authattempts
> MAXAUTHATTEMPT
) {
36 if ((aup
->authattempts
% 100) == 0)
37 chanservwallmessage("Warning: User %s!%s@%s attempted to auth %d times. Last attempt: AUTH %s %s",
38 nl
->np
->nick
, nl
->np
->ident
, nl
->np
->host
->name
->content
, cargv
[0], cargv
[1]);
39 chanservstdmessage(sender
, QM_AUTHFAIL
);
40 cs_log(sender
,"AUTH FAIL too many auth attempts (last attempt: AUTH %s %s)",cargv
[0], cargv
[1]);
44 if (!(rup
=findreguserbynick(cargv
[0]))) {
45 chanservstdmessage(sender
, QM_AUTHFAIL
);
46 cs_log(sender
,"AUTH FAIL bad username %s",cargv
[0]);
50 if (!checkpassword(rup
, cargv
[1])) {
51 chanservstdmessage(sender
, QM_AUTHFAIL
);
52 cs_log(sender
,"AUTH FAIL username %s bad password %s",rup
->username
,cargv
[1]);
56 rup
->lastauth
=time(NULL
);
57 sprintf(userhost
,"%s@%s",sender
->ident
,sender
->host
->name
->content
);
58 if (rup
->lastuserhost
)
59 freesstring(rup
->lastuserhost
);
60 rup
->lastuserhost
=getsstring(userhost
,USERLEN
+HOSTLEN
+1);
62 if (UHasSuspension(rup
) && rup
->suspendexp
&& (time(0) >= rup
->suspendexp
)) {
63 /* suspension has expired, remove it */
64 rup
->flags
&=(~(QUFLAG_SUSPENDED
|QUFLAG_GLINE
|QUFLAG_DELAYEDGLINE
));
67 freesstring(rup
->suspendreason
);
72 rup
->flags
&=~(QUFLAG_NEEDAUTH
);
75 if (UIsDelayedGline(rup
)) {
76 /* delayed-gline - schedule the user's squelching */
77 deleteschedule(NULL
, &chanservdgline
, (void*)rup
); /* icky, but necessary unless we stick more stuff in reguser structure */
78 scheduleoneshot(time(NULL
)+rand()%900
, &chanservdgline
, (void*)rup
);
80 else if (UIsGline(rup
)) {
81 /* instant-gline - lets be lazy and set a schedule expiring now :) */
82 deleteschedule(NULL
, &chanservdgline
, (void*)rup
); /* icky, but necessary unless we stick more stuff in reguser structure */
83 scheduleoneshot(time(NULL
), &chanservdgline
, (void*)rup
);
85 else if (UIsSuspended(rup
)) {
87 chanservstdmessage(sender
, QM_AUTHSUSPENDED
);
88 if(rup
->suspendreason
)
89 chanservstdmessage(sender
, QM_REASON
, rup
->suspendreason
->content
);
90 if (rup
->suspendexp
) {
94 tmp
=gmtime(&(rup
->suspendexp
));
95 strftime(buf
, 15, "%d/%m/%y %H:%M", tmp
);
96 chanservstdmessage(sender
, QM_EXPIRES
, buf
);
101 if (!UHasHelperPriv(rup
) && !UIsNoAuthLimit(rup
)) {
102 for (nl
=rup
->nicks
; nl
; nl
=nl
->next
)
105 if (ucount
>= MAXAUTHCOUNT
) {
106 chanservstdmessage(sender
, QM_TOOMANYAUTHS
);
111 chanservstdmessage(sender
, QM_AUTHOK
, rup
->username
);
112 cs_log(sender
,"AUTH OK username %s", rup
->username
);
113 localusersetaccount(sender
, rup
->username
);