yakker@ucrmath.ucr.edu (matt robinson) (03/09/91)
The problem I'm having is that I need to start up a new /bin/csh from my /bin/eggsh, which is designed to keep the user 'guest' out of the machine if he is coming from an invalid host (and not from the console.) The problem is in the function startup() in the code included here, which will hang from login. The user with the /bin/eggsh who comes in from a valid host just hangs without going into a new /bin/csh. I think the problem has to do with opening up a new pty, but I'm not sure as this is my first time attempting to write something of this nature. Any assistance would be greatly appreciated. Thanks for your time. --Matt ______________________________________________________________________________ Matt D. Robinson "...if I only had a brain..." Systems Programming Group, UC Riverside -- The Scarecrow, The Wizard Of Oz Internet : yakker@ucrmath.ucr.edu UUCP : ..!ucsd!ucrmath!{yakker,source} ------------BEGIN INCLUDED CODE------------BEGIN INCLUDED CODE----------- /* // Subject : Problems with execl("bin/csh", ...) in my OWN shell from login */ #include <stdio.h> #include <utmp.h> #define UTMP "/etc/utmp" #define ENTRY_MACH "/etc/disabled" #ifndef TRUE #define TRUE 0 #define FALSE 1 #endif #ifndef BUFSIZ #define BUFSIZ 1024 #endif int check_machines(char *host) { FILE *fp; char *str; if ((fp = fopen(ENTRY_MACH, "r")) == NULL) return FALSE; while (!feof(fp)) { str = (char *)malloc(BUFSIZ); fgets(str, BUFSIZ-1, fp); str[strlen(str) - 1] = '\0'; if (!feof(fp)) { if (!strcmp(host, str)) { fclose(fp); free(str); return TRUE; } } free(str); } fclose(fp); return FALSE; } /* // HERE IS THE PROBLEM. */ void startup() { int pid, nfd; if ((pid = fork()) < 0) { fprintf(stderr, "Could not start up csh. Exiting.\n"); exit(1); } if (!pid) { wait(&nfd); exit(0); } else { execl("/bin/csh","csh",(char *)0); } } /* // END PROBLEM */ int main() { FILE *fp; struct utmp ut; char *str, *console = "console"; if ((fp = fopen(UTMP, "r")) == NULL) startup(); while (fread((char *)&ut, sizeof(struct utmp), 1, fp) == 1) { if ((!strcmp(ut.ut_name, "guest")) && (strcmp(ut.ut_line, console))) { if (check_machines(ut.ut_host) == TRUE) { free(str); fclose(fp); fprintf(stderr, "No modem logins.\n"); exit(1); } } } fclose(fp); fprintf(stderr, "You look okay to me. You can login.\n"); startup(); } -------------END INCLUDED CODE--------------END INCLUDED CODE------------
reg@pinet.aip.org (Dr. Richard Glass) (03/10/91)
When cshell is a login shell, it is given a special name of -. What you may want to try is is the following : execl("/bin/csh", "-", (char **)0 ); This will invoke the csh as if the shell was invoked by login. Ricky Glass - reg@pinet.aip.org
yakker@ucrmath.ucr.edu (matt robinson) (03/18/91)
In article <12602@ucrmath.ucr.edu> yakker@ucrmath.ucr.edu writes: >The problem I'm having is that I need to start up a new /bin/csh from my >/bin/eggsh, which is designed to keep the user 'guest' out of the machine >if he is coming from an invalid host (and not from the console.) The problem >is in the function startup() in the code included here, which will hang from >login. The user with the /bin/eggsh who comes in from a valid host just hangs >without going into a new /bin/csh. Well, this was my own article, and I didn't have anyone reply to it (except for two individuals, whose answers didn't work.) Can someone out there come up with any reasonable answer? Is there any systems administrator willing to put forth the effort and try this on their machine? The suggestions given were to try execl("/bin/csh", "-csh", (char *)0), or execl("/bin/csh", "-", (char *)0), both of which do not work. I would appreciate your time and patience, and thanks again, NetLand! --Matt ______________________________________________________________________________ Matt D. Robinson "...if I only had a brain..." Systems Programming Group, UC Riverside -- The Scarecrow, The Wizard Of Oz Internet : yakker@ucrmath.ucr.edu UUCP : ..!ucsd!ucrmath!{yakker,source} INCLUDED FILE AGAIN: -------------------- ------------BEGIN INCLUDED CODE------------BEGIN INCLUDED CODE----------- /* // Subject : Problems with execl("bin/csh", ...) in my OWN shell from login */ #include <stdio.h> #include <utmp.h> #define UTMP "/etc/utmp" #define ENTRY_MACH "/etc/disabled" #ifndef TRUE #define TRUE 0 #define FALSE 1 #endif #ifndef BUFSIZ #define BUFSIZ 1024 #endif int check_machines(char *host) { FILE *fp; char *str; if ((fp = fopen(ENTRY_MACH, "r")) == NULL) return FALSE; while (!feof(fp)) { #ifndef lint str = (char *)malloc(BUFSIZ); #else str = NULL; #endif (void)fgets(str, BUFSIZ-1, fp); str[strlen(str) - 1] = '\0'; if (!feof(fp)) { if (!strcmp(host, str)) { (void)fclose(fp); (void)free(str); return TRUE; } } (void)free(str); } (void)fclose(fp); return FALSE; } /* // HERE IS THE PROBLEM. */ void startup() { /* // Even if I do the execl("/bin/csh", ...) with a "-csh", or a "-", // it does not work. WHY? */ (void)execl("/bin/csh","-csh",(char *)0); } /* // END PROBLEM */ int main() { FILE *fp; struct utmp ut; char *console = "console"; if ((fp = fopen(UTMP, "r")) == NULL) startup(); while (fread((char *)&ut, sizeof(struct utmp), 1, fp) == 1) { if ((!strcmp(ut.ut_name, "guest")) && (strcmp(ut.ut_line, console))) { if (check_machines(ut.ut_host) == TRUE) { (void)fclose(fp); (void)fprintf(stderr, "No modem logins.\n"); exit(1); } } } (void)fclose(fp); fprintf(stderr, "You look okay to me. You can login.\n"); startup(); } -------------END INCLUDED CODE--------------END INCLUDED CODE------------
john@iastate.edu (Hascall John Paul) (03/19/91)
In article <12860@ucrmath.ucr.edu> yakker@ucrmath.ucr.edu (matt robinson) writes: }In article <12602@ucrmath.ucr.edu> yakker@ucrmath.ucr.edu writes: }>The problem I'm having is that I need to start up a new /bin/csh from my }>/bin/eggsh, which is designed to keep the user 'guest' out of the machine } }The suggestions given were to try execl("/bin/csh", "-csh", (char *)0), }or execl("/bin/csh", "-", (char *)0), both of which do not work. This compiled and ran just fine for me. DECstation 2100, Ultrix 3.1 John -- John Hascall An ill-chosen word is the fool's messenger. Project Vincent Iowa State University Computation Center john@iastate.edu Ames, IA 50011 (515) 294-9551
ray@ctbilbo.UUCP (Ray Ward) (03/23/91)
In article <12860@ucrmath.ucr.edu>, yakker@ucrmath.ucr.edu (matt robinson) writes: > In article <12602@ucrmath.ucr.edu> yakker@ucrmath.ucr.edu writes: > >The problem I'm having is that I need to start up a new /bin/csh from my > >/bin/eggsh, [...] > > Well, this was my own article, and I didn't have anyone reply to it (except > for two individuals, whose answers didn't work.) [...] > > The suggestions given were to try execl("/bin/csh", "-csh", (char *)0), > or execl("/bin/csh", "-", (char *)0), both of which do not work. However, both of these DO work on the machine I am on at the moment, a XENIX SysV 386 :-( . So it would appear that the problem lies elsewhere. I only ran the execl calls in a small test program; I did not run your entire source excerpt as your utmp structure used fields this system's utmp.h did not have. You did not mention the machine that you are running on or the extent of the code in your eggsh ( but, then, I didn't see your original posting ). On some systems I have worked on I have experienced similar it-just-hangs symptoms from someone's wild pointer stepping on something. Try the calls in a small test program that only does an execl(). If the calls work in the same context without the other code present, I would bet the problem is in the other code. -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Ray Ward Email: uunet!ctbilbo!ray Voice: (214) 991-8338x226, (800) 331-7032 Fax : (214) 991-8968 =-=-=-=- There _are_ simple answers, just no _easy_ ones. -- R.R. -=-=-=-=