]> jfr.im git - solanum.git/blame - modules/m_pass.c
Remove trailing whitespace from all .c and .h files.
[solanum.git] / modules / m_pass.c
CommitLineData
212380e3
AC
1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_pass.c: Used to send a password for a server or client{} block.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 *
cda8e9b8 24 * $Id: m_pass.c 3550 2007-08-09 06:47:26Z nenolod $
212380e3
AC
25 */
26
27#include "stdinc.h"
28#include "client.h" /* client struct */
4562c604 29#include "match.h"
212380e3
AC
30#include "send.h" /* sendto_one */
31#include "numeric.h" /* ERR_xxx */
32#include "ircd.h" /* me */
33#include "msg.h"
34#include "parse.h"
35#include "modules.h"
36#include "s_serv.h"
37#include "hash.h"
38#include "s_conf.h"
39
40static int mr_pass(struct Client *, struct Client *, int, const char **);
41
42struct Message pass_msgtab = {
43 "PASS", 0, 0, 0, MFLG_SLOW | MFLG_UNREG,
44 {{mr_pass, 2}, mg_reg, mg_ignore, mg_ignore, mg_ignore, mg_reg}
45};
46
47mapi_clist_av1 pass_clist[] = { &pass_msgtab, NULL };
cda8e9b8 48DECLARE_MODULE_AV1(pass, NULL, NULL, pass_clist, NULL, NULL, "$Revision: 3550 $");
212380e3
AC
49
50/*
51 * m_pass() - Added Sat, 4 March 1989
52 *
53 *
54 * mr_pass - PASS message handler
212380e3
AC
55 * parv[1] = password
56 * parv[2] = "TS" if this server supports TS.
57 * parv[3] = optional TS version field -- needed for TS6
58 */
59static int
60mr_pass(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
61{
40c1fd47
VY
62 char *auth_user, *pass, *buf;
63 buf = LOCAL_COPY(parv[1]);
55abcbb2 64
212380e3
AC
65 if(client_p->localClient->passwd)
66 {
67 memset(client_p->localClient->passwd, 0,
68 strlen(client_p->localClient->passwd));
637c4932 69 rb_free(client_p->localClient->passwd);
15aa08ee
EFJ
70 client_p->localClient->passwd = NULL;
71 }
72
73 if (client_p->localClient->auth_user)
74 {
75 memset(client_p->localClient->auth_user, 0,
76 strlen(client_p->localClient->auth_user));
77 rb_free(client_p->localClient->auth_user);
78 client_p->localClient->auth_user = NULL;
212380e3
AC
79 }
80
40c1fd47
VY
81 if ((pass = strchr(buf, ':')) != NULL)
82 {
55abcbb2
KB
83 *pass++ = '\0';
84 auth_user = buf;
40c1fd47
VY
85 }
86 else
87 {
88 pass = buf;
89 auth_user = NULL;
90 }
55abcbb2 91
9f1bde26 92 client_p->localClient->passwd = *pass ? rb_strndup(pass, PASSWDLEN) : NULL;
55abcbb2 93
9f1bde26 94 if(auth_user && *auth_user)
40c1fd47 95 client_p->localClient->auth_user = rb_strndup(auth_user, PASSWDLEN);
212380e3
AC
96
97 /* These are for servers only */
98 if(parc > 2 && client_p->user == NULL)
99 {
55abcbb2 100 /*
212380e3
AC
101 * It looks to me as if orabidoo wanted to have more
102 * than one set of option strings possible here...
103 * i.e. ":AABBTS" as long as TS was the last two chars
104 * however, as we are now using CAPAB, I think we can
105 * safely assume if there is a ":TS" then its a TS server
106 * -Dianora
107 */
108 if(irccmp(parv[2], "TS") == 0 && client_p->tsinfo == 0)
109 client_p->tsinfo = TS_DOESTS;
110
cda8e9b8 111 if(parc == 5 && atoi(parv[3]) >= 6)
212380e3
AC
112 {
113 /* only mark as TS6 if the SID is valid.. */
114 if(IsDigit(parv[4][0]) && IsIdChar(parv[4][1]) &&
115 IsIdChar(parv[4][2]) && parv[4][3] == '\0' &&
116 EmptyString(client_p->id))
117 {
118 client_p->localClient->caps |= CAP_TS6;
119 strcpy(client_p->id, parv[4]);
120 }
121 }
122 }
123
124 return 0;
125}