PageRenderTime 24ms CodeModel.GetById 9ms app.highlight 11ms RepoModel.GetById 2ms app.codeStats 0ms

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