Path: blob/main/crypto/heimdal/lib/kadm5/check-cracklib.pl
34878 views
#!/usr/pkg/bin/perl1#2# Sample password verifier for Heimdals external password3# verifier, see the chapter "Password changing" in the the info4# documentation for more information about the protocol used.5#6# Three checks7# 1. Check that password is not the principal name8# 2. Check that the password passes cracklib9# 3. Check that password isn't repeated for this principal10#11# The repeat check must be last because some clients ask12# twice when getting "no" back and thus the error message13# would be wrong.14#15# Prereqs (example versions):16#17# * perl (5.8.5) http://www.perl.org/18# * cracklib (2.8.5) http://sourceforge.net/projects/cracklib19# * Crypt-Cracklib perlmodule (0.01) http://search.cpan.org/~daniel/20#21# Sample dictionaries:22# cracklib-words (1.1) http://sourceforge.net/projects/cracklib23# miscfiles (1.4.2) http://directory.fsf.org/miscfiles.html24#25# Configuration for krb5.conf or kdc.conf26#27# [password_quality]28# policies = builtin:external-check29# external_program = <your-path>/check-cracklib.pl30#31# $Id$3233use strict;34use Crypt::Cracklib;35use Digest::MD5;3637# NEED TO CHANGE THESE TO MATCH YOUR SYSTEM38my $database = '/usr/lib/cracklib_dict';39my $historydb = '/var/heimdal/historydb';40# NEED TO CHANGE THESE TO MATCH YOUR SYSTEM4142# seconds password reuse allowed (to catch retries from clients)43my $reusetime = 60;4445my %params;4647sub check_basic48{49my $principal = shift;50my $passwd = shift;5152if ($principal eq $passwd) {53return "Principal name as password is not allowed";54}55return "ok";56}5758sub check_repeat59{60my $principal = shift;61my $passwd = shift;62my $result = 'Do not reuse passwords';63my %DB;64my $md5context = new Digest::MD5;65my $timenow = scalar(time());6667$md5context->reset();68$md5context->add($principal, ":", $passwd);6970my $key=$md5context->hexdigest();7172dbmopen(%DB,$historydb,0600) or die "Internal: Could not open $historydb";73if (!$DB{$key} || ($timenow - $DB{$key} < $reusetime)) {74$result = "ok";75$DB{$key}=$timenow;76}77dbmclose(%DB) or die "Internal: Could not close $historydb";78return $result;79}8081sub badpassword82{83my $reason = shift;84print "$reason\n";85exit 086}8788while (<STDIN>) {89last if /^end$/;90if (!/^([^:]+): (.+)$/) {91die "key value pair not correct: $_";92}93$params{$1} = $2;94}9596die "missing principal" if (!defined $params{'principal'});97die "missing password" if (!defined $params{'new-password'});9899my $reason;100101$reason = check_basic($params{'principal'}, $params{'new-password'});102badpassword($reason) if ($reason ne "ok");103104$reason = fascist_check($params{'new-password'}, $database);105badpassword($reason) if ($reason ne "ok");106107$reason = check_repeat($params{'principal'}, $params{'new-password'});108badpassword($reason) if ($reason ne "ok");109110print "APPROVED\n";111exit 0112113114