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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2