2 * Copyright (C) 2006 Jilles Tjoelker
3 * Copyright (C) 2006 Stephen Bennett <spb@gentoo.org>
15 #include "s_newconf.h"
17 static int mo_grant(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[]);
18 static int me_grant(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[]);
20 static int do_grant(struct Client
*source_p
, struct Client
*target_p
, const char *new_privset
);
22 struct Message grant_msgtab
= {
24 { mg_ignore
, mg_not_oper
, mg_ignore
, mg_ignore
, {me_grant
, 3}, {mo_grant
, 3}}
27 mapi_clist_av1 grant_clist
[] = { &grant_msgtab
, NULL
};
29 DECLARE_MODULE_AV2(grant
, NULL
, NULL
, grant_clist
, NULL
, NULL
, NULL
, NULL
, NULL
);
32 mo_grant(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
34 struct Client
*target_p
;
36 if(!HasPrivilege(source_p
, "oper:grant"))
38 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "grant");
42 target_p
= find_named_person(parv
[1]);
45 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
46 form_str(ERR_NOSUCHNICK
), parv
[1]);
50 if (MyClient(target_p
))
52 do_grant(source_p
, target_p
, parv
[2]);
56 sendto_one(target_p
, ":%s ENCAP %s GRANT %s %s",
57 get_id(source_p
, target_p
), target_p
->servptr
->name
,
58 get_id(target_p
, target_p
), parv
[2]);
64 static int me_grant(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
66 struct Client
*target_p
;
68 target_p
= find_person(parv
[1]);
71 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
72 form_str(ERR_NOSUCHNICK
), parv
[1]);
76 if(!find_shared_conf(source_p
->username
, source_p
->host
,
77 source_p
->servptr
->name
, SHARED_GRANT
))
79 sendto_one(source_p
, ":%s NOTICE %s :You don't have an appropriate shared"
80 "block to grant privilege on this server.", me
.name
, source_p
->name
);
84 do_grant(source_p
, target_p
, parv
[2]);
90 static int do_grant(struct Client
*source_p
, struct Client
*target_p
, const char *new_privset
)
92 int dooper
= 0, dodeoper
= 0;
93 struct PrivilegeSet
*privset
= 0;
95 if (!strcmp(new_privset
, "deoper"))
97 if (!IsOper(target_p
))
99 sendto_one_notice(source_p
, ":You can't deoper someone who isn't an oper.");
102 new_privset
= "default";
105 sendto_one_notice(target_p
, ":%s is deopering you.", source_p
->name
);
106 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
, "%s is deopering %s.", get_oper_name(source_p
), target_p
->name
);
110 if (!(privset
= privilegeset_get(new_privset
)))
112 sendto_one_notice(source_p
, ":There is no privilege set named '%s'.", new_privset
);
116 if (privset
== target_p
->localClient
->privset
)
118 sendto_one_notice(source_p
, ":%s already has privilege set %s.", target_p
->name
, target_p
->localClient
->privset
->name
);
125 if (!IsOper(target_p
))
127 sendto_one_notice(target_p
, ":%s is opering you with privilege set %s", source_p
->name
, privset
->name
);
128 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
);
133 sendto_one_notice(target_p
, ":%s is changing your privilege set to %s", source_p
->name
, privset
->name
);
134 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
);
140 const char *modeparv
[4];
141 modeparv
[0] = modeparv
[1] = target_p
->name
;
144 user_mode(target_p
, target_p
, 3, modeparv
);
149 struct oper_conf oper
;
150 oper
.name
= "<grant>";
153 oper
.privset
= privset
;
155 oper_up(target_p
, &oper
);
158 target_p
->localClient
->privset
= privset
;
159 const char *modeparv
[4];
160 modeparv
[0] = modeparv
[1] = target_p
->name
;
163 user_mode(target_p
, target_p
, 3, modeparv
);