Quizzer
view release on metacpan or search on metacpan
exercises/compile-tcsh/tcsh-6.10.00/tc.func.c view on Meta::CPAN
{
static char pass[PASSMAX + 1];
int fd, i;
signalfun_t sigint;
sigint = (signalfun_t) sigset(SIGINT, SIG_IGN);
(void) Rawmode(); /* Make sure, cause we want echo off */
if ((fd = open("/dev/tty", O_RDWR)) == -1)
fd = SHIN;
xprintf("%s", prm); flush();
for (i = 0;;) {
if (read(fd, &pass[i], 1) < 1 || pass[i] == '\n')
break;
if (i < PASSMAX)
i++;
}
pass[i] = '\0';
if (fd != SHIN)
(void) close(fd);
(void) sigset(SIGINT, sigint);
return(pass);
}
/*
* Ask the user for his login password to continue working
* On systems that have a shadow password, this will only
* work for root, but what can we do?
*
* If we fail to get the password, then we log the user out
* immediately
*/
/*ARGSUSED*/
static void
auto_lock(n)
int n;
{
#ifndef NO_CRYPT
int i;
char *srpp = NULL;
struct passwd *pw;
#ifdef POSIX
extern char *crypt __P((const char *, const char *));
#else
extern char *crypt __P(());
#endif
#undef XCRYPT
#if defined(PW_AUTH) && !defined(XCRYPT)
struct authorization *apw;
extern char *crypt16 __P((const char *, const char *));
# define XCRYPT(a, b) crypt16(a, b)
if ((pw = getpwuid(euid)) != NULL && /* effective user passwd */
(apw = getauthuid(euid)) != NULL) /* enhanced ultrix passwd */
srpp = apw->a_password;
#endif /* PW_AUTH && !XCRYPT */
#if defined(PW_SHADOW) && !defined(XCRYPT)
struct spwd *spw;
# define XCRYPT(a, b) crypt(a, b)
if ((pw = getpwuid(euid)) != NULL && /* effective user passwd */
(spw = getspnam(pw->pw_name)) != NULL) /* shadowed passwd */
srpp = spw->sp_pwdp;
#endif /* PW_SHADOW && !XCRYPT */
#ifndef XCRYPT
#define XCRYPT(a, b) crypt(a, b)
#if !defined(__MVS__)
if ((pw = getpwuid(euid)) != NULL) /* effective user passwd */
srpp = pw->pw_passwd;
#endif /* !MVS */
#endif /* !XCRYPT */
if (srpp == NULL) {
auto_logout(0);
/*NOTREACHED*/
return;
}
setalarm(0); /* Not for locking any more */
#ifdef BSDSIGS
(void) sigsetmask(sigblock(0) & ~(sigmask(SIGALRM)));
#else /* !BSDSIGS */
(void) sigrelse(SIGALRM);
#endif /* BSDSIGS */
xputchar('\n');
for (i = 0; i < 5; i++) {
const char *crpp;
char *pp;
#ifdef AFS
char *afsname;
Char *safs;
if ((safs = varval(STRafsuser)) != STRNULL)
afsname = short2str(safs);
else
if ((afsname = getenv("AFSUSER")) == NULL)
afsname = pw->pw_name;
#endif
pp = xgetpass("Password:");
crpp = XCRYPT(pp, srpp);
if ((strcmp(crpp, srpp) == 0)
#ifdef AFS
|| (ka_UserAuthenticateGeneral(KA_USERAUTH_VERSION,
afsname, /* name */
NULL, /* instance */
NULL, /* realm */
pp, /* password */
0, /* lifetime */
0, 0, /* spare */
NULL) /* reason */
== 0)
#endif /* AFS */
) {
(void) memset(pp, 0, PASSMAX);
if (GettingInput && !just_signaled) {
(void) Rawmode();
ClearLines();
ClearDisp();
Refresh();
}
just_signaled = 0;
return;
}
xprintf(CGETS(22, 2, "\nIncorrect passwd for %s\n"), pw->pw_name);
}
#endif /* NO_CRYPT */
( run in 1.274 second using v1.01-cache-2.11-cpan-0b5f733616e )