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 #include <sys/types.h>
37 #include <time.h>
38 #include <sys/timeb.h>
39 #include <io.h>
40 #include <direct.h>
41 #include <sys/stat.h>
42 #include <sys/types.h>
|
43 kumpf 1.16 #include <winsock.h>
|
44 mike 1.13
45 #define ACCESS_EXISTS 0
46 #define ACCESS_WRITE 2
47 #define ACCESS_READ 4
48 #define ACCESS_READ_AND_WRITE 6
49
50 void System::getCurrentTime(Uint32& seconds, Uint32& milliseconds)
51 {
52 FILETIME ft;
53 GetSystemTimeAsFileTime(&ft);
54 ULARGE_INTEGER largeInt = { ft.dwLowDateTime, ft.dwHighDateTime };
55 largeInt.QuadPart -= 0x19db1ded53e8000;
56 seconds = long(largeInt.QuadPart / (10000 * 1000));
57 milliseconds = long((largeInt.QuadPart % (10000 * 1000)) / 10);
58 }
59
60 String System::getCurrentASCIITime()
61 {
62 char tmpbuf[128];
63 _strtime( tmpbuf );
64 String time = tmpbuf;
65 mike 1.13 _strdate( tmpbuf );
66 time.append("-");
67 time.append(tmpbuf);
68 return time;
69 }
70
71 void System::sleep(Uint32 seconds)
72 {
73 Sleep(seconds * 1000);
74 }
75
76 Boolean System::exists(const char* path)
77 {
78 return _access(path, ACCESS_EXISTS) == 0;
79 }
80
81 Boolean System::canRead(const char* path)
82 {
83 return _access(path, ACCESS_READ) == 0;
84 }
85
86 mike 1.13 Boolean System::canWrite(const char* path)
87 {
88 return _access(path, ACCESS_WRITE) == 0;
89 }
90
91 Boolean System::getCurrentDirectory(char* path, Uint32 size)
92 {
93 return GetCurrentDirectory(size, path) != 0;
94 }
95
96 Boolean System::isDirectory(const char* path)
97 {
98 struct stat st;
99
100 if (stat(path, &st) != 0)
101 return false;
102
103 return (st.st_mode & _S_IFDIR) != 0;
104 }
105
106 Boolean System::changeDirectory(const char* path)
107 mike 1.13 {
108 return chdir(path) == 0;
109 }
110
111 Boolean System::makeDirectory(const char* path)
112 {
113 return _mkdir(path) == 0;
114 }
115
116 Boolean System::getFileSize(const char* path, Uint32& size)
117 {
118 struct stat st;
119
120 if (stat(path, &st) != 0)
121 return false;
122
123 size = st.st_size;
124 return true;
125 }
126
127 Boolean System::removeDirectory(const char* path)
128 mike 1.13 {
129 return rmdir(path) == 0;
130 }
131
132 Boolean System::removeFile(const char* path)
133 {
134 return unlink(path) == 0;
135 }
136
137 Boolean System::renameFile(const char* oldPath, const char* newPath)
138 {
139 return rename(oldPath, newPath) == 0;
140 }
141
142 DynamicLibraryHandle System::loadDynamicLibrary(const char* fileName)
143 {
144 return DynamicLibraryHandle(LoadLibrary(fileName));
145 }
146
|
147 mike 1.14 void System::unloadDynamicLibrary(DynamicLibraryHandle libraryHandle)
148 {
149 FreeLibrary(HINSTANCE(libraryHandle));
150 }
151
|
152 mike 1.13 String System::dynamicLoadError(void) {
153 return String();
154 }
155
156 DynamicSymbolHandle System::loadDynamicSymbol(
157 DynamicLibraryHandle libraryHandle,
158 const char* symbolName)
159 {
160 return DynamicSymbolHandle(GetProcAddress(
161 (HINSTANCE)libraryHandle, symbolName));
162 }
163
164 String System::getHostName()
165 {
166 static char hostname[64];
167
168 if (!*hostname)
169 gethostname(hostname, sizeof(hostname));
170
171 return hostname;
|
172 kumpf 1.16 }
173
174 Uint32 System::lookupPort(
175 const char * serviceName,
176 Uint32 defaultPort)
177 {
178 Uint32 localPort;
179
180 struct servent *serv;
181
182 //
183 // Get wbem-local port from /etc/services
184 //
185 if ( (serv = getservbyname(serviceName, TCP)) != NULL )
186 {
187 localPort = serv->s_port;
188 }
189 else
190 {
191 localPort = defaultPort;
192 }
193 kumpf 1.16
194 return localPort;
|
195 mike 1.13 }
196
|
197 mike 1.14 String System::getPassword(const char* prompt)
198 {
199 //ATTN: Implement this method to get password from User with no echo
200 // This is used in cimuser CLI
201 String password("dummy");
202
203 return password;
204 }
205
206 String System::getCurrentLoginName()
207 {
208 //ATTN: Implement this method to get the current login user name
209 // This is used in local authentication.
210
211 return String();
212 }
213
214 String System::encryptPassword(const char* password, const char* salt)
215 {
216 //ATTN: Implement this method to encrypt the password
217 // This is used in User Manager
218 mike 1.14 return (String("dummy"));
219 }
220
221 Boolean System::isSystemUser(char* userName)
222 {
223 //ATTN: Implement this method to verify if user is vaild on the local system
224 // This is used in User Manager
225 return true;
226 }
227
228 Boolean System::isPrivilegedUser()
229 {
230 // ATTN: Implement this method to verify if user executing the current
231 // command is a priviliged user
232 // This is used in cimuser CLI
233 return true;
234 }
235
|
236 kumpf 1.15 Uint32 System::getPID()
237 {
238 // ATTN: Implement this to get the process ID of the current process
239 // This is used by the Tracer
240 return 0;
241 }
242
|
243 mike 1.13 PEGASUS_NAMESPACE_END
|