]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/authcmds/auth.c
1 /* Automatically generated by refactor.pl.
5 * CMDALIASES: login ircdauth
6 * CMDLEVEL: QCMD_SECURE | QCMD_NOTAUTHED
8 * CMDDESC: Authenticates you on the bot.
10 * CMDPROTO: int csa_doauth(void *source, int cargc, char **cargv);
11 * CMDHELP: Usage: @UCOMMAND@ <username> <password>
12 * CMDHELP: Authenticates you on the bot, where:
13 * CMDHELP: username - your username
14 * CMDHELP: password - your password
15 * CMDHELP: If you do not have a username and password, see HELLO.
16 * CMDHELP: Note: due to the sensitive nature of this command, you must send the message
17 * CMDHELP: to Q@CServe.quakenet.org when using it.
18 * CMDHELP: Note: the preferred way to authenticate is to use the /AUTH command.
21 #include "../chanserv.h"
22 #include "../authlib.h"
23 #include "../../lib/irc_string.h"
27 int csa_completeauth(nick
*sender
, reguser
*rup
, char *authtype
);
29 int csa_auth(void *source
, int cargc
, char **cargv
, CRAlgorithm alg
) {
34 char *authtype
= "AUTH";
38 authtype
= "CHALLENGEAUTH";
40 chanservstdmessage(sender
, QM_NOTENOUGHPARAMS
, "auth");
44 if (!(aup
= getactiveuserfromnick(sender
)))
48 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]);
55 chanservstdmessage(sender
, QM_AUTHFAIL
);
56 cs_log(sender
,"%s FAIL too many auth attempts (last attempt: %s %s %s)", authtype
, authtype
, cargv
[0], cargv
[1]);
60 if (!(rup
=findreguserbynick(cargv
[0]))) {
61 chanservstdmessage(sender
, QM_AUTHFAIL
);
62 cs_log(sender
,"%s FAIL bad username %s",authtype
,cargv
[0]);
67 if (!checkpassword(rup
, cargv
[1])) {
68 chanservstdmessage(sender
, QM_AUTHFAIL
);
69 cs_log(sender
,"%s FAIL username %s bad password %s",authtype
,rup
->username
,cargv
[1]);
73 if (!checkresponse(rup
, aup
->entropy
, cargv
[1], alg
)) {
74 chanservstdmessage(sender
, QM_AUTHFAIL
);
75 cs_log(sender
,"%s FAIL username %s bad response",authtype
,rup
->username
);
80 return csa_completeauth(sender
, rup
, authtype
);
83 int csa_completeauth(nick
*sender
, reguser
*rup
, char *authtype
) {
85 time_t now
, oldlastauth
;
86 char userhost
[USERLEN
+HOSTLEN
+2];
91 /* This should never fail but do something other than crashing if it does. */
92 if (!(anp
=findauthname(rup
->ID
))) {
93 chanservstdmessage(sender
, QM_AUTHFAIL
);
97 /* Check for too many auths. Don't return immediately, since we will still warn
98 * other users on the acct in this case. */
99 if (!UHasStaffPriv(rup
) && !UIsNoAuthLimit(rup
)) {
100 if (anp
->usercount
>= MAXAUTHCOUNT
) {
101 chanservstdmessage(sender
, QM_TOOMANYAUTHS
);
106 for (onp
=anp
->nicks
;onp
;onp
=onp
->nextbyauthname
) {
108 chanservstdmessage(onp
, QM_OTHERUSERAUTHEDLIMIT
, sender
->nick
, sender
->ident
, sender
->host
->name
->content
, MAXAUTHCOUNT
);
110 chanservstdmessage(onp
, QM_OTHERUSERAUTHED
, sender
->nick
, sender
->ident
, sender
->host
->name
->content
);
119 if (UHasSuspension(rup
) && rup
->suspendexp
&& (now
>= rup
->suspendexp
)) {
120 /* suspension has expired, remove it */
121 rup
->flags
&=(~(QUFLAG_SUSPENDED
|QUFLAG_GLINE
|QUFLAG_DELAYEDGLINE
));
124 freesstring(rup
->suspendreason
);
125 rup
->suspendreason
=0;
126 csdb_updateuser(rup
);
129 if (UIsSuspended(rup
)) {
131 chanservstdmessage(sender
, QM_AUTHSUSPENDED
);
132 if(rup
->suspendreason
)
133 chanservstdmessage(sender
, QM_REASON
, rup
->suspendreason
->content
);
135 chanservstdmessage(sender
, QM_EXPIRES
, rup
->suspendexp
);
138 if (UIsInactive(rup
)) {
139 chanservstdmessage(sender
, QM_INACTIVEACCOUNT
);
143 /* Guarantee a unique auth timestamp for each account */
144 oldlastauth
=rup
->lastauth
;
146 if (rup
->lastauth
< now
)
151 sprintf(userhost
,"%s@%s",sender
->ident
,sender
->host
->name
->content
);
152 if (rup
->lastuserhost
)
153 freesstring(rup
->lastuserhost
);
154 rup
->lastuserhost
=getsstring(userhost
,USERLEN
+HOSTLEN
+1);
156 csdb_updateuser(rup
);
158 cs_log(sender
,"%s OK username %s", authtype
,rup
->username
);
160 localusersetaccount(sender
, rup
->username
, rup
->ID
, cs_accountflagmap(rup
), rup
->lastauth
);
162 chanservstdmessage(sender
, QM_AUTHOK
, rup
->username
);
165 args
[1]=(void *)oldlastauth
;
166 triggerhook(HOOK_CHANSERV_AUTH
, args
);
171 int csa_doauth(void *source
, int cargc
, char **cargv
) {
172 return csa_auth(source
, cargc
, cargv
, NULL
);