]>
Commit | Line | Data |
---|---|---|
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" | |
6119faa9 | 16 | #include "msgbuf.h" |
3b1c2aa6 | 17 | |
7f373431 EK |
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[]); | |
eeabf33a | 20 | |
c1649fd0 | 21 | static int do_grant(struct Client *source_p, struct Client *target_p, const char *new_privset); |
3b1c2aa6 | 22 | |
c1649fd0 | 23 | struct Message grant_msgtab = { |
6119faa9 | 24 | "GRANT", 0, 0, 0, 0, |
c1649fd0 EK |
25 | { mg_ignore, mg_not_oper, mg_ignore, mg_ignore, {me_grant, 3}, {mo_grant, 3}} |
26 | }; | |
3b1c2aa6 | 27 | |
c1649fd0 | 28 | mapi_clist_av1 grant_clist[] = { &grant_msgtab, NULL }; |
3b1c2aa6 | 29 | |
7f373431 | 30 | static const char grant_desc[] = "Allows operators to set or remove operator privileges on other users"; |
c1649fd0 | 31 | |
7f373431 EK |
32 | DECLARE_MODULE_AV2(grant, NULL, NULL, grant_clist, NULL, NULL, NULL, NULL, grant_desc); |
33 | ||
34 | static void | |
6119faa9 | 35 | mo_grant(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
3b1c2aa6 | 36 | { |
c1649fd0 | 37 | struct Client *target_p; |
3b1c2aa6 | 38 | |
6119faa9 | 39 | if(!HasPrivilege(source_p, "oper:grant")) |
3b1c2aa6 | 40 | { |
c1649fd0 | 41 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "grant"); |
7f373431 | 42 | return; |
3b1c2aa6 AC |
43 | } |
44 | ||
c1649fd0 EK |
45 | target_p = find_named_person(parv[1]); |
46 | if (target_p == NULL) | |
3b1c2aa6 | 47 | { |
c1649fd0 EK |
48 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, |
49 | form_str(ERR_NOSUCHNICK), parv[1]); | |
7f373431 | 50 | return; |
3b1c2aa6 | 51 | } |
17f92581 | 52 | |
c1649fd0 | 53 | if (MyClient(target_p)) |
3b1c2aa6 | 54 | { |
c1649fd0 EK |
55 | do_grant(source_p, target_p, parv[2]); |
56 | } | |
57 | else | |
3b1c2aa6 | 58 | { |
c1649fd0 EK |
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]); | |
3b1c2aa6 | 62 | } |
17f92581 JV |
63 | } |
64 | ||
7f373431 | 65 | static void |
6119faa9 | 66 | me_grant(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
17f92581 | 67 | { |
c1649fd0 EK |
68 | struct Client *target_p; |
69 | ||
70 | target_p = find_person(parv[1]); | |
71 | if (target_p == NULL) | |
3b1c2aa6 | 72 | { |
c1649fd0 EK |
73 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, |
74 | form_str(ERR_NOSUCHNICK), parv[1]); | |
7f373431 | 75 | return; |
3b1c2aa6 AC |
76 | } |
77 | ||
c1649fd0 EK |
78 | if(!find_shared_conf(source_p->username, source_p->host, |
79 | source_p->servptr->name, SHARED_GRANT)) | |
17f92581 | 80 | { |
c1649fd0 EK |
81 | sendto_one(source_p, ":%s NOTICE %s :You don't have an appropriate shared" |
82 | "block to grant privilege on this server.", me.name, source_p->name); | |
7f373431 | 83 | return; |
17f92581 | 84 | } |
3b1c2aa6 | 85 | |
c1649fd0 | 86 | do_grant(source_p, target_p, parv[2]); |
c1649fd0 | 87 | } |
17f92581 | 88 | |
17f92581 | 89 | |
c1649fd0 EK |
90 | static 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 | ||
b143f5e3 | 95 | if (!strcasecmp(new_privset, "deoper")) |
c1649fd0 | 96 | { |
6119faa9 | 97 | if (!IsOper(target_p)) |
c1649fd0 EK |
98 | { |
99 | sendto_one_notice(source_p, ":You can't deoper someone who isn't an oper."); | |
100 | return 0; | |
101 | } | |
c1649fd0 EK |
102 | dodeoper = 1; |
103 | ||
104 | sendto_one_notice(target_p, ":%s is deopering you.", source_p->name); | |
105 | sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s is deopering %s.", get_oper_name(source_p), target_p->name); | |
106 | } | |
107 | else | |
3b1c2aa6 | 108 | { |
c1649fd0 EK |
109 | if (!(privset = privilegeset_get(new_privset))) |
110 | { | |
111 | sendto_one_notice(source_p, ":There is no privilege set named '%s'.", new_privset); | |
112 | return 0; | |
113 | } | |
114 | ||
115 | if (privset == target_p->user->privset) | |
116 | { | |
117 | sendto_one_notice(source_p, ":%s already has privilege set %s.", target_p->name, target_p->user->privset->name); | |
118 | return 0; | |
119 | } | |
3b1c2aa6 AC |
120 | } |
121 | ||
c1649fd0 | 122 | if (!dodeoper) |
3b1c2aa6 | 123 | { |
6119faa9 | 124 | if (!IsOper(target_p)) |
c1649fd0 EK |
125 | { |
126 | sendto_one_notice(target_p, ":%s is opering you with privilege set %s", source_p->name, privset->name); | |
127 | 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); | |
128 | dooper = 1; | |
129 | } | |
3b1c2aa6 | 130 | else |
c1649fd0 EK |
131 | { |
132 | sendto_one_notice(target_p, ":%s is changing your privilege set to %s", source_p->name, privset->name); | |
133 | 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 | } | |
135 | ||
136 | if (!IsOper(target_p)) | |
137 | { | |
138 | dooper = 1; | |
139 | } | |
3b1c2aa6 | 140 | } |
c1649fd0 EK |
141 | |
142 | if (dodeoper) | |
3b1c2aa6 | 143 | { |
c1649fd0 EK |
144 | const char *modeparv[4]; |
145 | modeparv[0] = modeparv[1] = target_p->name; | |
146 | modeparv[2] = "-o"; | |
147 | modeparv[3] = NULL; | |
148 | user_mode(target_p, target_p, 3, modeparv); | |
3b1c2aa6 AC |
149 | } |
150 | ||
c1649fd0 | 151 | if (dooper) |
17f92581 | 152 | { |
c1649fd0 EK |
153 | struct oper_conf oper; |
154 | oper.name = "<grant>"; | |
155 | oper.umodes = 0; | |
156 | oper.snomask = 0; | |
157 | oper.privset = privset; | |
158 | ||
159 | oper_up(target_p, &oper); | |
3b1c2aa6 | 160 | } |
bdc87b5f EK |
161 | else if (privset != NULL) |
162 | { | |
163 | privilegeset_ref(privset); | |
164 | } | |
165 | ||
166 | if (target_p->user->privset != NULL) | |
167 | privilegeset_unref(target_p->user->privset); | |
3b1c2aa6 | 168 | |
c1649fd0 | 169 | target_p->user->privset = privset; |
910f8839 EK |
170 | |
171 | if (privset != NULL) | |
172 | sendto_server(NULL, NULL, CAP_TS6, NOCAPS, ":%s OPER %s %s", | |
173 | use_id(target_p), target_p->user->opername, privset->name); | |
174 | ||
c1649fd0 EK |
175 | const char *modeparv[4]; |
176 | modeparv[0] = modeparv[1] = target_p->name; | |
177 | modeparv[2] = "+"; | |
178 | modeparv[3] = NULL; | |
179 | user_mode(target_p, target_p, 3, modeparv); | |
17f92581 | 180 | |
c1649fd0 EK |
181 | return 0; |
182 | } |