Example #1
0
int	main(void)
{
  char		*cmd;
  t_node	*tree;

  init_global();
  while (!global.status)
    {
      tree = NULL;
      global.prompt = edit_prompt(global.config, global.env);
      if ((cmd = edit_cmd(&global, global.prompt)) == NULL && !global.status)
	global.status = !global.status;
      if (my_strlen(cmd) >= MAX_LINE_NUMBER)
	fprintf(stderr, "%s: File name too long\n", cmd);
      else if (!global.status)
	if (is_singlestr(' ', cmd) && (tree = parsing_func(cmd, &global, 0)))
	  if ((exec_course_tree(tree, global.env, &global)) == EXIT_CHILD)
	    {
	      sh_free(&global, tree, cmd);
	      (global.prompt) ? free(global.prompt) : (global.prompt = NULL);
	      return (global.exit);
	    }
      sh_free(NULL, tree, cmd);
      (global.prompt) ? free(global.prompt) : (global.prompt = NULL);
    }
  sh_free(&global, NULL, NULL);
  return (global.exit);
}
Example #2
0
int	main(void)
{
  char		*cmd;
  t_node	*tree;
  int	exit;

  global.status = 0;
  global.env = creat_env();
  global.config = config_parser(".42shrc");
  global.hist = NULL;
  global.data = NULL;
  termcap_init(global.env);
  stop_signal();
  while (!global.status)
    {
      tree = NULL;
      global.prompt = edit_prompt(global.config, global.env);
      if ((cmd = edit_cmd(&global, global.prompt)) == NULL && !global.status)
	global.status = !global.status;
      if (!global.status)
	if (is_singlestr(' ', cmd) && (tree = parsing_func(cmd, &global)))
	  if ((exit = exec_course_tree(tree, global.env, &global)) == EXIT_CHILD)
	    return (exit);
      (cmd) ? free(cmd) : (cmd = NULL);
      (global.prompt) ? free(global.prompt) : (global.prompt = NULL);
    }
  return (exit);
}
Example #3
0
int
main(int argc, char *argv[]) {
	int exitstatus;

	setprogname(argv[0]);
	Pid = getpid();
	(void)setlocale(LC_ALL, "");

	euid = geteuid();
	egid = getegid();
	ruid = getuid();
	rgid = getgid();

	if (euid == ruid && ruid != 0)
		errx(ERROR_EXIT, "Not installed setuid root");

	(void)setvbuf(stderr, NULL, _IOLBF, 0);
	parse_args(argc, argv);		/* sets many globals, opens a file */
	set_cron_cwd();
	if (!allowed(RealUser, CRON_ALLOW, CRON_DENY)) {
		(void)fprintf(stderr,
			"You `%s' are not allowed to use this program `%s'\n",
			User, getprogname());
		(void)fprintf(stderr, "See crontab(1) for more information\n");
		log_it(RealUser, Pid, "AUTH", "crontab command not allowed");
		exit(ERROR_EXIT);
	}
	exitstatus = OK_EXIT;
	switch (Option) {
	case opt_unknown:
		usage("unrecognized option");
		exitstatus = ERROR_EXIT;
		break;
	case opt_list:
		list_cmd();
		break;
	case opt_delete:
		delete_cmd();
		break;
	case opt_edit:
		edit_cmd();
		break;
	case opt_replace:
		if (replace_cmd() < 0)
			exitstatus = ERROR_EXIT;
		break;
	default:
		abort();
	}
	exit(exitstatus);
	/*NOTREACHED*/
}
Example #4
0
int
main (int argc, char *argv[])
{
  int exitstatus;
  char *config_file;		/* Name of our configuration file;  NULL if none */

  Pid = getpid ();
  ProgramName = argv[0];

#if defined(POSIX)
  setlocale (LC_ALL, "");
#endif

#if HAVE_SETLINEBUF
  setlinebuf (stderr);
#endif /*HAVE_SETLINEBUF */
  parse_args (argc, argv, &config_file);	/* sets many globals, opens a file */

  read_config (config_file, &allow_only_root, &log_syslog, &allow_file,
	       &deny_file, &crondir, &spool_dir, &log_file, &syscrontab,
	       &lastrun_file, &pidfile, &mailprog, &mailargs);

  set_cron_cwd ();
  if (!allowed (User))
    {
      fprintf (stderr,
	       "You (%s) are not allowed to use this program (%s)\n",
	       User, ProgramName);
      fprintf (stderr, "See crontab(1) for more information\n");
      log_it (RealUser, Pid, "AUTH", "crontab command not allowed");
      exit (ERROR_EXIT);
    }
  exitstatus = OK_EXIT;
  switch (Option)
    {
    case opt_list:
      list_cmd ();
      break;
    case opt_delete:
      delete_cmd ();
      break;
    case opt_edit:
      edit_cmd ();
      break;
    case opt_replace:
      if (replace_cmd () < 0)
	exitstatus = ERROR_EXIT;
      break;
    }
  exit (0);
 /*NOTREACHED*/}
Example #5
0
int
main(int argc, char *argv[])
{
	int	exitstatus;

	Pid = getpid();
	ProgramName = argv[0];

#if defined(POSIX)
	setlocale(LC_ALL, "");
#endif

#if defined(BSD)
	setlinebuf(stderr);
#endif
	parse_args(argc, argv);		/* sets many globals, opens a file */
	set_cron_uid();
	set_cron_cwd();
	if (!allowed(User)) {
		warnx("you (%s) are not allowed to use this program", User);
		log_it(RealUser, Pid, "AUTH", "crontab command not allowed");
		exit(ERROR_EXIT);
	}
	exitstatus = OK_EXIT;
	switch (Option) {
	case opt_list:		list_cmd();
				break;
	case opt_delete:	delete_cmd();
				break;
	case opt_edit:		edit_cmd();
				break;
	case opt_replace:	if (replace_cmd() < 0)
					exitstatus = ERROR_EXIT;
				break;
	case opt_unknown:
				break;
	}
	exit(exitstatus);
	/*NOTREACHED*/
}
Example #6
0
int
edit_pol (SwitchPol * spol, AppData * a)
{
  uint32_t i, maxx;
  int state = 0;
  uint32_t num_strings;
  int lbl_x, idx = 0;
  MENU *my_menu;
  SwitchPol tmp;
  SwitchCmd *scmd;
  ITEM **my_items;
  char **mnu_str[2];
//      WINDOW * menu_win,*menu_sub;
  uint32_t num;

  spPolDeepCopy (&tmp, spol);
  num = tmp.num_cmds;
  scmd = tmp.cmds;

  message (a,
           "Modify Polarisation parameters or edit Commands.\nPress a to add a command, d to delete, press c to cancel");
  while (state >= 0)
  {
    num_strings = num + 1;
    state = 0;
    debugMsg ("allocating items\n");

    my_items = (ITEM **) utlCalloc (num_strings + 1, sizeof (ITEM *));

    mnu_str[0] = utlCalloc (num_strings, sizeof (char *));
    mnu_str[1] = utlCalloc (num_strings, sizeof (char *));

    debugMsg ("allocating items\n");
    mnu_str[0][0] = "Pol";
    mnu_str[1][0] = (char *) tpiGetPolStr (tmp.pol);
    my_items[0] = new_item (mnu_str[0][0], mnu_str[1][0]);

    for (i = 1; i < num_strings; ++i)
    {
      mnu_str[0][i] = utlCalloc (32, sizeof (char));
      mnu_str[1][i] = (char *) spGetCmdStr (scmd[i - 1].what);
      snprintf (mnu_str[0][i], 32, "Cmd%" PRIu32, i - 1);
      my_items[i] = new_item (mnu_str[0][i], mnu_str[1][i]);
      if (NULL == my_items[i])
      {
        if (errno == E_BAD_ARGUMENT)
          errMsg ("badarg i=%" PRIu32 "\n", i);
        if (errno == E_SYSTEM_ERROR)
          errMsg ("new_item: syserr i=%" PRIu32 "\n", i);
      }
    }
    my_items[num_strings] = (ITEM *) NULL;
    my_menu = new_menu ((ITEM **) my_items);
    set_menu_opts (my_menu,
                   O_ONEVALUE | O_NONCYCLIC | O_ROWMAJOR | O_SHOWDESC);
    maxx = getmaxx (stdscr);
    appDataMakeMenuWnd (my_menu);
    post_menu (my_menu);
    lbl_x = 3 + (maxx - 6) / 2 - strlen ("Pol") / 2;
    mvwprintw (menu_win (my_menu), 1, lbl_x, "%s", "Pol");
    wrefresh (menu_win (my_menu));
    debugMsg ("starting menu loop\n");
    while (state == 0)
    {
      int c;
      ITEM *selection;
      c = getch ();
      switch (c)
      {
      case 263:                //ESC
      case K_BACK:             //Backspace
        state = -1;
        break;
      case KEY_DOWN:
        menu_driver (my_menu, REQ_DOWN_ITEM);
        break;
      case KEY_UP:
        menu_driver (my_menu, REQ_UP_ITEM);
        break;
      case KEY_RESIZE:
        //windows need to be resized.. ignore
        break;
      case 'd':
        selection = current_item (my_menu);
        idx = item_index (selection);
        state = 1;
        break;
      case 'a':
        state = 2;
        break;
      case 'c':
        state = 3;
        break;
      case 13:                 //enter
        selection = current_item (my_menu);
        idx = item_index (selection);
        state = 5;
        break;
      default:
        break;
      }
      wrefresh (menu_win (my_menu));
    }
    unpost_menu (my_menu);
    appDataDestroyMenuWnd (my_menu);
    free_menu (my_menu);
    for (i = 0; i < num_strings; ++i)
    {
      free_item (my_items[i]);
    }
    for (i = 1; i < num_strings; ++i)
      utlFAN (mnu_str[0][i]);
    utlFAN (mnu_str[0]);
    utlFAN (mnu_str[1]);
    utlFAN (my_items);
    if (state > 0)
    {
      switch (state)
      {
      case 1:                  //del
        if (idx >= 1)
          spCmdDel (&scmd, &num, idx - 1);
        break;
      case 2:                  //add(at the end)
        spCmdAdd (&scmd, &num, num);
        break;
      case 3:                  //cancel
        spPolClear (&tmp);      //clear temporary
        return 1;
      case 5:                  //edit
        if (idx >= 1)
          edit_cmd (scmd + idx - 1, a);
        else
        {
          int rv;
          rv = get_pol (a);
          if (rv >= 0)
            tmp.pol = rv;
        }
        break;
      default:
        break;
      }
    }
  }
  spPolClear (spol);            //clear original
  *spol = tmp;                  //replace with temporary
  return 0;
}