Example #1
0
int main(int argc, char **argv) {
  GThread *thread;

  stoppuhr_init();
  open_spielplan();

  gtk_init(&argc, &argv);

  admin_init();
  beamer_init();

  context = g_main_context_default();

  thread = g_thread_new(NULL, thread_func, GINT_TO_POINTER(3));
  gtk_main();
  close_spielplan();
  return 0;
}
Example #2
0
int
session(void)
{
	fd_set rfds;
	struct timeval *timeout;
	int error;
	struct myaddrs *p;
	char pid_file[MAXPATHLEN];
	FILE *fp;
	pid_t racoon_pid = 0;
	int i;

	/* initialize schedular */
	sched_init();

	init_signal();

#ifdef ENABLE_ADMINPORT
	if (admin_init() < 0)
		exit(1);
#endif

	initmyaddr();

	if (isakmp_init() < 0)
		exit(1);

	initfds();

#ifdef ENABLE_NATT
	natt_keepalive_init ();
#endif

	if (privsep_init() != 0)
		exit(1);

	for (i = 0; i <= NSIG; i++)
		sigreq[i] = 0;

	/* write .pid file */
	racoon_pid = getpid();
	if (lcconf->pathinfo[LC_PATHTYPE_PIDFILE] == NULL) 
		strlcpy(pid_file, _PATH_VARRUN "racoon.pid", MAXPATHLEN);
	else if (lcconf->pathinfo[LC_PATHTYPE_PIDFILE][0] == '/') 
		strlcpy(pid_file, lcconf->pathinfo[LC_PATHTYPE_PIDFILE], MAXPATHLEN);
	else {
		strlcat(pid_file, _PATH_VARRUN, MAXPATHLEN);
		strlcat(pid_file, lcconf->pathinfo[LC_PATHTYPE_PIDFILE], MAXPATHLEN);
	} 
	fp = fopen(pid_file, "w");
	if (fp) {
		if (fchmod(fileno(fp),
			S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) == -1) {
			syslog(LOG_ERR, "%s", strerror(errno));
			fclose(fp);
			exit(1);
		}
		fprintf(fp, "%ld\n", (long)racoon_pid);
		fclose(fp);
	} else {
		plog(LLV_ERROR, LOCATION, NULL,
			"cannot open %s", pid_file);
	}

	while (1) {
		if (dying)
			rfds = maskdying;
		else
			rfds = mask0;

		/*
		 * asynchronous requests via signal.
		 * make sure to reset sigreq to 0.
		 */
		check_sigreq();

		/* scheduling */
		timeout = schedular();

		error = select(nfds, &rfds, (fd_set *)0, (fd_set *)0, timeout);
		if (error < 0) {
			switch (errno) {
			case EINTR:
				continue;
			default:
				plog(LLV_ERROR, LOCATION, NULL,
					"failed to select (%s)\n",
					strerror(errno));
				return -1;
			}
			/*NOTREACHED*/
		}

#ifdef ENABLE_ADMINPORT
		if ((lcconf->sock_admin != -1) &&
		    (FD_ISSET(lcconf->sock_admin, &rfds)))
			admin_handler();
#endif

		for (p = lcconf->myaddrs; p; p = p->next) {
			if (!p->addr)
				continue;
			if (FD_ISSET(p->sock, &rfds))
				isakmp_handler(p->sock);
		}

		if (FD_ISSET(lcconf->sock_pfkey, &rfds))
			pfkey_handler();

		if (lcconf->rtsock >= 0 && FD_ISSET(lcconf->rtsock, &rfds)) {
			if (update_myaddrs() && lcconf->autograbaddr)
				sched_new(5, check_rtsock, NULL);
			initfds();
		}
	}
}
Example #3
0
/*
 * Use global *tty_tmp and term_parent
 */
int
main( int argc, char **argv )
{
   struct cl_args *cl_args;
   struct term_node *tty_node = NULL;
   pid_t pid;
   pid_t parent_id;
#if defined(HAVE_PTHREAD_SETCONCURRENCY) && !defined(LINUX)
   int concurrent;
#endif

   handle_signals_parent();

   tcgetattr(0, &term_parent);   

   parent_id = getpid();

   if ((pid = fork()) < 0)
   {
      exit(1);
   }
   else
   {
      if (pid != 0)
      {
         wait(NULL);
         tcsetattr(0, TCSANOW, &term_parent);
         exit(0);
      }
   }

   fatal_error = 4;

   /* Disable all signals while initializing data...*/
   handle_signals();

   setvbuf(stdout, NULL, _IONBF, 0);

   tty_tmp = (struct term_tty *)calloc(1,sizeof(struct term_tty));

   if (tty_tmp == NULL)
   {
      printf("Out of memory on calloc tty_tmp\n");
      clean_exit();
   }

   tty_tmp->term = (struct termios *)calloc(1,sizeof(struct termios));      

   if (tty_tmp->term == NULL)
   {
      printf("Out of memory on calloc tty_tmp->term\n");
      clean_exit();
   }

   /* default values */
   tty_tmp->interactive = 0;
   tty_tmp->gtk = 0;
   tty_tmp->attack = -1;
   tty_tmp->mac_spoofing = -1;
   tty_tmp->splash = -1;
   strncpy(tty_tmp->username, VTY_USER, MAX_USERNAME);
   strncpy(tty_tmp->password, VTY_PASS, MAX_PASSWORD);
   strncpy(tty_tmp->e_password, VTY_ENABLE, MAX_PASSWORD);
   tty_tmp->port = VTY_PORT;
   tty_tmp->ip_filter = NULL;
#ifdef HAVE_GTK
   tty_tmp->buffer_log = NULL;
#endif

   cl_args = (struct cl_args *)calloc(1,sizeof(struct cl_args));

   if (cl_args == NULL)
   {
      printf("Out of memory on calloc cl_args\n");
      clean_exit();
   }

   if ( argc == 1 )                                                          
   {
      printf("GNU %s %s %s\n", PACKAGE, VERSION,
            "$Date: 2006/03/23 08:40:14 $");
      printf("Try '%s -h' to display the help.\n",PACKAGE);
      clean_exit();
   }

   if (getuid() != 0) 
   {
      printf("You must be root to run %s %s\n", PACKAGE, VERSION);
      clean_exit();
   }

   if (term_init() < 0)
      g00dbye();

   /* Register all the protocols */
   protocol_init();

   cl_args->proto_index = -1;

   if (parser_initial(tty_tmp, cl_args, argc, argv) < 0) {
      clean_exit();
   } 

   init_log();

#if defined(HAVE_PTHREAD_SETCONCURRENCY) && !defined(LINUX)
/*   concurrent = pthread_getconcurrency();*/

   concurrent = 15;/*(MAX_TERMS*MAX_PROTOCOLS*MAX_THREAD_ATTACK*2)+3;*/

   if (pthread_setconcurrency(concurrent) != 0)
   {
      thread_error("init pthread_setconcurrency()",errno);
      g00dbye();
   }
#endif

   if (interfaces_init(&terms->pcap_listen_th) < 0 )
      g00dbye();

   /* Establish TERM signal handler...*/
   posix_signal(SIGTERM, final);


#ifdef HAVE_REMOTE_ADMIN
   if (tty_tmp->daemonize)
   {
      if (admin_init(tty_tmp) < 0)
         g00dbye();
   }
#endif 

   if (thread_create(&terms->uptime_th.id, &th_uptime, (void *)NULL) < 0)
      g00dbye();

   /* Command line and ncurses cannot be choosed simultaneously...*/
   if ((!tty_tmp->interactive) && (!tty_tmp->gtk) && (cl_args->proto_index != -1)) 
   {
      terms->work_state = INITIAL;
      tty_node = term_type[TERM_TTY].list;
      if (thread_create(&tty_node[0].thread.id, &th_tty_peer, 
               (void *)cl_args) < 0)
         g00dbye();

      while(terms->work_state != STOPPED)
         thread_usleep(100000);
   }

#ifdef HAS_CURSES
   if (tty_tmp->interactive)
   {
      terms->work_state = INITIAL;
      if (thread_create(&terms->gui_th.id, &ncurses_gui, NULL) < 0 )
         g00dbye();
      /* Wait until the ncurses GUI is over */
      while(terms->work_state != STOPPED)
         thread_usleep(100000);
   }
   else
   {
#endif
#ifdef HAVE_GTK
      if (tty_tmp->gtk)
      {
         terms->work_state = INITIAL;
         if (thread_create(&terms->gui_gtk_th.id, &gtk_gui, NULL) < 0 )
            g00dbye();
         /* Wait until the GTK GUI is over */
         while(terms->work_state != STOPPED)
            thread_usleep(100000);
      }
#endif
#ifdef HAS_CURSES
   }
#endif

#ifdef HAVE_REMOTE_ADMIN
   if (tty_tmp->daemonize)
   {
      /* Ok, now that console (ncurses) is finished
       * we can become a true daemon... */
      become_daemon(parent_id);

      /* Wait until some important thread exits due to fatal_error...*/
      while (fatal_error == 4)
         thread_usleep(100000);
   }
#endif

   g00dbye();

   exit(1);
}
Example #4
0
int main(int argc, char **argv)
{
	void *dest_addr;
	struct cmd_struct *cmd;
	struct admin_opts opts;
	int i, ret, addr_type, status = 0;
	int cmd_num = ARRAY_SIZE(admin_cmds);
	int rsock;

	ret = parse_opts(argc, argv, &status);
	if (ret)
		exit(status);

	for (i = 0; i < cmd_num; i++) {
		cmd = admin_cmds + i;
		if (!strncmp(argv[optind], cmd->cmd, strlen(cmd->cmd)))
			break;
	}

	if (i == cmd_num) {
		fprintf(stderr, "Non-existing command specified\n");
		show_usage();
		exit(-1);
	}

	if (!strncmp(cmd->cmd, "help", 4)) {
		if (argc - optind <= 1) {
			fprintf(stderr, "No command was specified\n");
			exit(-1);
		}

		for (i = 0; i < cmd_num; i++) {
			cmd = admin_cmds + i;
			if (!strncmp(argv[optind + 1], cmd->cmd,
				     strlen(cmd->cmd)))
				break;
		}

		if (i == cmd_num) {
			fprintf(stderr, "Non-existing command specified\n");
			show_usage();
			exit(-1);
		}

		if (cmd)
			show_cmd_usage(cmd->cmd, admin_cmd_help(cmd->id),
				       admin_get_cmd_opts(cmd->id));

		exit(0);
	}

	if (dest_lid) {
		dest_addr = &dest_lid;
		addr_type = ADMIN_ADDR_TYPE_LID;
	} else {
		if (!dest_gid)
			dest_gid = "::1"; /* local host GID */
		dest_addr = dest_gid;
		addr_type = ADMIN_ADDR_TYPE_GID;
	}

	if (admin_init(short_option, long_option) < 0) {
		fprintf(stderr, "ERROR - unable to init admin client\n");
		exit(-1);
	}

	opts.dev = ca_name;
	opts.src_port = src_port;
	opts.admin_port = admin_port;
	opts.pkey = pkey;
	opts.timeout = timeout;

	rsock = admin_connect(dest_addr, addr_type, &opts);
	if (rsock < 0) {
		fprintf(stderr, "ERROR - unable to connect\n");
		exit(-1);
	}

	optind = 1;
	ret = admin_exec_recursive(rsock, cmd->id, recursive, argc, argv);
	if (ret) {
		fprintf(stderr, "Failed executing '%s' command (%s)\n",
		       cmd->cmd, admin_cmd_help(cmd->id)->desc);
		exit(-1);
	}

	admin_disconnect(rsock);
	admin_cleanup();

	return 0;
}