Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/libexec/ftpd - rename valid_passwd() -> checkpassword()



details:   https://anonhg.NetBSD.org/src/rev/353b5c99c069
branches:  trunk
changeset: 499811:353b5c99c069
user:      lukem <lukem%NetBSD.org@localhost>
date:      Thu Nov 30 06:06:08 2000 +0000

description:
- rename valid_passwd() -> checkpassword()
- move check for expired accounts from pass() into checkpassword()

diffstat:

 libexec/ftpd/ftpd.c |  55 ++++++++++++++++++++++++++++------------------------
 1 files changed, 30 insertions(+), 25 deletions(-)

diffs (103 lines):

diff -r 24d8f7b27127 -r 353b5c99c069 libexec/ftpd/ftpd.c
--- a/libexec/ftpd/ftpd.c       Thu Nov 30 05:14:01 2000 +0000
+++ b/libexec/ftpd/ftpd.c       Thu Nov 30 06:06:08 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ftpd.c,v 1.115 2000/11/30 02:59:11 lukem Exp $ */
+/*     $NetBSD: ftpd.c,v 1.116 2000/11/30 06:06:08 lukem Exp $ */
 
 /*
  * Copyright (c) 1997-2000 The NetBSD Foundation, Inc.
@@ -109,7 +109,7 @@
 #if 0
 static char sccsid[] = "@(#)ftpd.c     8.5 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: ftpd.c,v 1.115 2000/11/30 02:59:11 lukem Exp $");
+__RCSID("$NetBSD: ftpd.c,v 1.116 2000/11/30 06:06:08 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -210,6 +210,7 @@
 static int      bind_pasv_addr(void);
 static int      checkuser(const char *, const char *, int, int, char **);
 static int      checkaccess(const char *);
+static int      checkpassword(const struct passwd *, const char *);
 static void     dolog(struct sockinet *);
 static void     end_login(void);
 static FILE    *getdatasock(const char *);
@@ -218,7 +219,6 @@
 static void     myoob(int);
 static int      receive_data(FILE *, FILE *);
 static int      send_data(FILE *, FILE *, off_t, int);
-static int      valid_passwd(const struct passwd *, const char *);
 static struct passwd *sgetpwnam(const char *);
 
 int    main(int, char *[]);
@@ -865,15 +865,12 @@
                        }
                }
 #endif
-               if (!sflag && valid_passwd(pw, passwd)) {
-                       rval = 0;
-                       goto skip;
-               }
-               rval = 1;
+               if (!sflag)
+                       rval = checkpassword(pw, passwd);
+               else
+                       rval = 1;
 
  skip:
-               if (pw != NULL && pw->pw_expire && time(NULL) >= pw->pw_expire)
-                       rval = 2;
 
                        /*
                         * If rval > 0, the user failed the authentication check
@@ -2777,25 +2774,33 @@
 }
 
 /*
- * determine if password is valid for user given in pw
- * returns 1 if ok, 0 if not.
+ * Determine if `password' is valid for user given in `pw'.
+ * Returns 2 if password expired, 1 if otherwise failed, 0 if ok
  */
 int
-valid_passwd(const struct passwd *pw, const char *password)
+checkpassword(const struct passwd *pw, const char *password)
 {
-       char *orig, *new;
-       int rv;
+       char    *orig, *new;
+       time_t   expire;
+
+       expire = 0;
+       if (pw == NULL)
+               return 1;
+
+       orig = pw->pw_passwd;           /* save existing password */
+       expire = pw->pw_expire;
 
-                       /* save existing password */
-       orig = pw->pw_passwd;
-                       /* don't let people without passwords in */
-       if (orig[0] == '\0')
-               return 0;
-                       /* encrypt given password */
-       new = crypt(password, orig);
-                       /* compare */
-       rv = strcmp(new, orig) == 0;
-       return (rv);
+       if (orig[0] == '\0')            /* don't allow empty passwords */
+               return 1;
+
+       new = crypt(password, orig);    /* encrypt given password */
+       if (strcmp(new, orig) != 0)     /* compare */
+               return 1;
+
+       if (expire && time(NULL) >= expire)
+               return 2;               /* check if expired */
+
+       return 0;                       /* OK! */
 }
 
 char *



Home | Main Index | Thread Index | Old Index