📄 dcplib.c
字号:
/* We have a user id, now get a password */
/*--------------------------------------------------------------------*/
wmsg("\r\nPassword: ", 0);
strcpy(pswd,"");
if (rmsg(pswd, 0, 30, sizeof pswd) == TIMEOUT)
return FALSE;
/*--------------------------------------------------------------------*/
/* Zap unprintable characters before we log the password */
/*--------------------------------------------------------------------*/
printmsg(14, "login: password=%s", pswd);
/*--------------------------------------------------------------------*/
/* Validate the user id and passowrd */
/*--------------------------------------------------------------------*/
userp = checkuser(user); /* Locate user id in host table */
if (userp == BADUSER) /* Does user id exist? */
{ /* No --> Notify the user */
wmsg("\r\nlogin failed",0);
token = user;
while (!isalnum( *token ) && (*token != '\0'))
token ++; /* Scan for first alpha-numeric */
if (*token != '\0') /* If at least one good char */
printmsg(0,"login: login for user %s failed, bad user id",
user); /* Log the error for ourselves */
}
else if ( equal(pswd,userp->password)) /* Correct password? */
{ /* Yes --> Log the user "in" */
/* . . ..+....1.... +....2....+....3.... + . */
sprintf(line,"\r\n\nWelcome to %s; login complete at %s\r\n",
E_domain, arpadate());
wmsg(line, 0);
printmsg(0,"login: login user %s (%s) at %s",
userp->uid, userp->realname, arpadate());
if equal(userp->sh,UUCPSHELL) /* Standard uucp shell? */
{
securep = userp->hsecure;
printmsg(5,"Processing user via %s", UUCPSHELL);
return TRUE; /* Yes --> Startup the machine */
}
else { /* No --> run special shell */
if ( E_motd != NULL )
motd( E_motd, line, sizeof line );
LoginShell( userp );
return FALSE; /* Hang up phone and exit */
}
}
else { /* Password was wrong. Report */
wmsg("\r\nlogin failed",0);
printmsg(0,"login: login user %s (%s) failed, bad password %s",
userp->uid, userp->realname, pswd);
}
} /* for */
/*-----------------------------------------------------------------*/
/* If we fall through the loop, we have an excessive number of */
/* login attempts; hangup the telephone and try again. */
/*-----------------------------------------------------------------*/
return FALSE; /* Exit processing */
} /*login*/
/*--------------------------------------------------------------------*/
/* l o g i n b y p a s s */
/* */
/* Initialize user setup when login is bypassed */
/*--------------------------------------------------------------------*/
boolean loginbypass(const char *user)
{
struct UserTable *userp;
char line[BUFSIZ]; /* Allow for long domain names! */
printmsg(14, "loginbypass: login=%s", user);
/*--------------------------------------------------------------------*/
/* Validate the user id */
/*--------------------------------------------------------------------*/
userp = checkuser(user); /* Locate user id in host table */
if (userp == BADUSER) /* Does user id exist? */
{ /* No --> Notify the user */
wmsg("\r\nUUCICO login failed",0);
printmsg(0,"loginbypass: login for user %s failed, bad user id",
user); /* Log the error for ourselves */
return FALSE; /* Hang up phone and exit */
}
else {
/* Yes --> Log the user "in" */
/* . . ..+....1.... +....2....+....3.... + . */
sprintf(line,"\r\n\nWelcome to %s; login complete at %s\r\n",
E_domain, arpadate());
wmsg(line, 0);
printmsg(0,"loginbypass: login user %s (%s) at %s",
userp->uid, userp->realname, arpadate());
if equal(userp->sh,UUCPSHELL) /* Standard uucp shell? */
{
securep = userp->hsecure;
return TRUE; /* Yes --> Startup the machine */
} /* if equal(userp->sh,UUCPSHELL) */
else { /* No --> run special shell */
LoginShell( userp );
return FALSE; /* Hang up phone and exit */
} /* else */
} /* else */
} /*loginbypass*/
/*--------------------------------------------------------------------*/
/* L o g i n S h e l l */
/* */
/* Execute a non-default remote user shell */
/*--------------------------------------------------------------------*/
static void LoginShell( const struct UserTable *userp )
{
#if defined(_Windows)
char line[128];
//
// No special shell support under Windows, sorry!
//
sprintf(line,
"login: special shell %s not supported. Goodbye.\r\n",
userp->sh);
wmsg(line, 0);
printmsg(0, "Login with special shell %s, not supported.", userp->sh);
return;
#else
char *shellstring;
char *path;
char *args;
int rc;
/*--------------------------------------------------------------------*/
/* Get the program to run and its arguments */
/*--------------------------------------------------------------------*/
shellstring = strdup(userp->sh);
/* Copy user shell for parsing */
path = strtok(shellstring," \t"); /* Get program name */
args = strtok(NULL,""); /* Get rest of arg string */
printmsg(1,"LoginShell: Invoking %s in directory %s",
userp->sh, userp->homedir);
ddelay(250); /* Wait for port to stablize */
/*--------------------------------------------------------------------*/
/* Run the requested program in the user's home directory */
/*--------------------------------------------------------------------*/
PushDir(userp->homedir);/* Switch to user's home dir */
if (args == NULL)
rc = spawnl(P_WAIT, path, path, NULL);
else
rc = spawnl(P_WAIT, path, path, args, NULL);
PopDir(); /* Return to original directory */
/*--------------------------------------------------------------------*/
/* Report any errors we found */
/*--------------------------------------------------------------------*/
if ( rc < 0 ) /* Error condition? */
{ /* Yes --> Report it to the user */
printmsg(0,"LoginShell: Unable to execute user shell");
printerr(path);
}
else /* No --> Report normal result */
printmsg(rc == 0 ? 4 : 0,"LoginShell: %s return code is %d",
path,
rc);
#endif
} /* LoginShell */
/*--------------------------------------------------------------------*/
/* m o t d */
/* */
/* Display a message of the day to the remote login */
/*--------------------------------------------------------------------*/
void motd( const char *fname, char *buf, const int bufsiz )
{
FILE *stream = FOPEN( fname, "r", BINARY_MODE ); /* Leave CRLF in data */
if ( stream == NULL )
{
perror( fname );
wmsg( fname,0 );
wmsg( ": ", 0);
wmsg( strerror( errno ),0);
wmsg( "\n\r",0);
return;
} /* if ( stream == NULL ) */
while( fgets( buf, bufsiz, stream ) != NULL )
wmsg( buf, 0 );
fclose( stream );
} /* motd */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -