]> jfr.im git - solanum.git/blob - modules/m_pass.c
core/m_squit: Add AV2 description
[solanum.git] / modules / m_pass.c
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 */
24
25 #include "stdinc.h"
26 #include "client.h" /* client struct */
27 #include "match.h"
28 #include "send.h" /* sendto_one */
29 #include "numeric.h" /* ERR_xxx */
30 #include "ircd.h" /* me */
31 #include "msg.h"
32 #include "parse.h"
33 #include "modules.h"
34 #include "s_serv.h"
35 #include "hash.h"
36 #include "s_conf.h"
37
38 static int mr_pass(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
39
40 struct Message pass_msgtab = {
41 "PASS", 0, 0, 0, 0,
42 {{mr_pass, 2}, mg_reg, mg_ignore, mg_ignore, mg_ignore, mg_reg}
43 };
44
45 mapi_clist_av1 pass_clist[] = { &pass_msgtab, NULL };
46 DECLARE_MODULE_AV2(pass, NULL, NULL, pass_clist, NULL, NULL, NULL, NULL, NULL);
47
48 /*
49 * m_pass() - Added Sat, 4 March 1989
50 *
51 *
52 * mr_pass - PASS message handler
53 * parv[1] = password
54 * parv[2] = "TS" if this server supports TS.
55 * parv[3] = optional TS version field -- needed for TS6
56 */
57 static int
58 mr_pass(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
59 {
60 char *auth_user, *pass, *buf;
61 buf = LOCAL_COPY(parv[1]);
62
63 if(client_p->localClient->passwd || client_p->localClient->auth_user)
64 return 0;
65
66 if ((pass = strchr(buf, ':')) != NULL)
67 {
68 *pass++ = '\0';
69 auth_user = buf;
70 }
71 else
72 {
73 pass = buf;
74 auth_user = NULL;
75 }
76
77 client_p->localClient->passwd = *pass ? rb_strndup(pass, PASSWDLEN) : NULL;
78
79 if(auth_user && *auth_user)
80 client_p->localClient->auth_user = rb_strndup(auth_user, PASSWDLEN);
81
82 /* These are for servers only */
83 if(parc > 2 && client_p->user == NULL)
84 {
85 /*
86 * It looks to me as if orabidoo wanted to have more
87 * than one set of option strings possible here...
88 * i.e. ":AABBTS" as long as TS was the last two chars
89 * however, as we are now using CAPAB, I think we can
90 * safely assume if there is a ":TS" then its a TS server
91 * -Dianora
92 */
93 if(irccmp(parv[2], "TS") == 0 && client_p->tsinfo == 0)
94 client_p->tsinfo = TS_DOESTS;
95
96 if(parc == 5 && atoi(parv[3]) >= 6)
97 {
98 /* only mark as TS6 if the SID is valid.. */
99 if(IsDigit(parv[4][0]) && IsIdChar(parv[4][1]) &&
100 IsIdChar(parv[4][2]) && parv[4][3] == '\0' &&
101 EmptyString(client_p->id))
102 {
103 client_p->localClient->caps |= CAP_TS6;
104 strcpy(client_p->id, parv[4]);
105 }
106 }
107 }
108
109 return 0;
110 }