Beispiel #1
0
int main(int argc, char **argv) {
  /* Remember if we are admin */
  check_admin();

  /* Elevate */
  if (argc > 1) {
    /* Valid commands are install or remove */
    if (str_equiv(argv[1], "install")) {
      if (! is_admin) {
        print_message(stderr, NSSM_MESSAGE_NOT_ADMINISTRATOR_CANNOT_INSTALL);
        exit(100);
      }
      exit(pre_install_service(argc - 2, argv + 2));
    }
    if (str_equiv(argv[1], "remove")) {
      if (! is_admin) {
        print_message(stderr, NSSM_MESSAGE_NOT_ADMINISTRATOR_CANNOT_REMOVE);
        exit(100);
      }
      exit(pre_remove_service(argc - 2, argv + 2));
    }
  }

  /* Thread local storage for error message buffer */
  tls_index = TlsAlloc();

  /* Register messages */
  if (is_admin) create_messages();

  /*
    Optimisation for Windows 2000:
    When we're run from the command line the StartServiceCtrlDispatcher() call
    will time out after a few seconds on Windows 2000.  On newer versions the
    call returns instantly.  Check for stdin first and only try to call the
    function if there's no input stream found.  Although it's possible that
    we're running with input redirected it's much more likely that we're
    actually running as a service.
    This will save time when running with no arguments from a command prompt.
  */
  if (_fileno(stdin) < 0) {
    /* Set up function pointers. */
    if (get_imports()) exit(111);

    /* Start service magic */
    SERVICE_TABLE_ENTRY table[] = { { NSSM, service_main }, { 0, 0 } };
    if (! StartServiceCtrlDispatcher(table)) {
      unsigned long error = GetLastError();
      /* User probably ran nssm with no argument */
      if (error == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) exit(usage(1));
      log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_DISPATCHER_FAILED, error_string(error), 0);
      free_imports();
      exit(100);
    }
  }
  else exit(usage(1));

  /* And nothing more to do */
  exit(0);
}
Beispiel #2
0
/*
 * asetadmin
 *
 * Usage: asetadmin player AdminLevel
 *
 *   Sets the admin level of the player with the following restrictions.
 *   1. You can only set the admin level of players lower than yourself.
 *   2. You can only set the admin level to a level that is lower than
 *      yourself.
 */
int com_asetadmin(int p, param_list param)
{
  struct player *pp = &player_globals.parray[p];
  int p1, connected, oldlevel;

  if (!FindPlayer(p, param[0].val.word,&p1, &connected))
    return COM_OK;

  if (!check_admin2(p, p1)) {
    pprintf(p, "You can only set adminlevel for players below your adminlevel.\n");
    if (!connected)
      player_remove(p1);
    return COM_OK;
  }
  if (!strcmp(player_globals.parray[p1].login, pp->login)) {
    pprintf(p, "You can't change your own adminlevel.\n");
    return COM_OK;
  }
  if (!check_admin(p, param[1].val.integer+1)) {
    pprintf(p, "You can't promote someone to or above your adminlevel.\n");
    if (!connected)
      player_remove(p1);
    return COM_OK;
  }
  if (param[1].val.integer < 0)
  {
    pprintf(p, "Level must be positive.\n");
    if (!connected)
      player_remove(p1);
    return COM_OK;
  }
  oldlevel = player_globals.parray[p1].adminLevel;
  player_globals.parray[p1].adminLevel = param[1].val.integer;
  pprintf(p, "Admin level of %s set to %d.\n", player_globals.parray[p1].name, player_globals.parray[p1].adminLevel);
  player_save(p1);
  if (connected) {
    pprintf_prompt(p1, "\n\n%s has set your admin level to %d.\n\n", pp->name, player_globals.parray[p1].adminLevel);
  } else {
    player_remove(p1);
  }
  return COM_OK;
}
Beispiel #3
0
/*
 * annunreg
 *
 * Usage:  annunreg message
 *
 *   Broadcasts your message to all logged on unregistered users, and admins,
 *   too.  Announcements reach all unregistered users and admins and cannot be
 *   censored in any way (such as by "set shout 0").
 */
int com_annunreg(int p, param_list param)
{
	struct player *pp = &player_globals.parray[p];
	int p1;
	int count = 0;

	if (!printablestring(param[0].val.string)) {
		pprintf(p, "Your message contains some unprintable character(s).\n");
		return COM_OK;
	}
	for (p1 = 0; p1 < player_globals.p_num; p1++) {
		if (p1 == p) continue;
		if (player_globals.parray[p1].status != PLAYER_PROMPT) continue;
		if (CheckPFlag(p1, PFLAG_REG)
		    && !check_admin(p1, ADMIN_ADMIN))
			continue;
		count++;
		pprintf_prompt(p1, "\n\n    **UNREG ANNOUNCEMENT** from %s: %s\n\n",
			       pp->name, param[0].val.string);
	}
	pprintf(p, "\n(%d) **UNREG ANNOUNCEMENT** from %s: %s\n\n",
		count, pp->name, param[0].val.string);
	return COM_OK;
}
Beispiel #4
0
int _tmain(int argc, TCHAR **argv) {
  check_console();

#ifdef UNICODE
  /*
    Ensure we write in UTF-16 mode, so that non-ASCII characters don't get
    mangled.  If we were compiled in ANSI mode it won't work.
   */
  _setmode(_fileno(stdout), _O_U16TEXT);
  _setmode(_fileno(stderr), _O_U16TEXT);
#endif

  /* Remember if we are admin */
  check_admin();

  /* Set up function pointers. */
  if (get_imports()) exit(111);

  /* Remember our path for later. */
  GetModuleFileName(0, unquoted_imagepath, _countof(unquoted_imagepath));
  GetModuleFileName(0, imagepath, _countof(imagepath));
  PathQuoteSpaces(imagepath);

  /* Elevate */
  if (argc > 1) {
    /*
      Valid commands are:
      start, stop, pause, continue, install, edit, get, set, reset, unset, remove
    */
    if (str_equiv(argv[1], _T("start"))) exit(control_service(NSSM_SERVICE_CONTROL_START, argc - 2, argv + 2));
    if (str_equiv(argv[1], _T("stop"))) exit(control_service(SERVICE_CONTROL_STOP, argc - 2, argv + 2));
    if (str_equiv(argv[1], _T("restart"))) {
      int ret = control_service(SERVICE_CONTROL_STOP, argc - 2, argv + 2);
      if (ret) exit(ret);
      exit(control_service(NSSM_SERVICE_CONTROL_START, argc - 2, argv + 2));
    }
    if (str_equiv(argv[1], _T("pause"))) exit(control_service(SERVICE_CONTROL_PAUSE, argc - 2, argv + 2));
    if (str_equiv(argv[1], _T("continue"))) exit(control_service(SERVICE_CONTROL_CONTINUE, argc - 2, argv + 2));
    if (str_equiv(argv[1], _T("status"))) exit(control_service(SERVICE_CONTROL_INTERROGATE, argc - 2, argv + 2));
    if (str_equiv(argv[1], _T("rotate"))) exit(control_service(NSSM_SERVICE_CONTROL_ROTATE, argc - 2, argv + 2));
    if (str_equiv(argv[1], _T("install"))) {
      if (! is_admin) exit(elevate(argc, argv, NSSM_MESSAGE_NOT_ADMINISTRATOR_CANNOT_INSTALL));
      create_messages();
      exit(pre_install_service(argc - 2, argv + 2));
    }
    if (str_equiv(argv[1], _T("edit")) || str_equiv(argv[1], _T("get")) || str_equiv(argv[1], _T("set")) || str_equiv(argv[1], _T("reset")) || str_equiv(argv[1], _T("unset"))) {
      int ret = pre_edit_service(argc - 1, argv + 1);
      if (ret == 3 && ! is_admin && argc == 3) exit(elevate(argc, argv, NSSM_MESSAGE_NOT_ADMINISTRATOR_CANNOT_EDIT));
      /* There might be a password here. */
      for (int i = 0; i < argc; i++) SecureZeroMemory(argv[i], _tcslen(argv[i]) * sizeof(TCHAR));
      exit(ret);
    }
    if (str_equiv(argv[1], _T("list"))) exit(list_nssm_services());
    if (str_equiv(argv[1], _T("remove"))) {
      if (! is_admin) exit(elevate(argc, argv, NSSM_MESSAGE_NOT_ADMINISTRATOR_CANNOT_REMOVE));
      exit(pre_remove_service(argc - 2, argv + 2));
    }
  }

  /* Thread local storage for error message buffer */
  tls_index = TlsAlloc();

  /* Register messages */
  if (is_admin) create_messages();

  /*
    Optimisation for Windows 2000:
    When we're run from the command line the StartServiceCtrlDispatcher() call
    will time out after a few seconds on Windows 2000.  On newer versions the
    call returns instantly.  Check for stdin first and only try to call the
    function if there's no input stream found.  Although it's possible that
    we're running with input redirected it's much more likely that we're
    actually running as a service.
    This will save time when running with no arguments from a command prompt.
  */
  if (! GetStdHandle(STD_INPUT_HANDLE)) {
    /* Start service magic */
    SERVICE_TABLE_ENTRY table[] = { { NSSM, service_main }, { 0, 0 } };
    if (! StartServiceCtrlDispatcher(table)) {
      unsigned long error = GetLastError();
      /* User probably ran nssm with no argument */
      if (error == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) exit(usage(1));
      log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_DISPATCHER_FAILED, error_string(error), 0);
      free_imports();
      exit(100);
    }
  }
  else exit(usage(1));

  /* And nothing more to do */
  exit(0);
}
Beispiel #5
0
/*
  check that player p1 can do an admin operation on player p2
*/
static int check_admin2(int p1, int p2)
{
	return check_admin(p1, player_globals.parray[p2].adminLevel+1);
}