1#!/usr/bin/perl
2# Copyright (c) 2010 Sampo Kellomaki (sampo@iki.fi), All Rights Reserved.
3# This is confidential unpublished proprietary source code of the author.
4# NO WARRANTY, not even implied warranties. Contains trade secrets.
5# Distribution prohibited unless authorized in writing.
6# Licensed under Apache License 2.0, see file COPYING.
7# $Id$
8#
9# 17.9.2010, created --Sampo
10#
11# Commandline for importing .htpasswd file to /var/zxid/idpuid
12
13$usage = <<USAGE;
14Commandline for importing .htpasswd file to /var/zxid/idpuid
15Usage: ./zximport-htpasswd.pl <.htpasswd
16USAGE
17    ;
18die $USAGE if $ARGV[0] =~ /^-[Hh?]/;
19
20#$dir = '/tmp/idpuid';
21$dir = '/var/zxid/idpuid';
22
23use Data::Dumper;
24
25sub writeall {
26    my ($f,$d) = @_;
27    open F, ">$f" or die "Cant write($f): $!";
28    binmode F;
29    flock F, 2;    # Exclusive
30    print F $d;
31    flock F, 8;
32    close F;
33}
34
35while ($line = <STDIN>) {
36    ($uid, $crypt) = split /:/, $line, 2;
37    chomp $crypt;
38    mkdir "$dir/$uid" or die "Cant mkdir $dir/$uid: $!";
39    mkdir "$dir/$uid/.bs" or die "Cant mkdir $dir/$uid/.bs: $!";
40    mkdir "$dir/$uid/.ykspent" or die "Cant mkdir $dir/$uid/.ykspent: $!";
41    writeall("$dir/$uid/.pw", '$c$'.$crypt);
42    writeall("$dir/$uid/.bs/.at", "cn: $uid (TAS3)\ntas3entitlement: member\n");
43}
44
45__END__
46