*
* $Id$
*/
+#include "config.h"
+
#include "client.h"
#include "class.h"
#include "ircd.h"
+#include "ircd_features.h"
#include "ircd_reply.h"
#include "list.h"
+#include "msgq.h"
#include "numeric.h"
#include "s_conf.h"
#include "s_debug.h"
#include "struct.h"
#include <assert.h>
+#include <string.h>
#define BAD_PING ((unsigned int)-2)
-unsigned int client_get_ping(const struct Client* acptr)
+/*
+ * client_get_ping
+ * returns shortest ping time in attached server or client conf
+ * classes or PINGFREQUENCY
+ */
+int client_get_ping(const struct Client* acptr)
{
- unsigned int ping = 0;
- unsigned int tmp;
+ int ping = 0;
struct ConfItem* aconf;
struct SLink* link;
- for (link = acptr->confs; link; link = link->next) {
+ assert(cli_verify(acptr));
+
+ for (link = cli_confs(acptr); link; link = link->next) {
aconf = link->value.aconf;
if (aconf->status & (CONF_CLIENT | CONF_SERVER)) {
- tmp = get_conf_ping(aconf);
- if ((tmp != BAD_PING) && ((ping > tmp) || !ping))
+ int tmp = get_conf_ping(aconf);
+ if (0 < tmp && (ping > tmp || !ping))
ping = tmp;
}
}
if (0 == ping)
- ping = PINGFREQUENCY;
-
- Debug((DEBUG_DEBUG, "Client %s Ping %d", acptr->name, ping));
- return (ping);
-}
-
-#if 0
-#define BAD_CONF_CLASS ((unsigned int)-1)
-#define BAD_CLIENT_CLASS ((unsigned int)-3)
+ ping = feature_int(FEAT_PINGFREQUENCY);
-unsigned int get_conf_class(struct ConfItem *aconf)
-{
- if ((aconf) && (aconf->confClass))
- return (ConfClass(aconf));
-
- Debug((DEBUG_DEBUG, "No Class For %s", (aconf) ? aconf->name : "*No Conf*"));
-
- return (BAD_CONF_CLASS);
+ Debug((DEBUG_DEBUG, "Client %s Ping %d", cli_name(acptr), ping));
+ return ping;
}
-static unsigned int get_conf_ping(struct ConfItem *aconf)
+/*
+ * client_get_default_umode
+ * returns default usermode in attached client connection class
+ */
+const char* client_get_default_umode(const struct Client* sptr)
{
- if ((aconf) && (aconf->confClass))
- return (ConfPingFreq(aconf));
+ struct ConfItem* aconf;
+ struct SLink* link;
- Debug((DEBUG_DEBUG, "No Ping For %s", (aconf) ? aconf->name : "*No Conf*"));
+ assert(cli_verify(sptr));
- return (BAD_PING);
+ for (link = cli_confs(sptr); link; link = link->next) {
+ aconf = link->value.aconf;
+ if ((aconf->status & CONF_CLIENT) && ConfUmode(aconf))
+ return ConfUmode(aconf);
+ }
+ return NULL;
}
-unsigned int get_client_class(struct Client *acptr)
+/*
+ * client_drop_sendq
+ * removes the client's connection from the list of connections with
+ * queued data
+ */
+void client_drop_sendq(struct Connection* con)
{
- struct SLink *tmp;
- struct ConfClass *cl;
- unsigned int retc = BAD_CLIENT_CLASS;
-
- if (acptr && !IsMe(acptr) && (acptr->confs))
- for (tmp = acptr->confs; tmp; tmp = tmp->next)
- {
- if (!tmp->value.aconf || !(cl = tmp->value.aconf->confClass))
- continue;
- if (ConClass(cl) > retc || retc == BAD_CLIENT_CLASS)
- retc = ConClass(cl);
- }
+ if (con_prev_p(con)) { /* on the queued data list... */
+ if (con_next(con))
+ con_prev_p(con_next(con)) = con_prev_p(con);
+ *(con_prev_p(con)) = con_next(con);
- Debug((DEBUG_DEBUG, "Returning Class %d For %s", retc, acptr->name));
-
- return (retc);
-}
-unsigned int get_con_freq(struct ConfClass * clptr)
-{
- if (clptr)
- return (ConFreq(clptr));
- else
- return (CONNECTFREQUENCY);
+ con_next(con) = 0;
+ con_prev_p(con) = 0;
+ }
}
/*
- * When adding a class, check to see if it is already present first.
- * if so, then update the information for that class, rather than create
- * a new entry for it and later delete the old entry.
- * if no present entry is found, then create a new one and add it in
- * immeadiately after the first one (class 0).
+ * client_add_sendq
+ * adds the client's connection to the list of connections with
+ * queued data
*/
-void add_class(unsigned int conClass, unsigned int ping, unsigned int confreq,
- unsigned int maxli, unsigned int sendq)
+void client_add_sendq(struct Connection* con, struct Connection** con_p)
{
- struct ConfClass *t, *p;
+ if (!con_prev_p(con)) { /* not on the queued data list yet... */
+ con_prev_p(con) = con_p;
+ con_next(con) = *con_p;
- t = find_class(conClass);
- if ((t == classes) && (conClass != 0))
- {
- p = (struct ConfClass *) make_class();
- NextClass(p) = NextClass(t);
- NextClass(t) = p;
+ if (*con_p)
+ con_prev_p(*con_p) = &(con_next(con));
+ *con_p = con;
}
- else
- p = t;
- Debug((DEBUG_DEBUG, "Add Class %u: p %p t %p - cf: %u pf: %u ml: %u sq: %d",
- conClass, p, t, confreq, ping, maxli, sendq));
- ConClass(p) = conClass;
- ConFreq(p) = confreq;
- PingFreq(p) = ping;
- MaxLinks(p) = maxli;
- MaxSendq(p) = (sendq > 0) ? sendq : DEFAULTMAXSENDQLENGTH;
- if (p != t)
- Links(p) = 0;
}
-struct ConfClass *find_class(unsigned int cclass)
+static struct Privs privs_global;
+static struct Privs privs_local;
+static int privs_defaults_set;
+
+/* client_set_privs(struct Client* client)
+ *
+ * Sets the privileges for opers.
+ */
+void
+client_set_privs(struct Client *client, struct ConfItem *oper)
{
- struct ConfClass *cltmp;
+ struct Privs *source, *defaults;
+ enum Priv priv;
- for (cltmp = FirstClass(); cltmp; cltmp = NextClass(cltmp))
- if (ConClass(cltmp) == cclass)
- return cltmp;
- return classes;
-}
+ if (!privs_defaults_set)
+ {
+ memset(&privs_global, -1, sizeof(privs_global));
+ memset(&privs_local, 0, sizeof(privs_local));
+ PrivSet(&privs_local, PRIV_CHAN_LIMIT);
+ PrivSet(&privs_local, PRIV_MODE_LCHAN);
+ PrivSet(&privs_local, PRIV_SHOW_INVIS);
+ PrivSet(&privs_local, PRIV_SHOW_ALL_INVIS);
+ PrivSet(&privs_local, PRIV_LOCAL_KILL);
+ PrivSet(&privs_local, PRIV_REHASH);
+ PrivSet(&privs_local, PRIV_LOCAL_GLINE);
+ PrivSet(&privs_local, PRIV_LOCAL_JUPE);
+ PrivSet(&privs_local, PRIV_LOCAL_OPMODE);
+ PrivSet(&privs_local, PRIV_WHOX);
+ PrivSet(&privs_local, PRIV_DISPLAY);
+ PrivSet(&privs_local, PRIV_FORCE_LOCAL_OPMODE);
+ privs_defaults_set = 1;
+ }
+ memset(&(cli_privs(client)), 0, sizeof(struct Privs));
-void check_class(void)
-{
- struct ConfClass *cltmp, *cltmp2;
+ if (!IsAnOper(client))
+ return;
+ else if (!MyConnect(client))
+ {
+ memset(&(cli_privs(client)), 255, sizeof(struct Privs));
+ PrivClr(&(cli_privs(client)), PRIV_SET);
+ return;
+ }
+ else if (oper == NULL)
+ return;
- Debug((DEBUG_DEBUG, "Class check:"));
+ /* Clear out client's privileges. */
+ memset(&cli_privs(client), 0, sizeof(struct Privs));
- for (cltmp2 = cltmp = FirstClass(); cltmp; cltmp = NextClass(cltmp2))
+ /* Decide whether to use global or local oper defaults. */
+ if (PrivHas(&oper->privs_dirty, PRIV_PROPAGATE))
+ defaults = PrivHas(&oper->privs, PRIV_PROPAGATE) ? &privs_global : &privs_local;
+ else if (PrivHas(&oper->conn_class->privs_dirty, PRIV_PROPAGATE))
+ defaults = PrivHas(&oper->conn_class->privs, PRIV_PROPAGATE) ? &privs_global : &privs_local;
+ else
+ assert(0 && "Oper has no propagation and neither does connection class");
+
+ /* For each feature, figure out whether it comes from the operator
+ * conf, the connection class conf, or the defaults, then apply it.
+ */
+ for (priv = 0; priv < PRIV_LAST_PRIV; ++priv)
{
- Debug((DEBUG_DEBUG,
- "Class %d : CF: %d PF: %d ML: %d LI: %d SQ: %d",
- ConClass(cltmp), ConFreq(cltmp), PingFreq(cltmp),
- MaxLinks(cltmp), Links(cltmp), MaxSendq(cltmp)));
- if (IsMarkedDelete(cltmp))
- {
- NextClass(cltmp2) = NextClass(cltmp);
- if (Links(cltmp) == 0)
- free_class(cltmp);
- }
+ /* Figure out most applicable definition for the privilege. */
+ if (PrivHas(&oper->privs_dirty, priv))
+ source = &oper->privs;
+ else if (PrivHas(&oper->conn_class->privs_dirty, priv))
+ source = &oper->conn_class->privs;
else
- cltmp2 = cltmp;
+ source = defaults;
+
+ /* Set it if necessary (privileges were already cleared). */
+ if (PrivHas(source, priv))
+ PrivSet(&cli_privs(client), priv);
}
-}
-void initclass(void)
-{
- classes = (struct ConfClass *) make_class();
-
- ConClass(FirstClass()) = 0;
- ConFreq(FirstClass()) = CONNECTFREQUENCY;
- PingFreq(FirstClass()) = PINGFREQUENCY;
- MaxLinks(FirstClass()) = MAXIMUM_LINKS;
- MaxSendq(FirstClass()) = DEFAULTMAXSENDQLENGTH;
- Links(FirstClass()) = 0;
- NextClass(FirstClass()) = NULL;
+ /* This should be handled in the config, but lets be sure... */
+ if (PrivHas(&cli_privs(client), PRIV_PROPAGATE))
+ {
+ /* force propagating opers to display */
+ PrivSet(&cli_privs(client), PRIV_DISPLAY);
+ }
+ else
+ {
+ /* if they don't propagate oper status, prevent desyncs */
+ PrivClr(&cli_privs(client), PRIV_KILL);
+ PrivClr(&cli_privs(client), PRIV_GLINE);
+ PrivClr(&cli_privs(client), PRIV_JUPE);
+ PrivClr(&cli_privs(client), PRIV_OPMODE);
+ PrivClr(&cli_privs(client), PRIV_BADCHAN);
+ }
}
-void report_classes(struct Client *sptr)
+static struct {
+ char *name;
+ unsigned int priv;
+} privtab[] = {
+#define P(priv) { #priv, PRIV_ ## priv }
+ P(CHAN_LIMIT), P(MODE_LCHAN), P(WALK_LCHAN), P(DEOP_LCHAN),
+ P(SHOW_INVIS), P(SHOW_ALL_INVIS), P(UNLIMIT_QUERY), P(KILL),
+ P(LOCAL_KILL), P(REHASH), P(RESTART), P(DIE),
+ P(GLINE), P(LOCAL_GLINE), P(JUPE), P(LOCAL_JUPE),
+ P(OPMODE), P(LOCAL_OPMODE), P(SET), P(WHOX),
+ P(BADCHAN), P(LOCAL_BADCHAN), P(SEE_CHAN), P(PROPAGATE),
+ P(DISPLAY), P(SEE_OPERS), P(FORCE_OPMODE), P(FORCE_LOCAL_OPMODE),
+ P(WIDE_GLINE),
+#undef P
+ { 0, 0 }
+};
+
+/* client_report_privs(struct Client *to, struct Client *client)
+ *
+ * Sends a summary of the oper's privileges to the oper.
+ */
+int
+client_report_privs(struct Client *to, struct Client *client)
{
- struct ConfClass *cltmp;
+ struct MsgBuf *mb;
+ int found1 = 0;
+ int i;
- for (cltmp = FirstClass(); cltmp; cltmp = NextClass(cltmp))
- send_reply(sptr, RPL_STATSYLINE, 'Y', ConClass(cltmp), PingFreq(cltmp),
- ConFreq(cltmp), MaxLinks(cltmp), MaxSendq(cltmp));
-}
+ mb = msgq_make(to, rpl_str(RPL_PRIVS), cli_name(&me), cli_name(to),
+ cli_name(client));
-unsigned int get_sendq(struct Client *cptr)
-{
- assert(0 != cptr);
- assert(0 != cptr->local);
-
- if (cptr->max_sendq)
- return cptr->max_sendq;
-
- else if (cptr->confs) {
- struct SLink* tmp;
- struct ConfClass* cl;
-
- for (tmp = cptr->confs; tmp; tmp = tmp->next) {
- if (!tmp->value.aconf || !(cl = tmp->value.aconf->confClass))
- continue;
- if (ConClass(cl) != BAD_CLIENT_CLASS) {
- cptr->max_sendq = MaxSendq(cl);
- return cptr->max_sendq;
- }
- }
- }
- return DEFAULTMAXSENDQLENGTH;
+ for (i = 0; privtab[i].name; i++)
+ if (HasPriv(client, privtab[i].priv))
+ msgq_append(0, mb, "%s%s", found1++ ? " " : "", privtab[i].name);
+
+ send_buffer(to, mb, 0); /* send response */
+ msgq_clean(mb);
+
+ return 0;
}
-#endif