/*
- * $Id: uams_dhx_pam.c,v 1.25 2005-04-28 20:49:50 bfernhomberg Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* Copyright (c) 1999 Adrian Sun (asun@u.washington.edu)
#ifdef HAVE_PAM_PAM_APPL_H
#include <pam/pam_appl.h>
#endif
-
+#include <arpa/inet.h>
#if defined(GNUTLS_DHX)
#include <gnutls/openssl.h>
#include <openssl/bn.h>
#include <openssl/dh.h>
#include <openssl/cast.h>
-#ifdef sun
-#include <openssl/rand.h>
-#endif
+#include <openssl/err.h>
#else /* OPENSSL_DHX */
#include <bn.h>
#include <dh.h>
#include <cast.h>
+#include <err.h>
#endif /* OPENSSL_DHX */
#include <atalk/afp.h>
/* the secret key */
static CAST_KEY castkey;
static struct passwd *dhxpwd;
-static u_int8_t randbuf[KEYSIZE];
+static uint8_t randbuf[KEYSIZE];
/* diffie-hellman bits */
static unsigned char msg2_iv[] = "CJalbert";
static unsigned char msg3_iv[] = "LWallace";
-static const u_int8_t p[] = {0xBA, 0x28, 0x73, 0xDF, 0xB0, 0x60, 0x57, 0xD4,
+static const uint8_t p[] = {0xBA, 0x28, 0x73, 0xDF, 0xB0, 0x60, 0x57, 0xD4,
0x3F, 0x20, 0x24, 0x74, 0x4C, 0xEE, 0xE7, 0x5B};
-static const u_int8_t g = 0x07;
+static const uint8_t g = 0x07;
/* Static variables used to communicate between the conversation function
* echo off means password.
*/
static int PAM_conv (int num_msg,
+#ifdef LINUX
const struct pam_message **msg,
+#else
+ struct pam_message **msg,
+#endif
struct pam_response **resp,
void *appdata_ptr _U_) {
int count = 0;
};
-static int dhx_setup(void *obj, char *ibuf, int ibuflen _U_,
- char *rbuf, int *rbuflen)
+static int dhx_setup(void *obj, char *ibuf, size_t ibuflen _U_,
+ char *rbuf, size_t *rbuflen)
{
- u_int16_t sessid;
- int i;
+ uint16_t sessid;
+ size_t i;
BIGNUM *bn, *gbn, *pbn;
DH *dh;
- /* TODO: seed dhx_setup properly... this is a hack */
-#ifdef sun
- /* *SEVERE* hack... fix */
- RAND_load_file("/var/adm/messages", KEYSIZE);
-#endif /* sun */
-
/* get the client's public key */
- if (!(bn = BN_bin2bn(ibuf, KEYSIZE, NULL))) {
+ if (!(bn = BN_bin2bn((unsigned char *)ibuf, KEYSIZE, NULL))) {
/* Log Entry */
LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM No Public Key -- %s",
strerror(errno));
/* generate key and make sure that we have enough space */
dh->p = pbn;
dh->g = gbn;
- if (!DH_generate_key(dh) || (BN_num_bytes(dh->pub_key) > KEYSIZE)) {
- /* Log Entry */
- LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: Err Generating Key -- Not enough Space? -- %s",
- strerror(errno));
- /* Log Entry */
- goto pam_fail;
+ if (DH_generate_key(dh) == 0) {
+ unsigned long dherror;
+ char errbuf[256];
+
+ ERR_load_crypto_strings();
+ dherror = ERR_get_error();
+ ERR_error_string_n(dherror, errbuf, 256);
+
+ LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: Err Generating Key (OpenSSL error code: %u, %s)", dherror, errbuf);
+
+ ERR_free_strings();
+ goto pam_fail;
+ }
+ if (BN_num_bytes(dh->pub_key) > KEYSIZE) {
+ LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: Err Generating Key -- Not enough Space? -- %s", strerror(errno));
+ goto pam_fail;
}
/* figure out the key. store the key in rbuf for now. */
- i = DH_compute_key(rbuf, bn, dh);
+ i = DH_compute_key((unsigned char *)rbuf, bn, dh);
/* set the key */
- CAST_set_key(&castkey, i, rbuf);
+ CAST_set_key(&castkey, i, (unsigned char *)rbuf);
/* session id. it's just a hashed version of the object pointer. */
sessid = dhxhash(obj);
*rbuflen += sizeof(sessid);
/* public key */
- BN_bn2bin(dh->pub_key, rbuf);
+ BN_bn2bin(dh->pub_key, (unsigned char *)rbuf);
rbuf += KEYSIZE;
*rbuflen += KEYSIZE;
#endif /* 0 */
/* encrypt using cast */
- CAST_cbc_encrypt(rbuf, rbuf, CRYPTBUFLEN, &castkey, msg2_iv,
+ CAST_cbc_encrypt((unsigned char *)rbuf, (unsigned char *)rbuf, CRYPTBUFLEN, &castkey, msg2_iv,
CAST_ENCRYPT);
*rbuflen += CRYPTBUFLEN;
BN_free(bn);
/* -------------------------------- */
static int login(void *obj, char *username, int ulen, struct passwd **uam_pwd _U_,
- char *ibuf, int ibuflen,
- char *rbuf, int *rbuflen)
+ char *ibuf, size_t ibuflen,
+ char *rbuf, size_t *rbuflen)
{
if (( dhxpwd = uam_getname(obj, username, ulen)) == NULL ) {
- LOG(log_info, logtype_uams, "uams_dhx_pam.c: unknown username");
- return AFPERR_PARAM;
+ LOG(log_info, logtype_uams, "uams_dhx_pam.c: unknown username [%s]", username);
+ return AFPERR_NOTAUTH;
}
PAM_username = username;
/* dhx login: things are done in a slightly bizarre order to avoid
* having to clean things up if there's an error. */
static int pam_login(void *obj, struct passwd **uam_pwd,
- char *ibuf, int ibuflen,
- char *rbuf, int *rbuflen)
+ char *ibuf, size_t ibuflen,
+ char *rbuf, size_t *rbuflen)
{
char *username;
- int len, ulen;
+ size_t len, ulen;
*rbuflen = 0;
/* ----------------------------- */
static int pam_login_ext(void *obj, char *uname, struct passwd **uam_pwd,
- char *ibuf, int ibuflen,
- char *rbuf, int *rbuflen)
+ char *ibuf, size_t ibuflen,
+ char *rbuf, size_t *rbuflen)
{
char *username;
- int len, ulen;
- u_int16_t temp16;
+ int len;
+ size_t ulen;
+ uint16_t temp16;
*rbuflen = 0;
/* -------------------------------- */
static int pam_logincont(void *obj, struct passwd **uam_pwd,
- char *ibuf, int ibuflen _U_,
- char *rbuf, int *rbuflen)
+ char *ibuf, size_t ibuflen _U_,
+ char *rbuf, size_t *rbuflen)
{
- char *hostname;
+ const char *hostname;
BIGNUM *bn1, *bn2, *bn3;
- u_int16_t sessid;
+ uint16_t sessid;
int err, PAM_error;
*rbuflen = 0;
hostname = NULL;
}
- CAST_cbc_encrypt(ibuf, rbuf, CRYPT2BUFLEN, &castkey,
+ CAST_cbc_encrypt((unsigned char *)ibuf, (unsigned char *)rbuf, CRYPT2BUFLEN, &castkey,
msg3_iv, CAST_DECRYPT);
memset(&castkey, 0, sizeof(castkey));
/* check to make sure that the random number is the same. we
* get sent back an incremented random number. */
- if (!(bn1 = BN_bin2bn(rbuf, KEYSIZE, NULL)))
+ if (!(bn1 = BN_bin2bn((unsigned char *)rbuf, KEYSIZE, NULL)))
return AFPERR_PARAM;
if (!(bn2 = BN_bin2bn(randbuf, sizeof(randbuf), NULL))) {
}
/* logout */
-static void pam_logout() {
+static void pam_logout(void) {
pam_close_session(pamh, 0);
pam_end(pamh, 0);
pamh = NULL;
/* change pw for dhx needs a couple passes to get everything all
* right. basically, it's like the login/logincont sequence */
static int pam_changepw(void *obj, char *username,
- struct passwd *pwd _U_, char *ibuf, int ibuflen,
- char *rbuf, int *rbuflen)
+ struct passwd *pwd _U_, char *ibuf, size_t ibuflen,
+ char *rbuf, size_t *rbuflen)
{
BIGNUM *bn1, *bn2, *bn3;
char *hostname;
pam_handle_t *lpamh;
uid_t uid;
- u_int16_t sessid;
+ uint16_t sessid;
int PAM_error;
+ if (ibuflen < sizeof(sessid)) {
+ return AFPERR_PARAM;
+ }
+
/* grab the id */
memcpy(&sessid, ibuf, sizeof(sessid));
ibuf += sizeof(sessid);
}
/* grab the client's nonce, old password, and new password. */
- CAST_cbc_encrypt(ibuf, ibuf, CHANGEPWBUFLEN, &castkey,
+ CAST_cbc_encrypt((unsigned char *)ibuf, (unsigned char *)ibuf, CHANGEPWBUFLEN, &castkey,
msg3_iv, CAST_DECRYPT);
memset(&castkey, 0, sizeof(castkey));
/* check to make sure that the random number is the same. we
* get sent back an incremented random number. */
- if (!(bn1 = BN_bin2bn(ibuf, KEYSIZE, NULL))) {
+ if (!(bn1 = BN_bin2bn((unsigned char *)ibuf, KEYSIZE, NULL))) {
/* Log Entry */
LOG(log_info, logtype_uams, "uams_dhx_pam.c :PAM: Random Number Not the same or not incremented-- %s",
strerror(errno));