From b2712e35b948d7ab37cf6ef46bcdfea678506444 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Thu, 24 May 2001 21:58:39 +0000 Subject: 2000-05-24 Fernando Ruiz Casas * monitor/mon-prmisc.c: Correct print line. * shell/Makefile.am: Added new file telnetd.c. * shell/telnetd.c, shell/telnetd.h, shell/pty.c: New files. * shell/shell.c, shell/cmds.c, shell/shell.h: Numerous improvments: - The shell_init has a new parameter 'forever' because in /dev/console you need that this process runs forever but in tcp/ip not. (respawn?) - A new task for every session opened trought tcp/ip telnet client. (the chargen,daytime and more are possible of implementation but I ask me if they are necesary) - Exit from the session delete the task and when the client fails too. - More cmds have been implemented. (very reduced version of these) umask, chmod, id, whoami, rm, cat, ... - A reduced line edit has been implemented. Ctrl-C abort the input, Ctrl-d in the first position gives EOF (logout). '\b' and DEL makes the rubout operation. I think that readline() for every session spents a lot of resources. --- cpukit/libmisc/shell/cmds.c | 123 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 114 insertions(+), 9 deletions(-) (limited to 'cpukit/libmisc/shell/cmds.c') diff --git a/cpukit/libmisc/shell/cmds.c b/cpukit/libmisc/shell/cmds.c index c1c670f997..32402aa1e7 100644 --- a/cpukit/libmisc/shell/cmds.c +++ b/cpukit/libmisc/shell/cmds.c @@ -13,7 +13,7 @@ * MINIX date.c is adapted to run here. Like a exercise only.... * * TODO: A lot of improvements of course. - * cat, cp, rm, mv, ... + * cp, mv, ... * hexdump, * * More? Say me it, please... @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include #include #include @@ -257,6 +259,10 @@ int main_ls(int argc, char *argv[]) DIR *dirp; struct dirent *dp; struct stat stat_buf; + struct passwd * pwd; + struct group * grp; + char * user; + char * group; char sbuf[256]; char nbuf[1024]; int n,size; @@ -279,7 +285,11 @@ int main_ls(int argc, char *argv[]) if (stat(nbuf, &stat_buf) == 0) { /* AWFUL buts works...*/ strftime(sbuf,sizeof(sbuf)-1,"%b %d %H:%M",gmtime(&stat_buf.st_atime)); - printf("%c%c%c%c%c%c%c%c%c%c %3d rtems rtems %11d %s %s%c\n", + pwd=getpwuid(stat_buf.st_uid); + user=pwd?pwd->pw_name:"nouser"; + grp=getgrgid(stat_buf.st_gid); + group=grp?grp->gr_name:"nogrp"; + printf("%c%c%c%c%c%c%c%c%c%c %3d %6.6s %6.6s %11d %s %s%c\n", (S_ISLNK(stat_buf.st_mode)?('l'): (S_ISDIR(stat_buf.st_mode)?('d'):('-'))), (stat_buf.st_mode & S_IRUSR)?('r'):('-'), @@ -292,6 +302,7 @@ int main_ls(int argc, char *argv[]) (stat_buf.st_mode & S_IWOTH)?('w'):('-'), (stat_buf.st_mode & S_IXOTH)?('x'):('-'), (int)stat_buf.st_nlink, + user,group, (int)stat_buf.st_size, sbuf, dp->d_name, @@ -352,6 +363,28 @@ int main_chroot(int argc,char * argv[]) { return 0; } /*-----------------------------------------------------------*/ +int main_cat (int argc, char *argv[]) +{ + int n; + n=1; + while (nexit_shell=TRUE; + return 0; +} +/*-----------------------------------------------------------*/ +int main_tty (int argc,char *argv[]) +{ + printf("%s\n",ttyname(fileno(stdin))); + return 0; +} +/*-----------------------------------------------------------*/ +int main_whoami(int argc,char *argv[]) +{ + struct passwd * pwd; + pwd=getpwuid(getuid()); + printf("%s\n",pwd?pwd->pw_name:"nobody"); + return 0; +} +/*-----------------------------------------------------------*/ +int main_id (int argc,char *argv[]) +{ + struct passwd * pwd; + struct group * grp; + pwd=getpwuid(getuid()); + grp=getgrgid(getgid()); + printf("uid=%d(%s),gid=%d(%s),", + getuid(),pwd?pwd->pw_name:"", + getgid(),grp?grp->gr_name:""); + pwd=getpwuid(geteuid()); + grp=getgrgid(getegid()); + printf("euid=%d(%s),egid=%d(%s)\n", + geteuid(),pwd?pwd->pw_name:"", + getegid(),grp?grp->gr_name:""); + return 0; +} +/*-----------------------------------------------------------*/ +int main_umask(int argc,char *argv[]) +{ + mode_t msk=umask(0); + if (argc == 2) msk=str2int(argv[1]); + umask(msk); + msk=umask(0); + printf("0%o\n",msk); + umask(msk); + return 0; +} +/*-----------------------------------------------------------*/ +int main_chmod(int argc,char *argv[]) +{ + int n; + mode_t mode; + if (argc > 2){ + mode=str2int(argv[1])&0777; + n=2; + while (ncommand)) /*Exclude EXIT (alias quit)*/ + shell_add_cmd(command->command,"monitor", + command->usage ,main_monitor); + command=command->next; + }; /* dir[ectories] topic */ shell_add_cmd ("ls" ,"dir","ls [dir] # list files in the directory" ,main_ls ); shell_add_cmd ("chdir" ,"dir","chdir [dir] # change the current directory",main_chdir); @@ -449,14 +551,24 @@ void register_cmds(void) { shell_add_cmd ("mkdir" ,"dir","mkdir dir # make a directory" ,main_mkdir); shell_add_cmd ("pwd" ,"dir","pwd # print work directory" ,main_pwd ); shell_add_cmd ("chroot","dir","chroot [dir] # change the root directory" ,main_chroot); + shell_add_cmd ("cat" ,"dir","cat n1 [n2 [n3...]]# show the ascii contents",main_cat ); + shell_add_cmd ("rm" ,"dir","rm n1 [n2 [n3...]]# remove files" ,main_rm ); + shell_add_cmd ("chmod" ,"dir","chmod 0777 n1 n2... #change filemode" ,main_chmod); shell_alias_cmd("ls" ,"dir"); shell_alias_cmd("chdir" ,"cd"); /* misc. topic */ + shell_add_cmd ("logoff","misc","logoff from the system" ,main_logoff); + shell_alias_cmd("logoff","exit"); shell_add_cmd ("date" ,"misc","date [[MMDDYY]hhmm[ss]]" ,main_date); shell_add_cmd ("reset","misc","reset the BSP" ,main_reset); shell_add_cmd ("alias","misc","alias old new" ,main_alias); + shell_add_cmd ("tty" ,"misc","show ttyname" ,main_tty ); + shell_add_cmd ("whoami","misc","show current user" ,main_whoami); + shell_add_cmd ("id" ,"misc","show uid,gid,euid,egid" ,main_id ); + shell_add_cmd ("umask" ,"misc","umask [new_umask]" ,main_umask ); + /* memory topic */ shell_add_cmd ("mdump","mem" ,"mdump [adr [size]]" ,main_mdump); @@ -467,12 +579,5 @@ void register_cmds(void) { #ifdef MALLOC_STATS /* /rtems/s/src/lib/libc/malloc.c */ shell_add_cmd ("malloc","mem","mem show memory malloc'ed" ,main_mem); #endif - /* monitor topic */ - command=rtems_monitor_commands; - while (command) { - shell_add_cmd(command->command,"monitor", - command->usage ,main_monitor); - command=command->next; - }; } /*-----------------------------------------------------------*/ -- cgit v1.2.3