2 * IRC - Internet Relay Chat, ircd/client.c
3 * Copyright (C) 1990 Darren Reed
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 1, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include "ircd_features.h"
27 #include "ircd_reply.h"
39 #define BAD_PING ((unsigned int)-2)
43 * returns shortest ping time in attached server or client conf
44 * classes or PINGFREQUENCY
46 int client_get_ping(const struct Client* acptr)
49 struct ConfItem* aconf;
52 assert(cli_verify(acptr));
54 for (link = cli_confs(acptr); link; link = link->next) {
55 aconf = link->value.aconf;
56 if (aconf->status & (CONF_CLIENT | CONF_SERVER)) {
57 int tmp = get_conf_ping(aconf);
58 if (0 < tmp && (ping > tmp || !ping))
63 ping = feature_int(FEAT_PINGFREQUENCY);
65 Debug((DEBUG_DEBUG, "Client %s Ping %d", cli_name(acptr), ping));
71 * client_get_default_umode
72 * returns default usermode in attached client connection class
74 const char* client_get_default_umode(const struct Client* sptr)
76 struct ConfItem* aconf;
79 assert(cli_verify(sptr));
81 for (link = cli_confs(sptr); link; link = link->next) {
82 aconf = link->value.aconf;
83 if ((aconf->status & CONF_CLIENT) && ConfUmode(aconf))
84 return ConfUmode(aconf);
91 * removes the client's connection from the list of connections with
94 void client_drop_sendq(struct Connection* con)
96 if (con_prev_p(con)) { /* on the queued data list... */
98 con_prev_p(con_next(con)) = con_prev_p(con);
99 *(con_prev_p(con)) = con_next(con);
108 * adds the client's connection to the list of connections with
111 void client_add_sendq(struct Connection* con, struct Connection** con_p)
113 if (!con_prev_p(con)) { /* not on the queued data list yet... */
114 con_prev_p(con) = con_p;
115 con_next(con) = *con_p;
118 con_prev_p(*con_p) = &(con_next(con));
123 static struct Privs privs_global;
124 static struct Privs privs_local;
125 static int privs_defaults_set;
127 /* client_set_privs(struct Client* client)
129 * Sets the privileges for opers.
132 client_set_privs(struct Client *client, struct ConfItem *oper)
134 struct Privs *source, *defaults;
137 if (!privs_defaults_set)
139 memset(&privs_global, -1, sizeof(privs_global));
140 memset(&privs_local, 0, sizeof(privs_local));
141 PrivSet(&privs_local, PRIV_CHAN_LIMIT);
142 PrivSet(&privs_local, PRIV_MODE_LCHAN);
143 PrivSet(&privs_local, PRIV_SHOW_INVIS);
144 PrivSet(&privs_local, PRIV_SHOW_ALL_INVIS);
145 PrivSet(&privs_local, PRIV_LOCAL_KILL);
146 PrivSet(&privs_local, PRIV_REHASH);
147 PrivSet(&privs_local, PRIV_LOCAL_GLINE);
148 PrivSet(&privs_local, PRIV_LOCAL_JUPE);
149 PrivSet(&privs_local, PRIV_LOCAL_OPMODE);
150 PrivSet(&privs_local, PRIV_WHOX);
151 PrivSet(&privs_local, PRIV_DISPLAY);
152 PrivSet(&privs_local, PRIV_FORCE_LOCAL_OPMODE);
153 privs_defaults_set = 1;
155 memset(&(cli_privs(client)), 0, sizeof(struct Privs));
157 if (!IsAnOper(client))
159 else if (!MyConnect(client))
161 memset(&(cli_privs(client)), 255, sizeof(struct Privs));
162 PrivClr(&(cli_privs(client)), PRIV_SET);
165 else if (oper == NULL)
168 /* Clear out client's privileges. */
169 memset(&cli_privs(client), 0, sizeof(struct Privs));
171 /* Decide whether to use global or local oper defaults. */
172 if (PrivHas(&oper->privs_dirty, PRIV_PROPAGATE))
173 defaults = PrivHas(&oper->privs, PRIV_PROPAGATE) ? &privs_global : &privs_local;
174 else if (PrivHas(&oper->conn_class->privs_dirty, PRIV_PROPAGATE))
175 defaults = PrivHas(&oper->conn_class->privs, PRIV_PROPAGATE) ? &privs_global : &privs_local;
177 assert(0 && "Oper has no propagation and neither does connection class");
179 /* For each feature, figure out whether it comes from the operator
180 * conf, the connection class conf, or the defaults, then apply it.
182 for (priv = 0; priv < PRIV_LAST_PRIV; ++priv)
184 /* Figure out most applicable definition for the privilege. */
185 if (PrivHas(&oper->privs_dirty, priv))
186 source = &oper->privs;
187 else if (PrivHas(&oper->conn_class->privs_dirty, priv))
188 source = &oper->conn_class->privs;
192 /* Set it if necessary (privileges were already cleared). */
193 if (PrivHas(source, priv))
194 PrivSet(&cli_privs(client), priv);
197 /* This should be handled in the config, but lets be sure... */
198 if (PrivHas(&cli_privs(client), PRIV_PROPAGATE))
200 /* force propagating opers to display */
201 PrivSet(&cli_privs(client), PRIV_DISPLAY);
205 /* if they don't propagate oper status, prevent desyncs */
206 PrivClr(&cli_privs(client), PRIV_KILL);
207 PrivClr(&cli_privs(client), PRIV_GLINE);
208 PrivClr(&cli_privs(client), PRIV_JUPE);
209 PrivClr(&cli_privs(client), PRIV_OPMODE);
210 PrivClr(&cli_privs(client), PRIV_BADCHAN);
218 #define P(priv) { #priv, PRIV_ ## priv }
219 P(CHAN_LIMIT), P(MODE_LCHAN), P(WALK_LCHAN), P(DEOP_LCHAN),
220 P(SHOW_INVIS), P(SHOW_ALL_INVIS), P(UNLIMIT_QUERY), P(KILL),
221 P(LOCAL_KILL), P(REHASH), P(RESTART), P(DIE),
222 P(GLINE), P(LOCAL_GLINE), P(JUPE), P(LOCAL_JUPE),
223 P(OPMODE), P(LOCAL_OPMODE), P(SET), P(WHOX),
224 P(BADCHAN), P(LOCAL_BADCHAN), P(SEE_CHAN), P(PROPAGATE),
225 P(DISPLAY), P(SEE_OPERS), P(FORCE_OPMODE), P(FORCE_LOCAL_OPMODE),
231 /* client_report_privs(struct Client *to, struct Client *client)
233 * Sends a summary of the oper's privileges to the oper.
236 client_report_privs(struct Client *to, struct Client *client)
242 mb = msgq_make(to, rpl_str(RPL_PRIVS), cli_name(&me), cli_name(to),
245 for (i = 0; privtab[i].name; i++)
246 if (HasPriv(client, privtab[i].priv))
247 msgq_append(0, mb, "%s%s", found1++ ? " " : "", privtab[i].name);
249 send_buffer(to, mb, 0); /* send response */