]>
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 | ||
18 | int csa_doauth(void *source, int cargc, char **cargv) { | |
19 | reguser *rup; | |
20 | activeuser* aup; | |
21 | nick *sender=source; | |
22 | nicklist *nl = NULL; | |
23 | char userhost[USERLEN+HOSTLEN+2]; | |
24 | int ucount=0; | |
25 | ||
26 | if (cargc<2) { | |
27 | chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "auth"); | |
28 | return CMD_ERROR; | |
29 | } | |
30 | ||
31 | if (!(aup = getactiveuserfromnick(sender))) | |
32 | return CMD_ERROR; | |
33 | ||
34 | aup->authattempts++; | |
35 | if (aup->authattempts > MAXAUTHATTEMPT) { | |
36 | if ((aup->authattempts % 100) == 0) | |
37 | chanservwallmessage("Warning: User %s!%s@%s attempted to auth %d times. Last attempt: AUTH %s %s", | |
38 | nl->np->nick, nl->np->ident, nl->np->host->name->content, cargv[0], cargv[1]); | |
39 | chanservstdmessage(sender, QM_AUTHFAIL); | |
40 | cs_log(sender,"AUTH FAIL too many auth attempts (last attempt: AUTH %s %s)",cargv[0], cargv[1]); | |
41 | return CMD_ERROR; | |
42 | } | |
43 | ||
44 | if (!(rup=findreguserbynick(cargv[0]))) { | |
45 | chanservstdmessage(sender, QM_AUTHFAIL); | |
46 | cs_log(sender,"AUTH FAIL bad username %s",cargv[0]); | |
47 | return CMD_ERROR; | |
48 | } | |
49 | ||
50 | if (!checkpassword(rup, cargv[1])) { | |
51 | chanservstdmessage(sender, QM_AUTHFAIL); | |
52 | cs_log(sender,"AUTH FAIL username %s bad password %s",rup->username,cargv[1]); | |
53 | return CMD_ERROR; | |
54 | } | |
55 | ||
56 | rup->lastauth=time(NULL); | |
57 | sprintf(userhost,"%s@%s",sender->ident,sender->host->name->content); | |
58 | if (rup->lastuserhost) | |
59 | freesstring(rup->lastuserhost); | |
60 | rup->lastuserhost=getsstring(userhost,USERLEN+HOSTLEN+1); | |
61 | ||
62 | if (UHasSuspension(rup) && rup->suspendexp && (time(0) >= rup->suspendexp)) { | |
63 | /* suspension has expired, remove it */ | |
64 | rup->flags&=(~(QUFLAG_SUSPENDED|QUFLAG_GLINE|QUFLAG_DELAYEDGLINE)); | |
65 | rup->suspendby=0; | |
66 | rup->suspendexp=0; | |
67 | freesstring(rup->suspendreason); | |
68 | rup->suspendreason=0; | |
69 | } | |
70 | ||
71 | if (UIsNeedAuth(rup)) | |
72 | rup->flags&=~(QUFLAG_NEEDAUTH); | |
73 | csdb_updateuser(rup); | |
74 | ||
75 | if (UIsDelayedGline(rup)) { | |
76 | /* delayed-gline - schedule the user's squelching */ | |
77 | deleteschedule(NULL, &chanservdgline, (void*)rup); /* icky, but necessary unless we stick more stuff in reguser structure */ | |
78 | scheduleoneshot(time(NULL)+rand()%900, &chanservdgline, (void*)rup); | |
79 | } | |
80 | else if (UIsGline(rup)) { | |
81 | /* instant-gline - lets be lazy and set a schedule expiring now :) */ | |
82 | deleteschedule(NULL, &chanservdgline, (void*)rup); /* icky, but necessary unless we stick more stuff in reguser structure */ | |
83 | scheduleoneshot(time(NULL), &chanservdgline, (void*)rup); | |
84 | } | |
85 | else if (UIsSuspended(rup)) { | |
86 | /* plain suspend */ | |
87 | chanservstdmessage(sender, QM_AUTHSUSPENDED); | |
fc567a69 P |
88 | if(rup->suspendreason) |
89 | chanservstdmessage(sender, QM_REASON, rup->suspendreason->content); | |
1dd6d55d | 90 | if (rup->suspendexp) { |
91 | struct tm* tmp; | |
92 | char buf[200]; | |
93 | ||
94 | tmp=gmtime(&(rup->suspendexp)); | |
95 | strftime(buf, 15, "%d/%m/%y %H:%M", tmp); | |
96 | chanservstdmessage(sender, QM_EXPIRES, buf); | |
97 | } | |
98 | return CMD_ERROR; | |
99 | } | |
100 | ||
101 | if (!UHasHelperPriv(rup) && !UIsNoAuthLimit(rup)) { | |
102 | for (nl=rup->nicks; nl; nl=nl->next) | |
103 | ucount++; | |
104 | ||
105 | if (ucount >= MAXAUTHCOUNT) { | |
106 | chanservstdmessage(sender, QM_TOOMANYAUTHS); | |
107 | return CMD_ERROR; | |
108 | } | |
109 | } | |
110 | ||
111 | chanservstdmessage(sender, QM_AUTHOK, rup->username); | |
112 | cs_log(sender,"AUTH OK username %s", rup->username); | |
113 | localusersetaccount(sender, rup->username); | |
114 | ||
115 | return CMD_OK; | |
116 | } |