]> arthur.barton.de Git - netatalk.git/blobdiff - etc/uams/uams_randnum.c
Prevent security attack guessing valid server accounts
[netatalk.git] / etc / uams / uams_randnum.c
index 7d8d78b6f7408ada92f347978e9f152b96e527c7..3d3a5bb9b72afc9bf267a03bb3682d9288f28d1f 100644 (file)
@@ -1,5 +1,5 @@
 /* 
- * $Id: uams_randnum.c,v 1.16 2005-04-28 20:49:50 bfernhomberg Exp $
+ * $Id: uams_randnum.c,v 1.21 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) 
@@ -53,10 +53,6 @@ char *strchr (), *strrchr ();
 #include <crack.h>
 #endif /* USE_CRACKLIB */
 
-#ifndef __inline__
-#define __inline__
-#endif /* __inline__ */
-
 #define PASSWDLEN 8
 
 static C_Block         seskey;
@@ -71,9 +67,9 @@ static u_int8_t         randbuf[8];
 
 
 /* handle ~/.passwd. courtesy of shirsch@ibm.net. */
-static  __inline__ int home_passwd(const struct passwd *pwd, 
+static  int home_passwd(const struct passwd *pwd, 
                                   const char *path, const int pathlen _U_, 
-                                  char *passwd, const int len,
+                                  unsigned char *passwd, const int len,
                                   const int set)
 {
   struct stat st;
@@ -145,7 +141,7 @@ home_passwd_fail:
 #define unhex(x)  (isdigit(x) ? (x) - '0' : toupper(x) + 10 - 'A')
 static int afppasswd(const struct passwd *pwd, 
                     const char *path, const int pathlen, 
-                    char *passwd, int len, 
+                    unsigned char *passwd, int len, 
                     const int set)
 {
   u_int8_t key[DES_KEY_SZ*2];
@@ -264,7 +260,7 @@ afppasswd_done:
  * depending upon whether or not the password is in ~/.passwd
  * or in a global location */
 static int randpass(const struct passwd *pwd, const char *file,
-                   char *passwd, const int len, const int set) 
+                   unsigned char *passwd, const int len, const int set) 
 {
   int i;
   uid_t uid = geteuid();
@@ -304,16 +300,17 @@ static int randpass(const struct passwd *pwd, const char *file,
 /* randnum sends an 8-byte number and uses the user's password to
  * check against the encrypted reply. */
 static int rand_login(void *obj, char *username, int ulen, struct passwd **uam_pwd _U_,
-                        char *ibuf _U_, int ibuflen _U_,
-                        char *rbuf, int *rbuflen)
+                        char *ibuf _U_, size_t ibuflen _U_,
+                        char *rbuf, size_t *rbuflen)
 {
 
   char *passwdfile;
   u_int16_t sessid;
-  int len, err;
+  size_t len;
+  int err;
  
   if (( randpwd = uam_getname(obj, username, ulen)) == NULL )
-    return AFPERR_PARAM; /* unknown user */
+    return AFPERR_NOTAUTH; /* unknown user */
   
   LOG(log_info, logtype_uams, "randnum/rand2num login: %s", username);
   if (uam_checkuser(randpwd) < 0)
@@ -350,8 +347,8 @@ static int rand_login(void *obj, char *username, int ulen, struct passwd **uam_p
 /* check encrypted reply. we actually setup the encryption stuff
  * here as the first part of randnum and rand2num are identical. */
 static int randnum_logincont(void *obj, struct passwd **uam_pwd,
-                            char *ibuf, int ibuflen _U_, 
-                            char *rbuf _U_, int *rbuflen)
+                            char *ibuf, size_t ibuflen _U_, 
+                            char *rbuf _U_, size_t *rbuflen)
 {
   u_int16_t sessid;
 
@@ -389,8 +386,8 @@ static int randnum_logincont(void *obj, struct passwd **uam_pwd,
  *    and sends it back as part of the reply.
  */
 static int rand2num_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)
 {
   u_int16_t sessid;
   unsigned int i;
@@ -439,10 +436,11 @@ static int rand2num_logincont(void *obj, struct passwd **uam_pwd,
  */
 static int randnum_changepw(void *obj, const char *username _U_, 
                            struct passwd *pwd, char *ibuf,
-                           int ibuflen _U_, char *rbuf _U_, int *rbuflen _U_)
+                           size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen _U_)
 {
     char *passwdfile;
-    int err, len;
+    int err;
+    size_t len;
 
     if (uam_checkuser(pwd) < 0)
       return AFPERR_ACCESS;
@@ -478,7 +476,7 @@ static int randnum_changepw(void *obj, const char *username _U_,
 #endif /* USE_CRACKLIB */
 
     if (!err) 
-      err = randpass(pwd, passwdfile, ibuf + PASSWDLEN, sizeof(seskey), 1);
+        err = randpass(pwd, passwdfile, (unsigned char *)ibuf + PASSWDLEN, sizeof(seskey), 1);
 
     /* zero out some fields */
     memset(&seskeysched, 0, sizeof(seskeysched));
@@ -494,11 +492,11 @@ static int randnum_changepw(void *obj, const char *username _U_,
 
 /* randnum login */
 static int randnum_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;
 
@@ -506,7 +504,7 @@ static int randnum_login(void *obj, struct passwd **uam_pwd,
                              (void *) &username, &ulen) < 0)
         return AFPERR_MISC;
 
-    if (ibuflen <= 1) {
+    if (ibuflen < 2) {
         return( AFPERR_PARAM );
     }
 
@@ -529,11 +527,11 @@ static int randnum_login(void *obj, struct passwd **uam_pwd,
 
 /* randnum login ext */
 static int randnum_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;
+    size_t     len, ulen;
     u_int16_t  temp16;
 
     *rbuflen = 0;