X-Git-Url: https://jfr.im/git/irc/rqf/shadowircd.git/blobdiff_plain/9d393c9052eed3ccdc83f6b9fe75fd7d258ced57..cc2a7258f125c9ad0bc6e788f9a25a75e5e7944d:/src/client.c?ds=sidebyside diff --git a/src/client.c b/src/client.c index a395ec8..9e8c737 100644 --- a/src/client.c +++ b/src/client.c @@ -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" @@ -76,7 +75,7 @@ static rb_bh *client_heap = NULL; static rb_bh *lclient_heap = NULL; static rb_bh *pclient_heap = NULL; static rb_bh *user_heap = NULL; -static rb_bh *metadata_heap = NULL; +static rb_bh *away_heap = NULL; static char current_uid[IDLEN]; struct Dictionary *nd_dict = NULL; @@ -120,7 +119,7 @@ init_client(void) lclient_heap = rb_bh_create(sizeof(struct LocalUser), LCLIENT_HEAP_SIZE, "lclient_heap"); pclient_heap = rb_bh_create(sizeof(struct PreClient), PCLIENT_HEAP_SIZE, "pclient_heap"); user_heap = rb_bh_create(sizeof(struct User), USER_HEAP_SIZE, "user_heap"); - metadata_heap = rb_bh_create(sizeof(struct MetadataEntry), USER_HEAP_SIZE, "metadata_heap"); + away_heap = rb_bh_create(AWAYLEN, AWAY_HEAP_SIZE, "away_heap"); rb_event_addish("check_pings", check_pings, NULL, 30); rb_event_addish("free_exited_clients", &free_exited_clients, NULL, 4); @@ -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 { @@ -585,7 +592,7 @@ check_xlines(void) 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); + aconf->host); continue; } @@ -1105,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; @@ -1115,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)); @@ -1138,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); @@ -1651,16 +1661,18 @@ struct User * make_user(struct Client *client_p) { struct User *user; + struct Dictionary *metadata; user = client_p->user; if(!user) { user = (struct User *) rb_bh_alloc(user_heap); user->refcnt = 1; - user->metadata = irc_dictionary_create(irccmp); client_p->user = user; - } + metadata = irc_dictionary_create(irccmp); + client_p->user->metadata = metadata; + } return user; } @@ -1672,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; @@ -1697,8 +1709,13 @@ make_server(struct Client *client_p) void free_user(struct User *user, struct Client *client_p) { + free_away(client_p); + if(--user->refcnt <= 0) { + if(user->away) + rb_free((char *) user->away); + /* * sanity check */ @@ -1725,63 +1742,21 @@ free_user(struct User *user, struct Client *client_p) } } -const char * -get_metadata(struct Client *client_p, const char *key) -{ - struct MetadataEntry *md; - - if (client_p->user != NULL) - { - md = irc_dictionary_retrieve(client_p->user->metadata, key); - if (md == NULL) - return NULL; - - return md->value; - } - - return NULL; -} - void -set_metadata(struct Client *client_p, const char *key, const char *value) +allocate_away(struct Client *client_p) { - struct MetadataEntry *md; - - if(client_p->user != NULL) - { - md = irc_dictionary_retrieve(client_p->user->metadata, key); - if (md == NULL) - { - md = rb_bh_alloc(metadata_heap); - rb_strlcpy(md->key, key, sizeof md->key); - irc_dictionary_add(client_p->user->metadata, md->key, md); - } - else if (!strcmp(md->key, key) && !strcmp(md->value, value)) - return; - else - rb_strlcpy(md->key, key, sizeof md->key); - - rb_strlcpy(md->value, value, sizeof md->value); - } - - sendto_common_channels_local_with_capability(client_p, CLICAP_PRESENCE, form_str(RPL_METADATACHG), me.name, client_p->name, key, value); + if(client_p->user->away == NULL) + client_p->user->away = rb_bh_alloc(away_heap); } + void -delete_metadata(struct Client *client_p, const char *key) +free_away(struct Client *client_p) { - struct MetadataEntry *md; - - if(client_p->user != NULL) - { - md = irc_dictionary_delete(client_p->user->metadata, key); - if (md == NULL) - return; - - rb_bh_free(metadata_heap, md); + if(client_p->user != NULL && client_p->user->away != NULL) { + rb_bh_free(away_heap, client_p->user->away); + client_p->user->away = NULL; } - - sendto_common_channels_local_with_capability(client_p, CLICAP_PRESENCE, form_str(RPL_METADATACHG), me.name, client_p->name, key, ""); } void @@ -1956,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); + } +}