Advertisement
CSenshi

OS - FUSE (permisions)

Jul 14th, 2019
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.18 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # to run please change mode
  4. # chmod +x check_dir.bash
  5.  
  6. if [ "$#" -ne 1 ]; then
  7.     echo "Illegal number of parameters"
  8.     echo 'Call : ./check_dir.sh mounted_dir'
  9.     exit 1
  10. fi
  11.  
  12. MOUNT_DIR=$1
  13. cd $MOUNT_DIR
  14.  
  15. CMD="#### Command : "
  16.  
  17. test1(){
  18.     echo "Test 1 : test basic chmod"
  19.    
  20.     echo "$CMD mkdir dir_to_chmod"
  21.     mkdir dir_to_chmod
  22.    
  23.     echo "$CMD touch file_to_chmod"
  24.     touch file_to_chmod
  25.    
  26.     echo "$CMD ls -l"
  27.     ls --color=auto -l
  28.     echo
  29.    
  30.     echo "$CMD chmod 0777 dir_to_chmod file_to_chmod"
  31.     sudo chmod 0777 dir_to_chmod file_to_chmod
  32.     echo "$CMD ls -l"
  33.     ls --color=auto -l
  34.     echo
  35.    
  36.     echo "$CMD chmod -x dir_to_chmod file_to_chmod"
  37.     chmod -x dir_to_chmod file_to_chmod
  38.     echo "$CMD ls -l"
  39.     ls --color=auto -l
  40.     echo
  41.    
  42.     echo "$CMD sudo chmod 0643 dir_to_chmod file_to_chmod"
  43.     sudo chmod 0643 dir_to_chmod file_to_chmod
  44.     echo "$CMD ls -l"
  45.     ls --color=auto -l
  46.     echo
  47.    
  48.     echo "$CMD sudo chmod 0755 file_to_chmod"
  49.     sudo chmod 0755 file_to_chmod
  50.     echo "$CMD sudo chmod 0644 dir_to_chmod"
  51.     sudo chmod 0644 dir_to_chmod
  52.     echo "$CMD ls -l"
  53.     ls --color=auto -l
  54.     echo
  55.    
  56.     rmdir dir_to_chmod
  57.     rm file_to_chmod
  58. }
  59.  
  60.  
  61. test2(){
  62.     echo "Test 2 : check access"
  63.    
  64.     FILE=test_access.txt
  65.     CONTENT="You Shouldn't be able to see this :p"
  66.    
  67.     echo "$CMD echo $CONTENT > $FILE"
  68.     echo $CONTENT > $FILE
  69.    
  70.     echo "$CMD chmod 0000 $FILE"
  71.     chmod 0000 $FILE
  72.    
  73.     echo "$CMD cat $FILE (should not open)"
  74.     cat $FILE
  75.     echo
  76.    
  77.     NEW_CONTENT="NEW CONTENT"
  78.     echo "$CMD $NEW_CONTENT > $FILE (shouldn't be able to write)"
  79.     echo $NEW_CONTENT > $FILE
  80.     echo
  81.    
  82.    
  83.     echo "$CMD chmod 0777 $FILE"
  84.     chmod 0777 $FILE
  85.    
  86.     echo "$CMD echo $NEW_CONTENT > $FILE"
  87.     echo $NEW_CONTENT > $FILE
  88.    
  89.     echo "$CMD cat $FILE (should not open)"
  90.     cat $FILE
  91.     echo
  92.    
  93.     ls -l
  94. }
  95.  
  96.  
  97. run_test(){
  98.     # check basic chmod
  99.     test1
  100.    
  101.     # check basic access
  102.     test2
  103. }
  104.  
  105.  
  106. START=$(date +%s.%N)
  107. run_test
  108. END=$(date +%s.%N)
  109. DIFF=$(echo "$END - $START" | bc)
  110.  
  111. echo "Elapsed time : $DIFF seconds"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement