]> jfr.im git - irc/quakenet/newserv.git/blame - chanserv/authcmds/login.c
Added ability to specify timestamp when setting account.
[irc/quakenet/newserv.git] / chanserv / authcmds / login.c
CommitLineData
1dd6d55d 1/* Automatically generated by refactor.pl.
2 *
3 *
4 * CMDNAME: login
dd258305 5 * CMDLEVEL: QCMD_SECURE | QCMD_NOTAUTHED | QCMD_ALIAS
1dd6d55d 6 * CMDARGS: 2
7 * CMDDESC: Authenticates you on the bot.
8 * CMDFUNC: csa_doauth
9 * CMDPROTO: int csa_doauth(void *source, int cargc, char **cargv);
dd258305 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.
1dd6d55d 18 */
19
20#include "../chanserv.h"
21#include "../authlib.h"
22#include "../../lib/irc_string.h"
23#include <stdio.h>
24#include <string.h>
25
b7a95f03 26int csa_auth(void *source, int cargc, char **cargv, CRAlgorithm alg) {
1dd6d55d 27 reguser *rup;
23b85e10 28 activeuser *aup;
f3b0017b 29 nick *sender=source, *onp;
1dd6d55d 30 char userhost[USERLEN+HOSTLEN+2];
b7a95f03
CP
31 int challenge=0;
32 char *authtype = "AUTH";
23b85e10 33 authname *anp;
f3b0017b 34 int toomanyauths=0;
1dd6d55d 35
b7a95f03
CP
36 if (alg) {
37 challenge=1;
38 authtype = "CHALLENGEAUTH";
39 } else if (cargc<2) {
1dd6d55d 40 chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "auth");
41 return CMD_ERROR;
42 }
43
44 if (!(aup = getactiveuserfromnick(sender)))
45 return CMD_ERROR;
46
47 aup->authattempts++;
48 if (aup->authattempts > MAXAUTHATTEMPT) {
49 if ((aup->authattempts % 100) == 0)
b7a95f03 50 chanservwallmessage("Warning: User %s!%s@%s attempted to auth %d times. Last attempt: %s %s %s",
c0181971 51 sender->nick, sender->ident, sender->host->name->content, aup->authattempts, authtype, cargv[0], cargv[1]);
1dd6d55d 52 chanservstdmessage(sender, QM_AUTHFAIL);
b7a95f03 53 cs_log(sender,"%s FAIL too many auth attempts (last attempt: %s %s %s)", authtype, authtype, cargv[0], cargv[1]);
1dd6d55d 54 return CMD_ERROR;
55 }
56
57 if (!(rup=findreguserbynick(cargv[0]))) {
58 chanservstdmessage(sender, QM_AUTHFAIL);
b7a95f03 59 cs_log(sender,"%s FAIL bad username %s",authtype,cargv[0]);
1dd6d55d 60 return CMD_ERROR;
61 }
62
b7a95f03
CP
63 if (!challenge) {
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]);
67 return CMD_ERROR;
68 }
69 } else {
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);
73 return CMD_ERROR;
74 }
1dd6d55d 75 }
76
f3b0017b 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);
80 return CMD_ERROR;
81 }
82
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);
88 toomanyauths=1;
89 }
90 }
91
92 for (onp=anp->nicks;onp;onp=onp->nextbyauthname) {
93 if (toomanyauths) {
94 chanservstdmessage(onp, QM_OTHERUSERAUTHEDLIMIT, sender->nick, sender->ident, sender->host->name->content, MAXAUTHCOUNT);
95 } else {
96 chanservstdmessage(onp, QM_OTHERUSERAUTHED, sender->nick, sender->ident, sender->host->name->content);
97 }
98 }
99
100 if (toomanyauths)
101 return CMD_ERROR;
102
1dd6d55d 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);
108
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));
112 rup->suspendby=0;
113 rup->suspendexp=0;
114 freesstring(rup->suspendreason);
115 rup->suspendreason=0;
116 }
117
1dd6d55d 118 csdb_updateuser(rup);
119
c0587316 120 if (UIsSuspended(rup)) {
1dd6d55d 121 /* plain suspend */
122 chanservstdmessage(sender, QM_AUTHSUSPENDED);
fc567a69
P
123 if(rup->suspendreason)
124 chanservstdmessage(sender, QM_REASON, rup->suspendreason->content);
1dd6d55d 125 if (rup->suspendexp) {
126 struct tm* tmp;
127 char buf[200];
128
129 tmp=gmtime(&(rup->suspendexp));
130 strftime(buf, 15, "%d/%m/%y %H:%M", tmp);
131 chanservstdmessage(sender, QM_EXPIRES, buf);
132 }
133 return CMD_ERROR;
134 }
135
1dd6d55d 136
137 chanservstdmessage(sender, QM_AUTHOK, rup->username);
b7a95f03
CP
138
139 cs_log(sender,"%s OK username %s", authtype,rup->username);
23b85e10 140 localusersetaccountwithuserid(sender, rup->username, rup->ID);;
1dd6d55d 141
142 return CMD_OK;
143}
b7a95f03
CP
144
145int csa_doauth(void *source, int cargc, char **cargv) {
146 return csa_auth(source, cargc, cargv, NULL);
147}