Esempio n. 1
0
static void Signal_Handler(int signal)
{
  Put_message("Signal caught - exiting");
#ifdef HAVE_CURSES
  if (use_menu)
    Cleanup_menu();
#endif
  mr_disconnect();
  exit(1);
}
Esempio n. 2
0
int mr_do_call(struct mr_params *params, struct mr_params *reply)
{
  int status;

  CHECK_CONNECTED;

  status = mr_send(_mr_conn, params);
  if (status == MR_SUCCESS)
    status = mr_receive(_mr_conn, reply);

  if (status)
    mr_disconnect();

  return status;
}
Esempio n. 3
0
int main(int argc, char **argv)
{
  char cmdbuf[BUFSIZ];
  int c;

  whoami = argv[0];
  interactive = (isatty(0) && isatty(1));

  while ((c = getopt(argc, argv, "q")) != -1)
    {
      switch (c)
	{
	case 'q':
	  quote_output = 1;
	  break;

	default:
	  fprintf(stderr, "Usage: mrtest [-q]\n");
	  exit (1);
	}
    }

#if defined(__APPLE__) && defined(__MACH__)
  add_error_table(&et_sms_error_table);
  add_error_table(&et_krb_error_table);
#else
  initialize_sms_error_table();
  initialize_krb_error_table();
#endif

#ifdef HAVE_READLINE
  /* we don't want filename completion */
  rl_bind_key('\t', rl_insert);
#endif

  set_signal_handler(SIGINT, discard_input);
  sigsetjmp(jb, 1);

  while (!quit)
    {
      if (!mr_gets("moira:  ", cmdbuf, BUFSIZ))
	break;
      execute_line(cmdbuf);
    }
  mr_disconnect();
  exit(0);
}
Esempio n. 4
0
JNIEXPORT void JNICALL Java_mit_moira_MoiraConnectInternal_connect(JNIEnv *env,
							 jclass Class, jstring server) {
    int status;
    char buffer[1024];
    const char *aserver = (*env)->GetStringUTFChars(env, server, 0);
    if (strlen(aserver) > sizeof(buffer)) abort();
    strcpy(buffer, aserver);
    (*env)->ReleaseStringUTFChars(env, server, aserver);
    status = mr_connect(buffer);
    if (status != MR_SUCCESS) throwMoiraException(env, status);
    status = mr_version(2);
    if (status != MR_SUCCESS) {
	if (status == MR_VERSION_LOW) return; /* This is OK */
	else {
	    mr_disconnect();
	    throwMoiraException(env, status);
	}
    }
    return;
}
Esempio n. 5
0
int main(int argc, char *argv[])
{
  void (*old_hook)(const char *, long, const char *, va_list);
  int use_menu = 1, k_errno;
  char buf[BUFSIZ];

  if ((whoami = strrchr(argv[0], '/')) == NULL)
    whoami = argv[0];
  else
    whoami++;
  if (!(current_li = malloc(sizeof(List_info))))
    {
      sprintf(buf, ": allocating list info");
      goto punt;
    }
  else
    {
      current_li->acl_type = NULL;
      current_li->acl_name = NULL;
      current_li->desc = NULL;
      current_li->modtime = NULL;
      current_li->modby = NULL;
      current_li->modwith = NULL;
    }

  username = mrcl_krb_user();
  if (!username)
    exit(1);
  
  if (mrcl_connect(NULL, "mailmaint", 2, 1))
    exit(2);

  initscr();
  if ((LINES < 24) || (COLS < 60))
    {
      display_buff("Display window too small.\n\n");
      sprintf(buf, "Current window parameters are (%d lines, %d columns)\n",
	      LINES, COLS);
      display_buff(buf);
      display_buff("Please resize your window\n");
      display_buff("to at least 24 lines and 60 columns.\n");
      exit(0);
    }

  raw();
  noecho();
  old_hook = set_com_err_hook(menu_err_hook);
  position[0] = oldpos[0] = 1;
  level = 0;

  pack_main_menu();
  pack_help_menu();
  display_menu(main_menu);
  get_main_input();
  cls();
  endwin();
  set_com_err_hook(old_hook);

  free_menu(main_menu);
  free_menu(help_menu);

  if (current_li->acl_type)
    free(current_li->acl_type);
  if (current_li->acl_name)
    free(current_li->acl_name);
  if (current_li->desc)
    free(current_li->desc);
  if (current_li->modtime)
    free(current_li->modtime);
  if (current_li->modby)
    free(current_li->modby);
  if (current_li->modwith)
    free(current_li->modwith);
  free(current_li);

  mr_disconnect();

  exit(0);

punt:
  com_err(whoami, status, "%s", buf);
  exit(1);
}
Esempio n. 6
0
void test_disconnect(void)
{
  int status = mr_disconnect();
  if (status)
    com_err("moira (disconnect)", status, "");
}
Esempio n. 7
0
static void ErrorExit(char *buf, int status)
{
  com_err(program_name, status, "%s", buf);
  mr_disconnect();
  exit(1);
}
Esempio n. 8
0
int main(int argc, char **argv)
{
  int status;
  Menu *menu;
  char *motd, **arg;
  struct sigaction act;

  if (!(program_name = strrchr(argv[0], '/')))
    program_name = argv[0];
  else
    program_name++;
  program_name = strdup(program_name);
  whoami = strdup(program_name); /* used by menu.c,  ugh !!! */

  user = mrcl_krb_user();
  if (!user)
    exit(1);

  verbose = TRUE;
  arg = argv;
  moira_server = NULL;

  while (++arg - argv < argc)
    {
      if (**arg == '-')
	{
	  if (!strcmp(*arg, "-nomenu"))
	    {
#ifdef HAVE_CURSES
	      use_menu = FALSE;
#else
	      ;
#endif
	    }
	  else if (!strcmp(*arg, "-menu"))
	    {
#ifdef HAVE_CURSES
	      use_menu = TRUE;
#else
	      fprintf(stderr, "%s: No curses support. -menu option ignored\n",
		      whoami);
#endif
	    }
	  else if (!strcmp(*arg, "-db"))
	    if (arg - argv < argc - 1)
	      {
		++arg;
		moira_server = *arg;
	      }
	    else
	      Usage();
	  else
	    Usage();
	}
    }

  if (mrcl_connect(moira_server, program_name, QUERY_VERSION, 0)
      != MRCL_SUCCESS)
    exit(1);

  if ((status = mr_krb5_auth(program_name)))
    {
      if (status == MR_UNKNOWN_PROC)
	status = mr_auth(program_name);

      if (status)
	{
	  if (status == MR_USER_AUTH)
	    {
	      char buf[BUFSIZ];
	      com_err(program_name, status, "\nPress [RETURN] to continue");
	      fgets(buf, BUFSIZ, stdin);
	    }
	  else
	    ErrorExit("\nAuthorization failed -- please run kinit", status);
	}
    }

  /*
   * These signals should not be set until just before we fire up the menu
   * system.
   */

  sigemptyset(&act.sa_mask);
  act.sa_flags = 0;
  act.sa_handler = Signal_Handler;
  sigaction(SIGHUP, &act, NULL);
  sigaction(SIGQUIT, &act, NULL);
#ifdef HAVE_CURSES
  if (use_menu)
    sigaction(SIGINT, &act, NULL);
  else
#endif
    {
      act.sa_handler = CatchInterrupt;
      sigaction(SIGINT, &act, NULL);
    }

  menu = &namespace_menu;

#ifdef HAVE_CURSES
  if (use_menu)		/* Start menus that execute program */
    {
      Start_paging();
      Start_menu(menu);
      Stop_paging();
    }
  else			/* Start program without menus. */
#endif
    Start_no_menu(menu);

  mr_disconnect();
  exit(0);
}
Esempio n. 9
0
int main(int argc, char *argv[])
{
  int status;                   /* general purpose exit status */
  int q_argc;                   /* argc for mr_query */
  char *q_argv[U_END];          /* argv for mr_query */
  char *motd;                   /* determine Moira server status */
  int got_one = 0;              /* Have we got a shell yet? */
  int windowsflg = 0, unixflg = 0;  
  char **arg = argv;
  char *server = NULL, *shell = NULL;

  if ((whoami = strrchr(argv[0], '/')) == NULL)
    whoami = argv[0];
  else
    whoami++;

  /* parse our command line options */
  while (++arg - argv < argc)
    {
      if (**arg == '-')
	{
	  if (argis("w", "winshell"))
	    windowsflg++;
	  else if (argis("u", "unixshell"))
	    unixflg++;
	  else if (argis("s", "shell"))
	    {
	      if (arg - argv < argc - 1)
		{
		  ++arg;
		  shell = *arg;
		}
	      else
		usage();
	    }
	  else if (argis("db", "database"))
	    {
	      if (arg - argv < argc - 1)
		{
		  ++arg;
		  server = *arg;
		}
	      else
		usage();
	    }
	}
      else if (username == NULL)
	username = *arg;
      else
	usage();
    }

  if (!username)
    {
      username = mrcl_krb_user();
      if (!username)
	exit(1);
    }

  if (!unixflg && !windowsflg)
    unixflg++;

  if (unixflg && windowsflg)
    usage();
  
  if (mrcl_connect(server, "chsh", 14, 1) != MRCL_SUCCESS)
    exit(1);

  /* First, do an access check */

  q_argv[USH_NAME] = username;
  q_argv[USH_SHELL] = "junk";
  q_argc = USH_END;

  if ((status = mr_access("update_user_shell", q_argc, q_argv)))
    {
      com_err(whoami, status, "; shell not\nchanged.");
      exit(2);
    }

  printf("Changing login shell for %s.\n", username);

  /* Display current information */
  
  q_argv[NAME] = username;
  q_argc = NAME + 1;
  
  if ((status = mr_query("get_finger_by_login", q_argc, q_argv,
			 get_fmodtime, username)))
    {
      com_err(whoami, status, "while getting user information.");
      exit(2);
    }

  if (unixflg)
    {
      if ((status = mr_query("get_user_account_by_login", q_argc, q_argv,
			     get_shell, username)))
	{
	  com_err(whoami, status, "while getting user information.");
	  exit(2);
	}


      if (!shell)
	{
	  /* Ask for new shell */
	  while (!got_one)
	    {
	      shell = malloc(MAXPATHLEN);
	      if (!shell)
		exit(1);
	      printf("New shell: ");
	      if (!fgets(shell, MAXPATHLEN, stdin))
		exit(0);
	      got_one = (strlen(shell) > 1);
	    }

	  shell[strlen(shell) - 1] = 0; /* trim newline */
	}

      /* Make sure we have a valid shell.  This routine could exit */
      check_shell(shell);
      
      /* Change shell */
      
      printf("Changing shell to %s...\n", shell);
      
      q_argv[USH_NAME] = username;
      q_argv[USH_SHELL] = shell;
      q_argc = USH_END;
      if ((status = mr_query("update_user_shell", q_argc, q_argv, NULL, NULL)))
	{
	  com_err(whoami, status, "while changing shell.");
	  exit(2);
	}
      
      printf("Shell successfully changed.\n");
    }
  else if (windowsflg)
    {
      if ((status = mr_query("get_user_account_by_login", q_argc, q_argv,
			     get_winshell, username)))
	{
	  com_err(whoami, status, "while getting user information.");
	  exit(2);
	}

      if (!shell)
	{
	  /* Ask for new Windows shell */
	  while(!got_one)
	    {
	      shell = malloc(MAXPATHLEN);
	      if (!shell)
		exit(1);
	      printf("New Windows shell: ");
	      if (!fgets(shell, MAXPATHLEN, stdin))
		exit(0);
	      got_one = (strlen(shell) > 1);
	    }
      
	  shell[strlen(shell) - 1] = 0; /* strip off newline */
	}

      /* Change shell */
      
      printf("Changing Windows shell to %s...\n", shell);
      
      q_argv[USH_NAME] = username;
      q_argv[USH_SHELL] = shell;
      q_argc = USH_END;
      if ((status = mr_query("update_user_windows_shell", q_argc, q_argv,
			     NULL, NULL)))
	{
	  com_err(whoami, status, "while changing Windows shell.");
	  exit(2);
	}
      
      printf("Windows shell successfully changed.\n");
    }
     
  mr_disconnect();
      
  return 0;
}
Esempio n. 10
0
JNIEXPORT void JNICALL Java_mit_moira_MoiraConnectInternal_disconnect
    (JNIEnv *env, jclass Class) {
    mr_disconnect();
    return;
}