#!/usr/bin/env bash
# Provision an Ubuntu Samba AD member, or add shares on a member set up here.
set -Eeuo pipefail
umask 077
export LC_ALL=C

readonly smb_conf=/etc/samba/smb.conf
readonly nss_conf=/etc/nsswitch.conf
readonly kerberos_profile=/etc/samba/easysmb-krb5.conf
readonly marker='# Managed by easysmb.sh'

die() {
    printf 'easysmb: %s\n' "$*" >&2
    exit 1
}

ask() {
    read -r -p "$1" "$2" </dev/tty || die 'Input ended. Run this script from an interactive terminal.'
}

dns_name() {
    local label='[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?'
    [[ $1 =~ ^$label(\.$label)*$ && ${#1} -le 253 ]]
}

replace_file() {
    local source=$1 target=$2
    pending_file=$(mktemp -- "${target}.easysmb.XXXXXXXX")
    cat -- "$source" > "$pending_file"
    if [[ -f $target ]]; then
        chown --reference="$target" "$pending_file"
        chmod --reference="$target" "$pending_file"
    else
        chown root:root "$pending_file"
        chmod 0644 "$pending_file"
    fi
    mv -fT -- "$pending_file" "$target"
    pending_file=''
}

backup_file() {
    local backup
    backup=$(mktemp -- "$1.easysmb-backup.XXXXXXXX")
    cp --preserve=mode,ownership,timestamps -- "$1" "$backup"
    printf 'Saved configuration backup at %s\n' "$backup"
}

smb_parameter() {
    testparm -s --section-name="$1" --parameter-name="$2" "$3" 2>/dev/null
}

check_smb_config() {
    testparm -s "$1" >/dev/null || die 'Samba rejected the proposed configuration.'
}

check_existing_config() {
    if [[ -L $smb_conf || ( -e $smb_conf && ! -f $smb_conf ) ]]; then
        die "$smb_conf must be a regular file if present."
    fi
    if [[ -e $smb_conf ]] && ! managed_config &&
        ! cmp -s -- "$smb_conf" /usr/share/samba/smb.conf; then
        die "$smb_conf already has a custom configuration. Use an unconfigured Samba installation or one previously set up by easysmb.sh."
    fi
}

managed_config() {
    [[ -f $smb_conf ]] && grep -Fxq -- "$marker" "$smb_conf"
}

configure_nss() {
    # An action belongs to the preceding provider. Keep that pair together
    # when placing winbind before a provider that can return on a failed lookup.
    awk '
        /^[[:space:]]*(passwd|group)[[:space:]]*:/ {
            original = $0
            match($0, /^[^:]*:/)
            prefix = substr($0, 1, RLENGTH)
            body = substr($0, RLENGTH + 1)
            comment = ""
            if (match(body, /[[:space:]]*#.*/)) {
                comment = substr(body, RSTART)
                body = substr(body, 1, RSTART - 1)
            }
            count = first_return = winbind_at = 0
            duplicate = 0
            for (i in provider) delete provider[i]
            while (match(body, /^[[:space:]]*[^[:space:]\[\]]+/)) {
                service = substr(body, 1, RLENGTH)
                body = substr(body, RLENGTH + 1)
                sub(/^[[:space:]]+/, "", service)
                provider[++count] = service
                while (match(body, /^[[:space:]]*\[[^]]*\]/)) {
                    action = substr(body, 1, RLENGTH)
                    body = substr(body, RLENGTH + 1)
                    sub(/^[[:space:]]*/, "", action)
                    provider[count] = provider[count] " " action
                    # SUCCESS on its own will only stop an already-completed lookup.
                    action = toupper(action)
                    gsub(/[[:space:]]*=[[:space:]]*/, "=", action)
                    if (!first_return && service != "winbind" &&
                        action ~ /(^|[[:space:]\[])(NOTFOUND|UNAVAIL|TRYAGAIN|![A-Z]+)=RETURN([[:space:]\]]|$)/) {
                        first_return = count
                    }
                }
                if (service == "winbind") {
                    if (winbind_at) {
                        duplicate = 1
                        provider[count] = ""
                    } else {
                        winbind_at = count
                    }
                }
            }
            if (body !~ /^[[:space:]]*$/) {
                print "easysmb: cannot parse NSS line: " original > "/dev/stderr"
                exit 1
            }
            if (winbind_at && !duplicate && (!first_return || winbind_at < first_return)) {
                print original
                next
            }
            destination = first_return ? first_return : count + 1
            if (winbind_at && (!first_return || winbind_at < first_return)) destination = winbind_at
            entry = winbind_at ? provider[winbind_at] : "winbind"
            line = prefix
            for (i = 1; i <= count + 1; ++i) {
                if (i == destination) line = line " " entry
                if (i != winbind_at && provider[i] != "") line = line " " provider[i]
            }
            print line (comment ~ /^#/ ? " " : "") comment
            next
        }
        {print}
    ' "$nss_conf" > "$workdir/nsswitch.conf" || die 'Could not update NSS safely.'
    if ! cmp -s -- "$nss_conf" "$workdir/nsswitch.conf"; then
        backup_file "$nss_conf"
        replace_file "$workdir/nsswitch.conf" "$nss_conf"
    fi
}

cleanup() {
    [[ -z $probe_file ]] || rm -f -- "$probe_file"
    [[ -z $pending_file ]] || rm -f -- "$pending_file"
    rm -rf -- "$workdir"
}

read_ad_username() {
    local -n result=$2
    local join_user user_domain
    ask "$1" join_user
    if [[ $join_user == *\\* ]]; then
        [[ -n ${workgroup:-} ]] || die 'For a Kerberos check, enter a bare username or a UPN.'
        user_domain=${join_user%%\\*}
        [[ ${user_domain^^} == "$workgroup" ]] || die "Use an account from $workgroup."
        join_user=${join_user#*\\}
    elif [[ $join_user == *@* ]]; then
        user_domain=${join_user#*@}
        [[ ${user_domain,,} == "$domain" ]] || die "Use a username or UPN from $domain."
        join_user=${join_user%@*}
    fi
    [[ -n $join_user && $join_user != -* && ! $join_user =~ [[:cntrl:]@%\\/] ]] ||
        die 'Enter a valid AD username.'
    result=$join_user
}

configure_kerberos() {
    cat > "$workdir/krb5.conf" <<EOF
$marker
[libdefaults]
    default_realm = $realm
    dns_lookup_kdc = false
    rdns = false
    dns_canonicalize_hostname = false
[realms]
    $realm = {
        kdc = $dc
    }
[domain_realm]
    $domain = $realm
    .$domain = $realm
EOF
    export KRB5_CONFIG="$workdir/krb5.conf"
    export KRB5CCNAME="FILE:$workdir/krb5cc"
}

net_with_admin() {
    # Let Samba prompt directly so it can manage credentials across negotiation.
    env -u PASSWD -u PASSWD_FD -u PASSWD_FILE -u USER -u LOGNAME net \
        --option='client ipc signing=mandatory' -U "$workgroup\\$ad_username" \
        "$@" </dev/tty
}

discover_domain() {
    local lookup found_domain
    printf '[global]\n    realm = %s\n    security = ADS\n' "$realm" > "$workdir/discovery.conf"
    lookup=$(net -s "$workdir/discovery.conf" -S "$dc" ads lookup) ||
        die "AD discovery failed against $dc. Check AD DNS and LDAP connectivity."
    found_domain=$(awk -F ': ' '$1 == "Domain" {print $2; exit}' <<< "$lookup")
    workgroup=$(awk -F ': ' '$1 == "Pre-Win2k Domain" {print $2; exit}' <<< "$lookup")
    [[ ${found_domain,,} == "$domain" ]] || die "$dc reported AD domain '$found_domain' instead of '$domain'."
    [[ $workgroup =~ ^[A-Za-z0-9_-]{1,15}$ ]] || die 'Could not determine a valid AD NetBIOS domain name.'
    workgroup=${workgroup^^}
    printf '    workgroup = %s\n' "$workgroup" >> "$workdir/discovery.conf"
}

machine_trust_is_valid() {
    net -S "$dc" ads testjoin ||
        net -S "$dc" --option='client ipc signing=mandatory' rpc testjoin
}

kerberos_login() {
    local principal_user
    read_ad_username "$1" principal_user
    configure_kerberos
    printf 'Requesting a Kerberos ticket for %s from %s.\n' "$principal_user@$realm" "$dc"
    if kinit "$principal_user@$realm" </dev/tty 2>"$workdir/kinit.stderr"; then
        cat "$workdir/kinit.stderr" >&2
        return
    fi
    cat "$workdir/kinit.stderr" >&2
    if grep -Eqi 'KDC has no support for encryption type|KDC_ERR_ETYPE_NO(T)?SUPP' "$workdir/kinit.stderr"; then
        die "$dc could not issue a ticket with a compatible encryption type. To test the authentication used by the installer, run ./easysmb.sh --check-ad-auth."
    fi
    die "Kerberos ticket request failed against $dc. See the kinit error above."
}

if [[ ${1:-} == -h || ${1:-} == --help ]]; then
    cat <<'HELP'
Usage: sudo ./easysmb.sh
       ./easysmb.sh --check-ad-auth
       ./easysmb.sh --check-kerberos

--check-ad-auth tests Samba authentication to AD with a read-only LDAP query.
--check-kerberos requests a ticket from the selected DC and shows its encryption
types. It requires kinit and klist and makes no system configuration changes.

Run on a systemd-based Ubuntu server that uses AD DNS and has synchronized time.
Use an unconfigured Samba server or rerun on a server set up by this script.
Have an AD Domain Admin account and a trusted AD security group ready.
The chosen group is granted share Full Control and Samba's per-share root access.
Existing share permissions are preserved on reruns. New shares start admin-only.
Use local share storage that supports Samba's security.NTACL extended attribute.
Use a parent directory that intended SMB users can traverse under Linux ACLs.
For manual Kerberos commands, the script prints the path to an AD-only profile.
HELP
    exit 0
fi

mode=install
case "${1:-}" in
    '') [[ $# -eq 0 ]] || die 'Run with no arguments or use --help.' ;;
    --check-ad-auth|--check-kerberos)
        [[ $# -eq 1 ]] || die "Use $1 without other arguments."
        mode=$1
        ;;
    *) die 'Run with no arguments, --check-ad-auth, --check-kerberos, or --help.' ;;
esac
[[ -t 0 && -t 2 ]] || die 'An interactive terminal is required.'
if [[ $mode != install ]]; then
    workdir=$(mktemp -d -- "${TMPDIR:-/tmp}/easysmb.XXXXXXXX")
else
    [[ $EUID -eq 0 ]] || die 'Run from Ubuntu with sudo ./easysmb.sh.'
    [[ -r /etc/os-release ]] || die 'Cannot identify this Linux distribution.'
    # shellcheck source=/dev/null
    . /etc/os-release
    [[ ${ID:-} == ubuntu ]] || die 'This installer is for Ubuntu.'
    [[ -d /run/systemd/system ]] || die 'This installer requires a running systemd.'
    [[ ! -L $nss_conf && -f $nss_conf ]] || die "Expected a regular $nss_conf file."
    exec 9>/run/lock/easysmb.lock
    flock -n 9 || die 'Another easysmb.sh run is in progress.'
    check_existing_config

    workdir=$(mktemp -d /run/easysmb.XXXXXXXX)
fi
pending_file=''
probe_file=''
trap cleanup EXIT
trap 'exit 130' INT
trap 'exit 143' TERM
trap 'printf "easysmb: setup stopped at line %s. Resolve the error and rerun the script.\n" "$LINENO" >&2' ERR

ask 'AD DNS domain (e.g. corp.example.com): ' domain
domain=${domain%.}
domain=${domain,,}
dns_name "$domain" && [[ $domain == *.* ]] || die 'Enter the full AD DNS domain name.'
realm=${domain^^}

ask 'Domain controller (short name or FQDN): ' dc
dc=${dc%.}
[[ $dc == *.* ]] || dc="$dc.$domain"
dns_name "$dc" || die 'Enter a valid domain controller hostname.'
getent ahosts "$dc" >/dev/null || die "Cannot resolve $dc. Check the hostname and the server's AD DNS settings."

case $mode in
    --check-ad-auth)
        command -v net >/dev/null || die 'The AD authentication check requires net from samba-common-bin.'
        discover_domain
        configure_kerberos
        read_ad_username 'AD username: ' ad_username
        domain_dn="DC=${domain//./,DC=}"
        net_with_admin -s "$workdir/discovery.conf" -S "$dc" ads dn "$domain_dn" distinguishedName ||
            die "Samba could not complete the authenticated LDAP query to $dc. See the error above."
        printf 'Samba completed the authenticated LDAP query to %s.\n' "$dc"
        exit 0
        ;;
    --check-kerberos)
        command -v kinit >/dev/null && command -v klist >/dev/null ||
            die 'The Kerberos check requires kinit and klist from krb5-user.'
        kerberos_login 'AD username (bare name or UPN): '
        klist -e
        exit 0
        ;;
esac

host=$(hostname -s)
[[ $host =~ ^[A-Za-z0-9]([A-Za-z0-9-]{0,13}[A-Za-z0-9])?$ && ! $host =~ ^[0-9]+$ ]] ||
    die 'Set a valid, unique Ubuntu hostname of 1–15 characters before joining AD.'
server_fqdn="${host,,}.$domain"

ask 'AD group to give Full Control [Domain Admins]: ' group_input
group_input=${group_input:-Domain Admins}
[[ ! $group_input =~ [[:cntrl:]] && $group_input != *'"'* &&
   $group_input != *'%'* && $group_input != *','* ]] ||
    die 'Enter an AD group name without control characters, quotes, percent signs, or commas.'

declare -a names=() paths=()
declare -A requested_names=()
printf '\nEnter one absolute Linux directory per share. Press Enter on an empty line to finish.\n'
while :; do
    ask 'Directory to share: ' path
    [[ -n $path ]] || break
    if [[ $path != /* || $path =~ [[:cntrl:]%\\] ]]; then
        printf 'Use an absolute path without control characters, percent signs, or backslashes.\n' >&2
        continue
    fi
    if ! path=$(realpath -m -- "$path") ||
        [[ $path == / || $path == *[[:space:]] || $path =~ [[:cntrl:]%\\] ]]; then
        printf 'Use a path below / whose resolved name can be represented in smb.conf.\n' >&2
        continue
    fi
    if [[ -e $path && ! -d $path ]]; then
        printf 'That path exists and is not a directory.\n' >&2
        continue
    fi
    default_name=${path##*/}
    while :; do
        ask "Windows share name [$default_name]: " name
        name=${name:-$default_name}
        key=${name,,}
        if [[ ! $name =~ ^[A-Za-z0-9_][A-Za-z0-9_.\ \$-]{0,79}$ ||
              $name == *[.\ ] || $key =~ ^(global|homes|printers|ipc\$|admin\$)$ ]]; then
            printf 'Use a nonreserved share name with letters, numbers, spaces, underscores, hyphens, periods, or dollar signs.\n' >&2
        elif [[ -n ${requested_names[$key]+yes} ]]; then
            printf 'That share name has already been entered.\n' >&2
        else
            break
        fi
    done
    requested_names["$key"]=1
    names+=("$name")
    paths+=("$path")
done
(( ${#names[@]} > 0 )) || die 'Enter at least one directory to share.'

printf '\nInstalling Samba, Winbind, and Kerberos packages with apt-get.\n'
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
    samba samba-common-bin samba-vfs-modules winbind libnss-winbind krb5-user attr
check_existing_config

# Discover the NetBIOS name instead of guessing it from the DNS domain.
discover_domain
[[ ${host^^} != "$workgroup" ]] || die 'The server hostname must differ from the AD NetBIOS domain name.'

if [[ $group_input == *\\* ]]; then
    group_domain=${group_input%%\\*}
    [[ ${group_domain^^} == "$workgroup" ]] || die "Specify a group from $workgroup."
    group_input=${group_input#*\\}
fi
[[ -n $group_input && $group_input != *\\* ]] || die 'Enter an AD group name or NETBIOS\Group.'
admin_group="$workgroup\\$group_input"

if managed_config; then
    configured_realm=$(smb_parameter global realm "$smb_conf")
    configured_role=$(smb_parameter global 'server role' "$smb_conf")
    configured_workgroup=$(smb_parameter global workgroup "$smb_conf")
    configured_host=$(smb_parameter global 'netbios name' "$smb_conf")
    [[ ${configured_realm^^} == "$realm" && $configured_role == 'member server' &&
       ${configured_workgroup^^} == "$workgroup" && ${configured_host^^} == "${host^^}" ]] ||
        die 'The current Samba configuration belongs to a different domain, hostname, or server role.'
    cp -- "$smb_conf" "$workdir/base.conf"
else
    cat > "$workdir/base.conf" <<EOF
$marker
[global]
    server role = member server
    security = ADS
    workgroup = $workgroup
    realm = $realm
    netbios name = ${host^^}

    idmap config * : backend = tdb
    idmap config * : range = 10000-99999
    idmap config $workgroup : backend = rid
    # Upper bound is the maximum 31-bit AD RID plus the lower bound.
    idmap config $workgroup : range = 1000000-2148483647
    winbind use default domain = no

    server min protocol = SMB2_02
    smb ports = 445
    map to guest = Never
    load printers = no
    disable spoolss = yes
    usershare max shares = 0
EOF
fi
check_smb_config "$workdir/base.conf"
cp -- "$workdir/base.conf" "$workdir/proposed.conf"

declare -a new_indices=()
config_dump=$(testparm -s "$workdir/base.conf" 2>/dev/null)
for i in "${!names[@]}"; do
    name=${names[i]}
    path=${paths[i]}
    if [[ $'\n'${config_dump,,}$'\n' == *$'\n'"[${name,,}]"$'\n'* ]]; then
        current_path=$(smb_parameter "$name" path "$workdir/base.conf")
        [[ $current_path == "$path" ]] || die "Share '$name' is already assigned to '$current_path'."
        printf 'Keeping existing share %s and its permissions.\n' "$name"
        continue
    fi
    new_indices+=("$i")
    cat >> "$workdir/proposed.conf" <<EOF

[$name]
    path = $path
    read only = no
    guest ok = no
    follow symlinks = no
    wide links = no
    admin users = "@$admin_group"
    vfs objects = acl_xattr
    acl_xattr:ignore system acls = no
    map acl inherit = yes
    store dos attributes = yes
EOF
done
check_smb_config "$workdir/proposed.conf"
for i in "${new_indices[@]}"; do
    parsed_path=$(smb_parameter "${names[i]}" path "$workdir/proposed.conf")
    [[ $parsed_path == "${paths[i]}" ]] || die "Samba could not represent the path '${paths[i]}'."
done

configure_kerberos
read_ad_username 'AD Domain Admin username (e.g. Administrator): ' ad_username

# Write the base member config before joining so a retry can reuse the trust.
member_changed=false
if ! managed_config; then
    if [[ -f $smb_conf ]]; then
        backup_file "$smb_conf"
    fi
    replace_file "$workdir/base.conf" "$smb_conf"
    member_changed=true
fi
if ! machine_trust_is_valid; then
    printf '\nJoining %s using %s.\n' "$domain" "$dc"
    net_with_admin -S "$dc" ads join "dnshostname=$server_fqdn" ||
        die "Samba could not join $domain through $dc. See the join error above."
    machine_trust_is_valid || die 'The new machine trust could not be verified.'
    member_changed=true
fi

configure_nss

systemctl enable winbind.service smbd.service
if [[ $member_changed == true ]]; then
    systemctl restart winbind.service
    systemctl restart smbd.service
else
    systemctl start winbind.service smbd.service
fi
if ! wbinfo -t; then
    systemctl restart winbind.service
    wbinfo -t || die 'Winbind could not verify the AD trust.'
fi
group_info=$(wbinfo --name-to-sid="$admin_group") || die "Cannot resolve AD group '$admin_group'."
read -r group_sid group_type <<< "$group_info"
# Winbind normally returns a SID followed by a label and a numeric type,
# such as "SID_DOM_GROUP (2)". Also accept a bare numeric type.
if [[ $group_type =~ ^[[:alnum:]_]+[[:space:]]+\(([0-9]+)\)[[:space:]]*$ ]]; then
    group_type=${BASH_REMATCH[1]}
fi
[[ $group_sid =~ ^S-1-5(-[0-9]+)+$ && $group_type =~ ^(2|4)$ ]] ||
    die "'$admin_group' did not resolve to an AD group. Winbind returned: $group_info"
group_gid=$(wbinfo --sid-to-gid="$group_sid") || die "Cannot map AD group '$admin_group' to a Linux GID."
group_entry=$(getent group "$admin_group") || die "NSS could not look up '$admin_group' through $nss_conf."
IFS=: read -r _ _ nss_gid _ <<< "$group_entry"
[[ $nss_gid == "$group_gid" ]] || die "NSS returned an unexpected GID for '$admin_group'."
printf 'Verified AD group %s (GID %s).\n' "$admin_group" "$group_gid"

printf '\nGranting Windows share-management rights to %s on this Samba server.\n' "$admin_group"
net_with_admin -S "$server_fqdn" -I 127.0.0.1 \
    rpc rights grant "$admin_group" SeDiskOperatorPrivilege ||
    die "Could not grant SeDiskOperatorPrivilege on $server_fqdn. Check the local Samba RPC error and the account's administrative rights."

for path in "${paths[@]}"; do
    [[ $(realpath -m -- "$path") == "$path" ]] || die "The resolved path changed during setup: $path"
    if [[ -d $path ]]; then
        mode=$(stat -c %a -- "$path")
        if (( (8#$mode & 0077) != 0 )); then
            printf 'Existing directory %s has mode %s. Its Linux permissions are being preserved.\n' "$path" "$mode"
        fi
    else
        (umask 022; mkdir -p -m 0700 -- "$path")
    fi
    parent=${path%/*}
    while [[ -n $parent ]]; do
        mode=$(stat -c %a -- "$parent")
        if (( (8#$mode & 0001) == 0 )); then
            printf 'easysmb: %s has no search bit for other users. SMB users need Linux search access to this ancestor of %s through their owner, group, or ACL permissions.\n' "$parent" "$path" >&2
            break
        fi
        parent=${parent%/*}
    done
    probe_file=$(mktemp -- "$path/.easysmb-acl.XXXXXXXX")
    setfattr -n security.NTACL -v 0x00 -- "$probe_file" ||
        die "The filesystem at '$path' does not support Samba's security.NTACL attribute."
    rm -- "$probe_file"
    probe_file=''
done

# Share ACLs are stored separately from smb.conf. Seed them against the
# staged config before publishing it so a new share never starts as Everyone.
for i in "${new_indices[@]}"; do
    name=${names[i]}
    # sharesec prints ACL: before each ACE, but its input starts with the SID.
    sharesec "$name" --configfile="$workdir/proposed.conf" \
        --replace="$group_sid:ALLOWED/0/FULL" ||
        die "Could not set the initial share permissions for '$name'."
    share_acl=$(sharesec "$name" --configfile="$workdir/proposed.conf" --view)
    [[ $share_acl == *"ACL:$group_sid:ALLOWED/"* && $share_acl != *'ACL:S-1-1-0:'* ]] ||
        die "Could not verify the initial share permissions for '$name'."
done
if (( ${#new_indices[@]} )); then
    backup_file "$smb_conf"
    replace_file "$workdir/proposed.conf" "$smb_conf"
fi
smbcontrol smbd reload-config
systemctl is-active --quiet winbind.service
systemctl is-active --quiet smbd.service

# Retain the tested AD profile for manual use and keep the host-wide Kerberos
# defaults available to services and users that already rely on them.
if [[ -L $kerberos_profile || ( -e $kerberos_profile && ! -f $kerberos_profile ) ]] ||
    { [[ -f $kerberos_profile ]] && ! grep -Fxq -- "$marker" "$kerberos_profile"; }; then
    printf 'easysmb: Preserving the existing Kerberos profile at %s. For manual sign-in, verify it or use the system profile with AD DNS.\n' "$kerberos_profile" >&2
else
    if ! cmp -s -- "$workdir/krb5.conf" "$kerberos_profile"; then
        replace_file "$workdir/krb5.conf" "$kerberos_profile"
    fi
    printf '\nManual Kerberos sign-in: KRB5_CONFIG=%s kinit yourname@%s\n' "$kerberos_profile" "$realm"
fi

printf '\nReady. Windows share-management group: %s\n' "$admin_group"
for i in "${!names[@]}"; do
    printf '  \\\\%s\\%s  (%s)\n' "$server_fqdn" "${names[i]}" "${paths[i]}"
done
printf '\nOpen Computer Management > Connect to another computer > %s.\n' "$server_fqdn"
printf 'Go to Shared Folders > Shares > share Properties > Share Permissions.\n'
printf 'Use the Security tab on the share folder in File Explorer for file and folder ACLs.\n'
