Problems with execl("bin/csh", ...) in my OWN shell from login

matt robinson yakker at ucrmath.ucr.edu
Sat Mar 9 05:50:11 AEST 1991


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 at 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------------



More information about the Comp.unix.programmer mailing list