View | Details | Raw Unified | Return to bug 14284
Collapse All | Expand All

(-)libradius+/Makefile (-2 / +3 lines)
Lines 24-30 Link Here
24
#
24
#
25
#	$FreeBSD: src/lib/libradius/Makefile,v 1.2 1999/01/29 22:44:47 brian Exp $
25
#	$FreeBSD: src/lib/libradius/Makefile,v 1.2 1999/01/29 22:44:47 brian Exp $
26
26
27
LIB=		radius
27
LIB=		radius+
28
SRCS=		radlib.c
28
SRCS=		radlib.c
29
CFLAGS+=	-Wall
29
CFLAGS+=	-Wall
30
DPADD+=		${LIBMD}
30
DPADD+=		${LIBMD}
Lines 33-41 Link Here
33
SHLIB_MINOR=	0
33
SHLIB_MINOR=	0
34
MAN3+=		libradius.3
34
MAN3+=		libradius.3
35
MAN5+=		radius.conf.5
35
MAN5+=		radius.conf.5
36
#NOMAN=		noman
36
37
37
beforeinstall:
38
beforeinstall:
38
	${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \
39
	${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \
39
	    ${.CURDIR}/radlib.h ${DESTDIR}/usr/include
40
	    ${.CURDIR}/radlib.h ${DESTDIR}${INCLUDEDIR}/radlib+.h
40
41
41
.include <bsd.lib.mk>
42
.include <bsd.lib.mk>
(-)libradius+/radlib.c (-16 / +75 lines)
Lines 42-53 Link Here
42
#include <string.h>
42
#include <string.h>
43
#include <unistd.h>
43
#include <unistd.h>
44
44
45
/* For FreeBSD 2.2.8-STABLE */
46
#ifndef __printflike
47
#define __printflike(x,y)
48
#endif
49
45
#include "radlib_private.h"
50
#include "radlib_private.h"
46
51
47
static void	 clear_password(struct rad_handle *);
52
static void	 clear_password(struct rad_handle *);
48
static void	 generr(struct rad_handle *, const char *, ...)
53
static void	 generr(struct rad_handle *, const char *, ...)
49
		    __printflike(2, 3);
54
		    __printflike(2, 3);
50
static void	 insert_scrambled_password(struct rad_handle *, int);
55
static void	 insert_scrambled_password(struct rad_handle *, int);
56
static void	 insert_request_authenticator(struct rad_handle *, int);
51
static int	 is_valid_response(struct rad_handle *, int,
57
static int	 is_valid_response(struct rad_handle *, int,
52
		    const struct sockaddr_in *);
58
		    const struct sockaddr_in *);
53
static int	 put_password_attr(struct rad_handle *, int,
59
static int	 put_password_attr(struct rad_handle *, int,
Lines 110-115 Link Here
110
	}
116
	}
111
}
117
}
112
118
119
static void
120
insert_request_authenticator(struct rad_handle *h, int srv)
121
{
122
	MD5_CTX ctx;
123
	const struct rad_server *srvp;
124
125
	srvp = &h->servers[srv];
126
127
	/* Create the request authenticator */
128
	MD5Init(&ctx);
129
	MD5Update(&ctx, &h->request[POS_CODE], POS_AUTH - POS_CODE);
130
	MD5Update(&ctx, memset(&h->request[POS_AUTH], 0, LEN_AUTH), LEN_AUTH);
131
	MD5Update(&ctx, &h->request[POS_ATTRS], h->req_len - POS_ATTRS);
132
	MD5Update(&ctx, srvp->secret, strlen(srvp->secret));
133
	MD5Final(&h->request[POS_AUTH], &ctx);
134
}
135
113
/*
136
/*
114
 * Return true if the current response is valid for a request to the
137
 * Return true if the current response is valid for a request to the
115
 * specified server.
138
 * specified server.
Lines 229-237 Link Here
229
	else {
252
	else {
230
		struct servent *sent;
253
		struct servent *sent;
231
254
232
		srvp->addr.sin_port =
255
		if (h->type == RADIUS_AUTH)
233
		    (sent = getservbyname("radius", "udp")) != NULL ?
256
			srvp->addr.sin_port =
234
			sent->s_port : htons(RADIUS_PORT);
257
			    (sent = getservbyname("radius", "udp")) != NULL ?
258
				sent->s_port : htons(RADIUS_PORT);
259
		else
260
			srvp->addr.sin_port =
261
			    (sent = getservbyname("radacct", "udp")) != NULL ?
262
				sent->s_port : htons(RADACCT_PORT);
235
	}
263
	}
236
	if ((srvp->secret = strdup(secret)) == NULL) {
264
	if ((srvp->secret = strdup(secret)) == NULL) {
237
		generr(h, "Out of memory");
265
		generr(h, "Out of memory");
Lines 269-275 Link Here
269
	int retval;
297
	int retval;
270
298
271
	if (path == NULL)
299
	if (path == NULL)
272
		path = PATH_RADIUS_CONF;
300
		path = (h->type == RADIUS_AUTH)
301
		    ? PATH_RADIUS_CONF : PATH_RADACCT_CONF;
273
	if ((fp = fopen(path, "r")) == NULL) {
302
	if ((fp = fopen(path, "r")) == NULL) {
274
		generr(h, "Cannot open \"%s\": %s", path, strerror(errno));
303
		generr(h, "Cannot open \"%s\": %s", path, strerror(errno));
275
		return -1;
304
		return -1;
Lines 421-429 Link Here
421
		if (++h->srv >= h->num_servers)
450
		if (++h->srv >= h->num_servers)
422
			h->srv = 0;
451
			h->srv = 0;
423
452
424
	/* Insert the scrambled password into the request */
453
	if (h->request[POS_CODE] == RAD_ACCOUNTING_REQUEST)
425
	if (h->pass_pos != 0)
454
		/* Insert the request authenticator into the request */
426
		insert_scrambled_password(h, h->srv);
455
		insert_request_authenticator(h, h->srv);
456
	else
457
		/* Insert the scrambled password into the request */
458
		if (h->pass_pos != 0)
459
			insert_scrambled_password(h, h->srv);
427
460
428
	/* Send the request */
461
	/* Send the request */
429
	n = sendto(h->fd, h->request, h->req_len, 0,
462
	n = sendto(h->fd, h->request, h->req_len, 0,
Lines 552-565 Link Here
552
		}
585
		}
553
	}
586
	}
554
587
555
	/* Make sure the user gave us a password */
588
	if (h->request[POS_CODE] == RAD_ACCOUNTING_REQUEST) {
556
	if (h->pass_pos == 0 && !h->chap_pass) {
589
		/* Make sure no password given */
557
		generr(h, "No User or Chap Password attributes given");
590
		if (h->pass_pos || h->chap_pass) {
558
		return -1;
591
			generr(h, "User or Chap Password in accounting request");
559
	}
592
			return -1;
560
	if (h->pass_pos != 0 && h->chap_pass) {
593
		}
561
		generr(h, "Both User and Chap Password attributes given");
594
	} else {
562
		return -1;
595
		/* Make sure the user gave us a password */
596
		if (h->pass_pos == 0 && !h->chap_pass) {
597
			generr(h, "No User or Chap Password attributes given");
598
			return -1;
599
		}
600
		if (h->pass_pos != 0 && h->chap_pass) {
601
			generr(h, "Both User and Chap Password attributes given");
602
			return -1;
603
		}
563
	}
604
	}
564
605
565
	/* Fill in the length field in the message */
606
	/* Fill in the length field in the message */
Lines 591-597 Link Here
591
 * In that case, it returns NULL.
632
 * In that case, it returns NULL.
592
 */
633
 */
593
struct rad_handle *
634
struct rad_handle *
594
rad_open(void)
635
rad_auth_open(void)
595
{
636
{
596
	struct rad_handle *h;
637
	struct rad_handle *h;
597
638
Lines 606-613 Link Here
606
		h->pass_len = 0;
647
		h->pass_len = 0;
607
		h->pass_pos = 0;
648
		h->pass_pos = 0;
608
		h->chap_pass = 0;
649
		h->chap_pass = 0;
650
		h->type = RADIUS_AUTH;
609
	}
651
	}
610
	return h;
652
	return h;
653
}
654
655
struct rad_handle *
656
rad_acct_open(void)
657
{
658
	struct rad_handle *h;
659
660
	h = rad_open();
661
	if (h != NULL)
662
	        h->type = RADIUS_ACCT;
663
	return h;
664
}
665
666
struct rad_handle *
667
rad_open(void)
668
{
669
    return rad_auth_open();
611
}
670
}
612
671
613
int
672
int
(-)libradius+/radlib.h (+53 lines)
Lines 36-41 Link Here
36
#define RAD_ACCESS_REQUEST		1
36
#define RAD_ACCESS_REQUEST		1
37
#define RAD_ACCESS_ACCEPT		2
37
#define RAD_ACCESS_ACCEPT		2
38
#define RAD_ACCESS_REJECT		3
38
#define RAD_ACCESS_REJECT		3
39
#define RAD_ACCOUNTING_REQUEST		4
40
#define RAD_ACCOUNTING_RESPONSE		5
39
#define RAD_ACCESS_CHALLENGE		11
41
#define RAD_ACCESS_CHALLENGE		11
40
42
41
/* Attribute types and values */
43
/* Attribute types and values */
Lines 66-71 Link Here
66
#define RAD_FILTER_ID			11	/* String */
68
#define RAD_FILTER_ID			11	/* String */
67
#define RAD_FRAMED_MTU			12	/* Integer */
69
#define RAD_FRAMED_MTU			12	/* Integer */
68
#define RAD_FRAMED_COMPRESSION		13	/* Integer */
70
#define RAD_FRAMED_COMPRESSION		13	/* Integer */
71
	#define RAD_COMP_NONE			0
72
	#define RAD_COMP_VJ			1
73
	#define RAD_COMP_IPXHDR			2
69
#define RAD_LOGIN_IP_HOST		14	/* IP address */
74
#define RAD_LOGIN_IP_HOST		14	/* IP address */
70
#define RAD_LOGIN_SERVICE		15	/* Integer */
75
#define RAD_LOGIN_SERVICE		15	/* Integer */
71
#define RAD_LOGIN_TCP_PORT		16	/* Integer */
76
#define RAD_LOGIN_TCP_PORT		16	/* Integer */
Lines 95-102 Link Here
95
     /* reserved for accounting		40-59 */
100
     /* reserved for accounting		40-59 */
96
#define RAD_CHAP_CHALLENGE		60	/* String */
101
#define RAD_CHAP_CHALLENGE		60	/* String */
97
#define RAD_NAS_PORT_TYPE		61	/* Integer */
102
#define RAD_NAS_PORT_TYPE		61	/* Integer */
103
	#define RAD_ASYNC			0
104
	#define RAD_SYNC			1
105
	#define RAD_ISDN_SYNC			2
106
	#define RAD_ISDN_ASYNC_V120		3
107
	#define RAD_ISDN_ASYNC_V110		4
108
	#define RAD_VIRTUAL			5
98
#define RAD_PORT_LIMIT			62	/* Integer */
109
#define RAD_PORT_LIMIT			62	/* Integer */
99
#define RAD_LOGIN_LAT_PORT		63	/* Integer */
110
#define RAD_LOGIN_LAT_PORT		63	/* Integer */
111
#define RAD_CONNECT_INFO		77	/* String */
112
113
/* Accounting attribute types and values */
114
#define RAD_ACCT_STATUS_TYPE		40	/* Integer */
115
	#define RAD_START			1
116
	#define RAD_STOP			2
117
	#define RAD_ACCOUNTING_ON		7
118
	#define RAD_ACCOUNTING_OFF		8
119
#define RAD_ACCT_DELAY_TIME		41	/* Integer */
120
#define RAD_ACCT_INPUT_OCTETS		42	/* Integer */
121
#define RAD_ACCT_OUTPUT_OCTETS		43	/* Integer */
122
#define RAD_ACCT_SESSION_ID		44	/* String */
123
#define RAD_ACCT_AUTHENTIC		45	/* Integer */
124
	#define RAD_AUTH_RADIUS			1
125
	#define RAD_AUTH_LOCAL			2
126
	#define RAD_AUTH_REMOTE			3
127
#define RAD_ACCT_SESSION_TIME		46	/* Integer */
128
#define RAD_ACCT_INPUT_PACKETS		47	/* Integer */
129
#define RAD_ACCT_OUTPUT_PACKETS		48	/* Integer */
130
#define RAD_ACCT_TERMINATE_CAUSE	49	/* Integer */
131
        #define RAD_TERM_USER_REQUEST		1
132
        #define RAD_TERM_LOST_CARRIER		2
133
        #define RAD_TERM_LOST_SERVICE		3
134
        #define RAD_TERM_IDLE_TIMEOUT		4
135
        #define RAD_TERM_SESSION_TIMEOUT	5
136
        #define RAD_TERM_ADMIN_RESET		6
137
        #define RAD_TERM_ADMIN_REBOOT		7
138
        #define RAD_TERM_PORT_ERROR		8
139
        #define RAD_TERM_NAS_ERROR		9
140
        #define RAD_TERM_NAS_REQUEST		10
141
        #define RAD_TERM_NAS_REBOOT		11
142
        #define RAD_TERM_PORT_UNNEEDED		12
143
        #define RAD_TERM_PORT_PREEMPTED		13
144
        #define RAD_TERM_PORT_SUSPENDED		14
145
        #define RAD_TERM_SERVICE_UNAVAILABLE    15
146
        #define RAD_TERM_CALLBACK		16
147
        #define RAD_TERM_USER_ERROR		17
148
        #define RAD_TERM_HOST_REQUEST		18
149
#define	RAD_ACCT_MULTI_SESSION_ID	50	/* String */
150
#define	RAD_ACCT_LINK_COUNT		51	/* Integer */
100
151
101
struct rad_handle;
152
struct rad_handle;
102
struct timeval;
153
struct timeval;
Lines 117-122 Link Here
117
int			 rad_init_send_request(struct rad_handle *, int *,
168
int			 rad_init_send_request(struct rad_handle *, int *,
118
			    struct timeval *);
169
			    struct timeval *);
119
struct rad_handle	*rad_open(void);
170
struct rad_handle	*rad_open(void);
171
struct rad_handle	*rad_auth_open(void);
172
struct rad_handle	*rad_acct_open(void);
120
int			 rad_put_addr(struct rad_handle *, int, struct in_addr);
173
int			 rad_put_addr(struct rad_handle *, int, struct in_addr);
121
int			 rad_put_attr(struct rad_handle *, int,
174
int			 rad_put_attr(struct rad_handle *, int,
122
			    const void *, size_t);
175
			    const void *, size_t);
(-)libradius+/radlib_private.h (+7 lines)
Lines 34-43 Link Here
34
34
35
#include "radlib.h"
35
#include "radlib.h"
36
36
37
/* Handle types */
38
#define RADIUS_AUTH		0   /* RADIUS authentication, default */
39
#define RADIUS_ACCT		1   /* RADIUS accounting */
40
37
/* Defaults */
41
/* Defaults */
38
#define MAXTRIES		3
42
#define MAXTRIES		3
39
#define PATH_RADIUS_CONF	"/etc/radius.conf"
43
#define PATH_RADIUS_CONF	"/etc/radius.conf"
44
#define PATH_RADACCT_CONF	"/etc/radacct.conf"
40
#define RADIUS_PORT		1812
45
#define RADIUS_PORT		1812
46
#define RADACCT_PORT		1813
41
#define TIMEOUT			3	/* In seconds */
47
#define TIMEOUT			3	/* In seconds */
42
48
43
/* Limits */
49
/* Limits */
Lines 81-86 Link Here
81
	int		 total_tries;	/* How many requests we'll send */
87
	int		 total_tries;	/* How many requests we'll send */
82
	int		 try;		/* How many requests we've sent */
88
	int		 try;		/* How many requests we've sent */
83
	int		 srv;		/* Server number we did last */
89
	int		 srv;		/* Server number we did last */
90
	int		 type;		/* Handle type */
84
};
91
};
85
92
86
#endif
93
#endif

Return to bug 14284