paragraph for gnunet devs that don't know how to use the web
[oweals/gnunet.git] / src / include / winproc.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2001, 2002, 2003, 2004, 2005 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      Affero General Public License for more details.
14     
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /**
20  * @author Nils Durner
21  *
22  * @file
23  * Definitions for MS Windows
24  */
25
26 #ifndef _WINPROC_H
27 #define _WINPROC_H
28
29 #include <io.h>
30 #include <stdio.h>
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <sys/timeb.h>
34 #include <time.h>
35 #include <dirent.h>
36 #ifndef FD_SETSIZE
37 #define FD_SETSIZE 1024
38 #endif
39 #include <winsock2.h>
40 #include <ws2tcpip.h>
41 #include <windows.h>
42 #include <winerror.h>
43 #include <iphlpapi.h>
44 #include <shlobj.h>
45 #include <objbase.h>
46 #include <sys/param.h>          /* #define BYTE_ORDER */
47 #include <ntsecapi.h>
48 #include <lm.h>
49 #include <aclapi.h>
50
51
52 #ifdef __cplusplus
53 extern "C"
54 {
55 #endif
56
57 #ifndef MAX_NAME_LENGTH
58 #define MAX_NAME_LENGTH 25
59 #endif
60
61   typedef DWORD WINAPI (*TNtQuerySystemInformation) (int, PVOID, ULONG, PULONG);
62   typedef DWORD WINAPI (*TGetIfEntry) (PMIB_IFROW pIfRow);
63   typedef DWORD WINAPI (*TGetIpAddrTable) (PMIB_IPADDRTABLE pIpAddrTable,
64                                            PULONG pdwSize, BOOL bOrder);
65   typedef DWORD WINAPI (*TGetIfTable) (PMIB_IFTABLE pIfTable, PULONG pdwSize,
66                                        BOOL bOrder);
67   typedef DWORD WINAPI (*TGetBestInterfaceEx) (struct sockaddr *, PDWORD);
68   /* TODO: Explicitly import -A variants (i.e. TCreateHardLinkA) or -W
69    * variants (TCreateHardLinkW), etc.
70    */
71   typedef DWORD WINAPI (*TCreateHardLink) (LPCTSTR lpFileName,
72                                            LPCTSTR lpExistingFileName,
73                                            LPSECURITY_ATTRIBUTES
74                                            lpSecurityAttributes);
75   typedef SC_HANDLE WINAPI (*TOpenSCManager) (LPCTSTR lpMachineName,
76                                               LPCTSTR lpDatabaseName,
77                                               DWORD dwDesiredAccess);
78   typedef SC_HANDLE WINAPI (*TCreateService) (SC_HANDLE hSCManager,
79                                               LPCTSTR lpServiceName,
80                                               LPCTSTR lpDisplayName,
81                                               DWORD dwDesiredAccess,
82                                               DWORD dwServiceType,
83                                               DWORD dwStartType,
84                                               DWORD dwErrorControl,
85                                               LPCTSTR lpBinaryPathName,
86                                               LPCTSTR lpLoadOrderGroup,
87                                               LPDWORD lpdwTagId,
88                                               LPCTSTR lpDependencies,
89                                               LPCTSTR lpServiceStartName,
90                                               LPCTSTR lpPassword);
91   typedef BOOL WINAPI (*TCloseServiceHandle) (SC_HANDLE hSCObject);
92   typedef BOOL WINAPI (*TDeleteService) (SC_HANDLE hService);
93   typedef SERVICE_STATUS_HANDLE WINAPI (*TRegisterServiceCtrlHandler) (LPCTSTR
94                                                                        lpServiceName,
95                                                                        LPHANDLER_FUNCTION
96                                                                        lpHandlerProc);
97   typedef BOOL WINAPI (*TSetServiceStatus) (SERVICE_STATUS_HANDLE
98                                             hServiceStatus,
99                                             LPSERVICE_STATUS lpServiceStatus);
100   typedef BOOL WINAPI (*TStartServiceCtrlDispatcher) (const
101                                                       LPSERVICE_TABLE_ENTRY
102                                                       lpServiceTable);
103   typedef BOOL WINAPI (*TControlService) (SC_HANDLE hService, DWORD dwControl,
104                                           LPSERVICE_STATUS lpServiceStatus);
105   typedef SC_HANDLE WINAPI (*TOpenService) (SC_HANDLE hSCManager,
106                                             LPCTSTR lpServiceName,
107                                             DWORD dwDesiredAccess);
108   typedef DWORD WINAPI (*TGetAdaptersInfo) (PIP_ADAPTER_INFO pAdapterInfo,
109                                             PULONG pOutBufLen);
110   typedef NET_API_STATUS WINAPI (*TNetUserAdd) (LPCWSTR, DWORD, PBYTE, PDWORD);
111   typedef NET_API_STATUS WINAPI (*TNetUserSetInfo) (LPCWSTR servername,
112                                                     LPCWSTR username,
113                                                     DWORD level, LPBYTE buf,
114                                                     LPDWORD param_err);
115   typedef NTSTATUS NTAPI (*TLsaOpenPolicy) (PLSA_UNICODE_STRING,
116                                             PLSA_OBJECT_ATTRIBUTES, ACCESS_MASK,
117                                             PLSA_HANDLE);
118   typedef NTSTATUS NTAPI (*TLsaAddAccountRights) (LSA_HANDLE, PSID,
119                                                   PLSA_UNICODE_STRING, ULONG);
120   typedef NTSTATUS NTAPI (*TLsaRemoveAccountRights) (LSA_HANDLE, PSID, BOOLEAN,
121                                                      PLSA_UNICODE_STRING,
122                                                      ULONG);
123   typedef NTSTATUS NTAPI (*TLsaClose) (LSA_HANDLE);
124   typedef BOOL WINAPI (*TLookupAccountName) (LPCTSTR lpSystemName,
125                                              LPCTSTR lpAccountName, PSID Sid,
126                                              LPDWORD cbSid,
127                                              LPTSTR ReferencedDomainName,
128                                              LPDWORD cchReferencedDomainName,
129                                              PSID_NAME_USE peUse);
130
131   typedef BOOL WINAPI (*TGetFileSecurity) (LPCTSTR lpFileName,
132                                            SECURITY_INFORMATION
133                                            RequestedInformation,
134                                            PSECURITY_DESCRIPTOR
135                                            pSecurityDescriptor, DWORD nLength,
136                                            LPDWORD lpnLengthNeeded);
137   typedef BOOL WINAPI (*TInitializeSecurityDescriptor) (PSECURITY_DESCRIPTOR
138                                                         pSecurityDescriptor,
139                                                         DWORD dwRevision);
140   typedef BOOL WINAPI (*TGetSecurityDescriptorDacl) (PSECURITY_DESCRIPTOR
141                                                      pSecurityDescriptor,
142                                                      LPBOOL lpbDaclPresent,
143                                                      PACL * pDacl,
144                                                      LPBOOL lpbDaclDefaulted);
145   typedef BOOL WINAPI (*TGetAclInformation) (PACL pAcl, LPVOID pAclInformation,
146                                              DWORD nAclInformationLength,
147                                              ACL_INFORMATION_CLASS
148                                              dwAclInformationClass);
149   typedef BOOL WINAPI (*TInitializeAcl) (PACL pAcl, DWORD nAclLength,
150                                          DWORD dwAclRevision);
151   typedef BOOL WINAPI (*TGetAce) (PACL pAcl, DWORD dwAceIndex, LPVOID * pAce);
152   typedef BOOL WINAPI (*TEqualSid) (PSID pSid1, PSID pSid2);
153   typedef BOOL WINAPI (*TAddAce) (PACL pAcl, DWORD dwAceRevision,
154                                   DWORD dwStartingAceIndex, LPVOID pAceList,
155                                   DWORD nAceListLength);
156   typedef BOOL WINAPI (*TAddAccessAllowedAce) (PACL pAcl, DWORD dwAceRevision,
157                                                DWORD AccessMask, PSID pSid);
158   typedef BOOL WINAPI (*TSetNamedSecurityInfo) (LPTSTR pObjectName,
159                                                 SE_OBJECT_TYPE ObjectType,
160                                                 SECURITY_INFORMATION
161                                                 SecurityInfo, PSID psidOwner,
162                                                 PSID psidGroup, PACL pDacl,
163                                                 PACL pSacl);
164
165   extern TGetBestInterfaceEx GNGetBestInterfaceEx;
166   extern TNtQuerySystemInformation GNNtQuerySystemInformation;
167   extern TGetIfEntry GNGetIfEntry;
168   extern TGetIpAddrTable GNGetIpAddrTable;
169   extern TGetIfTable GNGetIfTable;
170   extern TCreateHardLink GNCreateHardLink;
171   extern TOpenSCManager GNOpenSCManager;
172   extern TCreateService GNCreateService;
173   extern TCloseServiceHandle GNCloseServiceHandle;
174   extern TDeleteService GNDeleteService;
175   extern TRegisterServiceCtrlHandler GNRegisterServiceCtrlHandler;
176   extern TSetServiceStatus GNSetServiceStatus;
177   extern TStartServiceCtrlDispatcher GNStartServiceCtrlDispatcher;
178   extern TControlService GNControlService;
179   extern TOpenService GNOpenService;
180   extern TGetAdaptersInfo GNGetAdaptersInfo;
181   extern TNetUserAdd GNNetUserAdd;
182   extern TNetUserSetInfo GNNetUserSetInfo;
183   extern TLsaOpenPolicy GNLsaOpenPolicy;
184   extern TLsaAddAccountRights GNLsaAddAccountRights;
185   extern TLsaRemoveAccountRights GNLsaRemoveAccountRights;
186   extern TLsaClose GNLsaClose;
187   extern TLookupAccountName GNLookupAccountName;
188   extern TGetFileSecurity GNGetFileSecurity;
189   extern TInitializeSecurityDescriptor GNInitializeSecurityDescriptor;
190   extern TGetSecurityDescriptorDacl GNGetSecurityDescriptorDacl;
191   extern TGetAclInformation GNGetAclInformation;
192   extern TInitializeAcl GNInitializeAcl;
193   extern TGetAce GNGetAce;
194   extern TEqualSid GNEqualSid;
195   extern TAddAce GNAddAce;
196   extern TAddAccessAllowedAce GNAddAccessAllowedAce;
197   extern TSetNamedSecurityInfo GNSetNamedSecurityInfo;
198
199
200   BOOL CreateShortcut (const char *pszSrc, const char *pszDest);
201   BOOL DereferenceShortcut (char *pszShortcut);
202   long QueryRegistry (HKEY hMainKey, const char *pszKey, const char *pszSubKey,
203                       char *pszBuffer, long *pdLength);
204   int ListNICs (void (*callback) (void *, const char *, int), void *cls);
205   BOOL AddPathAccessRights (char *lpszFileName, char *lpszAccountName,
206                             DWORD dwAccessMask);
207   char *winErrorStr (const char *prefix, int dwErr);
208   void EnumNICs (PMIB_IFTABLE * pIfTable, PMIB_IPADDRTABLE * pAddrTable);
209
210 #define ENUMNICS3_MASK_OK 0x01
211 #define ENUMNICS3_BCAST_OK 0x02
212
213   struct EnumNICs3_results
214   {
215     unsigned char flags;
216     int is_default;
217     char pretty_name[1001];
218     size_t addr_size;
219     SOCKADDR_STORAGE address;
220     SOCKADDR_STORAGE mask;
221     SOCKADDR_STORAGE broadcast;
222   };
223
224   int EnumNICs3 (struct EnumNICs3_results **, int *EnumNICs3_results_count);
225   void EnumNICs3_free (struct EnumNICs3_results *);
226   int GNInitWinEnv ();
227   void GNShutdownWinEnv ();
228
229   BOOL SafeTerminateProcess (HANDLE hProcess, UINT uExitCode, DWORD dwTimeout);
230 #ifdef __cplusplus
231 }
232 #endif
233
234 #endif