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.
30 #include "conn-func.h"
40 #include "irc-write.h"
43 #include "irc-login.h"
46 static bool Hello_User PARAMS(( CLIENT *Client ));
47 static bool Hello_User_PostAuth PARAMS(( CLIENT *Client ));
48 static void Kill_Nick PARAMS(( char *Nick, char *Reason ));
49 static void Introduce_Client PARAMS((CLIENT *To, CLIENT *Client, int Type));
50 static void Reject_Client PARAMS((CLIENT *Client));
52 static void cb_introduceClient PARAMS((CLIENT *Client, CLIENT *Prefix,
56 static void cb_Read_Auth_Result PARAMS((int r_fd, UNUSED short events));
60 * Handler for the IRC command "PASS".
61 * See RFC 2813 section 4.1.1, and RFC 2812 section 3.1.1.
64 IRC_PASS( CLIENT *Client, REQUEST *Req )
66 char *type, *orig_flags;
67 int protohigh, protolow;
69 assert( Client != NULL );
70 assert( Req != NULL );
72 /* Return an error if this is not a local client */
73 if (Client_Conn(Client) <= NONE)
74 return IRC_WriteStrClient(Client, ERR_UNKNOWNCOMMAND_MSG,
75 Client_ID(Client), Req->command);
77 if (Client_Type(Client) == CLIENT_UNKNOWN && Req->argc == 1) {
78 /* Not yet registered "unknown" connection, PASS with one
79 * argument: either a regular client, service, or server
80 * using the old RFC 1459 section 4.1.1 syntax. */
81 LogDebug("Connection %d: got PASS command (RFC 1459) ...",
83 } else if ((Client_Type(Client) == CLIENT_UNKNOWN ||
84 Client_Type(Client) == CLIENT_UNKNOWNSERVER) &&
85 (Req->argc == 3 || Req->argc == 4)) {
86 /* Not yet registered "unknown" connection or outgoing server
87 * link, PASS with three or four argument: server using the
88 * RFC 2813 section 4.1.1 syntax. */
89 LogDebug("Connection %d: got PASS command (RFC 2813, new server link) ...",
91 } else if (Client_Type(Client) == CLIENT_UNKNOWN ||
92 Client_Type(Client) == CLIENT_UNKNOWNSERVER) {
93 /* Unregistered connection, but wrong number of arguments: */
94 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
95 Client_ID(Client), Req->command);
97 /* Registered connection, PASS command is not allowed! */
98 return IRC_WriteStrClient(Client, ERR_ALREADYREGISTRED_MSG,
102 Client_SetPassword(Client, Req->argv[0]);
104 /* Protocol version */
105 if (Req->argc >= 2 && strlen(Req->argv[1]) >= 4) {
108 c2 = Req->argv[1][2];
109 c4 = Req->argv[1][4];
111 Req->argv[1][4] = '\0';
112 protolow = atoi(&Req->argv[1][2]);
113 Req->argv[1][2] = '\0';
114 protohigh = atoi(Req->argv[1]);
116 Req->argv[1][2] = c2;
117 Req->argv[1][4] = c4;
119 Client_SetType(Client, CLIENT_GOTPASS_2813);
121 protohigh = protolow = 0;
122 Client_SetType(Client, CLIENT_GOTPASS);
125 /* Protocol type, see doc/Protocol.txt */
126 if (Req->argc >= 2 && strlen(Req->argv[1]) > 4)
127 type = &Req->argv[1][4];
131 /* Protocol flags/options */
133 orig_flags = Req->argv[3];
137 /* Implementation, version and IRC+ flags */
138 if (Req->argc >= 3) {
139 char *impl, *ptr, *serverver, *flags;
142 ptr = strchr(impl, '|');
146 if (type && strcmp(type, PROTOIRCPLUS) == 0) {
147 /* The peer seems to be a server which supports the
148 * IRC+ protocol (see doc/Protocol.txt). */
149 serverver = ptr ? ptr + 1 : "?";
150 flags = strchr(ptr ? serverver : impl, ':');
157 "Peer on conenction %d announces itself as %s-%s using protocol %d.%d/IRC+ (flags: \"%s\").",
158 Client_Conn(Client), impl, serverver,
159 protohigh, protolow, flags);
161 /* The peer seems to be a server supporting the
162 * "original" IRC protocol (RFC 2813). */
163 if (strchr(orig_flags, 'Z'))
168 "Peer on connection %d announces itself as \"%s\" using protocol %d.%d (flags: \"%s\").",
169 Client_Conn(Client), impl,
170 protohigh, protolow, flags);
172 Client_SetFlags(Client, flags);
180 * IRC "NICK" command.
181 * This function implements the IRC command "NICK" which is used to register
182 * with the server, to change already registered nicknames and to introduce
183 * new users which are connected to other servers.
186 IRC_NICK( CLIENT *Client, REQUEST *Req )
188 CLIENT *intr_c, *target, *c;
189 char *nick, *user, *hostname, *modes, *info;
192 assert( Client != NULL );
193 assert( Req != NULL );
195 /* Some IRC clients, for example BitchX, send the NICK and USER
196 * commands in the wrong order ... */
197 if(Client_Type(Client) == CLIENT_UNKNOWN
198 || Client_Type(Client) == CLIENT_GOTPASS
199 || Client_Type(Client) == CLIENT_GOTNICK
201 || Client_Type(Client) == CLIENT_GOTUSER
203 || Client_Type(Client) == CLIENT_USER
204 || Client_Type(Client) == CLIENT_SERVICE
205 || (Client_Type(Client) == CLIENT_SERVER && Req->argc == 1))
207 /* User registration or change of nickname */
209 /* Wrong number of arguments? */
211 return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG,
215 /* Search "target" client */
216 if( Client_Type( Client ) == CLIENT_SERVER )
218 target = Client_Search( Req->prefix );
220 return IRC_WriteStrClient( Client,
227 /* Is this a restricted client? */
228 if( Client_HasMode( Client, 'r' ))
229 return IRC_WriteStrClient( Client,
231 Client_ID( Client ));
237 /* If the clients tries to change to its own nickname we won't
238 * do anything. This is how the original ircd behaves and some
239 * clients (for example Snak) expect it to be like this.
240 * But I doubt that this is "really the right thing" ... */
241 if( strcmp( Client_ID( target ), Req->argv[0] ) == 0 )
245 /* Check that the new nickname is available. Special case:
246 * the client only changes from/to upper to lower case. */
247 if( strcasecmp( Client_ID( target ), Req->argv[0] ) != 0 )
249 if( ! Client_CheckNick( target, Req->argv[0] ))
253 if (Client_Type(target) != CLIENT_USER &&
254 Client_Type(target) != CLIENT_SERVICE &&
255 Client_Type(target) != CLIENT_SERVER) {
257 LogDebug("Connection %d: got valid NICK command ...",
258 Client_Conn( Client ));
260 /* Register new nickname of this client */
261 Client_SetID( target, Req->argv[0] );
263 /* If we received a valid USER command already then
264 * register the new client! */
265 if( Client_Type( Client ) == CLIENT_GOTUSER )
266 return Hello_User( Client );
268 Client_SetType( Client, CLIENT_GOTNICK );
270 /* Nickname change */
271 if (Client_Conn(target) > NONE) {
274 "%s \"%s\" changed nick (connection %d): \"%s\" -> \"%s\".",
275 Client_TypeText(target), Client_Mask(target),
276 Client_Conn(target), Client_ID(target),
278 Conn_UpdateIdle(Client_Conn(target));
281 LogDebug("%s \"%s\" changed nick: \"%s\" -> \"%s\".",
282 Client_TypeText(target),
283 Client_Mask(target), Client_ID(target),
287 /* Inform all users and servers (which have to know)
288 * of this nickname change */
289 if( Client_Type( Client ) == CLIENT_USER )
290 IRC_WriteStrClientPrefix( Client, Client,
293 IRC_WriteStrServersPrefix( Client, target,
294 "NICK :%s", Req->argv[0] );
295 IRC_WriteStrRelatedPrefix( target, target, false,
296 "NICK :%s", Req->argv[0] );
298 /* Register old nickname for WHOWAS queries */
299 Client_RegisterWhowas( target );
301 /* Save new nickname */
302 Client_SetID( target, Req->argv[0] );
304 IRC_SetPenalty( target, 2 );
308 } else if(Client_Type(Client) == CLIENT_SERVER ||
309 Client_Type(Client) == CLIENT_SERVICE) {
310 /* Server or service introduces new client */
312 /* Bad number of parameters? */
313 if (Req->argc != 2 && Req->argc != 7)
314 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
315 Client_ID(Client), Req->command);
317 if (Req->argc >= 7) {
318 /* RFC 2813 compatible syntax */
320 hops = atoi(Req->argv[1]);
322 hostname = Req->argv[3];
323 token = atoi(Req->argv[4]);
324 modes = Req->argv[5] + 1;
327 /* RFC 1459 compatible syntax */
331 hostname = Client_ID(Client);
332 token = atoi(Req->argv[1]);
337 c = Client_Search(nick);
340 * the new nick is already present on this server:
341 * the new and the old one have to be disconnected now.
343 Log( LOG_ERR, "Server %s introduces already registered nick \"%s\"!", Client_ID( Client ), Req->argv[0] );
344 Kill_Nick( Req->argv[0], "Nick collision" );
348 /* Find the Server this client is connected to */
349 intr_c = Client_GetFromToken(Client, token);
352 Log( LOG_ERR, "Server %s introduces nick \"%s\" on unknown server!?", Client_ID( Client ), Req->argv[0] );
353 Kill_Nick( Req->argv[0], "Unknown server" );
357 c = Client_NewRemoteUser(intr_c, nick, hops, user, hostname,
358 token, modes, info, true);
361 /* out of memory, need to disconnect client to keep network state consistent */
362 Log( LOG_ALERT, "Can't create client structure! (on connection %d)", Client_Conn( Client ));
363 Kill_Nick( Req->argv[0], "Server error" );
367 /* RFC 2813: client is now fully registered, inform all the
368 * other servers about the new user.
369 * RFC 1459: announce the new client only after receiving the
370 * USER command, first we need more information! */
372 LogDebug("Client \"%s\" is being registered (RFC 1459) ...",
374 Client_SetType(c, CLIENT_GOTNICK);
376 Introduce_Client(Client, c, CLIENT_USER);
380 else return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
385 * Handler for the IRC command "USER".
388 IRC_USER(CLIENT * Client, REQUEST * Req)
395 assert(Client != NULL);
398 if (Client_Type(Client) == CLIENT_GOTNICK ||
400 Client_Type(Client) == CLIENT_UNKNOWN ||
402 Client_Type(Client) == CLIENT_GOTPASS)
406 return IRC_WriteStrClient(Client,
407 ERR_NEEDMOREPARAMS_MSG,
413 ptr = Client_User(Client);
414 if (!ptr || !*ptr || *ptr == '~')
415 Client_SetUser(Client, Req->argv[0], false);
417 Client_SetUser(Client, Req->argv[0], false);
419 Client_SetOrigUser(Client, Req->argv[0]);
421 /* "Real name" or user info text: Don't set it to the empty
422 * string, the original ircd can't deal with such "real names"
423 * (e. g. "USER user * * :") ... */
425 Client_SetInfo(Client, Req->argv[3]);
427 Client_SetInfo(Client, "-");
429 LogDebug("Connection %d: got valid USER command ...",
430 Client_Conn(Client));
431 if (Client_Type(Client) == CLIENT_GOTNICK)
432 return Hello_User(Client);
434 Client_SetType(Client, CLIENT_GOTUSER);
437 } else if (Client_Type(Client) == CLIENT_SERVER ||
438 Client_Type(Client) == CLIENT_SERVICE) {
439 /* Server/service updating an user */
441 return IRC_WriteStrClient(Client,
442 ERR_NEEDMOREPARAMS_MSG,
445 c = Client_Search(Req->prefix);
447 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
451 Client_SetUser(c, Req->argv[0], true);
452 Client_SetOrigUser(c, Req->argv[0]);
453 Client_SetHostname(c, Req->argv[1]);
454 Client_SetInfo(c, Req->argv[3]);
456 LogDebug("Connection %d: got valid USER command for \"%s\".",
457 Client_Conn(Client), Client_Mask(c));
459 /* RFC 1459 style user registration?
460 * Introduce client to network: */
461 if (Client_Type(c) == CLIENT_GOTNICK)
462 Introduce_Client(Client, c, CLIENT_USER);
465 } else if (Client_Type(Client) == CLIENT_USER) {
466 /* Already registered connection */
467 return IRC_WriteStrClient(Client, ERR_ALREADYREGISTRED_MSG,
470 /* Unexpected/invalid connection state? */
471 return IRC_WriteStrClient(Client, ERR_NOTREGISTERED_MSG,
478 * Handler for the IRC command "SERVICE".
479 * This function implements IRC Services registration using the SERVICE command
480 * defined in RFC 2812 3.1.6 and RFC 2813 4.1.4.
481 * At the moment ngIRCd doesn't support directly linked services, so this
482 * function returns ERR_ERRONEUSNICKNAME when the SERVICE command has not been
483 * received from a peer server.
486 IRC_SERVICE(CLIENT *Client, REQUEST *Req)
489 char *nick, *user, *host, *info, *modes, *ptr;
492 assert(Client != NULL);
495 if (Client_Type(Client) != CLIENT_GOTPASS &&
496 Client_Type(Client) != CLIENT_SERVER)
497 return IRC_WriteStrClient(Client, ERR_ALREADYREGISTRED_MSG,
501 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
502 Client_ID(Client), Req->command);
504 if (Client_Type(Client) != CLIENT_SERVER)
505 return IRC_WriteStrClient(Client, ERR_ERRONEUSNICKNAME_MSG,
506 Client_ID(Client), Req->argv[0]);
508 /* Bad number of parameters? */
510 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
511 Client_ID(Client), Req->command);
514 user = NULL; host = NULL;
515 token = atoi(Req->argv[1]);
516 hops = atoi(Req->argv[4]);
519 /* Validate service name ("nick name") */
520 c = Client_Search(nick);
522 /* Nick name collission: disconnect (KILL) both clients! */
523 Log(LOG_ERR, "Server %s introduces already registered service \"%s\"!",
524 Client_ID(Client), nick);
525 Kill_Nick(nick, "Nick collision");
529 /* Get the server to which the service is connected */
530 intr_c = Client_GetFromToken(Client, token);
532 Log(LOG_ERR, "Server %s introduces service \"%s\" on unknown server!?",
533 Client_ID(Client), nick);
534 Kill_Nick(nick, "Unknown server");
538 /* Get user and host name */
539 ptr = strchr(nick, '@');
545 host = Client_Hostname(intr_c);
546 ptr = strchr(nick, '!');
554 /* According to RFC 2812/2813 parameter 4 <type> "is currently reserved
555 * for future usage"; but we use it to transfer the modes and check
556 * that the first character is a '+' sign and ignore it otherwise. */
557 modes = (Req->argv[3][0] == '+') ? ++Req->argv[3] : "";
559 c = Client_NewRemoteUser(intr_c, nick, hops, user, host,
560 token, modes, info, true);
562 /* Couldn't create client structure, so KILL the service to
563 * keep network status consistent ... */
564 Log(LOG_ALERT, "Can't create client structure! (on connection %d)",
565 Client_Conn(Client));
566 Kill_Nick(nick, "Server error");
570 Introduce_Client(Client, c, CLIENT_SERVICE);
576 * Handler for the IRC command "WEBIRC".
577 * Syntax: WEBIRC <password> <username> <real-hostname> <real-IP-address>
580 IRC_WEBIRC(CLIENT *Client, REQUEST *Req)
582 /* Exactly 4 parameters are requited */
584 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
585 Client_ID(Client), Req->command);
587 if (!Conf_WebircPwd[0] || strcmp(Req->argv[0], Conf_WebircPwd) != 0)
588 return IRC_WriteStrClient(Client, ERR_PASSWDMISMATCH_MSG,
591 LogDebug("Connection %d: got valid WEBIRC command: user=%s, host=%s, ip=%s",
592 Client_Conn(Client), Req->argv[1], Req->argv[2], Req->argv[3]);
594 Client_SetUser(Client, Req->argv[1], true);
595 Client_SetOrigUser(Client, Req->argv[1]);
596 Client_SetHostname(Client, Req->argv[2]);
602 IRC_QUIT( CLIENT *Client, REQUEST *Req )
605 char quitmsg[LINE_LEN];
607 assert( Client != NULL );
608 assert( Req != NULL );
610 /* Wrong number of arguments? */
612 return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
615 strlcpy(quitmsg, Req->argv[0], sizeof quitmsg);
617 if ( Client_Type( Client ) == CLIENT_SERVER )
620 target = Client_Search( Req->prefix );
623 Log( LOG_WARNING, "Got QUIT from %s for unknown client!?", Client_ID( Client ));
627 Client_Destroy( target, "Got QUIT command.", Req->argc == 1 ? quitmsg : NULL, true);
633 if (Req->argc == 1 && quitmsg[0] != '\"') {
634 /* " " to avoid confusion */
635 strlcpy(quitmsg, "\"", sizeof quitmsg);
636 strlcat(quitmsg, Req->argv[0], sizeof quitmsg-1);
637 strlcat(quitmsg, "\"", sizeof quitmsg );
640 /* User, Service, or not yet registered */
641 Conn_Close( Client_Conn( Client ), "Got QUIT command.", Req->argc == 1 ? quitmsg : NULL, true);
649 IRC_PING(CLIENT *Client, REQUEST *Req)
651 CLIENT *target, *from;
653 assert(Client != NULL);
657 return IRC_WriteStrClient(Client, ERR_NOORIGIN_MSG,
660 /* Don't ignore additional arguments when in "strict" mode */
662 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
663 Client_ID(Client), Req->command);
667 /* A target has been specified ... */
668 target = Client_Search(Req->argv[1]);
670 if (!target || Client_Type(target) != CLIENT_SERVER)
671 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
672 Client_ID(Client), Req->argv[1]);
674 if (target != Client_ThisServer()) {
675 /* Ok, we have to forward the PING */
676 if (Client_Type(Client) == CLIENT_SERVER)
677 from = Client_Search(Req->prefix);
681 return IRC_WriteStrClient(Client,
682 ERR_NOSUCHSERVER_MSG,
683 Client_ID(Client), Req->prefix);
685 return IRC_WriteStrClientPrefix(target, from,
686 "PING %s :%s", Req->argv[0],
691 if (Client_Type(Client) == CLIENT_SERVER) {
693 from = Client_Search(Req->prefix);
697 from = Client_ThisServer();
699 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
700 Client_ID(Client), Req->prefix);
702 Log(LOG_DEBUG, "Connection %d: got PING, sending PONG ...",
703 Client_Conn(Client));
706 return IRC_WriteStrClient(Client, "PONG %s :%s",
707 Client_ID(from), Client_ID(Client));
709 /* Some clients depend on the argument being returned in the PONG
710 * reply (not mentioned in any RFC, though) */
711 return IRC_WriteStrClient(Client, "PONG %s :%s",
712 Client_ID(from), Req->argv[0]);
718 IRC_PONG(CLIENT *Client, REQUEST *Req)
720 CLIENT *target, *from;
723 assert(Client != NULL);
726 /* Wrong number of arguments? */
728 return IRC_WriteStrClient(Client, ERR_NOORIGIN_MSG,
731 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
732 Client_ID(Client), Req->command);
735 if (Req->argc == 2 && Client_Type(Client) == CLIENT_SERVER) {
736 target = Client_Search(Req->argv[0]);
738 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
739 Client_ID(Client), Req->argv[0]);
741 from = Client_Search(Req->prefix);
743 if (target != Client_ThisServer() && target != from) {
744 /* Ok, we have to forward the message. */
746 return IRC_WriteStrClient(Client,
747 ERR_NOSUCHSERVER_MSG,
748 Client_ID(Client), Req->prefix);
750 if (Client_Type(Client_NextHop(target)) != CLIENT_SERVER)
754 return IRC_WriteStrClientPrefix(target, from,
755 "PONG %s :%s", s, Req->argv[1]);
759 /* The connection timestamp has already been updated when the data has
760 * been read from so socket, so we don't need to update it here. */
762 if (Client_Conn(Client) > NONE)
764 "Connection %d: received PONG. Lag: %ld seconds.",
766 time(NULL) - Conn_LastPing(Client_Conn(Client)));
769 "Connection %d: received PONG.", Client_Conn(Client));
776 Hello_User(CLIENT * Client)
779 int pipefd[2], result;
783 assert(Client != NULL);
784 conn = Client_Conn(Client);
787 /* Don't do any PAM authentication at all, instead emulate
788 * the beahiour of the daemon compiled without PAM support:
789 * because there can't be any "server password", all
790 * passwords supplied are classified as "wrong". */
791 if(Client_Password(Client)[0] == '\0')
792 return Hello_User_PostAuth(Client);
793 Reject_Client(Client);
797 /* Fork child process for PAM authentication; and make sure that the
798 * process timeout is set higher than the login timeout! */
799 pid = Proc_Fork(Conn_GetProcStat(conn), pipefd,
800 cb_Read_Auth_Result, Conf_PongTimeout + 1);
802 LogDebug("Authenticator for connection %d created (PID %d).",
807 Log_Init_Subprocess("Auth");
808 result = PAM_Authenticate(Client);
809 write(pipefd[1], &result, sizeof(result));
810 Log_Exit_Subprocess("Auth");
814 assert(Client != NULL);
816 /* Check global server password ... */
817 if (strcmp(Client_Password(Client), Conf_ServerPwd) != 0) {
819 Reject_Client(Client);
822 return Hello_User_PostAuth(Client);
830 * Read result of the authenticatior sub-process from pipe
833 cb_Read_Auth_Result(int r_fd, UNUSED short events)
841 LogDebug("Auth: Got callback on fd %d, events %d", r_fd, events);
842 conn = Conn_GetFromProc(r_fd);
844 /* Ops, none found? Probably the connection has already
845 * been closed!? We'll ignore that ... */
847 LogDebug("Auth: Got callback for unknown connection!?");
850 proc = Conn_GetProcStat(conn);
851 client = Conn_GetClient(conn);
853 /* Read result from pipe */
854 len = Proc_Read(proc, &result, sizeof(result));
858 if (len != sizeof(result)) {
859 Log(LOG_CRIT, "Auth: Got malformed result!");
860 Reject_Client(client);
864 if (result == true) {
865 Client_SetUser(client, Client_OrigUser(client), true);
866 (void)Hello_User_PostAuth(client);
868 Reject_Client(client);
875 Reject_Client(CLIENT *Client)
878 "User \"%s\" rejected (connection %d): Access denied!",
879 Client_Mask(Client), Client_Conn(Client));
880 Conn_Close(Client_Conn(Client), NULL,
881 "Access denied! Bad password?", true);
886 Hello_User_PostAuth(CLIENT *Client)
888 Introduce_Client(NULL, Client, CLIENT_USER);
890 if (!IRC_WriteStrClient
891 (Client, RPL_WELCOME_MSG, Client_ID(Client), Client_Mask(Client)))
893 if (!IRC_WriteStrClient
894 (Client, RPL_YOURHOST_MSG, Client_ID(Client),
895 Client_ID(Client_ThisServer()), PACKAGE_VERSION, TARGET_CPU,
896 TARGET_VENDOR, TARGET_OS))
898 if (!IRC_WriteStrClient
899 (Client, RPL_CREATED_MSG, Client_ID(Client), NGIRCd_StartStr))
901 if (!IRC_WriteStrClient
902 (Client, RPL_MYINFO_MSG, Client_ID(Client),
903 Client_ID(Client_ThisServer()), PACKAGE_VERSION, USERMODES,
907 /* Features supported by this server (005 numeric, ISUPPORT),
908 * see <http://www.irc.org/tech_docs/005.html> for details. */
909 if (!IRC_Send_ISUPPORT(Client))
912 if (!IRC_Send_LUSERS(Client))
914 if (!IRC_Show_MOTD(Client))
917 /* Suspend the client for a second ... */
918 IRC_SetPenalty(Client, 1);
925 Kill_Nick( char *Nick, char *Reason )
929 assert( Nick != NULL );
930 assert( Reason != NULL );
932 r.prefix = (char *)Client_ThisServer( );
937 Log( LOG_ERR, "User(s) with nick \"%s\" will be disconnected: %s", Nick, Reason );
938 IRC_KILL( Client_ThisServer( ), &r );
943 Introduce_Client(CLIENT *From, CLIENT *Client, int Type)
945 /* Set client type (user or service) */
946 Client_SetType(Client, Type);
949 if (Conf_IsService(Conf_GetServer(Client_Conn(From)),
951 Client_SetType(Client, CLIENT_SERVICE);
952 LogDebug("%s \"%s\" (+%s) registered (via %s, on %s, %d hop%s).",
953 Client_TypeText(Client), Client_Mask(Client),
954 Client_Modes(Client), Client_ID(From),
955 Client_ID(Client_Introducer(Client)),
956 Client_Hops(Client), Client_Hops(Client) > 1 ? "s": "");
958 Log(LOG_NOTICE, "%s \"%s\" registered (connection %d).",
959 Client_TypeText(Client), Client_Mask(Client),
960 Client_Conn(Client));
961 Log_ServerNotice('c', "Client connecting: %s (%s@%s) [%s] - %s",
962 Client_ID(Client), Client_User(Client),
963 Client_Hostname(Client),
964 Conn_IPA(Client_Conn(Client)),
965 Client_TypeText(Client));
968 /* Inform other servers */
969 IRC_WriteStrServersPrefixFlag_CB(From,
970 From != NULL ? From : Client_ThisServer(),
971 '\0', cb_introduceClient, (void *)Client);
972 } /* Introduce_Client */
976 cb_introduceClient(CLIENT *To, CLIENT *Prefix, void *data)
978 CLIENT *c = (CLIENT *)data;
980 char *modes, *user, *host;
982 modes = Client_Modes(c);
983 user = Client_User(c) ? Client_User(c) : "-";
984 host = Client_Hostname(c) ? Client_Hostname(c) : "-";
986 conn = Client_Conn(To);
987 if (Conn_Options(conn) & CONN_RFC1459) {
988 /* RFC 1459 mode: separate NICK and USER commands */
989 Conn_WriteStr(conn, "NICK %s :%d", Client_ID(c),
991 Conn_WriteStr(conn, ":%s USER %s %s %s :%s",
992 Client_ID(c), user, host,
993 Client_ID(Client_Introducer(c)), Client_Info(c));
995 Conn_WriteStr(conn, ":%s MODE %s +%s",
996 Client_ID(c), Client_ID(c), modes);
998 /* RFC 2813 mode: one combined NICK or SERVICE command */
999 if (Client_Type(c) == CLIENT_SERVICE
1000 && strchr(Client_Flags(To), 'S'))
1001 IRC_WriteStrClientPrefix(To, Prefix,
1002 "SERVICE %s %d * +%s %d :%s",
1004 Client_MyToken(Client_Introducer(c)),
1005 Client_Modes(c), Client_Hops(c) + 1,
1008 IRC_WriteStrClientPrefix(To, Prefix,
1009 "NICK %s %d %s %s %d +%s :%s",
1010 Client_ID(c), Client_Hops(c) + 1,
1012 Client_MyToken(Client_Introducer(c)),
1013 modes, Client_Info(c));
1015 } /* cb_introduceClient */