3 # ----------------------------------------------------------------------
4 # AlternC - Web Hosting System
5 # Copyright (C) 2000-2016 by the AlternC Development Team.
7 # ----------------------------------------------------------------------
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License (GPL)
12 # as published by the Free Software Foundation; either version 2
13 # of the License, or (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # To read the license please visit http://www.gnu.org/copyleft/gpl.html
21 # ----------------------------------------------------------------------
22 # Original Author of file: Remi - 2016-04-27
23 # Purpose of file: Fixes permissions and ownerships of AlternC mailboxes
24 # ----------------------------------------------------------------------
30 Usage: `basename $0` [-c] [-n] [-l <login>] [-u <uid>] [-p <directory>] [-d <domain>]
32 Fixes rights of AlternC mailboxes
35 Compatibility mode: adapts rights for both pre 1.X and newer versions (using acl)
38 login of an AlternC account
41 uid of an AlternC account
44 path to a directory, if the path does not contain an underscore (_),
45 this is considered as a prefix.
48 fix mails belonging to a FQDN
51 dry run. Causes the program to show the modifications, without actually executing them.
54 shows this help message
63 if [ $DRY_RUN -eq 1 ]; then
70 query="select m.path, mem.uid from mailbox m join address a on m.address_id=a.id join domaines d on a.domain_id=d.id join membres mem on d.compte=mem.uid where delivery='dovecot'"
72 while getopts "hl:u:p:d:cn" optname
83 if [[ "$OPTARG" =~ ^[a-zA-Z0-9_]+$ ]]; then
84 query="$query and mem.login='$OPTARG'"
86 echo "error: \"$OPTARG\" is not a valid login" 1>&2
93 if [[ "$OPTARG" =~ ^[0-9]+$ ]]; then
94 query="$query and mem.uid='$OPTARG'"
96 echo "error: \"$OPTARG\" is not a valid uid" 1>&2
103 if [[ "$OPTARG" != *"'"* ]]; then
104 query="$query and d.domaine='$OPTARG'"
109 ## if path contains an underscore it's a full path, otherwise it's a prefix
110 if [ -d "$OPTARG" ]; then
111 if [[ $OPTARG == *"_"* ]]; then
112 query="$query and m.path='${OPTARG%/}'"
114 query="$query and m.path LIKE '$OPTARG%'"
117 echo "error: \"$OPTARG\" is not a valid directory" 1>&2
128 echo "Unkown option: $OPTARG" 1>&2
140 echo $query | mysql --defaults-file=/etc/alternc/my.cnf -N -B | while read path uid; do
141 echo "** Fixing $path ($uid)"
143 if [ $ACL -eq 1 ]; then
144 execute_cmd chown -R www-data.$uid $path
145 execute_cmd find $path -type d -exec chmod 2755 {} \\\;
146 execute_cmd setfacl -bknR -m d:u:$uid:rwx -m u:$uid:rwx -m d:o::--- -m o::---\
147 -m d:u:www-data:rwx -m u:www-data:rwx -m d:g:$uid:rwx -m g:$uid:rwx\
148 -m d:mask:rwx -m mask:rwx "$path"
150 execute_cmd chown -R $uid.vmail $path
151 execute_cmd find $path -type d -exec chmod 0700 {} \\\;