(file) Return to SystemWindows.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2