Notice: We have migrated to GitLab launching 2024-05-01 see here: https://gitlab.rtems.org/

Ticket #1331: pr1331-cpukit.diff

File pr1331-cpukit.diff, 7.7 KB (added by Joel Sherrill, on 10/15/08 at 16:34:35)

patch for telnetd/shell in cpukit on cvs head

  • libmisc/shell/shell.c

    ? telnetd/.telnetd.c.swp
    ? telnetd/a.out
    RCS file: /usr1/CVS/rtems/cpukit/libmisc/shell/shell.c,v
    retrieving revision 1.37
    diff -u -r1.37 shell.c
     
    460460
    461461  if (stat("/etc/issue",&buf)) {
    462462    rtems_shell_write_file("/etc/issue",
     463                           "\n"
    463464                           "Welcome to @V\\n"
    464465                           "Login into @S\\n");
    465466  }
    466467
    467468  if (stat("/etc/issue.net",&buf)) {
    468469     rtems_shell_write_file("/etc/issue.net",
     470                           "\n"
    469471                            "Welcome to %v\n"
    470472                            "running on %m\n");
    471473  }
  • telnetd/check_passwd.c

    RCS file: /usr1/CVS/rtems/cpukit/telnetd/check_passwd.c,v
    retrieving revision 1.1
    diff -u -r1.1 check_passwd.c
     
    7878#endif
    7979int check_passwd(char *peername)
    8080{
    81 char                    *pw;
    82 int                             rval = -1, tmp, retries;
    83 struct termios  t,told;
    84 int                             restore_flags = 0;
    85 char                    buf[30], cryptbuf[21];
    86 char                    salt[3];
     81  char                  *pw;
     82  int                   rval = -1, tmp, retries;
     83  struct termios        t,told;
     84  int                   restore_flags = 0;
     85  char                  buf[30], cryptbuf[21];
     86  char                  salt[3];
    8787
    8888  if ( !(pw=getenv("TELNETD_PASSWD")) || 0 == strlen(pw) )
    8989#ifdef TELNETD_DEFAULT_PASSWD
  • telnetd/telnetd.c

    RCS file: /usr1/CVS/rtems/cpukit/telnetd/telnetd.c,v
    retrieving revision 1.12
    diff -u -r1.12 telnetd.c
     
    8585);
    8686
    8787/***********************************************************/
    88 rtems_id            telnetd_task_id      =0;
    89 uint32_t            telnetd_stack_size   =32000;
    90 rtems_task_priority telnetd_task_priority=0;
    91 int                 telnetd_dont_spawn   =0;
    92 void                (*telnetd_shell)(char *, void*)=0;
    93 void                *telnetd_shell_arg         =0;
     88rtems_id            telnetd_task_id                 = 0;
     89uint32_t            telnetd_stack_size              = 32000;
     90rtems_task_priority telnetd_task_priority           = 0;
     91bool                telnetd_remain_on_caller_stdio  = false;
     92void                (*telnetd_shell)(char *, void*) = 0;
     93void                *telnetd_shell_arg              = NULL;
    9494void *              (*telnetd_spawn_task)(
    95         const char *, unsigned, unsigned, void (*)(void*), void *) = telnetd_dflt_spawn;
    96 
    97 static char *grab_a_Connection(int des_socket, uni_sa *srv, char *peername, int sz)
     95  const char *,
     96  unsigned,
     97  unsigned,
     98  void (*)(void*),
     99  void *) = telnetd_dflt_spawn;
     100
     101static char *grab_a_Connection(
     102  int des_socket,
     103  uni_sa *srv,
     104  char *peername,
     105  int sz
     106)
    98107{
    99108  char *rval = 0;
    100109#if 0
     
    190199  char               peername[16];
    191200  int                i=1;
    192201  int                size_adr;
    193   struct shell_args *arg;
     202  struct shell_args *arg = NULL;
    194203
    195204  if ((des_socket=socket(PF_INET,SOCK_STREAM,0))<0) {
    196205    perror("telnetd:socket");
     
    205214  size_adr=sizeof(srv.sin);
    206215  if ((bind(des_socket,&srv.sa,size_adr))<0) {
    207216    perror("telnetd:bind");
    208           close(des_socket);
     217    close(des_socket);
    209218    telnetd_task_id=0;
    210219    rtems_task_delete(RTEMS_SELF);
    211220  };
     
    220229   * was started from the console anyways..
    221230   */
    222231  do {
    223     devname = grab_a_Connection(des_socket, &srv, peername, sizeof(peername));
    224 
    225     if ( !devname ) {
    226       /* if something went wrong, sleep for some time */
    227       sleep(10);
    228       continue;
    229     }
    230     if ( telnetd_dont_spawn ) {
    231       if ( !telnetd_askForPassword || (0 == check_passwd(peername)) )
    232         telnetd_shell(devname, telnetd_shell_arg);
     232    if ( telnetd_remain_on_caller_stdio ) {
     233      char device_name[32];
     234      ttyname_r( 1, device_name, sizeof(device_name) );
     235      if ( !telnetd_askForPassword || (0 == check_passwd(arg->peername)) )
     236        telnetd_shell(device_name, telnetd_shell_arg);
    233237    } else {
     238      devname = grab_a_Connection(des_socket, &srv, peername, sizeof(peername));
     239
     240      if ( !devname ) {
     241        /* if something went wrong, sleep for some time */
     242        sleep(10);
     243        continue;
     244      }
     245
    234246      arg = malloc( sizeof(*arg) );
    235247
    236248      arg->devname = devname;
     
    288300int rtems_telnetd_initialize(
    289301  void               (*cmd)(char *, void *),
    290302  void                *arg,
    291   int                  dontSpawn,
     303  bool                 remainOnCallerSTDIO,
    292304  size_t               stack,
    293305  rtems_task_priority  priority,
    294   int                  askForPassword
     306  bool                 askForPassword
    295307)
    296308{
    297309  rtems_status_code sc;
     
    328340  }
    329341  if ( priority < 2 )
    330342    priority = 100;
    331   telnetd_task_priority = priority;
    332   telnetd_dont_spawn    = dontSpawn;
     343  telnetd_task_priority          = priority;
     344  telnetd_remain_on_caller_stdio = remainOnCallerSTDIO;
    333345
    334346  sc = initialize_telnetd();
    335347  if (sc != RTEMS_SUCCESSFUL) return sc;
    336348
    337   printf("rtems_telnetd() started with stacksize=%u,priority=%d\n",
    338     (unsigned)telnetd_stack_size,(int)telnetd_task_priority);
     349  if ( !telnetd_remain_on_caller_stdio )
     350    fprintf(stderr, "rtems_telnetd() started with stacksize=%u,priority=%d\n",
     351      (unsigned)telnetd_stack_size,(int)telnetd_task_priority);
    339352  return 0;
    340353}
    341354
  • telnetd/telnetd.h

    RCS file: /usr1/CVS/rtems/cpukit/telnetd/telnetd.h,v
    retrieving revision 1.7
    diff -u -r1.7 telnetd.h
     
    1717extern "C" {
    1818#endif 
    1919
    20 /*
    21  *  Initialize the telnetd subsystem.
     20/**
     21 *  This method initializes the telnetd subsystem.
    2222 *
    23  *  cmd              - function which is the "shell" telnetd invokes
    24  *  arg              - context pointer to cmd
    25  *  dontSpawn        - TRUE if telnetd takes over this task.
    26  *                     FALSE to create another task for the shell.
    27  *  stack            - stack size of spawned task
    28  *  priority         - initial priority of spawned task
    29  *  askForPassword   - TRUE if telnetd asks for password
    30  *                     FALSE to invoke "cmd" with no password check.
    31  *                        This may be OK if "cmd" includes its own check.
     23 *  @param[in] cmd is the function which is the "shell" telnetd invokes
     24 *  @param[in] arg is the context pointer to cmd
     25 *  @param[in] remainOnCallerSTDIO is set to TRUE if telnetd takes over the
     26 *    standard in, out and error associated with task.  In this case,
     27 *    it will be NOT be listening on any sockets.  When this parameters
     28 *    is FALSE the telnetd will create other tasks for the shell
     29 *    which listen on sockets.
     30 *  @param[in] stack is stack size of spawned task.
     31 *  @param[in] priority is the initial priority of spawned task(s).  If
     32 *    this parameter is less than 2, then the default priority of 100 is used.
     33 *  @param[in] askForPassword is set to TRUE if telnetd is to ask for a
     34 *    password. This is set to FALSE to invoke "cmd" with no password check.
     35 *    This may be OK if "cmd" includes its own check and indeed the RTEMS Shell
     36 *    uses a login with a user name and password so this is the usual case.
    3237 */
    3338int rtems_telnetd_initialize(
    3439  void               (*cmd)(char *, void *),
    3540  void                *arg,
    36   int                  dontSpawn,
     41  bool                 remainOnCallerSTDIO,
    3742  size_t               stack,
    3843  rtems_task_priority  priority,
    39   int                  askForPassword
     44  bool                 askForPassword
    4045);
    4146
    4247#ifdef __cplusplus