2 * m_privs.c: Shows effective operator privileges
4 * Copyright (C) 2008 Jilles Tjoelker
5 * Copyright (C) 2008 charybdis development team
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
11 * 1.Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * 2.Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3.The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
41 #include "s_newconf.h"
43 static int me_privs(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[]);
44 static int mo_privs(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[]);
46 struct Message privs_msgtab
= {
47 "PRIVS", 0, 0, 0, MFLG_SLOW
,
48 {mg_unreg
, mg_not_oper
, mg_ignore
, mg_ignore
, {me_privs
, 0}, {mo_privs
, 0}}
51 mapi_clist_av1 privs_clist
[] = {
56 /* XXX this is a copy, not so nice */
63 static struct mode_table oper_table
[] = {
64 /*{"encrypted", OPER_ENCRYPTED },*/
65 {"local_kill", OPER_LOCKILL
},
66 {"global_kill", OPER_GLOBKILL
/*|OPER_LOCKILL*/ },
67 {"remote", OPER_REMOTE
},
68 {"kline", OPER_KLINE
},
69 {"unkline", OPER_UNKLINE
},
70 {"gline", OPER_GLINE
},
71 {"nick_changes", OPER_NICKS
},
72 {"rehash", OPER_REHASH
},
74 {"admin", OPER_ADMIN
},
75 {"hidden_admin", OPER_HADMIN
},
76 {"xline", OPER_XLINE
},
78 {"operwall", OPER_OPERWALL
},
79 {"oper_spy", OPER_SPY
},
80 {"hidden_oper", OPER_INVIS
},
81 {"remoteban", OPER_REMOTEBAN
},
82 {"mass_notice", OPER_MASSNOTICE
},
86 /* there is no such table like this anywhere else */
87 static struct mode_table auth_client_table
[] = {
88 {"resv_exempt", FLAGS2_EXEMPTRESV
},
89 {"gline_exempt", FLAGS2_EXEMPTGLINE
},
90 {"kline_exempt", FLAGS2_EXEMPTKLINE
},
91 {"flood_exempt", FLAGS2_EXEMPTFLOOD
},
92 {"spambot_exempt", FLAGS2_EXEMPTSPAMBOT
},
93 {"shide_exempt", FLAGS2_EXEMPTSHIDE
},
94 {"jupe_exempt", FLAGS2_EXEMPTJUPE
},
98 DECLARE_MODULE_AV1(privs
, NULL
, NULL
, privs_clist
, NULL
, NULL
, "");
100 static void show_privs(struct Client
*source_p
, struct Client
*target_p
)
103 struct mode_table
*p
;
107 while (p
->name
!= NULL
)
109 if (target_p
->flags2
& p
->mode
)
112 strlcat(buf
, " ", sizeof buf
);
113 strlcat(buf
, p
->name
, sizeof buf
);
117 if (IsOper(target_p
))
120 strlcat(buf
, " ", sizeof buf
);
121 strlcat(buf
, "operator:", sizeof buf
);
122 strlcat(buf
, target_p
->localClient
->opername
, sizeof buf
);
124 p
= &auth_client_table
[0];
125 while (p
->name
!= NULL
)
127 if (target_p
->flags2
& p
->mode
)
130 strlcat(buf
, " ", sizeof buf
);
131 strlcat(buf
, p
->name
, sizeof buf
);
135 sendto_one_numeric(source_p
, RPL_PRIVS
, form_str(RPL_PRIVS
),
136 target_p
->name
, buf
);
139 static int me_privs(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
141 struct Client
*target_p
;
143 if (!IsOper(source_p
) || parc
< 2 || EmptyString(parv
[1]))
146 /* we cannot show privs for remote clients */
147 if((target_p
= find_person(parv
[1])) && MyClient(target_p
))
148 show_privs(source_p
, target_p
);
153 static int mo_privs(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
155 struct Client
*target_p
;
157 if (parc
< 2 || EmptyString(parv
[1]))
161 target_p
= find_named_person(parv
[1]);
162 if (target_p
== NULL
)
164 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
165 form_str(ERR_NOSUCHNICK
), parv
[1]);
170 if (MyClient(target_p
))
171 show_privs(source_p
, target_p
);
173 sendto_one(target_p
, ":%s ENCAP %s PRIVS %s",
174 get_id(source_p
, target_p
),
175 target_p
->servptr
->name
,