2 * Copyright (C) 2006 Jilles Tjoelker
3 * Copyright (C) 2006 Stephen Bennett <spb@gentoo.org>
15 #include "s_newconf.h"
18 static void mo_grant(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[]);
19 static void me_grant(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[]);
21 static int do_grant(struct Client
*source_p
, struct Client
*target_p
, const char *new_privset
);
23 struct Message grant_msgtab
= {
25 { mg_ignore
, mg_not_oper
, mg_ignore
, mg_ignore
, {me_grant
, 3}, {mo_grant
, 3}}
28 mapi_clist_av1 grant_clist
[] = { &grant_msgtab
, NULL
};
30 static const char grant_desc
[] = "Allows operators to set or remove operator privileges on other users";
32 DECLARE_MODULE_AV2(grant
, NULL
, NULL
, grant_clist
, NULL
, NULL
, NULL
, NULL
, grant_desc
);
35 mo_grant(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
37 struct Client
*target_p
;
39 if(!HasPrivilege(source_p
, "oper:grant"))
41 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "grant");
45 target_p
= find_named_person(parv
[1]);
48 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
49 form_str(ERR_NOSUCHNICK
), parv
[1]);
53 if (MyClient(target_p
))
55 do_grant(source_p
, target_p
, parv
[2]);
59 sendto_one(target_p
, ":%s ENCAP %s GRANT %s %s",
60 get_id(source_p
, target_p
), target_p
->servptr
->name
,
61 get_id(target_p
, target_p
), parv
[2]);
66 me_grant(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
68 struct Client
*target_p
;
70 target_p
= find_person(parv
[1]);
73 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
74 form_str(ERR_NOSUCHNICK
), parv
[1]);
78 do_grant(source_p
, target_p
, parv
[2]);
82 static int do_grant(struct Client
*source_p
, struct Client
*target_p
, const char *new_privset
)
84 int dooper
= 0, dodeoper
= 0;
85 struct PrivilegeSet
*privset
= NULL
, *old_privset
= NULL
;
87 if (!strcasecmp(new_privset
, "deoper"))
89 if (!IsOper(target_p
))
91 sendto_one_notice(source_p
, ":You can't deoper someone who isn't an oper.");
96 sendto_one_notice(target_p
, ":%s is deopering you.", source_p
->name
);
97 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
, "%s is deopering %s.", get_oper_name(source_p
), target_p
->name
);
101 if (!(privset
= privilegeset_get(new_privset
)))
103 sendto_one_notice(source_p
, ":There is no privilege set named '%s'.", new_privset
);
107 if (privset
== target_p
->user
->privset
)
109 sendto_one_notice(source_p
, ":%s already has privilege set %s.", target_p
->name
, target_p
->user
->privset
->name
);
113 if (ConfigFileEntry
.oper_secure_only
&& !IsSecureClient(target_p
))
115 sendto_one_notice(source_p
, ":Cannot GRANT %s, opers must be using secure connections.", target_p
->name
);
122 if (!IsOper(target_p
))
124 sendto_one_notice(target_p
, ":%s is opering you with privilege set %s", source_p
->name
, privset
->name
);
125 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
, "%s is opering %s with privilege set %s", get_oper_name(source_p
), target_p
->name
, privset
->name
);
130 sendto_one_notice(target_p
, ":%s is changing your privilege set to %s", source_p
->name
, privset
->name
);
131 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
, "%s is changing the privilege set of %s to %s", get_oper_name(source_p
), target_p
->name
, privset
->name
);
134 if (!IsOper(target_p
))
142 const char *modeparv
[4];
143 modeparv
[0] = modeparv
[1] = target_p
->name
;
146 user_mode(target_p
, target_p
, 3, modeparv
);
153 struct oper_conf oper
= {0};
154 oper
.name
= "<grant>";
155 oper
.privset
= privset
;
157 oper_up(target_p
, &oper
);
162 privilegeset_ref(privset
);
164 if (target_p
->user
->privset
!= NULL
)
165 old_privset
= target_p
->user
->privset
;
167 target_p
->user
->privset
= privset
;
170 sendto_server(NULL
, NULL
, CAP_TS6
, NOCAPS
, ":%s OPER %s %s",
171 use_id(target_p
), target_p
->user
->opername
, privset
->name
);
173 report_priv_change(target_p
, old_privset
, privset
);
175 if (old_privset
!= NULL
)
176 privilegeset_unref(old_privset
);
178 const char *modeparv
[4];
179 modeparv
[0] = modeparv
[1] = target_p
->name
;
182 user_mode(target_p
, target_p
, 3, modeparv
);