]> arthur.barton.de Git - netatalk.git/blobdiff - etc/uams/uams_dhx_pam.c
Enhance logging
[netatalk.git] / etc / uams / uams_dhx_pam.c
index adb00a1af90e1bed805b0684a23fa8b16dd962f6..b3bd931052c54b424cd328579be35f67531b7813 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: uams_dhx_pam.c,v 1.26 2008-12-02 18:24:55 morgana Exp $
+ * $Id: uams_dhx_pam.c,v 1.33 2010-03-30 10:25:49 franklahm Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * Copyright (c) 1999 Adrian Sun (asun@u.washington.edu) 
 #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>
@@ -185,20 +184,14 @@ static struct pam_conv PAM_conversation = {
 };
 
 
-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;
+    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))) {
     /* Log Entry */
@@ -327,12 +320,12 @@ pam_fail:
 
 /* -------------------------------- */
 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;
@@ -344,11 +337,11 @@ static int login(void *obj, char *username, int ulen,  struct passwd **uam_pwd _
 /* 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;
 
@@ -378,8 +371,8 @@ static int pam_login(void *obj, struct passwd **uam_pwd,
 
 /* ----------------------------- */
 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;
@@ -414,10 +407,10 @@ static int pam_login_ext(void *obj, char *uname, struct passwd **uam_pwd,
 /* -------------------------------- */
 
 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;
     int err, PAM_error;
@@ -561,7 +554,7 @@ logincont_err:
 }
 
 /* logout */
-static void pam_logout() {
+static void pam_logout(void) {
     pam_close_session(pamh, 0);
     pam_end(pamh, 0);
     pamh = NULL;
@@ -571,8 +564,8 @@ static void pam_logout() {
 /* 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;
 
@@ -582,6 +575,10 @@ static int pam_changepw(void *obj, char *username,
     u_int16_t sessid;
     int PAM_error;
 
+    if (ibuflen < sizeof(sessid)) {
+      return AFPERR_PARAM;
+    }
+
     /* grab the id */
     memcpy(&sessid, ibuf, sizeof(sessid));
     ibuf += sizeof(sessid);