1 karl 1.71 //%2003////////////////////////////////////////////////////////////////////////
|
2 mike 1.19 //
|
3 karl 1.71 // 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.19 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
9 mike 1.21 // 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.19 // 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.39 //
|
15 mike 1.21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
16 mike 1.19 // 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.21 // 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.19 // 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.21 // Modified By: Ben Heilbronn (ben_heilbronn@hp.com)
29 // Sushma Fernandes (sushma_fernandes@hp.com)
30 // Nag Boranna (nagaraja_boranna@hp.com)
|
31 mike 1.19 //
|
32 david 1.54 // Modified By: Dave Rosckes (rosckes@us.ibm.com)
33 //
|
34 mike 1.19 //%/////////////////////////////////////////////////////////////////////////////
35
36 #ifdef PEGASUS_OS_HPUX
37 # include <dl.h>
|
38 mike 1.21 #elif defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
39 # include <dll.h>
|
40 chuck 1.44 #elif defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM)
41 # include <fcntl.h>
|
42 david 1.70 # include <qycmutilu2.H>
|
43 chuck 1.44 # include <unistd.cleinc>
|
44 david 1.54 # include "qycmmsgclsMessage.H" // ycmMessage class
|
45 david 1.63 # include "OS400SystemState.h" // OS400LoadDynamicLibrary, etc
46 #include "OS400ConvertChar.h"
|
47 mike 1.19 #else
48 # include <dlfcn.h>
49 #endif
50
|
51 mike 1.21 #include <unistd.h>
|
52 mike 1.19 #include <dirent.h>
|
53 mike 1.21 #include <pwd.h>
|
54 sage 1.23
|
55 chuck 1.44 #if !defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) && !defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM)
|
56 kumpf 1.24 #include <crypt.h>
|
57 sage 1.23 #endif
58
|
59 marek 1.60 #ifdef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM
60 #include <arpa/inet.h>
61 #endif
62
|
63 david 1.54 #if defined(PEGASUS_USE_SYSLOGS)
64 #include <syslog.h>
65 #endif
66
|
67 mike 1.19 #include <sys/stat.h>
68 #include <sys/types.h>
69 #include <cstdio>
70 #include <time.h>
|
71 kumpf 1.41 #include <sys/time.h>
|
72 kumpf 1.24 #include <netdb.h>
|
73 kumpf 1.41 #include "System.h"
|
74 mike 1.21 #include <Pegasus/Common/Tracer.h>
|
75 kumpf 1.25 #include <Pegasus/Common/Destroyer.h>
|
76 kumpf 1.42 #include <Pegasus/Common/InternalException.h>
|
77 mike 1.21
|
78 mike 1.19 PEGASUS_NAMESPACE_BEGIN
79
|
80 kumpf 1.35 #if defined(PEGASUS_OS_HPUX)
81 Boolean System::bindVerbose = false;
82 #endif
83
|
84 david 1.63 #ifdef PEGASUS_OS_OS400
85 typedef struct os400_pnstruct
86 {
87 Qlg_Path_Name_T qlg_struct;
88 char * pn;
89 } OS400_PNSTRUCT;
90 #endif
91
|
92 mike 1.19 inline void sleep_wrapper(Uint32 seconds)
93 {
94 sleep(seconds);
95 }
96
97 void System::getCurrentTime(Uint32& seconds, Uint32& milliseconds)
98 {
99 timeval tv;
100 gettimeofday(&tv, 0);
|
101 kumpf 1.33 seconds = Uint32(tv.tv_sec);
102 milliseconds = Uint32(tv.tv_usec) / 1000;
|
103 mike 1.19 }
104
105 String System::getCurrentASCIITime()
106 {
107 char str[50];
108 time_t rawTime;
109
110 time(&rawTime);
|
111 kumpf 1.32 strftime(str, 40,"%m/%d/%Y-%T", localtime(&rawTime));
|
112 mike 1.19 String time = str;
113 return time;
114 }
115
116 void System::sleep(Uint32 seconds)
117 {
118 sleep_wrapper(seconds);
119 }
120
121 Boolean System::exists(const char* path)
122 {
|
123 david 1.63 #if defined(PEGASUS_OS_OS400)
124 OS400_PNSTRUCT pathname;
125 memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
126 pathname.qlg_struct.CCSID = 1208;
127 #pragma convert(37)
128 memcpy(pathname.qlg_struct.Country_ID,"US",2);
129 memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
130 #pragma convert(0)
131 pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
132 pathname.qlg_struct.Path_Length = strlen(path);
133 pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
134 pathname.pn = (char *)path;
135
136 return QlgAccess((Qlg_Path_Name_T *)&pathname, F_OK) == 0;
137 #else
|
138 mike 1.19 return access(path, F_OK) == 0;
|
139 david 1.63 #endif
|
140 mike 1.19 }
141
142 Boolean System::canRead(const char* path)
143 {
|
144 david 1.63
145 #if defined(PEGASUS_OS_OS400)
146 OS400_PNSTRUCT pathname;
147 memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
148 pathname.qlg_struct.CCSID = 1208;
149 #pragma convert(37)
150 memcpy(pathname.qlg_struct.Country_ID,"US",2);
151 memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
152 #pragma convert(0)
153 pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
154 pathname.qlg_struct.Path_Length = strlen(path);
155 pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
156 pathname.pn = (char *)path;
157
158 return QlgAccess((Qlg_Path_Name_T *)&pathname, R_OK) == 0;
159 #else
|
160 mike 1.19 return access(path, R_OK) == 0;
|
161 david 1.63 #endif
|
162 mike 1.19 }
163
164 Boolean System::canWrite(const char* path)
165 {
|
166 david 1.63 #if defined(PEGASUS_OS_OS400)
167 OS400_PNSTRUCT pathname;
168 memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
169 pathname.qlg_struct.CCSID = 1208;
170 #pragma convert(37)
171 memcpy(pathname.qlg_struct.Country_ID,"US",2);
172 memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
173 #pragma convert(0)
174 pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
175 pathname.qlg_struct.Path_Length = strlen(path);
176 pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
177 pathname.pn = (char *)path;
178
179 return QlgAccess((Qlg_Path_Name_T *)&pathname, W_OK) == 0;
180 #else
|
181 mike 1.19 return access(path, W_OK) == 0;
|
182 david 1.63 #endif
|
183 mike 1.19 }
184
185 Boolean System::getCurrentDirectory(char* path, Uint32 size)
186 {
|
187 david 1.63 #if defined(PEGASUS_OS_OS400)
188 OS400_PNSTRUCT pathname;
189 memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
190 pathname.qlg_struct.CCSID = 1208;
191 #pragma convert(37)
192 memcpy(pathname.qlg_struct.Country_ID,"US",2);
193 memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
194 #pragma convert(0)
195 pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
196 pathname.qlg_struct.Path_Length = strlen(path);
197 pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
198 pathname.pn = (char *)path;
199
200 return QlgGetcwd((Qlg_Path_Name_T *)&pathname, size) == 0;
201 #else
|
202 mike 1.19 return getcwd(path, size) != NULL;
|
203 david 1.63 #endif
|
204 mike 1.19 }
205
206 Boolean System::isDirectory(const char* path)
207 {
208 struct stat st;
209
|
210 david 1.63 #if defined(PEGASUS_OS_OS400)
211 OS400_PNSTRUCT pathname;
212 memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
213 pathname.qlg_struct.CCSID = 1208;
214 #pragma convert(37)
215 memcpy(pathname.qlg_struct.Country_ID,"US",2);
216 memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
217 #pragma convert(0)
218 pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
219 pathname.qlg_struct.Path_Length = strlen(path);
220 pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
221 pathname.pn = (char *)path;
222
223 if (QlgStat((Qlg_Path_Name_T *)&pathname, &st) != 0)
224 return false;
225 #else
|
226 mike 1.19 if (stat(path, &st) != 0)
|
227 mike 1.21 return false;
|
228 david 1.63 #endif
|
229 mike 1.19 return S_ISDIR(st.st_mode);
230 }
231
232 Boolean System::changeDirectory(const char* path)
233 {
|
234 david 1.63 #if defined(PEGASUS_OS_OS400)
235 OS400_PNSTRUCT pathname;
236 memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
237 pathname.qlg_struct.CCSID = 1208;
238 #pragma convert(37)
239 memcpy(pathname.qlg_struct.Country_ID,"US",2);
240 memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
241 #pragma convert(0)
242 pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
243 pathname.qlg_struct.Path_Length = strlen(path);
244 pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
245 pathname.pn = (char *)path;
246
247 return QlgChdir((Qlg_Path_Name_T *)&pathname) == 0;
248 #else
|
249 mike 1.19 return chdir(path) == 0;
|
250 david 1.63 #endif
|
251 mike 1.19 }
252
253 Boolean System::makeDirectory(const char* path)
254 {
|
255 david 1.63
256 #if defined(PEGASUS_OS_OS400)
257 OS400_PNSTRUCT pathname;
258 memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
259 pathname.qlg_struct.CCSID = 1208;
260 #pragma convert(37)
261 memcpy(pathname.qlg_struct.Country_ID,"US",2);
262 memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
263 #pragma convert(0)
264 pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
265 pathname.qlg_struct.Path_Length = strlen(path);
266 pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
267 pathname.pn = (char *)path;
268
269 return QlgMkdir((Qlg_Path_Name_T *)&pathname, 0777) == 0;
270 #else
|
271 mike 1.19 return mkdir(path, 0777) == 0;
|
272 david 1.63 #endif
273
|
274 mike 1.19 }
275
276 Boolean System::getFileSize(const char* path, Uint32& size)
277 {
278 struct stat st;
279
|
280 david 1.63 #if defined(PEGASUS_OS_OS400)
281 OS400_PNSTRUCT pathname;
282 memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
283 pathname.qlg_struct.CCSID = 1208;
284 #pragma convert(37)
285 memcpy(pathname.qlg_struct.Country_ID,"US",2);
286 memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
287 #pragma convert(0)
288 pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
289 pathname.qlg_struct.Path_Length = strlen(path);
290 pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
291 pathname.pn = (char *)path;
292
293 if (QlgStat((Qlg_Path_Name_T *)&pathname, &st) != 0)
294 return false;
295 #else
|
296 mike 1.19 if (stat(path, &st) != 0)
|
297 mike 1.21 return false;
|
298 david 1.63 #endif
|
299 mike 1.19
300 size = st.st_size;
301 return true;
302 }
303
304 Boolean System::removeDirectory(const char* path)
305 {
|
306 david 1.63 #if defined(PEGASUS_OS_OS400)
307 OS400_PNSTRUCT pathname;
308 memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
309 pathname.qlg_struct.CCSID = 1208;
310 #pragma convert(37)
311 memcpy(pathname.qlg_struct.Country_ID,"US",2);
312 memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
313 #pragma convert(0)
314 pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
315 pathname.qlg_struct.Path_Length = strlen(path);
316 pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
317 pathname.pn = (char *)path;
318
319 return QlgRmdir((Qlg_Path_Name_T *)&pathname) == 0;
320 #else
|
321 mike 1.21 return rmdir(path) == 0;
|
322 david 1.63 #endif
|
323 mike 1.19 }
324
325 Boolean System::removeFile(const char* path)
326 {
|
327 david 1.63 #if defined(PEGASUS_OS_OS400)
328 OS400_PNSTRUCT pathname;
329 memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
330 pathname.qlg_struct.CCSID = 1208;
331 #pragma convert(37)
332 memcpy(pathname.qlg_struct.Country_ID,"US",2);
333 memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
334 #pragma convert(0)
335 pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
336 pathname.qlg_struct.Path_Length = strlen(path);
337 pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
338 pathname.pn = (char *)path;
339
340 return QlgUnlink((Qlg_Path_Name_T *)&pathname) == 0;
341 #else
|
342 mike 1.21 return unlink(path) == 0;
|
343 david 1.63 #endif
|
344 mike 1.19 }
345
346 Boolean System::renameFile(const char* oldPath, const char* newPath)
347 {
|
348 david 1.63 #if defined(PEGASUS_OS_OS400)
349 OS400_PNSTRUCT oldpathname;
350 memset((void*)&oldpathname, 0x00, sizeof(OS400_PNSTRUCT));
351 oldpathname.qlg_struct.CCSID = 1208;
352 #pragma convert(37)
353 memcpy(oldpathname.qlg_struct.Country_ID,"US",2);
354 memcpy(oldpathname.qlg_struct.Language_ID,"ENU",3);
355 #pragma convert(0)
356 oldpathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
357 oldpathname.qlg_struct.Path_Length = strlen(oldPath);
358 oldpathname.qlg_struct.Path_Name_Delimiter[0] = '/';
359 oldpathname.pn = (char *)oldPath;
360
361 OS400_PNSTRUCT newpathname;
362 memset((void*)&newpathname, 0x00, sizeof(OS400_PNSTRUCT));
363 newpathname.qlg_struct.CCSID = 1208;
364 #pragma convert(37)
365 memcpy(newpathname.qlg_struct.Country_ID,"US",2);
366 memcpy(newpathname.qlg_struct.Language_ID,"ENU",3);
367 #pragma convert(0)
368 newpathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
369 david 1.63 newpathname.qlg_struct.Path_Length = strlen(newPath);
370 newpathname.qlg_struct.Path_Name_Delimiter[0] = '/';
371 newpathname.pn = (char *)newPath;
372
373 if (QlgLink((Qlg_Path_Name_T *)&oldpathname,
374 (Qlg_Path_Name_T *)&newpathname) != 0)
375 {
376 return false;
377 }
378
379 return QlgUnlink((Qlg_Path_Name_T *)&oldpathname) == 0;
380 #else
381
|
382 mike 1.19 if (link(oldPath, newPath) != 0)
|
383 mike 1.21 return false;
|
384 mike 1.19
385 return unlink(oldPath) == 0;
|
386 david 1.63 #endif
|
387 mike 1.19 }
388
389 DynamicLibraryHandle System::loadDynamicLibrary(const char* fileName)
390 {
|
391 kumpf 1.40 PEG_METHOD_ENTER(TRC_OS_ABSTRACTION, "System::loadDynamicLibrary()");
|
392 mike 1.19
|
393 mike 1.21 Tracer::trace(TRC_OS_ABSTRACTION, Tracer::LEVEL2,
394 "Attempting to load library %s", fileName);
|
395 mike 1.19
|
396 mike 1.21 #if defined(PEGASUS_OS_HPUX)
|
397 kumpf 1.35 void* handle;
398 if (bindVerbose)
399 {
400 handle = shl_load(fileName,
401 BIND_IMMEDIATE | DYNAMIC_PATH | BIND_VERBOSE, 0L);
402 }
403 else
404 {
405 handle = shl_load(fileName, BIND_IMMEDIATE | DYNAMIC_PATH, 0L);
406 }
|
407 mike 1.21 Tracer::trace(TRC_OS_ABSTRACTION, Tracer::LEVEL2,
|
408 kumpf 1.34 "After loading lib %s, error code is %d", fileName,
409 (handle == (void *)0)?errno:0);
|
410 mike 1.21
|
411 kumpf 1.40 PEG_METHOD_EXIT();
|
412 mike 1.19 return DynamicLibraryHandle(handle);
|
413 mike 1.21 #elif defined(PEGASUS_OS_TRU64)
|
414 kumpf 1.40 PEG_METHOD_EXIT();
|
415 mike 1.21 return DynamicLibraryHandle(dlopen(fileName, RTLD_NOW));
416 #elif defined(PEGASUS_OS_ZOS)
|
417 kumpf 1.40 PEG_METHOD_EXIT();
|
418 mike 1.21 return DynamicLibraryHandle(dllload(fileName));
|
419 chuck 1.44 #elif defined(PEGASUS_OS_OS400)
420 PEG_METHOD_EXIT();
|
421 chuck 1.57 return DynamicLibraryHandle(OS400_LoadDynamicLibrary(fileName));
|
422 mike 1.19 #else
|
423 kumpf 1.40 PEG_METHOD_EXIT();
|
424 david 1.63 return DynamicLibraryHandle(dlopen(fileName, RTLD_NOW | RTLD_GLOBAL));
|
425 mike 1.21 #endif
|
426 mike 1.20
|
427 mike 1.21 }
|
428 mike 1.20
|
429 mike 1.21 void System::unloadDynamicLibrary(DynamicLibraryHandle libraryHandle)
430 {
431 // ATTN: Should this method indicate success/failure?
|
432 keith.petley 1.62 #if defined(PEGASUS_OS_LINUX) || defined(PEGASUS_OS_SOLARIS)
|
433 mike 1.21 dlclose(libraryHandle);
434 #endif
435
436 #ifdef PEGASUS_OS_HPUX
437 // Note: shl_unload will unload the library even if it has been loaded
438 // multiple times. No reference count is kept.
|
439 kumpf 1.31 int ignored = shl_unload(reinterpret_cast<shl_t>(libraryHandle));
|
440 mike 1.19 #endif
|
441 chuck 1.57
442 #ifdef PEGASUS_OS_OS400
443 OS400_UnloadDynamicLibrary((int)libraryHandle);
444 #endif
|
445 kv.le 1.64
446 #ifdef PEGASUS_OS_AIX
447 dlclose(libraryHandle);
448 #endif
449
|
450 mike 1.19 }
451
452 String System::dynamicLoadError() {
|
453 mike 1.21 // ATTN: Is this safe in a multi-threaded process? Should this string
454 // be returned from loadDynamicLibrary?
|
455 mike 1.19 #ifdef PEGASUS_OS_HPUX
|
456 mike 1.21 // ATTN: If shl_load() returns NULL, this value should be strerror(errno)
457 return String();
458 #elif defined(PEGASUS_OS_ZOS)
|
459 mike 1.19 return String();
|
460 chuck 1.44 #elif defined(PEGASUS_OS_OS400)
|
461 chuck 1.57 return String(OS400_DynamicLoadError());
|
462 mike 1.19 #else
463 String dlerr = dlerror();
464 return dlerr;
465 #endif
466 }
467
468
469 DynamicSymbolHandle System::loadDynamicSymbol(
470 DynamicLibraryHandle libraryHandle,
471 const char* symbolName)
472 {
473 #ifdef PEGASUS_OS_HPUX
474 char* p = (char*)symbolName;
475 void* proc = 0;
476
|
477 kumpf 1.31 if (shl_findsym((shl_t*)&libraryHandle, symbolName, TYPE_UNDEFINED,
478 &proc) == 0)
479 {
|
480 mike 1.21 return DynamicSymbolHandle(proc);
|
481 kumpf 1.31 }
|
482 mike 1.19
|
483 kumpf 1.47 if (shl_findsym((shl_t*)libraryHandle,
484 (String("_") + symbolName).getCString(),
485 TYPE_UNDEFINED,
|
486 kumpf 1.31 &proc) == 0)
|
487 mike 1.19 {
|
488 mike 1.21 return DynamicSymbolHandle(proc);
|
489 mike 1.19 }
490
491 return 0;
492
|
493 mike 1.21 #elif defined(PEGASUS_OS_ZOS)
494 return DynamicSymbolHandle(dllqueryfn((dllhandle *)libraryHandle,
495 (char*)symbolName));
|
496 chuck 1.44
497 #elif defined(PEGASUS_OS_OS400)
|
498 chuck 1.57 return DynamicSymbolHandle(OS400_LoadDynamicSymbol((int)libraryHandle,
499 symbolName));
|
500 mike 1.19 #else
501
|
502 chuck 1.57 return DynamicSymbolHandle(dlsym(libraryHandle,(char *) symbolName));
|
503 mike 1.19
504 #endif
505 }
506
507 String System::getHostName()
508 {
509 static char hostname[64];
510
511 if (!*hostname)
|
512 david 1.63 {
|
513 mike 1.19 gethostname(hostname, sizeof(hostname));
|
514 david 1.63 #if defined(PEGASUS_OS_OS400)
515 EtoA(hostname);
516 #endif
517 }
|
518 mike 1.19
519 return hostname;
|
520 kumpf 1.24 }
521
|
522 kumpf 1.30 String System::getFullyQualifiedHostName ()
523 {
524 #ifdef PEGASUS_OS_HPUX
525 char hostName [MAXHOSTNAMELEN];
526 struct hostent *he;
527 String fqName;
528
529 if (gethostname (hostName, MAXHOSTNAMELEN) != 0)
530 {
531 return String::EMPTY;
532 }
533
534 if (he = gethostbyname (hostName))
535 {
536 strcpy (hostName, he->h_name);
537 }
538
539 fqName.assign (hostName);
540
541 return fqName;
542 #else
543 kumpf 1.30 //
544 // ATTN: Implement this method to return the fully qualified host name
545 //
546 return String::EMPTY;
547 #endif
548 }
549
550 String System::getSystemCreationClassName ()
551 {
552 #ifdef PEGASUS_OS_HPUX
553 return "CIM_ComputerSystem";
554 #else
555 //
556 // ATTN: Implement this method to return the system creation class name
557 //
558 return String::EMPTY;
559 #endif
560 }
561
|
562 kumpf 1.24 Uint32 System::lookupPort(
563 const char * serviceName,
564 Uint32 defaultPort)
565 {
566 Uint32 localPort;
567
568 struct servent *serv;
569
570 //
571 // Get wbem-local port from /etc/services
572 //
|
573 chuck 1.44 #if !defined(PEGASUS_OS_OS400)
|
574 keith.petley 1.62 #ifdef PEGASUS_OS_SOLARIS
575 #define SERV_BUFF_SIZE 1024
576 struct servent serv_result;
577 char buf[SERV_BUFF_SIZE];
578
579 if ( (serv = getservbyname_r(serviceName, TCP, &serv_result,
580 buf, SERV_BUFF_SIZE)) != NULL )
581 #else // PEGASUS_OS_SOLARIS
|
582 kumpf 1.37 if ( (serv = getservbyname(serviceName, TCP)) != NULL )
|
583 keith.petley 1.62 #endif // PEGASUS_OS_SOLARIS
584 #else // !PEGASUS_OS_OS400
|
585 chuck 1.65 // Note - serviceName came from Constants.h - no need to
586 // convert to EBCDIC
|
587 chuck 1.44 // Need to cast on OS/400
588 if ( (serv = getservbyname((char *)serviceName, TCP)) != NULL )
|
589 keith.petley 1.62 #endif // !PEGASUS_OS_OS400
|
590 kumpf 1.24 {
|
591 sage 1.43 localPort = htons((uint16_t)serv->s_port);
|
592 kumpf 1.24 }
593 else
594 {
595 localPort = defaultPort;
596 }
597
598 return localPort;
|
599 mike 1.19 }
600
|
601 mike 1.21 String System::getPassword(const char* prompt)
602 {
603
604 String password;
605
|
606 chuck 1.44 #if !defined(PEGASUS_OS_OS400)
607 // Not supported on OS/400, and we don't need it.
|
608 mike 1.21 password = String(getpass( prompt ));
|
609 chuck 1.44 #endif
|
610 mike 1.21
611 return password;
612 }
613
|
614 kumpf 1.38 String System::getEffectiveUserName()
|
615 mike 1.21 {
616 String userName = String::EMPTY;
617 struct passwd* pwd = NULL;
618
|
619 kumpf 1.66 #if defined(PEGASUS_OS_SOLARIS) || \
620 defined(PEGASUS_OS_HPUX) || \
621 defined(PEGASUS_OS_LINUX)
622
623 const unsigned int PWD_BUFF_SIZE = 1024;
|
624 keith.petley 1.62 struct passwd local_pwd;
625 char buf[PWD_BUFF_SIZE];
626 if(getpwuid_r(geteuid(), &local_pwd, buf, PWD_BUFF_SIZE, &pwd)) {
627 pwd = (struct passwd *)NULL;
628 }
629 #else
|
630 mike 1.21 //
631 // get the currently logged in user's UID.
632 //
|
633 kumpf 1.38 pwd = getpwuid(geteuid());
|
634 keith.petley 1.62 #endif
|
635 mike 1.21 if ( pwd == NULL )
636 {
637 //ATTN: Log a message
638 // "User might have been removed just after login"
639 }
640 else
641 {
|
642 chuck 1.65 #if defined(PEGASUS_OS_OS400)
643 EtoA(pwd->pw_name);
644 #endif
|
645 mike 1.21 //
646 // get the user name
647 //
648 userName.assign(pwd->pw_name);
649 }
650
651 return(userName);
652 }
653
654 String System::encryptPassword(const char* password, const char* salt)
655 {
|
656 chuck 1.44 #if !defined(PEGASUS_OS_OS400)
|
657 mike 1.21 return ( String(crypt( password,salt)) );
|
658 chuck 1.44 #else
659 // Not supported on OS400, and we don't need it.
660 return ( String(password) );
661 #endif
|
662 mike 1.21 }
663
|
664 kumpf 1.47 Boolean System::isSystemUser(const char* userName)
|
665 mike 1.21 {
|
666 chuck 1.65 #if defined(PEGASUS_OS_OS400)
667 AtoE((char *)userName);
668 #endif
669
|
670 kumpf 1.66 #if defined(PEGASUS_OS_SOLARIS) || \
671 defined(PEGASUS_OS_HPUX) || \
672 defined(PEGASUS_OS_LINUX)
673
674 const unsigned int PWD_BUFF_SIZE = 1024;
|
675 keith.petley 1.62 struct passwd pwd;
676 struct passwd *result;
|
677 kumpf 1.66 char pwdBuffer[PWD_BUFF_SIZE];
|
678 keith.petley 1.62
|
679 kumpf 1.66 if (getpwnam_r(userName, &pwd, pwdBuffer, PWD_BUFF_SIZE, &result) != 0)
|
680 keith.petley 1.62 #else
|
681 mike 1.21 //
682 // get the password entry for the user
683 //
684 if ( getpwnam(userName) == NULL )
|
685 keith.petley 1.62 #endif
|
686 mike 1.21 {
|
687 chuck 1.65 #if defined(PEGASUS_OS_OS400)
688 EtoA((char *)userName);
689 #endif
|
690 mike 1.21 return false;
691 }
|
692 chuck 1.65 #if defined(PEGASUS_OS_OS400)
693 EtoA((char *)userName);
694 #endif
|
695 mike 1.21 return true;
696 }
697
|
698 kumpf 1.25 Boolean System::isPrivilegedUser(const String userName)
|
699 mike 1.21 {
700 //
|
701 kumpf 1.38 // Check if the given user is a privileged user
|
702 mike 1.21 //
|
703 chuck 1.51 #if !defined(PEGASUS_OS_OS400)
|
704 kumpf 1.38 struct passwd pwd;
705 struct passwd *result;
706 char pwdBuffer[1024];
|
707 kumpf 1.25
|
708 kumpf 1.47 if (getpwnam_r(userName.getCString(), &pwd, pwdBuffer, 1024, &result) == 0)
|
709 kumpf 1.25 {
|
710 kumpf 1.38 if ( pwd.pw_uid == 0 )
|
711 kumpf 1.25 {
|
712 kumpf 1.38 return true;
|
713 kumpf 1.25 }
|
714 mike 1.21 }
|
715 kumpf 1.38 return false;
|
716 chuck 1.51 #else
|
717 chuck 1.65 CString user = userName.getCString();
718 const char * tmp = (const char *)user;
719 AtoE((char *)tmp);
720 return ycmCheckUserCmdAuthorities(tmp);
|
721 chuck 1.51 #endif
|
722 kumpf 1.26 }
723
724 String System::getPrivilegedUserName()
725 {
726 static String userName = String::EMPTY;
727
728 if (userName == String::EMPTY)
729 {
730 struct passwd* pwd = NULL;
|
731 kumpf 1.66 #if defined(PEGASUS_OS_SOLARIS) || \
732 defined(PEGASUS_OS_HPUX) || \
733 defined(PEGASUS_OS_LINUX)
734 const unsigned int PWD_BUFF_SIZE = 1024;
|
735 keith.petley 1.62 struct passwd local_pwd;
736 char buf[PWD_BUFF_SIZE];
737 if(getpwuid_r(0, &local_pwd, buf, PWD_BUFF_SIZE, &pwd)) {
738 pwd = (struct passwd *)NULL;
739 }
740 #else
|
741 kumpf 1.26 //
742 // get the privileged user's UID.
743 //
|
744 chuck 1.51 // (on OS/400, this is QSECOFR)
|
745 kumpf 1.26 pwd = getpwuid(0);
|
746 keith.petley 1.62 #endif
|
747 kumpf 1.26 if ( pwd != NULL )
748 {
|
749 chuck 1.65 #if defined(PEGASUS_OS_OS400)
750 EtoA(pwd->pw_name);
751 #endif
|
752 kumpf 1.26 //
753 // get the user name
754 //
755 userName.assign(pwd->pw_name);
756 }
757 else
758 {
759 PEGASUS_ASSERT(0);
760 }
761 }
762
763 return (userName);
|
764 mike 1.21 }
|
765 kumpf 1.22
766 Uint32 System::getPID()
767 {
768 //
769 // Get the Process ID
770 //
771 Uint32 pid = getpid();
772
773 return pid;
774 }
|
775 mike 1.28
776 Boolean System::truncateFile(
777 const char* path,
778 size_t newSize)
779 {
|
780 chuck 1.44 #if !defined(PEGASUS_OS_OS400)
|
781 kumpf 1.29 return (truncate(path, newSize) == 0);
|
782 chuck 1.44 #else
|
783 chuck 1.65 OS400_PNSTRUCT pathname;
784 memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
785 pathname.qlg_struct.CCSID = 1208;
786 #pragma convert(37)
787 memcpy(pathname.qlg_struct.Country_ID,"US",2);
788 memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
789 #pragma convert(0)
790 pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
791 pathname.qlg_struct.Path_Length = strlen(path);
792 pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
793 pathname.pn = (char *)path;
794
795 int fd = QlgOpen((Qlg_Path_Name_T *)&pathname, O_WRONLY);
|
796 chuck 1.44 if (fd != -1)
797 {
798 int rc = ftruncate(fd, newSize);
799 close(fd);
800 return (rc == 0);
801 }
802
803 return false;
804 #endif
|
805 mike 1.28 }
|
806 tony 1.52
807 // Is absolute path?
808 Boolean System::is_absolute_path(const char *path)
809 {
810 if (path == NULL)
811 return false;
812
813 if (path[0] == '/')
814 return true;
815
816 return false;
817 }
|
818 david 1.54
819 void System::openlog(const String ident)
820 {
821 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
822
|
823 kumpf 1.56 // ATTN: Hard-code the "cimserver" identifier until the infrastructure
824 // is set up to pass this as the "ident" string.
825 //::openlog(ident.getCString(), LOG_PID|LOG_CONS, LOG_DAEMON);
|
826 kumpf 1.69 ::openlog("cimserver", LOG_PID, LOG_DAEMON);
|
827 david 1.54
828 #endif
829
830 return;
831 }
832
833 void System::syslog(Uint32 severity, const char *data)
834 {
835 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
836
837 // FUTURE-SF-P3-20020517 : Use the Syslog on HP-UX. Eventually only
838 // certain messages will go to the Syslog and others to the
839 // Pegasus Logger.
840 Uint32 syslogLevel = LOG_DEBUG;
841
842 // Map the log levels.
843 if (severity & Logger::TRACE) syslogLevel = LOG_DEBUG;
844 if (severity & Logger::INFORMATION) syslogLevel = LOG_INFO;
845 if (severity & Logger::WARNING) syslogLevel = LOG_WARNING;
846 if (severity & Logger::SEVERE) syslogLevel = LOG_ERR;
847 if (severity & Logger::FATAL) syslogLevel = LOG_CRIT;
848 david 1.54
|
849 david 1.55 ::syslog(syslogLevel, "%s", data);
|
850 david 1.54
851 #elif defined(PEGASUS_OS_OS400)
852
853 std::string replacementData = data;
854 // All messages will go to the joblog. In the future
855 // some messages may go to other message queues yet
856 // to be determined.
857 if ((severity & Logger::TRACE) ||
858 (severity & Logger::INFORMATION))
859 {
860
861 // turn into ycmMessage so we can put it in the job log
|
862 chuck 1.65 #pragma convert(37)
|
863 david 1.67 ycmMessage theMessage("CPIDF80",
864 data,
865 strlen(data),
866 "Logger",
867 ycmCTLCIMID,
|
868 david 1.68 TRUE);
|
869 chuck 1.65 #pragma convert(0)
|
870 david 1.54
871 // put the message in the joblog
872 theMessage.joblogIt(UnitOfWorkError,
873 ycmMessage::Informational);
874 }
875
876 if ((severity & Logger::WARNING) ||
877 (severity & Logger::SEVERE) ||
878 (severity & Logger::FATAL))
879 {
880 // turn into ycmMessage so we can put it in the job log
|
881 chuck 1.65 #pragma convert(37)
|
882 david 1.67 ycmMessage theMessage("CPDDF82",
883 data,
884 strlen(data),
885 "Logger",
886 ycmCTLCIMID,
|
887 david 1.68 TRUE);
|
888 chuck 1.65 #pragma convert(0)
|
889 david 1.54 // put the message in the joblog
890 theMessage.joblogIt(UnitOfWorkError,
891 ycmMessage::Diagnostic);
892 }
893
894 #endif
895
896 return;
897 }
898
899 void System::closelog()
900 {
901 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
902
|
903 david 1.55 ::closelog();
|
904 david 1.54
905 #endif
906
907 return;
908 }
909
910 // System ID constants for Logger::put and Logger::trace
911 #if defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM)
912 const String System::CIMSERVER = "qycmcimom"; // Server system ID
913 #else
914 const String System::CIMSERVER = "cimserver"; // Server system ID
915 #endif
|
916 mike 1.21
|
917 mike 1.19 PEGASUS_NAMESPACE_END
|