irc-login.c 20 KB

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