/* check-dirs.c - Check for security hazards
 *
 * Copyright (C) 2001 Alan Shutko
 *
 * 
 * Description:
 * 
 *  This program tries to check for home directories which are writable
 *  by groups or other users.  The intent is to catch vulnerabilities
 *  on multiuser systems where another user could toss in a .rhost
 *  file and break into an account.
 * 
 * History:
 * ats     2/26/01    Created
 *
 * Tokens: ::Header:: check-dirs.h
 */

#ifndef lint
static char *rcsid = "$Header: /hubert/shared/CVS/ats/hacks/check-dirs.c,v 1.2 2001/02/28 17:02:14 ats Exp $";
#endif

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <pwd.h>

int main(int argc, char **argv)
{
    struct stat dir;
    int i;
    uid_t me;
    gid_t mygid;
    struct passwd *pwent;
    
    me = getuid();
    pwent = getpwuid(me);
    mygid = pwent->pw_gid;
    
    for (i = 1; pwent = getpwent(); i++)
    {
        if (lstat(pwent->pw_dir, &dir))
            continue;

        if ((S_ISDIR(dir.st_mode)))
            if ( (dir.st_mode & S_IWOTH) ||
                 (dir.st_mode & S_IWGRP))
                printf("%s\n", pwent->pw_dir);
    }
    printf("%d dirs checked.\n", i);
    exit(0);
}
