GNUnet  0.10.x
winproc.h
Go to the documentation of this file.
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  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
28 #ifndef _WINPROC_H
29 #define _WINPROC_H
30 
31 #include <io.h>
32 #include <stdio.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <sys/timeb.h>
36 #include <time.h>
37 #include <dirent.h>
38 #ifndef FD_SETSIZE
39 #define FD_SETSIZE 1024
40 #endif
41 #include <winsock2.h>
42 #include <ws2tcpip.h>
43 #include <windows.h>
44 #include <winerror.h>
45 #include <iphlpapi.h>
46 #include <shlobj.h>
47 #include <objbase.h>
48 #include <sys/param.h> /* #define BYTE_ORDER */
49 #include <ntsecapi.h>
50 #include <lm.h>
51 #include <aclapi.h>
52 
53 
54 #ifdef __cplusplus
55 extern "C"
56 {
57 #endif
58 
59 #ifndef MAX_NAME_LENGTH
60 #define MAX_NAME_LENGTH 25
61 #endif
62 
63 typedef DWORD WINAPI (*TNtQuerySystemInformation) (int, PVOID, ULONG, PULONG);
64 typedef DWORD WINAPI (*TGetIfEntry) (PMIB_IFROW pIfRow);
65 typedef DWORD WINAPI (*TGetIpAddrTable) (PMIB_IPADDRTABLE pIpAddrTable,
66  PULONG pdwSize, BOOL bOrder);
67 typedef DWORD WINAPI (*TGetIfTable) (PMIB_IFTABLE pIfTable, PULONG pdwSize,
68  BOOL bOrder);
69 typedef DWORD WINAPI (*TGetBestInterfaceEx) (struct sockaddr *, PDWORD);
70 /* TODO: Explicitly import -A variants (i.e. TCreateHardLinkA) or -W
71  * variants (TCreateHardLinkW), etc.
72  */
73 typedef DWORD WINAPI (*TCreateHardLink) (LPCTSTR lpFileName,
74  LPCTSTR lpExistingFileName,
75  LPSECURITY_ATTRIBUTES
76  lpSecurityAttributes);
77 typedef SC_HANDLE WINAPI (*TOpenSCManager) (LPCTSTR lpMachineName,
78  LPCTSTR lpDatabaseName,
79  DWORD dwDesiredAccess);
80 typedef SC_HANDLE WINAPI (*TCreateService) (SC_HANDLE hSCManager,
81  LPCTSTR lpServiceName,
82  LPCTSTR lpDisplayName,
83  DWORD dwDesiredAccess,
84  DWORD dwServiceType,
85  DWORD dwStartType,
86  DWORD dwErrorControl,
87  LPCTSTR lpBinaryPathName,
88  LPCTSTR lpLoadOrderGroup,
89  LPDWORD lpdwTagId,
90  LPCTSTR lpDependencies,
91  LPCTSTR lpServiceStartName,
92  LPCTSTR lpPassword);
93 typedef BOOL WINAPI (*TCloseServiceHandle) (SC_HANDLE hSCObject);
94 typedef BOOL WINAPI (*TDeleteService) (SC_HANDLE hService);
95 typedef SERVICE_STATUS_HANDLE WINAPI (*TRegisterServiceCtrlHandler) (LPCTSTR
96  lpServiceName,
97  LPHANDLER_FUNCTION
98  lpHandlerProc);
99 typedef BOOL WINAPI (*TSetServiceStatus) (SERVICE_STATUS_HANDLE
100  hServiceStatus,
101  LPSERVICE_STATUS lpServiceStatus);
102 typedef BOOL WINAPI (*TStartServiceCtrlDispatcher) (const
103  LPSERVICE_TABLE_ENTRY
104  lpServiceTable);
105 typedef BOOL WINAPI (*TControlService) (SC_HANDLE hService, DWORD dwControl,
106  LPSERVICE_STATUS lpServiceStatus);
107 typedef SC_HANDLE WINAPI (*TOpenService) (SC_HANDLE hSCManager,
108  LPCTSTR lpServiceName,
109  DWORD dwDesiredAccess);
110 typedef DWORD WINAPI (*TGetAdaptersInfo) (PIP_ADAPTER_INFO pAdapterInfo,
111  PULONG pOutBufLen);
112 typedef NET_API_STATUS WINAPI (*TNetUserAdd) (LPCWSTR, DWORD, PBYTE, PDWORD);
113 typedef NET_API_STATUS WINAPI (*TNetUserSetInfo) (LPCWSTR servername,
114  LPCWSTR username,
115  DWORD level, LPBYTE buf,
116  LPDWORD param_err);
117 typedef NTSTATUS NTAPI (*TLsaOpenPolicy) (PLSA_UNICODE_STRING,
118  PLSA_OBJECT_ATTRIBUTES, ACCESS_MASK,
119  PLSA_HANDLE);
120 typedef NTSTATUS NTAPI (*TLsaAddAccountRights) (LSA_HANDLE, PSID,
121  PLSA_UNICODE_STRING, ULONG);
122 typedef NTSTATUS NTAPI (*TLsaRemoveAccountRights) (LSA_HANDLE, PSID, BOOLEAN,
123  PLSA_UNICODE_STRING,
124  ULONG);
125 typedef NTSTATUS NTAPI (*TLsaClose) (LSA_HANDLE);
126 typedef BOOL WINAPI (*TLookupAccountName) (LPCTSTR lpSystemName,
127  LPCTSTR lpAccountName, PSID Sid,
128  LPDWORD cbSid,
129  LPTSTR ReferencedDomainName,
130  LPDWORD cchReferencedDomainName,
131  PSID_NAME_USE peUse);
132 
133 typedef BOOL WINAPI (*TGetFileSecurity) (LPCTSTR lpFileName,
134  SECURITY_INFORMATION
135  RequestedInformation,
136  PSECURITY_DESCRIPTOR
137  pSecurityDescriptor, DWORD nLength,
138  LPDWORD lpnLengthNeeded);
139 typedef BOOL WINAPI (*TInitializeSecurityDescriptor) (PSECURITY_DESCRIPTOR
140  pSecurityDescriptor,
141  DWORD dwRevision);
142 typedef BOOL WINAPI (*TGetSecurityDescriptorDacl) (PSECURITY_DESCRIPTOR
143  pSecurityDescriptor,
144  LPBOOL lpbDaclPresent,
145  PACL * pDacl,
146  LPBOOL lpbDaclDefaulted);
147 typedef BOOL WINAPI (*TGetAclInformation) (PACL pAcl, LPVOID pAclInformation,
148  DWORD nAclInformationLength,
149  ACL_INFORMATION_CLASS
150  dwAclInformationClass);
151 typedef BOOL WINAPI (*TInitializeAcl) (PACL pAcl, DWORD nAclLength,
152  DWORD dwAclRevision);
153 typedef BOOL WINAPI (*TGetAce) (PACL pAcl, DWORD dwAceIndex, LPVOID * pAce);
154 typedef BOOL WINAPI (*TEqualSid) (PSID pSid1, PSID pSid2);
155 typedef BOOL WINAPI (*TAddAce) (PACL pAcl, DWORD dwAceRevision,
156  DWORD dwStartingAceIndex, LPVOID pAceList,
157  DWORD nAceListLength);
158 typedef BOOL WINAPI (*TAddAccessAllowedAce) (PACL pAcl, DWORD dwAceRevision,
159  DWORD AccessMask, PSID pSid);
160 typedef BOOL WINAPI (*TSetNamedSecurityInfo) (LPTSTR pObjectName,
161  SE_OBJECT_TYPE ObjectType,
162  SECURITY_INFORMATION
163  SecurityInfo, PSID psidOwner,
164  PSID psidGroup, PACL pDacl,
165  PACL pSacl);
166 
188 extern TLsaClose GNLsaClose;
195 extern TGetAce GNGetAce;
196 extern TEqualSid GNEqualSid;
197 extern TAddAce GNAddAce;
200 
201 
202 BOOL CreateShortcut(const char *pszSrc, const char *pszDest);
203 BOOL DereferenceShortcut(char *pszShortcut);
204 long QueryRegistry(HKEY hMainKey, const char *pszKey, const char *pszSubKey,
205  char *pszBuffer, long *pdLength);
206 int ListNICs(void (*callback)(void *, const char *, int), void *cls);
207 BOOL AddPathAccessRights(char *lpszFileName, char *lpszAccountName,
208  DWORD dwAccessMask);
209 char *winErrorStr(const char *prefix, int dwErr);
210 void EnumNICs(PMIB_IFTABLE * pIfTable, PMIB_IPADDRTABLE * pAddrTable);
211 
212 #define ENUMNICS3_MASK_OK 0x01
213 #define ENUMNICS3_BCAST_OK 0x02
214 
216  unsigned char flags;
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 BOOL SafeTerminateProcess(HANDLE hProcess, UINT uExitCode, DWORD dwTimeout);
231 #ifdef __cplusplus
232 }
233 #endif
234 
235 #endif
NTSTATUS NTAPI(* TLsaClose)(LSA_HANDLE)
Definition: winproc.h:125
TEqualSid GNEqualSid
BOOL WINAPI(* TGetAclInformation)(PACL pAcl, LPVOID pAclInformation, DWORD nAclInformationLength, ACL_INFORMATION_CLASS dwAclInformationClass)
Definition: winproc.h:147
TLsaAddAccountRights GNLsaAddAccountRights
SOCKADDR_STORAGE address
Definition: winproc.h:220
NET_API_STATUS WINAPI(* TNetUserAdd)(LPCWSTR, DWORD, PBYTE, PDWORD)
Definition: winproc.h:112
BOOL WINAPI(* TInitializeSecurityDescriptor)(PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD dwRevision)
Definition: winproc.h:139
BOOL WINAPI(* TSetServiceStatus)(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: winproc.h:99
TLookupAccountName GNLookupAccountName
BOOL WINAPI(* TCloseServiceHandle)(SC_HANDLE hSCObject)
Definition: winproc.h:93
TDeleteService GNDeleteService
NTSTATUS NTAPI(* TLsaAddAccountRights)(LSA_HANDLE, PSID, PLSA_UNICODE_STRING, ULONG)
Definition: winproc.h:120
BOOL SafeTerminateProcess(HANDLE hProcess, UINT uExitCode, DWORD dwTimeout)
Terminate a process by creating a remote thread within it, which proceeds to call ExitProcess() insid...
Definition: win.c:1309
DWORD WINAPI(* TNtQuerySystemInformation)(int, PVOID, ULONG, PULONG)
Definition: winproc.h:63
TRegisterServiceCtrlHandler GNRegisterServiceCtrlHandler
SERVICE_STATUS_HANDLE WINAPI(* TRegisterServiceCtrlHandler)(LPCTSTR lpServiceName, LPHANDLER_FUNCTION lpHandlerProc)
Definition: winproc.h:95
TGetAdaptersInfo GNGetAdaptersInfo
TStartServiceCtrlDispatcher GNStartServiceCtrlDispatcher
DWORD WINAPI(* TCreateHardLink)(LPCTSTR lpFileName, LPCTSTR lpExistingFileName, LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: winproc.h:73
TCreateService GNCreateService
SC_HANDLE WINAPI(* TCreateService)(SC_HANDLE hSCManager, LPCTSTR lpServiceName, LPCTSTR lpDisplayName, DWORD dwDesiredAccess, DWORD dwServiceType, DWORD dwStartType, DWORD dwErrorControl, LPCTSTR lpBinaryPathName, LPCTSTR lpLoadOrderGroup, LPDWORD lpdwTagId, LPCTSTR lpDependencies, LPCTSTR lpServiceStartName, LPCTSTR lpPassword)
Definition: winproc.h:80
long QueryRegistry(HKEY hMainKey, const char *pszKey, const char *pszSubKey, char *pszBuffer, long *pdLength)
TGetAce GNGetAce
TSetServiceStatus GNSetServiceStatus
DWORD WINAPI(* TGetBestInterfaceEx)(struct sockaddr *, PDWORD)
Definition: winproc.h:69
BOOL CreateShortcut(const char *pszSrc, const char *pszDest)
SC_HANDLE WINAPI(* TOpenService)(SC_HANDLE hSCManager, LPCTSTR lpServiceName, DWORD dwDesiredAccess)
Definition: winproc.h:107
void EnumNICs(PMIB_IFTABLE *pIfTable, PMIB_IPADDRTABLE *pAddrTable)
SC_HANDLE WINAPI(* TOpenSCManager)(LPCTSTR lpMachineName, LPCTSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: winproc.h:77
BOOL WINAPI(* TInitializeAcl)(PACL pAcl, DWORD nAclLength, DWORD dwAclRevision)
Definition: winproc.h:151
char * winErrorStr(const char *prefix, int dwErr)
Definition: win.c:1274
TNetUserSetInfo GNNetUserSetInfo
NTSTATUS NTAPI(* TLsaRemoveAccountRights)(LSA_HANDLE, PSID, BOOLEAN, PLSA_UNICODE_STRING, ULONG)
Definition: winproc.h:122
DWORD WINAPI(* TGetIpAddrTable)(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL bOrder)
Definition: winproc.h:65
TGetAclInformation GNGetAclInformation
TCloseServiceHandle GNCloseServiceHandle
TLsaClose GNLsaClose
static char buf[2048]
TGetIfEntry GNGetIfEntry
TInitializeSecurityDescriptor GNInitializeSecurityDescriptor
char pretty_name[1001]
Definition: winproc.h:218
BOOL WINAPI(* TGetFileSecurity)(LPCTSTR lpFileName, SECURITY_INFORMATION RequestedInformation, PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD nLength, LPDWORD lpnLengthNeeded)
Definition: winproc.h:133
NET_API_STATUS WINAPI(* TNetUserSetInfo)(LPCWSTR servername, LPCWSTR username, DWORD level, LPBYTE buf, LPDWORD param_err)
Definition: winproc.h:113
TLsaOpenPolicy GNLsaOpenPolicy
void GNShutdownWinEnv()
int GNInitWinEnv()
int EnumNICs3(struct EnumNICs3_results **, int *EnumNICs3_results_count)
Definition: win.c:364
size_t addr_size
Definition: winproc.h:219
TOpenService GNOpenService
SOCKADDR_STORAGE broadcast
Definition: winproc.h:222
TNetUserAdd GNNetUserAdd
TSetNamedSecurityInfo GNSetNamedSecurityInfo
DWORD WINAPI(* TGetIfEntry)(PMIB_IFROW pIfRow)
Definition: winproc.h:64
BOOL WINAPI(* TGetAce)(PACL pAcl, DWORD dwAceIndex, LPVOID *pAce)
Definition: winproc.h:153
unsigned char flags
Definition: winproc.h:216
BOOL WINAPI(* TLookupAccountName)(LPCTSTR lpSystemName, LPCTSTR lpAccountName, PSID Sid, LPDWORD cbSid, LPTSTR ReferencedDomainName, LPDWORD cchReferencedDomainName, PSID_NAME_USE peUse)
Definition: winproc.h:126
BOOL WINAPI(* TGetSecurityDescriptorDacl)(PSECURITY_DESCRIPTOR pSecurityDescriptor, LPBOOL lpbDaclPresent, PACL *pDacl, LPBOOL lpbDaclDefaulted)
Definition: winproc.h:142
BOOL WINAPI(* TEqualSid)(PSID pSid1, PSID pSid2)
Definition: winproc.h:154
TGetBestInterfaceEx GNGetBestInterfaceEx
TGetIfTable GNGetIfTable
TAddAccessAllowedAce GNAddAccessAllowedAce
void EnumNICs3_free(struct EnumNICs3_results *)
Definition: win.c:626
BOOL AddPathAccessRights(char *lpszFileName, char *lpszAccountName, DWORD dwAccessMask)
Grant permission to a file.
Definition: win.c:972
BOOL WINAPI(* TAddAce)(PACL pAcl, DWORD dwAceRevision, DWORD dwStartingAceIndex, LPVOID pAceList, DWORD nAceListLength)
Definition: winproc.h:155
TNtQuerySystemInformation GNNtQuerySystemInformation
BOOL WINAPI(* TStartServiceCtrlDispatcher)(const LPSERVICE_TABLE_ENTRY lpServiceTable)
Definition: winproc.h:102
TOpenSCManager GNOpenSCManager
BOOL WINAPI(* TAddAccessAllowedAce)(PACL pAcl, DWORD dwAceRevision, DWORD AccessMask, PSID pSid)
Definition: winproc.h:158
DWORD WINAPI(* TGetAdaptersInfo)(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
Definition: winproc.h:110
TAddAce GNAddAce
int ListNICs(void(*callback)(void *, const char *, int), void *cls)
Lists all network interfaces in a combo box Used by the basic GTK configurator.
Definition: win.c:640
BOOL WINAPI(* TDeleteService)(SC_HANDLE hService)
Definition: winproc.h:94
TGetSecurityDescriptorDacl GNGetSecurityDescriptorDacl
TLsaRemoveAccountRights GNLsaRemoveAccountRights
TGetFileSecurity GNGetFileSecurity
NTSTATUS NTAPI(* TLsaOpenPolicy)(PLSA_UNICODE_STRING, PLSA_OBJECT_ATTRIBUTES, ACCESS_MASK, PLSA_HANDLE)
Definition: winproc.h:117
BOOL WINAPI(* TSetNamedSecurityInfo)(LPTSTR pObjectName, SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo, PSID psidOwner, PSID psidGroup, PACL pDacl, PACL pSacl)
Definition: winproc.h:160
BOOL DereferenceShortcut(char *pszShortcut)
TInitializeAcl GNInitializeAcl
TControlService GNControlService
TGetIpAddrTable GNGetIpAddrTable
TCreateHardLink GNCreateHardLink
SOCKADDR_STORAGE mask
Definition: winproc.h:221
BOOL WINAPI(* TControlService)(SC_HANDLE hService, DWORD dwControl, LPSERVICE_STATUS lpServiceStatus)
Definition: winproc.h:105
DWORD WINAPI(* TGetIfTable)(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder)
Definition: winproc.h:67