]>
Commit | Line | Data |
---|---|---|
bc6c8fbe CP |
1 | /* Automatically generated by refactor.pl. |
2 | * | |
3 | * | |
4 | * CMDNAME: ticketauth | |
5 | * CMDLEVEL: QCMD_SECURE | QCMD_NOTAUTHED | QCMD_HIDDEN | |
6 | * CMDARGS: 5 | |
7 | * CMDDESC: Authenticates you on the bot using a ticket. | |
8 | * CMDFUNC: csa_doticketauth | |
9 | * CMDPROTO: int csa_doticketauth(void *source, int cargc, char **cargv); | |
10 | * CMDHELP: Usage: ticketauth <ticket> | |
11 | * CMDHELP: This is an internal QuakeNet function, there's no point in | |
12 | * CMDHELP: asking for details on how it works cos' you'll not get any! | |
13 | */ | |
14 | ||
15 | #include "../chanserv.h" | |
16 | #include <stdio.h> | |
17 | #include <time.h> | |
18 | ||
19 | int csa_completeauth(nick *sender, reguser *rup, char *authtype); | |
20 | ||
21 | int csa_doticketauth(void *source, int cargc, char **cargv) { | |
22 | activeuser* aup; | |
23 | time_t t; | |
24 | nick *sender=(nick *)source; | |
25 | long uid; | |
26 | int ret; | |
27 | reguser *rup; | |
28 | time_t logintimestamp, expiry; | |
29 | char buf[512], *digest, *junk; | |
30 | ||
31 | if(cargc!=5) { | |
32 | chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "ticketauth"); | |
33 | return CMD_ERROR; | |
34 | } | |
35 | ||
36 | if (!(aup=getactiveuserfromnick(sender))) | |
37 | return CMD_ERROR; | |
38 | ||
39 | t = time(NULL); | |
40 | ||
41 | uid = atoi(cargv[0]); | |
42 | logintimestamp = atoi(cargv[1]); | |
43 | expiry = atoi(cargv[2]); | |
44 | junk = cargv[3]; | |
45 | digest = cargv[4]; | |
46 | ||
47 | if(t < logintimestamp) { | |
48 | chanservstdmessage(sender, QM_TICKETNOTYETVALID); | |
49 | return CMD_ERROR; | |
50 | } | |
51 | if(t > expiry) { | |
52 | chanservstdmessage(sender, QM_TICKETEXPIRED); | |
53 | return CMD_ERROR; | |
54 | } | |
55 | ||
56 | snprintf(buf, sizeof(buf), "%ld %jd %jd %s", uid, (intmax_t)logintimestamp, (intmax_t)expiry, junk); | |
57 | ||
58 | ret = csc_verifyqticket(buf, digest); | |
59 | if(ret < 0) { | |
60 | chanservstdmessage(sender, QM_CONFIGURATIONERROR); | |
61 | return CMD_ERROR; | |
62 | } else if(ret > 0) { | |
63 | chanservstdmessage(sender, QM_INVALIDHMAC); | |
64 | return CMD_ERROR; | |
65 | } | |
66 | ||
67 | if(!(rup=findreguserbyID(uid))) { | |
68 | chanservstdmessage(sender, QM_UNKNOWNUSER, "??"); | |
69 | return CMD_ERROR; | |
70 | } | |
71 | ||
72 | if(rup->lastpasschange >= logintimestamp) { | |
73 | chanservstdmessage(sender, QM_PASSEMAILCHANGED); | |
74 | return CMD_ERROR; | |
75 | } | |
76 | ||
77 | return csa_completeauth(sender, rup, "TICKETAUTH"); | |
78 | } |