]> jfr.im git - solanum.git/blame - modules/m_grant.c
modules: Add AV2 descriptions to all m_r* modules
[solanum.git] / modules / m_grant.c
CommitLineData
3b1c2aa6
AC
1/*
2 * Copyright (C) 2006 Jilles Tjoelker
3 * Copyright (C) 2006 Stephen Bennett <spb@gentoo.org>
3b1c2aa6
AC
4 */
5
6#include "stdinc.h"
7#include "modules.h"
8#include "numeric.h"
9#include "client.h"
10#include "ircd.h"
11#include "send.h"
12#include "s_user.h"
13#include "s_serv.h"
14#include "s_conf.h"
15#include "s_newconf.h"
16
428ca87b
AC
17static int mo_grant(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
18static int me_grant(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
3b1c2aa6
AC
19
20static int do_grant(struct Client *source_p, struct Client *target_p, const char *new_privset);
21
22struct Message grant_msgtab = {
7baa37a9 23 "GRANT", 0, 0, 0, 0,
3b1c2aa6
AC
24 { mg_ignore, mg_not_oper, mg_ignore, mg_ignore, {me_grant, 3}, {mo_grant, 3}}
25};
26
27mapi_clist_av1 grant_clist[] = { &grant_msgtab, NULL };
28
105a4985 29DECLARE_MODULE_AV2(grant, NULL, NULL, grant_clist, NULL, NULL, NULL, NULL, NULL);
3b1c2aa6
AC
30
31static int
428ca87b 32mo_grant(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
3b1c2aa6
AC
33{
34 struct Client *target_p;
35
36 if(!HasPrivilege(source_p, "oper:grant"))
37 {
38 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "grant");
39 return 0;
40 }
41
42 target_p = find_named_person(parv[1]);
43 if (target_p == NULL)
44 {
45 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
46 form_str(ERR_NOSUCHNICK), parv[1]);
47 return 0;
48 }
49
50 if (MyClient(target_p))
51 {
52 do_grant(source_p, target_p, parv[2]);
53 }
54 else
55 {
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]);
59 }
60
61 return 0;
62}
63
428ca87b 64static int me_grant(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
3b1c2aa6
AC
65{
66 struct Client *target_p;
67
68 target_p = find_person(parv[1]);
69 if (target_p == NULL)
70 {
71 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
72 form_str(ERR_NOSUCHNICK), parv[1]);
73 return 0;
74 }
75
76 if(!find_shared_conf(source_p->username, source_p->host,
77 source_p->servptr->name, SHARED_GRANT))
78 {
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);
81 return 0;
82 }
83
84 do_grant(source_p, target_p, parv[2]);
85
86 return 0;
87}
88
89
90static int do_grant(struct Client *source_p, struct Client *target_p, const char *new_privset)
91{
92 int dooper = 0, dodeoper = 0;
93 struct PrivilegeSet *privset = 0;
94
95 if (!strcmp(new_privset, "deoper"))
96 {
97 if (!IsOper(target_p))
98 {
99 sendto_one_notice(source_p, ":You can't deoper someone who isn't an oper.");
100 return 0;
101 }
102 new_privset = "default";
103 dodeoper = 1;
104
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);
107 }
108 else
109 {
110 if (!(privset = privilegeset_get(new_privset)))
111 {
112 sendto_one_notice(source_p, ":There is no privilege set named '%s'.", new_privset);
113 return 0;
114 }
115
116 if (privset == target_p->localClient->privset)
117 {
118 sendto_one_notice(source_p, ":%s already has privilege set %s.", target_p->name, target_p->localClient->privset->name);
119 return 0;
120 }
121 }
122
123 if (!dodeoper)
124 {
125 if (!IsOper(target_p))
126 {
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);
129 dooper = 1;
130 }
131 else
132 {
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);
135 }
136 }
137
138 if (dodeoper)
139 {
140 const char *modeparv[4];
141 modeparv[0] = modeparv[1] = target_p->name;
142 modeparv[2] = "-o";
143 modeparv[3] = NULL;
144 user_mode(target_p, target_p, 3, modeparv);
145 }
146
147 if (dooper)
148 {
149 struct oper_conf oper;
150 oper.name = "<grant>";
151 oper.umodes = 0;
152 oper.snomask = 0;
153 oper.privset = privset;
154
155 oper_up(target_p, &oper);
156 }
157
158 target_p->localClient->privset = privset;
159 const char *modeparv[4];
160 modeparv[0] = modeparv[1] = target_p->name;
161 modeparv[2] = "+";
162 modeparv[3] = NULL;
163 user_mode(target_p, target_p, 3, modeparv);
164
165 return 0;
166}