aboutsummaryrefslogtreecommitdiff
path: root/contrib/mod_passwd/mod_passwd.c
blob: 817a7227acd25545498ab7b354becfddb17de79a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/************************************************************************
 *   IRC - Internet Relay Chat, mod_passwd.c
 *   Copyright (C) 1999 Christophe Kalt
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 1, or (at your option)
 *   any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef lint
static  char rcsid[] = "@(#)$Id: mod_passwd.c,v 1.1 1999/03/13 23:06:15 kalt Exp $";
#endif

#include "os.h"
#include "a_defines.h"
#include "a_externs.h"

/*
 * passwd_init
 *
 *	This procedure is called when a particular module is loaded.
 *	Returns NULL if everything went fine,
 *	an error message otherwise.
 */
char *
passwd_init(self)
AnInstance *self;
{
	return NULL;
}

/*
 * passwd_release
 *
 *	This procedure is called when a particular module is unloaded.
 */
void
passwd_release(self)
AnInstance *self;
{
}

/*
 * passwd_stats
 *
 *	This procedure is called regularly to update statistics sent to ircd.
 */
void
passwd_stats(self)
AnInstance *self;
{
}

/*
 * passwd_start
 *
 *	This procedure is called to start an authentication.
 *	Returns 0 if everything went fine,
 *	+1 if still waiting for some data (username, password)..
 *	-1 otherwise (nothing to be done, or failure)
 *
 *	It is responsible for sending error messages where appropriate.
 *	In case of failure, it's responsible for cleaning up (e.g. passwd_clean
 *	will NOT be called)
 */
int
passwd_start(cl)
u_int cl;
{
	if (cldata[cl].authuser &&
	    cldata[cl].authfrom < cldata[cl].instance->in)
	    {
		/*
		** another instance preceding this one in the configuration
		** has already authenticated the user, no need to bother
		** doing anything here then. (the other takes precedence)
		*/
		return -1;
	    }
	if ((cldata[cl].state & A_GOTU) == 0)
		/* haven't received username/password pair from ircd yet */
		return 1;
	if ((cldata[cl].state & A_GOTP) == 0)
	    {
		/* no password to check -> reject user! */
		cldata[cl].state |= A_DENY;
		sendto_ircd("K %d %s %u ", cl, cldata[cl].itsip,
			    cldata[cl].itsport);
		return -1; /* done */
	    }
	/* 
	**
	**
	** INSERT FUNCTION TO CHECK PASSWORD VALIDITY
	**
	**
	*/
	/* if failure, see above */
	/* if success: */
	cldata[cl].state |= A_UNIX;
	if (cldata[cl].authuser)
		free(cldata[cl].authuser);
	cldata[cl].authuser = mystrdup(cldata[cl].user);
	cldata[cl].authfrom = cldata[cl].instance->in;
	sendto_ircd("U %d %s %u %s", cl, cldata[cl].itsip, cldata[cl].itsport,
		    cldata[cl].authuser);
	return -1; /* done */
}

/*
 * passwd_work
 *
 *	This procedure is called whenever there's new data in the buffer.
 *	Returns 0 if everything went fine, and there is more work to be done,
 *	Returns -1 if the module has finished its work (and cleaned up).
 *
 *	It is responsible for sending error messages where appropriate.
 */
int
passwd_work(cl)
u_int cl;
{
	return -1;
}

/*
 * passwd_clean
 *
 *	This procedure is called whenever the module should interrupt its work.
 *	It is responsible for cleaning up any allocated data, and in particular
 *	closing file descriptors.
 */
void
passwd_clean(cl)
u_int cl;
{
}

/*
 * passwd_timeout
 *
 *	This procedure is called whenever the timeout set by the module is
 *	reached.
 *
 *	Returns 0 if things are okay, -1 if authentication was aborted.
 */
int
passwd_timeout(cl)
u_int cl;
{
}

static aModule Module_passwd =
	{ "passwd", passwd_init, passwd_release, passwd_stats,
	  passwd_start, passwd_work, passwd_timeout, passwd_clean };

aModule *
passwd_load()
{
	return &Module_passwd;
}