File: convert-sha1.pl

package info (click to toggle)
apache2 2.4.64-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 59,104 kB
  • sloc: ansic: 211,971; python: 13,977; perl: 11,307; sh: 7,102; php: 1,315; javascript: 1,314; awk: 749; makefile: 712; lex: 374; yacc: 161; xml: 2
file content (36 lines) | stat: -rw-r--r-- 934 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/perl -w
use strict;

# This is public domain code.  Do whatever you want with it.
# It was originally included in Clinton Wong's Apache 1.3.6 SHA1/ldif
# patch distribution as sample code for converting accounts from
# ldif format (as used by Netscape web servers) to Apache password format.

my $uid='';
my $passwd='';

while (my $line = <>) {
  chomp $line;
  if ( $line =~ /uid:\s*(.+)/) { $uid = $1 }
  if ( $line =~ /userpassword:\s*(\{\w+\}.+)/) {
    $passwd = $1;
    $passwd =~ s/^\{crypt\}//i;  # Apache stores crypt without a magic string
  }

  if (length($line)==0) {

    if (length $uid and length $passwd) {
      print $uid, ':', $passwd, "\n";
    } # output if we have something to print

    $uid = '';
    $passwd = '';

  } # if newline
} # while something to read

# handle last entry if there isn't a newline before EOF
    if (length $uid and length $passwd) {
  print $uid, ':', $passwd, "\n";
}