2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2010 Alexander Barton (alex@barton.de)
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * Please read the file COPYING, README and AUTHORS for more information.
26 #include "conn-func.h"
36 #include "irc-write.h"
39 #include "irc-login.h"
42 static bool Hello_User PARAMS(( CLIENT *Client ));
43 static bool Hello_User_PostAuth PARAMS(( CLIENT *Client ));
44 static void Kill_Nick PARAMS(( char *Nick, char *Reason ));
45 static void Introduce_Client PARAMS((CLIENT *To, CLIENT *Client, int Type));
46 static void Reject_Client PARAMS((CLIENT *Client));
48 static void cb_introduceClient PARAMS((CLIENT *Client, CLIENT *Prefix,
52 static void cb_Read_Auth_Result PARAMS((int r_fd, UNUSED short events));
56 * Handler for the IRC command "PASS".
57 * See RFC 2813 section 4.1.1, and RFC 2812 section 3.1.1.
60 IRC_PASS( CLIENT *Client, REQUEST *Req )
62 char *type, *orig_flags;
63 int protohigh, protolow;
65 assert( Client != NULL );
66 assert( Req != NULL );
68 /* Return an error if this is not a local client */
69 if (Client_Conn(Client) <= NONE)
70 return IRC_WriteStrClient(Client, ERR_UNKNOWNCOMMAND_MSG,
71 Client_ID(Client), Req->command);
73 if (Client_Type(Client) == CLIENT_UNKNOWN && Req->argc == 1) {
74 /* Not yet registered "unknown" connection, PASS with one
75 * argument: either a regular client, service, or server
76 * using the old RFC 1459 section 4.1.1 syntax. */
77 LogDebug("Connection %d: got PASS command (RFC 1459) ...",
79 } else if ((Client_Type(Client) == CLIENT_UNKNOWN ||
80 Client_Type(Client) == CLIENT_UNKNOWNSERVER) &&
81 (Req->argc == 3 || Req->argc == 4)) {
82 /* Not yet registered "unknown" connection or outgoing server
83 * link, PASS with three or four argument: server using the
84 * RFC 2813 section 4.1.1 syntax. */
85 LogDebug("Connection %d: got PASS command (RFC 2813, new server link) ...",
87 } else if (Client_Type(Client) == CLIENT_UNKNOWN ||
88 Client_Type(Client) == CLIENT_UNKNOWNSERVER) {
89 /* Unregistered connection, but wrong number of arguments: */
90 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
91 Client_ID(Client), Req->command);
93 /* Registered connection, PASS command is not allowed! */
94 return IRC_WriteStrClient(Client, ERR_ALREADYREGISTRED_MSG,
98 Client_SetPassword(Client, Req->argv[0]);
100 /* Protocol version */
101 if (Req->argc >= 2 && strlen(Req->argv[1]) >= 4) {
104 c2 = Req->argv[1][2];
105 c4 = Req->argv[1][4];
107 Req->argv[1][4] = '\0';
108 protolow = atoi(&Req->argv[1][2]);
109 Req->argv[1][2] = '\0';
110 protohigh = atoi(Req->argv[1]);
112 Req->argv[1][2] = c2;
113 Req->argv[1][4] = c4;
115 Client_SetType(Client, CLIENT_GOTPASS_2813);
117 protohigh = protolow = 0;
118 Client_SetType(Client, CLIENT_GOTPASS);
121 /* Protocol type, see doc/Protocol.txt */
122 if (Req->argc >= 2 && strlen(Req->argv[1]) > 4)
123 type = &Req->argv[1][4];
127 /* Protocol flags/options */
129 orig_flags = Req->argv[3];
133 /* Implementation, version and IRC+ flags */
134 if (Req->argc >= 3) {
135 char *impl, *ptr, *serverver, *flags;
138 ptr = strchr(impl, '|');
142 if (type && strcmp(type, PROTOIRCPLUS) == 0) {
143 /* The peer seems to be a server which supports the
144 * IRC+ protocol (see doc/Protocol.txt). */
146 flags = strchr(serverver, ':');
153 "Peer announces itself as %s-%s using protocol %d.%d/IRC+ (flags: \"%s\").",
154 impl, serverver, protohigh, protolow, flags);
156 /* The peer seems to be a server supporting the
157 * "original" IRC protocol (RFC 2813). */
158 if (strchr(orig_flags, 'Z'))
163 "Peer announces itself as \"%s\" using protocol %d.%d (flags: \"%s\").",
164 impl, protohigh, protolow, flags);
166 Client_SetFlags(Client, flags);
174 * IRC "NICK" command.
175 * This function implements the IRC command "NICK" which is used to register
176 * with the server, to change already registered nicknames and to introduce
177 * new users which are connected to other servers.
180 IRC_NICK( CLIENT *Client, REQUEST *Req )
182 CLIENT *intr_c, *target, *c;
183 char *nick, *user, *hostname, *modes, *info;
186 assert( Client != NULL );
187 assert( Req != NULL );
189 /* Some IRC clients, for example BitchX, send the NICK and USER
190 * commands in the wrong order ... */
191 if(Client_Type(Client) == CLIENT_UNKNOWN
192 || Client_Type(Client) == CLIENT_GOTPASS
193 || Client_Type(Client) == CLIENT_GOTNICK
195 || Client_Type(Client) == CLIENT_GOTUSER
197 || Client_Type(Client) == CLIENT_USER
198 || Client_Type(Client) == CLIENT_SERVICE
199 || (Client_Type(Client) == CLIENT_SERVER && Req->argc == 1))
201 /* User registration or change of nickname */
203 /* Wrong number of arguments? */
205 return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG,
209 /* Search "target" client */
210 if( Client_Type( Client ) == CLIENT_SERVER )
212 target = Client_Search( Req->prefix );
214 return IRC_WriteStrClient( Client,
221 /* Is this a restricted client? */
222 if( Client_HasMode( Client, 'r' ))
223 return IRC_WriteStrClient( Client,
225 Client_ID( Client ));
231 /* If the clients tries to change to its own nickname we won't
232 * do anything. This is how the original ircd behaves and some
233 * clients (for example Snak) expect it to be like this.
234 * But I doubt that this is "really the right thing" ... */
235 if( strcmp( Client_ID( target ), Req->argv[0] ) == 0 )
239 /* Check that the new nickname is available. Special case:
240 * the client only changes from/to upper to lower case. */
241 if( strcasecmp( Client_ID( target ), Req->argv[0] ) != 0 )
243 if( ! Client_CheckNick( target, Req->argv[0] ))
247 if (Client_Type(target) != CLIENT_USER &&
248 Client_Type(target) != CLIENT_SERVICE &&
249 Client_Type(target) != CLIENT_SERVER) {
251 LogDebug("Connection %d: got valid NICK command ...",
252 Client_Conn( Client ));
254 /* Register new nickname of this client */
255 Client_SetID( target, Req->argv[0] );
257 /* If we received a valid USER command already then
258 * register the new client! */
259 if( Client_Type( Client ) == CLIENT_GOTUSER )
260 return Hello_User( Client );
262 Client_SetType( Client, CLIENT_GOTNICK );
264 /* Nickname change */
265 if (Client_Conn(target) > NONE) {
268 "%s \"%s\" changed nick (connection %d): \"%s\" -> \"%s\".",
269 Client_TypeText(target), Client_Mask(target),
270 Client_Conn(target), Client_ID(target),
272 Conn_UpdateIdle(Client_Conn(target));
275 LogDebug("%s \"%s\" changed nick: \"%s\" -> \"%s\".",
276 Client_TypeText(target),
277 Client_Mask(target), Client_ID(target),
281 /* Inform all users and servers (which have to know)
282 * of this nickname change */
283 if( Client_Type( Client ) == CLIENT_USER )
284 IRC_WriteStrClientPrefix( Client, Client,
287 IRC_WriteStrServersPrefix( Client, target,
288 "NICK :%s", Req->argv[0] );
289 IRC_WriteStrRelatedPrefix( target, target, false,
290 "NICK :%s", Req->argv[0] );
292 /* Register old nickname for WHOWAS queries */
293 Client_RegisterWhowas( target );
295 /* Save new nickname */
296 Client_SetID( target, Req->argv[0] );
298 IRC_SetPenalty( target, 2 );
302 } else if(Client_Type(Client) == CLIENT_SERVER ||
303 Client_Type(Client) == CLIENT_SERVICE) {
304 /* Server or service introduces new client */
306 /* Bad number of parameters? */
307 if (Req->argc != 2 && Req->argc != 7)
308 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
309 Client_ID(Client), Req->command);
311 if (Req->argc >= 7) {
312 /* RFC 2813 compatible syntax */
314 hops = atoi(Req->argv[1]);
316 hostname = Req->argv[3];
317 token = atoi(Req->argv[4]);
318 modes = Req->argv[5] + 1;
321 /* RFC 1459 compatible syntax */
325 hostname = Client_ID(Client);
326 token = atoi(Req->argv[1]);
331 c = Client_Search(nick);
334 * the new nick is already present on this server:
335 * the new and the old one have to be disconnected now.
337 Log( LOG_ERR, "Server %s introduces already registered nick \"%s\"!", Client_ID( Client ), Req->argv[0] );
338 Kill_Nick( Req->argv[0], "Nick collision" );
342 /* Find the Server this client is connected to */
343 intr_c = Client_GetFromToken(Client, token);
346 Log( LOG_ERR, "Server %s introduces nick \"%s\" on unknown server!?", Client_ID( Client ), Req->argv[0] );
347 Kill_Nick( Req->argv[0], "Unknown server" );
351 c = Client_NewRemoteUser(intr_c, nick, hops, user, hostname,
352 token, modes, info, true);
355 /* out of memory, need to disconnect client to keep network state consistent */
356 Log( LOG_ALERT, "Can't create client structure! (on connection %d)", Client_Conn( Client ));
357 Kill_Nick( Req->argv[0], "Server error" );
361 /* RFC 2813: client is now fully registered, inform all the
362 * other servers about the new user.
363 * RFC 1459: announce the new client only after receiving the
364 * USER command, first we need more information! */
366 LogDebug("Client \"%s\" is being registered (RFC 1459) ...",
368 Client_SetType(c, CLIENT_GOTNICK);
370 Introduce_Client(Client, c, CLIENT_USER);
374 else return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
379 * Handler for the IRC command "USER".
382 IRC_USER(CLIENT * Client, REQUEST * Req)
389 assert(Client != NULL);
392 if (Client_Type(Client) == CLIENT_GOTNICK ||
394 Client_Type(Client) == CLIENT_UNKNOWN ||
396 Client_Type(Client) == CLIENT_GOTPASS)
400 return IRC_WriteStrClient(Client,
401 ERR_NEEDMOREPARAMS_MSG,
407 ptr = Client_User(Client);
408 if (!ptr || !*ptr || *ptr == '~')
409 Client_SetUser(Client, Req->argv[0], false);
411 Client_SetUser(Client, Req->argv[0], false);
413 Client_SetOrigUser(Client, Req->argv[0]);
415 /* "Real name" or user info text: Don't set it to the empty
416 * string, the original ircd can't deal with such "real names"
417 * (e. g. "USER user * * :") ... */
419 Client_SetInfo(Client, Req->argv[3]);
421 Client_SetInfo(Client, "-");
423 LogDebug("Connection %d: got valid USER command ...",
424 Client_Conn(Client));
425 if (Client_Type(Client) == CLIENT_GOTNICK)
426 return Hello_User(Client);
428 Client_SetType(Client, CLIENT_GOTUSER);
431 } else if (Client_Type(Client) == CLIENT_SERVER ||
432 Client_Type(Client) == CLIENT_SERVICE) {
433 /* Server/service updating an user */
435 return IRC_WriteStrClient(Client,
436 ERR_NEEDMOREPARAMS_MSG,
439 c = Client_Search(Req->prefix);
441 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
445 Client_SetUser(c, Req->argv[0], true);
446 Client_SetOrigUser(c, Req->argv[0]);
447 Client_SetHostname(c, Req->argv[1]);
448 Client_SetInfo(c, Req->argv[3]);
450 LogDebug("Connection %d: got valid USER command for \"%s\".",
451 Client_Conn(Client), Client_Mask(c));
453 /* RFC 1459 style user registration?
454 * Introduce client to network: */
455 if (Client_Type(c) == CLIENT_GOTNICK)
456 Introduce_Client(Client, c, CLIENT_USER);
459 } else if (Client_Type(Client) == CLIENT_USER) {
460 /* Already registered connection */
461 return IRC_WriteStrClient(Client, ERR_ALREADYREGISTRED_MSG,
464 /* Unexpected/invalid connection state? */
465 return IRC_WriteStrClient(Client, ERR_NOTREGISTERED_MSG,
472 * Handler for the IRC command "SERVICE".
473 * This function implements IRC Services registration using the SERVICE command
474 * defined in RFC 2812 3.1.6 and RFC 2813 4.1.4.
475 * At the moment ngIRCd doesn't support directly linked services, so this
476 * function returns ERR_ERRONEUSNICKNAME when the SERVICE command has not been
477 * received from a peer server.
480 IRC_SERVICE(CLIENT *Client, REQUEST *Req)
483 char *nick, *user, *host, *info, *modes, *ptr;
486 assert(Client != NULL);
489 if (Client_Type(Client) != CLIENT_GOTPASS &&
490 Client_Type(Client) != CLIENT_SERVER)
491 return IRC_WriteStrClient(Client, ERR_ALREADYREGISTRED_MSG,
495 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
496 Client_ID(Client), Req->command);
498 if (Client_Type(Client) != CLIENT_SERVER)
499 return IRC_WriteStrClient(Client, ERR_ERRONEUSNICKNAME_MSG,
500 Client_ID(Client), Req->argv[0]);
502 /* Bad number of parameters? */
504 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
505 Client_ID(Client), Req->command);
508 user = NULL; host = NULL;
509 token = atoi(Req->argv[1]);
510 hops = atoi(Req->argv[4]);
513 /* Validate service name ("nick name") */
514 c = Client_Search(nick);
516 /* Nick name collission: disconnect (KILL) both clients! */
517 Log(LOG_ERR, "Server %s introduces already registered service \"%s\"!",
518 Client_ID(Client), nick);
519 Kill_Nick(nick, "Nick collision");
523 /* Get the server to which the service is connected */
524 intr_c = Client_GetFromToken(Client, token);
526 Log(LOG_ERR, "Server %s introduces service \"%s\" on unknown server!?",
527 Client_ID(Client), nick);
528 Kill_Nick(nick, "Unknown server");
532 /* Get user and host name */
533 ptr = strchr(nick, '@');
539 host = Client_Hostname(intr_c);
540 ptr = strchr(nick, '!');
548 /* According to RFC 2812/2813 parameter 4 <type> "is currently reserved
549 * for future usage"; but we use it to transfer the modes and check
550 * that the first character is a '+' sign and ignore it otherwise. */
551 modes = (Req->argv[3][0] == '+') ? ++Req->argv[3] : "";
553 c = Client_NewRemoteUser(intr_c, nick, hops, user, host,
554 token, modes, info, true);
556 /* Couldn't create client structure, so KILL the service to
557 * keep network status consistent ... */
558 Log(LOG_ALERT, "Can't create client structure! (on connection %d)",
559 Client_Conn(Client));
560 Kill_Nick(nick, "Server error");
564 Introduce_Client(Client, c, CLIENT_SERVICE);
570 * Handler for the IRC command "WEBIRC".
571 * Syntax: WEBIRC <password> <username> <real-hostname> <real-IP-address>
574 IRC_WEBIRC(CLIENT *Client, REQUEST *Req)
576 /* Exactly 4 parameters are requited */
578 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
579 Client_ID(Client), Req->command);
581 if (!Conf_WebircPwd[0] || strcmp(Req->argv[0], Conf_WebircPwd) != 0)
582 return IRC_WriteStrClient(Client, ERR_PASSWDMISMATCH_MSG,
585 LogDebug("Connection %d: got valid WEBIRC command: user=%s, host=%s, ip=%s",
586 Client_Conn(Client), Req->argv[1], Req->argv[2], Req->argv[3]);
588 Client_SetUser(Client, Req->argv[1], true);
589 Client_SetOrigUser(Client, Req->argv[1]);
590 Client_SetHostname(Client, Req->argv[2]);
596 IRC_QUIT( CLIENT *Client, REQUEST *Req )
599 char quitmsg[LINE_LEN];
601 assert( Client != NULL );
602 assert( Req != NULL );
604 /* Wrong number of arguments? */
606 return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
609 strlcpy(quitmsg, Req->argv[0], sizeof quitmsg);
611 if ( Client_Type( Client ) == CLIENT_SERVER )
614 target = Client_Search( Req->prefix );
617 Log( LOG_WARNING, "Got QUIT from %s for unknown client!?", Client_ID( Client ));
621 Client_Destroy( target, "Got QUIT command.", Req->argc == 1 ? quitmsg : NULL, true);
627 if (Req->argc == 1 && quitmsg[0] != '\"') {
628 /* " " to avoid confusion */
629 strlcpy(quitmsg, "\"", sizeof quitmsg);
630 strlcat(quitmsg, Req->argv[0], sizeof quitmsg-1);
631 strlcat(quitmsg, "\"", sizeof quitmsg );
634 /* User, Service, or not yet registered */
635 Conn_Close( Client_Conn( Client ), "Got QUIT command.", Req->argc == 1 ? quitmsg : NULL, true);
643 IRC_PING(CLIENT *Client, REQUEST *Req)
645 CLIENT *target, *from;
647 assert(Client != NULL);
651 return IRC_WriteStrClient(Client, ERR_NOORIGIN_MSG,
654 /* Don't ignore additional arguments when in "strict" mode */
656 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
657 Client_ID(Client), Req->command);
661 /* A target has been specified ... */
662 target = Client_Search(Req->argv[1]);
664 if (!target || Client_Type(target) != CLIENT_SERVER)
665 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
666 Client_ID(Client), Req->argv[1]);
668 if (target != Client_ThisServer()) {
669 /* Ok, we have to forward the PING */
670 if (Client_Type(Client) == CLIENT_SERVER)
671 from = Client_Search(Req->prefix);
675 return IRC_WriteStrClient(Client,
676 ERR_NOSUCHSERVER_MSG,
677 Client_ID(Client), Req->prefix);
679 return IRC_WriteStrClientPrefix(target, from,
680 "PING %s :%s", Req->argv[0],
685 if (Client_Type(Client) == CLIENT_SERVER) {
687 from = Client_Search(Req->prefix);
691 from = Client_ThisServer();
693 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
694 Client_ID(Client), Req->prefix);
696 Log(LOG_DEBUG, "Connection %d: got PING, sending PONG ...",
697 Client_Conn(Client));
700 return IRC_WriteStrClient(Client, "PONG %s :%s",
701 Client_ID(from), Client_ID(Client));
703 /* Some clients depend on the argument being returned in the PONG
704 * reply (not mentioned in any RFC, though) */
705 return IRC_WriteStrClient(Client, "PONG %s :%s",
706 Client_ID(from), Req->argv[0]);
712 IRC_PONG(CLIENT *Client, REQUEST *Req)
714 CLIENT *target, *from;
717 assert(Client != NULL);
720 /* Wrong number of arguments? */
722 return IRC_WriteStrClient(Client, ERR_NOORIGIN_MSG,
725 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
726 Client_ID(Client), Req->command);
729 if (Req->argc == 2 && Client_Type(Client) == CLIENT_SERVER) {
730 target = Client_Search(Req->argv[0]);
732 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
733 Client_ID(Client), Req->argv[0]);
735 from = Client_Search(Req->prefix);
737 if (target != Client_ThisServer() && target != from) {
738 /* Ok, we have to forward the message. */
740 return IRC_WriteStrClient(Client,
741 ERR_NOSUCHSERVER_MSG,
742 Client_ID(Client), Req->prefix);
744 if (Client_Type(Client_NextHop(target)) != CLIENT_SERVER)
748 return IRC_WriteStrClientPrefix(target, from,
749 "PONG %s :%s", s, Req->argv[1]);
753 /* The connection timestamp has already been updated when the data has
754 * been read from so socket, so we don't need to update it here. */
756 if (Client_Conn(Client) > NONE)
758 "Connection %d: received PONG. Lag: %ld seconds.",
760 time(NULL) - Conn_LastPing(Client_Conn(Client)));
763 "Connection %d: received PONG.", Client_Conn(Client));
770 Hello_User(CLIENT * Client)
773 int pipefd[2], result;
777 assert(Client != NULL);
778 conn = Client_Conn(Client);
780 pid = Proc_Fork(Conn_GetProcStat(conn), pipefd, cb_Read_Auth_Result);
782 LogDebug("Authenticator for connection %d created (PID %d).",
787 signal(SIGTERM, Proc_GenericSignalHandler);
788 Log_Init_Subprocess("Auth");
789 result = PAM_Authenticate(Client);
790 write(pipefd[1], &result, sizeof(result));
791 Log_Exit_Subprocess("Auth");
795 assert(Client != NULL);
797 /* Check global server password ... */
798 if (strcmp(Client_Password(Client), Conf_ServerPwd) != 0) {
800 Reject_Client(Client);
803 return Hello_User_PostAuth(Client);
811 * Read result of the authenticatior sub-process from pipe
814 cb_Read_Auth_Result(int r_fd, UNUSED short events)
822 LogDebug("Auth: Got callback on fd %d, events %d", r_fd, events);
823 conn = Conn_GetFromProc(r_fd);
825 /* Ops, none found? Probably the connection has already
826 * been closed!? We'll ignore that ... */
828 LogDebug("Auth: Got callback for unknown connection!?");
831 proc = Conn_GetProcStat(conn);
832 client = Conn_GetClient(conn);
834 /* Read result from pipe */
835 len = Proc_Read(proc, &result, sizeof(result));
839 /* Make sure authenticator sub-process is dead now ... */
842 if (len != sizeof(result)) {
843 Log(LOG_CRIT, "Auth: Got malformed result!");
844 Reject_Client(client);
849 (void)Hello_User_PostAuth(client);
851 Reject_Client(client);
858 Reject_Client(CLIENT *Client)
861 "User \"%s\" rejected (connection %d): Access denied!",
862 Client_Mask(Client), Client_Conn(Client));
863 Conn_Close(Client_Conn(Client), NULL,
864 "Access denied! Bad password?", true);
869 Hello_User_PostAuth(CLIENT *Client)
871 Introduce_Client(NULL, Client, CLIENT_USER);
873 if (!IRC_WriteStrClient
874 (Client, RPL_WELCOME_MSG, Client_ID(Client), Client_Mask(Client)))
876 if (!IRC_WriteStrClient
877 (Client, RPL_YOURHOST_MSG, Client_ID(Client),
878 Client_ID(Client_ThisServer()), PACKAGE_VERSION, TARGET_CPU,
879 TARGET_VENDOR, TARGET_OS))
881 if (!IRC_WriteStrClient
882 (Client, RPL_CREATED_MSG, Client_ID(Client), NGIRCd_StartStr))
884 if (!IRC_WriteStrClient
885 (Client, RPL_MYINFO_MSG, Client_ID(Client),
886 Client_ID(Client_ThisServer()), PACKAGE_VERSION, USERMODES,
890 /* Features supported by this server (005 numeric, ISUPPORT),
891 * see <http://www.irc.org/tech_docs/005.html> for details. */
892 if (!IRC_Send_ISUPPORT(Client))
895 if (!IRC_Send_LUSERS(Client))
897 if (!IRC_Show_MOTD(Client))
900 /* Suspend the client for a second ... */
901 IRC_SetPenalty(Client, 1);
908 Kill_Nick( char *Nick, char *Reason )
912 assert( Nick != NULL );
913 assert( Reason != NULL );
915 r.prefix = (char *)Client_ThisServer( );
920 Log( LOG_ERR, "User(s) with nick \"%s\" will be disconnected: %s", Nick, Reason );
921 IRC_KILL( Client_ThisServer( ), &r );
926 Introduce_Client(CLIENT *From, CLIENT *Client, int Type)
928 /* Set client type (user or service) */
929 Client_SetType(Client, Type);
932 if (Conf_IsService(Conf_GetServer(Client_Conn(From)),
934 Client_SetType(Client, CLIENT_SERVICE);
935 LogDebug("%s \"%s\" (+%s) registered (via %s, on %s, %d hop%s).",
936 Client_TypeText(Client), Client_Mask(Client),
937 Client_Modes(Client), Client_ID(From),
938 Client_ID(Client_Introducer(Client)),
939 Client_Hops(Client), Client_Hops(Client) > 1 ? "s": "");
941 Log(LOG_NOTICE, "%s \"%s\" registered (connection %d).",
942 Client_TypeText(Client), Client_Mask(Client),
943 Client_Conn(Client));
944 Log_ServerNotice('c', "Client connecting: %s (%s@%s) [%s] - %s",
945 Client_ID(Client), Client_User(Client),
946 Client_Hostname(Client),
947 Conn_IPA(Client_Conn(Client)),
948 Client_TypeText(Client));
951 /* Inform other servers */
952 IRC_WriteStrServersPrefixFlag_CB(From,
953 From != NULL ? From : Client_ThisServer(),
954 '\0', cb_introduceClient, (void *)Client);
955 } /* Introduce_Client */
959 cb_introduceClient(CLIENT *To, CLIENT *Prefix, void *data)
961 CLIENT *c = (CLIENT *)data;
963 char *modes, *user, *host;
965 modes = Client_Modes(c);
966 user = Client_User(c) ? Client_User(c) : "-";
967 host = Client_Hostname(c) ? Client_Hostname(c) : "-";
969 conn = Client_Conn(To);
970 if (Conn_Options(conn) & CONN_RFC1459) {
971 /* RFC 1459 mode: separate NICK and USER commands */
972 Conn_WriteStr(conn, "NICK %s :%d", Client_ID(c),
974 Conn_WriteStr(conn, ":%s USER %s %s %s :%s",
975 Client_ID(c), user, host,
976 Client_ID(Client_Introducer(c)), Client_Info(c));
978 Conn_WriteStr(conn, ":%s MODE %s +%s",
979 Client_ID(c), Client_ID(c), modes);
981 /* RFC 2813 mode: one combined NICK or SERVICE command */
982 if (Client_Type(c) == CLIENT_SERVICE
983 && strchr(Client_Flags(To), 'S'))
984 IRC_WriteStrClientPrefix(To, Prefix,
985 "SERVICE %s %d * +%s %d :%s",
987 Client_MyToken(Client_Introducer(c)),
988 Client_Modes(c), Client_Hops(c) + 1,
991 IRC_WriteStrClientPrefix(To, Prefix,
992 "NICK %s %d %s %s %d +%s :%s",
993 Client_ID(c), Client_Hops(c) + 1,
995 Client_MyToken(Client_Introducer(c)),
996 modes, Client_Info(c));
998 } /* cb_introduceClient */