-
Notifications
You must be signed in to change notification settings - Fork 0
/
kolab_fix_acl
executable file
·78 lines (65 loc) · 2.78 KB
/
kolab_fix_acl
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env bash
################################################################################
##
## Fix user mailbox self-access ACLs
##
## Copyright (C) 2015-2024 Michael Roland <[email protected]>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <https://www.gnu.org/licenses/>.
##
################################################################################
SCRIPT_NAME=$(basename $0)
SCRIPT_PATH=$(readlink -f "$(dirname $0)")
. "$SCRIPT_PATH/kolab_config_loader"
usage() {
echo "Usage: ${SCRIPT_NAME} [options]"
echo "Fix user mailbox self-access ACLs"
echo ""
echo -e "Options:"
echo -e "\t-h Show this message"
echo ""
echo "Copyright (c) 2015-2024 Michael Roland <[email protected]>"
echo "License GPLv3+: GNU GPL version 3 or later <https://www.gnu.org/licenses/>"
echo ""
echo "This is free software: you can redistribute and/or modify it under the"
echo "terms of the GPLv3+. There is NO WARRANTY; not even the implied warranty"
echo "of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
echo ""
}
while getopts ":h?:" opt; do
case "$opt" in
h|\?)
if [ ! -z $OPTARG ] ; then
echo "${SCRIPT_NAME}: invalid option -- $OPTARG" >&2
fi
usage
exit 1
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
echo "Scanning mailboxes, adding self-access permissions if missing ..."
userprefix="${IMAP_NAMESPACE_USER}${IMAP_HIERARCHY_SEP}"
for mailbox in $(${KOLAB_CMD}list-mailboxes "$userprefix%") ; do
username=$(echo "$mailbox" | sed -n -E 's/^'"$IMAP_NAMESPACE_USER"'[\'"$IMAP_HIERARCHY_SEP"'](.*?)(@[^@]*)$/\1/p')
domain=$(echo "$mailbox" | sed -n -E 's/^'"$IMAP_NAMESPACE_USER"'[\'"$IMAP_HIERARCHY_SEP"'](.*?)(@[^@]*)$/\2/p')
if [ $(${KOLAB_CMD}user-info "$username$domain" | head -c1 | wc -c) -gt 0 ] ; then
# user exists, try to fix permissions
echo "Updating self-access ACL for user $username$domain on $userprefix$username$domain ..."
${KOLAB_CMD}set-mailbox-acl "$userprefix$username$domain" "$username$domain" "${IMAP_PERMISSIONS_SELF}"
${KOLAB_CMD}set-mailbox-acl "$userprefix$username${IMAP_HIERARCHY_SEP}*$domain" "$username$domain" "${IMAP_PERMISSIONS_SELF}"
fi
done
echo "Done."