/*
* ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001-2011 Alexander Barton (alex@barton.de) and Contributors.
+ * Copyright (c)2001-2012 Alexander Barton (alex@barton.de) and Contributors.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "imp.h"
#include <assert.h>
+#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "exp.h"
#include "irc-login.h"
-static void Kill_Nick PARAMS(( char *Nick, char *Reason ));
+static void Kill_Nick PARAMS((char *Nick, char *Reason));
+static void Change_Nick PARAMS((CLIENT * Origin, CLIENT * Target, char *NewNick,
+ bool InformClient));
+
/**
* Handler for the IRC "PASS" command.
} else
flags = "";
Log(LOG_INFO,
- "Peer on conenction %d announces itself as %s-%s using protocol %d.%d/IRC+ (flags: \"%s\").",
+ "Peer on connection %d announces itself as %s-%s using protocol %d.%d/IRC+ (flags: \"%s\").",
Client_Conn(Client), impl, serverver,
protohigh, protolow, flags);
} else {
Client_SetType( Client, CLIENT_GOTNICK );
} else {
/* Nickname change */
- if (Client_Conn(target) > NONE) {
- /* Local client */
- Log(LOG_INFO,
- "%s \"%s\" changed nick (connection %d): \"%s\" -> \"%s\".",
- Client_TypeText(target), Client_Mask(target),
- Client_Conn(target), Client_ID(target),
- Req->argv[0]);
- Conn_UpdateIdle(Client_Conn(target));
- } else {
- /* Remote client */
- LogDebug("%s \"%s\" changed nick: \"%s\" -> \"%s\".",
- Client_TypeText(target),
- Client_Mask(target), Client_ID(target),
- Req->argv[0]);
- }
-
- /* Inform all users and servers (which have to know)
- * of this nickname change */
- if( Client_Type( Client ) == CLIENT_USER )
- IRC_WriteStrClientPrefix( Client, Client,
- "NICK :%s",
- Req->argv[0] );
- IRC_WriteStrServersPrefix( Client, target,
- "NICK :%s", Req->argv[0] );
- IRC_WriteStrRelatedPrefix( target, target, false,
- "NICK :%s", Req->argv[0] );
-
- /* Register old nickname for WHOWAS queries */
- Client_RegisterWhowas( target );
-
- /* Save new nickname */
- Client_SetID( target, Req->argv[0] );
-
- IRC_SetPenalty( target, 2 );
+ Change_Nick(Client, target, Req->argv[0],
+ Client_Type(Client) == CLIENT_USER ? true : false);
+ IRC_SetPenalty(target, 2);
}
return CONNECTED;
} /* IRC_NICK */
+/**
+ * Handler for the IRC "SVSNICK" command.
+ *
+ * @param Client The client from which this command has been received.
+ * @param Req Request structure with prefix and all parameters.
+ * @return CONNECTED or DISCONNECTED.
+ */
+GLOBAL bool
+IRC_SVSNICK(CLIENT *Client, REQUEST *Req)
+{
+ CLIENT *from, *target;
+
+ assert(Client != NULL);
+ assert(Req != NULL);
+
+ if (Req->argc != 2)
+ return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
+ Client_ID(Client), Req->command);
+
+ /* Search the originator */
+ from = Client_Search(Req->prefix);
+ if (!from)
+ from = Client;
+
+ /* Search the target */
+ target = Client_Search(Req->argv[0]);
+ if (!target || Client_Type(target) != CLIENT_USER) {
+ return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
+ Client_ID(Client), Req->argv[0]);
+ }
+
+ if (Client_Conn(target) <= NONE) {
+ /* We have to forward the message to the server handling
+ * this user; this is required to make sure all servers
+ * in the network do follow the nick name change! */
+ return IRC_WriteStrClientPrefix(Client_NextHop(target), from,
+ "SVSNICK %s %s",
+ Req->argv[0], Req->argv[1]);
+ }
+
+ /* Make sure that the new nickname is valid */
+ if (!Client_CheckNick(from, Req->argv[1]))
+ return CONNECTED;
+
+ Change_Nick(from, target, Req->argv[1], true);
+ return CONNECTED;
+}
+
/**
* Handler for the IRC "USER" command.
*
Client_ID(Client),
Req->command);
- /* User name: only alphanumeric characters are allowed! */
+ /* User name: only alphanumeric characters and limited
+ punctuation is allowed.*/
ptr = Req->argv[0];
while (*ptr) {
- if ((*ptr < '0' || *ptr > '9') &&
- (*ptr < 'A' || *ptr > 'Z') &&
- (*ptr < 'a' || *ptr > 'z')) {
+ if (!isalnum((int)*ptr) &&
+ *ptr != '+' && *ptr != '-' && *ptr != '@' &&
+ *ptr != '.' && *ptr != '_') {
Conn_Close(Client_Conn(Client), NULL,
"Invalid user name", true);
return DISCONNECTED;
ptr++;
}
+ /* Save the received username for authentication, and use
+ * it up to the first '@' as default user name (like ircd2.11,
+ * bahamut, ircd-seven, ...), prefixed with '~', if needed: */
+ Client_SetOrigUser(Client, Req->argv[0]);
+ ptr = strchr(Req->argv[0], '@');
+ if (ptr)
+ *ptr = '\0';
#ifdef IDENTAUTH
ptr = Client_User(Client);
if (!ptr || !*ptr || *ptr == '~')
#else
Client_SetUser(Client, Req->argv[0], false);
#endif
- Client_SetOrigUser(Client, Req->argv[0]);
/* "Real name" or user info text: Don't set it to the empty
* string, the original ircd can't deal with such "real names"
hops = atoi(Req->argv[4]);
info = Req->argv[5];
- /* Validate service name ("nick name") */
+ /* Validate service name ("nickname") */
c = Client_Search(nick);
if(c) {
- /* Nick name collission: disconnect (KILL) both clients! */
+ /* Nickname collission: disconnect (KILL) both clients! */
Log(LOG_ERR, "Server %s introduces already registered service \"%s\"!",
Client_ID(Client), nick);
Kill_Nick(nick, "Nick collision");
}
if (target != Client) {
- Client_Destroy(target, "Got QUIT command.",
+ Client_Destroy(target, "Got QUIT command",
Req->argc == 1 ? quitmsg : NULL, true);
return CONNECTED;
} else {
- Conn_Close(Client_Conn(Client), "Got QUIT command.",
+ Conn_Close(Client_Conn(Client), "Got QUIT command",
Req->argc == 1 ? quitmsg : NULL, true);
return DISCONNECTED;
}
}
/* User, Service, or not yet registered */
- Conn_Close(Client_Conn(Client), "Got QUIT command.",
+ Conn_Close(Client_Conn(Client), "Got QUIT command",
Req->argc == 1 ? quitmsg : NULL, true);
return DISCONNECTED;
if (Client_Type(Client) == CLIENT_SERVER && Conn_LastPing(conn) == 0) {
Log(LOG_INFO,
- "Synchronization with \"%s\" done (connection %d): %ld seconds [%ld users, %ld channels]",
+ "Synchronization with \"%s\" done (connection %d): %ld second%s [%ld users, %ld channels].",
Client_ID(Client), conn, time(NULL) - Conn_GetSignon(conn),
+ time(NULL) - Conn_GetSignon(conn) == 1 ? "" : "s",
Client_UserCount(), Channel_CountVisible(NULL));
Conn_UpdatePing(conn);
} else
/**
- * Kill all users with a specific nick name in the network.
+ * Kill all users with a specific nickname in the network.
*
- * @param Nick Nick name.
+ * @param Nick Nickname.
* @param Reason Reason for the KILL.
*/
static void
r.argv[1] = Reason;
r.argc = 2;
- Log(LOG_ERR, "User(s) with nick \"%s\" will be disconnected: %s",
+ Log(LOG_ERR, "User(s) with nick \"%s\" will be disconnected: %s!",
Nick, Reason);
IRC_KILL(Client_ThisServer(), &r);
} /* Kill_Nick */
+/**
+ * Change the nickname of a client.
+ *
+ * @param Origin The client which caused the nickname change.
+ * @param Target The client of which the nickname should be changed.
+ * @param NewNick The new nickname.
+ */
+static void
+Change_Nick(CLIENT *Origin, CLIENT *Target, char *NewNick, bool InformClient)
+{
+ if (Client_Conn(Target) > NONE) {
+ /* Local client */
+ Log(LOG_INFO,
+ "%s \"%s\" changed nick (connection %d): \"%s\" -> \"%s\".",
+ Client_TypeText(Target), Client_Mask(Target),
+ Client_Conn(Target), Client_ID(Target), NewNick);
+ Conn_UpdateIdle(Client_Conn(Target));
+ } else {
+ /* Remote client */
+ LogDebug("%s \"%s\" changed nick: \"%s\" -> \"%s\".",
+ Client_TypeText(Target),
+ Client_Mask(Target), Client_ID(Target), NewNick);
+ }
+
+ /* Inform all servers and users (which have to know) of the new name */
+ if (InformClient) {
+ IRC_WriteStrClientPrefix(Target, Target, "NICK :%s", NewNick);
+ IRC_WriteStrServersPrefix(NULL, Target, "NICK :%s", NewNick);
+ } else
+ IRC_WriteStrServersPrefix(Origin, Target, "NICK :%s", NewNick);
+ IRC_WriteStrRelatedPrefix(Target, Target, false, "NICK :%s", NewNick);
+
+ /* Register old nickname for WHOWAS queries */
+ Client_RegisterWhowas(Target);
+
+ /* Save new nickname */
+ Client_SetID(Target, NewNick);
+}
+
+
/* -eof- */