Regex para encontrar sistemas de arquivos NFS que não estão sendo montados com nosuid, exceto para aqueles com necessidades especiais

2

Eu tenho um script que executa o comando mount -v 2>/some/file , que depois analiso com outro script usando o seguinte regex:

^.*[\ \t]+type[\ \t]+nfs(?![\ \t]+.*\b(?:nosuid|nosetuid)\b).*

O problema que estou tendo é o seguinte: há algumas montagens do NFS que têm exceções excluindo-as de serem montadas com nosuid (eles são repositórios do Solaris 11 IPS). Agora preciso modificar meu regex para excluir uma montagem conhecida ...

Para fornecer um ponto de referência, aqui está um exemplo de saída de mount -v :

$ mount -v
/dev/dsk/c1t0d0s0                 on  /                  type  ufs      read/write/setuid/devices/rstchown/intr/largefiles/logging/xattr/onerror=panic/dev=840000  on  Fri  Sep  6   12:10:35  2013
/devices                          on  /devices           type  devfs    read/write/setuid/devices/rstchown/dev=4c00000                                             on  Fri  Sep  6   12:10:25  2013
ctfs                              on  /system/contract   type  ctfs     read/write/setuid/devices/rstchown/dev=4c80001                                             on  Fri  Sep  6   12:10:25  2013
proc                              on  /proc              type  proc     read/write/setuid/devices/rstchown/dev=4c40000                                             on  Fri  Sep  6   12:10:25  2013
mnttab                            on  /etc/mnttab        type  mntfs    read/write/setuid/devices/rstchown/dev=4cc0001                                             on  Fri  Sep  6   12:10:25  2013
swap                              on  /etc/svc/volatile  type  tmpfs    read/write/setuid/devices/rstchown/xattr/dev=4d00001                                       on  Fri  Sep  6   12:10:25  2013
objfs                             on  /system/object     type  objfs    read/write/setuid/devices/rstchown/dev=4d40001                                             on  Fri  Sep  6   12:10:25  2013
sharefs                           on  /etc/dfs/sharetab  type  sharefs  read/write/setuid/devices/rstchown/dev=4d80001                                             on  Fri  Sep  6   12:10:25  2013
/usr/lib/libc/libc_hwcap1.so.1    on  /lib/libc.so.1     type  lofs     read/write/setuid/devices/rstchown/dev=840000                                              on  Fri  Sep  6   12:10:31  2013
fd                                on  /dev/fd            type  fd       read/write/setuid/devices/rstchown/dev=4f00001                                             on  Fri  Sep  6   12:10:35  2013
swap                              on  /tmp               type  tmpfs    read/write/setuid/devices/rstchown/xattr/dev=4d00002                                       on  Fri  Sep  6   12:10:38  2013
swap                              on  /var/run           type  tmpfs    read/write/setuid/devices/rstchown/xattr/dev=4d00003                                       on  Fri  Sep  6   12:10:38  2013
/dev/dsk/c1t0d0s7                 on  /export/home       type  ufs      read/write/setuid/devices/rstchown/intr/largefiles/logging/xattr/onerror=panic/dev=840007  on  Fri  Sep  6   12:10:44  2013
sample-ips:/ips/blargSolaris11.1  on  /blargSolaris11.1  type  nfs      remote/read/write/setuid/devices/rstchown/soft/xattr/dev=8c00001                           on  Tue  Sep  10  12:07:46  2013

Eu tentei modificar o regex para excluir a montagem do IP com base na correspondência da montagem no início da linha da seguinte forma:

^(.*|[^sample])[\ \t]+type[\ \t]+nfs(?![\ \t]+.*\b(?:nosuid|nosetuid)\b).*

Mas não está funcionando ...

    
por Dallas Moore 25.09.2013 / 22:36

1 resposta

2

Não tenho certeza do que você está fazendo com essa expressão regular, mas parece bem para mim. Parece ser o Perl, então usando a versão GNU do switch -P do grep eu usei o seu regex da seguinte forma:

$ column -t mount.txt | \
     grep -vP '^(.*|[^sample])[\ \t]+type[\ \t]+nfs(?![\ \t]+.*\b(?:nosuid|nosetuid)\b).*'

Exemplo

$ column -t mount.txt | \
     grep -vP '^(.*|[^sample])[\ \t]+type[\ \t]+nfs(?![\ \t]+.*\b(?:nosuid|nosetuid)\b).*'
/dev/dsk/c1t0d0s0                 on  /                  type  ufs      read/write/setuid/devices/rstchown/intr/largefiles/logging/xattr/onerror=panic/dev=840000  on  Fri  Sep  6   12:10:35  2013
/devices                          on  /devices           type  devfs    read/write/setuid/devices/rstchown/dev=4c00000                                             on  Fri  Sep  6   12:10:25  2013
ctfs                              on  /system/contract   type  ctfs     read/write/setuid/devices/rstchown/dev=4c80001                                             on  Fri  Sep  6   12:10:25  2013
proc                              on  /proc              type  proc     read/write/setuid/devices/rstchown/dev=4c40000                                             on  Fri  Sep  6   12:10:25  2013
mnttab                            on  /etc/mnttab        type  mntfs    read/write/setuid/devices/rstchown/dev=4cc0001                                             on  Fri  Sep  6   12:10:25  2013
swap                              on  /etc/svc/volatile  type  tmpfs    read/write/setuid/devices/rstchown/xattr/dev=4d00001                                       on  Fri  Sep  6   12:10:25  2013
objfs                             on  /system/object     type  objfs    read/write/setuid/devices/rstchown/dev=4d40001                                             on  Fri  Sep  6   12:10:25  2013
sharefs                           on  /etc/dfs/sharetab  type  sharefs  read/write/setuid/devices/rstchown/dev=4d80001                                             on  Fri  Sep  6   12:10:25  2013
/usr/lib/libc/libc_hwcap1.so.1    on  /lib/libc.so.1     type  lofs     read/write/setuid/devices/rstchown/dev=840000                                              on  Fri  Sep  6   12:10:31  2013
fd                                on  /dev/fd            type  fd       read/write/setuid/devices/rstchown/dev=4f00001                                             on  Fri  Sep  6   12:10:35  2013
swap                              on  /tmp               type  tmpfs    read/write/setuid/devices/rstchown/xattr/dev=4d00002                                       on  Fri  Sep  6   12:10:38  2013
swap                              on  /var/run           type  tmpfs    read/write/setuid/devices/rstchown/xattr/dev=4d00003                                       on  Fri  Sep  6   12:10:38  2013
/dev/dsk/c1t0d0s7                 on  /export/home       type  ufs      read/write/setuid/devices/rstchown/intr/largefiles/logging/xattr/onerror=panic/dev=840007  on  Fri  Sep  6   12:10:44  2013

Você notará que a linha que começa com sample-ips:/ips/blargSolaris11.1 está sendo filtrada conforme pretendido.

    
por 26.09.2013 / 02:50