/hudson-core/src/main/java/hudson/util/jna/Advapi32.java

http://github.com/hudson/hudson · Java · 351 lines · 75 code · 35 blank · 241 comment · 0 complexity · 105d57ffc7bea840341cf9a7581785f5 MD5 · raw file

  1. /*
  2. Copyright (c) 2007 Thomas Boerkel, All Rights Reserved
  3. Disclaimer:
  4. ===========
  5. This code is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. This code is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. */
  14. package hudson.util.jna;
  15. import com.sun.jna.Structure;
  16. import com.sun.jna.Native;
  17. import com.sun.jna.WString;
  18. import com.sun.jna.Pointer;
  19. import com.sun.jna.win32.StdCallLibrary;
  20. import com.sun.jna.ptr.PointerByReference;
  21. import com.sun.jna.ptr.IntByReference;
  22. /**
  23. *
  24. * @author TB
  25. */
  26. public interface Advapi32 extends StdCallLibrary {
  27. Advapi32 INSTANCE = (Advapi32) Native.loadLibrary("Advapi32", Advapi32.class, Options.UNICODE_OPTIONS);
  28. /**
  29. * Retrieves the name of the user associated with the current thread.
  30. *
  31. * <p>
  32. * See http://msdn.microsoft.com/en-us/library/ms724432(VS.85).aspx
  33. */
  34. boolean GetUserName(char[] buffer, IntByReference lpnSize);
  35. /*
  36. BOOL WINAPI LookupAccountName(
  37. LPCTSTR lpSystemName,
  38. LPCTSTR lpAccountName,
  39. PSID Sid,
  40. LPDWORD cbSid,
  41. LPTSTR ReferencedDomainName,
  42. LPDWORD cchReferencedDomainName,
  43. PSID_NAME_USE peUse
  44. );*/
  45. public boolean LookupAccountName(String lpSystemName, String lpAccountName,
  46. byte[] Sid, IntByReference cbSid, char[] ReferencedDomainName,
  47. IntByReference cchReferencedDomainName, PointerByReference peUse);
  48. /*
  49. BOOL WINAPI LookupAccountSid(
  50. LPCTSTR lpSystemName,
  51. PSID lpSid,
  52. LPTSTR lpName,
  53. LPDWORD cchName,
  54. LPTSTR lpReferencedDomainName,
  55. LPDWORD cchReferencedDomainName,
  56. PSID_NAME_USE peUse
  57. );*/
  58. public boolean LookupAccountSid(String lpSystemName, byte[] Sid,
  59. char[] lpName, IntByReference cchName, char[] ReferencedDomainName,
  60. IntByReference cchReferencedDomainName, PointerByReference peUse);
  61. /*
  62. BOOL ConvertSidToStringSid(
  63. PSID Sid,
  64. LPTSTR* StringSid
  65. );*/
  66. public boolean ConvertSidToStringSid(byte[] Sid, PointerByReference StringSid);
  67. /*
  68. BOOL WINAPI ConvertStringSidToSid(
  69. LPCTSTR StringSid,
  70. PSID* Sid
  71. );*/
  72. public boolean ConvertStringSidToSid(String StringSid, PointerByReference Sid);
  73. /*
  74. SC_HANDLE WINAPI OpenSCManager(
  75. LPCTSTR lpMachineName,
  76. LPCTSTR lpDatabaseName,
  77. DWORD dwDesiredAccess
  78. );*/
  79. public Pointer OpenSCManager(String lpMachineName, WString lpDatabaseName, int dwDesiredAccess);
  80. /*
  81. BOOL WINAPI CloseServiceHandle(
  82. SC_HANDLE hSCObject
  83. );*/
  84. public boolean CloseServiceHandle(Pointer hSCObject);
  85. /*
  86. SC_HANDLE WINAPI OpenService(
  87. SC_HANDLE hSCManager,
  88. LPCTSTR lpServiceName,
  89. DWORD dwDesiredAccess
  90. );*/
  91. public Pointer OpenService(Pointer hSCManager, String lpServiceName, int dwDesiredAccess);
  92. /*
  93. BOOL WINAPI StartService(
  94. SC_HANDLE hService,
  95. DWORD dwNumServiceArgs,
  96. LPCTSTR* lpServiceArgVectors
  97. );*/
  98. public boolean StartService(Pointer hService, int dwNumServiceArgs, char[] lpServiceArgVectors);
  99. /*
  100. BOOL WINAPI ControlService(
  101. SC_HANDLE hService,
  102. DWORD dwControl,
  103. LPSERVICE_STATUS lpServiceStatus
  104. );*/
  105. public boolean ControlService(Pointer hService, int dwControl, SERVICE_STATUS lpServiceStatus);
  106. /*
  107. BOOL WINAPI StartServiceCtrlDispatcher(
  108. const SERVICE_TABLE_ENTRY* lpServiceTable
  109. );*/
  110. public boolean StartServiceCtrlDispatcher(Structure[] lpServiceTable);
  111. /*
  112. SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandler(
  113. LPCTSTR lpServiceName,
  114. LPHANDLER_FUNCTION lpHandlerProc
  115. );*/
  116. public Pointer RegisterServiceCtrlHandler(String lpServiceName, Handler lpHandlerProc);
  117. /*
  118. SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerEx(
  119. LPCTSTR lpServiceName,
  120. LPHANDLER_FUNCTION_EX lpHandlerProc,
  121. LPVOID lpContext
  122. );*/
  123. public Pointer RegisterServiceCtrlHandlerEx(String lpServiceName, HandlerEx lpHandlerProc, Pointer lpContext);
  124. /*
  125. BOOL WINAPI SetServiceStatus(
  126. SERVICE_STATUS_HANDLE hServiceStatus,
  127. LPSERVICE_STATUS lpServiceStatus
  128. );*/
  129. public boolean SetServiceStatus(Pointer hServiceStatus, SERVICE_STATUS lpServiceStatus);
  130. /*
  131. SC_HANDLE WINAPI CreateService(
  132. SC_HANDLE hSCManager,
  133. LPCTSTR lpServiceName,
  134. LPCTSTR lpDisplayName,
  135. DWORD dwDesiredAccess,
  136. DWORD dwServiceType,
  137. DWORD dwStartType,
  138. DWORD dwErrorControl,
  139. LPCTSTR lpBinaryPathName,
  140. LPCTSTR lpLoadOrderGroup,
  141. LPDWORD lpdwTagId,
  142. LPCTSTR lpDependencies,
  143. LPCTSTR lpServiceStartName,
  144. LPCTSTR lpPassword
  145. );*/
  146. public Pointer CreateService(Pointer hSCManager, String lpServiceName, String lpDisplayName,
  147. int dwDesiredAccess, int dwServiceType, int dwStartType, int dwErrorControl,
  148. String lpBinaryPathName, String lpLoadOrderGroup, IntByReference lpdwTagId,
  149. String lpDependencies, String lpServiceStartName, String lpPassword);
  150. /*
  151. BOOL WINAPI DeleteService(
  152. SC_HANDLE hService
  153. );*/
  154. public boolean DeleteService(Pointer hService);
  155. /*
  156. BOOL WINAPI ChangeServiceConfig2(
  157. SC_HANDLE hService,
  158. DWORD dwInfoLevel,
  159. LPVOID lpInfo
  160. );*/
  161. public boolean ChangeServiceConfig2(Pointer hService, int dwInfoLevel, ChangeServiceConfig2Info lpInfo);
  162. /*
  163. LONG WINAPI RegOpenKeyEx(
  164. HKEY hKey,
  165. LPCTSTR lpSubKey,
  166. DWORD ulOptions,
  167. REGSAM samDesired,
  168. PHKEY phkResult
  169. );*/
  170. public int RegOpenKeyEx(int hKey, String lpSubKey, int ulOptions, int samDesired, IntByReference phkResult);
  171. /*
  172. LONG WINAPI RegQueryValueEx(
  173. HKEY hKey,
  174. LPCTSTR lpValueName,
  175. LPDWORD lpReserved,
  176. LPDWORD lpType,
  177. LPBYTE lpData,
  178. LPDWORD lpcbData
  179. );*/
  180. public int RegQueryValueEx(int hKey, String lpValueName, IntByReference lpReserved, IntByReference lpType, byte[] lpData, IntByReference lpcbData);
  181. /*
  182. LONG WINAPI RegCloseKey(
  183. HKEY hKey
  184. );*/
  185. public int RegCloseKey(int hKey);
  186. /*
  187. LONG WINAPI RegDeleteValue(
  188. HKEY hKey,
  189. LPCTSTR lpValueName
  190. );*/
  191. public int RegDeleteValue(int hKey, String lpValueName);
  192. /*
  193. LONG WINAPI RegSetValueEx(
  194. HKEY hKey,
  195. LPCTSTR lpValueName,
  196. DWORD Reserved,
  197. DWORD dwType,
  198. const BYTE* lpData,
  199. DWORD cbData
  200. );*/
  201. public int RegSetValueEx(int hKey, String lpValueName, int Reserved, int dwType, byte[] lpData, int cbData);
  202. /*
  203. LONG WINAPI RegCreateKeyEx(
  204. HKEY hKey,
  205. LPCTSTR lpSubKey,
  206. DWORD Reserved,
  207. LPTSTR lpClass,
  208. DWORD dwOptions,
  209. REGSAM samDesired,
  210. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  211. PHKEY phkResult,
  212. LPDWORD lpdwDisposition
  213. );*/
  214. public int RegCreateKeyEx(int hKey, String lpSubKey, int Reserved, String lpClass, int dwOptions,
  215. int samDesired, WINBASE.SECURITY_ATTRIBUTES lpSecurityAttributes, IntByReference phkResult,
  216. IntByReference lpdwDisposition);
  217. /*
  218. LONG WINAPI RegDeleteKey(
  219. HKEY hKey,
  220. LPCTSTR lpSubKey
  221. );*/
  222. public int RegDeleteKey(int hKey, String name);
  223. /*
  224. LONG WINAPI RegEnumKeyEx(
  225. HKEY hKey,
  226. DWORD dwIndex,
  227. LPTSTR lpName,
  228. LPDWORD lpcName,
  229. LPDWORD lpReserved,
  230. LPTSTR lpClass,
  231. LPDWORD lpcClass,
  232. PFILETIME lpftLastWriteTime
  233. );*/
  234. public int RegEnumKeyEx(int hKey, int dwIndex, char[] lpName, IntByReference lpcName, IntByReference reserved,
  235. char[] lpClass, IntByReference lpcClass, WINBASE.FILETIME lpftLastWriteTime);
  236. /*
  237. LONG WINAPI RegEnumValue(
  238. HKEY hKey,
  239. DWORD dwIndex,
  240. LPTSTR lpValueName,
  241. LPDWORD lpcchValueName,
  242. LPDWORD lpReserved,
  243. LPDWORD lpType,
  244. LPBYTE lpData,
  245. LPDWORD lpcbData
  246. );*/
  247. public int RegEnumValue(int hKey, int dwIndex, char[] lpValueName, IntByReference lpcchValueName, IntByReference reserved,
  248. IntByReference lpType, byte[] lpData, IntByReference lpcbData);
  249. interface SERVICE_MAIN_FUNCTION extends StdCallCallback {
  250. /*
  251. VOID WINAPI ServiceMain(
  252. DWORD dwArgc,
  253. LPTSTR* lpszArgv
  254. );*/
  255. public void callback(int dwArgc, Pointer lpszArgv);
  256. }
  257. interface Handler extends StdCallCallback {
  258. /*
  259. VOID WINAPI Handler(
  260. DWORD fdwControl
  261. );*/
  262. public void callback(int fdwControl);
  263. }
  264. interface HandlerEx extends StdCallCallback {
  265. /*
  266. DWORD WINAPI HandlerEx(
  267. DWORD dwControl,
  268. DWORD dwEventType,
  269. LPVOID lpEventData,
  270. LPVOID lpContext
  271. );*/
  272. public int callback(int dwControl, int dwEventType, Pointer lpEventData, Pointer lpContext);
  273. }
  274. /*
  275. typedef struct _SERVICE_STATUS {
  276. DWORD dwServiceType;
  277. DWORD dwCurrentState;
  278. DWORD dwControlsAccepted;
  279. DWORD dwWin32ExitCode;
  280. DWORD dwServiceSpecificExitCode;
  281. DWORD dwCheckPoint;
  282. DWORD dwWaitHint;
  283. } SERVICE_STATUS,
  284. *LPSERVICE_STATUS;*/
  285. public static class SERVICE_STATUS extends Structure {
  286. public int dwServiceType;
  287. public int dwCurrentState;
  288. public int dwControlsAccepted;
  289. public int dwWin32ExitCode;
  290. public int dwServiceSpecificExitCode;
  291. public int dwCheckPoint;
  292. public int dwWaitHint;
  293. }
  294. /*
  295. typedef struct _SERVICE_TABLE_ENTRY {
  296. LPTSTR lpServiceName;
  297. LPSERVICE_MAIN_FUNCTION lpServiceProc;
  298. } SERVICE_TABLE_ENTRY,
  299. *LPSERVICE_TABLE_ENTRY;*/
  300. public static class SERVICE_TABLE_ENTRY extends Structure {
  301. public String lpServiceName;
  302. public SERVICE_MAIN_FUNCTION lpServiceProc;
  303. }
  304. public static class ChangeServiceConfig2Info extends Structure {
  305. }
  306. /*
  307. typedef struct _SERVICE_DESCRIPTION {
  308. LPTSTR lpDescription;
  309. } SERVICE_DESCRIPTION,
  310. *LPSERVICE_DESCRIPTION;*/
  311. public static class SERVICE_DESCRIPTION extends ChangeServiceConfig2Info {
  312. public String lpDescription;
  313. }
  314. }