irc-login.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. /*
  2. * ngIRCd -- The Next Generation IRC Daemon
  3. * Copyright (c)2001-2008 Alexander Barton (alex@barton.de)
  4. *
  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.
  10. *
  11. * Login and logout
  12. */
  13. #include "portab.h"
  14. #include "imp.h"
  15. #include <assert.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <strings.h>
  20. #include "ngircd.h"
  21. #include "resolve.h"
  22. #include "conn-func.h"
  23. #include "conf.h"
  24. #include "client.h"
  25. #include "channel.h"
  26. #include "log.h"
  27. #include "messages.h"
  28. #include "parse.h"
  29. #include "irc.h"
  30. #include "irc-info.h"
  31. #include "irc-write.h"
  32. #include "exp.h"
  33. #include "irc-login.h"
  34. static bool Hello_User PARAMS(( CLIENT *Client ));
  35. static void Kill_Nick PARAMS(( char *Nick, char *Reason ));
  36. /**
  37. * Handler for the IRC command "PASS".
  38. * See RFC 2813 section 4.1.1, and RFC 2812 section 3.1.1.
  39. */
  40. GLOBAL bool
  41. IRC_PASS( CLIENT *Client, REQUEST *Req )
  42. {
  43. char *type, *orig_flags;
  44. int protohigh, protolow;
  45. assert( Client != NULL );
  46. assert( Req != NULL );
  47. /* Return an error if this is not a local client */
  48. if (Client_Conn(Client) <= NONE)
  49. return IRC_WriteStrClient(Client, ERR_UNKNOWNCOMMAND_MSG,
  50. Client_ID(Client), Req->command);
  51. if (Client_Type(Client) == CLIENT_UNKNOWN && Req->argc == 1) {
  52. /* Not yet registered "unknown" connection, PASS with one
  53. * argument: either a regular client, service, or server
  54. * using the old RFC 1459 section 4.1.1 syntax. */
  55. LogDebug("Connection %d: got PASS command ...",
  56. Client_Conn(Client));
  57. } else if ((Client_Type(Client) == CLIENT_UNKNOWN ||
  58. Client_Type(Client) == CLIENT_UNKNOWNSERVER) &&
  59. (Req->argc == 3 || Req->argc == 4)) {
  60. /* Not yet registered "unknown" connection or outgoing server
  61. * link, PASS with three or four argument: server using the
  62. * RFC 2813 section 4.1.1 syntax. */
  63. LogDebug("Connection %d: got PASS command (new server link) ...",
  64. Client_Conn(Client));
  65. } else if (Client_Type(Client) == CLIENT_UNKNOWN ||
  66. Client_Type(Client) == CLIENT_UNKNOWNSERVER) {
  67. /* Unregistered connection, but wrong number of arguments: */
  68. return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
  69. Client_ID(Client), Req->command);
  70. } else {
  71. /* Registered connection, PASS command is not allowed! */
  72. return IRC_WriteStrClient(Client, ERR_ALREADYREGISTRED_MSG,
  73. Client_ID(Client));
  74. }
  75. Client_SetPassword(Client, Req->argv[0]);
  76. Client_SetType(Client, CLIENT_GOTPASS);
  77. /* Protocol version */
  78. if (Req->argc >= 2 && strlen(Req->argv[1]) >= 4) {
  79. int c2, c4;
  80. c2 = Req->argv[1][2];
  81. c4 = Req->argv[1][4];
  82. Req->argv[1][4] = '\0';
  83. protolow = atoi(&Req->argv[1][2]);
  84. Req->argv[1][2] = '\0';
  85. protohigh = atoi(Req->argv[1]);
  86. Req->argv[1][2] = c2;
  87. Req->argv[1][4] = c4;
  88. } else
  89. protohigh = protolow = 0;
  90. /* Protocol type, see doc/Protocol.txt */
  91. if (Req->argc >= 2 && strlen(Req->argv[1]) > 4)
  92. type = &Req->argv[1][4];
  93. else
  94. type = NULL;
  95. /* Protocol flags/options */
  96. if (Req->argc >= 4)
  97. orig_flags = Req->argv[3];
  98. else
  99. orig_flags = "";
  100. /* Implementation, version and IRC+ flags */
  101. if (Req->argc >= 3) {
  102. char *impl, *ptr, *serverver, *flags;
  103. impl = Req->argv[2];
  104. ptr = strchr(impl, '|');
  105. if (ptr)
  106. *ptr = '\0';
  107. if (type && strcmp(type, PROTOIRCPLUS) == 0) {
  108. /* The peer seems to be a server which supports the
  109. * IRC+ protocol (see doc/Protocol.txt). */
  110. serverver = ptr + 1;
  111. flags = strchr(serverver, ':');
  112. if (flags) {
  113. *flags = '\0';
  114. flags++;
  115. } else
  116. flags = "";
  117. Log(LOG_INFO,
  118. "Peer announces itself as %s-%s using protocol %d.%d/IRC+ (flags: \"%s\").",
  119. impl, serverver, protohigh, protolow, flags);
  120. } else {
  121. /* The peer seems to be a server supporting the
  122. * "original" IRC protocol (RFC 2813). */
  123. serverver = "";
  124. if (strchr(orig_flags, 'Z'))
  125. flags = "Z";
  126. else
  127. flags = "";
  128. Log(LOG_INFO,
  129. "Peer announces itself as \"%s\" using protocol %d.%d (flags: \"%s\").",
  130. impl, protohigh, protolow, flags);
  131. }
  132. Client_SetFlags(Client, flags);
  133. }
  134. return CONNECTED;
  135. } /* IRC_PASS */
  136. /**
  137. * IRC "NICK" command.
  138. * This function implements the IRC command "NICK" which is used to register
  139. * with the server, to change already registered nicknames and to introduce
  140. * new users which are connected to other servers.
  141. */
  142. GLOBAL bool
  143. IRC_NICK( CLIENT *Client, REQUEST *Req )
  144. {
  145. CLIENT *intr_c, *target, *c;
  146. char *modes;
  147. assert( Client != NULL );
  148. assert( Req != NULL );
  149. #ifndef STRICT_RFC
  150. /* Some IRC clients, for example BitchX, send the NICK and USER
  151. * commands in the wrong order ... */
  152. if( Client_Type( Client ) == CLIENT_UNKNOWN
  153. || Client_Type( Client ) == CLIENT_GOTPASS
  154. || Client_Type( Client ) == CLIENT_GOTNICK
  155. || Client_Type( Client ) == CLIENT_GOTUSER
  156. || Client_Type( Client ) == CLIENT_USER
  157. || ( Client_Type( Client ) == CLIENT_SERVER && Req->argc == 1 ))
  158. #else
  159. if( Client_Type( Client ) == CLIENT_UNKNOWN
  160. || Client_Type( Client ) == CLIENT_GOTPASS
  161. || Client_Type( Client ) == CLIENT_GOTNICK
  162. || Client_Type( Client ) == CLIENT_USER
  163. || ( Client_Type( Client ) == CLIENT_SERVER && Req->argc == 1 ))
  164. #endif
  165. {
  166. /* User registration or change of nickname */
  167. /* Wrong number of arguments? */
  168. if( Req->argc != 1 )
  169. return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG,
  170. Client_ID( Client ),
  171. Req->command );
  172. /* Search "target" client */
  173. if( Client_Type( Client ) == CLIENT_SERVER )
  174. {
  175. target = Client_Search( Req->prefix );
  176. if( ! target )
  177. return IRC_WriteStrClient( Client,
  178. ERR_NOSUCHNICK_MSG,
  179. Client_ID( Client ),
  180. Req->argv[0] );
  181. }
  182. else
  183. {
  184. /* Is this a restricted client? */
  185. if( Client_HasMode( Client, 'r' ))
  186. return IRC_WriteStrClient( Client,
  187. ERR_RESTRICTED_MSG,
  188. Client_ID( Client ));
  189. target = Client;
  190. }
  191. #ifndef STRICT_RFC
  192. /* If the clients tries to change to its own nickname we won't
  193. * do anything. This is how the original ircd behaves and some
  194. * clients (for example Snak) expect it to be like this.
  195. * But I doubt that this is "really the right thing" ... */
  196. if( strcmp( Client_ID( target ), Req->argv[0] ) == 0 )
  197. return CONNECTED;
  198. #endif
  199. /* Check that the new nickname is available. Special case:
  200. * the client only changes from/to upper to lower case. */
  201. if( strcasecmp( Client_ID( target ), Req->argv[0] ) != 0 )
  202. {
  203. if( ! Client_CheckNick( target, Req->argv[0] ))
  204. return CONNECTED;
  205. }
  206. if(( Client_Type( target ) != CLIENT_USER )
  207. && ( Client_Type( target ) != CLIENT_SERVER ))
  208. {
  209. /* New client */
  210. Log( LOG_DEBUG, "Connection %d: got valid NICK command ...",
  211. Client_Conn( Client ));
  212. /* Register new nickname of this client */
  213. Client_SetID( target, Req->argv[0] );
  214. /* If we received a valid USER command already then
  215. * register the new client! */
  216. if( Client_Type( Client ) == CLIENT_GOTUSER )
  217. return Hello_User( Client );
  218. else
  219. Client_SetType( Client, CLIENT_GOTNICK );
  220. }
  221. else
  222. {
  223. /* Nickname change */
  224. if( Client_Conn( target ) > NONE )
  225. {
  226. /* Local client */
  227. Log( LOG_INFO,
  228. "User \"%s\" changed nick (connection %d): \"%s\" -> \"%s\".",
  229. Client_Mask( target ), Client_Conn( target ),
  230. Client_ID( target ), Req->argv[0] );
  231. }
  232. else
  233. {
  234. /* Remote client */
  235. Log( LOG_DEBUG,
  236. "User \"%s\" changed nick: \"%s\" -> \"%s\".",
  237. Client_Mask( target ), Client_ID( target ),
  238. Req->argv[0] );
  239. }
  240. /* Inform all users and servers (which have to know)
  241. * of this nickname change */
  242. if( Client_Type( Client ) == CLIENT_USER )
  243. IRC_WriteStrClientPrefix( Client, Client,
  244. "NICK :%s",
  245. Req->argv[0] );
  246. IRC_WriteStrServersPrefix( Client, target,
  247. "NICK :%s", Req->argv[0] );
  248. IRC_WriteStrRelatedPrefix( target, target, false,
  249. "NICK :%s", Req->argv[0] );
  250. /* Register old nickname for WHOWAS queries */
  251. Client_RegisterWhowas( target );
  252. /* Save new nickname */
  253. Client_SetID( target, Req->argv[0] );
  254. IRC_SetPenalty( target, 2 );
  255. }
  256. return CONNECTED;
  257. }
  258. else if( Client_Type( Client ) == CLIENT_SERVER )
  259. {
  260. /* Server introduces new client */
  261. /* Falsche Anzahl Parameter? */
  262. if( Req->argc != 7 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
  263. /* Nick ueberpruefen */
  264. c = Client_Search( Req->argv[0] );
  265. if( c )
  266. {
  267. /* Der neue Nick ist auf diesem Server bereits registriert:
  268. * sowohl der neue, als auch der alte Client muessen nun
  269. * disconnectiert werden. */
  270. Log( LOG_ERR, "Server %s introduces already registered nick \"%s\"!", Client_ID( Client ), Req->argv[0] );
  271. Kill_Nick( Req->argv[0], "Nick collision" );
  272. return CONNECTED;
  273. }
  274. /* Server, zu dem der Client connectiert ist, suchen */
  275. intr_c = Client_GetFromToken( Client, atoi( Req->argv[4] ));
  276. if( ! intr_c )
  277. {
  278. Log( LOG_ERR, "Server %s introduces nick \"%s\" on unknown server!?", Client_ID( Client ), Req->argv[0] );
  279. Kill_Nick( Req->argv[0], "Unknown server" );
  280. return CONNECTED;
  281. }
  282. /* Neue Client-Struktur anlegen */
  283. c = Client_NewRemoteUser( intr_c, Req->argv[0], atoi( Req->argv[1] ), Req->argv[2], Req->argv[3], atoi( Req->argv[4] ), Req->argv[5] + 1, Req->argv[6], true);
  284. if( ! c )
  285. {
  286. /* Eine neue Client-Struktur konnte nicht angelegt werden.
  287. * Der Client muss disconnectiert werden, damit der Netz-
  288. * status konsistent bleibt. */
  289. Log( LOG_ALERT, "Can't create client structure! (on connection %d)", Client_Conn( Client ));
  290. Kill_Nick( Req->argv[0], "Server error" );
  291. return CONNECTED;
  292. }
  293. modes = Client_Modes( c );
  294. if( *modes ) Log( LOG_DEBUG, "User \"%s\" (+%s) registered (via %s, on %s, %d hop%s).", Client_Mask( c ), modes, Client_ID( Client ), Client_ID( intr_c ), Client_Hops( c ), Client_Hops( c ) > 1 ? "s": "" );
  295. else Log( LOG_DEBUG, "User \"%s\" registered (via %s, on %s, %d hop%s).", Client_Mask( c ), Client_ID( Client ), Client_ID( intr_c ), Client_Hops( c ), Client_Hops( c ) > 1 ? "s": "" );
  296. /* Andere Server, ausser dem Introducer, informieren */
  297. IRC_WriteStrServersPrefix( Client, Client, "NICK %s %d %s %s %d %s :%s", Req->argv[0], atoi( Req->argv[1] ) + 1, Req->argv[2], Req->argv[3], Client_MyToken( intr_c ), Req->argv[5], Req->argv[6] );
  298. return CONNECTED;
  299. }
  300. else return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
  301. } /* IRC_NICK */
  302. GLOBAL bool
  303. IRC_USER( CLIENT *Client, REQUEST *Req )
  304. {
  305. #ifdef IDENTAUTH
  306. char *ptr;
  307. #endif
  308. assert( Client != NULL );
  309. assert( Req != NULL );
  310. #ifndef STRICT_RFC
  311. if( Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_GOTPASS || Client_Type( Client ) == CLIENT_UNKNOWN )
  312. #else
  313. if( Client_Type( Client ) == CLIENT_GOTNICK || Client_Type( Client ) == CLIENT_GOTPASS )
  314. #endif
  315. {
  316. /* Wrong number of parameters? */
  317. if( Req->argc != 4 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
  318. /* User name */
  319. #ifdef IDENTAUTH
  320. ptr = Client_User( Client );
  321. if( ! ptr || ! *ptr || *ptr == '~' ) Client_SetUser( Client, Req->argv[0], false );
  322. #else
  323. Client_SetUser( Client, Req->argv[0], false );
  324. #endif
  325. /* "Real name" or user info text: Don't set it to the empty string, the original ircd
  326. * can't deal with such "real names" (e. g. "USER user * * :") ... */
  327. if( *Req->argv[3] ) Client_SetInfo( Client, Req->argv[3] );
  328. else Client_SetInfo( Client, "-" );
  329. Log( LOG_DEBUG, "Connection %d: got valid USER command ...", Client_Conn( Client ));
  330. if( Client_Type( Client ) == CLIENT_GOTNICK ) return Hello_User( Client );
  331. else Client_SetType( Client, CLIENT_GOTUSER );
  332. return CONNECTED;
  333. }
  334. else if( Client_Type( Client ) == CLIENT_USER || Client_Type( Client ) == CLIENT_SERVER || Client_Type( Client ) == CLIENT_SERVICE )
  335. {
  336. return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
  337. }
  338. else return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
  339. } /* IRC_USER */
  340. GLOBAL bool
  341. IRC_QUIT( CLIENT *Client, REQUEST *Req )
  342. {
  343. CLIENT *target;
  344. char quitmsg[LINE_LEN];
  345. assert( Client != NULL );
  346. assert( Req != NULL );
  347. /* Wrong number of arguments? */
  348. if( Req->argc > 1 )
  349. return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
  350. if (Req->argc == 1)
  351. strlcpy(quitmsg, Req->argv[0], sizeof quitmsg);
  352. if ( Client_Type( Client ) == CLIENT_SERVER )
  353. {
  354. /* Server */
  355. target = Client_Search( Req->prefix );
  356. if( ! target )
  357. {
  358. /* Den Client kennen wir nicht (mehr), also nichts zu tun. */
  359. Log( LOG_WARNING, "Got QUIT from %s for unknown client!?", Client_ID( Client ));
  360. return CONNECTED;
  361. }
  362. Client_Destroy( target, "Got QUIT command.", Req->argc == 1 ? quitmsg : NULL, true);
  363. return CONNECTED;
  364. }
  365. else
  366. {
  367. if (Req->argc == 1 && quitmsg[0] != '\"') {
  368. /* " " to avoid confusion */
  369. strlcpy(quitmsg, "\"", sizeof quitmsg);
  370. strlcat(quitmsg, Req->argv[0], sizeof quitmsg-1);
  371. strlcat(quitmsg, "\"", sizeof quitmsg );
  372. }
  373. /* User, Service, oder noch nicht registriert */
  374. Conn_Close( Client_Conn( Client ), "Got QUIT command.", Req->argc == 1 ? quitmsg : NULL, true);
  375. return DISCONNECTED;
  376. }
  377. } /* IRC_QUIT */
  378. GLOBAL bool
  379. IRC_PING(CLIENT *Client, REQUEST *Req)
  380. {
  381. CLIENT *target, *from;
  382. assert(Client != NULL);
  383. assert(Req != NULL);
  384. /* Wrong number of arguments? */
  385. if (Req->argc < 1)
  386. return IRC_WriteStrClient(Client, ERR_NOORIGIN_MSG,
  387. Client_ID(Client));
  388. #ifdef STRICT_RFC
  389. /* Don't ignore additional arguments when in "strict" mode */
  390. if (Req->argc > 2)
  391. return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
  392. Client_ID(Client), Req->command);
  393. #endif
  394. if (Req->argc > 1) {
  395. /* A target has been specified ... */
  396. target = Client_Search(Req->argv[1]);
  397. if (!target || Client_Type(target) != CLIENT_SERVER)
  398. return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
  399. Client_ID(Client), Req->argv[1]);
  400. if (target != Client_ThisServer()) {
  401. /* Ok, we have to forward the PING */
  402. if (Client_Type(Client) == CLIENT_SERVER)
  403. from = Client_Search(Req->prefix);
  404. else
  405. from = Client;
  406. if (!from)
  407. return IRC_WriteStrClient(Client,
  408. ERR_NOSUCHSERVER_MSG,
  409. Client_ID(Client), Req->prefix);
  410. return IRC_WriteStrClientPrefix(target, from,
  411. "PING %s :%s", Req->argv[0],
  412. Req->argv[1] );
  413. }
  414. }
  415. if (Client_Type(Client) == CLIENT_SERVER) {
  416. if (Req->prefix)
  417. from = Client_Search(Req->prefix);
  418. else
  419. from = Client;
  420. } else
  421. from = Client_ThisServer();
  422. if (!from)
  423. return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
  424. Client_ID(Client), Req->prefix);
  425. Log(LOG_DEBUG, "Connection %d: got PING, sending PONG ...",
  426. Client_Conn(Client));
  427. #ifdef STRICT_RFC
  428. return IRC_WriteStrClient(Client, "PONG %s :%s",
  429. Client_ID(from), Client_ID(Client));
  430. #else
  431. /* Some clients depend on the argument being returned in the PONG
  432. * reply (not mentioned in any RFC, though) */
  433. return IRC_WriteStrClient(Client, "PONG %s :%s",
  434. Client_ID(from), Req->argv[0]);
  435. #endif
  436. } /* IRC_PING */
  437. GLOBAL bool
  438. IRC_PONG(CLIENT *Client, REQUEST *Req)
  439. {
  440. CLIENT *target, *from;
  441. char *s;
  442. assert(Client != NULL);
  443. assert(Req != NULL);
  444. /* Wrong number of arguments? */
  445. if (Req->argc < 1)
  446. return IRC_WriteStrClient(Client, ERR_NOORIGIN_MSG,
  447. Client_ID(Client));
  448. if (Req->argc > 2)
  449. return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
  450. Client_ID(Client), Req->command);
  451. /* Forward? */
  452. if (Req->argc == 2 && Client_Type(Client) == CLIENT_SERVER) {
  453. target = Client_Search(Req->argv[0]);
  454. if (!target)
  455. return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
  456. Client_ID(Client), Req->argv[0]);
  457. from = Client_Search(Req->prefix);
  458. if (target != Client_ThisServer() && target != from) {
  459. /* Ok, we have to forward the message. */
  460. if (!from)
  461. return IRC_WriteStrClient(Client,
  462. ERR_NOSUCHSERVER_MSG,
  463. Client_ID(Client), Req->prefix);
  464. if (Client_Type(Client_NextHop(target)) != CLIENT_SERVER)
  465. s = Client_ID(from);
  466. else
  467. s = Req->argv[0];
  468. return IRC_WriteStrClientPrefix(target, from,
  469. "PONG %s :%s", s, Req->argv[1]);
  470. }
  471. }
  472. /* The connection timestamp has already been updated when the data has
  473. * been read from so socket, so we don't need to update it here. */
  474. if (Client_Conn(Client) > NONE)
  475. Log(LOG_DEBUG,
  476. "Connection %d: received PONG. Lag: %ld seconds.",
  477. Client_Conn(Client),
  478. time(NULL) - Conn_LastPing(Client_Conn(Client)));
  479. else
  480. Log(LOG_DEBUG,
  481. "Connection %d: received PONG.", Client_Conn(Client));
  482. return CONNECTED;
  483. } /* IRC_PONG */
  484. static bool
  485. Hello_User(CLIENT * Client)
  486. {
  487. assert(Client != NULL);
  488. /* Check password ... */
  489. if (strcmp(Client_Password(Client), Conf_ServerPwd) != 0) {
  490. /* Bad password! */
  491. Log(LOG_ERR,
  492. "User \"%s\" rejected (connection %d): Bad password!",
  493. Client_Mask(Client), Client_Conn(Client));
  494. Conn_Close(Client_Conn(Client), NULL, "Bad password", true);
  495. return DISCONNECTED;
  496. }
  497. Log(LOG_NOTICE, "User \"%s\" registered (connection %d).",
  498. Client_Mask(Client), Client_Conn(Client));
  499. /* Inform other servers */
  500. IRC_WriteStrServers(NULL, "NICK %s 1 %s %s 1 +%s :%s",
  501. Client_ID(Client), Client_User(Client),
  502. Client_Hostname(Client), Client_Modes(Client),
  503. Client_Info(Client));
  504. if (!IRC_WriteStrClient
  505. (Client, RPL_WELCOME_MSG, Client_ID(Client), Client_Mask(Client)))
  506. return false;
  507. if (!IRC_WriteStrClient
  508. (Client, RPL_YOURHOST_MSG, Client_ID(Client),
  509. Client_ID(Client_ThisServer()), PACKAGE_VERSION, TARGET_CPU,
  510. TARGET_VENDOR, TARGET_OS))
  511. return false;
  512. if (!IRC_WriteStrClient
  513. (Client, RPL_CREATED_MSG, Client_ID(Client), NGIRCd_StartStr))
  514. return false;
  515. if (!IRC_WriteStrClient
  516. (Client, RPL_MYINFO_MSG, Client_ID(Client),
  517. Client_ID(Client_ThisServer()), PACKAGE_VERSION, USERMODES,
  518. CHANMODES))
  519. return false;
  520. /* Features supported by this server (005 numeric, ISUPPORT),
  521. * see <http://www.irc.org/tech_docs/005.html> for details. */
  522. if (!IRC_Send_ISUPPORT(Client))
  523. return DISCONNECTED;
  524. Client_SetType(Client, CLIENT_USER);
  525. if (!IRC_Send_LUSERS(Client))
  526. return DISCONNECTED;
  527. if (!IRC_Show_MOTD(Client))
  528. return DISCONNECTED;
  529. /* Suspend the client for a second ... */
  530. IRC_SetPenalty(Client, 1);
  531. return CONNECTED;
  532. } /* Hello_User */
  533. static void
  534. Kill_Nick( char *Nick, char *Reason )
  535. {
  536. REQUEST r;
  537. assert( Nick != NULL );
  538. assert( Reason != NULL );
  539. r.prefix = (char *)Client_ThisServer( );
  540. r.argv[0] = Nick;
  541. r.argv[1] = Reason;
  542. r.argc = 2;
  543. Log( LOG_ERR, "User(s) with nick \"%s\" will be disconnected: %s", Nick, Reason );
  544. IRC_KILL( Client_ThisServer( ), &r );
  545. } /* Kill_Nick */
  546. /* -eof- */