2 * Copyright (C) 2006 Jilles Tjoelker
3 * Copyright (C) 2006 Stephen Bennett <spb@gentoo.org>
4 * Copyright (C) 2016 Jason Volk <jason@zemos.net>
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice is present in all copies.
10 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
11 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
12 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
13 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
14 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
15 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
16 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
17 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
18 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
19 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
20 * POSSIBILITY OF SUCH DAMAGE.
32 #include "s_newconf.h"
33 #include "privilege.h"
37 void set_mode(struct Client
*const target
,
38 const char *const str
)
48 user_mode(target
, target
, 3, mode
);
53 void set_privset(struct Client
*const source
,
54 struct Client
*const target
,
55 const char *const privset_name
)
57 struct PrivilegeSet
*const privset
= privilegeset_get(privset_name
);
60 sendto_one_notice(source
, ":There is no privilege set named '%s'.", privset_name
);
64 if(IsOper(target
) && target
->localClient
->privset
== privset
)
66 sendto_one_notice(source
, ":%s already has role of %s.", target
->name
, privset_name
);
72 sendto_one_notice(target
, ":%s has changed your role to %s.", source
->name
, privset_name
);
73 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
, "%s has changed %s's role to %s.", get_oper_name(source
), target
->name
, privset_name
);
74 target
->localClient
->privset
= privset
;
78 struct oper_conf oper
=
80 .name
= (char *)privset
->name
,
84 oper_up(target
, &oper
);
85 set_mode(target
, "+o");
86 sendto_one_notice(target
, ":%s has granted you the role of %s.", source
->name
, privset_name
);
87 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
, "%s has granted %s the role of %s.", get_oper_name(source
), target
->name
, privset_name
);
92 void grant_revoke(struct Client
*const source
,
93 struct Client
*const target
)
97 sendto_one_notice(source
, ":You can't deoper someone who isn't an oper.");
101 set_mode(target
, "-o");
102 sendto_one_notice(target
, ":%s has deopered you.", source
->name
);
103 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
, "%s has deopered %s.", get_oper_name(source
), target
->name
);
108 void grant(struct MsgBuf
*msgbuf
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
110 if(MyClient(source_p
) && !HasPrivilege(source_p
, "oper:grant"))
112 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "grant");
118 sendto_one_notice(source_p
, ":usage GRANT: <target nickname> <privilegese name | 'revoke'>");
122 struct Client
*const target_p
= find_person(parv
[1]);
126 if(IsPerson(source_p
))
127 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
, form_str(ERR_NOSUCHNICK
), parv
[1]);
132 if(!MyClient(source_p
) && !find_shared_conf(source_p
->username
, source_p
->host
, source_p
->servptr
->name
, SHARED_GRANT
))
134 sendto_one_notice(source_p
, ":GRANT failed: You have no shared configuration block on this server.");
138 if(MyClient(target_p
))
140 if(irccmp(parv
[2], "revoke") == 0)
141 grant_revoke(source_p
, target_p
);
143 set_privset(source_p
, target_p
, parv
[2]);
145 else if(MyClient(source_p
))
147 sendto_one(target_p
, ":%s ENCAP %s GRANT %s %s",
148 get_id(source_p
, target_p
),
149 target_p
->servptr
->name
,
150 get_id(target_p
, target_p
),
157 struct Message msgtab
=
170 mapi_clist_av1 grant_clist
[] =
176 static const char grant_desc
[] =
177 "Provides the grant facility for giving other users specific privilege sets";