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