Set the userdb path to be /etc/courier/userdb.
[hcoop/debian/courier-authlib.git] / makedat / makedat.in
1 #! @SHELL@
2 #
3 # $Id: makedat.in,v 1.5 2004/05/09 17:47:04 mrsam Exp $
4 #
5 # Copyright 1998 - 2004 Double Precision, Inc. See COPYING for
6 # distribution information.
7 #
8 # Generic wrapper for makedat.
9 #
10 # Usage: makedat.sh -src=src -file=file -tmp=tmpfile -hup=hupfile [ -cidr ]
11 #
12 # Create [file] from [src]. [src] can be either a plain text file, or a
13 # directory. [tmpfile] is used. if [hupfile] is specified and it exists,
14 # this file contains a PID, which is SIGHUPed.
15 #
16 # -cidr - [src] contains a list of IP netblocks. Expand entries in [src]
17 # that use CIDR or start-end notation using the Net::CIDR Perl
18 # module. Download the Net::CIDR module from
19 # http://www.cpan.org/authors/id/M/MR/MRSAM/
20
21 prefix="@prefix@";
22 exec_prefix="@exec_prefix@";
23
24 srcfile=""
25 dstfile=""
26 tmpfile=""
27 hupfile=""
28
29 usage() {
30 echo "Usage: $0 -src=src -file=file -tmp=tmpfile -hup=hupfile [-cidr]" >&2
31 exit 1
32 }
33
34 cidr=""
35
36 while test $# -gt 0
37 do
38 case $1 in
39 -cidr)
40 cidr=1
41 shift
42 ;;
43 -src=*)
44 srcfile=`echo "$1" | sed 's/-src=//'`;
45 shift
46 ;;
47 -tmp=*)
48 tmpfile=`echo "$1" | sed 's/-tmp=//'`;
49 shift
50 ;;
51 -file=*)
52 dstfile=`echo "$1" | sed 's/-file=//'`;
53 shift
54 ;;
55 -hup=*)
56 hupfile=`echo "$1" | sed 's/-hup=//'`;
57 shift
58 ;;
59 *)
60 usage
61 ;;
62 esac
63 done
64
65 if test "$dstfile" = ""
66 then
67 usage
68 fi
69
70 if test "$srcfile" = ""
71 then
72 usage
73 fi
74
75 if test "$tmpfile" = ""
76 then
77 usage
78 fi
79
80
81 get_access() {
82
83 if test -d "$srcfile"
84 then
85 if test "$srcfile" != "CVS"
86 then
87 for f in "$srcfile"/*
88 do
89 test -f $f || continue
90 cat "$f" || return
91 done
92 fi
93 else
94 cat "$srcfile" || return
95 fi
96 echo "."
97 }
98
99 docidr() {
100 if test "$cidr" = 1
101 then
102 @PERL@ -e '
103 eval "use Net::CIDR;";
104
105 while (<>)
106 {
107 unless ( $Net::CIDR::VERSION &&
108 /^([a-fA-F0-9:\.]+[\-\/][a-fA-F0-9:\.]+)\s+(.*)$/)
109 {
110 print;
111 next;
112 }
113
114 my ($net, $line)=($1, $2);
115
116 foreach ( Net::CIDR::cidr2octets(
117 Net::CIDR::range2cidr($net)))
118 {
119 print "$_\t$line\n";
120 }
121 }
122 '
123 else
124 @CAT@
125 fi
126 }
127
128 get_access | docidr | @makedatprogpath@ - "$tmpfile" "$dstfile" || exit 1
129
130 if test "$hupfile" != ""
131 then
132 if test -f $hupfile
133 then
134 kill -HUP `cat "$hupfile"`
135 fi
136 fi