]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/authcmds/login.c
Various changes to support authname being stored inside the authext.
[irc/quakenet/newserv.git] / chanserv / authcmds / login.c
1 /* Automatically generated by refactor.pl.
2 *
3 *
4 * CMDNAME: login
5 * CMDLEVEL: QCMD_SECURE | QCMD_NOTAUTHED | QCMD_ALIAS
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);
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.
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
26 int csa_auth(void *source, int cargc, char **cargv, CRAlgorithm alg) {
27 reguser *rup;
28 activeuser *aup;
29 nick *sender=source, *onp;
30 char userhost[USERLEN+HOSTLEN+2];
31 int challenge=0;
32 char *authtype = "AUTH";
33 authname *anp;
34 int toomanyauths=0;
35 time_t now;
36
37 if (alg) {
38 challenge=1;
39 authtype = "CHALLENGEAUTH";
40 } else if (cargc<2) {
41 chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "auth");
42 return CMD_ERROR;
43 }
44
45 if (!(aup = getactiveuserfromnick(sender)))
46 return CMD_ERROR;
47
48 aup->authattempts++;
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]);
55 return CMD_ERROR;
56 }
57
58 if (!(rup=findreguserbynick(cargv[0]))) {
59 chanservstdmessage(sender, QM_AUTHFAIL);
60 cs_log(sender,"%s FAIL bad username %s",authtype,cargv[0]);
61 return CMD_ERROR;
62 }
63
64 if (!challenge) {
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]);
68 return CMD_ERROR;
69 }
70 } else {
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);
74 return CMD_ERROR;
75 }
76 }
77
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);
81 return CMD_ERROR;
82 }
83
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);
89 toomanyauths=1;
90 }
91 }
92
93 for (onp=anp->nicks;onp;onp=onp->nextbyauthname) {
94 if (toomanyauths) {
95 chanservstdmessage(onp, QM_OTHERUSERAUTHEDLIMIT, sender->nick, sender->ident, sender->host->name->content, MAXAUTHCOUNT);
96 } else {
97 chanservstdmessage(onp, QM_OTHERUSERAUTHED, sender->nick, sender->ident, sender->host->name->content);
98 }
99 }
100
101 if (toomanyauths)
102 return CMD_ERROR;
103
104 /* Guarantee a unique auth timestamp for each account */
105 now=time(NULL);
106 if (rup->lastauth < now)
107 rup->lastauth=now;
108 else
109 rup->lastauth++;
110
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);
115
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));
119 rup->suspendby=0;
120 rup->suspendexp=0;
121 freesstring(rup->suspendreason);
122 rup->suspendreason=0;
123 }
124
125 csdb_updateuser(rup);
126
127 if (UIsSuspended(rup)) {
128 /* plain suspend */
129 chanservstdmessage(sender, QM_AUTHSUSPENDED);
130 if(rup->suspendreason)
131 chanservstdmessage(sender, QM_REASON, rup->suspendreason->content);
132 if (rup->suspendexp)
133 chanservstdmessage(sender, QM_EXPIRES, rup->suspendexp);
134 return CMD_ERROR;
135 }
136
137
138 chanservstdmessage(sender, QM_AUTHOK, rup->username);
139
140 cs_log(sender,"%s OK username %s", authtype,rup->username);
141
142 localusersetaccount(sender, rup->username, rup->ID, cs_accountflagmap(rup), rup->lastauth);
143
144 return CMD_OK;
145 }
146
147 int csa_doauth(void *source, int cargc, char **cargv) {
148 return csa_auth(source, cargc, cargv, NULL);
149 }