2008-10-15 Joel Sherrill <joel.sherrill@oarcorp.com>

PR 1331/networking
	* libmisc/shell/shell.c, telnetd/check_passwd.c, telnetd/telnetd.c,
	telnetd/telnetd.h: Improve comments and explanation of options to
	rtems_telnetd_initialize. Add extra newline to login sequence from
	shell.
This commit is contained in:
Joel Sherrill
2008-10-15 17:37:16 +00:00
parent f3b9811b51
commit 1fae7b43d7
5 changed files with 73 additions and 45 deletions

View File

@@ -1,3 +1,11 @@
2008-10-15 Joel Sherrill <joel.sherrill@oarcorp.com>
PR 1331/networking
* libmisc/shell/shell.c, telnetd/check_passwd.c, telnetd/telnetd.c,
telnetd/telnetd.h: Improve comments and explanation of options to
rtems_telnetd_initialize. Add extra newline to login sequence from
shell.
2008-10-14 Tim Cussins <timcussins@eml.cc>
PR 1330/cpukit

View File

@@ -460,12 +460,14 @@ void rtems_shell_init_issue(void)
if (stat("/etc/issue",&buf)) {
rtems_shell_write_file("/etc/issue",
"\n"
"Welcome to @V\\n"
"Login into @S\\n");
}
if (stat("/etc/issue.net",&buf)) {
rtems_shell_write_file("/etc/issue.net",
"\n"
"Welcome to %v\n"
"running on %m\n");
}

View File

@@ -78,12 +78,12 @@ static
#endif
int check_passwd(char *peername)
{
char *pw;
int rval = -1, tmp, retries;
struct termios t,told;
int restore_flags = 0;
char buf[30], cryptbuf[21];
char salt[3];
char *pw;
int rval = -1, tmp, retries;
struct termios t,told;
int restore_flags = 0;
char buf[30], cryptbuf[21];
char salt[3];
if ( !(pw=getenv("TELNETD_PASSWD")) || 0 == strlen(pw) )
#ifdef TELNETD_DEFAULT_PASSWD

View File

@@ -85,16 +85,25 @@ void * telnetd_dflt_spawn(
);
/***********************************************************/
rtems_id telnetd_task_id =0;
uint32_t telnetd_stack_size =32000;
rtems_task_priority telnetd_task_priority=0;
int telnetd_dont_spawn =0;
void (*telnetd_shell)(char *, void*)=0;
void *telnetd_shell_arg =0;
rtems_id telnetd_task_id = 0;
uint32_t telnetd_stack_size = 32000;
rtems_task_priority telnetd_task_priority = 0;
bool telnetd_remain_on_caller_stdio = false;
void (*telnetd_shell)(char *, void*) = 0;
void *telnetd_shell_arg = NULL;
void * (*telnetd_spawn_task)(
const char *, unsigned, unsigned, void (*)(void*), void *) = telnetd_dflt_spawn;
const char *,
unsigned,
unsigned,
void (*)(void*),
void *) = telnetd_dflt_spawn;
static char *grab_a_Connection(int des_socket, uni_sa *srv, char *peername, int sz)
static char *grab_a_Connection(
int des_socket,
uni_sa *srv,
char *peername,
int sz
)
{
char *rval = 0;
#if 0
@@ -190,7 +199,7 @@ rtems_task_telnetd(void *task_argument)
char peername[16];
int i=1;
int size_adr;
struct shell_args *arg;
struct shell_args *arg = NULL;
if ((des_socket=socket(PF_INET,SOCK_STREAM,0))<0) {
perror("telnetd:socket");
@@ -205,7 +214,7 @@ rtems_task_telnetd(void *task_argument)
size_adr=sizeof(srv.sin);
if ((bind(des_socket,&srv.sa,size_adr))<0) {
perror("telnetd:bind");
close(des_socket);
close(des_socket);
telnetd_task_id=0;
rtems_task_delete(RTEMS_SELF);
};
@@ -220,17 +229,20 @@ rtems_task_telnetd(void *task_argument)
* was started from the console anyways..
*/
do {
devname = grab_a_Connection(des_socket, &srv, peername, sizeof(peername));
if ( !devname ) {
/* if something went wrong, sleep for some time */
sleep(10);
continue;
}
if ( telnetd_dont_spawn ) {
if ( !telnetd_askForPassword || (0 == check_passwd(peername)) )
telnetd_shell(devname, telnetd_shell_arg);
if ( telnetd_remain_on_caller_stdio ) {
char device_name[32];
ttyname_r( 1, device_name, sizeof(device_name) );
if ( !telnetd_askForPassword || (0 == check_passwd(arg->peername)) )
telnetd_shell(device_name, telnetd_shell_arg);
} else {
devname = grab_a_Connection(des_socket, &srv, peername, sizeof(peername));
if ( !devname ) {
/* if something went wrong, sleep for some time */
sleep(10);
continue;
}
arg = malloc( sizeof(*arg) );
arg->devname = devname;
@@ -288,10 +300,10 @@ static int initialize_telnetd(void) {
int rtems_telnetd_initialize(
void (*cmd)(char *, void *),
void *arg,
int dontSpawn,
bool remainOnCallerSTDIO,
size_t stack,
rtems_task_priority priority,
int askForPassword
bool askForPassword
)
{
rtems_status_code sc;
@@ -328,14 +340,15 @@ int rtems_telnetd_initialize(
}
if ( priority < 2 )
priority = 100;
telnetd_task_priority = priority;
telnetd_dont_spawn = dontSpawn;
telnetd_task_priority = priority;
telnetd_remain_on_caller_stdio = remainOnCallerSTDIO;
sc = initialize_telnetd();
if (sc != RTEMS_SUCCESSFUL) return sc;
printf("rtems_telnetd() started with stacksize=%u,priority=%d\n",
(unsigned)telnetd_stack_size,(int)telnetd_task_priority);
if ( !telnetd_remain_on_caller_stdio )
fprintf(stderr, "rtems_telnetd() started with stacksize=%u,priority=%d\n",
(unsigned)telnetd_stack_size,(int)telnetd_task_priority);
return 0;
}

View File

@@ -17,26 +17,31 @@
extern "C" {
#endif
/*
* Initialize the telnetd subsystem.
/**
* This method initializes the telnetd subsystem.
*
* cmd - function which is the "shell" telnetd invokes
* arg - context pointer to cmd
* dontSpawn - TRUE if telnetd takes over this task.
* FALSE to create another task for the shell.
* stack - stack size of spawned task
* priority - initial priority of spawned task
* askForPassword - TRUE if telnetd asks for password
* FALSE to invoke "cmd" with no password check.
* This may be OK if "cmd" includes its own check.
* @param[in] cmd is the function which is the "shell" telnetd invokes
* @param[in] arg is the context pointer to cmd
* @param[in] remainOnCallerSTDIO is set to TRUE if telnetd takes over the
* standard in, out and error associated with task. In this case,
* it will be NOT be listening on any sockets. When this parameters
* is FALSE the telnetd will create other tasks for the shell
* which listen on sockets.
* @param[in] stack is stack size of spawned task.
* @param[in] priority is the initial priority of spawned task(s). If
* this parameter is less than 2, then the default priority of 100 is used.
* @param[in] askForPassword is set to TRUE if telnetd is to ask for a
* password. This is set to FALSE to invoke "cmd" with no password check.
* This may be OK if "cmd" includes its own check and indeed the RTEMS Shell
* uses a login with a user name and password so this is the usual case.
*/
int rtems_telnetd_initialize(
void (*cmd)(char *, void *),
void *arg,
int dontSpawn,
bool remainOnCallerSTDIO,
size_t stack,
rtems_task_priority priority,
int askForPassword
bool askForPassword
);
#ifdef __cplusplus