]>
Commit | Line | Data |
---|---|---|
5a4ec14f | 1 | /* |
2 | * CMDNAME: giveowner | |
3 | * CMDLEVEL: QCMD_AUTHED | |
4 | * CMDARGS: 3 | |
5 | * CMDDESC: Gives total control over a channel to another user. | |
6 | * CMDFUNC: csc_dogiveowner | |
7 | * CMDPROTO: int csc_dogiveowner(void *source, int cargc, char **cargv); | |
1e32d528 | 8 | * CMDHELP: Usage: GIVEOWNER <channel> <user> [<code>] |
9 | * CMDHELP: Gives complete control (+n flag) to the named user on the channel. The new owner | |
10 | * CMDHELP: will have full control over the channel, including the ability to remove the | |
11 | * CMDHELP: existing owner(s). As a precaution the named user must already have master (+m) | |
12 | * CMDHELP: access on the channel. Use this command with extreme caution. Where: | |
13 | * CMDHELP: channel - channel to use | |
14 | * CMDHELP: user - user to give owner to, either a nickname on the network or #accountname. | |
15 | * CMDHELP: code - a unique code used to authorize the operation. If the code is not | |
16 | * CMDHELP: supplied, the appropriate code will be provided together with a | |
17 | * CMDHELP: warning about the dangers of this command. If the wrong code is | |
18 | * CMDHELP: entered owner access will not be granted. | |
19 | * CMDHELP: GIVEOWNER requires owner (+n) access on the named channel. | |
5a4ec14f | 20 | */ |
21 | ||
22 | #include "../chanserv.h" | |
23 | #include "../../nick/nick.h" | |
24 | #include "../../lib/flags.h" | |
25 | #include "../../lib/irc_string.h" | |
26 | #include "../../channel/channel.h" | |
27 | #include "../../parser/parser.h" | |
28 | #include "../../irc/irc.h" | |
29 | #include "../../localuser/localuserchannel.h" | |
30 | #include <string.h> | |
31 | #include <stdio.h> | |
32 | ||
33 | int csc_dogiveowner(void *source, int cargc, char **cargv) { | |
34 | nick *sender=source; | |
35 | chanindex *cip; | |
36 | regchan *rcp; | |
37 | regchanuser *rcup; | |
38 | reguser *rup=getreguserfromnick(sender), *target; | |
39 | char flagbuf[30]; | |
40 | flag_t oldflags; | |
41 | unsigned int thehash; | |
42 | char hashstr[100]; | |
43 | ||
44 | if (cargc<2) { | |
45 | chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "giveowner"); | |
46 | return CMD_ERROR; | |
47 | } | |
48 | ||
49 | /* You need to either be +n or have the relevant override... */ | |
50 | if (!(cip=cs_checkaccess(sender, cargv[0], CA_OWNERPRIV, | |
51 | NULL, "chanlev", QPRIV_CHANGECHANLEV, 0))) | |
52 | return CMD_ERROR; | |
53 | ||
54 | rcp=cip->exts[chanservext]; | |
55 | ||
56 | if (!(target=findreguser(sender, cargv[1]))) | |
57 | return CMD_ERROR; /* If there was an error, findreguser will have sent a message saying why.. */ | |
58 | ||
59 | rcup=findreguseronchannel(rcp, target); | |
60 | ||
61 | /* You can only promote a master */ | |
62 | if (!rcup || !(rcup->flags & QCUFLAG_MASTER)) { | |
63 | chanservstdmessage(sender,QM_GIVEOWNERNOTMASTER,target->username,cip->name->content); | |
64 | return CMD_ERROR; | |
65 | } | |
66 | ||
67 | /* Can't promote if already owner */ | |
68 | if (rcup->flags & QCUFLAG_OWNER) { | |
69 | chanservstdmessage(sender,QM_GIVEOWNERALREADYOWNER,target->username,cip->name->content); | |
70 | return CMD_ERROR; | |
71 | } | |
72 | ||
73 | /* Compute ze hash */ | |
74 | sprintf(hashstr,"%u.%u.%u",rcp->ID,target->ID,rup->ID); | |
75 | thehash=crc32(hashstr); | |
76 | ||
77 | sprintf(hashstr,"%x",thehash); | |
78 | ||
79 | if (cargc<3) { | |
80 | chanservstdmessage(sender,QM_GIVEOWNERNEEDHASH,cip->name->content,target->username, | |
81 | cip->name->content,target->username,hashstr); | |
82 | return CMD_OK; | |
83 | } | |
84 | ||
85 | if (ircd_strcmp(cargv[2], hashstr)) { | |
86 | chanservstdmessage(sender,QM_GIVEOWNERWRONGHASH,target->username, | |
87 | cip->name->content); | |
88 | return CMD_ERROR; | |
89 | } | |
90 | ||
91 | /* OK, hash matches, do it. */ | |
92 | oldflags = rcup->flags; | |
93 | rcup->flags |= QCUFLAG_OWNER; | |
94 | ||
95 | chanservstdmessage(sender,QM_DONE); | |
96 | ||
97 | strcpy(flagbuf,printflags(oldflags,rcuflags)); | |
98 | cs_log(sender,"GIVEOWNER %s #%s (%s -> %s)",cip->name->content,rcup->user->username, | |
99 | flagbuf,printflags(rcup->flags,rcuflags)); | |
100 | ||
101 | csdb_chanlevhistory_insert(rcp, sender, rcup->user, oldflags, rcup->flags); | |
102 | csdb_updatechanuser(rcup); | |
103 | ||
104 | return CMD_OK; | |
105 | } |