]>
Commit | Line | Data |
---|---|---|
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 | ||
36 | if (alg) { | |
37 | challenge=1; | |
38 | authtype = "CHALLENGEAUTH"; | |
39 | } else if (cargc<2) { | |
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) | |
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, aup->authattempts, 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]); | |
54 | return CMD_ERROR; | |
55 | } | |
56 | ||
57 | if (!(rup=findreguserbynick(cargv[0]))) { | |
58 | chanservstdmessage(sender, QM_AUTHFAIL); | |
59 | cs_log(sender,"%s FAIL bad username %s",authtype,cargv[0]); | |
60 | return CMD_ERROR; | |
61 | } | |
62 | ||
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 | } | |
75 | } | |
76 | ||
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 | ||
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 | ||
118 | csdb_updateuser(rup); | |
119 | ||
120 | if (UIsSuspended(rup)) { | |
121 | /* plain suspend */ | |
122 | chanservstdmessage(sender, QM_AUTHSUSPENDED); | |
123 | if(rup->suspendreason) | |
124 | chanservstdmessage(sender, QM_REASON, rup->suspendreason->content); | |
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 | ||
136 | ||
137 | chanservstdmessage(sender, QM_AUTHOK, rup->username); | |
138 | ||
139 | cs_log(sender,"%s OK username %s", authtype,rup->username); | |
140 | localusersetaccountwithuserid(sender, rup->username, rup->ID);; | |
141 | ||
142 | return CMD_OK; | |
143 | } | |
144 | ||
145 | int csa_doauth(void *source, int cargc, char **cargv) { | |
146 | return csa_auth(source, cargc, cargv, NULL); | |
147 | } |