0,0 → 1,90 |
#!/bin/sh |
|
# |
# HostAdmiral backend. Executed with ROOT privileges |
# |
# The script must ensure the specified new maildir exists and |
# has correct structure. If old mailbox found it must be moved |
# to new one. In any case the new maildir has specified owner |
# |
# Params: |
# maildir_owner_uid (e.g. 1001) |
# old_maildir (e.g. example.com/john) |
# new_maildir (e.g. domain.net/merry) |
# |
# if old_maildir should not exist first param is equal to the second one |
# |
# Return: |
# 0 - nothing done, all OK |
# 1 - empty maildir created |
# 2 - old maildir moved or owner changed |
# 3 - wrong params |
# 4 - some error |
# 5 - error from system |
# |
|
### config ################################################ |
|
ROOT=/var/spool/mail |
DEFAULT_OWNER=202 |
|
### validate params ####################################### |
|
if [ -z "$3" -o -n "$4" ] ; then echo "Wrong params 1"; exit 3; fi |
|
OWNER="$1" |
if [ -z "${OWNER}" ] ; then |
OWNER=${DEFAULT_OWNER} |
elif [ ! "${OWNER}" -ge 1000 ] ; then |
echo "Wrong params 2"; exit 3 |
fi |
|
OLD="/$2/" |
echo "$OLD" | awk '$0 ~ "//" || $0 ~ "/\\./" || $0 ~ "/\\.\\./" || $0 !~ "^/(([a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)\\.)*([a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)/[a-zA-Z]([a-zA-Z0-9._-]*[a-zA-Z0-9])?/$" {exit 1} {exit 0}' |
if [ $? -ne 0 ]; then |
echo "Wrong params 3"; exit 3 |
fi |
|
NEW="/$3/" |
echo "$NEW" | awk '$0 ~ "//" || $0 ~ "/\\./" || $0 ~ "/\\.\\./" || $0 !~ "^/(([a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)\\.)*([a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)/[a-zA-Z]([a-zA-Z0-9._-]*[a-zA-Z0-9])?/$" {exit 1} {exit 0}' |
if [ $? -ne 0 ]; then |
echo "Wrong params 4"; exit 3 |
fi |
|
### work ################################################## |
|
if [ -d "${ROOT}${NEW}" ] ; then |
# the new maildir exists and is the same as old one - do nothing |
if [ "$OLD" = "$NEW" ] ; then |
WRONG_OWNER=`find "${ROOT}${NEW}" -not -user "${OWNER}"` |
if [ -z "$WRONG_OWNER" ] ; then |
exit 0; # correct owner |
else |
chown -R "${OWNER}" "${ROOT}${NEW}" || { echo "Cannot change owner"; exit 5; } |
exit 2; |
fi |
fi |
|
# the new maildir exists and differs from old one - error |
exit 4; |
else |
# the new maildir doesn't exist and is the same as old one or the old one doesn't exist |
# - create an empty |
if [ "$OLD" = "$NEW" -o ! -d "${ROOT}${OLD}" ] ; then |
mkdir -p "${ROOT}${NEW}cur" "${ROOT}${NEW}new" "${ROOT}${NEW}tmp" \ |
|| { echo "Cannot create maildir"; exit 5; } |
chmod 700 "${ROOT}${NEW}" || { echo "Cannot change mod"; exit 5; } |
chown -R "${OWNER}" "${ROOT}${NEW}" || { echo "Cannot change owner"; exit 5; } |
chown -R "${DEFAULT_OWNER}" `dirname "${ROOT}${NEW}"` || { echo "Cannot change owner"; exit 5; } |
exit 1; |
fi |
|
# the new maildir doesn't exist, differs from old one and the old one exists |
# - move it |
mkdir -p `dirname "${ROOT}${NEW}"` |
chown -R "${DEFAULT_OWNER}" `dirname "${ROOT}${NEW}"` || { echo "Cannot change owner"; exit 5; } |
mv "${ROOT}${OLD}" "${ROOT}${NEW}" || { echo "Cannot move maildir"; exit 5; } |
chown -R "${OWNER}" "${ROOT}${NEW}" || { echo "Cannot change owner"; exit 5; } |
exit 2; |
fi |
|
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |