2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2004, 2005, 2006 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file util/winproc.c
23 * @brief Functions for MS Windows
28 #include "gnunet_common.h"
30 #define DEBUG_WINPROC 0
34 static HINSTANCE hNTDLL, hIphlpapi, hAdvapi, hNetapi;
36 TNtQuerySystemInformation GNNtQuerySystemInformation;
37 TGetIfEntry GNGetIfEntry;
38 TGetIpAddrTable GNGetIpAddrTable;
39 TGetIfTable GNGetIfTable;
40 TOpenSCManager GNOpenSCManager;
41 TCreateService GNCreateService;
42 TCloseServiceHandle GNCloseServiceHandle;
43 TDeleteService GNDeleteService;
44 TRegisterServiceCtrlHandler GNRegisterServiceCtrlHandler;
45 TSetServiceStatus GNSetServiceStatus;
46 TStartServiceCtrlDispatcher GNStartServiceCtrlDispatcher;
47 TControlService GNControlService;
48 TOpenService GNOpenService;
49 TGetBestInterface GNGetBestInterface;
50 TGetAdaptersInfo GGetAdaptersInfo;
51 TNetUserAdd GNNetUserAdd;
52 TNetUserSetInfo GNNetUserSetInfo;
53 TLsaOpenPolicy GNLsaOpenPolicy;
54 TLsaAddAccountRights GNLsaAddAccountRights;
55 TLsaRemoveAccountRights GNLsaRemoveAccountRights;
57 TLookupAccountName GNLookupAccountName;
58 TGetFileSecurity GNGetFileSecurity;
59 TInitializeSecurityDescriptor GNInitializeSecurityDescriptor;
60 TGetSecurityDescriptorDacl GNGetSecurityDescriptorDacl;
61 TGetAclInformation GNGetAclInformation;
62 TInitializeAcl GNInitializeAcl;
66 TAddAccessAllowedAce GNAddAccessAllowedAce;
67 TSetNamedSecurityInfo GNSetNamedSecurityInfo;
70 * Log (panic) messages from PlibC
73 plibc_panic (int err, char *msg)
76 INT_MAX) ? GNUNET_ERROR_TYPE_DEBUG : GNUNET_ERROR_TYPE_ERROR),
81 * @brief Initialize PlibC and set up Windows environment
82 * @param logging context, NULL means stderr
83 * @return Error code from winerror.h, ERROR_SUCCESS on success
91 plibc_set_panic_proc (plibc_panic);
92 ret = plibc_init ("GNU", PACKAGE);
94 /* don't load other DLLs twice */
98 hNTDLL = LoadLibrary ("ntdll.dll");
100 /* Function to get CPU usage under Win NT */
103 GNNtQuerySystemInformation =
104 (TNtQuerySystemInformation) GetProcAddress (hNTDLL,
105 "NtQuerySystemInformation");
109 GNNtQuerySystemInformation = NULL;
112 /* Functions to get information about a network adapter */
113 hIphlpapi = LoadLibrary ("iphlpapi.dll");
116 GNGetIfEntry = (TGetIfEntry) GetProcAddress (hIphlpapi, "GetIfEntry");
118 (TGetIpAddrTable) GetProcAddress (hIphlpapi, "GetIpAddrTable");
119 GNGetIfTable = (TGetIfTable) GetProcAddress (hIphlpapi, "GetIfTable");
121 (TGetBestInterface) GetProcAddress (hIphlpapi, "GetBestInterface");
123 (TGetAdaptersInfo) GetProcAddress (hIphlpapi, "GetAdaptersInfo");
128 GNGetIpAddrTable = NULL;
130 GNGetBestInterface = NULL;
131 GGetAdaptersInfo = NULL;
134 /* Service & Account functions */
135 hAdvapi = LoadLibrary ("advapi32.dll");
139 (TOpenSCManager) GetProcAddress (hAdvapi, "OpenSCManagerA");
141 (TCreateService) GetProcAddress (hAdvapi, "CreateServiceA");
142 GNCloseServiceHandle =
143 (TCloseServiceHandle) GetProcAddress (hAdvapi, "CloseServiceHandle");
145 (TDeleteService) GetProcAddress (hAdvapi, "DeleteService");
146 GNRegisterServiceCtrlHandler =
147 (TRegisterServiceCtrlHandler) GetProcAddress (hAdvapi,
148 "RegisterServiceCtrlHandlerA");
150 (TSetServiceStatus) GetProcAddress (hAdvapi, "SetServiceStatus");
151 GNStartServiceCtrlDispatcher =
152 (TStartServiceCtrlDispatcher) GetProcAddress (hAdvapi,
153 "StartServiceCtrlDispatcherA");
155 (TControlService) GetProcAddress (hAdvapi, "ControlService");
156 GNOpenService = (TOpenService) GetProcAddress (hAdvapi, "OpenServiceA");
159 (TLsaOpenPolicy) GetProcAddress (hAdvapi, "LsaOpenPolicy");
160 GNLsaAddAccountRights =
161 (TLsaAddAccountRights) GetProcAddress (hAdvapi, "LsaAddAccountRights");
162 GNLsaRemoveAccountRights =
163 (TLsaRemoveAccountRights) GetProcAddress (hAdvapi,
164 "LsaRemoveAccountRights");
165 GNLsaClose = (TLsaClose) GetProcAddress (hAdvapi, "LsaClose");
166 GNLookupAccountName =
167 (TLookupAccountName) GetProcAddress (hAdvapi, "LookupAccountNameA");
170 (TGetFileSecurity) GetProcAddress (hAdvapi, "GetFileSecurityA");
171 GNInitializeSecurityDescriptor =
172 (TInitializeSecurityDescriptor) GetProcAddress (hAdvapi,
173 "InitializeSecurityDescriptor");
174 GNGetSecurityDescriptorDacl =
175 (TGetSecurityDescriptorDacl) GetProcAddress (hAdvapi,
176 "GetSecurityDescriptorDacl");
177 GNGetAclInformation =
178 (TGetAclInformation) GetProcAddress (hAdvapi, "GetAclInformation");
180 (TInitializeAcl) GetProcAddress (hAdvapi, "InitializeAcl");
181 GNGetAce = (TGetAce) GetProcAddress (hAdvapi, "GetAce");
182 GNEqualSid = (TEqualSid) GetProcAddress (hAdvapi, "EqualSid");
183 GNAddAce = (TAddAce) GetProcAddress (hAdvapi, "AddAce");
184 GNAddAccessAllowedAce =
185 (TAddAccessAllowedAce) GetProcAddress (hAdvapi, "AddAccessAllowedAce");
186 GNSetNamedSecurityInfo =
187 (TSetNamedSecurityInfo) GetProcAddress (hAdvapi,
188 "SetNamedSecurityInfoA");
192 GNOpenSCManager = NULL;
193 GNCreateService = NULL;
194 GNCloseServiceHandle = NULL;
195 GNDeleteService = NULL;
196 GNRegisterServiceCtrlHandler = NULL;
197 GNSetServiceStatus = NULL;
198 GNStartServiceCtrlDispatcher = NULL;
199 GNControlService = NULL;
200 GNOpenService = NULL;
202 GNLsaOpenPolicy = NULL;
203 GNLsaAddAccountRights = NULL;
204 GNLsaRemoveAccountRights = NULL;
206 GNLookupAccountName = NULL;
208 GNGetFileSecurity = NULL;
209 GNInitializeSecurityDescriptor = NULL;
210 GNGetSecurityDescriptorDacl = NULL;
211 GNGetAclInformation = NULL;
212 GNInitializeAcl = NULL;
216 GNAddAccessAllowedAce = NULL;
217 GNSetNamedSecurityInfo = NULL;
220 /* Account function */
221 hNetapi = LoadLibrary ("netapi32.dll");
224 GNNetUserAdd = (TNetUserAdd) GetProcAddress (hNetapi, "NetUserAdd");
226 (TNetUserSetInfo) GetProcAddress (hNetapi, "NetUserSetInfo");
231 GNNetUserSetInfo = NULL;
238 * Clean up Windows environment
245 FreeLibrary (hNTDLL);
246 FreeLibrary (hIphlpapi);
247 FreeLibrary (hAdvapi);
248 FreeLibrary (hNetapi);
257 atoll (const char *nptr)