]>
Commit | Line | Data |
---|---|---|
c86edd1d Q |
1 | /* chanservprivs.c */ |
2 | ||
3 | #include "chanserv.h" | |
4 | #include "../nick/nick.h" | |
5 | #include "../lib/irc_string.h" | |
6 | #include <string.h> | |
7 | #include <ctype.h> | |
8 | ||
9 | int cs_privcheck(int privnum, nick *np) { | |
10 | reguser *rup=NULL; | |
11 | ||
12 | if (np) | |
13 | rup=getreguserfromnick(np); | |
14 | ||
15 | switch(privnum) { | |
16 | case QPRIV_SUSPENDBYPASS: | |
17 | case QPRIV_VIEWCHANFLAGS: | |
18 | case QPRIV_VIEWFULLCHANLEV: | |
19 | case QPRIV_VIEWFULLWHOIS: | |
20 | case QPRIV_VIEWCHANMODES: | |
21 | case QPRIV_VIEWAUTOLIMIT: | |
22 | case QPRIV_VIEWBANTIMER: | |
23 | case QPRIV_VIEWUSERFLAGS: | |
e086f1b5 | 24 | case QPRIV_VIEWCHANSUSPENSION: |
c86edd1d Q |
25 | return (rup && UHasHelperPriv(rup)); |
26 | ||
27 | case QPRIV_VIEWCOMMENTS: | |
28 | case QPRIV_VIEWEMAIL: | |
29 | case QPRIV_CHANGECHANLEV: | |
30 | case QPRIV_CHANGECHANFLAGS: | |
31 | case QPRIV_CHANGECHANMODES: | |
32 | case QPRIV_CHANGEAUTOLIMIT: | |
33 | case QPRIV_CHANGEBANTIMER: | |
34 | case QPRIV_CHANGEUSERFLAGS: | |
e086f1b5 | 35 | case QPRIV_VIEWSUSPENDEDBY: |
9de8d198 | 36 | case QPRIV_VIEWWALLMESSAGE: /* if you change VIEWWALLMESSAGE alter chanservwallmessage too */ |
c86edd1d Q |
37 | return (np && rup && IsOper(np) && UHasOperPriv(rup)); |
38 | ||
103521a1 | 39 | default: /* By default opers can override anything */ |
40 | return (np && rup && IsOper(np) && UHasOperPriv(rup)); | |
c86edd1d Q |
41 | } |
42 | } | |
43 | ||
44 | /* Generic access check function. | |
45 | * Note that the chanindex is returned for success, this | |
46 | * can be used to avoid duplicate hash lookups */ | |
47 | ||
48 | chanindex *cs_checkaccess(nick *np, const char *chan, unsigned int flags, | |
49 | chanindex *cip, const char *cmdname, int priv, int quiet) { | |
50 | reguser *rup=getreguserfromnick(np); | |
51 | regchan *rcp; | |
52 | regchanuser *rcup=NULL; | |
53 | unsigned long *lp; | |
54 | ||
55 | if ((flags & CA_AUTHED) && !rup) | |
56 | return NULL; | |
57 | ||
58 | if (!cip && !(cip=findchanindex(chan))) { | |
59 | if (!quiet) chanservstdmessage(np, QM_UNKNOWNCHAN, chan); | |
60 | return NULL; | |
61 | } | |
62 | ||
63 | if (!(rcp=cip->exts[chanservext]) || | |
64 | (CIsSuspended(rcp) && !cs_privcheck(QPRIV_SUSPENDBYPASS, np))) { | |
65 | if (!quiet) chanservstdmessage(np, QM_UNKNOWNCHAN, cip->name->content); | |
66 | return NULL; | |
67 | } | |
e70833ab | 68 | |
69 | if (rcp && rup) | |
70 | rcup=findreguseronchannel(rcp, rup); | |
c86edd1d | 71 | |
e4946b42 | 72 | if (!cs_privcheck(priv,np)) { |
c86edd1d Q |
73 | if ((flags & CA_VOICEPRIV) && |
74 | !(rcp && (CIsVoiceAll(rcp)) && | |
5cde8af0 | 75 | !(cip->channel && (nickbanned_visible(np, cip->channel) || IsInviteOnly(cip->channel)))) && |
c86edd1d Q |
76 | !(rcup && (CUHasVoicePriv(rcup)))) { |
77 | if (!quiet) chanservstdmessage(np, QM_NOACCESSONCHAN, cip->name->content, cmdname); | |
78 | return NULL; | |
79 | } | |
80 | ||
81 | if ((flags & CA_NEEDKNOWN) && !rup) { | |
82 | if (!quiet) chanservstdmessage(np, QM_NOACCESSONCHAN, cip->name->content, cmdname); | |
83 | return NULL; | |
84 | } | |
85 | ||
e70833ab | 86 | if ((flags & CA_NEEDKNOWN) && (!rcup || !CUKnown(rcup))) { |
c86edd1d Q |
87 | if (!quiet) chanservstdmessage(np, QM_NOACCESSONCHAN, cip->name->content, cmdname); |
88 | return NULL; | |
89 | } | |
90 | ||
91 | if (((flags & CA_OPPRIV ) && !CUHasOpPriv(rcup)) || | |
92 | ((flags & CA_MASTERPRIV) && !CUHasMasterPriv(rcup)) || | |
93 | ((flags & CA_OWNERPRIV) && !CUIsOwner(rcup)) || | |
94 | ((flags & CA_TOPICPRIV ) && !CUHasTopicPriv(rcup))) { | |
95 | if (!quiet) chanservstdmessage(np, QM_NOACCESSONCHAN, cip->name->content, cmdname); | |
96 | return NULL; | |
97 | } | |
98 | } | |
99 | ||
100 | if ((flags & CA_ONCHANREQ) && !(cip->channel)) { | |
101 | if (!quiet) chanservstdmessage(np, QM_NOTONCHAN, cip->name->content); | |
102 | return NULL; | |
103 | } | |
104 | ||
105 | if (cip->channel) { | |
106 | lp=getnumerichandlefromchanhash(cip->channel->users, np->numeric); | |
107 | ||
108 | if ((flags & CA_ONCHANREQ) && !lp) { | |
109 | if (!quiet) chanservstdmessage(np, QM_NOTONCHAN, cip->name->content); | |
110 | return NULL; | |
111 | } | |
112 | ||
113 | if ((flags & CA_OPPED) && !(*lp & CUMODE_OP)) { | |
114 | if (!quiet) chanservstdmessage(np, QM_NOTOPPED, cip->name->content); | |
115 | return NULL; | |
116 | } | |
117 | ||
118 | if ((flags & CA_DEOPPED) && (*lp & CUMODE_OP)) { | |
119 | if (!quiet) chanservstdmessage(np, QM_ALREADYOPPED, cip->name->content); | |
120 | return NULL; | |
121 | } | |
122 | ||
123 | if ((flags & CA_VOICED) && !(*lp & CUMODE_VOICE)) { | |
124 | if (!quiet) chanservstdmessage(np, QM_NOTVOICED, cip->name->content); | |
125 | return NULL; | |
126 | } | |
127 | ||
128 | if ((flags & CA_DEVOICED) && (*lp & CUMODE_VOICE)) { | |
129 | if (!quiet) chanservstdmessage(np, QM_ALREADYVOICED, cip->name->content); | |
130 | return NULL; | |
131 | } | |
132 | ||
133 | if ((flags & CA_OFFCHAN) && lp) { | |
134 | if (!quiet) chanservstdmessage(np, QM_ALREADYONCHAN, cip->name->content); | |
135 | return NULL; | |
136 | } | |
137 | } | |
138 | ||
139 | return cip; | |
140 | } | |
141 |