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 }
61
62 String System::getCurrentASCIITime()
63 {
64 char tmpbuf[128];
65 _strtime( tmpbuf );
66 String time = tmpbuf;
67 mike 1.13 _strdate( tmpbuf );
68 time.append("-");
69 time.append(tmpbuf);
70 return time;
71 }
72
73 void System::sleep(Uint32 seconds)
74 {
75 Sleep(seconds * 1000);
76 }
77
78 Boolean System::exists(const char* path)
79 {
80 return _access(path, ACCESS_EXISTS) == 0;
81 }
82
83 Boolean System::canRead(const char* path)
84 {
85 return _access(path, ACCESS_READ) == 0;
86 }
87
88 mike 1.13 Boolean System::canWrite(const char* path)
89 {
90 return _access(path, ACCESS_WRITE) == 0;
91 }
92
93 Boolean System::getCurrentDirectory(char* path, Uint32 size)
94 {
95 return GetCurrentDirectory(size, path) != 0;
96 }
97
98 Boolean System::isDirectory(const char* path)
99 {
100 struct stat st;
101
102 if (stat(path, &st) != 0)
103 return false;
104
105 return (st.st_mode & _S_IFDIR) != 0;
106 }
107
108 Boolean System::changeDirectory(const char* path)
109 mike 1.13 {
110 return chdir(path) == 0;
111 }
112
113 Boolean System::makeDirectory(const char* path)
114 {
115 return _mkdir(path) == 0;
116 }
117
118 Boolean System::getFileSize(const char* path, Uint32& size)
119 {
120 struct stat st;
121
122 if (stat(path, &st) != 0)
123 return false;
124
125 size = st.st_size;
126 return true;
127 }
128
129 Boolean System::removeDirectory(const char* path)
130 mike 1.13 {
131 return rmdir(path) == 0;
132 }
133
134 Boolean System::removeFile(const char* path)
135 {
136 return unlink(path) == 0;
137 }
138
139 Boolean System::renameFile(const char* oldPath, const char* newPath)
140 {
141 return rename(oldPath, newPath) == 0;
142 }
143
144 DynamicLibraryHandle System::loadDynamicLibrary(const char* fileName)
145 {
146 return DynamicLibraryHandle(LoadLibrary(fileName));
147 }
148
|
149 mike 1.14 void System::unloadDynamicLibrary(DynamicLibraryHandle libraryHandle)
150 {
151 FreeLibrary(HINSTANCE(libraryHandle));
152 }
153
|
154 mike 1.13 String System::dynamicLoadError(void) {
155 return String();
156 }
157
158 DynamicSymbolHandle System::loadDynamicSymbol(
159 DynamicLibraryHandle libraryHandle,
160 const char* symbolName)
161 {
162 return DynamicSymbolHandle(GetProcAddress(
163 (HINSTANCE)libraryHandle, symbolName));
164 }
165
166 String System::getHostName()
167 {
168 static char hostname[64];
169
170 if (!*hostname)
171 gethostname(hostname, sizeof(hostname));
172
173 return hostname;
|
174 kumpf 1.16 }
175
176 Uint32 System::lookupPort(
177 const char * serviceName,
178 Uint32 defaultPort)
179 {
180 Uint32 localPort;
181
182 struct servent *serv;
183
184 //
185 // Get wbem-local port from /etc/services
186 //
187 if ( (serv = getservbyname(serviceName, TCP)) != NULL )
188 {
189 localPort = serv->s_port;
190 }
191 else
192 {
193 localPort = defaultPort;
194 }
195 kumpf 1.16
196 return localPort;
|
197 mike 1.13 }
198
|
199 mike 1.14 String System::getPassword(const char* prompt)
200 {
201 //ATTN: Implement this method to get password from User with no echo
202 // This is used in cimuser CLI
203 String password("dummy");
204
205 return password;
206 }
207
208 String System::getCurrentLoginName()
209 {
210 //ATTN: Implement this method to get the current login user name
211 // This is used in local authentication.
212
213 return String();
214 }
215
216 String System::encryptPassword(const char* password, const char* salt)
217 {
218 //ATTN: Implement this method to encrypt the password
219 // This is used in User Manager
220 mike 1.14 return (String("dummy"));
221 }
222
223 Boolean System::isSystemUser(char* userName)
224 {
225 //ATTN: Implement this method to verify if user is vaild on the local system
226 // This is used in User Manager
227 return true;
228 }
229
|
230 kumpf 1.17 Boolean System::isPrivilegedUser(const String userName)
|
231 mike 1.14 {
232 // ATTN: Implement this method to verify if user executing the current
|
233 kumpf 1.17 // command is a priviliged user, when user name is not passed as
234 // as argument. If user name is passed the function checks
235 // whether the given user is a priviliged user.
236 // This is used in cimuser CLI and CIMOperationRequestAuthorizer
|
237 mike 1.14 return true;
238 }
|
239 kumpf 1.20
240 String System::getPrivilegedUserName()
241 {
242 // ATTN-NB-03-20000304: Implement better way to get the privileged
243 // user on the system.
244
245 return (String("Administrator"));
246 }
|
247 mike 1.14
|
248 kumpf 1.15 Uint32 System::getPID()
249 {
|
250 kumpf 1.18 return _getpid();
|
251 mike 1.21 }
252
253 Boolean System::truncateFile(
254 const char* path,
255 size_t newSize)
256 {
257 int fd = open(path, O_RDWR);
258
259 if (fd == -1)
260 return false;
261
262 if (chsize(fd, newSize) != 0)
263 return false;
264
265 close(fd);
266 return true;
|
267 kumpf 1.15 }
268
|
269 mike 1.13 PEGASUS_NAMESPACE_END
|