services.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Services.exe - include file
  3. *
  4. * Copyright 2007 Google (Mikolaj Zalewski)
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  19. */
  20. #ifndef WINE_PROGRAMS_UTILS_H_
  21. #define WINE_PROGRAMS_UTILS_H_
  22. #include "wine/list.h"
  23. struct scmdatabase
  24. {
  25. HKEY root_key;
  26. LONG service_start_lock;
  27. struct list processes;
  28. struct list services;
  29. CRITICAL_SECTION cs;
  30. };
  31. struct process_entry
  32. {
  33. struct list entry;
  34. struct scmdatabase *db;
  35. LONG ref_count;
  36. LONG use_count;
  37. DWORD process_id;
  38. HANDLE process;
  39. HANDLE control_mutex;
  40. HANDLE control_pipe;
  41. HANDLE overlapped_event;
  42. };
  43. struct service_entry
  44. {
  45. struct list entry;
  46. struct scmdatabase *db;
  47. LONG ref_count; /* number of references - if goes to zero and the service is deleted the structure will be freed */
  48. LPWSTR name;
  49. SERVICE_STATUS status;
  50. HANDLE status_changed_event;
  51. QUERY_SERVICE_CONFIGW config;
  52. DWORD preshutdown_timeout;
  53. LPWSTR description;
  54. LPWSTR dependOnServices;
  55. LPWSTR dependOnGroups;
  56. struct process_entry *process;
  57. BOOL shared_process;
  58. BOOL force_shutdown;
  59. BOOL marked_for_delete;
  60. BOOL is_wow64;
  61. BOOL delayed_autostart;
  62. struct list handles;
  63. };
  64. extern struct scmdatabase *active_database;
  65. /* SCM database functions */
  66. struct service_entry *scmdatabase_find_service(struct scmdatabase *db, LPCWSTR name);
  67. struct service_entry *scmdatabase_find_service_by_displayname(struct scmdatabase *db, LPCWSTR name);
  68. DWORD scmdatabase_add_service(struct scmdatabase *db, struct service_entry *entry);
  69. BOOL scmdatabase_lock_startup(struct scmdatabase *db, int timeout);
  70. void scmdatabase_unlock_startup(struct scmdatabase *db);
  71. void scmdatabase_lock(struct scmdatabase *db);
  72. void scmdatabase_unlock(struct scmdatabase *db);
  73. /* Service functions */
  74. DWORD service_create(LPCWSTR name, struct service_entry **entry);
  75. BOOL validate_service_name(LPCWSTR name);
  76. BOOL validate_service_config(struct service_entry *entry);
  77. DWORD save_service_config(struct service_entry *entry);
  78. void free_service_entry(struct service_entry *entry);
  79. struct service_entry *grab_service(struct service_entry *service);
  80. void release_service(struct service_entry *service);
  81. void service_lock(struct service_entry *service);
  82. void service_unlock(struct service_entry *service);
  83. DWORD service_start(struct service_entry *service, DWORD service_argc, LPCWSTR *service_argv);
  84. /* Process functions */
  85. struct process_entry *grab_process(struct process_entry *process);
  86. void release_process(struct process_entry *process);
  87. BOOL process_send_control(struct process_entry *process, BOOL winedevice, const WCHAR *name,
  88. DWORD control, const BYTE *data, DWORD data_size, DWORD *result);
  89. void process_terminate(struct process_entry *process);
  90. extern DWORD service_pipe_timeout;
  91. extern DWORD service_kill_timeout;
  92. extern HANDLE exit_event;
  93. DWORD RPC_Init(void);
  94. void RPC_Stop(void);
  95. /* from utils.c */
  96. LPWSTR strdupW(LPCWSTR str);
  97. BOOL check_multisz(LPCWSTR lpMultiSz, DWORD cbSize);
  98. DWORD load_reg_string(HKEY hKey, LPCWSTR szValue, BOOL bExpand, LPWSTR *output);
  99. DWORD load_reg_multisz(HKEY hKey, LPCWSTR szValue, BOOL bAllowSingle, LPWSTR *output);
  100. DWORD load_reg_dword(HKEY hKey, LPCWSTR szValue, DWORD *output);
  101. static inline LPCWSTR get_display_name(struct service_entry *service)
  102. {
  103. return service->config.lpDisplayName ? service->config.lpDisplayName : service->name;
  104. }
  105. static inline BOOL is_marked_for_delete(struct service_entry *service)
  106. {
  107. return service->marked_for_delete;
  108. }
  109. static inline DWORD mark_for_delete(struct service_entry *service)
  110. {
  111. service->marked_for_delete = TRUE;
  112. return ERROR_SUCCESS;
  113. }
  114. #endif /*WINE_PROGRAMS_UTILS_H_*/