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;
69 #define LOG(kind,...) GNUNET_log_from (kind, "winproc", __VA_ARGS__)
71 * Log (panic) messages from PlibC
74 plibc_panic (int err, char *msg)
77 INT_MAX) ? GNUNET_ERROR_TYPE_DEBUG : GNUNET_ERROR_TYPE_ERROR),
82 * @brief Initialize PlibC and set up Windows environment
83 * @param logging context, NULL means stderr
84 * @return Error code from winerror.h, ERROR_SUCCESS on success
92 plibc_set_panic_proc (plibc_panic);
93 ret = plibc_init ("GNU", PACKAGE);
95 /* don't load other DLLs twice */
99 hNTDLL = LoadLibrary ("ntdll.dll");
101 /* Function to get CPU usage under Win NT */
104 GNNtQuerySystemInformation =
105 (TNtQuerySystemInformation) GetProcAddress (hNTDLL,
106 "NtQuerySystemInformation");
110 GNNtQuerySystemInformation = NULL;
113 /* Functions to get information about a network adapter */
114 hIphlpapi = LoadLibrary ("iphlpapi.dll");
117 GNGetIfEntry = (TGetIfEntry) GetProcAddress (hIphlpapi, "GetIfEntry");
119 (TGetIpAddrTable) GetProcAddress (hIphlpapi, "GetIpAddrTable");
120 GNGetIfTable = (TGetIfTable) GetProcAddress (hIphlpapi, "GetIfTable");
122 (TGetBestInterface) GetProcAddress (hIphlpapi, "GetBestInterface");
124 (TGetAdaptersInfo) GetProcAddress (hIphlpapi, "GetAdaptersInfo");
129 GNGetIpAddrTable = NULL;
131 GNGetBestInterface = NULL;
132 GGetAdaptersInfo = NULL;
135 /* Service & Account functions */
136 hAdvapi = LoadLibrary ("advapi32.dll");
140 (TOpenSCManager) GetProcAddress (hAdvapi, "OpenSCManagerA");
142 (TCreateService) GetProcAddress (hAdvapi, "CreateServiceA");
143 GNCloseServiceHandle =
144 (TCloseServiceHandle) GetProcAddress (hAdvapi, "CloseServiceHandle");
146 (TDeleteService) GetProcAddress (hAdvapi, "DeleteService");
147 GNRegisterServiceCtrlHandler =
148 (TRegisterServiceCtrlHandler) GetProcAddress (hAdvapi,
149 "RegisterServiceCtrlHandlerA");
151 (TSetServiceStatus) GetProcAddress (hAdvapi, "SetServiceStatus");
152 GNStartServiceCtrlDispatcher =
153 (TStartServiceCtrlDispatcher) GetProcAddress (hAdvapi,
154 "StartServiceCtrlDispatcherA");
156 (TControlService) GetProcAddress (hAdvapi, "ControlService");
157 GNOpenService = (TOpenService) GetProcAddress (hAdvapi, "OpenServiceA");
160 (TLsaOpenPolicy) GetProcAddress (hAdvapi, "LsaOpenPolicy");
161 GNLsaAddAccountRights =
162 (TLsaAddAccountRights) GetProcAddress (hAdvapi,
163 "LsaAddAccountRights");
164 GNLsaRemoveAccountRights =
165 (TLsaRemoveAccountRights) GetProcAddress (hAdvapi,
166 "LsaRemoveAccountRights");
167 GNLsaClose = (TLsaClose) GetProcAddress (hAdvapi, "LsaClose");
168 GNLookupAccountName =
169 (TLookupAccountName) GetProcAddress (hAdvapi, "LookupAccountNameA");
172 (TGetFileSecurity) GetProcAddress (hAdvapi, "GetFileSecurityA");
173 GNInitializeSecurityDescriptor =
174 (TInitializeSecurityDescriptor) GetProcAddress (hAdvapi,
175 "InitializeSecurityDescriptor");
176 GNGetSecurityDescriptorDacl =
177 (TGetSecurityDescriptorDacl) GetProcAddress (hAdvapi,
178 "GetSecurityDescriptorDacl");
179 GNGetAclInformation =
180 (TGetAclInformation) GetProcAddress (hAdvapi, "GetAclInformation");
182 (TInitializeAcl) GetProcAddress (hAdvapi, "InitializeAcl");
183 GNGetAce = (TGetAce) GetProcAddress (hAdvapi, "GetAce");
184 GNEqualSid = (TEqualSid) GetProcAddress (hAdvapi, "EqualSid");
185 GNAddAce = (TAddAce) GetProcAddress (hAdvapi, "AddAce");
186 GNAddAccessAllowedAce =
187 (TAddAccessAllowedAce) GetProcAddress (hAdvapi,
188 "AddAccessAllowedAce");
189 GNSetNamedSecurityInfo =
190 (TSetNamedSecurityInfo) GetProcAddress (hAdvapi,
191 "SetNamedSecurityInfoA");
195 GNOpenSCManager = NULL;
196 GNCreateService = NULL;
197 GNCloseServiceHandle = NULL;
198 GNDeleteService = NULL;
199 GNRegisterServiceCtrlHandler = NULL;
200 GNSetServiceStatus = NULL;
201 GNStartServiceCtrlDispatcher = NULL;
202 GNControlService = NULL;
203 GNOpenService = NULL;
205 GNLsaOpenPolicy = NULL;
206 GNLsaAddAccountRights = NULL;
207 GNLsaRemoveAccountRights = NULL;
209 GNLookupAccountName = NULL;
211 GNGetFileSecurity = NULL;
212 GNInitializeSecurityDescriptor = NULL;
213 GNGetSecurityDescriptorDacl = NULL;
214 GNGetAclInformation = NULL;
215 GNInitializeAcl = NULL;
219 GNAddAccessAllowedAce = NULL;
220 GNSetNamedSecurityInfo = NULL;
223 /* Account function */
224 hNetapi = LoadLibrary ("netapi32.dll");
227 GNNetUserAdd = (TNetUserAdd) GetProcAddress (hNetapi, "NetUserAdd");
229 (TNetUserSetInfo) GetProcAddress (hNetapi, "NetUserSetInfo");
234 GNNetUserSetInfo = NULL;
241 * Clean up Windows environment
248 FreeLibrary (hNTDLL);
249 FreeLibrary (hIphlpapi);
250 FreeLibrary (hAdvapi);
251 FreeLibrary (hNetapi);
260 atoll (const char *nptr)