Linux Help: Permissions of Parent Directories

Discussion in 'PC and I.T support/Advice posts' started by Spinal, Jun 27, 2011.

  1. Spinal

    Spinal Hardcore MB Enthusiast

    Messages:
    4,793
    Joined:
    Sep 14, 2004
    Location:
    Uxbridge
    Car:
    Smart, S320 and C180 with 3-pointed stars amongst others
    This ones a weird one...

    I'm writing a script to check some permissions... that said, the script needs to be written into a GUI-based tool... which is causing a problem or two...

    In essence, the script needs to check file permissions, so assuming you're working in root:
    \Users\root\

    idea is to check all files/directories in the home folder are owned by root and only editable by root... easy:
    ls -lar | grep -v "root root"
    -> gives us any files not owned by root with group root, and similar commands for the permissions. The GUI tool allows for AND, OR and NOT operators.

    Second part I'm having trouble with... need to check that the parent folders are only writable by root...
    so, in the example above,
    \Users\root
    and
    \Users\
    need to only root writable...
    again, not too complex if given a scripting language...

    Problem is, I need to write this as a 1-line command... any ideas of of a command that returns all the parent directories?

    i.e.
    root@~ someCommand .
    would return
    \Users\root
    \Users
    \

    (which I could then pipe into ls, and in turn into grep... normally, while loop would do the trick...)

    M.
     
    Last edited: Jun 27, 2011
  2. Dryce

    Dryce MB Club Veteran

    Messages:
    6,884
    Joined:
    May 17, 2006
    Car:
    ..
    Use 'pwd' and split the returned path. This will give you a path - of sorts.

    One of the problems you have under Unix/Linux is that there may be more than one path - with hard links.
     
  3. Alfie

    Alfie Authorised Forum Sponsor Authorised Forum Sponsor

    Messages:
    7,645
    Joined:
    May 5, 2004
    Location:
    Surrey/Cotswolds
    Car:
    W169 A, W205 C, W451 smart
    Depending on the shell you are using try `echo $cwd`

    And you should be using '/' not '\' as this is used to escape the character.

    Try striping out the current top level filesystem from 'df .' and piping it into 'find' with the -exec switch.
     
  4. Ted

    Ted MB Club Veteran

    Messages:
    5,639
    Joined:
    Feb 26, 2004
    Location:
    Bourton on Dunsmore
    Car:
    SLC 250D AMG Line, Yamaha XVS 1100, Jeep Renegade
    Alfie pretty much has it (not that I write shell scripts)
    Remember that you are returning the owner and group NOT the permissions - i.e. just because a file owner is root, that doesn't mean you automatically have rwx permissions if you are logged in as root.

    And last of all remember unix actually works in octal! :)
     
  5. OP
    OP
    Spinal

    Spinal Hardcore MB Enthusiast

    Messages:
    4,793
    Joined:
    Sep 14, 2004
    Location:
    Uxbridge
    Car:
    Smart, S320 and C180 with 3-pointed stars amongst others
    Great, thanks.

    Re \ vs / - very true, that was a typo from the dark side :p

    Unfortunately, the tool wont let me do recursive things, so using a while/for loop is out.

    I've found a workaround though... I wrote a tiny script that does the checks and returns a 0 or a 1... I'm using the fancy £200k tool to call my script and then report on the return condition...

    Sigh... I was trying to avoid using additional bits and keep it as kosher as possible :p

    M.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.