QTS e la gestione dello sticky bit

Utilizzate questo forum per qualsiasi argomento che non è categorizzato altrove.
fede.lt
Messaggi: 139
Iscritto il: 24 apr 2016, 18:47
Località: provincia di ANCONA

Re: QTS e la gestione dello sticky bit

Messaggio da fede.lt »

Sicuro che si sono? Se chiedo un --help mi da 4 opzioni messe in croce ed in rete ho trovato diversi post su BusyBox che è limitato.

Però non era fatto male lo script, dai...
Server NAS: QNAP TVS-EC880
HW: Intel Xeon E3 1246v3 with 32GB RAM (Transcend+Kingston)
HDDs: WD Red 8TB Helium Filled
Cache: nr.2 SSD Samsung EVO 850 250GB
merluzzo
Messaggi: 478
Iscritto il: 21 nov 2014, 09:24

Re: QTS e la gestione dello sticky bit

Messaggio da merluzzo »

Ma non facevi prima a controllare gli script con un semplice

Codice: Seleziona tutto

grep -i "xargs "  /etc/init.d/* 
e te ne accertavi tu stesso?
Ecco una delle tante linee..

Codice: Seleziona tutto

/usr/bin/find ${DEF_VOLMP}/${SMB_TARGET_NAME}/private -name "*.ldb.bak" | xargs /bin/rm > /dev/null 2>&1
tra le 43 disponibili.

Alt! So gia' cosa stai per dire, c'e' piu' di un modo per ottenere lo stesso risultato tant'e' che con busybox quelli di qnap ci inizializzano tutto il sistema.
comprare un bisturi non fa necessariamente di te un chirurgo : Doctor :
fede.lt
Messaggi: 139
Iscritto il: 24 apr 2016, 18:47
Località: provincia di ANCONA

Re: QTS e la gestione dello sticky bit

Messaggio da fede.lt »

Script ver.2.0 del 10/05/2016
Sono riuscito a farlo girare sotto BusyBox!! : Yahooo : : CoolGun : : Yahooo :

Codice: Seleziona tutto

#!/bin/bash
# Script file: only_the_owner.sh
# "Only the owner can delete the contents" managment (taylored for QNAP NAS)
# Ver.2.0 - 10/05/2016
# Copyright (C) by Lametti Federico <federico.lametti@gmail.com>
# Released under the GNU GPL - General Public License	

action="unknown"
base_dir="No"

# select action to do
# -------------------
if [ $# -eq 0 ] 
  then 
    clear
    echo "\"Only the owner can delete the contents\" flag:"
    select choice in Set Clear Exit
      do
        action=$choice
        if [ "$choice" != "Exit" ]
          then
            echo "Include base dir?"
            select choice in Yes No
              do
                base_dir=$choice
                break
              done              
          fi
        break  
      done
  elif [ $# -le 2 ]
    then 
      case "$1" in
        "--set" | "-s")
          action="Set"
        ;;

        "--clear" | "-c")
          action="Clear"
        ;;

        "--help" | "-h" | "/?")
		clear
		cat <<- HELP_END
		Script file: only_the_owner.sh
		"Only the owner can delete the contents" managment (taylored for QNAP NAS)

		DESCRIPTION:
		Set or Clear the Sticky bit to every sub-directories from current dir onwards.
		That is: only the owner can delete files into directories with such a flag.
	
		USAGE:
		./only_the_owner.sh { --set | --clear } { base }
		./only_the_owner.sh {  -s   |  -c     } {  -b  }
	
		--set   | -s :  set  sticky bit -> Only the owner can delete the contents
		--clear | -c : clear sticky bit -> Every user  could  delete the contents
		  base  | -b : sticky bit set/clear also in base directory

		to get this help page:
		./only_the_owner.sh { --help | -h | /?}                 

		Ver.2.0 - 10/05/2016 
		Copyright (C) by Lametti Federico <federico.lametti@gmail.com>
		Released under the GNU GPL - General Public License	


		HELP_END
           	exit 2
        ;;
      esac

      if [ $# -eq 2 ]
        then
          if ([ "$2" == "base" ] || [ "$2" == "-b" ])
            then 
              base_dir="Yes" 
            else
              action="unknown"
            fi
        fi
  else # nr of  arguments > 2
    action="too_many_args"
  fi

echo

# execute action
# --------------
# Very Important Note:
# QNAP NAS you have to use BusyBox shell and it does not support find -exec: it's mandatory to use xargs...
# ...but BusyBox does not support also find -print0: it's mandatory to use sed
# also $() in not standard: it's a hard life... :-(

case "$action" in
  "Set")
    # in a standard bash use this!
    # find ./ -type d -exec chmod +t {} +
    
    # for QNAP BusyBox you have to use this:
    find ./ -type d -print | sed 's/ /\\ /g' | xargs chmod +t
    echo "Sticky bit SET for every directories"
    
    if [ "$base_dir" == "No" ]
      then
        # in a standard bash use this! 
        # chmod -t $(pwd)

        # for QNAP BusyBox you have to use this:
        pwd | sed 's/ /\\ /g' | xargs chmod -t
        echo "Sticky bit not set for base directory"
      fi
    echo
  ;;
  
  "Clear")
    # in a standard bash use this!
    # find ./ -type d -exec chmod -t {} +

    # for QNAP BusyBox you have to use this:
    find ./ -type d -print | sed 's/ /\\ /g' | xargs chmod -t
    echo "Sticky bit CLEARED for every directories"

    if [ "$base_dir" == "No" ]
      then 
        # in a standard bash use this! 
        # chmod +t $(pwd)

        # for QNAP BusyBox you have to use this:
        pwd | sed 's/ /\\ /g' | xargs chmod +t
        echo "Sticky bit not cleared for base directory"
      fi
    echo
  ;;

  "Exit")
    echo "Exit without any change. Operation aborted."
    echo
    exit 1
  ;; 

  "unknown")
    echo "Maybe you mean \"antani, come se fosse antani\", isn't it? "
    echo "Use --help for instructions"
    echo
    exit 1
  ;;

  "too_many_args")
    echo "Too many arguments."
    echo "Use --help for instructions"
    echo
    exit 1
  ;;

  *)
    echo "Errors occurred!! Operation aborted."
    echo
    exit 1
  ;;  
esac

exit 0
Debug: sticky SET

Codice: Seleziona tutto

admin@ubuntu_14:~/Desktop/test_folder$ only_the_owner.sh

"Only the owner can delete the contents" flag:
1) Set
2) Clear
3) Exit
#? 1
Include base dir?
1) Yes
2) No
#? 1

Sticky bit SET for every directories

admin@ubuntu_14:~/Desktop/test_folder$ ll -R
.:
total 20
drwxr-xr-t 4 admin administrator 4096 May  9 07:24 ./
drwxr-xr-x 3 admin administrator 4096 May  9 05:31 ../
-rw-r--r-- 1 admin administrator  292 May  9 07:24 file
drwxr-xr-t 3 admin administrator 4096 May  9 05:08 piu    spazi/
-rw-r--r-- 1 admin administrator    0 May  9 05:07 Untitled Document
drwxr-xr-t 4 admin administrator 4096 May  9 05:08 Untitled Folder 2/

./piu    spazi:
total 12
drwxr-xr-t 3 admin administrator 4096 May  9 05:08 ./
drwxr-xr-t 4 admin administrator 4096 May  9 07:24 ../
-rw-r--r-- 1 admin administrator    0 May  9 05:07 Untitled Document
-rw-r--r-- 1 admin administrator    0 May  9 05:07 Untitled Document 2
drwxr-xr-t 2 admin administrator 4096 May  9 05:08 Untitled Folder/

./piu    spazi/Untitled Folder:
total 8
drwxr-xr-t 2 admin administrator 4096 May  9 05:08 ./
drwxr-xr-t 3 admin administrator 4096 May  9 05:08 ../
-rw-r--r-- 1 admin administrator    0 May  9 05:08 Untitled Document

./Untitled Folder 2:
total 16
drwxr-xr-t 4 admin administrator 4096 May  9 05:08 ./
drwxr-xr-t 4 admin administrator 4096 May  9 07:24 ../
-rw-r--r-- 1 admin administrator    0 May  9 05:08 Untitled Document
-rw-r--r-- 1 admin administrator    0 May  9 05:08 Untitled Document 2
drwxr-xr-t 2 admin administrator 4096 May  9 05:08 Untitled Folder/
drwxr-xr-t 2 admin administrator 4096 May  9 05:08 Untitled Folder 2/

./Untitled Folder 2/Untitled Folder:
total 8
drwxr-xr-t 2 admin administrator 4096 May  9 05:08 ./
drwxr-xr-t 4 admin administrator 4096 May  9 05:08 ../
-rw-r--r-- 1 admin administrator    0 May  9 05:08 Untitled Document
-rw-r--r-- 1 admin administrator    0 May  9 05:08 Untitled Document 2

./Untitled Folder 2/Untitled Folder 2:
total 8
drwxr-xr-t 2 admin administrator 4096 May  9 05:08 ./
drwxr-xr-t 4 admin administrator 4096 May  9 05:08 ../
-rw-r--r-- 1 admin administrator    0 May  9 05:08 Untitled Document
admin@ubuntu_14:~/Desktop/test_folder$ ll ../test_folder/
total 20
drwxr-xr-t 4 admin administrator 4096 May  9 07:24 ./
drwxr-xr-x 3 admin administrator 4096 May  9 05:31 ../
-rw-r--r-- 1 admin administrator  292 May  9 07:24 file
drwxr-xr-t 3 admin administrator 4096 May  9 05:08 piu    spazi/
-rw-r--r-- 1 admin administrator    0 May  9 05:07 Untitled Document
drwxr-xr-t 4 admin administrator 4096 May  9 05:08 Untitled Folder 2/
Debug: sticky CLEAR

Codice: Seleziona tutto

admin@ubuntu_14:~/Desktop/test_folder$ only_the_owner.sh

"Only the owner can delete the contents" flag:
1) Set
2) Clear
3) Exit
#? 2
Include base dir?
1) Yes
2) No
#? 2

Sticky bit CLEARED for every directories
Sticky bit not cleared for base directory

admin@ubuntu_14:~/Desktop/test_folder$ ll -R
.:
total 20
drwxr-xr-t 4 admin administrator 4096 May  9 07:24 ./
drwxr-xr-x 3 admin administrator 4096 May  9 05:31 ../
-rw-r--r-- 1 admin administrator  292 May  9 07:24 file
drwxr-xr-x 3 admin administrator 4096 May  9 05:08 piu    spazi/
-rw-r--r-- 1 admin administrator    0 May  9 05:07 Untitled Document
drwxr-xr-x 4 admin administrator 4096 May  9 05:08 Untitled Folder 2/

./piu    spazi:
total 12
drwxr-xr-x 3 admin administrator 4096 May  9 05:08 ./
drwxr-xr-t 4 admin administrator 4096 May  9 07:24 ../
-rw-r--r-- 1 admin administrator    0 May  9 05:07 Untitled Document
-rw-r--r-- 1 admin administrator    0 May  9 05:07 Untitled Document 2
drwxr-xr-x 2 admin administrator 4096 May  9 05:08 Untitled Folder/

./piu    spazi/Untitled Folder:
total 8
drwxr-xr-x 2 admin administrator 4096 May  9 05:08 ./
drwxr-xr-x 3 admin administrator 4096 May  9 05:08 ../
-rw-r--r-- 1 admin administrator    0 May  9 05:08 Untitled Document

./Untitled Folder 2:
total 16
drwxr-xr-x 4 admin administrator 4096 May  9 05:08 ./
drwxr-xr-t 4 admin administrator 4096 May  9 07:24 ../
-rw-r--r-- 1 admin administrator    0 May  9 05:08 Untitled Document
-rw-r--r-- 1 admin administrator    0 May  9 05:08 Untitled Document 2
drwxr-xr-x 2 admin administrator 4096 May  9 05:08 Untitled Folder/
drwxr-xr-x 2 admin administrator 4096 May  9 05:08 Untitled Folder 2/

./Untitled Folder 2/Untitled Folder:
total 8
drwxr-xr-x 2 admin administrator 4096 May  9 05:08 ./
drwxr-xr-x 4 admin administrator 4096 May  9 05:08 ../
-rw-r--r-- 1 admin administrator    0 May  9 05:08 Untitled Document
-rw-r--r-- 1 admin administrator    0 May  9 05:08 Untitled Document 2

./Untitled Folder 2/Untitled Folder 2:
total 8
drwxr-xr-x 2 admin administrator 4096 May  9 05:08 ./
drwxr-xr-x 4 admin administrator 4096 May  9 05:08 ../
-rw-r--r-- 1 admin administrator    0 May  9 05:08 Untitled Document
admin@ubuntu_14:~/Desktop/test_folder$ 
Server NAS: QNAP TVS-EC880
HW: Intel Xeon E3 1246v3 with 32GB RAM (Transcend+Kingston)
HDDs: WD Red 8TB Helium Filled
Cache: nr.2 SSD Samsung EVO 850 250GB
merluzzo
Messaggi: 478
Iscritto il: 21 nov 2014, 09:24

Re: QTS e la gestione dello sticky bit

Messaggio da merluzzo »

fede.lt ha scritto: Sono riuscito a farlo girare sotto BusyBox!! : Yahooo : : CoolGun : : Yahooo :
Tutto cio' e' stupendo : Chessygrin :
Ora mi faresti una cortesia?

Lascia stare ubuntu per un attimo e vai di ssh -l admin tuonas.tuodominio

crea la tua directory "grande ammucchiata" di users-files
e dai chmod 777 "grande ammucchiata"
e poi chmod +t "grande ammucchiata"

e fammi sapere come va.
comprare un bisturi non fa necessariamente di te un chirurgo : Doctor :
fede.lt
Messaggi: 139
Iscritto il: 24 apr 2016, 18:47
Località: provincia di ANCONA

Re: QTS e la gestione dello sticky bit

Messaggio da fede.lt »

Già provato come prima cosa: succede che appiccica lo sticky bit anche ai files, cosa che invece non voglio fare perché non ha senso.
Per inciso, senza nemmeno che lo provo : mi sa che ti sei scordato un -R
Server NAS: QNAP TVS-EC880
HW: Intel Xeon E3 1246v3 with 32GB RAM (Transcend+Kingston)
HDDs: WD Red 8TB Helium Filled
Cache: nr.2 SSD Samsung EVO 850 250GB
merluzzo
Messaggi: 478
Iscritto il: 21 nov 2014, 09:24

Re: QTS e la gestione dello sticky bit

Messaggio da merluzzo »

fede.lt ha scritto:senza nemmeno che lo provo
Si vede che sei troppo avanti : Thumbup :
comprare un bisturi non fa necessariamente di te un chirurgo : Doctor :
Avatar utente
luciano
Amministratore
Messaggi: 8706
Iscritto il: 25 apr 2008, 01:45
Località: Roma
Contatta:

Re: QTS e la gestione dello sticky bit

Messaggio da luciano »

Ciao fede.it, grazie per lo script! Ho marcato questo thread come "importante" cosi che rimanga in cima al forum. Spero cmq che QNAP risolva prima o poi la cosa implementando una ACL degna di questo nome. Si vocifera della 4.2.2 ma finchè non la vedo...
fede.lt
Messaggi: 139
Iscritto il: 24 apr 2016, 18:47
Località: provincia di ANCONA

Re: QTS e la gestione dello sticky bit

Messaggio da fede.lt »

merluzzo ha scritto:Si vede che sei troppo avanti : Thumbup :
Troppo gentile, io pensavo di essere semplicemente un genio... : Chessygrin :

X Luciano: .lt : : Sad : : WohoW :
Server NAS: QNAP TVS-EC880
HW: Intel Xeon E3 1246v3 with 32GB RAM (Transcend+Kingston)
HDDs: WD Red 8TB Helium Filled
Cache: nr.2 SSD Samsung EVO 850 250GB
merluzzo
Messaggi: 478
Iscritto il: 21 nov 2014, 09:24

Re: QTS e la gestione dello sticky bit

Messaggio da merluzzo »

fede.lt ha scritto:
merluzzo ha scritto:Si vede che sei troppo avanti : Thumbup :
Troppo gentile, io pensavo di essere semplicemente un genio... : Chessygrin :
Se tu avessi provato a fare come ti suggerivo tre msg piu' sopra avresti capito in tutta la sua portata la vastita' del tuo genio : Chessygrin :
comprare un bisturi non fa necessariamente di te un chirurgo : Doctor :
fede.lt
Messaggi: 139
Iscritto il: 24 apr 2016, 18:47
Località: provincia di ANCONA

Re: QTS e la gestione dello sticky bit

Messaggio da fede.lt »

merluzzo ha scritto: ...
e fammi sapere come va.
Come previsto... o sono Nostradamus oppure dimmi te cosa sto sbagliando : Eeek :
Server NAS: QNAP TVS-EC880
HW: Intel Xeon E3 1246v3 with 32GB RAM (Transcend+Kingston)
HDDs: WD Red 8TB Helium Filled
Cache: nr.2 SSD Samsung EVO 850 250GB
merluzzo
Messaggi: 478
Iscritto il: 21 nov 2014, 09:24

Re: QTS e la gestione dello sticky bit

Messaggio da merluzzo »

Getto la spugna, a me funziona e a questo punto non so che dirti.
L'unica cosa che mi viene in mente e' che tu abbia attivato "autorizzazioni avanzate" e gestione acl win e si sia impastato qualcosa.
comprare un bisturi non fa necessariamente di te un chirurgo : Doctor :
Avatar utente
luciano
Amministratore
Messaggi: 8706
Iscritto il: 25 apr 2008, 01:45
Località: Roma
Contatta:

Re: QTS e la gestione dello sticky bit

Messaggio da luciano »

Scusate se mi intrometto..... ma perchè non vi parlate facendo copia/incolla dei comandi e relativi risultati da una parte e dall'altra?! Altrimenti non ne uscite.
fede.lt
Messaggi: 139
Iscritto il: 24 apr 2016, 18:47
Località: provincia di ANCONA

Re: QTS e la gestione dello sticky bit

Messaggio da fede.lt »

Ciao ragazzi,
il mio amico esperto di Linux (che ringrazio) mi ha fatto un po' di debug e mi ha erudito sul fatto che sotto Linux una cartella può contenere qualsiasi carattere.
ERGO sono corso ai ripari "escapando" tutti i caratteri (e non solo gli spazi) per evitare problemi coi nomi files.
Rimane solo un caso che mette in crisi lo script: se una cartella contiene un \n = new line ma, ragionevolemente, se c'è un \n è giusto che chi lo ha messo debba soffrire!!
Per me, povero utente Windows, il problema non si pone!! : Thumbup :

Vi allego l'ultima revisione, sperando di essere stato utile a qualcuno (oltre che a me stesso : Chessygrin : )

Codice: Seleziona tutto

#!/bin/bash
# only_the_owner.sh - Ver.2.1 (11/05/2016)
# "Only the owner can delete the contents" flag manager
# Copyright (C) by Lametti Federico <federico.lametti@gmail.com>
# Released under the GNU GPL - General Public License
# Suggestions and bug reports are welcome.

action="unknown"  # init action to execute as "unknown"
base_dir="Yes"    # manage flag on base dir as default

# select action
# -------------
if [ $# -eq 0 ] 
  then 
    clear
    echo "\"Only the owner can delete the contents\" flag:"
    select choice in Set Clear Exit
      do
        action=$choice
        if [ "$choice" != "Exit" ]
          then
            echo "Include base dir?"
            select choice in Yes No
              do
                base_dir=$choice
                break
              done              
          fi
        break  
      done
  elif [ $# -le 2 ]
    then 
      case "$1" in
        "--set" | "-s")
          action="Set"
        ;;

        "--clear" | "-c")
          action="Clear"
        ;;

        "--help" | "-h" | "/?")
		clear
		cat <<- HELP_END
		only_the_owner.sh - Ver.2.1 (11/05/2016)
		"Only the owner can delete the contents" flag manager

		DESCRIPTION:
		 Set or Clear the sticky bit to every sub-directories from current dir onwards.
		 That is: only the owner can delete files into directories with such a flag.
	
		USAGE:
		 ./only_the_owner.sh { --set | --clear } { nobase }
		 ./only_the_owner.sh {  -s   |  -c     } {   nb   }
		 parameters:
		  --set   | -s :  set  sticky bit -> only the owner can delete the contents
		  --clear | -c : clear sticky bit -> every user  could  delete the contents
		  nobase  | nb : do NOT set/clear sticky bit in base directory
		
		To get this help page:
		 ./only_the_owner.sh { --help | -h | /?}
		
		ADDITIONAL INFORMATION:
		 1) This script is tailored for QNAP QTS with BusyBox shell
		 2) Known issue: does not work if folder names contain new line symbol \n
		
		Copyright (C) by Lametti Federico <federico.lametti@gmail.com>
		Released under the GNU GPL - General Public License	
		Suggestions and bug reports are welcome.

		HELP_END
		exit 2
        ;;
      esac

      if [ $# -eq 2 ]
        then
          if ([ "$2" == "nobase" ] || [ "$2" == "nb" ])
            then 
              base_dir="No" 
            else
              action="unknown"
            fi
        fi
  else # nr of arguments > 2
    action="too_many_args"
  fi

echo

# execute action
# --------------
# Very Important Note:
# With QNAP QTS you have to use BusyBox shell and it does not support find -exec:
# it's mandatory to use xargs but BusyBox does not support also find -print0: 
# it's mandatory to use sed. Also $() in not standard: it's a hard life... :-(

# VERY IMPORTANT: Which characters need to be escaped in Bash? - trick found at following link:
# http://stackoverflow.com/questions/15783701/which-characters-need-to-be-escaped-in-bash-how-do-we-know-it
# Escape every char with a backslash.
# This works for all characters except newline. For newline characters use single or double quotes. 
# Empty strings must still be handled - replace with ""
# \I\'\m\ \a\ \s\@\f\e\ \$\t\r\i\n\g\ \w\h\i\c\h\ \e\n\d\s\ \i\n\ \n\e\w\l\i\n\e"
# "
# sed command: sed -e 's/./\\&/g; 1{$s/^$/""/}; 1!s/^/"/; $!s/$/"/'

case "$action" in
  "Set")
    # in a standard bash use this!
    # find ./ -type d -exec chmod +t {} +
    
    # for QNAP BusyBox you have to use this:
    # (Pay attention: new lines does not work!)
    find ./ -type d | sed 's/./\\&/g' | xargs chmod +t
    echo "Sticky bit SET for every directories"
    
    if [ "$base_dir" == "No" ]
      then
        # in a standard bash use this! 
        # chmod -t $(pwd)

        # for QNAP BusyBox you have to use this:
        # (Pay attention: new lines does not work!)
        pwd  | sed 's/./\\&/g' | xargs chmod -t
        echo "Sticky bit of base directory NOT set"
      fi
    echo
  ;;
  
  "Clear")
    # in a standard bash use this!
    # find ./ -type d -exec chmod -t {} +

    # for QNAP BusyBox you have to use this:
    # (Pay attention: new lines does not work!)
    find ./ -type d | sed 's/./\\&/g' | xargs chmod -t
    echo "Sticky bit CLEARED for every directories"

    if [ "$base_dir" == "No" ]
      then 
        # in a standard bash use this! 
        # chmod +t $(pwd)

        # for QNAP BusyBox you have to use this:
        # (Pay attention: new lines does not work!)
        pwd  | sed 's/./\\&/g' | xargs chmod +t
        echo "Sticky bit of base directory SET"
      fi
    echo
  ;;

  "Exit")
    echo "Exit without any change. Operation aborted."
    echo
    exit 1
  ;; 

  "unknown")
    echo "Maybe you mean \"antani, come se fosse antani\", isn't it? "
    echo "Use --help for instructions"
    echo
    exit 1
  ;;

  "too_many_args")
    echo "Too many arguments."
    echo "Use --help for instructions"
    echo
    exit 1
  ;;

  *)
    echo "Errors occurred!! Operation aborted."
    echo
    exit 1
  ;;  
esac

exit 0

# -------------- #
#   Changelog:   #
# -------------- #
# Ver.1.0: (07/05/16) - first draft
# Ver.2.0: (08/05/16)
#   1) fixed expansion bug: $(pwd) is the correct form
#   2) used sed to escape spaces, fixing lack of find -print0 in BusyBox
#   3) used sed to escape spaces, fixing non-standard $() expansion in BusyBox
# Ver.2.1: (11/05/16)
#   1) used sed to escape ALL characters instead of spaces only
#   2) {base|-b} replaced by {nobase|nb} with opposite meaning
#   3) known issue: does not work if folder names contain new line symbol \n
Server NAS: QNAP TVS-EC880
HW: Intel Xeon E3 1246v3 with 32GB RAM (Transcend+Kingston)
HDDs: WD Red 8TB Helium Filled
Cache: nr.2 SSD Samsung EVO 850 250GB
merluzzo
Messaggi: 478
Iscritto il: 21 nov 2014, 09:24

Re: QTS e la gestione dello sticky bit

Messaggio da merluzzo »

luciano ha scritto:Scusate se mi intrometto..... ma perchè non vi parlate facendo copia/incolla dei comandi e relativi risultati da una parte e dall'altra?! Altrimenti non ne uscite.
Luciano i comandi io li ho postati, chiunque puo' eseguirli e verificare di persona che dandoli si ottiene esattamente quello che serviva al "povero utente windows" come si autodefinisce fede.it
Giusto per sicurezza, potevo avere un bug io, ho ripetuto i comandi su un nas con processore arm e tutto funziona.
fede.lt ha scritto: Rimane solo un caso che mette in crisi lo script: se una cartella contiene un \n = new line ma, ragionevolemente, se c'è un \n è giusto che chi lo ha messo debba soffrire!!
Per me, povero utente Windows, il problema non si pone!! : Thumbup :
Come "povero utente windows" diciamo che sei nella norma, come programmatore imho non e' che fai una bella figura a postare uno script (inutile o meno che sia) con un bug : Blink :

I comandi sono scritti, chiunque li puo' provare e vedere che le shares, come richiesto, ereditano lo sticky bit e solo il proprietario potra' cancellare quanto inserito.
comprare un bisturi non fa necessariamente di te un chirurgo : Doctor :
fede.lt
Messaggi: 139
Iscritto il: 24 apr 2016, 18:47
Località: provincia di ANCONA

Re: QTS e la gestione dello sticky bit

Messaggio da fede.lt »

Io non insisto... ma a me lo sticky bit non lo eredita col tuo metodo.

Come programmatore: se leggi all'inizio del post, avevo detto che avrei pubblicato uno script in develop chiedendo aiuto per migliorarlo.
Ad ogni modo, la questione del \n sulle dir non la considero un bug ma una anomalia.

Magari potresti essere un po' più pro-attivo invece che scrivere post criptici...
Server NAS: QNAP TVS-EC880
HW: Intel Xeon E3 1246v3 with 32GB RAM (Transcend+Kingston)
HDDs: WD Red 8TB Helium Filled
Cache: nr.2 SSD Samsung EVO 850 250GB
merluzzo
Messaggi: 478
Iscritto il: 21 nov 2014, 09:24

Re: QTS e la gestione dello sticky bit

Messaggio da merluzzo »

fede.lt ha scritto: Magari potresti essere un po' più pro-attivo invece che scrivere post criptici...
Non so come potrei essere piu' attivo : Chessygrin :
Sono due comandi in croce, non c'e' nulla di criptico ne di speciale, in mp pvt ti ho indicato esattamente come fare, piu' di dirti che a me funziona su due nas, uno intel e uno arm.
I casi sono:
- io ho due nas buggati (e nota bene che non lo escludo anche se molto improbabile)
- misteri dell'informatica.

salvo che tu non ti ostini a dare i comandi e creare delle sotto directory con lo stesso utente.
comprare un bisturi non fa necessariamente di te un chirurgo : Doctor :
fede.lt
Messaggi: 139
Iscritto il: 24 apr 2016, 18:47
Località: provincia di ANCONA

Re: QTS e la gestione dello sticky bit

Messaggio da fede.lt »

: Eeek : Urka: adesso si che potresti avermi trovato un baco!! : Eeek :
Potevi dirlo prima, però! : Blink :
Si, è vero, stavo lavorando sempre con lo stesso utente: visto che sei stato pro-attivo? : WohoW :
Più tardi provo & se fosse come dici tu questo semplificherebbe il problema!!

Cmq il mio script servirebbe per "sanificare" una situazione di cartelle già pre-esistente, senza appiccicare lo sticky bit a tutti i file.
Spero possa servire... adesso starei lavorando sulla esclusione delle cartelle nascoste: non avevo considerato le cartelle di thumb...
Se pensate possa essere utile lo pubblico, se no desisto.
Server NAS: QNAP TVS-EC880
HW: Intel Xeon E3 1246v3 with 32GB RAM (Transcend+Kingston)
HDDs: WD Red 8TB Helium Filled
Cache: nr.2 SSD Samsung EVO 850 250GB
fede.lt
Messaggi: 139
Iscritto il: 24 apr 2016, 18:47
Località: provincia di ANCONA

Re: QTS e la gestione dello sticky bit

Messaggio da fede.lt »

Ciao merluzzo,
io ho appena testato nuovamente la tua soluzione e, pur seguendo le tue indicazioni, a me non funziona.
Ho prestato particolare attenzione nel cambire utente, come mi hai suggerito negli ultimi post, ma lo sticky bit non si propaga.

Potresti essere così gentile da postare un listato del tuo terminale o alcuni screenshot che mostrano i comandi che impartisci ed i risultati ottenuti?
Server NAS: QNAP TVS-EC880
HW: Intel Xeon E3 1246v3 with 32GB RAM (Transcend+Kingston)
HDDs: WD Red 8TB Helium Filled
Cache: nr.2 SSD Samsung EVO 850 250GB
fede.lt
Messaggi: 139
Iscritto il: 24 apr 2016, 18:47
Località: provincia di ANCONA

Re: QTS e la gestione dello sticky bit

Messaggio da fede.lt »

Se qualcuno dovesse essere interessato, pubblico l'ultima revisione del mio script: ho gestito la possibilità di escludere i file nascosti, per poter lasciare invariate le cartelle di transcodifica del sistema.
Alla fine dello script, comunque, trovate il changelog.

NOTA BENE: lo script non setta lo sticky bit nelle cartelle che contengono un capo riga.
Tale evenienza è, comunque, un'anomalia nel nome cartella dovuto al fatto che Linux non pone limitazioni ma, per fortuna, nei sistemi Windows non è consentita.

Codice: Seleziona tutto

#!/bin/bash
# only_the_owner.sh - Ver.2.2 (18/05/2016)
# "Only the owner can delete the contents" flag's utility
# Copyright (C) by Lametti Federico <federico.lametti@gmail.com>
# Released under the GNU GPL - General Public License
# Suggestions and bug reports are welcome.

action="unknown"  # init action to execute as "unknown"
hidden_dirs="No"  # init flag for hidden dirs management to "No"

# select action
# -------------
if [ $# -eq 0 ] 
  then 
    clear
    echo "\"Only the owner can delete the contents\" flag:"
    select choice in Set Clear Exit
      do
        action=$choice
        if [ "$choice" != "Exit" ]
          then
            echo "Include hidden directories?"
            select choice in Yes No
              do
                hidden_dirs=$choice
                break
              done              
          fi
        break  
      done
  elif [ $# -le 2 ]
    then 
      case "$1" in
        "--set" | "-s")
          action="Set"
        ;;

        "--clear" | "-c")
          action="Clear"
        ;;

        "--help" | "/?")
			clear
			#NOTE: with <<- (instead of <<) you can use tab to indent
			cat <<- HELP_END
			only_the_owner.sh - Ver.2.2 (18/05/2016)
			"Only the owner can delete the contents" flag's utility

			DESCRIPTION:
			 Set or Clear the sticky bit to every sub-directories from the current dir onwards.
			 That is: only the owner can delete files into directories with such a flag.
			 Base dir always included. Hidden directories always excluded, unless specified.
			USAGE:
			 ./only_the_owner.sh { --set | --clear } { hidden }
			 ./only_the_owner.sh {  -s   |  -c     } {  -h    }
			 parameters:
			  --set   | -s :  set  sticky bit -> only the owner can delete the contents
			  --clear | -c : clear sticky bit -> every user  could  delete the contents
			   hidden | -h : set/clear sticky bit also in hidden directory
		
			To get this help page:
			 ./only_the_owner.sh { --help | /?}
		
			ADDITIONAL INFORMATION:
			 1) This script is tailored for QNAP QTS with BusyBox shell
			 2) Known issue: does not work if folder names contain new line symbol \n
		
			Copyright (C) by Lametti Federico <federico.lametti@gmail.com>
			Released under the GNU GPL - General Public License	
			Suggestions and bug reports are welcome.

			HELP_END
			exit 2
        ;;
      esac

      if [ $# -eq 2 ]
        then
          if ([ "$2" == "hidden" ] || [ "$2" == "-h" ])
            then 
              hidden_dirs="Yes" 
            else
              action="unknown"
            fi
        fi
  else # nr of arguments > 2
    action="too_many_args"
  fi

echo

# execute action
# --------------

# In a standard bash use these command lines:
# find ./ -type d -exec chmod +t {} +
# chmod +t $(pwd)
#
# With QNAP QTS you have to use BusyBox shell and it does not support find -exec:
# it's mandatory to use xargs but BusyBox does not support also find -print0: 
# it's mandatory to use sed. Also $() in not standard: it's a hard life... :-(
#
# VERY IMPORTANT: Which characters need to be escaped in Bash? - trick found at following link:
# http://stackoverflow.com/questions/15783701/which-characters-need-to-be-escaped-in-bash-how-do-we-know-it
# Escape every char with a backslash.
# This works for all characters except newline. For newline characters use single or double quotes. 
# Empty strings must still be handled - replace with ""
# \I\'\m\ \a\ \s\@\f\e\ \$\t\r\i\n\g\ \w\h\i\c\h\ \e\n\d\s\ \i\n\ \n\e\w\l\i\n\e"
# "
# sed command: sed -e 's/./\\&/g; 1{$s/^$/""/}; 1!s/^/"/; $!s/$/"/'
#
# NOTE: regex spacial character & = reference at entire match.
#       The entire string that was matched by the search operation will be substituted.
#
# Trick to skip hidden dirs: find -type d | grep -v '.*/\..*'
# that is: "anything, then a slash, then a dot, then anything" (.*=at least one char, no void!)

case "$action" in
  "Set")
    # IMPORTANT: will not work if directory name contains new lines!
    if [ "$hidden_dirs" == "Yes" ]
      then
    	find ./ -type d | sed 's/./\\&/g' | xargs chmod +t
    	echo "Sticky bit SET for all directories"
      else
        find ./ -type d | grep -v '.*/\..*' | sed 's/./\\&/g' | xargs chmod +t 
        echo "Sticky bit SET for all directories except hidden ones"
      fi
    echo
  ;;
  
  "Clear")
    # IMPORTANT: will not work if directory name contains new lines!
    if [ "$hidden_dirs" == "Yes" ]
      then
    	find ./ -type d | sed 's/./\\&/g' | xargs chmod -t
    	echo "Sticky bit CLEARED for all directories"
      else
        find ./ -type d | grep -v '.*/\..*' | sed 's/./\\&/g' | xargs chmod -t 
        echo "Sticky bit CLEARED for all directories except hidden ones"
      fi
    echo
  ;;

  "Exit")
    echo "Exit without any change. Operation aborted."
    echo
    exit 1
  ;; 

  "unknown")
    echo "Maybe you mean \"antani, come se fosse antani\", isn't it? "
    echo "Use --help for instructions"
    echo
    exit 1
  ;;

  "too_many_args")
    echo "Too many arguments."
    echo "Use --help for instructions"
    echo
    exit 1
  ;;

  *)
    echo "Errors occurred!! Operation aborted."
    echo
    exit 1
  ;;  
esac

exit 0

# -------------- #
#   Changelog:   #
# -------------- #
# Ver.1.0: (07/05/16) - first draft
# Ver.2.0: (08/05/16)
#   1) fixed expansion bug: $(pwd) is the correct form
#   2) used sed to escape spaces, fixing lack of find -print0 in BusyBox
#   3) used sed to escape spaces, fixing non-standard $() expansion in BusyBox
# Ver.2.1: (11/05/16)
#   1) used sed to escape ALL characters instead of spaces only
#   2) {base|-b} replaced by {nobase|nb} with opposite meaning
# Ver.2.2: (18/05/16)
#   1) removed option for base dir: now it is included for default
#   2) added new options to manage hidden directories
#   3) removed -h help option to avoid misleading
#
# ---------------- #
#   Known issues   #
# ---------------- #
# Script does not work if folder names contain new line symbol \n
#
# Bye, Federico :)
Server NAS: QNAP TVS-EC880
HW: Intel Xeon E3 1246v3 with 32GB RAM (Transcend+Kingston)
HDDs: WD Red 8TB Helium Filled
Cache: nr.2 SSD Samsung EVO 850 250GB
merluzzo
Messaggi: 478
Iscritto il: 21 nov 2014, 09:24

Re: QTS e la gestione dello sticky bit

Messaggio da merluzzo »

fede.lt ha scritto: io ho appena testato nuovamente la tua soluzione e, pur seguendo le tue indicazioni, a me non funziona.
Potresti essere così gentile da postare un listato del tuo terminale o alcuni screenshot che mostrano i comandi che impartisci ed i risultati ottenuti?
Non so cosa dirti a me funziona su due nas diversi con architetture diverse (arm e x86)
Abbi pazienza ma non voglio rendermi ridicolo postando lo screenshot di un mkdir e chmod, sono due comandi in croce basta darli e accedere alle shares per verificare.

Piuttosto potresti indicare esattamente come verifichi che lo sticky non si propaga? Intendo in modo preciso i comandi e le operazioni che fai per verificarlo?
comprare un bisturi non fa necessariamente di te un chirurgo : Doctor :
Rispondi