Changeset 70d689a in rtems


Ignore:
Timestamp:
08/09/01 22:08:46 (22 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
b6a2d2fa
Parents:
bd520203
Message:

2001-08-09 Fernando-Ruiz Casas <correo@…>

  • shell/Makefile.am, shell/README, shell/cmds.c, shell/shell.c, shell/shell.h: Updates.
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • c/src/libmisc/ChangeLog

    rbd520203 r70d689a  
     12001-08-09      Fernando-Ruiz Casas <correo@fernando-ruiz.com>
     2
     3        * shell/Makefile.am, shell/README, shell/cmds.c, shell/shell.c,
     4        shell/shell.h: Updates.
     5
    162001-08-09      Keith Outwater <vac4050@cae597.rsc.raytheon.com>
    27
  • c/src/libmisc/shell/Makefile.am

    rbd520203 r70d689a  
    1010LIB = $(ARCH)/$(LIBNAME).a
    1111
    12 C_FILES = cmds.c shell.c pty.c
     12C_FILES = cmds.c shell.c
    1313C_O_FILES = $(C_FILES:%.c=$(ARCH)/%.o)
    1414
     
    4040.PRECIOUS: $(LIB)
    4141
    42 EXTRA_DIST = README shell.c cmds.c pty.c shell.h
     42EXTRA_DIST = README shell.c cmds.c shell.h
    4343
    4444include $(top_srcdir)/../../../automake/local.am
  • c/src/libmisc/shell/README

    rbd520203 r70d689a  
    2020    and enjoy it.
    2121
    22 3.  If you have tcp/ip inited you can start telnetd daemon.
    23     You need register pseudo-terminals driver into device drivers table.
    24     16 ptyX termios device terminales are created into /dev/.
    25     Calling rtems_initialize_telnetd() starts the daemon.
     223.  Telnetd daemon uses this (browse libnetworking/rtems_telnetd)
    2623    Enjoy it.
    2724
  • c/src/libmisc/shell/cmds.c

    rbd520203 r70d689a  
    335335int main_mkdir (int argc, char *argv[]) {
    336336   char *dir;
    337    dir=NULL;
    338    if (argc>1) dir=argv[1];
    339    if (mkdir(dir,S_IRWXU|S_IRWXG|S_IRWXO)) {
    340      printf("mkdir '%s' failed:%s\n",dir,strerror(errno));
     337   int n;
     338   n=1;
     339   while (n<argc) {
     340    dir=argv[n++];
     341    if (mkdir(dir,S_IRWXU|S_IRWXG|S_IRWXO)) {
     342      printf("mkdir '%s' failed:%s\n",dir,strerror(errno));
     343    }; 
    341344   }; 
    342345   return errno;
     
    346349{
    347350   char *dir;
    348    dir=NULL;
    349    if (argc>1) dir=argv[1];
    350    if (rmdir(dir)) printf("rmdir '%s' failed:%s\n",dir,strerror(errno));
     351   int n;
     352   n=1;
     353   while (n<argc) {
     354    dir=argv[n++];
     355    if (rmdir(dir)) printf("rmdir '%s' failed:%s\n",dir,strerror(errno));
     356   };
    351357   return errno;
    352358}
     
    384390}
    385391/*-----------------------------------------------------------*/         
    386 /* date - print or set time and date */
    387 
    388 static int set_time(char *t)
    389 {
    390   rtems_time_of_day tod;       
    391   FILE * rtc;
    392   int len;
    393 
    394   if ( rtems_clock_get(RTEMS_CLOCK_GET_TOD,&tod) != RTEMS_SUCCESSFUL )
    395      memset( &tod, 0, sizeof(tod) );
    396 
    397   /* JRS
    398    *
    399    *  This code that was used to parse the command line was taken
    400    *  from an inappropriate source.  It has been removed and needs
    401    *  to be replaced.
    402    */
    403 
    404   if (!_TOD_Validate(&tod)) {
    405     fprintf(stderr, "Invalid date value\n");
    406   } else {
    407    rtems_clock_set(&tod);         
    408    rtems_clock_get(RTEMS_CLOCK_GET_TOD,&tod);     
    409    rtc=fopen("/dev/rtc","r+");
    410    if (rtc) {
    411     fwrite(&tod,sizeof(tod),1,rtc);
    412     fclose(rtc);
    413    };
    414   };
    415   return 1;
    416 }
     392/* date - print time and date */
    417393
    418394int main_date(int argc,char *argv[])
    419395{
    420396  time_t t;
    421   if (argc == 2)
    422     set_time(argv[1]);
    423397  time(&t);
    424398  printf("%s", ctime(&t));
     
    529503  shell_add_cmd  ("logoff","misc","logoff from the system"                    ,main_logoff);
    530504  shell_alias_cmd("logoff","exit");
    531   shell_add_cmd  ("date" ,"misc","date [[MMDDYY]hhmm[ss]]"                    ,main_date);
     505  shell_add_cmd  ("date" ,"misc","date"                                       ,main_date);
    532506  shell_add_cmd  ("reset","misc","reset the BSP"                              ,main_reset);
    533507  shell_add_cmd  ("alias","misc","alias old new"                              ,main_alias);
  • c/src/libmisc/shell/shell.c

    rbd520203 r70d689a  
    1717#endif
    1818
     19#undef  __STRICT_ANSI__  /* fileno() */
    1920#include <stdio.h>
    2021
     
    3031#include <stdlib.h>
    3132#include <ctype.h>
     33#include <sys/stat.h>
    3234#include <unistd.h>
    3335#include <errno.h>
     
    223225  shell_cmd_t * shell_cmd=shell_first_cmd;
    224226  if (argc<2) {
    225    printf("help: TOPIC? The topics are\n");       
     227   printf("help: ('r' repeat last cmd - 'e' edit last cmd)\n"     
     228          "  TOPIC? The topics are\n");   
    226229   topic=shell_first_topic;
    227230   col=0;
     
    276279}
    277280/* ----------------------------------------------- *
    278  * TODO:Change to bash readline() better.
     281 * TODO: Add improvements. History, edit vi or emacs, ...
    279282 * ----------------------------------------------- */
    280283int shell_scanline(char * line,int size,FILE * in,FILE * out) {
    281284  int c,col;
    282285  col=0;
     286  if (*line) {
     287   col=strlen(line);     
     288   if (out) fprintf(out,"%s",line);
     289  };
     290  tcdrain(fileno(in ));
    283291  tcdrain(fileno(out));
    284292  for (;;) {
     
    344352}
    345353
     354void write_file(char * name,char * content) {
     355        FILE * fd;
     356        fd=fopen(name,"w");
     357        if (fd) {
     358         fwrite(content,1,strlen(content),fd);
     359         fclose(fd);
     360        }; 
     361}
     362
     363void init_issue(void) {
     364 static char issue_inited=FALSE;
     365 struct stat buf;
     366 if (issue_inited) return;
     367 issue_inited=TRUE;
     368 getpwnam("root"); /* dummy call to init /etc dir */
     369 if (stat("/etc/issue",&buf))
     370  write_file("/etc/issue",
     371             "Welcome to @V\\n"
     372             "Login into @S(@L)\\n");
     373 if (stat("/etc/issue.net",&buf))
     374  write_file("/etc/issue.net",
     375             "Welcome to %v\n"
     376             "running on %m\n");
     377}
     378
    346379int shell_login(FILE * in,FILE * out) {
    347380        FILE * fd;
     
    352385        char pass[128];
    353386        struct passwd * passwd;
     387        init_issue();
    354388        setuid(0);
    355389        setgid(0);
     
    360394            (current_shell_env->devname[6]!='t')||
    361395            (current_shell_env->devname[7]!='y')) {
    362            cat_file(out,"/etc/issue");
     396          fd=fopen("/etc/issue","r");
     397          if (fd) {
     398           while ((c=fgetc(fd))!=EOF) {
     399            if (c=='@')  {
     400             switch(c=fgetc(fd)) {
     401              case 'L':fprintf(out,"%s",current_shell_env->devname);
     402                      break;
     403              case 'B':fprintf(out,"0");
     404                      break;
     405              case 'T':
     406              case 'D':time(&t);
     407                      fprintf(out,"%s",ctime(&t));
     408                      break;
     409              case 'S':fprintf(out,"RTEMS");
     410                      break;
     411              case 'V':fprintf(out,"%s\n%s",_RTEMS_version,_Copyright_Notice);
     412                      break;
     413              case '@':fprintf(out,"@");
     414                      break;
     415              default :fprintf(out,"@%c",c);
     416                      break;
     417             };
     418            } else
     419            if (c=='\\')  {
     420             switch(c=fgetc(fd)) {
     421              case '\\':fprintf(out,"\\");
     422                      break;
     423              case 'b':fprintf(out,"\b"); break;
     424              case 'f':fprintf(out,"\f"); break;
     425              case 'n':fprintf(out,"\n"); break;
     426              case 'r':fprintf(out,"\r"); break;
     427              case 's':fprintf(out," "); break;
     428              case 't':fprintf(out,"\t"); break;
     429              case '@':fprintf(out,"@"); break;
     430             };
     431            } else {
     432             fputc(c,out);                             
     433            };
     434           };
     435           fclose(fd);
     436          }
    363437         } else { 
    364438          fd=fopen("/etc/issue.net","r");
     
    398472        };
    399473        times=0;
     474        strcpy(name,"");
     475        strcpy(pass,"");
    400476        for (;;) {
    401477                times++;
     
    407483                if (out) fprintf(out,"\n");
    408484                if ((passwd=getpwnam(name))) {
    409                  setuid(passwd->pw_uid);                       
    410                  setgid(passwd->pw_gid);                       
    411                  rtems_current_user_env->euid=
    412                  rtems_current_user_env->egid=0;
    413                  chown(current_shell_env->devname,passwd->pw_uid,0);
    414                  rtems_current_user_env->euid=passwd->pw_uid;                   
    415                  rtems_current_user_env->egid=passwd->pw_gid;                   
    416                  if (!strcmp(passwd->pw_passwd,"*")) {
    417                  /* /etc/shadow */
    418                   return 0;
    419                  } else {
    420                   /* crypt() */
    421                   return 0;
     485                 if (strcmp(passwd->pw_passwd,"!")) { /* valid user */
     486                  setuid(passwd->pw_uid);                       
     487                  setgid(passwd->pw_gid);                       
     488                  rtems_current_user_env->euid=
     489                  rtems_current_user_env->egid=0;
     490                  chown(current_shell_env->devname,passwd->pw_uid,0);
     491                  rtems_current_user_env->euid=passwd->pw_uid;                 
     492                  rtems_current_user_env->egid=passwd->pw_gid;                 
     493                  if (!strcmp(passwd->pw_passwd,"*")) {
     494                   /* /etc/shadow */
     495                   return 0;
     496                  } else {
     497                   /* crypt() */
     498                   return 0;
     499                  };
    422500                 };
    423501                };
    424502                if (out) fprintf(out,"Login incorrect\n");
     503                strcpy(name,"");
     504                strcpy(pass,"");
    425505        };
    426506        return -1;
     
    487567    fprintf(stderr,"shell:unable to open stdout.%s:%s\n",devname,strerror(errno));
    488568   };
     569   setvbuf(stdout,NULL,_IONBF,0); /* Not buffered*/
    489570   stderr=fopen(devname,"r+");
    490571   if (!stderr) {
     
    498579  shell_add_cmd(NULL,NULL,NULL,NULL); /* init the chain list*/
    499580  do {
     581   /* Set again root user and root filesystem, side effect of set_priv..*/       
     582  sc=rtems_libio_set_private_env();
     583  if (sc!=RTEMS_SUCCESSFUL) {
     584   rtems_error(sc,"rtems_libio_set_private_env():");     
     585   rtems_task_delete(RTEMS_SELF);
     586  };
    500587  if (!shell_login(stdin,stdout))  {
    501588   cat_file(stdout,"/etc/motd");
     
    503590   strcpy(cmd,"");
    504591   printf("\n"
    505           "RTEMS SHELL (Version 1.0-FRC):%s. "__DATE__". 'help' to list commands.\n",devname);
    506    chdir("/");
     592          "RTEMS SHELL (Ver.1.0-FRC):%s. "__DATE__". 'help' to list commands.\n",devname);
     593   chdir("/"); /* XXX: chdir to getpwent homedir */
    507594   shell_env->exit_shell=FALSE;
    508595   for (;;) {
     
    514601    if (!shell_scanline(cmd,sizeof(cmd),stdin,stdout)) break; /*EOF*/
    515602    /* evaluate cmd section */   
    516     if (!strcmp(cmd,"r")) {  /* repeat last command, forced, not automatic */
     603    if (!strcmp(cmd,"e")) {  /* edit last command */
     604     strcpy(cmd,last_cmd);
     605     continue;
     606    } else
     607    if (!strcmp(cmd,"r")) {  /* repeat last command */
    517608     strcpy(cmd,last_cmd);
    518609    } else
     
    537628    /* end exec cmd section */   
    538629    if (shell_env->exit_shell)  break;
     630    cmd[0]=0;
    539631   };
    540632   printf("\nGoodbye from RTEMS SHELL :-(\n");
     
    589681 return rtems_task_start(task_id,shell_shell,(rtems_task_argument) shell_env);
    590682}
    591 /* ----------------------------------------------- */
  • c/src/libmisc/shell/shell.h

    rbd520203 r70d689a  
    11/*
     2 *
     3 *  Instantatiate a new terminal shell.
     4 *
     5 *  Author:
     6 *
     7 *   WORK: fernando.ruiz@ctv.es
     8 *   HOME: correo@fernando-ruiz.com
     9 *
     10 *   Thanks at:
     11 *    Chris John
     12 *
    213 *  $Id$
    314 */
     
    5465int shell_scanline(char * line,int size,FILE * in,FILE * out) ;
    5566void cat_file(FILE * out,char *name);
     67void write_file(char *name,char * content);
    5668       
    5769rtems_status_code shell_init(char * task_name      ,
     
    6577                *  current_shell_env;
    6678/*--------*/
    67 /* pty.c */
    68 /*--------*/
    69 
    70 char * get_pty(int socket);
    71 
    72 
    73 rtems_device_driver pty_initialize(
    74   rtems_device_major_number  major,
    75   rtems_device_minor_number  minor,
    76   void                      *arg);
    77 rtems_device_driver pty_open(
    78   rtems_device_major_number major,
    79   rtems_device_minor_number minor,
    80   void                    * arg);
    81 rtems_device_driver pty_close(
    82   rtems_device_major_number major,
    83   rtems_device_minor_number minor,
    84   void                    * arg);
    85 rtems_device_driver pty_read(
    86   rtems_device_major_number major,
    87   rtems_device_minor_number minor,
    88   void                    * arg);
    89 rtems_device_driver pty_write(
    90   rtems_device_major_number major,
    91   rtems_device_minor_number minor,
    92   void                    * arg);
    93 rtems_device_driver pty_control(
    94   rtems_device_major_number major,
    95   rtems_device_minor_number minor,
    96   void                    * arg);
    97 
    98 
    99 #define PTY_DRIVER_TABLE_ENTRY \
    100        { pty_initialize , pty_open , pty_close , \
    101          pty_read , pty_write , pty_control }
    102 /*--------*/
    10379/* cmds.c */
    10480/*--------*/
  • cpukit/libmisc/ChangeLog

    rbd520203 r70d689a  
     12001-08-09      Fernando-Ruiz Casas <correo@fernando-ruiz.com>
     2
     3        * shell/Makefile.am, shell/README, shell/cmds.c, shell/shell.c,
     4        shell/shell.h: Updates.
     5
    162001-08-09      Keith Outwater <vac4050@cae597.rsc.raytheon.com>
    27
  • cpukit/libmisc/shell/Makefile.am

    rbd520203 r70d689a  
    1010LIB = $(ARCH)/$(LIBNAME).a
    1111
    12 C_FILES = cmds.c shell.c pty.c
     12C_FILES = cmds.c shell.c
    1313C_O_FILES = $(C_FILES:%.c=$(ARCH)/%.o)
    1414
     
    4040.PRECIOUS: $(LIB)
    4141
    42 EXTRA_DIST = README shell.c cmds.c pty.c shell.h
     42EXTRA_DIST = README shell.c cmds.c shell.h
    4343
    4444include $(top_srcdir)/../../../automake/local.am
  • cpukit/libmisc/shell/README

    rbd520203 r70d689a  
    2020    and enjoy it.
    2121
    22 3.  If you have tcp/ip inited you can start telnetd daemon.
    23     You need register pseudo-terminals driver into device drivers table.
    24     16 ptyX termios device terminales are created into /dev/.
    25     Calling rtems_initialize_telnetd() starts the daemon.
     223.  Telnetd daemon uses this (browse libnetworking/rtems_telnetd)
    2623    Enjoy it.
    2724
  • cpukit/libmisc/shell/cmds.c

    rbd520203 r70d689a  
    335335int main_mkdir (int argc, char *argv[]) {
    336336   char *dir;
    337    dir=NULL;
    338    if (argc>1) dir=argv[1];
    339    if (mkdir(dir,S_IRWXU|S_IRWXG|S_IRWXO)) {
    340      printf("mkdir '%s' failed:%s\n",dir,strerror(errno));
     337   int n;
     338   n=1;
     339   while (n<argc) {
     340    dir=argv[n++];
     341    if (mkdir(dir,S_IRWXU|S_IRWXG|S_IRWXO)) {
     342      printf("mkdir '%s' failed:%s\n",dir,strerror(errno));
     343    }; 
    341344   }; 
    342345   return errno;
     
    346349{
    347350   char *dir;
    348    dir=NULL;
    349    if (argc>1) dir=argv[1];
    350    if (rmdir(dir)) printf("rmdir '%s' failed:%s\n",dir,strerror(errno));
     351   int n;
     352   n=1;
     353   while (n<argc) {
     354    dir=argv[n++];
     355    if (rmdir(dir)) printf("rmdir '%s' failed:%s\n",dir,strerror(errno));
     356   };
    351357   return errno;
    352358}
     
    384390}
    385391/*-----------------------------------------------------------*/         
    386 /* date - print or set time and date */
    387 
    388 static int set_time(char *t)
    389 {
    390   rtems_time_of_day tod;       
    391   FILE * rtc;
    392   int len;
    393 
    394   if ( rtems_clock_get(RTEMS_CLOCK_GET_TOD,&tod) != RTEMS_SUCCESSFUL )
    395      memset( &tod, 0, sizeof(tod) );
    396 
    397   /* JRS
    398    *
    399    *  This code that was used to parse the command line was taken
    400    *  from an inappropriate source.  It has been removed and needs
    401    *  to be replaced.
    402    */
    403 
    404   if (!_TOD_Validate(&tod)) {
    405     fprintf(stderr, "Invalid date value\n");
    406   } else {
    407    rtems_clock_set(&tod);         
    408    rtems_clock_get(RTEMS_CLOCK_GET_TOD,&tod);     
    409    rtc=fopen("/dev/rtc","r+");
    410    if (rtc) {
    411     fwrite(&tod,sizeof(tod),1,rtc);
    412     fclose(rtc);
    413    };
    414   };
    415   return 1;
    416 }
     392/* date - print time and date */
    417393
    418394int main_date(int argc,char *argv[])
    419395{
    420396  time_t t;
    421   if (argc == 2)
    422     set_time(argv[1]);
    423397  time(&t);
    424398  printf("%s", ctime(&t));
     
    529503  shell_add_cmd  ("logoff","misc","logoff from the system"                    ,main_logoff);
    530504  shell_alias_cmd("logoff","exit");
    531   shell_add_cmd  ("date" ,"misc","date [[MMDDYY]hhmm[ss]]"                    ,main_date);
     505  shell_add_cmd  ("date" ,"misc","date"                                       ,main_date);
    532506  shell_add_cmd  ("reset","misc","reset the BSP"                              ,main_reset);
    533507  shell_add_cmd  ("alias","misc","alias old new"                              ,main_alias);
  • cpukit/libmisc/shell/shell.c

    rbd520203 r70d689a  
    1717#endif
    1818
     19#undef  __STRICT_ANSI__  /* fileno() */
    1920#include <stdio.h>
    2021
     
    3031#include <stdlib.h>
    3132#include <ctype.h>
     33#include <sys/stat.h>
    3234#include <unistd.h>
    3335#include <errno.h>
     
    223225  shell_cmd_t * shell_cmd=shell_first_cmd;
    224226  if (argc<2) {
    225    printf("help: TOPIC? The topics are\n");       
     227   printf("help: ('r' repeat last cmd - 'e' edit last cmd)\n"     
     228          "  TOPIC? The topics are\n");   
    226229   topic=shell_first_topic;
    227230   col=0;
     
    276279}
    277280/* ----------------------------------------------- *
    278  * TODO:Change to bash readline() better.
     281 * TODO: Add improvements. History, edit vi or emacs, ...
    279282 * ----------------------------------------------- */
    280283int shell_scanline(char * line,int size,FILE * in,FILE * out) {
    281284  int c,col;
    282285  col=0;
     286  if (*line) {
     287   col=strlen(line);     
     288   if (out) fprintf(out,"%s",line);
     289  };
     290  tcdrain(fileno(in ));
    283291  tcdrain(fileno(out));
    284292  for (;;) {
     
    344352}
    345353
     354void write_file(char * name,char * content) {
     355        FILE * fd;
     356        fd=fopen(name,"w");
     357        if (fd) {
     358         fwrite(content,1,strlen(content),fd);
     359         fclose(fd);
     360        }; 
     361}
     362
     363void init_issue(void) {
     364 static char issue_inited=FALSE;
     365 struct stat buf;
     366 if (issue_inited) return;
     367 issue_inited=TRUE;
     368 getpwnam("root"); /* dummy call to init /etc dir */
     369 if (stat("/etc/issue",&buf))
     370  write_file("/etc/issue",
     371             "Welcome to @V\\n"
     372             "Login into @S(@L)\\n");
     373 if (stat("/etc/issue.net",&buf))
     374  write_file("/etc/issue.net",
     375             "Welcome to %v\n"
     376             "running on %m\n");
     377}
     378
    346379int shell_login(FILE * in,FILE * out) {
    347380        FILE * fd;
     
    352385        char pass[128];
    353386        struct passwd * passwd;
     387        init_issue();
    354388        setuid(0);
    355389        setgid(0);
     
    360394            (current_shell_env->devname[6]!='t')||
    361395            (current_shell_env->devname[7]!='y')) {
    362            cat_file(out,"/etc/issue");
     396          fd=fopen("/etc/issue","r");
     397          if (fd) {
     398           while ((c=fgetc(fd))!=EOF) {
     399            if (c=='@')  {
     400             switch(c=fgetc(fd)) {
     401              case 'L':fprintf(out,"%s",current_shell_env->devname);
     402                      break;
     403              case 'B':fprintf(out,"0");
     404                      break;
     405              case 'T':
     406              case 'D':time(&t);
     407                      fprintf(out,"%s",ctime(&t));
     408                      break;
     409              case 'S':fprintf(out,"RTEMS");
     410                      break;
     411              case 'V':fprintf(out,"%s\n%s",_RTEMS_version,_Copyright_Notice);
     412                      break;
     413              case '@':fprintf(out,"@");
     414                      break;
     415              default :fprintf(out,"@%c",c);
     416                      break;
     417             };
     418            } else
     419            if (c=='\\')  {
     420             switch(c=fgetc(fd)) {
     421              case '\\':fprintf(out,"\\");
     422                      break;
     423              case 'b':fprintf(out,"\b"); break;
     424              case 'f':fprintf(out,"\f"); break;
     425              case 'n':fprintf(out,"\n"); break;
     426              case 'r':fprintf(out,"\r"); break;
     427              case 's':fprintf(out," "); break;
     428              case 't':fprintf(out,"\t"); break;
     429              case '@':fprintf(out,"@"); break;
     430             };
     431            } else {
     432             fputc(c,out);                             
     433            };
     434           };
     435           fclose(fd);
     436          }
    363437         } else { 
    364438          fd=fopen("/etc/issue.net","r");
     
    398472        };
    399473        times=0;
     474        strcpy(name,"");
     475        strcpy(pass,"");
    400476        for (;;) {
    401477                times++;
     
    407483                if (out) fprintf(out,"\n");
    408484                if ((passwd=getpwnam(name))) {
    409                  setuid(passwd->pw_uid);                       
    410                  setgid(passwd->pw_gid);                       
    411                  rtems_current_user_env->euid=
    412                  rtems_current_user_env->egid=0;
    413                  chown(current_shell_env->devname,passwd->pw_uid,0);
    414                  rtems_current_user_env->euid=passwd->pw_uid;                   
    415                  rtems_current_user_env->egid=passwd->pw_gid;                   
    416                  if (!strcmp(passwd->pw_passwd,"*")) {
    417                  /* /etc/shadow */
    418                   return 0;
    419                  } else {
    420                   /* crypt() */
    421                   return 0;
     485                 if (strcmp(passwd->pw_passwd,"!")) { /* valid user */
     486                  setuid(passwd->pw_uid);                       
     487                  setgid(passwd->pw_gid);                       
     488                  rtems_current_user_env->euid=
     489                  rtems_current_user_env->egid=0;
     490                  chown(current_shell_env->devname,passwd->pw_uid,0);
     491                  rtems_current_user_env->euid=passwd->pw_uid;                 
     492                  rtems_current_user_env->egid=passwd->pw_gid;                 
     493                  if (!strcmp(passwd->pw_passwd,"*")) {
     494                   /* /etc/shadow */
     495                   return 0;
     496                  } else {
     497                   /* crypt() */
     498                   return 0;
     499                  };
    422500                 };
    423501                };
    424502                if (out) fprintf(out,"Login incorrect\n");
     503                strcpy(name,"");
     504                strcpy(pass,"");
    425505        };
    426506        return -1;
     
    487567    fprintf(stderr,"shell:unable to open stdout.%s:%s\n",devname,strerror(errno));
    488568   };
     569   setvbuf(stdout,NULL,_IONBF,0); /* Not buffered*/
    489570   stderr=fopen(devname,"r+");
    490571   if (!stderr) {
     
    498579  shell_add_cmd(NULL,NULL,NULL,NULL); /* init the chain list*/
    499580  do {
     581   /* Set again root user and root filesystem, side effect of set_priv..*/       
     582  sc=rtems_libio_set_private_env();
     583  if (sc!=RTEMS_SUCCESSFUL) {
     584   rtems_error(sc,"rtems_libio_set_private_env():");     
     585   rtems_task_delete(RTEMS_SELF);
     586  };
    500587  if (!shell_login(stdin,stdout))  {
    501588   cat_file(stdout,"/etc/motd");
     
    503590   strcpy(cmd,"");
    504591   printf("\n"
    505           "RTEMS SHELL (Version 1.0-FRC):%s. "__DATE__". 'help' to list commands.\n",devname);
    506    chdir("/");
     592          "RTEMS SHELL (Ver.1.0-FRC):%s. "__DATE__". 'help' to list commands.\n",devname);
     593   chdir("/"); /* XXX: chdir to getpwent homedir */
    507594   shell_env->exit_shell=FALSE;
    508595   for (;;) {
     
    514601    if (!shell_scanline(cmd,sizeof(cmd),stdin,stdout)) break; /*EOF*/
    515602    /* evaluate cmd section */   
    516     if (!strcmp(cmd,"r")) {  /* repeat last command, forced, not automatic */
     603    if (!strcmp(cmd,"e")) {  /* edit last command */
     604     strcpy(cmd,last_cmd);
     605     continue;
     606    } else
     607    if (!strcmp(cmd,"r")) {  /* repeat last command */
    517608     strcpy(cmd,last_cmd);
    518609    } else
     
    537628    /* end exec cmd section */   
    538629    if (shell_env->exit_shell)  break;
     630    cmd[0]=0;
    539631   };
    540632   printf("\nGoodbye from RTEMS SHELL :-(\n");
     
    589681 return rtems_task_start(task_id,shell_shell,(rtems_task_argument) shell_env);
    590682}
    591 /* ----------------------------------------------- */
  • cpukit/libmisc/shell/shell.h

    rbd520203 r70d689a  
    11/*
     2 *
     3 *  Instantatiate a new terminal shell.
     4 *
     5 *  Author:
     6 *
     7 *   WORK: fernando.ruiz@ctv.es
     8 *   HOME: correo@fernando-ruiz.com
     9 *
     10 *   Thanks at:
     11 *    Chris John
     12 *
    213 *  $Id$
    314 */
     
    5465int shell_scanline(char * line,int size,FILE * in,FILE * out) ;
    5566void cat_file(FILE * out,char *name);
     67void write_file(char *name,char * content);
    5668       
    5769rtems_status_code shell_init(char * task_name      ,
     
    6577                *  current_shell_env;
    6678/*--------*/
    67 /* pty.c */
    68 /*--------*/
    69 
    70 char * get_pty(int socket);
    71 
    72 
    73 rtems_device_driver pty_initialize(
    74   rtems_device_major_number  major,
    75   rtems_device_minor_number  minor,
    76   void                      *arg);
    77 rtems_device_driver pty_open(
    78   rtems_device_major_number major,
    79   rtems_device_minor_number minor,
    80   void                    * arg);
    81 rtems_device_driver pty_close(
    82   rtems_device_major_number major,
    83   rtems_device_minor_number minor,
    84   void                    * arg);
    85 rtems_device_driver pty_read(
    86   rtems_device_major_number major,
    87   rtems_device_minor_number minor,
    88   void                    * arg);
    89 rtems_device_driver pty_write(
    90   rtems_device_major_number major,
    91   rtems_device_minor_number minor,
    92   void                    * arg);
    93 rtems_device_driver pty_control(
    94   rtems_device_major_number major,
    95   rtems_device_minor_number minor,
    96   void                    * arg);
    97 
    98 
    99 #define PTY_DRIVER_TABLE_ENTRY \
    100        { pty_initialize , pty_open , pty_close , \
    101          pty_read , pty_write , pty_control }
    102 /*--------*/
    10379/* cmds.c */
    10480/*--------*/
Note: See TracChangeset for help on using the changeset viewer.