]>
Commit | Line | Data |
---|---|---|
1dd6d55d | 1 | /* Automatically generated by refactor.pl. |
2 | * | |
3 | * | |
4 | * CMDNAME: login | |
5 | * CMDLEVEL: QCMD_SECURE | QCMD_NOTAUTHED | |
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 | */ | |
11 | ||
12 | #include "../chanserv.h" | |
13 | #include "../authlib.h" | |
14 | #include "../../lib/irc_string.h" | |
15 | #include <stdio.h> | |
16 | #include <string.h> | |
17 | ||
b7a95f03 | 18 | int csa_auth(void *source, int cargc, char **cargv, CRAlgorithm alg) { |
1dd6d55d | 19 | reguser *rup; |
23b85e10 | 20 | activeuser *aup; |
1dd6d55d | 21 | nick *sender=source; |
1dd6d55d | 22 | char userhost[USERLEN+HOSTLEN+2]; |
b7a95f03 CP |
23 | int challenge=0; |
24 | char *authtype = "AUTH"; | |
23b85e10 | 25 | authname *anp; |
1dd6d55d | 26 | |
b7a95f03 CP |
27 | if (alg) { |
28 | challenge=1; | |
29 | authtype = "CHALLENGEAUTH"; | |
30 | } else if (cargc<2) { | |
1dd6d55d | 31 | chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "auth"); |
32 | return CMD_ERROR; | |
33 | } | |
34 | ||
35 | if (!(aup = getactiveuserfromnick(sender))) | |
36 | return CMD_ERROR; | |
37 | ||
38 | aup->authattempts++; | |
39 | if (aup->authattempts > MAXAUTHATTEMPT) { | |
40 | if ((aup->authattempts % 100) == 0) | |
b7a95f03 | 41 | chanservwallmessage("Warning: User %s!%s@%s attempted to auth %d times. Last attempt: %s %s %s", |
23b85e10 | 42 | sender->nick, sender->ident, sender->host->name->content, authtype, cargv[0], cargv[1]); |
1dd6d55d | 43 | chanservstdmessage(sender, QM_AUTHFAIL); |
b7a95f03 | 44 | cs_log(sender,"%s FAIL too many auth attempts (last attempt: %s %s %s)", authtype, authtype, cargv[0], cargv[1]); |
1dd6d55d | 45 | return CMD_ERROR; |
46 | } | |
47 | ||
48 | if (!(rup=findreguserbynick(cargv[0]))) { | |
49 | chanservstdmessage(sender, QM_AUTHFAIL); | |
b7a95f03 | 50 | cs_log(sender,"%s FAIL bad username %s",authtype,cargv[0]); |
1dd6d55d | 51 | return CMD_ERROR; |
52 | } | |
53 | ||
b7a95f03 CP |
54 | if (!challenge) { |
55 | if (!checkpassword(rup, cargv[1])) { | |
56 | chanservstdmessage(sender, QM_AUTHFAIL); | |
57 | cs_log(sender,"%s FAIL username %s bad password %s",authtype,rup->username,cargv[1]); | |
58 | return CMD_ERROR; | |
59 | } | |
60 | } else { | |
61 | if (!checkresponse(rup, aup->entropy, cargv[1], alg)) { | |
62 | chanservstdmessage(sender, QM_AUTHFAIL); | |
63 | cs_log(sender,"%s FAIL username %s bad response",authtype,rup->username); | |
64 | return CMD_ERROR; | |
65 | } | |
1dd6d55d | 66 | } |
67 | ||
68 | rup->lastauth=time(NULL); | |
69 | sprintf(userhost,"%s@%s",sender->ident,sender->host->name->content); | |
70 | if (rup->lastuserhost) | |
71 | freesstring(rup->lastuserhost); | |
72 | rup->lastuserhost=getsstring(userhost,USERLEN+HOSTLEN+1); | |
73 | ||
74 | if (UHasSuspension(rup) && rup->suspendexp && (time(0) >= rup->suspendexp)) { | |
75 | /* suspension has expired, remove it */ | |
76 | rup->flags&=(~(QUFLAG_SUSPENDED|QUFLAG_GLINE|QUFLAG_DELAYEDGLINE)); | |
77 | rup->suspendby=0; | |
78 | rup->suspendexp=0; | |
79 | freesstring(rup->suspendreason); | |
80 | rup->suspendreason=0; | |
81 | } | |
82 | ||
83 | if (UIsNeedAuth(rup)) | |
84 | rup->flags&=~(QUFLAG_NEEDAUTH); | |
85 | csdb_updateuser(rup); | |
86 | ||
87 | if (UIsDelayedGline(rup)) { | |
88 | /* delayed-gline - schedule the user's squelching */ | |
89 | deleteschedule(NULL, &chanservdgline, (void*)rup); /* icky, but necessary unless we stick more stuff in reguser structure */ | |
90 | scheduleoneshot(time(NULL)+rand()%900, &chanservdgline, (void*)rup); | |
23b85e10 | 91 | } else if (UIsGline(rup)) { |
1dd6d55d | 92 | /* instant-gline - lets be lazy and set a schedule expiring now :) */ |
93 | deleteschedule(NULL, &chanservdgline, (void*)rup); /* icky, but necessary unless we stick more stuff in reguser structure */ | |
94 | scheduleoneshot(time(NULL), &chanservdgline, (void*)rup); | |
23b85e10 | 95 | } else if (UIsSuspended(rup)) { |
1dd6d55d | 96 | /* plain suspend */ |
97 | chanservstdmessage(sender, QM_AUTHSUSPENDED); | |
fc567a69 P |
98 | if(rup->suspendreason) |
99 | chanservstdmessage(sender, QM_REASON, rup->suspendreason->content); | |
1dd6d55d | 100 | if (rup->suspendexp) { |
101 | struct tm* tmp; | |
102 | char buf[200]; | |
103 | ||
104 | tmp=gmtime(&(rup->suspendexp)); | |
105 | strftime(buf, 15, "%d/%m/%y %H:%M", tmp); | |
106 | chanservstdmessage(sender, QM_EXPIRES, buf); | |
107 | } | |
108 | return CMD_ERROR; | |
109 | } | |
110 | ||
111 | if (!UHasHelperPriv(rup) && !UIsNoAuthLimit(rup)) { | |
23b85e10 | 112 | anp=findauthname(rup->ID); |
113 | if (!anp || (anp->usercount >= MAXAUTHCOUNT)) { | |
1dd6d55d | 114 | chanservstdmessage(sender, QM_TOOMANYAUTHS); |
115 | return CMD_ERROR; | |
116 | } | |
117 | } | |
118 | ||
119 | chanservstdmessage(sender, QM_AUTHOK, rup->username); | |
b7a95f03 CP |
120 | |
121 | cs_log(sender,"%s OK username %s", authtype,rup->username); | |
23b85e10 | 122 | localusersetaccountwithuserid(sender, rup->username, rup->ID);; |
1dd6d55d | 123 | |
124 | return CMD_OK; | |
125 | } | |
b7a95f03 CP |
126 | |
127 | int csa_doauth(void *source, int cargc, char **cargv) { | |
128 | return csa_auth(source, cargc, cargv, NULL); | |
129 | } |