* Copyright 2006 TRI-D Systems, Inc.
*/
-#include "ident.h"
+#include <freeradius-devel/ident.h>
RCSID("$Id$")
-#include <freeradius-devel/autoconf.h>
#include <freeradius-devel/radiusd.h>
#include <freeradius-devel/modules.h>
#include "otp.h"
#include "otp_pw_valid.h"
-#include <errno.h>
+#ifdef HAVE_PTHREAD_H
#include <pthread.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+#endif
#include <sys/un.h>
-#include <unistd.h>
/* transform otpd return codes into rlm return codes */
(void) radlog(L_AUTH, "rlm_otp: otpd reply for [%s] invalid "
"(version %d != 1)",
request->username, reply->version);
+ otp_putfd(fdp, 1);
return -1;
}
if (reply->passcode[OTP_MAX_PASSCODE_LEN] != '\0') {
(void) radlog(L_AUTH, "rlm_otp: otpd reply for [%s] invalid (passcode)",
request->username);
+ otp_putfd(fdp, 1);
return -1;
}
+ otp_putfd(fdp, 0);
return reply->rc;
}
} else {
(void) radlog(L_ERR, "rlm_otp: %s: read from otpd: %s",
__func__, strerror(errno));
- otp_putfd(fdp);
+ otp_putfd(fdp, 1);
return -1;
}
}
if (!n) {
(void) radlog(L_ERR, "rlm_otp: %s: otpd disconnect", __func__);
- otp_putfd(fdp);
+ otp_putfd(fdp, 1);
return 0;
}
nread += n;
} else {
(void) radlog(L_ERR, "rlm_otp: %s: write to otpd: %s",
__func__, strerror(errno));
- otp_putfd(fdp);
+ otp_putfd(fdp, 1);
return errno;
}
}
return fdp;
}
-/* disconnect from otpd */
+/* release fd, and optionally disconnect from otpd */
static void
-otp_putfd(otp_fd_t *fdp)
+otp_putfd(otp_fd_t *fdp, int disconnect)
{
- (void) close(fdp->fd);
- fdp->fd = -1;
+ if (disconnect) {
+ (void) close(fdp->fd);
+ fdp->fd = -1;
+ }
+
/* make connection available to another thread */
otp_pthread_mutex_unlock(&fdp->mutex);
}