-fixing indentation
[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 #include <winsock2.h>
38 #include <ws2tcpip.h>
39 #include <windows.h>
40 #include <winerror.h>
41 #include <iphlpapi.h>
42 #include <shlobj.h>
43 #include <objbase.h>
44 #include <sys/param.h>          /* #define BYTE_ORDER */
45 #include <ntsecapi.h>
46 #include <lm.h>
47 #include <aclapi.h>
48
49
50 #ifdef __cplusplus
51 extern "C"
52 {
53 #endif
54
55 #ifndef MAX_NAME_LENGTH
56 #define MAX_NAME_LENGTH 25
57 #endif
58
59   typedef DWORD WINAPI (*TNtQuerySystemInformation) (int, PVOID, ULONG, PULONG);
60   typedef DWORD WINAPI (*TGetIfEntry) (PMIB_IFROW pIfRow);
61   typedef DWORD WINAPI (*TGetIpAddrTable) (PMIB_IPADDRTABLE pIpAddrTable,
62                                            PULONG pdwSize, BOOL bOrder);
63   typedef DWORD WINAPI (*TGetIfTable) (PMIB_IFTABLE pIfTable, PULONG pdwSize,
64                                        BOOL bOrder);
65   typedef DWORD WINAPI (*TGetBestInterfaceEx) (struct sockaddr *, PDWORD);
66   /* TODO: Explicitly import -A variants (i.e. TCreateHardLinkA) or -W
67    * variants (TCreateHardLinkW), etc.
68    */
69   typedef DWORD WINAPI (*TCreateHardLink) (LPCTSTR lpFileName,
70                                            LPCTSTR lpExistingFileName,
71                                            LPSECURITY_ATTRIBUTES
72                                            lpSecurityAttributes);
73   typedef SC_HANDLE WINAPI (*TOpenSCManager) (LPCTSTR lpMachineName,
74                                               LPCTSTR lpDatabaseName,
75                                               DWORD dwDesiredAccess);
76   typedef SC_HANDLE WINAPI (*TCreateService) (SC_HANDLE hSCManager,
77                                               LPCTSTR lpServiceName,
78                                               LPCTSTR lpDisplayName,
79                                               DWORD dwDesiredAccess,
80                                               DWORD dwServiceType,
81                                               DWORD dwStartType,
82                                               DWORD dwErrorControl,
83                                               LPCTSTR lpBinaryPathName,
84                                               LPCTSTR lpLoadOrderGroup,
85                                               LPDWORD lpdwTagId,
86                                               LPCTSTR lpDependencies,
87                                               LPCTSTR lpServiceStartName,
88                                               LPCTSTR lpPassword);
89   typedef BOOL WINAPI (*TCloseServiceHandle) (SC_HANDLE hSCObject);
90   typedef BOOL WINAPI (*TDeleteService) (SC_HANDLE hService);
91   typedef SERVICE_STATUS_HANDLE WINAPI (*TRegisterServiceCtrlHandler) (LPCTSTR
92                                                                        lpServiceName,
93                                                                        LPHANDLER_FUNCTION
94                                                                        lpHandlerProc);
95   typedef BOOL WINAPI (*TSetServiceStatus) (SERVICE_STATUS_HANDLE
96                                             hServiceStatus,
97                                             LPSERVICE_STATUS lpServiceStatus);
98   typedef BOOL WINAPI (*TStartServiceCtrlDispatcher) (const
99                                                       LPSERVICE_TABLE_ENTRY
100                                                       lpServiceTable);
101   typedef BOOL WINAPI (*TControlService) (SC_HANDLE hService, DWORD dwControl,
102                                           LPSERVICE_STATUS lpServiceStatus);
103   typedef SC_HANDLE WINAPI (*TOpenService) (SC_HANDLE hSCManager,
104                                             LPCTSTR lpServiceName,
105                                             DWORD dwDesiredAccess);
106   typedef DWORD WINAPI (*TGetAdaptersInfo) (PIP_ADAPTER_INFO pAdapterInfo,
107                                             PULONG pOutBufLen);
108   typedef NET_API_STATUS WINAPI (*TNetUserAdd) (LPCWSTR, DWORD, PBYTE, PDWORD);
109   typedef NET_API_STATUS WINAPI (*TNetUserSetInfo) (LPCWSTR servername,
110                                                     LPCWSTR username,
111                                                     DWORD level, LPBYTE buf,
112                                                     LPDWORD parm_err);
113   typedef NTSTATUS NTAPI (*TLsaOpenPolicy) (PLSA_UNICODE_STRING,
114                                             PLSA_OBJECT_ATTRIBUTES, ACCESS_MASK,
115                                             PLSA_HANDLE);
116   typedef NTSTATUS NTAPI (*TLsaAddAccountRights) (LSA_HANDLE, PSID,
117                                                   PLSA_UNICODE_STRING, ULONG);
118   typedef NTSTATUS NTAPI (*TLsaRemoveAccountRights) (LSA_HANDLE, PSID, BOOLEAN,
119                                                      PLSA_UNICODE_STRING,
120                                                      ULONG);
121   typedef NTSTATUS NTAPI (*TLsaClose) (LSA_HANDLE);
122   typedef BOOL WINAPI (*TLookupAccountName) (LPCTSTR lpSystemName,
123                                              LPCTSTR lpAccountName, PSID Sid,
124                                              LPDWORD cbSid,
125                                              LPTSTR ReferencedDomainName,
126                                              LPDWORD cchReferencedDomainName,
127                                              PSID_NAME_USE peUse);
128
129   typedef BOOL WINAPI (*TGetFileSecurity) (LPCTSTR lpFileName,
130                                            SECURITY_INFORMATION
131                                            RequestedInformation,
132                                            PSECURITY_DESCRIPTOR
133                                            pSecurityDescriptor, DWORD nLength,
134                                            LPDWORD lpnLengthNeeded);
135   typedef BOOL WINAPI (*TInitializeSecurityDescriptor) (PSECURITY_DESCRIPTOR
136                                                         pSecurityDescriptor,
137                                                         DWORD dwRevision);
138   typedef BOOL WINAPI (*TGetSecurityDescriptorDacl) (PSECURITY_DESCRIPTOR
139                                                      pSecurityDescriptor,
140                                                      LPBOOL lpbDaclPresent,
141                                                      PACL * pDacl,
142                                                      LPBOOL lpbDaclDefaulted);
143   typedef BOOL WINAPI (*TGetAclInformation) (PACL pAcl, LPVOID pAclInformation,
144                                              DWORD nAclInformationLength,
145                                              ACL_INFORMATION_CLASS
146                                              dwAclInformationClass);
147   typedef BOOL WINAPI (*TInitializeAcl) (PACL pAcl, DWORD nAclLength,
148                                          DWORD dwAclRevision);
149   typedef BOOL WINAPI (*TGetAce) (PACL pAcl, DWORD dwAceIndex, LPVOID * pAce);
150   typedef BOOL WINAPI (*TEqualSid) (PSID pSid1, PSID pSid2);
151   typedef BOOL WINAPI (*TAddAce) (PACL pAcl, DWORD dwAceRevision,
152                                   DWORD dwStartingAceIndex, LPVOID pAceList,
153                                   DWORD nAceListLength);
154   typedef BOOL WINAPI (*TAddAccessAllowedAce) (PACL pAcl, DWORD dwAceRevision,
155                                                DWORD AccessMask, PSID pSid);
156   typedef BOOL WINAPI (*TSetNamedSecurityInfo) (LPTSTR pObjectName,
157                                                 SE_OBJECT_TYPE ObjectType,
158                                                 SECURITY_INFORMATION
159                                                 SecurityInfo, PSID psidOwner,
160                                                 PSID psidGroup, PACL pDacl,
161                                                 PACL pSacl);
162
163   extern TGetBestInterfaceEx GNGetBestInterfaceEx;
164   extern TNtQuerySystemInformation GNNtQuerySystemInformation;
165   extern TGetIfEntry GNGetIfEntry;
166   extern TGetIpAddrTable GNGetIpAddrTable;
167   extern TGetIfTable GNGetIfTable;
168   extern TCreateHardLink GNCreateHardLink;
169   extern TOpenSCManager GNOpenSCManager;
170   extern TCreateService GNCreateService;
171   extern TCloseServiceHandle GNCloseServiceHandle;
172   extern TDeleteService GNDeleteService;
173   extern TRegisterServiceCtrlHandler GNRegisterServiceCtrlHandler;
174   extern TSetServiceStatus GNSetServiceStatus;
175   extern TStartServiceCtrlDispatcher GNStartServiceCtrlDispatcher;
176   extern TControlService GNControlService;
177   extern TOpenService GNOpenService;
178   extern TGetAdaptersInfo GNGetAdaptersInfo;
179   extern TNetUserAdd GNNetUserAdd;
180   extern TNetUserSetInfo GNNetUserSetInfo;
181   extern TLsaOpenPolicy GNLsaOpenPolicy;
182   extern TLsaAddAccountRights GNLsaAddAccountRights;
183   extern TLsaRemoveAccountRights GNLsaRemoveAccountRights;
184   extern TLsaClose GNLsaClose;
185   extern TLookupAccountName GNLookupAccountName;
186   extern TGetFileSecurity GNGetFileSecurity;
187   extern TInitializeSecurityDescriptor GNInitializeSecurityDescriptor;
188   extern TGetSecurityDescriptorDacl GNGetSecurityDescriptorDacl;
189   extern TGetAclInformation GNGetAclInformation;
190   extern TInitializeAcl GNInitializeAcl;
191   extern TGetAce GNGetAce;
192   extern TEqualSid GNEqualSid;
193   extern TAddAce GNAddAce;
194   extern TAddAccessAllowedAce GNAddAccessAllowedAce;
195   extern TSetNamedSecurityInfo GNSetNamedSecurityInfo;
196
197
198   BOOL CreateShortcut (const char *pszSrc, const char *pszDest);
199   BOOL DereferenceShortcut (char *pszShortcut);
200   long QueryRegistry (HKEY hMainKey, const char *pszKey, const char *pszSubKey,
201                       char *pszBuffer, long *pdLength);
202   int ListNICs (void (*callback) (void *, const char *, int), void *cls);
203   BOOL AddPathAccessRights (char *lpszFileName, char *lpszAccountName,
204                             DWORD dwAccessMask);
205   char *winErrorStr (const char *prefix, int dwErr);
206   void EnumNICs (PMIB_IFTABLE * pIfTable, PMIB_IPADDRTABLE * pAddrTable);
207
208 #define ENUMNICS3_MASK_OK 0x01
209 #define ENUMNICS3_BCAST_OK 0x02
210
211   struct EnumNICs3_results
212   {
213     unsigned char flags;
214     int is_default;
215     char pretty_name[1001];
216     size_t addr_size;
217     struct sockaddr address;
218     struct sockaddr mask;
219     struct sockaddr broadcast;
220   };
221
222   int EnumNICs3 (struct EnumNICs3_results **, int *EnumNICs3_results_count);
223   void EnumNICs3_free (struct EnumNICs3_results *);
224   int GNInitWinEnv ();
225   void GNShutdownWinEnv ();
226
227 #ifdef __cplusplus
228 }
229 #endif
230
231 #endif