unixauth/unixauth.c

/* [<][>]
[^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following functions.
  1. main

/* $Id: unixauth.c,v 1.3 2000/02/19 16:20:56 proff Exp $
 * $Copyright$
 */

/*
 * simple setuid program to test a password; run as "unixauth user"
 * and pass write the argument as input.  it will exit(0) for a
 * valid user and exit(1) else for invalid.  run this to test a
 * authentication when passwords are secret in /etc/shadow, 
 * /etc/master.passwd, etc.
 */

#include "standard.h"
#include "password.h"

/* ugh! */
#ifdef HAVE_LIBWRAP
int deny_severity;
int accept_severity;
#endif

int main (int argc, char **argv, char **envp)
/* [<][>][^][v][top][bottom][index][help] */
{
        char pass[256];
#ifdef HAVE_GETSPNAM
        struct spwd *spw;
#else
        struct passwd *pw;
#endif
        sleep(1);
        if ((argc == 2)
         && fgets(pass, sizeof pass, stdin) != NULL
         && pass[0]
#ifdef HAVE_GETSPNAM
         && (spw = getspnam(argv[1]))
         && strcmp(crypt(pass, spw->sp_pwdp), spw->sp_pwdp) == 0)
#else
         && (pw = getpwnam(argv[1]))
         && strcmp(crypt(pass, pw->pw_passwd), pw->pw_passwd) == 0)
#endif
        {
                exit(0);
        }
        sleep(4);
        exit(1);
}

/* [<][>][^][v][top][bottom][index][help] */