]>
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";
38 authtype
= "CHALLENGEAUTH";
40 chanservstdmessage(sender
, QM_NOTENOUGHPARAMS
, "auth");
44 if (!(aup
= getactiveuserfromnick(sender
)))
48 if (aup
->authattempts
> MAXAUTHATTEMPT
) {
49 if ((aup
->authattempts
% 100) == 0)
50 chanservwallmessage("Warning: User %s!%s@%s attempted to auth %d times. Last attempt: %s %s %s",
51 sender
->nick
, sender
->ident
, sender
->host
->name
->content
, authtype
, cargv
[0], cargv
[1]);
52 chanservstdmessage(sender
, QM_AUTHFAIL
);
53 cs_log(sender
,"%s FAIL too many auth attempts (last attempt: %s %s %s)", authtype
, authtype
, cargv
[0], cargv
[1]);
57 if (!(rup
=findreguserbynick(cargv
[0]))) {
58 chanservstdmessage(sender
, QM_AUTHFAIL
);
59 cs_log(sender
,"%s FAIL bad username %s",authtype
,cargv
[0]);
64 if (!checkpassword(rup
, cargv
[1])) {
65 chanservstdmessage(sender
, QM_AUTHFAIL
);
66 cs_log(sender
,"%s FAIL username %s bad password %s",authtype
,rup
->username
,cargv
[1]);
70 if (!checkresponse(rup
, aup
->entropy
, cargv
[1], alg
)) {
71 chanservstdmessage(sender
, QM_AUTHFAIL
);
72 cs_log(sender
,"%s FAIL username %s bad response",authtype
,rup
->username
);
77 /* This should never fail but do something other than crashing if it does. */
78 if (!(anp
=findauthname(rup
->ID
))) {
79 chanservstdmessage(sender
, QM_AUTHFAIL
);
83 /* Check for too many auths. Don't return immediately, since we will still warn
84 * other users on the acct in this case. */
85 if (!UHasHelperPriv(rup
) && !UIsNoAuthLimit(rup
)) {
86 if (anp
->usercount
>= MAXAUTHCOUNT
) {
87 chanservstdmessage(sender
, QM_TOOMANYAUTHS
);
92 for (onp
=anp
->nicks
;onp
;onp
=onp
->nextbyauthname
) {
94 chanservstdmessage(onp
, QM_OTHERUSERAUTHEDLIMIT
, sender
->nick
, sender
->ident
, sender
->host
->name
->content
, MAXAUTHCOUNT
);
96 chanservstdmessage(onp
, QM_OTHERUSERAUTHED
, sender
->nick
, sender
->ident
, sender
->host
->name
->content
);
103 rup
->lastauth
=time(NULL
);
104 sprintf(userhost
,"%s@%s",sender
->ident
,sender
->host
->name
->content
);
105 if (rup
->lastuserhost
)
106 freesstring(rup
->lastuserhost
);
107 rup
->lastuserhost
=getsstring(userhost
,USERLEN
+HOSTLEN
+1);
109 if (UHasSuspension(rup
) && rup
->suspendexp
&& (time(0) >= rup
->suspendexp
)) {
110 /* suspension has expired, remove it */
111 rup
->flags
&=(~(QUFLAG_SUSPENDED
|QUFLAG_GLINE
|QUFLAG_DELAYEDGLINE
));
114 freesstring(rup
->suspendreason
);
115 rup
->suspendreason
=0;
118 csdb_updateuser(rup
);
120 if (UIsDelayedGline(rup
)) {
121 /* delayed-gline - schedule the user's squelching */
122 deleteschedule(NULL
, &chanservdgline
, (void*)rup
); /* icky, but necessary unless we stick more stuff in reguser structure */
123 scheduleoneshot(time(NULL
)+rand()%900
, &chanservdgline
, (void*)rup
);
124 } else if (UIsGline(rup
)) {
125 /* instant-gline - lets be lazy and set a schedule expiring now :) */
126 deleteschedule(NULL
, &chanservdgline
, (void*)rup
); /* icky, but necessary unless we stick more stuff in reguser structure */
127 scheduleoneshot(time(NULL
), &chanservdgline
, (void*)rup
);
128 } else if (UIsSuspended(rup
)) {
130 chanservstdmessage(sender
, QM_AUTHSUSPENDED
);
131 if(rup
->suspendreason
)
132 chanservstdmessage(sender
, QM_REASON
, rup
->suspendreason
->content
);
133 if (rup
->suspendexp
) {
137 tmp
=gmtime(&(rup
->suspendexp
));
138 strftime(buf
, 15, "%d/%m/%y %H:%M", tmp
);
139 chanservstdmessage(sender
, QM_EXPIRES
, buf
);
145 chanservstdmessage(sender
, QM_AUTHOK
, rup
->username
);
147 cs_log(sender
,"%s OK username %s", authtype
,rup
->username
);
148 localusersetaccountwithuserid(sender
, rup
->username
, rup
->ID
);;
153 int csa_doauth(void *source
, int cargc
, char **cargv
) {
154 return csa_auth(source
, cargc
, cargv
, NULL
);