![]() ![]() |
![]() |
1 karl 1.25 //%2005//////////////////////////////////////////////////////////////////////// | ||
2 mike 1.6 // | ||
3 karl 1.23 // 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 karl 1.19 // IBM Corp.; EMC Corporation, The Open Group. | ||
7 karl 1.23 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.; 8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. | ||
9 karl 1.25 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; 10 // EMC Corporation; VERITAS Software Corporation; The Open Group. | ||
11 mike 1.6 // 12 // Permission is hereby granted, free of charge, to any person obtaining a copy | ||
13 kumpf 1.11 // of this software and associated documentation files (the "Software"), to 14 // deal in the Software without restriction, including without limitation the 15 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
16 mike 1.6 // sell copies of the Software, and to permit persons to whom the Software is 17 // furnished to do so, subject to the following conditions: | ||
18 karl 1.23 // | ||
19 kumpf 1.11 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN | ||
20 mike 1.6 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED 21 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT | ||
22 kumpf 1.11 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 23 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
25 mike 1.6 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 // 28 //============================================================================== 29 // 30 // Author: Mike Brasher (mbrasher@bmc.com) 31 // | ||
32 mike 1.7 // Modified By: Rudy Schuet (rudy.schuet@compaq.com) 11/12/01 | ||
33 ramnath 1.9 // added nsk platform support 34 // Ramnath Ravindran (Ramnath.Ravindran@compaq.com) 03/21/2002 | ||
35 r.kieninger 1.21 // replaced instances of "| ios::binary" with | ||
36 ramnath 1.9 // PEGASUS_OR_IOS_BINARY | ||
37 r.kieninger 1.21 // Robert Kieninger, IBM (kieningr@de.ibm.com) for Bug#667 | ||
38 dave.sudlik 1.22 // Dave Sudlik, IBM (dsudlik@us.ibm.com) for Bug#1462 | ||
39 gs.keenan 1.26 // Sean Keenan, Hewlett-Packard Company (sean.keenan@hp.com) | ||
40 mike 1.6 // 41 //%///////////////////////////////////////////////////////////////////////////// | ||
42 mike 1.8 | ||
43 sage 1.12 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) | ||
44 r.kieninger 1.21 #include <Pegasus/Common/Config.h> 45 #endif | ||
46 sage 1.12 47 | ||
48 mike 1.8 #include <fstream> | ||
49 kumpf 1.13 #include <cctype> // for tolower() | ||
50 kumpf 1.14 #include <cstring> | ||
51 mike 1.6 #include "System.h" | ||
52 r.kieninger 1.21 #include "Socket.h" 53 54 #ifdef PEGASUS_PLATFORM_WIN32_IX86_MSVC 55 # include <windows.h> 56 #else 57 # include <arpa/inet.h> 58 #endif | ||
59 mike 1.6 | ||
60 kumpf 1.10 #include <Pegasus/Common/PegasusVersion.h> 61 | ||
62 mike 1.6 #if defined(PEGASUS_OS_TYPE_WINDOWS) 63 # include "SystemWindows.cpp" 64 #elif defined(PEGASUS_OS_TYPE_UNIX) 65 # include "SystemUnix.cpp" | ||
66 mike 1.7 #elif defined(PEGASUS_OS_TYPE_NSK) 67 # include "SystemNsk.cpp" | ||
68 gs.keenan 1.26 #elif defined(PEGASUS_OS_VMS) 69 # include "SystemVms.cpp" | ||
70 mike 1.6 #else 71 # error "Unsupported platform" 72 #endif | ||
73 mike 1.8 | ||
74 david 1.16 #if defined(PEGASUS_OS_OS400) 75 # include "OS400ConvertChar.h" 76 #endif 77 | ||
78 mike 1.8 PEGASUS_USING_STD; 79 80 PEGASUS_NAMESPACE_BEGIN 81 | ||
82 kumpf 1.20 Boolean System::bindVerbose = false; 83 | ||
84 mike 1.8 Boolean System::copyFile(const char* fromPath, const char* toPath) 85 { | ||
86 ramnath 1.9 ifstream is(fromPath PEGASUS_IOS_BINARY); 87 ofstream os(toPath PEGASUS_IOS_BINARY); | ||
88 mike 1.8 89 char c; 90 91 while (is.get(c)) 92 { 93 if (!os.put(c)) 94 return false; 95 } 96 97 return true; | ||
98 kumpf 1.13 } 99 | ||
100 mike 1.32 static const Uint8 _toLowerTable[256] = 101 { 102 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, 103 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F, 104 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17, 105 0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F, 106 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27, 107 0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F, 108 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37, 109 0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F, 110 0x40,0x61,0x62,0x63,0x64,0x65,0x66,0x67, 111 0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F, 112 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77, 113 0x78,0x79,0x7A,0x5B,0x5C,0x5D,0x5E,0x5F, 114 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67, 115 0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F, 116 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77, 117 0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F, 118 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, 119 0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, 120 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97, 121 mike 1.32 0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, 122 0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7, 123 0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, 124 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7, 125 0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, 126 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7, 127 0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, 128 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7, 129 0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, 130 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7, 131 0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, 132 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7, 133 0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF, 134 }; 135 | ||
136 kumpf 1.13 Sint32 System::strcasecmp(const char* s1, const char* s2) 137 { | ||
138 mike 1.32 // Note: this is faster than glibc strcasecmp(). 139 140 Uint8* p = (Uint8*)s1; 141 Uint8* q = (Uint8*)s2; 142 int r; 143 144 for (;;) | ||
145 kumpf 1.13 { | ||
146 mike 1.32 if ((r = _toLowerTable[p[0]] - _toLowerTable[q[0]]) || !p[0] || 147 (r = _toLowerTable[p[1]] - _toLowerTable[q[1]]) || !p[1] || 148 (r = _toLowerTable[p[2]] - _toLowerTable[q[2]]) || !p[2] || 149 (r = _toLowerTable[p[3]] - _toLowerTable[q[3]]) || !p[3]) 150 break; | ||
151 kumpf 1.13 | ||
152 mike 1.32 p += 4; 153 q += 4; | ||
154 kumpf 1.13 } 155 | ||
156 mike 1.32 return r; | ||
157 mike 1.8 } 158 | ||
159 tony 1.15 // Return the just the file name from the path into basename 160 char *System::extract_file_name(const char *fullpath, char *basename) 161 { 162 if (fullpath == NULL) | ||
163 kumpf 1.31 { | ||
164 tony 1.15 basename[0] = '\0'; 165 return basename; | ||
166 kumpf 1.31 } 167 168 for (const char* p = fullpath + strlen(fullpath) - 1; p >= fullpath; p--) 169 { | ||
170 tony 1.15 if (*p == '\\' || *p == '/') | ||
171 kumpf 1.31 { | ||
172 tony 1.15 strcpy(basename, p+1); 173 return basename; | ||
174 kumpf 1.31 } 175 } 176 | ||
177 tony 1.15 strcpy(basename, fullpath); 178 return basename; 179 } 180 181 // Return the just the path to the file name into dirname 182 char *System::extract_file_path(const char *fullpath, char *dirname) 183 { 184 char *p; 185 char buff[2048]; 186 if (fullpath == NULL) 187 { 188 dirname[0] = '\0'; 189 return dirname; 190 } 191 strcpy(buff, fullpath); 192 for(p = buff + strlen(buff); p >= buff; p--) 193 { 194 if (*p == '\\' || *p == '/') 195 { 196 strncpy(dirname, buff, p+1 - buff); 197 dirname[p+1 - buff] = '\0'; 198 tony 1.15 return dirname; 199 } 200 } 201 strcpy(dirname, fullpath); 202 return dirname; 203 } 204 | ||
205 marek 1.24 String System::getHostIP(const String &hostName) 206 { 207 struct hostent * phostent; 208 struct in_addr inaddr; 209 String ipAddress = String::EMPTY; | ||
210 humberto 1.27 CString csName = hostName.getCString(); 211 const char * ccName = csName; 212 #ifndef PEGASUS_OS_OS400 213 if ((phostent = ::gethostbyname(ccName)) != NULL) 214 #else | ||
215 chuck 1.28 char ebcdicHost[PEGASUS_MAXHOSTNAMELEN]; 216 if (strlen(ccName) < PEGASUS_MAXHOSTNAMELEN) 217 strcpy(ebcdicHost, ccName); 218 else 219 return ipAddress; 220 AtoE(ebcdicHost); 221 if ((phostent = ::gethostbyname(ebcdicHost)) != NULL) | ||
222 humberto 1.27 #endif | ||
223 marek 1.24 { 224 ::memcpy( &inaddr, phostent->h_addr,4); | ||
225 marek 1.34 #if defined(PEGASUS_OS_OS400) | ||
226 david 1.33 char * gottenIPAdress = NULL; 227 gottenIPAdress = ::inet_ntoa( inaddr ); 228 229 if (gottenIPAdress != NULL) 230 { 231 EtoA(gottenIPAdress); 232 ipAddress.assign(gottenIPAdress); 233 } | ||
234 marek 1.24 #else 235 ipAddress = ::inet_ntoa( inaddr ); 236 #endif 237 } 238 return ipAddress; 239 } | ||
240 r.kieninger 1.21 241 // ------------------------------------------------------------------------ 242 // Convert a hostname into a a single host unique integer representation 243 // ------------------------------------------------------------------------ 244 Uint32 System::_acquireIP(const char* hostname) 245 { 246 Uint32 ip = 0xFFFFFFFF; 247 if (!hostname) return 0xFFFFFFFF; 248 249 #ifdef PEGASUS_OS_OS400 250 char ebcdicHost[PEGASUS_MAXHOSTNAMELEN]; 251 if (strlen(hostname) < PEGASUS_MAXHOSTNAMELEN) 252 strcpy(ebcdicHost, hostname); 253 else 254 return 0xFFFFFFFF; 255 AtoE(ebcdicHost); 256 #endif 257 | ||
258 dave.sudlik 1.22 //////////////////////////////////////////////////////////////////////////////// 259 // This code used to check if the first character of "hostname" was alphabetic 260 // to indicate hostname instead of IP address. But RFC 1123, section 2.1, relaxed 261 // this requirement to alphabetic character *or* digit. So bug 1462 changed the 262 // flow here to call inet_addr first to check for a valid IP address in dotted 263 // decimal notation. If it's not a valid IP address, then try to validate 264 // it as a hostname. 265 // RFC 1123 states: The host SHOULD check the string syntactically for a 266 // dotted-decimal number before looking it up in the Domain Name System. 267 // Hence the call to inet_addr() first. 268 //////////////////////////////////////////////////////////////////////////////// 269 270 #ifdef PEGASUS_OS_OS400 271 Uint32 tmp_addr = inet_addr(ebcdicHost); 272 #else 273 Uint32 tmp_addr = inet_addr((char *) hostname); 274 #endif 275 | ||
276 r.kieninger 1.21 struct hostent *entry; 277 | ||
278 dave.sudlik 1.22 // Note: 0xFFFFFFFF is actually a valid IP address (255.255.255.255). 279 // A better solution would be to use inet_aton() or equivalent, as 280 // inet_addr() is now considered "obsolete". 281 282 if (tmp_addr == 0xFFFFFFFF) // if hostname is not an IP address | ||
283 r.kieninger 1.21 { 284 #ifdef PEGASUS_PLATFORM_SOLARIS_SPARC_CC 285 #define HOSTENT_BUFF_SIZE 8192 286 char buf[HOSTENT_BUFF_SIZE]; 287 int h_errorp; 288 struct hostent hp; 289 290 entry = gethostbyname_r((char *)hostname, &hp, buf, 291 HOSTENT_BUFF_SIZE, &h_errorp); 292 #elif defined(PEGASUS_OS_OS400) 293 entry = gethostbyname(ebcdicHost); 294 #elif defined(PEGASUS_OS_ZOS) | ||
295 kumpf 1.30 char hostName[PEGASUS_MAXHOSTNAMELEN + 1]; | ||
296 r.kieninger 1.21 if (String::equalNoCase("localhost",String(hostname))) 297 { 298 gethostname( hostName, PEGASUS_MAXHOSTNAMELEN ); | ||
299 kumpf 1.30 hostName[sizeof(hostName)-1] = 0; | ||
300 r.kieninger 1.21 entry = gethostbyname(hostName); 301 } else 302 { 303 entry = gethostbyname((char *)hostname); 304 } 305 #else 306 entry = gethostbyname((char *)hostname); 307 #endif 308 if (!entry) 309 { 310 return 0xFFFFFFFF; 311 } 312 unsigned char ip_part1,ip_part2,ip_part3,ip_part4; 313 314 ip_part1 = entry->h_addr[0]; 315 ip_part2 = entry->h_addr[1]; 316 ip_part3 = entry->h_addr[2]; 317 ip_part4 = entry->h_addr[3]; 318 ip = ip_part1; 319 ip = (ip << 8) + ip_part2; 320 ip = (ip << 8) + ip_part3; 321 r.kieninger 1.21 ip = (ip << 8) + ip_part4; | ||
322 dave.sudlik 1.22 } 323 else // else hostname *is* a dotted-decimal IP address | ||
324 r.kieninger 1.21 { 325 // resolve hostaddr to a real host entry 326 // casting to (const char *) as (char *) will work as (void *) too, those it fits all platforms | ||
327 humberto 1.27 #ifndef PEGASUS_OS_OS400 328 entry = gethostbyaddr((const char *) &tmp_addr, sizeof(tmp_addr), AF_INET); 329 #else | ||
330 chuck 1.28 entry = gethostbyaddr((char *) &tmp_addr, sizeof(tmp_addr), AF_INET); | ||
331 humberto 1.27 #endif | ||
332 r.kieninger 1.21 if (entry == 0) 333 { 334 // error, couldn't resolve the ip 335 return 0xFFFFFFFF; 336 } else 337 { 338 339 unsigned char ip_part1,ip_part2,ip_part3,ip_part4; 340 341 ip_part1 = entry->h_addr[0]; 342 ip_part2 = entry->h_addr[1]; 343 ip_part3 = entry->h_addr[2]; 344 ip_part4 = entry->h_addr[3]; 345 ip = ip_part1; 346 ip = (ip << 8) + ip_part2; 347 ip = (ip << 8) + ip_part3; 348 ip = (ip << 8) + ip_part4; 349 } 350 } 351 352 return ip; 353 r.kieninger 1.21 } 354 | ||
355 carolann.graves 1.29 Boolean System::sameHost (const String & hostName) 356 { 357 // 358 // If a port is included, return false 359 // 360 if (hostName.find (":") != PEG_NOT_FOUND) 361 { 362 return false; 363 } 364 365 // 366 // Retrieve IP addresses for both hostnames 367 // 368 Uint32 hostNameIP, systemHostIP = 0xFFFFFFFF; 369 hostNameIP = System::_acquireIP ((const char *) hostName.getCString ()); 370 if (hostNameIP == 0x7F000001) 371 { 372 // 373 // localhost or IP address of 127.0.0.1 374 // real IP address needed for compare 375 // 376 carolann.graves 1.29 hostNameIP = System::_acquireIP 377 ((const char *) System::getHostName ().getCString ()); 378 } 379 if (hostNameIP == 0xFFFFFFFF) 380 { 381 // 382 // Malformed IP address or not resolveable 383 // 384 return false; 385 } 386 387 systemHostIP = System::_acquireIP 388 ((const char *) System::getFullyQualifiedHostName ().getCString ()); 389 390 if (systemHostIP == 0x7F000001) 391 { 392 // 393 // localhost or IP address of 127.0.0.1 394 // real IP address needed for compare 395 // 396 systemHostIP = System::_acquireIP 397 carolann.graves 1.29 ((const char *) System::getHostName ().getCString ()); 398 } 399 if (systemHostIP == 0xFFFFFFFF) 400 { 401 // 402 // Malformed IP address or not resolveable 403 // 404 return false; 405 } 406 407 if (hostNameIP != systemHostIP) 408 { 409 return false; 410 } 411 412 return true; 413 } 414 | ||
415 tony 1.17 // System ID constants for Logger::put and Logger::trace 416 const String System::CIMLISTENER = "cimlistener"; // Listener systme ID 417 | ||
418 mike 1.8 PEGASUS_NAMESPACE_END |
No CVS admin address has been configured |
Powered by ViewCVS 0.9.2 |