Script per impostare le permission delle share utenti in samba

From RVM Wiki
Revision as of 17:27, 26 February 2025 by Gabriele.vivinetto (talk | contribs)
Jump to navigation Jump to search

Windows setacl

  • Se si hanno le directory corrispondenti agli username, e si vogliono impostare le permission delle share:
\\fileserver.example.com\users
  user1
  user2
  user3
scriptname.cmd \\fileserver.example.com\users
  • disabilita l'ereditarietà, scartando le ACL ereditate
  • cancella tutte le acl esplicite
  • resetta tutti gli oggetti figli
  • Imposta l'owner ricorsivamente
  • imposta Full Control per lo user
  • imposta Full Control per Domain Admins
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION

cls

if "%~1"=="" (
    echo Devi specificare un percorso!
    exit /b
)

set "targetPath=%~1"

for /D %%d in ("%targetPath%\*") do (
    echo PATH: "%%d"
    REM echo USER: "%%~nxd"
    SET "DIR=%%~nxd
    echo DIR=!DIR!

echo Disable Inheritance ================================
SetACL.exe -on "\\metsrv03.ad.metrica.it\Utenti\!DIR!" ^
           -ot file ^
           -actn setprot -op "dacl:p_nc" ^
           -silent

echo Clearing ===========================================
SetACL.exe -on "\\metsrv03.ad.metrica.it\Utenti\!DIR!" ^
           -ot file ^
           -actn clear -clr "dacl" -rec cont_obj ^
           -silent

echo Resetting ==========================================
SetACL.exe -on "\\metsrv03.ad.metrica.it\Utenti\!DIR!" ^
           -ot file ^
           -actn rstchldrn -rst "dacl" -rec cont_obj ^
           -silent

echo SetOwner  ==========================================
SetACL.exe -on "\\metsrv03.ad.metrica.it\Utenti\!DIR!" ^
           -ot file ^
           -actn setowner -ownr "n:METRICA\!DIR!" ^
           -rec cont_obj ^
           -silent

echo Setting ============================================
SetACL.exe -on "\\metsrv03.ad.metrica.it\Utenti\!DIR!" ^
           -ot file -actn ace ^
           -ace "n:METRICA\!DIR!;p:full" ^
           -rec cont_obj ^
           -silent

SetACL.exe -on "\\metsrv03.ad.metrica.it\Utenti\!DIR!" ^
           -ot file -actn ace ^
           -ace "n:METRICA\Domain Admins;p:full" ^
           -rec cont_obj ^
           -silent



    pushd "%%d"
    popd
)

ENDLOCAL

Linux samba-tool

NON FUNZIONA

Se si hanno le directory corrispondenti agli username, e si vogliono impostare le permission delle share, usare:

#!/bin/bash
DOMAIN=EXAMPLE
REALM=ad.example.com
touch /tmp/errors.txt
rm -f errors.txt
for DIR in *
do 
	echo $DIR
	chown -R ${DOMAIN}\\${DIR}:${DOMAIN}\\Domain\ Users $DIR 2>&1 > /dev/null || echo "$DIR" >> /tmp/errors.txt
	samba-tool ntacl set "O:$(wbinfo --name-to-sid ${DIR}@a$REALM | cut -f 1 --delimiter=' ')G:DUD:(A;;0x001f01ff;;;$(wbinfo --name-to-sid ${DIR}@$REALM | cut -f 1 --delimiter=' '))(A;;;;;DU)(A;;;;;WD)(A;OICIIO;0x001f01ff;;;CO)(A;OICIIO;0x001200a9;;;CG)(A;OICIIO;0x001200a9;;;WD)" ./${DIR} 2>&1 > /dev/null || echo "$DIR" >> /tmp/errors.txt
done