1 mike 1.13 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 mike 1.14 // of this software and associated documentation files (the "Software"), to
7 // deal in the Software without restriction, including without limitation the
8 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
9 mike 1.13 // sell copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
|
11 mike 1.14 //
12 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
13 mike 1.13 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
14 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
15 mike 1.14 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
18 mike 1.13 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 //
21 //==============================================================================
22 //
23 // Author: Mike Brasher (mbrasher@bmc.com)
24 //
|
25 mike 1.14 // Modified By: Sushma Fernandes (sushma_fernandes@hp.com)
26 //
27 // Nag Boranna, Hewlett-Packard Company (nagaraja_boranna@hp.com)
|
28 mike 1.13 //
29 //%/////////////////////////////////////////////////////////////////////////////
30
31 #include "System.h"
32
33 PEGASUS_NAMESPACE_BEGIN
34
35 #include <windows.h>
|
36 mike 1.21 #include <fcntl.h>
|
37 mike 1.13 #include <sys/types.h>
38 #include <time.h>
39 #include <sys/timeb.h>
40 #include <io.h>
41 #include <direct.h>
42 #include <sys/stat.h>
43 #include <sys/types.h>
|
44 mday 1.19 #include <windows.h>
|
45 kumpf 1.18 #include <process.h>
|
46 mike 1.13
47 #define ACCESS_EXISTS 0
48 #define ACCESS_WRITE 2
49 #define ACCESS_READ 4
50 #define ACCESS_READ_AND_WRITE 6
51
52 void System::getCurrentTime(Uint32& seconds, Uint32& milliseconds)
53 {
54 FILETIME ft;
55 GetSystemTimeAsFileTime(&ft);
56 ULARGE_INTEGER largeInt = { ft.dwLowDateTime, ft.dwHighDateTime };
57 largeInt.QuadPart -= 0x19db1ded53e8000;
58 seconds = long(largeInt.QuadPart / (10000 * 1000));
59 milliseconds = long((largeInt.QuadPart % (10000 * 1000)) / 10);
|
60 karl 1.23 // This is a real hack. Added the following line after timevalue was
61 // corrected and this apparently wrong. ks 7 apri 2002
62 milliseconds = milliseconds / 1000;
|
63 mike 1.13 }
64
65 String System::getCurrentASCIITime()
66 {
67 char tmpbuf[128];
68 _strtime( tmpbuf );
69 String time = tmpbuf;
70 _strdate( tmpbuf );
71 time.append("-");
72 time.append(tmpbuf);
73 return time;
74 }
75
76 void System::sleep(Uint32 seconds)
77 {
78 Sleep(seconds * 1000);
79 }
80
81 Boolean System::exists(const char* path)
82 {
83 return _access(path, ACCESS_EXISTS) == 0;
84 mike 1.13 }
85
86 Boolean System::canRead(const char* path)
87 {
88 return _access(path, ACCESS_READ) == 0;
89 }
90
91 Boolean System::canWrite(const char* path)
92 {
93 return _access(path, ACCESS_WRITE) == 0;
94 }
95
96 Boolean System::getCurrentDirectory(char* path, Uint32 size)
97 {
98 return GetCurrentDirectory(size, path) != 0;
99 }
100
101 Boolean System::isDirectory(const char* path)
102 {
103 struct stat st;
104
105 mike 1.13 if (stat(path, &st) != 0)
106 return false;
107
108 return (st.st_mode & _S_IFDIR) != 0;
109 }
110
111 Boolean System::changeDirectory(const char* path)
112 {
113 return chdir(path) == 0;
114 }
115
116 Boolean System::makeDirectory(const char* path)
117 {
118 return _mkdir(path) == 0;
119 }
120
121 Boolean System::getFileSize(const char* path, Uint32& size)
122 {
123 struct stat st;
124
125 if (stat(path, &st) != 0)
126 mike 1.13 return false;
127
128 size = st.st_size;
129 return true;
130 }
131
132 Boolean System::removeDirectory(const char* path)
133 {
134 return rmdir(path) == 0;
135 }
136
137 Boolean System::removeFile(const char* path)
138 {
139 return unlink(path) == 0;
140 }
141
142 Boolean System::renameFile(const char* oldPath, const char* newPath)
143 {
144 return rename(oldPath, newPath) == 0;
145 }
146
147 mike 1.13 DynamicLibraryHandle System::loadDynamicLibrary(const char* fileName)
148 {
149 return DynamicLibraryHandle(LoadLibrary(fileName));
150 }
151
|
152 mike 1.14 void System::unloadDynamicLibrary(DynamicLibraryHandle libraryHandle)
153 {
154 FreeLibrary(HINSTANCE(libraryHandle));
155 }
156
|
157 mike 1.13 String System::dynamicLoadError(void) {
158 return String();
159 }
160
161 DynamicSymbolHandle System::loadDynamicSymbol(
162 DynamicLibraryHandle libraryHandle,
163 const char* symbolName)
164 {
165 return DynamicSymbolHandle(GetProcAddress(
166 (HINSTANCE)libraryHandle, symbolName));
167 }
168
169 String System::getHostName()
170 {
171 static char hostname[64];
172
173 if (!*hostname)
174 gethostname(hostname, sizeof(hostname));
175
176 return hostname;
|
177 kumpf 1.16 }
178
|
179 kumpf 1.22 String System::getFullyQualifiedHostName ()
180 {
181 //
182 // ATTN: Implement this method to return the fully qualified host name
183 //
184 return String::EMPTY;
185 }
186
187 String System::getSystemCreationClassName ()
188 {
189 //
190 // ATTN: Implement this method to return the system creation class name
191 //
192 return String::EMPTY;
193 }
194
|
195 kumpf 1.16 Uint32 System::lookupPort(
196 const char * serviceName,
197 Uint32 defaultPort)
198 {
199 Uint32 localPort;
200
201 struct servent *serv;
202
203 //
204 // Get wbem-local port from /etc/services
205 //
206 if ( (serv = getservbyname(serviceName, TCP)) != NULL )
207 {
208 localPort = serv->s_port;
209 }
210 else
211 {
212 localPort = defaultPort;
213 }
214
215 return localPort;
|
216 mike 1.13 }
217
|
218 mike 1.14 String System::getPassword(const char* prompt)
219 {
220 //ATTN: Implement this method to get password from User with no echo
221 // This is used in cimuser CLI
222 String password("dummy");
223
224 return password;
225 }
226
227 String System::getCurrentLoginName()
228 {
229 //ATTN: Implement this method to get the current login user name
230 // This is used in local authentication.
231
232 return String();
233 }
234
235 String System::encryptPassword(const char* password, const char* salt)
236 {
237 //ATTN: Implement this method to encrypt the password
238 // This is used in User Manager
239 mike 1.14 return (String("dummy"));
240 }
241
242 Boolean System::isSystemUser(char* userName)
243 {
244 //ATTN: Implement this method to verify if user is vaild on the local system
245 // This is used in User Manager
246 return true;
247 }
248
|
249 kumpf 1.17 Boolean System::isPrivilegedUser(const String userName)
|
250 mike 1.14 {
251 // ATTN: Implement this method to verify if user executing the current
|
252 kumpf 1.17 // command is a priviliged user, when user name is not passed as
253 // as argument. If user name is passed the function checks
254 // whether the given user is a priviliged user.
255 // This is used in cimuser CLI and CIMOperationRequestAuthorizer
|
256 mike 1.14 return true;
257 }
|
258 kumpf 1.20
259 String System::getPrivilegedUserName()
260 {
261 // ATTN-NB-03-20000304: Implement better way to get the privileged
262 // user on the system.
263
264 return (String("Administrator"));
265 }
|
266 mike 1.14
|
267 kumpf 1.15 Uint32 System::getPID()
268 {
|
269 kumpf 1.18 return _getpid();
|
270 mike 1.21 }
271
272 Boolean System::truncateFile(
273 const char* path,
274 size_t newSize)
275 {
276 int fd = open(path, O_RDWR);
277
278 if (fd == -1)
279 return false;
280
281 if (chsize(fd, newSize) != 0)
282 return false;
283
284 close(fd);
285 return true;
|
286 kumpf 1.15 }
287
|
288 mike 1.13 PEGASUS_NAMESPACE_END
|