]> jfr.im git - irc/rqf/shadowircd.git/blobdiff - src/client.c
Send only one ERR_MLOCKRESTRICTED per MODE command.
[irc/rqf/shadowircd.git] / src / client.c
index 41da8952df029a3ac5c29f874b2b08ed3dc18312..9e8c737dd3bf74e8723e11556eb9367b4d77c180 100644 (file)
@@ -22,7 +22,6 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  *  USA
  *
- *  $Id: client.c 3514 2007-06-06 16:25:21Z nenolod $
  */
 #include "stdinc.h"
 #include "config.h"
@@ -231,6 +230,13 @@ free_local_client(struct Client *client_p)
                rb_free(client_p->localClient->passwd);
        }
 
+       rb_free(client_p->localClient->auth_user);
+
+       if(client_p->localClient->override_timeout_event)
+       {
+               rb_event_delete(client_p->localClient->override_timeout_event);
+       }
+
        rb_free(client_p->localClient->challenge);
        rb_free(client_p->localClient->fullcaps);
        rb_free(client_p->localClient->opername);
@@ -255,6 +261,7 @@ free_client(struct Client *client_p)
        s_assert(&me != client_p);
        free_local_client(client_p);
        free_pre_client(client_p);
+       rb_free(client_p->certfp);
        rb_bh_free(client_heap, client_p);
 }
 
@@ -416,10 +423,10 @@ notify_banned_client(struct Client *client_p, struct ConfItem *aconf, int ban)
        const char *reason = NULL;
        const char *exit_reason = conn_closed;
 
-       if(ConfigFileEntry.kline_with_reason && !EmptyString(aconf->passwd))
+       if(ConfigFileEntry.kline_with_reason)
        {
-               reason = aconf->passwd;
-               exit_reason = aconf->passwd;
+               reason = get_user_ban_reason(aconf);
+               exit_reason = reason;
        }
        else
        {
@@ -447,81 +454,9 @@ notify_banned_client(struct Client *client_p, struct ConfItem *aconf, int ban)
 void
 check_banned_lines(void)
 {
-       struct Client *client_p;        /* current local client_p being examined */
-       struct ConfItem *aconf = NULL;
-       rb_dlink_node *ptr, *next_ptr;
-
-       RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head)
-       {
-               client_p = ptr->data;
-
-               if(IsMe(client_p))
-                       continue;
-
-               /* if there is a returned struct ConfItem then kill it */
-               if((aconf = find_dline((struct sockaddr *)&client_p->localClient->ip, client_p->localClient->ip.ss_family)) && !(aconf->status & CONF_EXEMPTDLINE))
-               {
-                       sendto_realops_snomask(SNO_GENERAL, L_ALL,
-                                            "DLINE active for %s",
-                                            get_client_name(client_p, HIDE_IP));
-
-                       notify_banned_client(client_p, aconf, D_LINED);
-                       continue;       /* and go examine next fd/client_p */
-               }
-
-               if(!IsPerson(client_p))
-                       continue;
-
-               if((aconf = find_kline(client_p)) != NULL)
-               {
-                       if(IsExemptKline(client_p))
-                       {
-                               sendto_realops_snomask(SNO_GENERAL, L_ALL,
-                                               "KLINE over-ruled for %s, client is kline_exempt [%s@%s]",
-                                               get_client_name(client_p, HIDE_IP),
-                                               aconf->user, aconf->host);
-                               continue;
-                       }
-
-                       sendto_realops_snomask(SNO_GENERAL, L_ALL,
-                                       "KLINE active for %s",
-                                       get_client_name(client_p, HIDE_IP));
-                       notify_banned_client(client_p, aconf, K_LINED);
-                       continue;
-               }
-               else if((aconf = find_xline(client_p->info, 1)) != NULL)
-               {
-                       if(IsExemptKline(client_p))
-                       {
-                               sendto_realops_snomask(SNO_GENERAL, L_ALL,
-                                               "XLINE over-ruled for %s, client is kline_exempt [%s]",
-                                               get_client_name(client_p, HIDE_IP),
-                                               aconf->name);
-                               continue;
-                       }
-
-                       sendto_realops_snomask(SNO_GENERAL, L_ALL, "XLINE active for %s",
-                                       get_client_name(client_p, HIDE_IP));
-
-                       (void) exit_client(client_p, client_p, &me, "Bad user info");
-                       continue;
-               }
-       }
-
-       /* also check the unknowns list for new dlines */
-       RB_DLINK_FOREACH_SAFE(ptr, next_ptr, unknown_list.head)
-       {
-               client_p = ptr->data;
-
-               if((aconf = find_dline((struct sockaddr *)&client_p->localClient->ip,client_p->localClient->ip.ss_family)))
-               {
-                       if(aconf->status & CONF_EXEMPTDLINE)
-                               continue;
-
-                       notify_banned_client(client_p, aconf, D_LINED);
-               }
-       }
-
+       check_dlines();
+       check_klines();
+       check_xlines();
 }
 
 /* check_klines_event()
@@ -563,8 +498,9 @@ check_klines(void)
                        if(IsExemptKline(client_p))
                        {
                                sendto_realops_snomask(SNO_GENERAL, L_ALL,
-                                                    "KLINE over-ruled for %s, client is kline_exempt",
-                                                    get_client_name(client_p, HIDE_IP));
+                                                    "KLINE over-ruled for %s, client is kline_exempt [%s@%s]",
+                                                    get_client_name(client_p, HIDE_IP),
+                                                    aconf->user, aconf->host);
                                continue;
                        }
 
@@ -654,8 +590,9 @@ check_xlines(void)
                        if(IsExemptKline(client_p))
                        {
                                sendto_realops_snomask(SNO_GENERAL, L_ALL,
-                                                    "XLINE over-ruled for %s, client is kline_exempt",
-                                                    get_client_name(client_p, HIDE_IP));
+                                                    "XLINE over-ruled for %s, client is kline_exempt [%s]",
+                                                    get_client_name(client_p, HIDE_IP),
+                                                    aconf->host);
                                continue;
                        }
 
@@ -1175,7 +1112,7 @@ exit_aborted_clients(void *unused)
  *
  */
 void
-dead_link(struct Client *client_p)
+dead_link(struct Client *client_p, int sendqex)
 {
        struct abort_client *abt;
 
@@ -1185,7 +1122,7 @@ dead_link(struct Client *client_p)
 
        abt = (struct abort_client *) rb_malloc(sizeof(struct abort_client));
 
-       if(client_p->flags & FLAGS_SENDQEX)
+       if(sendqex)
                rb_strlcpy(abt->notice, "Max SendQ exceeded", sizeof(abt->notice));
        else
                rb_snprintf(abt->notice, sizeof(abt->notice), "Write error: %s", strerror(errno));
@@ -1208,6 +1145,9 @@ exit_generic_client(struct Client *client_p, struct Client *source_p, struct Cli
        if(IsOper(source_p))
                rb_dlinkFindDestroy(source_p, &oper_list);
 
+       /* get rid of any metadata the user may have */
+       user_metadata_clear(source_p);
+
        sendto_common_channels_local(source_p, ":%s!%s@%s QUIT :%s",
                                     source_p->name,
                                     source_p->username, source_p->host, comment);
@@ -1721,6 +1661,7 @@ struct User *
 make_user(struct Client *client_p)
 {
        struct User *user;
+       struct Dictionary *metadata;
 
        user = client_p->user;
        if(!user)
@@ -1728,6 +1669,9 @@ make_user(struct Client *client_p)
                user = (struct User *) rb_bh_alloc(user_heap);
                user->refcnt = 1;
                client_p->user = user;
+
+               metadata = irc_dictionary_create(irccmp);
+               client_p->user->metadata = metadata;
        }
        return user;
 }
@@ -1740,14 +1684,14 @@ make_user(struct Client *client_p)
  * side effects - add's an Server information block to a client
  *                if it was not previously allocated.
  */
-server_t *
+struct Server *
 make_server(struct Client *client_p)
 {
-       server_t *serv = client_p->serv;
+       struct Server *serv = client_p->serv;
 
        if(!serv)
        {
-               serv = (server_t *) rb_malloc(sizeof(server_t));
+               serv = (struct Server *) rb_malloc(sizeof(struct Server));
                client_p->serv = serv;
        }
        return client_p->serv;
@@ -1771,6 +1715,7 @@ free_user(struct User *user, struct Client *client_p)
        {
                if(user->away)
                        rb_free((char *) user->away);
+               
                /*
                 * sanity check
                 */
@@ -1986,3 +1931,96 @@ error_exit_client(struct Client *client_p, int error)
 
        exit_client(client_p, client_p, &me, errmsg);
 }
+
+/*
+ * user_metadata_add
+ * 
+ * inputs      - pointer to client struct
+ *             - name of metadata item you wish to add
+ *             - value of metadata item
+ *             - 1 if metadata should be propegated, 0 if not
+ * output      - none
+ * side effects - metadata is added to the user in question
+ *             - metadata is propegated if propegate is set.
+ */
+struct Metadata *
+user_metadata_add(struct Client *target, const char *name, const char *value, int propegate)
+{
+       struct Metadata *md;
+
+       md = rb_malloc(sizeof(struct Metadata));
+       md->name = rb_strdup(name);
+       md->value = rb_strdup(value);
+
+       irc_dictionary_add(target->user->metadata, md->name, md);
+       
+       if(propegate)
+               sendto_match_servs(&me, "*", CAP_ENCAP, NOCAPS, "ENCAP * METADATA ADD %s %s :%s",
+                               target->id, name, value);
+
+       return md;
+}
+
+/*
+ * user_metadata_delete
+ * 
+ * inputs      - pointer to client struct
+ *             - name of metadata item you wish to delete
+ * output      - none
+ * side effects - metadata is deleted from the user in question
+ *             - deletion is propegated if propegate is set
+ */
+void
+user_metadata_delete(struct Client *target, const char *name, int propegate)
+{
+       struct Metadata *md = user_metadata_find(target, name);
+
+       if(!md)
+               return;
+
+       irc_dictionary_delete(target->user->metadata, md->name);
+
+       rb_free(md);
+
+       if(propegate)
+               sendto_match_servs(&me, "*", CAP_ENCAP, NOCAPS, "ENCAP * METADATA DELETE %s %s",
+                               target->id, name);
+}
+
+/*
+ * user_metadata_find
+ * 
+ * inputs      - pointer to client struct
+ *             - name of metadata item you wish to read
+ * output      - the requested metadata, if it exists, elsewise null.
+ * side effects - 
+ */
+struct Metadata *
+user_metadata_find(struct Client *target, const char *name)
+{
+       if(!target->user)
+               return NULL;
+
+       if(!target->user->metadata)
+               return NULL;
+
+       return irc_dictionary_retrieve(target->user->metadata, name);
+}
+/*
+ * user_metadata_clear
+ * 
+ * inputs      - pointer to user struct
+ * output      - none
+ * side effects - metadata is cleared from the user in question
+ */
+void
+user_metadata_clear(struct Client *target)
+{
+       struct Metadata *md;
+       struct DictionaryIter iter;
+       
+       DICTIONARY_FOREACH(md, &iter, target->user->metadata)
+       {
+               user_metadata_delete(target, md->name, 0);
+       }
+}