xref: /netbsd-src/lib/libpam/modules/pam_radius/pam_radius.c (revision a97560b6443382e82fd5f94e9bc73592eafbcfea)
1*a97560b6Sjoerg /*	$NetBSD: pam_radius.c,v 1.8 2014/01/07 02:07:43 joerg Exp $	*/
2e7d22a2eSchristos 
36f11bdf1Schristos /*-
46f11bdf1Schristos  * Copyright 1998 Juniper Networks, Inc.
56f11bdf1Schristos  * All rights reserved.
66f11bdf1Schristos  * Copyright (c) 2001-2003 Networks Associates Technology, Inc.
76f11bdf1Schristos  * All rights reserved.
86f11bdf1Schristos  *
96f11bdf1Schristos  * Portions of this software were developed for the FreeBSD Project by
106f11bdf1Schristos  * ThinkSec AS and NAI Labs, the Security Research Division of Network
116f11bdf1Schristos  * Associates, Inc.  under DARPA/SPAWAR contract N66001-01-C-8035
126f11bdf1Schristos  * ("CBOSS"), as part of the DARPA CHATS research program.
136f11bdf1Schristos  *
146f11bdf1Schristos  * Redistribution and use in source and binary forms, with or without
156f11bdf1Schristos  * modification, are permitted provided that the following conditions
166f11bdf1Schristos  * are met:
176f11bdf1Schristos  * 1. Redistributions of source code must retain the above copyright
186f11bdf1Schristos  *    notice, this list of conditions and the following disclaimer.
196f11bdf1Schristos  * 2. Redistributions in binary form must reproduce the above copyright
206f11bdf1Schristos  *    notice, this list of conditions and the following disclaimer in the
216f11bdf1Schristos  *    documentation and/or other materials provided with the distribution.
226f11bdf1Schristos  * 3. The name of the author may not be used to endorse or promote
236f11bdf1Schristos  *    products derived from this software without specific prior written
246f11bdf1Schristos  *    permission.
256f11bdf1Schristos  *
266f11bdf1Schristos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
276f11bdf1Schristos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
286f11bdf1Schristos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
296f11bdf1Schristos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
306f11bdf1Schristos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
316f11bdf1Schristos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
326f11bdf1Schristos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
336f11bdf1Schristos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
346f11bdf1Schristos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
356f11bdf1Schristos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
366f11bdf1Schristos  * SUCH DAMAGE.
376f11bdf1Schristos  */
386f11bdf1Schristos 
396f11bdf1Schristos #include <sys/cdefs.h>
40e7d22a2eSchristos #ifdef __FreeBSD__
416f11bdf1Schristos __FBSDID("$FreeBSD: src/lib/libpam/modules/pam_radius/pam_radius.c,v 1.22 2004/06/25 12:32:45 kan Exp $");
42e7d22a2eSchristos #else
43*a97560b6Sjoerg __RCSID("$NetBSD: pam_radius.c,v 1.8 2014/01/07 02:07:43 joerg Exp $");
44e7d22a2eSchristos #endif
456f11bdf1Schristos 
466f11bdf1Schristos #include <sys/param.h>
476f11bdf1Schristos #include <sys/types.h>
486f11bdf1Schristos #include <sys/socket.h>
496f11bdf1Schristos #include <netdb.h>
506f11bdf1Schristos #include <pwd.h>
516f11bdf1Schristos #include <radlib.h>
526f11bdf1Schristos #include <stdlib.h>
536f11bdf1Schristos #include <string.h>
546f11bdf1Schristos #include <syslog.h>
556f11bdf1Schristos #include <unistd.h>
56e76ecd93Schristos #include <stdarg.h>
576f11bdf1Schristos 
586f11bdf1Schristos #define PAM_SM_AUTH
596f11bdf1Schristos 
606f11bdf1Schristos #include <security/pam_appl.h>
616f11bdf1Schristos #include <security/pam_modules.h>
626f11bdf1Schristos #include <security/pam_mod_misc.h>
636f11bdf1Schristos 
646f11bdf1Schristos #define PAM_OPT_CONF		"conf"
656f11bdf1Schristos #define PAM_OPT_TEMPLATE_USER	"template_user"
666f11bdf1Schristos #define PAM_OPT_NAS_ID		"nas_id"
676f11bdf1Schristos #define PAM_OPT_NAS_IPADDR	"nas_ipaddr"
686f11bdf1Schristos 
696f11bdf1Schristos #define	MAX_CHALLENGE_MSGS	10
706f11bdf1Schristos #define	PASSWORD_PROMPT		"RADIUS Password:"
716f11bdf1Schristos 
726f11bdf1Schristos static int	 build_access_request(struct rad_handle *, const char *,
736f11bdf1Schristos 		    const char *, const char *, const char *, const void *,
746f11bdf1Schristos 		    size_t);
756f11bdf1Schristos static int	 do_accept(pam_handle_t *, struct rad_handle *);
766f11bdf1Schristos static int	 do_challenge(pam_handle_t *, struct rad_handle *,
776f11bdf1Schristos 		    const char *);
786f11bdf1Schristos 
79*a97560b6Sjoerg __printflike(2, 3)
80e76ecd93Schristos static void
logit(int level,const char * fmt,...)81e76ecd93Schristos logit(int level, const char *fmt, ...)
82e76ecd93Schristos {
83e76ecd93Schristos 	va_list ap;
844ed3eb7fSchristos 	struct syslog_data data = SYSLOG_DATA_INIT;
85e76ecd93Schristos 
86e76ecd93Schristos 	openlog_r("pam_radius", LOG_PID, LOG_AUTHPRIV, &data);
87e76ecd93Schristos 	va_start(ap, fmt);
88e76ecd93Schristos 	vsyslog_r(level, &data, fmt, ap);
89e76ecd93Schristos 	va_end(ap);
90e76ecd93Schristos 	closelog_r(&data);
91e76ecd93Schristos }
92e76ecd93Schristos 
936f11bdf1Schristos /*
946f11bdf1Schristos  * Construct an access request, but don't send it.  Returns 0 on success,
956f11bdf1Schristos  * -1 on failure.
966f11bdf1Schristos  */
976f11bdf1Schristos static int
build_access_request(struct rad_handle * radh,const char * user,const char * pass,const char * nas_id,const char * nas_ipaddr,const void * state,size_t state_len)986f11bdf1Schristos build_access_request(struct rad_handle *radh, const char *user,
996f11bdf1Schristos     const char *pass, const char *nas_id, const char *nas_ipaddr,
1006f11bdf1Schristos     const void *state, size_t state_len)
1016f11bdf1Schristos {
1026f11bdf1Schristos 	int error;
1036f11bdf1Schristos 	char host[MAXHOSTNAMELEN];
1046f11bdf1Schristos 	struct sockaddr_in *haddr;
1056f11bdf1Schristos 	struct addrinfo hints;
1066f11bdf1Schristos 	struct addrinfo *res;
1076f11bdf1Schristos 
1086f11bdf1Schristos 	if (rad_create_request(radh, RAD_ACCESS_REQUEST) == -1) {
109e76ecd93Schristos 		logit(LOG_CRIT, "rad_create_request: %s", rad_strerror(radh));
1106f11bdf1Schristos 		return (-1);
1116f11bdf1Schristos 	}
1126f11bdf1Schristos 	if (nas_id == NULL ||
1136f11bdf1Schristos 	    (nas_ipaddr != NULL && strlen(nas_ipaddr) == 0)) {
1146f11bdf1Schristos 		if (gethostname(host, sizeof host) != -1) {
1156f11bdf1Schristos 			if (nas_id == NULL)
1166f11bdf1Schristos 				nas_id = host;
1176f11bdf1Schristos 			if (nas_ipaddr != NULL && strlen(nas_ipaddr) == 0)
1186f11bdf1Schristos 				nas_ipaddr = host;
1196f11bdf1Schristos 		}
1206f11bdf1Schristos 	}
1216f11bdf1Schristos 	if ((user != NULL &&
1226f11bdf1Schristos 	    rad_put_string(radh, RAD_USER_NAME, user) == -1) ||
1236f11bdf1Schristos 	    (pass != NULL &&
1246f11bdf1Schristos 	    rad_put_string(radh, RAD_USER_PASSWORD, pass) == -1) ||
1256f11bdf1Schristos 	    (nas_id != NULL &&
1266f11bdf1Schristos 	    rad_put_string(radh, RAD_NAS_IDENTIFIER, nas_id) == -1)) {
127e76ecd93Schristos 		logit(LOG_CRIT, "rad_put_string: %s", rad_strerror(radh));
1286f11bdf1Schristos 		return (-1);
1296f11bdf1Schristos 	}
1306f11bdf1Schristos 	if (nas_ipaddr != NULL) {
1316f11bdf1Schristos 		memset(&hints, 0, sizeof(hints));
1326f11bdf1Schristos 		hints.ai_family = PF_INET;
1336f11bdf1Schristos 		if (getaddrinfo(nas_ipaddr, NULL, &hints, &res) == 0 &&
1346f11bdf1Schristos 		    res != NULL) {
135bb1ca526Smatt 			haddr = (struct sockaddr_in *)res->ai_addr;
1366f11bdf1Schristos 			error = rad_put_addr(radh, RAD_NAS_IP_ADDRESS,
1376f11bdf1Schristos 			    haddr->sin_addr);
1386f11bdf1Schristos 			freeaddrinfo(res);
1396f11bdf1Schristos 			if (error == -1) {
140e76ecd93Schristos 				logit(LOG_CRIT, "rad_put_addr: %s",
1416f11bdf1Schristos 				    rad_strerror(radh));
1426f11bdf1Schristos 				return (-1);
1436f11bdf1Schristos 			}
1446f11bdf1Schristos 		}
1456f11bdf1Schristos 	}
1466f11bdf1Schristos 	if (state != NULL && rad_put_attr(radh, RAD_STATE, state,
1476f11bdf1Schristos 	    state_len) == -1) {
148e76ecd93Schristos 		logit(LOG_CRIT, "rad_put_attr: %s", rad_strerror(radh));
1496f11bdf1Schristos 		return (-1);
1506f11bdf1Schristos 	}
1516f11bdf1Schristos 	if (rad_put_int(radh, RAD_SERVICE_TYPE, RAD_AUTHENTICATE_ONLY) == -1) {
152e76ecd93Schristos 		logit(LOG_CRIT, "rad_put_int: %s", rad_strerror(radh));
1536f11bdf1Schristos 		return (-1);
1546f11bdf1Schristos 	}
1556f11bdf1Schristos 	return (0);
1566f11bdf1Schristos }
1576f11bdf1Schristos 
1586f11bdf1Schristos static int
do_accept(pam_handle_t * pamh,struct rad_handle * radh)1596f11bdf1Schristos do_accept(pam_handle_t *pamh, struct rad_handle *radh)
1606f11bdf1Schristos {
1616f11bdf1Schristos 	int attrtype;
1626f11bdf1Schristos 	const void *attrval;
1636f11bdf1Schristos 	size_t attrlen;
1646f11bdf1Schristos 	char *s;
1656f11bdf1Schristos 
1666f11bdf1Schristos 	while ((attrtype = rad_get_attr(radh, &attrval, &attrlen)) > 0) {
1676f11bdf1Schristos 		if (attrtype == RAD_USER_NAME) {
1686f11bdf1Schristos 			s = rad_cvt_string(attrval, attrlen);
1696f11bdf1Schristos 			if (s == NULL) {
170e76ecd93Schristos 				logit(LOG_CRIT,
1716f11bdf1Schristos 				    "rad_cvt_string: out of memory");
1726f11bdf1Schristos 				return (-1);
1736f11bdf1Schristos 			}
1746f11bdf1Schristos 			pam_set_item(pamh, PAM_USER, s);
1756f11bdf1Schristos 			free(s);
1766f11bdf1Schristos 		}
1776f11bdf1Schristos 	}
1786f11bdf1Schristos 	if (attrtype == -1) {
179e76ecd93Schristos 		logit(LOG_CRIT, "rad_get_attr: %s", rad_strerror(radh));
1806f11bdf1Schristos 		return (-1);
1816f11bdf1Schristos 	}
1826f11bdf1Schristos 	return (0);
1836f11bdf1Schristos }
1846f11bdf1Schristos 
1856f11bdf1Schristos static int
do_challenge(pam_handle_t * pamh,struct rad_handle * radh,const char * user)1866f11bdf1Schristos do_challenge(pam_handle_t *pamh, struct rad_handle *radh, const char *user)
1876f11bdf1Schristos {
1886f11bdf1Schristos 	int retval;
1896f11bdf1Schristos 	int attrtype;
1906f11bdf1Schristos 	const void *attrval;
1916f11bdf1Schristos 	size_t attrlen;
1926f11bdf1Schristos 	const void *state;
1936f11bdf1Schristos 	size_t statelen;
1946f11bdf1Schristos 	struct pam_message msgs[MAX_CHALLENGE_MSGS];
1956f11bdf1Schristos 	const struct pam_message *msg_ptrs[MAX_CHALLENGE_MSGS];
1966f11bdf1Schristos 	struct pam_response *resp;
1976f11bdf1Schristos 	int num_msgs;
1986f11bdf1Schristos 	const void *item;
1996f11bdf1Schristos 	const struct pam_conv *conv;
2006f11bdf1Schristos 
2016f11bdf1Schristos 	state = NULL;
2026f11bdf1Schristos 	statelen = 0;
2036f11bdf1Schristos 	num_msgs = 0;
2046f11bdf1Schristos 	while ((attrtype = rad_get_attr(radh, &attrval, &attrlen)) > 0) {
2056f11bdf1Schristos 		switch (attrtype) {
2066f11bdf1Schristos 
2076f11bdf1Schristos 		case RAD_STATE:
2086f11bdf1Schristos 			state = attrval;
2096f11bdf1Schristos 			statelen = attrlen;
2106f11bdf1Schristos 			break;
2116f11bdf1Schristos 
2126f11bdf1Schristos 		case RAD_REPLY_MESSAGE:
2136f11bdf1Schristos 			if (num_msgs >= MAX_CHALLENGE_MSGS) {
214e76ecd93Schristos 				logit(LOG_CRIT,
2156f11bdf1Schristos 				    "Too many RADIUS challenge messages");
2166f11bdf1Schristos 				return (PAM_SERVICE_ERR);
2176f11bdf1Schristos 			}
2186f11bdf1Schristos 			msgs[num_msgs].msg = rad_cvt_string(attrval, attrlen);
2196f11bdf1Schristos 			if (msgs[num_msgs].msg == NULL) {
220e76ecd93Schristos 				logit(LOG_CRIT,
2216f11bdf1Schristos 				    "rad_cvt_string: out of memory");
2226f11bdf1Schristos 				return (PAM_SERVICE_ERR);
2236f11bdf1Schristos 			}
2246f11bdf1Schristos 			msgs[num_msgs].msg_style = PAM_TEXT_INFO;
2256f11bdf1Schristos 			msg_ptrs[num_msgs] = &msgs[num_msgs];
2266f11bdf1Schristos 			num_msgs++;
2276f11bdf1Schristos 			break;
2286f11bdf1Schristos 		}
2296f11bdf1Schristos 	}
2306f11bdf1Schristos 	if (attrtype == -1) {
231e76ecd93Schristos 		logit(LOG_CRIT, "rad_get_attr: %s", rad_strerror(radh));
2326f11bdf1Schristos 		return (PAM_SERVICE_ERR);
2336f11bdf1Schristos 	}
2346f11bdf1Schristos 	if (num_msgs == 0) {
2356f11bdf1Schristos 		msgs[num_msgs].msg = strdup("(null RADIUS challenge): ");
2366f11bdf1Schristos 		if (msgs[num_msgs].msg == NULL) {
237e76ecd93Schristos 			logit(LOG_CRIT, "Out of memory");
2386f11bdf1Schristos 			return (PAM_SERVICE_ERR);
2396f11bdf1Schristos 		}
2406f11bdf1Schristos 		msgs[num_msgs].msg_style = PAM_TEXT_INFO;
2416f11bdf1Schristos 		msg_ptrs[num_msgs] = &msgs[num_msgs];
2426f11bdf1Schristos 		num_msgs++;
2436f11bdf1Schristos 	}
2446f11bdf1Schristos 	msgs[num_msgs-1].msg_style = PAM_PROMPT_ECHO_ON;
2456f11bdf1Schristos 	if ((retval = pam_get_item(pamh, PAM_CONV, &item)) != PAM_SUCCESS) {
246e76ecd93Schristos 		logit(LOG_CRIT, "do_challenge: cannot get PAM_CONV");
2476f11bdf1Schristos 		return (retval);
2486f11bdf1Schristos 	}
2496f11bdf1Schristos 	conv = (const struct pam_conv *)item;
2506f11bdf1Schristos 	if ((retval = conv->conv(num_msgs, msg_ptrs, &resp,
2516f11bdf1Schristos 	    conv->appdata_ptr)) != PAM_SUCCESS)
2526f11bdf1Schristos 		return (retval);
2536f11bdf1Schristos 	if (build_access_request(radh, user, resp[num_msgs-1].resp, NULL,
2546f11bdf1Schristos 	    NULL, state, statelen) == -1)
2556f11bdf1Schristos 		return (PAM_SERVICE_ERR);
2566f11bdf1Schristos 	memset(resp[num_msgs-1].resp, 0, strlen(resp[num_msgs-1].resp));
2576f11bdf1Schristos 	free(resp[num_msgs-1].resp);
2586f11bdf1Schristos 	free(resp);
2596f11bdf1Schristos 	while (num_msgs > 0)
2606f11bdf1Schristos 		free(msgs[--num_msgs].msg);
2616f11bdf1Schristos 	return (PAM_SUCCESS);
2626f11bdf1Schristos }
2636f11bdf1Schristos 
2646f11bdf1Schristos PAM_EXTERN int
pam_sm_authenticate(pam_handle_t * pamh,int flags __unused,int argc __unused,const char * argv[]__unused)2656f11bdf1Schristos pam_sm_authenticate(pam_handle_t *pamh, int flags __unused,
2666f11bdf1Schristos     int argc __unused, const char *argv[] __unused)
2676f11bdf1Schristos {
2686f11bdf1Schristos 	struct rad_handle *radh;
2696f11bdf1Schristos 	const char *user, *pass;
2706f11bdf1Schristos 	const void *tmpuser;
27159cbc9e2Sthorpej 	struct passwd *pwd, pwres;
27259cbc9e2Sthorpej 	char pwbuf[1024];
2736f11bdf1Schristos 	const char *conf_file, *template_user, *nas_id, *nas_ipaddr;
2746f11bdf1Schristos 	int retval;
2756f11bdf1Schristos 	int e;
2766f11bdf1Schristos 
2776f11bdf1Schristos 	conf_file = openpam_get_option(pamh, PAM_OPT_CONF);
2786f11bdf1Schristos 	template_user = openpam_get_option(pamh, PAM_OPT_TEMPLATE_USER);
2796f11bdf1Schristos 	nas_id = openpam_get_option(pamh, PAM_OPT_NAS_ID);
2806f11bdf1Schristos 	nas_ipaddr = openpam_get_option(pamh, PAM_OPT_NAS_IPADDR);
2816f11bdf1Schristos 
2826f11bdf1Schristos 	retval = pam_get_user(pamh, &user, NULL);
2836f11bdf1Schristos 	if (retval != PAM_SUCCESS)
2846f11bdf1Schristos 		return (retval);
2856f11bdf1Schristos 
2866f11bdf1Schristos 	PAM_LOG("Got user: %s", user);
2876f11bdf1Schristos 
2886f11bdf1Schristos 	retval = pam_get_authtok(pamh, PAM_AUTHTOK, &pass, PASSWORD_PROMPT);
2896f11bdf1Schristos 	if (retval != PAM_SUCCESS)
2906f11bdf1Schristos 		return (retval);
2916f11bdf1Schristos 
2926f11bdf1Schristos 	PAM_LOG("Got password");
2936f11bdf1Schristos 
2946f11bdf1Schristos 	radh = rad_open();
2956f11bdf1Schristos 	if (radh == NULL) {
296e76ecd93Schristos 		logit(LOG_CRIT, "rad_open failed");
2976f11bdf1Schristos 		return (PAM_SERVICE_ERR);
2986f11bdf1Schristos 	}
2996f11bdf1Schristos 
3006f11bdf1Schristos 	PAM_LOG("Radius opened");
3016f11bdf1Schristos 
3026f11bdf1Schristos 	if (rad_config(radh, conf_file) == -1) {
303e76ecd93Schristos 		logit(LOG_ALERT, "rad_config: %s", rad_strerror(radh));
3046f11bdf1Schristos 		rad_close(radh);
3056f11bdf1Schristos 		return (PAM_SERVICE_ERR);
3066f11bdf1Schristos 	}
3076f11bdf1Schristos 
3086f11bdf1Schristos 	PAM_LOG("Radius config file read");
3096f11bdf1Schristos 
3106f11bdf1Schristos 	if (build_access_request(radh, user, pass, nas_id, nas_ipaddr, NULL,
3116f11bdf1Schristos 	    0) == -1) {
3126f11bdf1Schristos 		rad_close(radh);
3136f11bdf1Schristos 		return (PAM_SERVICE_ERR);
3146f11bdf1Schristos 	}
3156f11bdf1Schristos 
3166f11bdf1Schristos 	PAM_LOG("Radius build access done");
3176f11bdf1Schristos 
3186f11bdf1Schristos 	for (;;) {
3196f11bdf1Schristos 		switch (rad_send_request(radh)) {
3206f11bdf1Schristos 
3216f11bdf1Schristos 		case RAD_ACCESS_ACCEPT:
3226f11bdf1Schristos 			e = do_accept(pamh, radh);
3236f11bdf1Schristos 			rad_close(radh);
3246f11bdf1Schristos 			if (e == -1)
3256f11bdf1Schristos 				return (PAM_SERVICE_ERR);
3266f11bdf1Schristos 			if (template_user != NULL) {
3276f11bdf1Schristos 
3286f11bdf1Schristos 				PAM_LOG("Trying template user: %s",
3296f11bdf1Schristos 				    template_user);
3306f11bdf1Schristos 
3316f11bdf1Schristos 				/*
3326f11bdf1Schristos 				 * If the given user name doesn't exist in
3336f11bdf1Schristos 				 * the local password database, change it
3346f11bdf1Schristos 				 * to the value given in the "template_user"
3356f11bdf1Schristos 				 * option.
3366f11bdf1Schristos 				 */
3376f11bdf1Schristos 				retval = pam_get_item(pamh, PAM_USER, &tmpuser);
3386f11bdf1Schristos 				if (retval != PAM_SUCCESS)
3396f11bdf1Schristos 					return (retval);
34059cbc9e2Sthorpej 				if (getpwnam_r(tmpuser, &pwres, pwbuf,
3412a62e4e1Schristos 					       sizeof(pwbuf), &pwd) != 0 ||
3422a62e4e1Schristos 				    pwd == NULL) {
3436f11bdf1Schristos 					pam_set_item(pamh, PAM_USER,
3446f11bdf1Schristos 					    template_user);
3456f11bdf1Schristos 					PAM_LOG("Using template user");
3466f11bdf1Schristos 				}
3476f11bdf1Schristos 
3486f11bdf1Schristos 			}
3496f11bdf1Schristos 			return (PAM_SUCCESS);
3506f11bdf1Schristos 
3516f11bdf1Schristos 		case RAD_ACCESS_REJECT:
3526f11bdf1Schristos 			rad_close(radh);
3536f11bdf1Schristos 			PAM_VERBOSE_ERROR("Radius rejection");
3546f11bdf1Schristos 			return (PAM_AUTH_ERR);
3556f11bdf1Schristos 
3566f11bdf1Schristos 		case RAD_ACCESS_CHALLENGE:
3576f11bdf1Schristos 			retval = do_challenge(pamh, radh, user);
3586f11bdf1Schristos 			if (retval != PAM_SUCCESS) {
3596f11bdf1Schristos 				rad_close(radh);
3606f11bdf1Schristos 				return (retval);
3616f11bdf1Schristos 			}
3626f11bdf1Schristos 			break;
3636f11bdf1Schristos 
3646f11bdf1Schristos 		case -1:
365e76ecd93Schristos 			logit(LOG_CRIT, "rad_send_request: %s",
3666f11bdf1Schristos 			    rad_strerror(radh));
3676f11bdf1Schristos 			rad_close(radh);
3686f11bdf1Schristos 			PAM_VERBOSE_ERROR("Radius failure");
3696f11bdf1Schristos 			return (PAM_AUTHINFO_UNAVAIL);
3706f11bdf1Schristos 
3716f11bdf1Schristos 		default:
372e76ecd93Schristos 			logit(LOG_CRIT,
3736f11bdf1Schristos 			    "rad_send_request: unexpected return value");
3746f11bdf1Schristos 			rad_close(radh);
3756f11bdf1Schristos 			PAM_VERBOSE_ERROR("Radius error");
3766f11bdf1Schristos 			return (PAM_SERVICE_ERR);
3776f11bdf1Schristos 		}
3786f11bdf1Schristos 	}
3796f11bdf1Schristos }
3806f11bdf1Schristos 
3816f11bdf1Schristos PAM_EXTERN int
pam_sm_setcred(pam_handle_t * pamh __unused,int flags __unused,int argc __unused,const char * argv[]__unused)3826f11bdf1Schristos pam_sm_setcred(pam_handle_t *pamh __unused, int flags __unused,
3836f11bdf1Schristos     int argc __unused, const char *argv[] __unused)
3846f11bdf1Schristos {
3856f11bdf1Schristos 
3866f11bdf1Schristos 	return (PAM_SUCCESS);
3876f11bdf1Schristos }
3886f11bdf1Schristos 
3896f11bdf1Schristos PAM_MODULE_ENTRY("pam_radius");
390