X-Git-Url: https://jfr.im/git/irc/rqf/shadowircd.git/blobdiff_plain/95ffa6859587102dff666dff485800b40f4c6c58..90a3c35b295b07ebe3793bf5d3b882c3c1a5dc7c:/modules/core/m_nick.c diff --git a/modules/core/m_nick.c b/modules/core/m_nick.c index 326ab1a..b8b6771 100644 --- a/modules/core/m_nick.c +++ b/modules/core/m_nick.c @@ -21,7 +21,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * - * $Id: m_nick.c 3418 2007-04-22 11:22:10Z jilles $ + * $Id: m_nick.c 3518 2007-06-22 21:59:09Z jilles $ */ #include "stdinc.h" @@ -48,6 +48,13 @@ #include "s_newconf.h" #include "monitor.h" +/* Give all UID nicks the same TS. This ensures nick TS is always the same on + * all servers for each nick-user pair, also if a user with a UID nick changes + * their nick but is collided again (the server detecting the collision will + * not propagate the nick change further). -- jilles + */ +#define SAVE_NICKTS 100 + static int mr_nick(struct Client *, struct Client *, int, const char **); static int m_nick(struct Client *, struct Client *, int, const char **); static int mc_nick(struct Client *, struct Client *, int, const char **); @@ -78,7 +85,7 @@ struct Message save_msgtab = { mapi_clist_av1 nick_clist[] = { &nick_msgtab, &uid_msgtab, &euid_msgtab, &save_msgtab, NULL }; -DECLARE_MODULE_AV1(nick, NULL, NULL, nick_clist, NULL, NULL, "$Revision: 3418 $"); +DECLARE_MODULE_AV1(nick, NULL, NULL, nick_clist, NULL, NULL, "$Revision: 3518 $"); static int change_remote_nick(struct Client *, struct Client *, time_t, const char *, int); @@ -149,7 +156,7 @@ mr_nick(struct Client *client_p, struct Client *source_p, int parc, const char * return 0; } - if(hash_find_nd(nick)) + if(irc_dictionary_find(nd_dict, nick)) { sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), me.name, EmptyString(source_p->name) ? "*" : source_p->name, nick); @@ -210,7 +217,7 @@ m_nick(struct Client *client_p, struct Client *source_p, int parc, const char *p return 0; } - if(hash_find_nd(nick)) + if(irc_dictionary_find(nd_dict, nick)) { sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), me.name, EmptyString(source_p->name) ? "*" : source_p->name, nick); @@ -277,7 +284,7 @@ mc_nick(struct Client *client_p, struct Client *source_p, int parc, const char * ServerStats->is_kill++; sendto_realops_snomask(SNO_DEBUG, L_ALL, "Bad Nick: %s From: %s(via %s)", - parv[1], source_p->user->server, client_p->name); + parv[1], source_p->servptr->name, client_p->name); sendto_one(client_p, ":%s KILL %s :%s (Bad Nickname)", me.name, parv[1], me.name); /* bad nick change, issue kill for the old nick to the rest @@ -724,6 +731,7 @@ static void set_initial_nick(struct Client *client_p, struct Client *source_p, char *nick) { char buf[USERLEN + 1]; + char note[NICKLEN + 10]; /* This had to be copied here to avoid problems.. */ source_p->tsinfo = CurrentTime; @@ -733,8 +741,8 @@ set_initial_nick(struct Client *client_p, struct Client *source_p, char *nick) strcpy(source_p->name, nick); add_to_client_hash(nick, source_p); - /* fd_desc is long enough */ - comm_note(client_p->localClient->fd, "Nick: %s", nick); + rb_snprintf(note, sizeof(note), "Nick: %s", nick); + rb_note(client_p->localClient->F, note); if(source_p->flags & FLAGS_SENTUSER) { @@ -751,8 +759,9 @@ change_local_nick(struct Client *client_p, struct Client *source_p, char *nick, int dosend) { struct Client *target_p; - dlink_node *ptr, *next_ptr; + rb_dlink_node *ptr, *next_ptr; struct Channel *chptr; + char note[NICKLEN + 10]; int samenick; if (dosend) @@ -834,16 +843,16 @@ change_local_nick(struct Client *client_p, struct Client *source_p, * to clear a clients own list of accepted clients. So just remove * them from everyone elses list --anfl */ - DLINK_FOREACH_SAFE(ptr, next_ptr, source_p->on_allow_list.head) + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, source_p->on_allow_list.head) { target_p = ptr->data; - dlinkFindDestroy(source_p, &target_p->localClient->allow_list); - dlinkDestroy(ptr, &source_p->on_allow_list); + rb_dlinkFindDestroy(source_p, &target_p->localClient->allow_list); + rb_dlinkDestroy(ptr, &source_p->on_allow_list); } - /* fd_desc is long enough */ - comm_note(client_p->localClient->fd, "Nick: %s", nick); + rb_snprintf(note, sizeof(note), "Nick: %s", nick); + rb_note(client_p->localClient->F, note); return; } @@ -883,7 +892,7 @@ change_remote_nick(struct Client *client_p, struct Client *source_p, del_from_client_hash(source_p->name, source_p); /* invalidate nick delay when a remote client uses the nick.. */ - if((nd = hash_find_nd(nick))) + if((nd = irc_dictionary_retrieve(nd_dict, nick))) free_nd_entry(nd); strcpy(source_p->name, nick); @@ -925,7 +934,7 @@ perform_nick_collides(struct Client *source_p, struct Client *client_p, sendto_one(client_p, ":%s SAVE %s %ld", me.id, uid, (long)newts); register_client(client_p, source_p, - uid, newts, parc, parv); + uid, SAVE_NICKTS, parc, parv); } else { @@ -966,7 +975,7 @@ perform_nick_collides(struct Client *source_p, struct Client *client_p, sendto_one(client_p, ":%s SAVE %s %ld", me.id, uid, (long)newts); register_client(client_p, source_p, - uid, newts, parc, parv); + uid, SAVE_NICKTS, parc, parv); } else if(uid) sendto_one(client_p, @@ -1044,7 +1053,7 @@ perform_nickchange_collides(struct Client *source_p, struct Client *client_p, source_p->id, (long)newts); /* don't send a redundant nick change */ if (!IsDigit(source_p->name[0])) - change_remote_nick(client_p, source_p, CurrentTime, source_p->id, 1); + change_remote_nick(client_p, source_p, SAVE_NICKTS, source_p->id, 1); } else { @@ -1092,10 +1101,9 @@ perform_nickchange_collides(struct Client *source_p, struct Client *client_p, * but not in other directions -- jilles */ sendto_one(client_p, ":%s SAVE %s %ld", me.id, source_p->id, (long)newts); - /* same CurrentTime as in save_user() */ /* send a : NICK (!) */ if (!IsDigit(source_p->name[0])) - change_remote_nick(client_p, source_p, CurrentTime, source_p->id, 1); + change_remote_nick(client_p, source_p, SAVE_NICKTS, source_p->id, 1); } else { @@ -1166,9 +1174,22 @@ register_client(struct Client *client_p, struct Client *server, const char *m; int flag; + if(server == NULL) + { + if((server = find_server(NULL, parv[7])) == NULL) + { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Ghost killed: %s on invalid server %s", + nick, parv[7]); + sendto_one(client_p, ":%s KILL %s :%s (Server doesn't exist)", + get_id(&me, client_p), nick, me.name); + return 0; + } + } + source_p = make_client(client_p); user = make_user(source_p); - dlinkAddTail(source_p, &source_p->node, &global_client_list); + rb_dlinkAddTail(source_p, &source_p->node, &global_client_list); source_p->hopcount = atoi(parv[2]); source_p->tsinfo = newts; @@ -1180,7 +1201,6 @@ register_client(struct Client *client_p, struct Client *server, if(parc == 12) { - user->server = find_or_add(server->name); strlcpy(source_p->info, parv[11], sizeof(source_p->info)); strlcpy(source_p->sockhost, parv[7], sizeof(source_p->sockhost)); strlcpy(source_p->id, parv[8], sizeof(source_p->id)); @@ -1196,7 +1216,6 @@ register_client(struct Client *client_p, struct Client *server, } else if(parc == 10) { - user->server = find_or_add(server->name); strlcpy(source_p->info, parv[9], sizeof(source_p->info)); strlcpy(source_p->sockhost, parv[7], sizeof(source_p->sockhost)); strlcpy(source_p->id, parv[8], sizeof(source_p->id)); @@ -1204,16 +1223,15 @@ register_client(struct Client *client_p, struct Client *server, } else { - user->server = find_or_add(parv[7]); strlcpy(source_p->info, parv[8], sizeof(source_p->info)); } /* remove any nd entries for this nick */ - if((nd = hash_find_nd(nick))) + if((nd = irc_dictionary_retrieve(nd_dict, nick))) free_nd_entry(nd); add_to_client_hash(nick, source_p); - add_to_hostname_hash(source_p->host, source_p); + add_to_hostname_hash(source_p->orighost, source_p); monitor_signon(source_p); m = &parv[4][1]; @@ -1224,11 +1242,11 @@ register_client(struct Client *client_p, struct Client *server, if(flag & UMODE_SERVICE) { int hit = 0; - dlink_node *ptr; + rb_dlink_node *ptr; - DLINK_FOREACH(ptr, service_list.head) + RB_DLINK_FOREACH(ptr, service_list.head) { - if(!irccmp((const char *) ptr->data, user->server)) + if(!irccmp((const char *) ptr->data, server->name)) { hit++; break; @@ -1255,29 +1273,16 @@ register_client(struct Client *client_p, struct Client *server, } if(IsOper(source_p) && !IsService(source_p)) - dlinkAddAlloc(source_p, &oper_list); + rb_dlinkAddAlloc(source_p, &oper_list); SetRemoteClient(source_p); if(++Count.total > Count.max_tot) Count.max_tot = Count.total; - if(server == NULL) - { - if((source_p->servptr = find_server(NULL, user->server)) == NULL) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Ghost killed: %s on invalid server %s", - source_p->name, user->server); - kill_client(client_p, source_p, "%s (Server doesn't exist)", me.name); - source_p->flags |= FLAGS_KILLED; - return exit_client(NULL, source_p, &me, "Ghosted Client"); - } - } - else - source_p->servptr = server; + source_p->servptr = server; - dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->users); + rb_dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->users); /* fake direction */ if(source_p->servptr->from != source_p->from) @@ -1288,10 +1293,10 @@ register_client(struct Client *client_p, struct Client *server, "Bad User [%s] :%s USER %s@%s %s, != %s[%s]", client_p->name, source_p->name, source_p->username, source_p->host, - user->server, target_p->name, target_p->from->name); + server->name, target_p->name, target_p->from->name); kill_client(client_p, source_p, "%s (NICK from wrong direction (%s != %s))", - me.name, user->server, target_p->from->name); + me.name, server->name, target_p->from->name); source_p->flags |= FLAGS_KILLED; return exit_client(source_p, source_p, &me, "USER server wrong direction"); } @@ -1343,9 +1348,9 @@ save_user(struct Client *client_p, struct Client *source_p, sendto_server(client_p, NULL, CAP_SAVE|CAP_TS6, NOCAPS, ":%s SAVE %s %ld", source_p->id, target_p->id, (long)target_p->tsinfo); sendto_server(client_p, NULL, CAP_TS6, CAP_SAVE, ":%s NICK %s :%ld", - target_p->id, target_p->id, (long)CurrentTime); + target_p->id, target_p->id, (long)SAVE_NICKTS); sendto_server(client_p, NULL, NOCAPS, CAP_TS6, ":%s NICK %s :%ld", - target_p->name, target_p->id, (long)CurrentTime); + target_p->name, target_p->id, (long)SAVE_NICKTS); if (!IsMe(client_p)) sendto_realops_snomask(SNO_SKILL, L_ALL, "Received SAVE message for %s from %s", @@ -1355,10 +1360,8 @@ save_user(struct Client *client_p, struct Client *source_p, sendto_one_numeric(target_p, RPL_SAVENICK, form_str(RPL_SAVENICK), target_p->id); change_local_nick(target_p, target_p, target_p->id, 0); + target_p->tsinfo = SAVE_NICKTS; } else - { - /* XXX the uid nick gets garbage TS; shouldn't matter though */ - change_remote_nick(target_p, target_p, CurrentTime, target_p->id, 0); - } + change_remote_nick(target_p, target_p, SAVE_NICKTS, target_p->id, 0); }