summaryrefslogtreecommitdiffstats
path: root/cpukit/telnetd
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2008-10-15 17:37:16 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2008-10-15 17:37:16 +0000
commit1fae7b43d751ca803b12f63d4dfc074f0de8e613 (patch)
tree8dcc632d0a164f8ae4ab0603c7650f66a53fa8d7 /cpukit/telnetd
parentRemove. (diff)
downloadrtems-1fae7b43d751ca803b12f63d4dfc074f0de8e613.tar.bz2
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.
Diffstat (limited to 'cpukit/telnetd')
-rw-r--r--cpukit/telnetd/check_passwd.c12
-rw-r--r--cpukit/telnetd/telnetd.c67
-rw-r--r--cpukit/telnetd/telnetd.h31
3 files changed, 64 insertions, 46 deletions
diff --git a/cpukit/telnetd/check_passwd.c b/cpukit/telnetd/check_passwd.c
index e1df00d2d9..8486058fa0 100644
--- a/cpukit/telnetd/check_passwd.c
+++ b/cpukit/telnetd/check_passwd.c
@@ -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
diff --git a/cpukit/telnetd/telnetd.c b/cpukit/telnetd/telnetd.c
index 1c76e63dc6..7593fdca46 100644
--- a/cpukit/telnetd/telnetd.c
+++ b/cpukit/telnetd/telnetd.c
@@ -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;
-
-static char *grab_a_Connection(int des_socket, uni_sa *srv, char *peername, int sz)
+ 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
+)
{
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;
}
diff --git a/cpukit/telnetd/telnetd.h b/cpukit/telnetd/telnetd.h
index afebd20a16..db0ea94162 100644
--- a/cpukit/telnetd/telnetd.h
+++ b/cpukit/telnetd/telnetd.h
@@ -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