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 = (TNtQuerySystemInformation)
104 GetProcAddress (hNTDLL, "NtQuerySystemInformation");
108 GNNtQuerySystemInformation = NULL;
111 /* Functions to get information about a network adapter */
112 hIphlpapi = LoadLibrary ("iphlpapi.dll");
115 GNGetIfEntry = (TGetIfEntry) GetProcAddress (hIphlpapi, "GetIfEntry");
116 GNGetIpAddrTable = (TGetIpAddrTable) GetProcAddress (hIphlpapi,
118 GNGetIfTable = (TGetIfTable) GetProcAddress (hIphlpapi, "GetIfTable");
119 GNGetBestInterface = (TGetBestInterface) GetProcAddress (hIphlpapi,
121 GGetAdaptersInfo = (TGetAdaptersInfo) GetProcAddress (hIphlpapi,
127 GNGetIpAddrTable = NULL;
129 GNGetBestInterface = NULL;
130 GGetAdaptersInfo = NULL;
133 /* Service & Account functions */
134 hAdvapi = LoadLibrary ("advapi32.dll");
137 GNOpenSCManager = (TOpenSCManager)
138 GetProcAddress (hAdvapi, "OpenSCManagerA");
139 GNCreateService = (TCreateService)
140 GetProcAddress (hAdvapi, "CreateServiceA");
141 GNCloseServiceHandle = (TCloseServiceHandle)
142 GetProcAddress (hAdvapi, "CloseServiceHandle");
143 GNDeleteService = (TDeleteService)
144 GetProcAddress (hAdvapi, "DeleteService");
145 GNRegisterServiceCtrlHandler = (TRegisterServiceCtrlHandler)
146 GetProcAddress (hAdvapi, "RegisterServiceCtrlHandlerA");
147 GNSetServiceStatus = (TSetServiceStatus)
148 GetProcAddress (hAdvapi, "SetServiceStatus");
149 GNStartServiceCtrlDispatcher = (TStartServiceCtrlDispatcher)
150 GetProcAddress (hAdvapi, "StartServiceCtrlDispatcherA");
151 GNControlService = (TControlService)
152 GetProcAddress (hAdvapi, "ControlService");
153 GNOpenService = (TOpenService) GetProcAddress (hAdvapi, "OpenServiceA");
155 GNLsaOpenPolicy = (TLsaOpenPolicy)
156 GetProcAddress (hAdvapi, "LsaOpenPolicy");
157 GNLsaAddAccountRights = (TLsaAddAccountRights)
158 GetProcAddress (hAdvapi, "LsaAddAccountRights");
159 GNLsaRemoveAccountRights = (TLsaRemoveAccountRights)
160 GetProcAddress (hAdvapi, "LsaRemoveAccountRights");
161 GNLsaClose = (TLsaClose) GetProcAddress (hAdvapi, "LsaClose");
162 GNLookupAccountName = (TLookupAccountName)
163 GetProcAddress (hAdvapi, "LookupAccountNameA");
165 GNGetFileSecurity = (TGetFileSecurity)
166 GetProcAddress (hAdvapi, "GetFileSecurityA");
167 GNInitializeSecurityDescriptor = (TInitializeSecurityDescriptor)
168 GetProcAddress (hAdvapi, "InitializeSecurityDescriptor");
169 GNGetSecurityDescriptorDacl = (TGetSecurityDescriptorDacl)
170 GetProcAddress (hAdvapi, "GetSecurityDescriptorDacl");
171 GNGetAclInformation = (TGetAclInformation)
172 GetProcAddress (hAdvapi, "GetAclInformation");
173 GNInitializeAcl = (TInitializeAcl)
174 GetProcAddress (hAdvapi, "InitializeAcl");
175 GNGetAce = (TGetAce) GetProcAddress (hAdvapi, "GetAce");
176 GNEqualSid = (TEqualSid) GetProcAddress (hAdvapi, "EqualSid");
177 GNAddAce = (TAddAce) GetProcAddress (hAdvapi, "AddAce");
178 GNAddAccessAllowedAce = (TAddAccessAllowedAce)
179 GetProcAddress (hAdvapi, "AddAccessAllowedAce");
180 GNSetNamedSecurityInfo = (TSetNamedSecurityInfo)
181 GetProcAddress (hAdvapi, "SetNamedSecurityInfoA");
185 GNOpenSCManager = NULL;
186 GNCreateService = NULL;
187 GNCloseServiceHandle = NULL;
188 GNDeleteService = NULL;
189 GNRegisterServiceCtrlHandler = NULL;
190 GNSetServiceStatus = NULL;
191 GNStartServiceCtrlDispatcher = NULL;
192 GNControlService = NULL;
193 GNOpenService = NULL;
195 GNLsaOpenPolicy = NULL;
196 GNLsaAddAccountRights = NULL;
197 GNLsaRemoveAccountRights = NULL;
199 GNLookupAccountName = NULL;
201 GNGetFileSecurity = NULL;
202 GNInitializeSecurityDescriptor = NULL;
203 GNGetSecurityDescriptorDacl = NULL;
204 GNGetAclInformation = NULL;
205 GNInitializeAcl = NULL;
209 GNAddAccessAllowedAce = NULL;
210 GNSetNamedSecurityInfo = NULL;
213 /* Account function */
214 hNetapi = LoadLibrary ("netapi32.dll");
217 GNNetUserAdd = (TNetUserAdd) GetProcAddress (hNetapi, "NetUserAdd");
218 GNNetUserSetInfo = (TNetUserSetInfo)
219 GetProcAddress (hNetapi, "NetUserSetInfo");
224 GNNetUserSetInfo = NULL;
231 * Clean up Windows environment
238 FreeLibrary (hNTDLL);
239 FreeLibrary (hIphlpapi);
240 FreeLibrary (hAdvapi);
241 FreeLibrary (hNetapi);
250 atoll (const char *nptr)