Added cryptpasswd command, to create/check encrypted passwords.
authoraland <aland>
Fri, 28 Sep 2001 14:04:29 +0000 (14:04 +0000)
committeraland <aland>
Fri, 28 Sep 2001 14:04:29 +0000 (14:04 +0000)
by miquels@cistron-office.nl (Miquel van Smoorenburg)

configure
configure.in
scripts/cryptpasswd.in [new file with mode: 0755]

index 2614874..d455530 100755 (executable)
--- a/configure
+++ b/configure
@@ -4582,6 +4582,7 @@ trap 'rm -fr `echo "\
        ./scripts/check-radiusd-config \
        ./scripts/radiusd.cron.daily \
        ./scripts/radiusd.cron.monthly \
+       ./scripts/cryptpasswd \
        ./raddb/radiusd.conf
  src/include/autoconf.h" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15
 EOF
@@ -4717,6 +4718,7 @@ CONFIG_FILES=\${CONFIG_FILES-"\
        ./scripts/check-radiusd-config \
        ./scripts/radiusd.cron.daily \
        ./scripts/radiusd.cron.monthly \
+       ./scripts/cryptpasswd \
        ./raddb/radiusd.conf
 "}
 EOF
@@ -4993,7 +4995,7 @@ fi
 echo timestamp > src/include/stamp-h
 (cd ./src/include && /bin/sh ./build-radpaths-h)
 (cd ./src/main   && chmod +x checkrad.pl radlast radtest)
-(cd ./scripts    && chmod +x rc.radiusd radwatch check-radiusd-config radiusd.cron.daily radiusd.cron.monthly)
+(cd ./scripts    && chmod +x rc.radiusd radwatch check-radiusd-config radiusd.cron.daily radiusd.cron.monthly cryptpasswd)
 
 cat >> src/include/autoconf.h <<EOF
 
index cd0cc34..4e7c3ba 100644 (file)
@@ -727,13 +727,14 @@ AC_OUTPUT(\
        ./scripts/check-radiusd-config \
        ./scripts/radiusd.cron.daily \
        ./scripts/radiusd.cron.monthly \
+       ./scripts/cryptpasswd \
        ./raddb/radiusd.conf
 )
 
 AC_OUTPUT_COMMANDS([echo timestamp > src/include/stamp-h])
 AC_OUTPUT_COMMANDS([(cd ./src/include && /bin/sh ./build-radpaths-h)])
 AC_OUTPUT_COMMANDS([(cd ./src/main   && chmod +x checkrad.pl radlast radtest)])
-AC_OUTPUT_COMMANDS([(cd ./scripts    && chmod +x rc.radiusd radwatch check-radiusd-config radiusd.cron.daily radiusd.cron.monthly)])
+AC_OUTPUT_COMMANDS([(cd ./scripts    && chmod +x rc.radiusd radwatch check-radiusd-config radiusd.cron.daily radiusd.cron.monthly cryptpasswd)])
 AC_OUTPUT_COMMANDS([
 cat >> src/include/autoconf.h <<EOF
 
diff --git a/scripts/cryptpasswd.in b/scripts/cryptpasswd.in
new file mode 100755 (executable)
index 0000000..e9388ad
--- /dev/null
@@ -0,0 +1,80 @@
+#!@PERL@
+#
+# cryptpasswd  Generate or check md5 and DES hashed passwords.
+#
+#    This program is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program; if not, write to the Free Software
+#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+#    Copyright (C) 2001 The FreeRADIUS Project   http://www.freeradius.org
+#
+#    Written by Miquel van Smoorenburg <miquels@cistron-office.nl>
+#
+#    $Id$
+#
+
+use Getopt::Long;
+
+sub check_des {
+       return (crypt("fnord", "aa") =~ m/^aa/);
+}
+
+sub check_md5 {
+       return (crypt("fnord", "\$1\$aa") =~ m/^\$1\$/);
+}
+
+sub usage {
+       die "Usage: cryptpasswd [--des|--md5|--check] plaintext_password [crypted_password]\n";
+}
+
+@saltc = ( '.', '/', '0'..'9', 'A'..'Z', 'a'..'z' );
+
+#
+#      MAIN
+#
+sub main {
+
+       Getopt::Long::Configure("no_ignore_case", "bundling");
+       my @options = ( "des|d+", "md5|m+", "check|c+" );
+       usage() unless (eval { Getopt::Long::GetOptions(@options) } );
+
+       if ($opt_check) {
+               usage unless ($#ARGV == 1);
+               if (crypt($ARGV[0], $ARGV[1]) ne $ARGV[1]) {
+                       print "Password BAD\n";
+                       return 0;
+               } else {
+                       print "Password OK\n";
+                       return 1;
+               }
+       }
+
+       usage() unless ($opt_des || $opt_md5);
+       usage() unless ($#ARGV == 0);
+
+       die "DES password hashing not available\n"
+               if ($opt_des && !check_des());
+       die "MD5 password hashing not available\n"
+               if ($opt_md5 && !check_md5());
+
+       $salt = ($opt_md5 ? '$1$' : '');
+       for ($i = 0; $i < ($opt_md5 ? 8 : 2); $i++) {
+               $salt .= $saltc[rand 64];
+       }
+       $salt .= '$' if ($opt_md5);
+       print crypt($ARGV[0], $salt), "\n";
+
+       1;
+}
+
+exit !main();