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