Пример #1
0
static NTSTATUS rpc_service_resume_internal(const DOM_SID *domain_sid,
					const char *domain_name, 
					struct cli_state *cli,
					struct rpc_pipe_client *pipe_hnd,
					TALLOC_CTX *mem_ctx, 
					int argc,
					const char **argv )
{
	POLICY_HND hSCM;
	WERROR result = WERR_GENERAL_FAILURE;
	fstring servicename;
	
	if (argc != 1 ) {
		d_printf("Usage: net rpc service status <service>\n");
		return NT_STATUS_OK;
	}

	fstrcpy( servicename, argv[0] );

	/* Open the Service Control Manager */
	
	result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE  );
	if ( !W_ERROR_IS_OK(result) ) {
		d_fprintf(stderr, "Failed to open Service Control Manager.  [%s]\n", dos_errstr(result));
		return werror_to_ntstatus(result);
	}
	
	result = control_service(pipe_hnd, mem_ctx, &hSCM, servicename, 
		SVCCTL_CONTROL_CONTINUE, SVCCTL_RUNNING );
		
	rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hSCM  );
		
	return werror_to_ntstatus(result);
}	
Пример #2
0
static void _handleAction(Event_T E, Action_T A) {
        ASSERT(E);
        ASSERT(A);

        E->flag = Handler_Succeeded;

        if (A->id != Action_Ignored) {
                /* Alert and mmonit event notification are common actions */
                E->flag |= handle_mmonit(E);
                E->flag |= handle_alert(E);
                /* In the case that some subhandler failed, enqueue the event for partial reprocessing */
                if (E->flag != Handler_Succeeded) {
                        if (Run.eventlist_dir)
                                _queueAdd(E);
                        else
                                LogError("Aborting event\n");
                }
                /* Action event is handled already. For Instance events we don't want actions like stop to be executed to prevent the disabling of system service monitoring */
                if (A->id == Action_Alert || E->id == Event_Instance) {
                        return;
                } else if (A->id == Action_Exec) {
                        if (E->state_changed || (E->state && A->repeat && E->count % A->repeat == 0)) {
                                LogInfo("'%s' exec: %s\n", E->source->name, A->exec->arg[0]);
                                spawn(E->source, A->exec, E);
                                return;
                        }
                } else {
                        if (E->source->actionratelist && (A->id == Action_Start || A->id == Action_Restart))
                                E->source->nstart++;
                        if (E->source->mode == Monitor_Passive && (A->id == Action_Start || A->id == Action_Stop  || A->id == Action_Restart))
                                return;
                        control_service(E->source->name, A->id);
                }
        }
}
Пример #3
0
static void 
process_proxy_thread(void *data, void *user)
{
    proxy_ctrl_t *ctrl = NULL;
    proxy_task_t *task = (proxy_task_t*)data;
    NMP_ASSERT(data);

    switch (task->cmd)
    {
        case BROADCAST_EVENT:
            proxy_broadcast_event(task->data);
            break;
        case CONTROL_DEVICE:
            ctrl = (proxy_ctrl_t*)task->data;
            control_service(ctrl->srv, ctrl->cmd, ctrl->user);
            break;
        case RESOLVE_HOST:
            resolve_host_proxy(task->data);
            break;
        case REBOOT_SERVER:
            proxy_destroy_all_device();
            cleanup_all_service_template();
            EXIT_PROXY_SERVER(3, 0);
            break;

        default:
            break;
    }

    proxy_free_task(task);
    return ;
}
Пример #4
0
HRESULT service_pause_service( IWbemClassObject *obj, IWbemClassObject *in, IWbemClassObject **out )
{
    VARIANT name, retval;
    IWbemClassObject *sig;
    HRESULT hr;

    TRACE("%p, %p, %p\n", obj, in, out);

    hr = IWbemClassObject_Get( obj, prop_nameW, 0, &name, NULL, NULL );
    if (hr != S_OK) return hr;

    hr = create_signature( class_serviceW, method_pauseserviceW, PARAM_OUT, &sig );
    if (hr != S_OK)
    {
        VariantClear( &name );
        return hr;
    }
    hr = IWbemClassObject_SpawnInstance( sig, 0, out );
    if (hr != S_OK)
    {
        VariantClear( &name );
        IWbemClassObject_Release( sig );
        return hr;
    }
    hr = control_service( V_BSTR(&name), SERVICE_CONTROL_PAUSE, &retval );
    if (hr != S_OK) goto done;
    hr = IWbemClassObject_Put( *out, param_returnvalueW, 0, &retval, CIM_UINT32 );

done:
    VariantClear( &name );
    IWbemClassObject_Release( sig );
    if (hr != S_OK) IWbemClassObject_Release( *out );
    return hr;
}
Пример #5
0
/**
 * Check to see if we should try to start/stop service
 * @param S A service name as stated in the config file
 * @param A A string describing the action to execute
 * @return FALSE for error, otherwise TRUE
 */
int control_service_string(const char *S, const char *A) {
  int a;

  ASSERT(S);
  ASSERT(A);

  if ((a = Util_getAction(A)) == ACTION_IGNORE) {
    LogError("%s: service '%s' -- invalid action %s\n", prog, S, A);
    return FALSE;
  }
  return control_service(S, a);
}
Пример #6
0
static void change_mode(gpointer data, int mode)
{
  switch (mode) {
    case TTM_MODE:
      enable_hid_parameters(data, hid_indexes, "0c00");
      break;
    case POINTER_MODE:
      enable_hid_parameters(data, hid_indexes, "0c03");
      break;
    case OPENSPATIAL_MODE:
      control_service(os_indexes, GET_SZ(os_indexes), ENABLE_NOTIFICATION);
      break;
  }
}
Пример #7
0
HRESULT service_stop_service( IWbemClassObject *obj, IWbemClassObject *in, IWbemClassObject **out )
{
    VARIANT name, retval;
    IWbemClassObject *sig, *out_params = NULL;
    HRESULT hr;

    TRACE("%p, %p, %p\n", obj, in, out);

    hr = IWbemClassObject_Get( obj, prop_nameW, 0, &name, NULL, NULL );
    if (hr != S_OK) return hr;

    hr = create_signature( class_serviceW, method_stopserviceW, PARAM_OUT, &sig );
    if (hr != S_OK)
    {
        VariantClear( &name );
        return hr;
    }
    if (out)
    {
        hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
        if (hr != S_OK)
        {
            VariantClear( &name );
            IWbemClassObject_Release( sig );
            return hr;
        }
    }
    hr = control_service( V_BSTR(&name), SERVICE_CONTROL_STOP, &retval );
    if (hr != S_OK) goto done;

    if (out_params)
        hr = IWbemClassObject_Put( out_params, param_returnvalueW, 0, &retval, CIM_UINT32 );

done:
    VariantClear( &name );
    IWbemClassObject_Release( sig );
    if (hr == S_OK && out)
    {
        *out = out_params;
        IWbemClassObject_AddRef( out_params );
    }
    if (out_params) IWbemClassObject_Release( out_params );
    return hr;
}
Пример #8
0
static NTSTATUS rpc_service_resume_internal(struct net_context *c,
					const DOM_SID *domain_sid,
					const char *domain_name,
					struct cli_state *cli,
					struct rpc_pipe_client *pipe_hnd,
					TALLOC_CTX *mem_ctx,
					int argc,
					const char **argv )
{
	struct policy_handle hSCM;
	WERROR result = WERR_GENERAL_FAILURE;
	NTSTATUS status;
	fstring servicename;

	if (argc != 1 ) {
		d_printf(_("Usage: net rpc service status <service>\n"));
		return NT_STATUS_OK;
	}

	fstrcpy( servicename, argv[0] );

	/* Open the Service Control Manager */
	status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx,
					      pipe_hnd->srv_name_slash,
					      NULL,
					      SC_RIGHT_MGR_ENUMERATE_SERVICE,
					      &hSCM,
					      &result);
	if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
		d_fprintf(stderr,
			  _("Failed to open Service Control Manager.  [%s]\n"),
			  win_errstr(result));
		return werror_to_ntstatus(result);
	}

	result = control_service(pipe_hnd, mem_ctx, &hSCM, servicename,
		SVCCTL_CONTROL_CONTINUE, SVCCTL_RUNNING );

	rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM, NULL);

	return werror_to_ntstatus(result);
}
Пример #9
0
static void signal_handler(int sig)
{
  /* some error caused user to hit ^C */
  if (get_state() == STATE_SCANNING) {
    finish_scanning = 1;
  /* if the user wishes to exit the program */
  } else if((get_state() == STATE_DATARCVD) && (sig == SIGINT)) {
    printf("Disabling all notifications\n");
    control_service(all_indexes, GET_SZ(all_indexes), DISABLE_NOTIFICATION);
    printf("Changing back to TTM mode\n");
    change_mode((gpointer)attrib, TTM_MODE);
    /* wait for the notification writes to flush out */
    sleep(1);
    wait_for_cleanup = 0;
    /* exit the looper */
    g_main_loop_quit(event_loop);
  } else {
    /* just exit this app */
    exit(-1);
  }

  return;
}
Пример #10
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);
}
Пример #11
0
int main(int argc, char **argv)
{
  char addr[18];
  char *handle, *value;
  int ret, choice;

  printf("*********************************\n");
  printf("**** Nod Labs test framework ****\n");
  printf("*********************************\n");

  /* initialize a glib event loop */
  event_loop = g_main_loop_new(NULL, FALSE);

  printf("Scanning for all BTLE devices in proximity...");
  printf("Press ^C to stop scanning\n");

  if(ret = cmd_lescan(0) < 0) {
    printf("Scanning failed!! Quitting %d\n", ret);
    exit(-1);
  }

  printf("Enter the device to connect: ");
  scanf("%s", addr);

  ret = 0;
  if (ret = cmd_connect(addr, NULL) < 0) {
    printf("Connection failed %d\n", ret);
    exit(-2);
  } else {
    printf("Connected to [%s]\n", addr);
  }

  printf("SERVICES:\n");
  discover_services((gpointer)attrib);

  printf("\nCHARACTERISTICS:\n");
  discover_characteristics((gpointer)attrib, CHAR_START, CHAR_END);

  /* IMP: If the native bluez stack is running while this test runs, then the
   * keys get cached in the system(on which this is running). Next time, when this
   * test case is being run, it will fail to change the security level to
   * anything other than "low". To resolve this issue, we need to check for
   * the paired devices in bluetoothctl (using cmd 'show devices') and remove
   * the device from bluez device cache.
   *
   * HIGH security level is needed for initiating the bonding with the device. This
   * is important as HID services need the link to be encrypted.
   */
  if (cmd_set_sec_level("high") < 0) {
    printf("Failed to set the security level to HIGH\n");
    exit(-1);
  } else {
    printf("Security level set to HIGH\n");
  }

  /* Now, enable battery and nControl notifications in the ring */
  control_service(non_os_indexes, GET_SZ(non_os_indexes), ENABLE_NOTIFICATION);

  /*
   * TODO: Make sure the below mode list is up-to-date with
   * the numbers used in the f/w
   */

  ret = 0;
  printf("Which mode you want to enable?\n");
  printf("1. TTM\n");
  printf("2. Free pointer\n");
  printf("3. OpenSpatial (Pose6D & Buttons)\n");
  printf("0. Exit\n");
  printf("Enter your choice: ");
  scanf("%d", &choice);
  printf("\n");

  if (!choice) {
    exit(0);
  }
  /* update the mode accordingly */
  change_mode((gpointer)attrib, choice);

  /* We have an active connection, with the data ready to be received */
  set_state(STATE_CONNACTIVE);

  /* let the signal handler do necessary cleanup before proceeding to disconnect */
  wait_for_cleanup = 1;

  /* below loop will control the event loop for receiving the data */
  g_main_loop_run(event_loop);

  while (wait_for_cleanup);

  printf("Disconnecting from device [%s]\n", addr);

  cmd_disconnect();

  /* un-initialize glib event loop */
  g_main_loop_unref(event_loop);

  return 0;
}
Пример #12
0
static void enable_hid_parameters(gpointer data, int notify_array[], const char *mode_str)
{
  control_service(notify_array, GET_SZ(notify_array), ENABLE_NOTIFICATION);
  cmd_write_val(data, NCONTROL_HDL, mode_str);
}