Hi Mark,

I don't know shell scripting, but I put together a PHP script for you.
It loops through the directory, turns the directory name into the user
id, gets the owners userid and does the compare. Doesn't check things
starting with a ".".

Put it into a file on the server and run "php FILENAME" and wait for the
answer.

<?php

// Path to check
$path = "/var/spool/mail";

// Get the directory listing
$dir = dir($path);

// Go through the directory
while(($entry = $dir->read()) != NULL){
  if(substr($entry, 0, 1) != "."){ // Don't check hidden items
    $owner = fileowner($path."/".$entry); // Get the owner
    $id = `id -u $entry`; // Get the ID of the user whos mailbox this is
    if($id != $owner){ // If the ID and owner don't match
      echo "Directory: ".$entry."\n"; // Print it out for Mark to see
    }
  }
}

?>


I think the reason this could have happened is that permissions are set
as the ID of the user (not the username). When the user is deleted, the
permissions don't change ID. When a new user is created, if they assume
the ID of the old person they also get ownership of what they had.

Steve

On Wed, 2007-02-28 at 12:05 +0000, Mark Rogers wrote:
> For some reason, at my hosted server some mailboxes have ended up with 
> the wrong ownership. (It seems to be where the user has been deleted; 
> their files have been allocated to a different user, which seems odd.) 
> This has caused problems with users finding their quota has been used up 
> even though their mailbox is empty.
> 
> Anyway, I have a lot of mailboxes and I want to write a script which 
> will list all the mailboxes not owned by their correct owner. They're 
> all in /var/spool/mail, and should all have a filename that matches the 
> name of the user that owns (or should own) that mailbox. Eg "ls -la" shows:
>     -rw-rw---- 1 markroge admin  1234 Fen 28 12:01 markrogers
>     -rw-rw---- 1 markroge admin  4321 Fen 28 12:01 someoneelse
> (I made up those mailboxes, by the way)
> 
> Note that ls truncates the user name to 8 chars - most of my mailboxes 
> are >8 chars.
> 
> So, suggestions for a script that would list all files which are not 
> correctly owned, like the second file in the above example?
> 
> [If anyone has suggestions as to how this happened I'm also interested 
> in that, of-course, although I'm taking that up with the hosting company.]
> 


_______________________________________________
Peterboro mailing list
[email protected]
https://mailman.lug.org.uk/mailman/listinfo/peterboro

Reply via email to