cpukit: Remove telnetd

Update #3850
This commit is contained in:
Vijay Kumar Banerjee
2021-04-07 16:15:39 -06:00
parent 3dca9ed92b
commit 3299dda245
15 changed files with 0 additions and 2165 deletions
-23
View File
@@ -1,23 +0,0 @@
Author: fernando.ruiz@ctv.es (correo@fernando-ruiz.com)
This directory contains a telnetd server
primary features:
+ create a user shell pseudo-terminal task.
This code has not been extensively tested. It is provided as a tool
for RTEMS users to open more shell tcp/ip pseudo-terminal.
Suggestions and comments are appreciated.
Read libmisc/shell for more information.
NOTES:
1. OOB not yet implemented. Only a reduced negotiation is implemented.
2. If you have tcp/ip initialied you can start telnetd daemon.
You need register pseudo-terminals driver into device drivers table.
Enjoy it.
FUTURE:
-106
View File
@@ -1,106 +0,0 @@
/*
* Authorship
* ----------
* This software was created by
* Till Straumann <strauman@slac.stanford.edu>, 2003-2007
* Stanford Linear Accelerator Center, Stanford University.
*
* Acknowledgement of sponsorship
* ------------------------------
* This software was produced by
* the Stanford Linear Accelerator Center, Stanford University,
* under Contract DE-AC03-76SFO0515 with the Department of Energy.
*
* Government disclaimer of liability
* ----------------------------------
* Neither the United States nor the United States Department of Energy,
* nor any of their employees, makes any warranty, express or implied, or
* assumes any legal liability or responsibility for the accuracy,
* completeness, or usefulness of any data, apparatus, product, or process
* disclosed, or represents that its use would not infringe privately owned
* rights.
*
* Stanford disclaimer of liability
* --------------------------------
* Stanford University makes no representations or warranties, express or
* implied, nor assumes any liability for the use of this software.
*
* Stanford disclaimer of copyright
* --------------------------------
* Stanford University, owner of the copyright, hereby disclaims its
* copyright and all other rights in this software. Hence, anyone may
* freely use it for any purpose without restriction.
*
* Maintenance of notices
* ----------------------
* In the interest of clarity regarding the origin and status of this
* SLAC software, this and all the preceding Stanford University notices
* are to remain affixed to any copy or derivative of this software made
* or distributed by the recipient and are to be affixed to any copy of
* software made or distributed by the recipient that contains a copy or
* derivative of this software.
*
* ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
*
* Copyright (c) 2009 embedded brains GmbH and others.
*
* embedded brains GmbH
* Obere Lagerstr. 30
* D-82178 Puchheim
* Germany
* <rtems@embedded-brains.de>
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <termios.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <rtems/telnetd.h>
#include "des.h"
#include <rtems/passwd.h>
/**
* @brief Standard Telnet login check that uses DES to encrypt the passphrase.
*
* Takes a @a passphrase, encrypts it and compares it to the encrypted
* passphrase in the @c TELNETD_PASSWD environment variable. No password is
* required if @c TELNETD_PASSWD is unset. The argument @a user is ignored.
*/
bool rtems_telnetd_login_check(
const char *user,
const char *passphrase
)
{
char *pw = getenv( "TELNETD_PASSWD");
char cryptbuf [21];
char salt [3];
if (pw == NULL || strlen( pw) == 0) {
#ifdef TELNETD_DEFAULT_PASSWD
pw = TELNETD_DEFAULT_PASSWD;
#else
return true;
#endif
}
strncpy( salt, pw, 2);
salt [2] = '\0';
return strcmp(
__des_crypt_r( passphrase, salt, cryptbuf, sizeof( cryptbuf)),
pw
) == 0;
}
File diff suppressed because it is too large Load Diff
-1
View File
@@ -1 +0,0 @@
char *__des_crypt_r(const char *, const char *, char *, int);
-79
View File
@@ -1,79 +0,0 @@
/*
* Authorship
* ----------
* This software was created by
* Till Straumann <strauman@slac.stanford.edu>, 2003-2007
* Stanford Linear Accelerator Center, Stanford University.
*
* Acknowledgement of sponsorship
* ------------------------------
* This software was produced by
* the Stanford Linear Accelerator Center, Stanford University,
* under Contract DE-AC03-76SFO0515 with the Department of Energy.
*
* Government disclaimer of liability
* ----------------------------------
* Neither the United States nor the United States Department of Energy,
* nor any of their employees, makes any warranty, express or implied, or
* assumes any legal liability or responsibility for the accuracy,
* completeness, or usefulness of any data, apparatus, product, or process
* disclosed, or represents that its use would not infringe privately owned
* rights.
*
* Stanford disclaimer of liability
* --------------------------------
* Stanford University makes no representations or warranties, express or
* implied, nor assumes any liability for the use of this software.
*
* Stanford disclaimer of copyright
* --------------------------------
* Stanford University, owner of the copyright, hereby disclaims its
* copyright and all other rights in this software. Hence, anyone may
* freely use it for any purpose without restriction.
*
* Maintenance of notices
* ----------------------
* In the interest of clarity regarding the origin and status of this
* SLAC software, this and all the preceding Stanford University notices
* are to remain affixed to any copy or derivative of this software made
* or distributed by the recipient and are to be affixed to any copy of
* software made or distributed by the recipient that contains a copy or
* derivative of this software.
*
* ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <crypt.h>
#include <stdio.h>
#include <unistd.h>
static void
usage(char *nm)
{
fprintf(stderr,"Usage: %s [-h] [-s salt] cleartext_password\n", nm);
}
int
main(int argc, char **argv)
{
int ch;
char *salt="td";
while ( (ch=getopt(argc, argv, "hs:")) >=0 ) {
switch (ch) {
default: fprintf(stderr,"Unknown Option '%c'\n",ch);
case 'h': usage(argv[0]);
return 0;
case 's': salt=optarg;
break;
}
}
if ( optind >= argc ) {
usage(argv[0]);
return 1;
}
printf("#define TELNETD_DEFAULT_PASSWD \"%s\"\n",crypt(argv[optind],salt));
}
-401
View File
@@ -1,401 +0,0 @@
/*
* /dev/ptyXX (Support for pseudo-terminals)
*
* Original Author: Fernando RUIZ CASAS (fernando.ruiz@ctv.es)
* May 2001
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* Till Straumann <strauman@slac.stanford.edu>
*
* - converted into a loadable module
* - NAWS support / ioctls for querying/setting the window
* size added.
* - don't delete the running task when the connection
* is closed. Rather let 'read()' return a 0 count so
* they may cleanup. Some magic hack works around termios
* limitation.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define DEBUG_WH (1<<0)
#define DEBUG_DETAIL (1<<1)
/* #define DEBUG DEBUG_WH */
/*-----------------------------------------*/
#include <sys/ttycom.h>
#include <rtems/pty.h>
#include <rtems/seterr.h>
#include <errno.h>
#include <sys/socket.h>
/*-----------------------------------------*/
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
/*-----------------------------------------*/
#define IAC_ESC 255
#define IAC_DONT 254
#define IAC_DO 253
#define IAC_WONT 252
#define IAC_WILL 251
#define IAC_SB 250
#define IAC_GA 249
#define IAC_EL 248
#define IAC_EC 247
#define IAC_AYT 246
#define IAC_AO 245
#define IAC_IP 244
#define IAC_BRK 243
#define IAC_DMARK 242
#define IAC_NOP 241
#define IAC_SE 240
#define IAC_EOR 239
#define SB_MAX RTEMS_PTY_SB_MAX
static bool ptyPollInitialize(rtems_termios_tty *,
rtems_termios_device_context *, struct termios *,
rtems_libio_open_close_args_t *);
static void ptyShutdown(rtems_termios_tty *,
rtems_termios_device_context *, rtems_libio_open_close_args_t *);
static void ptyPollWrite(rtems_termios_device_context *, const char *, size_t);
static int ptyPollRead(rtems_termios_device_context *);
static bool ptySetAttributes(rtems_termios_device_context *,
const struct termios *);
static int my_pty_control(rtems_termios_device_context *,
ioctl_command_t, void *);
static const rtems_termios_device_handler pty_handler = {
.first_open = ptyPollInitialize,
.last_close = ptyShutdown,
.poll_read = ptyPollRead,
.write = ptyPollWrite,
.set_attributes = ptySetAttributes,
.ioctl = my_pty_control
};
static
int send_iac(rtems_pty_context *pty, unsigned char mode, unsigned char option)
{
unsigned char buf[3];
buf[0]=IAC_ESC;
buf[1]=mode;
buf[2]=option;
return write(pty->socket, buf, sizeof(buf));
}
const char *rtems_pty_initialize(rtems_pty_context *pty, uintptr_t unique)
{
rtems_status_code sc;
memset(pty, 0, sizeof(*pty));
(void)snprintf(pty->name, sizeof(pty->name), "/dev/pty%" PRIuPTR, unique);
rtems_termios_device_context_initialize(&pty->base, "pty");
pty->socket = -1;
sc = rtems_termios_device_install(pty->name, &pty_handler, NULL, &pty->base);
if (sc != RTEMS_SUCCESSFUL) {
return NULL;
}
return pty->name;
}
void rtems_pty_close_socket(rtems_pty_context *pty)
{
if (pty->socket >= 0) {
(void)close(pty->socket);
pty->socket = -1;
}
}
void rtems_pty_set_socket(rtems_pty_context *pty, int socket)
{
struct timeval t;
rtems_pty_close_socket(pty);
pty->socket = socket;
/* set a long polling interval to save CPU time */
t.tv_sec=2;
t.tv_usec=00000;
(void)setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, &t, sizeof(t));
/* inform the client that we will echo */
send_iac(pty, IAC_WILL, 1);
}
/*-----------------------------------------------------------*/
/*
* The NVT terminal is negociated in PollRead and PollWrite
* with every BYTE sendded or received.
* A litle status machine in the pty_read_byte(int minor)
*
*/
static const char IAC_AYT_RSP[]="\r\nAYT? Yes, RTEMS-SHELL is here\r\n";
static const char IAC_BRK_RSP[]="<*Break*>";
static const char IAC_IP_RSP []="<*Interrupt*>";
static int
handleSB(rtems_pty_context *pty)
{
switch (pty->sb_buf[0]) {
case 31: /* NAWS */
pty->width = (pty->sb_buf[1]<<8) + pty->sb_buf[2];
pty->height = (pty->sb_buf[3]<<8) + pty->sb_buf[4];
#if DEBUG & DEBUG_WH
fprintf(stderr,
"Setting width/height to %ix%i\n",
pty->width,
pty->height);
#endif
break;
default:
break;
}
return 0;
}
static int ptyPollRead(rtems_termios_device_context *base)
{ /* Characters written to the client side*/
rtems_pty_context *pty = (rtems_pty_context *)base;
unsigned char value;
unsigned int omod;
int count;
int result;
count=read(pty->socket,&value,sizeof(value));
if (count<0)
return -1;
if (count<1) {
/* Unfortunately, there is no way of passing an EOF
* condition through the termios driver. Hence, we
* resort to an ugly hack. Setting cindex>ccount
* causes the termios driver to return a read count
* of '0' which is what we want here. We leave
* 'errno' untouched.
*/
pty->ttyp->cindex=pty->ttyp->ccount+1;
return pty->ttyp->termios.c_cc[VEOF];
};
omod=pty->iac_mode;
pty->iac_mode=0;
switch(omod & 0xff) {
case IAC_ESC:
switch(value) {
case IAC_ESC :
/* in case this is an ESC ESC sequence in SB mode */
pty->iac_mode = omod>>8;
return IAC_ESC;
case IAC_DONT:
case IAC_DO :
case IAC_WONT:
case IAC_WILL:
pty->iac_mode=value;
return -1;
case IAC_SB :
#if DEBUG & DEBUG_DETAIL
printk("SB\n");
#endif
pty->iac_mode=value;
pty->sb_ind=0;
return -100;
case IAC_GA :
return -1;
case IAC_EL :
return 0x03; /* Ctrl-C*/
case IAC_EC :
return '\b';
case IAC_AYT :
write(pty->socket,IAC_AYT_RSP,strlen(IAC_AYT_RSP));
return -1;
case IAC_AO :
return -1;
case IAC_IP :
write(pty->socket,IAC_IP_RSP,strlen(IAC_IP_RSP));
return -1;
case IAC_BRK :
write(pty->socket,IAC_BRK_RSP,strlen(IAC_BRK_RSP));
return -1;
case IAC_DMARK:
return -2;
case IAC_NOP :
return -1;
case IAC_SE :
#if DEBUG & DEBUG_DETAIL
{
int i;
printk("SE");
for (i=0; i<pty->sb_ind; i++)
printk(" %02x",pty->sb_buf[i]);
printk("\n");
}
#endif
handleSB(pty);
return -101;
case IAC_EOR :
return -102;
default :
return -1;
};
break;
case IAC_SB:
pty->iac_mode=omod;
if (IAC_ESC==value) {
pty->iac_mode=(omod<<8)|value;
} else {
if (pty->sb_ind < SB_MAX)
pty->sb_buf[pty->sb_ind++]=value;
}
return -1;
case IAC_WILL:
if (value==34){
send_iac(pty,IAC_DONT, 34); /*LINEMODE*/
send_iac(pty,IAC_DO , 1); /*ECHO */
} else if (value==31) {
send_iac(pty,IAC_DO , 31); /*NAWS */
#if DEBUG & DEBUG_DETAIL
printk("replied DO NAWS\n");
#endif
} else {
send_iac(pty,IAC_DONT,value);
}
return -1;
case IAC_DONT:
return -1;
case IAC_DO :
if (value==3) {
send_iac(pty,IAC_WILL, 3); /* GO AHEAD*/
} else if (value==1) {
send_iac(pty,IAC_WILL, 1); /* ECHO */
} else {
send_iac(pty,IAC_WONT,value);
};
return -1;
case IAC_WONT:
if (value==1) {
send_iac(pty,IAC_WILL, 1);
} else { /* ECHO */
send_iac(pty,IAC_WONT,value);
}
return -1;
default:
if (value==IAC_ESC) {
pty->iac_mode=value;
return -1;
} else {
result=value;
if ( 0
/* map CRLF to CR for symmetry */
|| ((value=='\n') && pty->last_cr)
/* map telnet CRNUL to CR down here */
|| ((value==0) && pty->last_cr)
) result=-1;
pty->last_cr=(value=='\r');
return result;
};
};
/* should never get here but keep compiler happy */
return -1;
}
/*-----------------------------------------------------------*/
/* Set the 'Hardware' */
/*-----------------------------------------------------------*/
static bool
ptySetAttributes(rtems_termios_device_context *base, const struct termios *t)
{
rtems_pty_context *pty = (rtems_pty_context *)base;
pty->c_cflag = t->c_cflag;
return true;
}
/*-----------------------------------------------------------*/
static bool
ptyPollInitialize(rtems_termios_tty *ttyp,
rtems_termios_device_context *base, struct termios *t,
rtems_libio_open_close_args_t *args)
{
rtems_pty_context *pty = (rtems_pty_context *)base;
pty->ttyp = ttyp;
pty->iac_mode = 0;
pty->sb_ind = 0;
pty->width = 0;
pty->height = 0;
return ptySetAttributes(&pty->base, t);
}
/*-----------------------------------------------------------*/
static void
ptyShutdown(rtems_termios_tty *ttyp,
rtems_termios_device_context *base, rtems_libio_open_close_args_t *arg)
{
rtems_pty_context *pty = (rtems_pty_context *)base;
close(pty->socket);
}
/*-----------------------------------------------------------*/
/* Write Characters into pty device */
/*-----------------------------------------------------------*/
static void
ptyPollWrite(rtems_termios_device_context *base, const char *buf, size_t len)
{
rtems_pty_context *pty = (rtems_pty_context *)base;
while (len > 0) {
ssize_t n = write(pty->socket, buf, len);
if (n <= 0) {
break;
}
buf += (size_t)n;
len -= (size_t)n;
}
}
static int
my_pty_control(rtems_termios_device_context *base,
ioctl_command_t request, void *buffer)
{
rtems_pty_context *p = (rtems_pty_context *)base;
struct winsize *wp = buffer;
switch (request) {
case TIOCGWINSZ:
wp->ws_row = p->height;
wp->ws_col = p->width;
#if DEBUG & DEBUG_WH
fprintf(stderr,
"ioctl(TIOCGWINSZ), returning %ix%i\n",
wp->ws_col,
wp->ws_row);
#endif
break;
case TIOCSWINSZ:
#if DEBUG & DEBUG_WH
fprintf(stderr,
"ioctl(TIOCGWINSZ), setting %ix%i\n",
wp->ws_col,
wp->ws_row);
#endif
p->height = wp->ws_row;
p->width = wp->ws_col;
break;
default:
rtems_set_errno_and_return_minus_one(EINVAL);
break;
}
return 0;
}
-18
View File
@@ -1,18 +0,0 @@
/*
* Copyright (c) 2018 embedded brains GmbH. All rights reserved.
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <rtems/telnetd.h>
rtems_status_code rtems_telnetd_initialize( void )
{
return rtems_telnetd_start( &rtems_telnetd_config );
}
-459
View File
@@ -1,459 +0,0 @@
/***********************************************************/
/*
*
* The telnet DAEMON
*
* Author: 17,may 2001
*
* WORK: fernando.ruiz@ctv.es
* HOME: correo@fernando-ruiz.com
*
* After start the net you can start this daemon.
* It uses the previously inited pseudo-terminales (pty.c)
* getting a new terminal with getpty(). This function
* gives a terminal name passing a opened socket like parameter.
*
* With register_telnetd() you add a new command in the shell to start
* this daemon interactively. (Login in /dev/console of course)
*
* Sorry but OOB is not still implemented. (This is the first version)
*
* Till Straumann <strauman@slac.stanford.edu>
* - made the 'shell' interface more generic, i.e. it is now
* possible to have 'telnetd' run an arbitrary 'shell'
* program.
*
* Copyright (c) 2009, 2018 embedded brains GmbH and others.
*
* embedded brains GmbH
* Dornierstr. 4
* D-82178 Puchheim
* Germany
* <rtems@embedded-brains.de>
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/queue.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <inttypes.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <syslog.h>
#include <rtems.h>
#include <rtems/pty.h>
#include <rtems/shell.h>
#include <rtems/telnetd.h>
#include <rtems/thread.h>
#include <rtems/userenv.h>
#ifdef RTEMS_NETWORKING
#include <rtems/rtems_bsdnet.h>
#endif
#define TELNETD_EVENT_SUCCESS RTEMS_EVENT_0
#define TELNETD_EVENT_ERROR RTEMS_EVENT_1
typedef struct telnetd_context telnetd_context;
typedef struct telnetd_session {
rtems_pty_context pty;
char peername[16];
telnetd_context *ctx;
rtems_id task_id;
LIST_ENTRY(telnetd_session) link;
} telnetd_session;
struct telnetd_context {
rtems_telnetd_config_table config;
int server_socket;
rtems_id task_id;
rtems_mutex mtx;
LIST_HEAD(, telnetd_session) free_sessions;
telnetd_session sessions[RTEMS_ZERO_LENGTH_ARRAY];
};
typedef union {
struct sockaddr_in sin;
struct sockaddr sa;
} telnetd_address;
RTEMS_NO_RETURN static void telnetd_session_fatal_error(
const telnetd_context *ctx
)
{
(void)rtems_event_send(ctx->task_id, TELNETD_EVENT_ERROR);
rtems_task_exit();
}
static bool telnetd_login(telnetd_context *ctx, telnetd_session *session)
{
bool success;
if (ctx->config.login_check == NULL) {
return true;
}
success = rtems_shell_login_prompt(
stdin,
stderr,
session->pty.name,
ctx->config.login_check
);
if (!success) {
syslog(
LOG_AUTHPRIV | LOG_WARNING,
"telnetd: too many wrong passwords entered from %s",
session->peername
);
}
return success;
}
static void telnetd_session_task(rtems_task_argument arg)
{
rtems_status_code sc;
telnetd_session *session;
telnetd_context *ctx;
const char *path;
session = (telnetd_session *) arg;
ctx = session->ctx;
sc = rtems_libio_set_private_env();
if (sc != RTEMS_SUCCESSFUL) {
telnetd_session_fatal_error(ctx);
}
path = rtems_pty_get_path(&session->pty);
stdin = fopen(path, "r+");
if (stdin == NULL) {
telnetd_session_fatal_error(ctx);
}
stdout = fopen(path, "r+");
if (stdout == NULL) {
telnetd_session_fatal_error(ctx);
}
stderr = fopen(path, "r+");
if (stderr == NULL) {
telnetd_session_fatal_error(ctx);
}
(void)rtems_event_send(ctx->task_id, TELNETD_EVENT_SUCCESS);
while (true) {
rtems_event_set events;
(void)rtems_event_system_receive(
RTEMS_EVENT_SYSTEM_SERVER,
RTEMS_WAIT | RTEMS_EVENT_ALL,
RTEMS_NO_TIMEOUT,
&events
);
syslog(
LOG_DAEMON | LOG_INFO,
"telnetd: accepted connection from %s on %s",
session->peername,
path
);
if (telnetd_login(ctx, session)) {
(*ctx->config.command)(session->pty.name, ctx->config.arg);
}
syslog(
LOG_DAEMON | LOG_INFO,
"telnetd: releasing connection from %s on %s",
session->peername,
path
);
rtems_pty_close_socket(&session->pty);
rtems_mutex_lock(&ctx->mtx);
LIST_INSERT_HEAD(&ctx->free_sessions, session, link);
rtems_mutex_unlock(&ctx->mtx);
}
}
static void telnetd_sleep_after_error(void)
{
/* If something went wrong, sleep for some time */
rtems_task_wake_after(10 * rtems_clock_get_ticks_per_second());
}
static void telnetd_server_task(rtems_task_argument arg)
{
telnetd_context *ctx;
ctx = (telnetd_context *) arg;
while (true) {
telnetd_address peer;
socklen_t address_len;
int session_socket;
telnetd_session *session;
address_len = sizeof(peer.sin);
session_socket = accept(ctx->server_socket, &peer.sa, &address_len);
if (session_socket < 0) {
syslog(LOG_DAEMON | LOG_ERR, "telnetd: cannot accept session");
telnetd_sleep_after_error();
continue;
};
rtems_mutex_lock(&ctx->mtx);
session = LIST_FIRST(&ctx->free_sessions);
if (session == NULL) {
rtems_mutex_unlock(&ctx->mtx);
(void)close(session_socket);
syslog(LOG_DAEMON | LOG_ERR, "telnetd: no free session available");
telnetd_sleep_after_error();
continue;
}
LIST_REMOVE(session, link);
rtems_mutex_unlock(&ctx->mtx);
rtems_pty_set_socket(&session->pty, session_socket);
if (
inet_ntop(
AF_INET,
&peer.sin.sin_addr,
session->peername,
sizeof(session->peername)
) == NULL
) {
strlcpy(session->peername, "<UNKNOWN>", sizeof(session->peername));
}
(void)rtems_event_system_send(session->task_id, RTEMS_EVENT_SYSTEM_SERVER);
}
}
static void telnetd_destroy_context(telnetd_context *ctx)
{
telnetd_session *session;
LIST_FOREACH(session, &ctx->free_sessions, link) {
if (session->task_id != 0) {
(void)rtems_task_delete(session->task_id);
}
(void)unlink(rtems_pty_get_path(&session->pty));
}
if (ctx->server_socket >= 0) {
(void)close(ctx->server_socket);
}
rtems_mutex_destroy(&ctx->mtx);
free(ctx);
}
static rtems_status_code telnetd_create_server_socket(telnetd_context *ctx)
{
telnetd_address srv;
socklen_t address_len;
int enable;
ctx->server_socket = socket(PF_INET, SOCK_STREAM, 0);
if (ctx->server_socket < 0) {
syslog(LOG_DAEMON | LOG_ERR, "telnetd: cannot create server socket");
return RTEMS_UNSATISFIED;
}
enable = 1;
(void)setsockopt(
ctx->server_socket,
SOL_SOCKET,
SO_KEEPALIVE,
&enable,
sizeof(enable)
);
memset(&srv, 0, sizeof(srv));
srv.sin.sin_family = AF_INET;
srv.sin.sin_port = htons(ctx->config.port);
address_len = sizeof(srv.sin);
if (bind(ctx->server_socket, &srv.sa, address_len) != 0) {
syslog(LOG_DAEMON | LOG_ERR, "telnetd: cannot bind server socket");
return RTEMS_RESOURCE_IN_USE;
};
if (listen(ctx->server_socket, ctx->config.client_maximum) != 0) {
syslog(LOG_DAEMON | LOG_ERR, "telnetd: cannot listen on server socket");
return RTEMS_UNSATISFIED;
};
return RTEMS_SUCCESSFUL;
}
static rtems_status_code telnetd_create_session_tasks(telnetd_context *ctx)
{
uint16_t i;
ctx->task_id = rtems_task_self();
for (i = 0; i < ctx->config.client_maximum; ++i) {
telnetd_session *session;
rtems_status_code sc;
const char *path;
rtems_event_set events;
session = &ctx->sessions[i];
session->ctx = ctx;
rtems_mutex_init(&ctx->mtx, "Telnet");
LIST_INSERT_HEAD(&ctx->free_sessions, session, link);
sc = rtems_task_create(
rtems_build_name('T', 'N', 'T', 'a' + i % 26),
ctx->config.priority,
ctx->config.stack_size,
RTEMS_DEFAULT_MODES,
RTEMS_FLOATING_POINT,
&session->task_id
);
if (sc != RTEMS_SUCCESSFUL) {
syslog(LOG_DAEMON | LOG_ERR, "telnetd: cannot create session task");
return RTEMS_UNSATISFIED;
}
path = rtems_pty_initialize(&session->pty, i);
if (path == NULL) {
syslog(LOG_DAEMON | LOG_ERR, "telnetd: cannot create session PTY");
return RTEMS_UNSATISFIED;
}
(void)rtems_task_start(
session->task_id,
telnetd_session_task,
(rtems_task_argument) session
);
(void)rtems_event_receive(
TELNETD_EVENT_SUCCESS | TELNETD_EVENT_ERROR,
RTEMS_WAIT | RTEMS_EVENT_ANY,
RTEMS_NO_TIMEOUT,
&events
);
if ((events & TELNETD_EVENT_ERROR) != 0) {
syslog(LOG_DAEMON | LOG_ERR, "telnetd: cannot initialize session task");
return RTEMS_UNSATISFIED;
}
}
return RTEMS_SUCCESSFUL;
}
rtems_status_code rtems_telnetd_start(const rtems_telnetd_config_table* config)
{
telnetd_context *ctx;
rtems_status_code sc;
uint16_t client_maximum;
if (config->command == NULL) {
syslog(LOG_DAEMON | LOG_ERR, "telnetd: configuration with invalid command");
return RTEMS_INVALID_ADDRESS;
}
if (config->client_maximum == 0) {
client_maximum = 5;
} else {
client_maximum = config->client_maximum;
}
ctx = calloc(
1,
sizeof(*ctx) + client_maximum * sizeof(ctx->sessions[0])
);
if (ctx == NULL) {
syslog(LOG_DAEMON | LOG_ERR, "telnetd: cannot allocate server context");
return RTEMS_UNSATISFIED;
}
ctx->config = *config;
ctx->config.client_maximum = client_maximum;
ctx->server_socket = -1;
LIST_INIT(&ctx->free_sessions);
/* Check priority */
#ifdef RTEMS_NETWORKING
if (ctx->config.priority == 0) {
ctx->config.priority = rtems_bsdnet_config.network_task_priority;
}
#endif
if (ctx->config.priority == 0) {
ctx->config.priority = 100;
}
/* Check stack size */
if (ctx->config.stack_size == 0) {
ctx->config.stack_size = (size_t)32 * 1024;
}
if (ctx->config.port == 0) {
ctx->config.port = 23;
}
sc = telnetd_create_server_socket(ctx);
if (sc != RTEMS_SUCCESSFUL) {
telnetd_destroy_context(ctx);
return sc;
}
sc = telnetd_create_session_tasks(ctx);
if (sc != RTEMS_SUCCESSFUL) {
telnetd_destroy_context(ctx);
return sc;
}
sc = rtems_task_create(
rtems_build_name('T', 'N', 'T', 'D'),
ctx->config.priority,
RTEMS_MINIMUM_STACK_SIZE,
RTEMS_DEFAULT_MODES,
RTEMS_FLOATING_POINT,
&ctx->task_id
);
if (sc != RTEMS_SUCCESSFUL) {
syslog(LOG_DAEMON | LOG_ERR, "telnetd: cannot create server task");
telnetd_destroy_context(ctx);
return RTEMS_UNSATISFIED;
}
(void)rtems_task_start(
ctx->task_id,
telnetd_server_task,
(rtems_task_argument) ctx
);
syslog(
LOG_DAEMON | LOG_INFO,
"telnetd: started successfully on port %" PRIu16, ctx->config.port
);
return RTEMS_SUCCESSFUL;
}
-2
View File
@@ -29,8 +29,6 @@ links:
uid: librtemsdfltcfg
- role: build-dependency
uid: librtemstest
- role: build-dependency
uid: libtelnetd
- role: build-dependency
uid: libtftpfs
- role: build-dependency
-24
View File
@@ -1,24 +0,0 @@
SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
build-type: library
cflags: []
copyrights:
- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
cppflags: []
cxxflags: []
enabled-by: true
includes:
- cpukit/libnetworking
install:
- destination: ${BSP_INCLUDEDIR}/rtems
source:
- cpukit/include/rtems/telnetd.h
install-path: ${BSP_LIBDIR}
links: []
source:
- cpukit/telnetd/check_passwd.c
- cpukit/telnetd/des.c
- cpukit/telnetd/pty.c
- cpukit/telnetd/telnetd-init.c
- cpukit/telnetd/telnetd.c
target: telnetd
type: build
-2
View File
@@ -266,8 +266,6 @@ links:
uid: tar02
- role: build-dependency
uid: tar03
- role: build-dependency
uid: telnetd01
- role: build-dependency
uid: termios
- role: build-dependency
@@ -1,22 +0,0 @@
SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
build-type: test-program
cflags: []
copyrights:
- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
cppflags: []
cxxflags: []
enabled-by:
- RTEMS_NETWORKING
features: c cprogram
includes:
- cpukit/libnetworking
ldflags: []
links: []
source:
- testsuites/libtests/telnetd01/init.c
stlib: []
target: testsuites/libtests/telnetd01.exe
type: build
use-after:
- telnetd
use-before: []
-120
View File
@@ -1,120 +0,0 @@
/*
* Copyright (c) 2018 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
* Dornierstr. 4
* 82178 Puchheim
* Germany
* <rtems@embedded-brains.de>
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <rtems.h>
#include <rtems/rtems_bsdnet.h>
#include <rtems/telnetd.h>
#include <tmacros.h>
const char rtems_test_name[] = "TELNETD 1";
struct rtems_bsdnet_config rtems_bsdnet_config;
static void command(char *device_name, void *arg)
{
}
static void test_command_null(void)
{
static const rtems_telnetd_config_table config = {
.command = NULL
};
rtems_status_code sc;
sc = rtems_telnetd_start(&config);
rtems_test_assert(sc == RTEMS_INVALID_ADDRESS);
}
static void test_cannot_start_server_task(void)
{
static const rtems_telnetd_config_table config = {
.command = command,
.priority = UINT32_MAX
};
rtems_status_code sc;
sc = rtems_telnetd_start(&config);
rtems_test_assert(sc == RTEMS_UNSATISFIED);
}
static void test_successful_start(void)
{
static const rtems_telnetd_config_table config = {
.command = command,
.stack_size = RTEMS_MINIMUM_STACK_SIZE
};
rtems_status_code sc;
sc = rtems_telnetd_start(&config);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
}
static void test_already_started(void)
{
static const rtems_telnetd_config_table config = {
.command = command
};
rtems_status_code sc;
sc = rtems_telnetd_start(&config);
rtems_test_assert(sc == RTEMS_RESOURCE_IN_USE);
}
static rtems_task Init(rtems_task_argument argument)
{
int rv;
TEST_BEGIN();
rv = rtems_bsdnet_initialize_network();
rtems_test_assert(rv == 0);
test_command_null();
test_cannot_start_server_task();
test_successful_start();
test_already_started();
TEST_END();
rtems_test_exit(0);
}
#define CONFIGURE_INIT
#define CONFIGURE_MICROSECONDS_PER_TICK 10000
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS (3 + 1 + 5 * 4)
#define CONFIGURE_MAXIMUM_TASKS 8
#define CONFIGURE_MAXIMUM_POSIX_KEYS 1
#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
#include <rtems/confdefs.h>
@@ -1,24 +0,0 @@
#
# Copyright (c) 2018 embedded brains GmbH. All rights reserved.
#
# embedded brains GmbH
# Dornierstr. 4
# 82178 Puchheim
# Germany
# <rtems@embedded-brains.de>
#
# The license and distribution terms for this file may be
# found in the file LICENSE in this distribution or at
# http://www.rtems.org/license/LICENSE.
This file describes the directives and concepts tested by this test set.
test set name: telnetd01
directives:
- rtems_telnetd_start()
concepts:
+ Check if Telnet server works.
@@ -1,11 +0,0 @@
*** BEGIN OF TEST TELNETD 1 ***
*** TEST VERSION: 5.0.0.dc32b6aa0807fb70f9b26bc0bc6e164ddb49bd3a
*** TEST STATE: EXPECTED_PASS
*** TEST BUILD: RTEMS_NETWORKING
*** TEST TOOLS: 7.3.0 20180125 (RTEMS 5, RSB 9670d7541e0621915e521fe76e7bb33de8cee661, Newlib d13c84eb07e35984bf7a974cd786a6cdac29e6b9)
syslog: telnetd: configuration with invalid command
syslog: telnetd: cannot create session task
syslog: telnetd: started successfully on port 23
syslog: telnetd: cannot bind server socket
*** END OF TEST TELNETD 1 ***