]>
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
) {
22 char userhost
[USERLEN
+HOSTLEN
+2];
24 char *authtype
= "AUTH";
29 authtype
= "CHALLENGEAUTH";
31 chanservstdmessage(sender
, QM_NOTENOUGHPARAMS
, "auth");
35 if (!(aup
= getactiveuserfromnick(sender
)))
39 if (aup
->authattempts
> MAXAUTHATTEMPT
) {
40 if ((aup
->authattempts
% 100) == 0)
41 chanservwallmessage("Warning: User %s!%s@%s attempted to auth %d times. Last attempt: %s %s %s",
42 sender
->nick
, sender
->ident
, sender
->host
->name
->content
, authtype
, cargv
[0], cargv
[1]);
43 chanservstdmessage(sender
, QM_AUTHFAIL
);
44 cs_log(sender
,"%s FAIL too many auth attempts (last attempt: %s %s %s)", authtype
, authtype
, cargv
[0], cargv
[1]);
48 if (!(rup
=findreguserbynick(cargv
[0]))) {
49 chanservstdmessage(sender
, QM_AUTHFAIL
);
50 cs_log(sender
,"%s FAIL bad username %s",authtype
,cargv
[0]);
55 if (!checkpassword(rup
, cargv
[1])) {
56 chanservstdmessage(sender
, QM_AUTHFAIL
);
57 cs_log(sender
,"%s FAIL username %s bad password %s",authtype
,rup
->username
,cargv
[1]);
61 if (!checkresponse(rup
, aup
->entropy
, cargv
[1], alg
)) {
62 chanservstdmessage(sender
, QM_AUTHFAIL
);
63 cs_log(sender
,"%s FAIL username %s bad response",authtype
,rup
->username
);
68 rup
->lastauth
=time(NULL
);
69 sprintf(userhost
,"%s@%s",sender
->ident
,sender
->host
->name
->content
);
70 if (rup
->lastuserhost
)
71 freesstring(rup
->lastuserhost
);
72 rup
->lastuserhost
=getsstring(userhost
,USERLEN
+HOSTLEN
+1);
74 if (UHasSuspension(rup
) && rup
->suspendexp
&& (time(0) >= rup
->suspendexp
)) {
75 /* suspension has expired, remove it */
76 rup
->flags
&=(~(QUFLAG_SUSPENDED
|QUFLAG_GLINE
|QUFLAG_DELAYEDGLINE
));
79 freesstring(rup
->suspendreason
);
84 rup
->flags
&=~(QUFLAG_NEEDAUTH
);
87 if (UIsDelayedGline(rup
)) {
88 /* delayed-gline - schedule the user's squelching */
89 deleteschedule(NULL
, &chanservdgline
, (void*)rup
); /* icky, but necessary unless we stick more stuff in reguser structure */
90 scheduleoneshot(time(NULL
)+rand()%900
, &chanservdgline
, (void*)rup
);
91 } else if (UIsGline(rup
)) {
92 /* instant-gline - lets be lazy and set a schedule expiring now :) */
93 deleteschedule(NULL
, &chanservdgline
, (void*)rup
); /* icky, but necessary unless we stick more stuff in reguser structure */
94 scheduleoneshot(time(NULL
), &chanservdgline
, (void*)rup
);
95 } else if (UIsSuspended(rup
)) {
97 chanservstdmessage(sender
, QM_AUTHSUSPENDED
);
98 if(rup
->suspendreason
)
99 chanservstdmessage(sender
, QM_REASON
, rup
->suspendreason
->content
);
100 if (rup
->suspendexp
) {
104 tmp
=gmtime(&(rup
->suspendexp
));
105 strftime(buf
, 15, "%d/%m/%y %H:%M", tmp
);
106 chanservstdmessage(sender
, QM_EXPIRES
, buf
);
111 if (!UHasHelperPriv(rup
) && !UIsNoAuthLimit(rup
)) {
112 anp
=findauthname(rup
->ID
);
113 if (!anp
|| (anp
->usercount
>= MAXAUTHCOUNT
)) {
114 chanservstdmessage(sender
, QM_TOOMANYAUTHS
);
119 chanservstdmessage(sender
, QM_AUTHOK
, rup
->username
);
121 cs_log(sender
,"%s OK username %s", authtype
,rup
->username
);
122 localusersetaccountwithuserid(sender
, rup
->username
, rup
->ID
);;
127 int csa_doauth(void *source
, int cargc
, char **cargv
) {
128 return csa_auth(source
, cargc
, cargv
, NULL
);