]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/authcmds/login.c
1 /* Automatically generated by refactor.pl.
5 * CMDLEVEL: QCMD_SECURE | QCMD_NOTAUTHED | QCMD_ALIAS
7 * CMDDESC: Authenticates you on the bot.
9 * CMDPROTO: int csa_doauth(void *source, int cargc, char **cargv);
10 * CMDHELP: Usage: LOGIN <username> <password>
11 * CMDHELP: Authenticates you on the bot, where:
12 * CMDHELP: username - your username
13 * CMDHELP: password - your password
14 * CMDHELP: If you do not have a username and password, see HELLO.
15 * CMDHELP: Note: due to the sensitive nature of this command, you must send the message
16 * CMDHELP: to Q@CServe.quakenet.org when using it.
17 * CMDHELP: Note: the preferred way to authenticate is to use the /AUTH command.
20 #include "../chanserv.h"
21 #include "../authlib.h"
22 #include "../../lib/irc_string.h"
26 int csa_auth(void *source
, int cargc
, char **cargv
, CRAlgorithm alg
) {
29 nick
*sender
=source
, *onp
;
30 char userhost
[USERLEN
+HOSTLEN
+2];
32 char *authtype
= "AUTH";
39 authtype
= "CHALLENGEAUTH";
41 chanservstdmessage(sender
, QM_NOTENOUGHPARAMS
, "auth");
45 if (!(aup
= getactiveuserfromnick(sender
)))
49 if (aup
->authattempts
> MAXAUTHATTEMPT
) {
50 if ((aup
->authattempts
% 100) == 0)
51 chanservwallmessage("Warning: User %s!%s@%s attempted to auth %d times. Last attempt: %s %s %s",
52 sender
->nick
, sender
->ident
, sender
->host
->name
->content
, aup
->authattempts
, authtype
, cargv
[0], cargv
[1]);
53 chanservstdmessage(sender
, QM_AUTHFAIL
);
54 cs_log(sender
,"%s FAIL too many auth attempts (last attempt: %s %s %s)", authtype
, authtype
, cargv
[0], cargv
[1]);
58 if (!(rup
=findreguserbynick(cargv
[0]))) {
59 chanservstdmessage(sender
, QM_AUTHFAIL
);
60 cs_log(sender
,"%s FAIL bad username %s",authtype
,cargv
[0]);
65 if (!checkpassword(rup
, cargv
[1])) {
66 chanservstdmessage(sender
, QM_AUTHFAIL
);
67 cs_log(sender
,"%s FAIL username %s bad password %s",authtype
,rup
->username
,cargv
[1]);
71 if (!checkresponse(rup
, aup
->entropy
, cargv
[1], alg
)) {
72 chanservstdmessage(sender
, QM_AUTHFAIL
);
73 cs_log(sender
,"%s FAIL username %s bad response",authtype
,rup
->username
);
78 /* This should never fail but do something other than crashing if it does. */
79 if (!(anp
=findauthname(rup
->ID
))) {
80 chanservstdmessage(sender
, QM_AUTHFAIL
);
84 /* Check for too many auths. Don't return immediately, since we will still warn
85 * other users on the acct in this case. */
86 if (!UHasHelperPriv(rup
) && !UIsNoAuthLimit(rup
)) {
87 if (anp
->usercount
>= MAXAUTHCOUNT
) {
88 chanservstdmessage(sender
, QM_TOOMANYAUTHS
);
93 for (onp
=anp
->nicks
;onp
;onp
=onp
->nextbyauthname
) {
95 chanservstdmessage(onp
, QM_OTHERUSERAUTHEDLIMIT
, sender
->nick
, sender
->ident
, sender
->host
->name
->content
, MAXAUTHCOUNT
);
97 chanservstdmessage(onp
, QM_OTHERUSERAUTHED
, sender
->nick
, sender
->ident
, sender
->host
->name
->content
);
104 /* Guarantee a unique auth timestamp for each account */
106 if (rup
->lastauth
< now
)
111 sprintf(userhost
,"%s@%s",sender
->ident
,sender
->host
->name
->content
);
112 if (rup
->lastuserhost
)
113 freesstring(rup
->lastuserhost
);
114 rup
->lastuserhost
=getsstring(userhost
,USERLEN
+HOSTLEN
+1);
116 if (UHasSuspension(rup
) && rup
->suspendexp
&& (time(0) >= rup
->suspendexp
)) {
117 /* suspension has expired, remove it */
118 rup
->flags
&=(~(QUFLAG_SUSPENDED
|QUFLAG_GLINE
|QUFLAG_DELAYEDGLINE
));
121 freesstring(rup
->suspendreason
);
122 rup
->suspendreason
=0;
125 csdb_updateuser(rup
);
127 if (UIsSuspended(rup
)) {
129 chanservstdmessage(sender
, QM_AUTHSUSPENDED
);
130 if(rup
->suspendreason
)
131 chanservstdmessage(sender
, QM_REASON
, rup
->suspendreason
->content
);
132 if (rup
->suspendexp
) {
136 tmp
=gmtime(&(rup
->suspendexp
));
137 strftime(buf
, 15, "%d/%m/%y %H:%M", tmp
);
138 chanservstdmessage(sender
, QM_EXPIRES
, buf
);
144 chanservstdmessage(sender
, QM_AUTHOK
, rup
->username
);
146 cs_log(sender
,"%s OK username %s", authtype
,rup
->username
);
147 localusersetaccountwithuseridts(sender
, rup
->username
, rup
->ID
, rup
->lastauth
);
152 int csa_doauth(void *source
, int cargc
, char **cargv
) {
153 return csa_auth(source
, cargc
, cargv
, NULL
);