]>
Commit | Line | Data |
---|---|---|
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 | 26 | int 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; |
152583d5 | 35 | time_t now; |
1dd6d55d | 36 | |
b7a95f03 CP |
37 | if (alg) { |
38 | challenge=1; | |
39 | authtype = "CHALLENGEAUTH"; | |
40 | } else if (cargc<2) { | |
1dd6d55d | 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) | |
b7a95f03 | 51 | chanservwallmessage("Warning: User %s!%s@%s attempted to auth %d times. Last attempt: %s %s %s", |
c0181971 | 52 | sender->nick, sender->ident, sender->host->name->content, aup->authattempts, authtype, cargv[0], cargv[1]); |
1dd6d55d | 53 | chanservstdmessage(sender, QM_AUTHFAIL); |
b7a95f03 | 54 | cs_log(sender,"%s FAIL too many auth attempts (last attempt: %s %s %s)", authtype, authtype, cargv[0], cargv[1]); |
1dd6d55d | 55 | return CMD_ERROR; |
56 | } | |
57 | ||
58 | if (!(rup=findreguserbynick(cargv[0]))) { | |
59 | chanservstdmessage(sender, QM_AUTHFAIL); | |
b7a95f03 | 60 | cs_log(sender,"%s FAIL bad username %s",authtype,cargv[0]); |
1dd6d55d | 61 | return CMD_ERROR; |
62 | } | |
63 | ||
b7a95f03 CP |
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 | } | |
1dd6d55d | 76 | } |
77 | ||
f3b0017b | 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 | ||
152583d5 | 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 | ||
1dd6d55d | 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 | ||
1dd6d55d | 125 | csdb_updateuser(rup); |
126 | ||
c0587316 | 127 | if (UIsSuspended(rup)) { |
1dd6d55d | 128 | /* plain suspend */ |
129 | chanservstdmessage(sender, QM_AUTHSUSPENDED); | |
fc567a69 P |
130 | if(rup->suspendreason) |
131 | chanservstdmessage(sender, QM_REASON, rup->suspendreason->content); | |
79313d98 CP |
132 | if (rup->suspendexp) |
133 | chanservstdmessage(sender, QM_EXPIRES, rup->suspendexp); | |
1dd6d55d | 134 | return CMD_ERROR; |
135 | } | |
136 | ||
1dd6d55d | 137 | |
138 | chanservstdmessage(sender, QM_AUTHOK, rup->username); | |
b7a95f03 CP |
139 | |
140 | cs_log(sender,"%s OK username %s", authtype,rup->username); | |
3294b10b CP |
141 | |
142 | localusersetaccount(sender, rup->username, rup->ID, cs_accountflagmap(rup), rup->lastauth); | |
1dd6d55d | 143 | |
144 | return CMD_OK; | |
145 | } | |
b7a95f03 CP |
146 | |
147 | int csa_doauth(void *source, int cargc, char **cargv) { | |
148 | return csa_auth(source, cargc, cargv, NULL); | |
149 | } |