forked from Imagelibrary/rtems
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:
@@ -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>
|
2008-10-14 Tim Cussins <timcussins@eml.cc>
|
||||||
|
|
||||||
PR 1330/cpukit
|
PR 1330/cpukit
|
||||||
|
|||||||
@@ -460,12 +460,14 @@ void rtems_shell_init_issue(void)
|
|||||||
|
|
||||||
if (stat("/etc/issue",&buf)) {
|
if (stat("/etc/issue",&buf)) {
|
||||||
rtems_shell_write_file("/etc/issue",
|
rtems_shell_write_file("/etc/issue",
|
||||||
|
"\n"
|
||||||
"Welcome to @V\\n"
|
"Welcome to @V\\n"
|
||||||
"Login into @S\\n");
|
"Login into @S\\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stat("/etc/issue.net",&buf)) {
|
if (stat("/etc/issue.net",&buf)) {
|
||||||
rtems_shell_write_file("/etc/issue.net",
|
rtems_shell_write_file("/etc/issue.net",
|
||||||
|
"\n"
|
||||||
"Welcome to %v\n"
|
"Welcome to %v\n"
|
||||||
"running on %m\n");
|
"running on %m\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,12 +78,12 @@ static
|
|||||||
#endif
|
#endif
|
||||||
int check_passwd(char *peername)
|
int check_passwd(char *peername)
|
||||||
{
|
{
|
||||||
char *pw;
|
char *pw;
|
||||||
int rval = -1, tmp, retries;
|
int rval = -1, tmp, retries;
|
||||||
struct termios t,told;
|
struct termios t,told;
|
||||||
int restore_flags = 0;
|
int restore_flags = 0;
|
||||||
char buf[30], cryptbuf[21];
|
char buf[30], cryptbuf[21];
|
||||||
char salt[3];
|
char salt[3];
|
||||||
|
|
||||||
if ( !(pw=getenv("TELNETD_PASSWD")) || 0 == strlen(pw) )
|
if ( !(pw=getenv("TELNETD_PASSWD")) || 0 == strlen(pw) )
|
||||||
#ifdef TELNETD_DEFAULT_PASSWD
|
#ifdef TELNETD_DEFAULT_PASSWD
|
||||||
|
|||||||
@@ -85,16 +85,25 @@ void * telnetd_dflt_spawn(
|
|||||||
);
|
);
|
||||||
|
|
||||||
/***********************************************************/
|
/***********************************************************/
|
||||||
rtems_id telnetd_task_id =0;
|
rtems_id telnetd_task_id = 0;
|
||||||
uint32_t telnetd_stack_size =32000;
|
uint32_t telnetd_stack_size = 32000;
|
||||||
rtems_task_priority telnetd_task_priority=0;
|
rtems_task_priority telnetd_task_priority = 0;
|
||||||
int telnetd_dont_spawn =0;
|
bool telnetd_remain_on_caller_stdio = false;
|
||||||
void (*telnetd_shell)(char *, void*)=0;
|
void (*telnetd_shell)(char *, void*) = 0;
|
||||||
void *telnetd_shell_arg =0;
|
void *telnetd_shell_arg = NULL;
|
||||||
void * (*telnetd_spawn_task)(
|
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;
|
char *rval = 0;
|
||||||
#if 0
|
#if 0
|
||||||
@@ -190,7 +199,7 @@ rtems_task_telnetd(void *task_argument)
|
|||||||
char peername[16];
|
char peername[16];
|
||||||
int i=1;
|
int i=1;
|
||||||
int size_adr;
|
int size_adr;
|
||||||
struct shell_args *arg;
|
struct shell_args *arg = NULL;
|
||||||
|
|
||||||
if ((des_socket=socket(PF_INET,SOCK_STREAM,0))<0) {
|
if ((des_socket=socket(PF_INET,SOCK_STREAM,0))<0) {
|
||||||
perror("telnetd:socket");
|
perror("telnetd:socket");
|
||||||
@@ -205,7 +214,7 @@ rtems_task_telnetd(void *task_argument)
|
|||||||
size_adr=sizeof(srv.sin);
|
size_adr=sizeof(srv.sin);
|
||||||
if ((bind(des_socket,&srv.sa,size_adr))<0) {
|
if ((bind(des_socket,&srv.sa,size_adr))<0) {
|
||||||
perror("telnetd:bind");
|
perror("telnetd:bind");
|
||||||
close(des_socket);
|
close(des_socket);
|
||||||
telnetd_task_id=0;
|
telnetd_task_id=0;
|
||||||
rtems_task_delete(RTEMS_SELF);
|
rtems_task_delete(RTEMS_SELF);
|
||||||
};
|
};
|
||||||
@@ -220,17 +229,20 @@ rtems_task_telnetd(void *task_argument)
|
|||||||
* was started from the console anyways..
|
* was started from the console anyways..
|
||||||
*/
|
*/
|
||||||
do {
|
do {
|
||||||
devname = grab_a_Connection(des_socket, &srv, peername, sizeof(peername));
|
if ( telnetd_remain_on_caller_stdio ) {
|
||||||
|
char device_name[32];
|
||||||
if ( !devname ) {
|
ttyname_r( 1, device_name, sizeof(device_name) );
|
||||||
/* if something went wrong, sleep for some time */
|
if ( !telnetd_askForPassword || (0 == check_passwd(arg->peername)) )
|
||||||
sleep(10);
|
telnetd_shell(device_name, telnetd_shell_arg);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ( telnetd_dont_spawn ) {
|
|
||||||
if ( !telnetd_askForPassword || (0 == check_passwd(peername)) )
|
|
||||||
telnetd_shell(devname, telnetd_shell_arg);
|
|
||||||
} else {
|
} 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 = malloc( sizeof(*arg) );
|
||||||
|
|
||||||
arg->devname = devname;
|
arg->devname = devname;
|
||||||
@@ -288,10 +300,10 @@ static int initialize_telnetd(void) {
|
|||||||
int rtems_telnetd_initialize(
|
int rtems_telnetd_initialize(
|
||||||
void (*cmd)(char *, void *),
|
void (*cmd)(char *, void *),
|
||||||
void *arg,
|
void *arg,
|
||||||
int dontSpawn,
|
bool remainOnCallerSTDIO,
|
||||||
size_t stack,
|
size_t stack,
|
||||||
rtems_task_priority priority,
|
rtems_task_priority priority,
|
||||||
int askForPassword
|
bool askForPassword
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
rtems_status_code sc;
|
rtems_status_code sc;
|
||||||
@@ -328,14 +340,15 @@ int rtems_telnetd_initialize(
|
|||||||
}
|
}
|
||||||
if ( priority < 2 )
|
if ( priority < 2 )
|
||||||
priority = 100;
|
priority = 100;
|
||||||
telnetd_task_priority = priority;
|
telnetd_task_priority = priority;
|
||||||
telnetd_dont_spawn = dontSpawn;
|
telnetd_remain_on_caller_stdio = remainOnCallerSTDIO;
|
||||||
|
|
||||||
sc = initialize_telnetd();
|
sc = initialize_telnetd();
|
||||||
if (sc != RTEMS_SUCCESSFUL) return sc;
|
if (sc != RTEMS_SUCCESSFUL) return sc;
|
||||||
|
|
||||||
printf("rtems_telnetd() started with stacksize=%u,priority=%d\n",
|
if ( !telnetd_remain_on_caller_stdio )
|
||||||
(unsigned)telnetd_stack_size,(int)telnetd_task_priority);
|
fprintf(stderr, "rtems_telnetd() started with stacksize=%u,priority=%d\n",
|
||||||
|
(unsigned)telnetd_stack_size,(int)telnetd_task_priority);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,26 +17,31 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Initialize the telnetd subsystem.
|
* This method initializes the telnetd subsystem.
|
||||||
*
|
*
|
||||||
* cmd - function which is the "shell" telnetd invokes
|
* @param[in] cmd is the function which is the "shell" telnetd invokes
|
||||||
* arg - context pointer to cmd
|
* @param[in] arg is the context pointer to cmd
|
||||||
* dontSpawn - TRUE if telnetd takes over this task.
|
* @param[in] remainOnCallerSTDIO is set to TRUE if telnetd takes over the
|
||||||
* FALSE to create another task for the shell.
|
* standard in, out and error associated with task. In this case,
|
||||||
* stack - stack size of spawned task
|
* it will be NOT be listening on any sockets. When this parameters
|
||||||
* priority - initial priority of spawned task
|
* is FALSE the telnetd will create other tasks for the shell
|
||||||
* askForPassword - TRUE if telnetd asks for password
|
* which listen on sockets.
|
||||||
* FALSE to invoke "cmd" with no password check.
|
* @param[in] stack is stack size of spawned task.
|
||||||
* This may be OK if "cmd" includes its own check.
|
* @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(
|
int rtems_telnetd_initialize(
|
||||||
void (*cmd)(char *, void *),
|
void (*cmd)(char *, void *),
|
||||||
void *arg,
|
void *arg,
|
||||||
int dontSpawn,
|
bool remainOnCallerSTDIO,
|
||||||
size_t stack,
|
size_t stack,
|
||||||
rtems_task_priority priority,
|
rtems_task_priority priority,
|
||||||
int askForPassword
|
bool askForPassword
|
||||||
);
|
);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
Reference in New Issue
Block a user