0
|
1 #! /bin/sh -e |
|
2 |
|
3 # create a per-user whitelist target directory, password, and so forth. |
|
4 |
|
5 # This script creates the directories needed for per-addressee white |
|
6 # lists and log directories. It also runs htpasswd to create an entry |
|
7 # in the Apache password file for the userdirs directory. |
|
8 |
|
9 # The files and directories must be writable by both the httpd and dccm |
|
10 # processes. That is assumed to be arranged by having the processes share |
|
11 # a group such as "www" and using a umask of 007. |
|
12 # The dccm log directories and files should not be globally readable |
|
13 # to protect the privacy of mail. |
|
14 # If dccm is run by a "user" such as "dcc", you might be able to |
|
15 # use suEXEC. You might need to make a symbolic of ~dcc/public_html" |
|
16 # to ~dcc/userdirs. |
|
17 |
|
18 # The web "usernames" are related the per-user white list directory names |
|
19 # see in DCC log files. The white list and log directory in |
|
20 # "userdirs/local/xxx" is accessed with the user name "xxx". |
|
21 # "userdirs/esmtp/xxx@example.com" uses the user name "esmtp/xxx@example.com |
|
22 |
|
23 # One additional directory named @prefix@/userdirs/tmp is created for the |
|
24 # CGI scripts that manage the per-user white lists and logs. |
|
25 |
|
26 |
|
27 # Copyright (c) 2008 by Rhyolite Software, LLC |
|
28 # |
|
29 # This agreement is not applicable to any entity which sells anti-spam |
|
30 # solutions to others or provides an anti-spam solution as part of a |
|
31 # security solution sold to other entities, or to a private network |
|
32 # which employs the DCC or uses data provided by operation of the DCC |
|
33 # but does not provide corresponding data to other users. |
|
34 # |
|
35 # Permission to use, copy, modify, and distribute this software without |
|
36 # changes for any purpose with or without fee is hereby granted, provided |
|
37 # that the above copyright notice and this permission notice appear in all |
|
38 # copies and any distributed versions or copies are either unchanged |
|
39 # or not called anything similar to "DCC" or "Distributed Checksum |
|
40 # Clearinghouse". |
|
41 # |
|
42 # Parties not eligible to receive a license under this agreement can |
|
43 # obtain a commercial license to use DCC by contacting Rhyolite Software |
|
44 # at sales@rhyolite.com. |
|
45 # |
|
46 # A commercial license would be for Distributed Checksum and Reputation |
|
47 # Clearinghouse software. That software includes additional features. This |
|
48 # free license for Distributed ChecksumClearinghouse Software does not in any |
|
49 # way grant permision to use Distributed Checksum and Reputation Clearinghouse |
|
50 # software |
|
51 # |
|
52 # THE SOFTWARE IS PROVIDED "AS IS" AND RHYOLITE SOFTWARE, LLC DISCLAIMS ALL |
|
53 # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES |
|
54 # OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL RHYOLITE SOFTWARE, LLC |
|
55 # BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES |
|
56 # OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, |
|
57 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, |
|
58 # ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS |
|
59 # SOFTWARE. |
|
60 # Rhyolite Software DCC 1.3.103-1.11 $Revision$ |
|
61 # @configure_input@ |
|
62 |
|
63 |
|
64 exec 1>&2 </dev/null |
|
65 |
|
66 # Since the CGI scripts cannot accept args and so must rely on the |
|
67 # DCC parameter file in the built-in homedir, do the same here. |
|
68 DCC_HOMEDIR=@prefix@ |
|
69 . $DCC_HOMEDIR/dcc_conf |
|
70 |
|
71 USAGE="`basename $0`: [-x] [-p htpasswd-pgm] [-g group] [-P whitelist-prototype] username" |
|
72 HTPASSWD=@HTPASSWD@ |
|
73 GROUP=www |
|
74 while getopts "xp:g:P:" c; do |
|
75 case $c in |
|
76 x) set -x;; |
|
77 p) HTPASSWD=$OPTARG;; |
|
78 g) GROUP="$OPTARG";; #GID shared with httpd |
|
79 P) PROTO="$OPTARG";; |
|
80 *) echo "$USAGE" 1>&2; exit 1;; |
|
81 esac |
|
82 done |
|
83 shift `expr $OPTIND - 1 || true` |
|
84 if test "$#" -ne 1 -o -z "$1"; then |
|
85 echo "$USAGE" 1>&2 |
|
86 exit 1 |
|
87 fi |
|
88 USER=$1 |
|
89 |
|
90 if test -z "$DCCM_USERDIRS"; then |
|
91 cat <<EOF 1>&2 |
|
92 Per-user white lists require DCCM_USERDIRS defined in$DCC_HOMEDIR/dcc_conf. |
|
93 Please consider installing a new version of dcc_conf. |
|
94 EOF |
|
95 exit 1 |
|
96 fi |
|
97 |
|
98 if test ! -r $DCC_HOMEDIR/ids; then |
|
99 if test -n "$DCCUID"; then |
|
100 echo "`basename $0: must be run by root or $DCCUID" 1>&2 |
|
101 else |
|
102 echo "`basename $0: must be run by root" 1>&2 |
|
103 fi |
|
104 exit 1 |
|
105 fi |
|
106 |
|
107 |
|
108 USERDIRS=$DCC_HOMEDIR/$DCCM_USERDIRS |
|
109 WEBUSERS=$USERDIRS/webusers |
|
110 TMP_DIR=$USERDIRS/tmp |
|
111 USER=`expr "$USER" : "$DCCM_USERDIRS/\(.*\)" \| "$USER"` |
|
112 LOCAL_DIR=`expr "$USER" : '\(..*\)/..*' || true` |
|
113 if test -z "$LOCAL_DIR"; then |
|
114 LOCAL_DIR="$USERDIRS/local" |
|
115 PER_USER="$USERDIRS/local/$USER" |
|
116 else |
|
117 USER=`expr "$USER" : 'local/\(.*\)' \| "$USER"` |
|
118 LOCAL_DIR="$USERDIRS/$LOCAL_DIR" |
|
119 PER_USER="$USERDIRS/$USER" |
|
120 fi |
|
121 |
|
122 # create the directories |
|
123 # (some systems don't have `mkdir -p`) |
|
124 for nm in "$USERDIRS" "$TMP_DIR" "$LOCAL_DIR" "$PER_USER" "$PER_USER/log"; do |
|
125 if test ! -d "$nm"; then |
|
126 mkdir "$nm" |
|
127 fi |
|
128 done |
|
129 |
|
130 # create the initial whiteclnt file |
|
131 # copy the prototype |
|
132 if test ! -s $PER_USER/whiteclnt; then |
|
133 date "+# white list for $USER%n#%n#%n#webuser created %x %X %Z%n" \ |
|
134 > "$PER_USER/whiteclnt" |
|
135 if test "$PROTO" != ""; then |
|
136 cat "$PROTO" >> "$PER_USER/whiteclnt" |
|
137 fi |
|
138 fi |
|
139 |
|
140 # Add the username and password to the htpasswd file |
|
141 # Create the htpasswd file for the first user. |
|
142 if test ! -f $WEBUSERS; then |
|
143 $HTPASSWD -c $WEBUSERS "$USER" |
|
144 else |
|
145 $HTPASSWD $WEBUSERS "$USER" |
|
146 fi |
|
147 |
|
148 # set permissions of existing files and directories in case they're wrong |
|
149 chgrp $GROUP "$USERDIRS" "$TMP_DIR" "$PER_USER" "$PER_USER/log" |
|
150 chgrp $GROUP "$PER_USER/whiteclnt" $WEBUSERS |
|
151 if test -n "$DCCUID"; then |
|
152 chown $DCCUID $WEBUSERS "$USERDIRS" "$TMP_DIR" "$LOCAL_DIR" |
|
153 chown $DCCUID "$PER_USER" "$PER_USER/log" "$PER_USER/whiteclnt" |
|
154 fi |
|
155 chmod g=rwx "$USERDIRS" "$TMP_DIR" "$PER_USER" "$PER_USER/log" |
|
156 chmod g=rw "$PER_USER/whiteclnt" $WEBUSERS |
|
157 chmod o= "$PER_USER/log" $WEBUSERS |