{{tag>find Regex}} # DRAFT Oops j'ai fait un boulette ### Exemple de connerie 1 ~~~bash chown -R oracle:dba / ~~~ Comment la retrapper (en ajustant ctime & mtime par les valeurs qu'il est possible de trouver avec la commande stat) : Pour info : Différence en CTIME *(change time)* et MTIME *(modification time)* Voir aussi `man ls` `[--time={atime,access,use,ctime,status}]` ~~~ $ cat foo Hello, World ~~~ Met à jour atime (access time), mais pas ctime (change time) ni mtime (modification time) ~~~bash chmod 777 foo ~~~ Met à jour ctime mais pas atime ni mtime. Car le fichier n'est pas modifié, seulement les métadonnées (droits) ~~~bash echo "Goodbye, World!" > foo ~~~ Met à jour ctime et mtime mais pas atime. **Machine de référence** ~~~bash find / ! -wholename "/proc/*" -type f -fprintf jbset_f.sh "chown %u:%g \"%p\" \n" find / ! -wholename "/proc/*" -type d -fprintf jbset_d.sh "chown %u:%g \"%p\" \n" find / ! -wholename "/proc/*" -type l -fprintf jbset_l.sh "chown -h %u:%g \"%p\" \n" find / ! -wholename "/proc/*" ! -type d -a ! -type f -a ! -type l -fprintf jbset_o.sh "chown %u:%g \"%p\" \n" find / ! -wholename "/proc/*" -type f -perm /u+s -fprintf jbset_suid.sh "chmod %m \"%p\" \n" find / ! -wholename "/proc/*" -type f -perm /g+s -fprintf jbset_guid.sh "chmod %m \"%p\" \n" ~~~ **Machine à corriger** ~~~bash bash jbset_f.sh 2>jbset_f.err bash jbset_d.sh 2>jbset_d.err bash jbset_l.sh 2>jbset_l.err bash jbset_o.sh 2>jbset_o.err ~~~ On repositionne les SUID & GUID. ~~~bash bash jbset_suid.sh 2>jbset_suid.err bash jbset_guid.sh 2>jbset_guid.err ~~~ On jete un petit coup d'oeil sur les logs ~~~bash cat *.err |grep -v "No such file or directory" ~~~ Fichiers restants à modifier ~~~bash find / -ctime -1 -mtime +2 -user oracle -group dba ~~~ Root propriétaire des fichiers restants ~~~bash find / -ctime -1 -mtime +2 -user oracle -group dba -type f ! -iname "*oracle*" ! -iwholename "*oracle*" -print0 |xargs -0 chown root:root find / -ctime -1 -mtime +2 -user oracle -group dba -type d ! -iname "*oracle*" ! -iwholename "*oracle*" -print0 |xargs -0 chown root:root find / -ctime -1 -mtime +2 -user oracle -group dba -type l ! -iname "*oracle*" ! -iwholename "*oracle*" -print0 |xargs -0 chown -h root:root ~~~ On jete un coup d'oeil : ~~~bash find / -user oracle -group dba |grep -iv oracle ~~~ Un reboot est nécessaire pour les devices de type char/block/socket de /proc /dev /sys. Il faudra (peut-être) redéfinir les droits Oracle tel que initialement prévu. ### Exemple de connerie 2 ~~~bash chmod -R 777 /etc ~~~ Comment la rattraper : ~~~bash find /etc/ ! -type l ! -type d -exec ls -l {} \;|awk ' { u=substr($1,2,3); gsub("\-","",u); g=substr($1,5,3); gsub("\-","",g); o=substr($1,8,3); gsub("\-","",o); print "chmod u="u",g="g",o="o,$NF }' >/tmp/liste.ksh find /etc/ -type d -exec ls -ld {} \;|awk ' { u=substr($1,2,3); gsub("\-","",u); g=substr($1,5,3); gsub("\-","",g); o=substr($1,8,3); gsub("\-","",o); print "chmod u="u",g="g",o="o,$NF }' >>/tmp/liste.ksh ~~~