1 karl 1.95 //%2005////////////////////////////////////////////////////////////////////////
|
2 mike 1.19 //
|
3 karl 1.92 // 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.71 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.92 // 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.95 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 mike 1.19 //
12 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
13 mike 1.21 // 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.19 // 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 david.dillard 1.107 //
|
19 mike 1.21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
20 mike 1.19 // 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 mike 1.21 // 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.19 // 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.21 // Modified By: Ben Heilbronn (ben_heilbronn@hp.com)
33 // Sushma Fernandes (sushma_fernandes@hp.com)
34 // Nag Boranna (nagaraja_boranna@hp.com)
|
35 kumpf 1.75 // Bapu Patil (bapu_patil@hp.com)
|
36 kumpf 1.104 // Dave Rosckes (rosckes@us.ibm.com)
|
37 a.arora 1.87 // Amit K Arora (amita@in.ibm.com) for PEP101
|
38 david.dillard 1.93 // David Dillard, VERITAS Software Corp.
39 // (david.dillard@veritas.com)
|
40 yi.zhou 1.96 // Yi Zhou (yi.zhou@hp.com)
|
41 joyce.j 1.101 // Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) for Bug#3194
|
42 kumpf 1.104 // Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
|
43 david 1.54 //
|
44 mike 1.19 //%/////////////////////////////////////////////////////////////////////////////
45
46 #ifdef PEGASUS_OS_HPUX
47 # include <dl.h>
|
48 mike 1.21 #elif defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
49 # include <dll.h>
|
50 chuck 1.44 #elif defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM)
|
51 kumpf 1.104 # include <fcntl.h>
52 # include <qycmutilu2.H>
53 # include <unistd.cleinc>
54 # include "qycmmsgclsMessage.H" // ycmMessage class
55 # include "OS400SystemState.h" // OS400LoadDynamicLibrary, etc
56 # include "OS400ConvertChar.h"
|
57 mike 1.19 #else
58 # include <dlfcn.h>
59 #endif
60
|
61 mike 1.21 #include <unistd.h>
|
62 mike 1.19 #include <dirent.h>
|
63 mike 1.21 #include <pwd.h>
|
64 kumpf 1.81 #include <grp.h>
|
65 sage 1.23
|
66 kumpf 1.79 #include <errno.h>
|
67 kumpf 1.104 #if defined(PEGASUS_OS_SOLARIS)
68 # include <string.h>
69 #endif
|
70 kumpf 1.79
|
71 kumpf 1.104 #if !defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) && !defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM) && !defined(PEGASUS_PLATFORM_DARWIN_PPC_GNU)
72 #include <crypt.h>
|
73 sage 1.23 #endif
74
|
75 marek 1.60 #ifdef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM
|
76 marek 1.113 #define _OPEN_SYS_SOCK_IPV6
77 #include <sys/socket.h>
|
78 marek 1.60 #include <arpa/inet.h>
|
79 marek 1.113 //#include <__ftp.h>
80 #define _OPEN_SYS_EXT
81 #include <sys/ps.h>
|
82 marek 1.60 #endif
83
|
84 kumpf 1.104 #if defined(PEGASUS_USE_SYSLOGS)
|
85 david 1.54 #include <syslog.h>
86 #endif
87
|
88 mike 1.19 #include <sys/stat.h>
89 #include <sys/types.h>
90 #include <cstdio>
91 #include <time.h>
|
92 kumpf 1.41 #include <sys/time.h>
|
93 kumpf 1.24 #include <netdb.h>
|
94 kumpf 1.41 #include "System.h"
|
95 mike 1.21 #include <Pegasus/Common/Tracer.h>
|
96 kumpf 1.42 #include <Pegasus/Common/InternalException.h>
|
97 kumpf 1.104 #include <Pegasus/Common/IPC.h>
|
98 marek 1.73 #ifdef PEGASUS_ZOS_SECURITY
99 #include "DynamicLibraryzOS_inline.h"
100 #endif
|
101 mike 1.21
|
102 konrad.r 1.86 #if defined(PEGASUS_OS_LSB)
103 #include <netinet/in.h>
104 #include <termios.h>
105 #include <stdio.h>
106 #include <stdlib.h>
107 #endif
108
|
109 mike 1.19 PEGASUS_NAMESPACE_BEGIN
110
|
111 david 1.63 #ifdef PEGASUS_OS_OS400
112 typedef struct os400_pnstruct
113 {
114 Qlg_Path_Name_T qlg_struct;
|
115 kumpf 1.104 char * pn;
|
116 david 1.63 } OS400_PNSTRUCT;
117 #endif
118
|
119 mike 1.19 inline void sleep_wrapper(Uint32 seconds)
120 {
121 sleep(seconds);
122 }
123
124 void System::getCurrentTime(Uint32& seconds, Uint32& milliseconds)
125 {
126 timeval tv;
127 gettimeofday(&tv, 0);
|
128 kumpf 1.33 seconds = Uint32(tv.tv_sec);
129 milliseconds = Uint32(tv.tv_usec) / 1000;
|
130 mike 1.19 }
131
|
132 jim.wunderlich 1.112 void System::getCurrentTimeUsec(Uint32& seconds, Uint32& microseconds)
133 {
134 timeval tv;
135 gettimeofday(&tv, 0);
136 seconds = Uint32(tv.tv_sec);
137 microseconds = Uint32(tv.tv_usec);
138 }
139
|
140 mike 1.19 String System::getCurrentASCIITime()
141 {
142 char str[50];
143 time_t rawTime;
|
144 kumpf 1.88 struct tm tmBuffer;
|
145 mike 1.19
146 time(&rawTime);
|
147 kumpf 1.88 strftime(str, 40,"%m/%d/%Y-%T", localtime_r(&rawTime, &tmBuffer));
148 return String(str);
|
149 mike 1.19 }
150
151 void System::sleep(Uint32 seconds)
152 {
153 sleep_wrapper(seconds);
154 }
155
156 Boolean System::exists(const char* path)
157 {
|
158 david 1.63 #if defined(PEGASUS_OS_OS400)
159 OS400_PNSTRUCT pathname;
160 memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
161 pathname.qlg_struct.CCSID = 1208;
162 #pragma convert(37)
163 memcpy(pathname.qlg_struct.Country_ID,"US",2);
164 memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
165 #pragma convert(0)
166 pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
167 pathname.qlg_struct.Path_Length = strlen(path);
168 pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
169 pathname.pn = (char *)path;
|
170 kumpf 1.104
|
171 david 1.63 return QlgAccess((Qlg_Path_Name_T *)&pathname, F_OK) == 0;
172 #else
|
173 mike 1.19 return access(path, F_OK) == 0;
|
174 david 1.63 #endif
|
175 mike 1.19 }
176
177 Boolean System::canRead(const char* path)
178 {
|
179 david 1.63
180 #if defined(PEGASUS_OS_OS400)
181 OS400_PNSTRUCT pathname;
182 memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
183 pathname.qlg_struct.CCSID = 1208;
184 #pragma convert(37)
185 memcpy(pathname.qlg_struct.Country_ID,"US",2);
186 memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
187 #pragma convert(0)
188 pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
189 pathname.qlg_struct.Path_Length = strlen(path);
190 pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
191 pathname.pn = (char *)path;
192
193 return QlgAccess((Qlg_Path_Name_T *)&pathname, R_OK) == 0;
194 #else
|
195 mike 1.19 return access(path, R_OK) == 0;
|
196 david 1.63 #endif
|
197 mike 1.19 }
198
199 Boolean System::canWrite(const char* path)
200 {
|
201 david 1.63 #if defined(PEGASUS_OS_OS400)
202 OS400_PNSTRUCT pathname;
203 memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
204 pathname.qlg_struct.CCSID = 1208;
205 #pragma convert(37)
206 memcpy(pathname.qlg_struct.Country_ID,"US",2);
207 memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
208 #pragma convert(0)
209 pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
210 pathname.qlg_struct.Path_Length = strlen(path);
211 pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
212 pathname.pn = (char *)path;
|
213 kumpf 1.104
|
214 david 1.63 return QlgAccess((Qlg_Path_Name_T *)&pathname, W_OK) == 0;
215 #else
|
216 mike 1.19 return access(path, W_OK) == 0;
|
217 david 1.63 #endif
|
218 mike 1.19 }
219
220 Boolean System::getCurrentDirectory(char* path, Uint32 size)
221 {
|
222 david 1.63 #if defined(PEGASUS_OS_OS400)
223 OS400_PNSTRUCT pathname;
224 memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
225 pathname.qlg_struct.CCSID = 1208;
226 #pragma convert(37)
227 memcpy(pathname.qlg_struct.Country_ID,"US",2);
228 memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
229 #pragma convert(0)
230 pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
231 pathname.qlg_struct.Path_Length = strlen(path);
232 pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
233 pathname.pn = (char *)path;
|
234 kumpf 1.104
|
235 david 1.63 return QlgGetcwd((Qlg_Path_Name_T *)&pathname, size) == 0;
236 #else
|
237 mike 1.19 return getcwd(path, size) != NULL;
|
238 david 1.63 #endif
|
239 mike 1.19 }
240
241 Boolean System::isDirectory(const char* path)
242 {
243 struct stat st;
244
|
245 david 1.63 #if defined(PEGASUS_OS_OS400)
246 OS400_PNSTRUCT pathname;
247 memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
248 pathname.qlg_struct.CCSID = 1208;
249 #pragma convert(37)
250 memcpy(pathname.qlg_struct.Country_ID,"US",2);
251 memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
252 #pragma convert(0)
253 pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
254 pathname.qlg_struct.Path_Length = strlen(path);
255 pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
256 pathname.pn = (char *)path;
257
258 if (QlgStat((Qlg_Path_Name_T *)&pathname, &st) != 0)
|
259 kumpf 1.104 return false;
|
260 david 1.63 #else
|
261 mike 1.19 if (stat(path, &st) != 0)
|
262 mike 1.21 return false;
|
263 david 1.63 #endif
|
264 mike 1.19 return S_ISDIR(st.st_mode);
265 }
266
267 Boolean System::changeDirectory(const char* path)
268 {
|
269 david 1.63 #if defined(PEGASUS_OS_OS400)
270 OS400_PNSTRUCT pathname;
271 memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
272 pathname.qlg_struct.CCSID = 1208;
273 #pragma convert(37)
274 memcpy(pathname.qlg_struct.Country_ID,"US",2);
275 memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
276 #pragma convert(0)
277 pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
278 pathname.qlg_struct.Path_Length = strlen(path);
279 pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
280 pathname.pn = (char *)path;
|
281 kumpf 1.104
|
282 david 1.63 return QlgChdir((Qlg_Path_Name_T *)&pathname) == 0;
283 #else
|
284 mike 1.19 return chdir(path) == 0;
|
285 david 1.63 #endif
|
286 mike 1.19 }
287
288 Boolean System::makeDirectory(const char* path)
289 {
|
290 david 1.63
291 #if defined(PEGASUS_OS_OS400)
292 OS400_PNSTRUCT pathname;
293 memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
294 pathname.qlg_struct.CCSID = 1208;
295 #pragma convert(37)
296 memcpy(pathname.qlg_struct.Country_ID,"US",2);
297 memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
298 #pragma convert(0)
299 pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
300 pathname.qlg_struct.Path_Length = strlen(path);
301 pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
302 pathname.pn = (char *)path;
|
303 kumpf 1.104
|
304 david 1.63 return QlgMkdir((Qlg_Path_Name_T *)&pathname, 0777) == 0;
305 #else
|
306 mike 1.19 return mkdir(path, 0777) == 0;
|
307 david 1.63 #endif
308
|
309 mike 1.19 }
310
311 Boolean System::getFileSize(const char* path, Uint32& size)
312 {
313 struct stat st;
314
|
315 david 1.63 #if defined(PEGASUS_OS_OS400)
316 OS400_PNSTRUCT pathname;
317 memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
318 pathname.qlg_struct.CCSID = 1208;
319 #pragma convert(37)
320 memcpy(pathname.qlg_struct.Country_ID,"US",2);
321 memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
322 #pragma convert(0)
323 pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
324 pathname.qlg_struct.Path_Length = strlen(path);
325 pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
326 pathname.pn = (char *)path;
327
328 if (QlgStat((Qlg_Path_Name_T *)&pathname, &st) != 0)
|
329 kumpf 1.104 return false;
|
330 david 1.63 #else
|
331 mike 1.19 if (stat(path, &st) != 0)
|
332 mike 1.21 return false;
|
333 david 1.63 #endif
|
334 mike 1.19
335 size = st.st_size;
336 return true;
337 }
338
339 Boolean System::removeDirectory(const char* path)
340 {
|
341 david 1.63 #if defined(PEGASUS_OS_OS400)
342 OS400_PNSTRUCT pathname;
343 memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
344 pathname.qlg_struct.CCSID = 1208;
345 #pragma convert(37)
346 memcpy(pathname.qlg_struct.Country_ID,"US",2);
347 memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
348 #pragma convert(0)
349 pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
350 pathname.qlg_struct.Path_Length = strlen(path);
351 pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
352 pathname.pn = (char *)path;
|
353 kumpf 1.104
|
354 david 1.63 return QlgRmdir((Qlg_Path_Name_T *)&pathname) == 0;
355 #else
|
356 mike 1.21 return rmdir(path) == 0;
|
357 david 1.63 #endif
|
358 mike 1.19 }
359
360 Boolean System::removeFile(const char* path)
361 {
|
362 david 1.63 #if defined(PEGASUS_OS_OS400)
363 OS400_PNSTRUCT pathname;
364 memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
365 pathname.qlg_struct.CCSID = 1208;
366 #pragma convert(37)
367 memcpy(pathname.qlg_struct.Country_ID,"US",2);
368 memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
369 #pragma convert(0)
370 pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
371 pathname.qlg_struct.Path_Length = strlen(path);
372 pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
373 pathname.pn = (char *)path;
|
374 kumpf 1.104
|
375 david 1.63 return QlgUnlink((Qlg_Path_Name_T *)&pathname) == 0;
376 #else
|
377 mike 1.21 return unlink(path) == 0;
|
378 david 1.63 #endif
|
379 mike 1.19 }
380
381 Boolean System::renameFile(const char* oldPath, const char* newPath)
382 {
|
383 david 1.63 #if defined(PEGASUS_OS_OS400)
384 OS400_PNSTRUCT oldpathname;
385 memset((void*)&oldpathname, 0x00, sizeof(OS400_PNSTRUCT));
386 oldpathname.qlg_struct.CCSID = 1208;
387 #pragma convert(37)
388 memcpy(oldpathname.qlg_struct.Country_ID,"US",2);
389 memcpy(oldpathname.qlg_struct.Language_ID,"ENU",3);
390 #pragma convert(0)
391 oldpathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
392 oldpathname.qlg_struct.Path_Length = strlen(oldPath);
393 oldpathname.qlg_struct.Path_Name_Delimiter[0] = '/';
394 oldpathname.pn = (char *)oldPath;
395
396 OS400_PNSTRUCT newpathname;
397 memset((void*)&newpathname, 0x00, sizeof(OS400_PNSTRUCT));
398 newpathname.qlg_struct.CCSID = 1208;
399 #pragma convert(37)
400 memcpy(newpathname.qlg_struct.Country_ID,"US",2);
401 memcpy(newpathname.qlg_struct.Language_ID,"ENU",3);
402 #pragma convert(0)
403 newpathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
404 david 1.63 newpathname.qlg_struct.Path_Length = strlen(newPath);
405 newpathname.qlg_struct.Path_Name_Delimiter[0] = '/';
406 newpathname.pn = (char *)newPath;
407
408 if (QlgLink((Qlg_Path_Name_T *)&oldpathname,
|
409 kumpf 1.104 (Qlg_Path_Name_T *)&newpathname) != 0)
|
410 david 1.63 {
|
411 kumpf 1.104 return false;
|
412 david 1.63 }
413
414 return QlgUnlink((Qlg_Path_Name_T *)&oldpathname) == 0;
415 #else
416
|
417 mike 1.19 if (link(oldPath, newPath) != 0)
|
418 mike 1.21 return false;
|
419 mike 1.19
420 return unlink(oldPath) == 0;
|
421 david 1.63 #endif
|
422 mike 1.19 }
423
424 DynamicLibraryHandle System::loadDynamicLibrary(const char* fileName)
425 {
|
426 kumpf 1.40 PEG_METHOD_ENTER(TRC_OS_ABSTRACTION, "System::loadDynamicLibrary()");
|
427 mike 1.19
|
428 kumpf 1.104 Tracer::trace(TRC_OS_ABSTRACTION, Tracer::LEVEL2,
|
429 mike 1.21 "Attempting to load library %s", fileName);
|
430 mike 1.19
|
431 kumpf 1.115 #if defined(PEGASUS_OS_HPUX)
432 void* handle;
433 if (bindVerbose)
434 {
435 handle = shl_load(fileName,
436 BIND_IMMEDIATE | DYNAMIC_PATH | BIND_VERBOSE, 0L);
437 }
438 else
439 {
440 handle = shl_load(fileName, BIND_IMMEDIATE | DYNAMIC_PATH, 0L);
441 }
442 Tracer::trace(TRC_OS_ABSTRACTION, Tracer::LEVEL2,
443 "After loading lib %s, error code is %d", fileName,
444 (handle == (void *)0)?errno:0);
445
446 PEG_METHOD_EXIT();
447 return DynamicLibraryHandle(handle);
448 #elif defined(PEGASUS_OS_TRU64)
|
449 kumpf 1.40 PEG_METHOD_EXIT();
|
450 mike 1.21 return DynamicLibraryHandle(dlopen(fileName, RTLD_NOW));
451 #elif defined(PEGASUS_OS_ZOS)
|
452 kumpf 1.104 # if defined(PEGASUS_ZOS_SECURITY)
453 if (!hasProgramControl(fileName))
454 {
455 PEG_METHOD_EXIT();
456 return 0;
457 }
458 # endif
|
459 kumpf 1.40 PEG_METHOD_EXIT();
|
460 kumpf 1.104 return DynamicLibraryHandle(dllload(fileName));
|
461 chuck 1.44 #elif defined(PEGASUS_OS_OS400)
462 PEG_METHOD_EXIT();
|
463 chuck 1.57 return DynamicLibraryHandle(OS400_LoadDynamicLibrary(fileName));
|
464 mike 1.19 #else
|
465 kumpf 1.40 PEG_METHOD_EXIT();
|
466 konrad.r 1.106 return DynamicLibraryHandle(dlopen(fileName, RTLD_GLOBAL|RTLD_NOW));
|
467 mike 1.21 #endif
|
468 mike 1.20
|
469 mike 1.21 }
|
470 mike 1.20
|
471 mike 1.21 void System::unloadDynamicLibrary(DynamicLibraryHandle libraryHandle)
472 {
|
473 kumpf 1.115 // ATTN: Should this method indicate success/failure?
474 #if defined(PEGASUS_OS_LINUX) || defined(PEGASUS_OS_SOLARIS) || defined(PEGASUS_OS_DARWIN)
475 dlclose(libraryHandle);
476 #endif
477
478 #ifdef PEGASUS_OS_HPUX
479 // Note: shl_unload will unload the library even if it has been loaded
480 // multiple times. No reference count is kept.
481 int ignored = shl_unload(reinterpret_cast<shl_t>(libraryHandle));
482 #endif
483
|
484 chuck 1.57 #ifdef PEGASUS_OS_OS400
485 OS400_UnloadDynamicLibrary((int)libraryHandle);
|
486 kumpf 1.115 #endif
487
488 #ifdef PEGASUS_OS_AIX
489 dlclose(libraryHandle);
490 #endif
491
492 #ifdef PEGASUS_OS_ZOS
|
493 mateus.baur 1.114 dllfree(reinterpret_cast<dllhandle *> (libraryHandle));
|
494 kv.le 1.64 #endif
|
495 mike 1.19 }
496
497 String System::dynamicLoadError() {
|
498 mike 1.21 // ATTN: Is this safe in a multi-threaded process? Should this string
499 // be returned from loadDynamicLibrary?
|
500 kumpf 1.115 #ifdef PEGASUS_OS_HPUX
501 // If shl_load() returns NULL, errno is set to indicate the error
502 return strerror(errno);
503 #elif defined(PEGASUS_OS_ZOS)
|
504 mike 1.19 return String();
|
505 chuck 1.44 #elif defined(PEGASUS_OS_OS400)
|
506 chuck 1.57 return String(OS400_DynamicLoadError());
|
507 mike 1.19 #else
508 String dlerr = dlerror();
509 return dlerr;
510 #endif
511 }
512
513
514 DynamicSymbolHandle System::loadDynamicSymbol(
515 DynamicLibraryHandle libraryHandle,
516 const char* symbolName)
517 {
|
518 kumpf 1.115 #ifdef PEGASUS_OS_HPUX
519 char* p = (char*)symbolName;
520 void* proc = 0;
|
521 mike 1.19
|
522 kumpf 1.115 if (shl_findsym((shl_t*)&libraryHandle, symbolName, TYPE_UNDEFINED,
523 &proc) == 0)
524 {
525 return DynamicSymbolHandle(proc);
526 }
527
528 if (shl_findsym((shl_t*)libraryHandle,
529 (String("_") + symbolName).getCString(),
530 TYPE_UNDEFINED,
531 &proc) == 0)
532 {
533 return DynamicSymbolHandle(proc);
534 }
535
536 return 0;
537
538 #elif defined(PEGASUS_OS_ZOS)
|
539 mike 1.21 return DynamicSymbolHandle(dllqueryfn((dllhandle *)libraryHandle,
540 (char*)symbolName));
|
541 chuck 1.44
542 #elif defined(PEGASUS_OS_OS400)
|
543 chuck 1.57 return DynamicSymbolHandle(OS400_LoadDynamicSymbol((int)libraryHandle,
544 symbolName));
|
545 mike 1.19 #else
546
|
547 chuck 1.57 return DynamicSymbolHandle(dlsym(libraryHandle,(char *) symbolName));
|
548 mike 1.19
549 #endif
550 }
551
552 String System::getHostName()
553 {
|
554 kumpf 1.110 static char hostname[PEGASUS_MAXHOSTNAMELEN + 1];
|
555 mike 1.19
556 if (!*hostname)
|
557 david 1.63 {
|
558 mike 1.19 gethostname(hostname, sizeof(hostname));
|
559 kumpf 1.110 hostname[sizeof(hostname)-1] = 0;
|
560 david 1.63 #if defined(PEGASUS_OS_OS400)
|
561 kumpf 1.104 EtoA(hostname);
|
562 david 1.63 #endif
563 }
|
564 mike 1.19
565 return hostname;
|
566 kumpf 1.24 }
567
|
568 kumpf 1.30 String System::getFullyQualifiedHostName ()
569 {
|
570 chuck 1.102 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_AIX) || defined(PEGASUS_OS_LINUX) || defined(PEGASUS_OS_OS400)
|
571 kumpf 1.110 char hostName[PEGASUS_MAXHOSTNAMELEN + 1];
|
572 kumpf 1.30 struct hostent *he;
573 String fqName;
574
|
575 kumpf 1.110 if (gethostname(hostName, sizeof(hostName)) != 0)
|
576 kumpf 1.30 {
577 return String::EMPTY;
578 }
|
579 kumpf 1.110 hostName[sizeof(hostName)-1] = 0;
|
580 kumpf 1.30
|
581 kumpf 1.90 if ((he = gethostbyname (hostName)))
|
582 kumpf 1.30 {
|
583 kumpf 1.111 strncpy(hostName, he->h_name, sizeof(hostName)-1);
|
584 kumpf 1.30 }
585
|
586 chuck 1.102 #if defined(PEGASUS_OS_OS400)
587 EtoA(hostName);
588 #endif
589
|
590 kumpf 1.30 fqName.assign (hostName);
591
592 return fqName;
|
593 marek 1.78 #elif defined(PEGASUS_OS_ZOS)
|
594 kumpf 1.110 char hostName[PEGASUS_MAXHOSTNAMELEN + 1];
|
595 kumpf 1.104 String fqName;
|
596 marek 1.113 struct addrinfo *resolv;
597 struct addrinfo hint;
598 struct hostent *he;
|
599 kumpf 1.104 // receive short name of the local host
|
600 marek 1.113 if (gethostname(hostName, PEGASUS_MAXHOSTNAMELEN) != 0)
|
601 kumpf 1.104 {
602 return String::EMPTY;
603 }
|
604 marek 1.113 resolv = new struct addrinfo;
605 hint.ai_flags = AI_CANONNAME;
606 hint.ai_family = AF_UNSPEC; // any family
607 hint.ai_socktype = 0; // any socket type
608 hint.ai_protocol = 0; // any protocol
609 int success = getaddrinfo(hostName,
610 NULL,
611 &hint,
612 &resolv);
613 if (success==0)
614 {
615 // assign fully qualified hostname
616 fqName.assign(resolv->ai_canonname);
617 } else
|
618 kumpf 1.104 {
|
619 marek 1.113 if ((he = gethostbyname(hostName)))
620 {
621 strcpy (hostName, he->h_name);
622 }
623 // assign hostName
624 // if gethostbyname was successful assign that result
625 // else assign unqualified hostname
626 fqName.assign(hostName);
|
627 kumpf 1.104 }
|
628 marek 1.113 freeaddrinfo(resolv);
629 delete resolv;
|
630 marek 1.78
|
631 kumpf 1.104 return fqName;
|
632 kumpf 1.30 #else
633 //
634 // ATTN: Implement this method to return the fully qualified host name
635 //
636 return String::EMPTY;
637 #endif
638 }
639
640 String System::getSystemCreationClassName ()
641 {
|
642 carolann.graves 1.91 //
643 // The value returned should match the value of the CreationClassName key
644 // property used in the instrumentation of the CIM_ComputerSystem class
645 // as determined by the provider for the CIM_ComputerSystem class
646 //
|
647 kumpf 1.30 return "CIM_ComputerSystem";
648 }
649
|
650 kumpf 1.24 Uint32 System::lookupPort(
|
651 kumpf 1.104 const char * serviceName,
|
652 kumpf 1.24 Uint32 defaultPort)
653 {
654 Uint32 localPort;
655
656 struct servent *serv;
657
658 //
659 // Get wbem-local port from /etc/services
660 //
|
661 david 1.100
|
662 keith.petley 1.62 #ifdef PEGASUS_OS_SOLARIS
|
663 kumpf 1.104 #define SERV_BUFF_SIZE 1024
664 struct servent serv_result;
665 char buf[SERV_BUFF_SIZE];
|
666 keith.petley 1.62
667 if ( (serv = getservbyname_r(serviceName, TCP, &serv_result,
|
668 kumpf 1.104 buf, SERV_BUFF_SIZE)) != NULL )
|
669 david 1.100 #elif defined(PEGASUS_OS_OS400)
|
670 kumpf 1.104 struct servent serv_result;
|
671 david 1.100 serv = &serv_result;
|
672 kumpf 1.104 struct servent_data buf;
|
673 david 1.100 memset(&buf, 0x00, sizeof(struct servent_data));
674
|
675 chuck 1.102 char srvnameEbcdic[256];
676 strcpy(srvnameEbcdic, serviceName);
677 AtoE(srvnameEbcdic);
678
679 char tcpEbcdic[64];
680 strcpy(tcpEbcdic, TCP);
681 AtoE(tcpEbcdic);
682
683 if ( (getservbyname_r(srvnameEbcdic, tcpEbcdic, &serv_result,
|
684 kumpf 1.104 &buf)) == 0 )
|
685 keith.petley 1.62 #else // PEGASUS_OS_SOLARIS
|
686 kumpf 1.37 if ( (serv = getservbyname(serviceName, TCP)) != NULL )
|
687 keith.petley 1.62 #endif // PEGASUS_OS_SOLARIS
|
688 kumpf 1.24 {
|
689 sage 1.43 localPort = htons((uint16_t)serv->s_port);
|
690 kumpf 1.24 }
691 else
692 {
693 localPort = defaultPort;
694 }
695
696 return localPort;
|
697 mike 1.19 }
|
698 konrad.r 1.86 #if defined(PEGASUS_OS_LSB)
699 /*
|
700 kumpf 1.104 getpass equivalent.
|
701 konrad.r 1.86 Adapted from example implementation described in GLIBC documentation
|
702 kumpf 1.104 (http://www.dusek.ch/manual/glibc/libc_32.html) and
|
703 konrad.r 1.86 "Advanced Programming in the UNIX Environment" by Richard Stevens,
704 pg. 350.
|
705 kumpf 1.104
|
706 konrad.r 1.86 */
707 #define MAX_PASS_LEN 1024
708 char *getpassword(const char *prompt)
709 {
710 static char buf[MAX_PASS_LEN];
711 struct termios old, new_val;
712 char *ptr;
713 int c;
714
715 buf[0] = 0;
716
717 /* Turn echoing off and fail if we can't. */
718 if (tcgetattr (fileno (stdin), &old) != 0)
719 return buf;
720 new_val = old;
721 new_val.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
722 if (tcsetattr (fileno (stdin), TCSAFLUSH, &new_val) != 0)
723 return buf;
|
724 kumpf 1.104
|
725 konrad.r 1.86 /* Read the password. */
726 fputs (prompt, stdin);
727 ptr = buf;
728 while ( (c = getc(stdin)) != EOF && c != '\n') {
729 if (ptr < &buf[MAX_PASS_LEN])
730 *ptr++ = c;
731 }
732 *ptr = 0;
733 putc('\n', stdin);
734
735 /* Restore terminal. */
736 (void) tcsetattr (fileno (stdin), TCSAFLUSH, &old);
737 fclose(stdin);
738 return buf;
739 }
740 #endif
|
741 mike 1.19
|
742 mike 1.21 String System::getPassword(const char* prompt)
743 {
744
745 String password;
746
|
747 chuck 1.44 #if !defined(PEGASUS_OS_OS400)
748 // Not supported on OS/400, and we don't need it.
|
749 konrad.r 1.86 // 'getpass' is DEPRECATED
|
750 kumpf 1.104 # if !defined(PEGASUS_OS_LSB)
|
751 mike 1.21 password = String(getpass( prompt ));
|
752 kumpf 1.104 # else
|
753 konrad.r 1.86 password = String(getpassword( prompt ));
|
754 kumpf 1.104 # endif
|
755 konrad.r 1.86
|
756 chuck 1.44 #endif
|
757 mike 1.21
758 return password;
759 }
760
|
761 kumpf 1.38 String System::getEffectiveUserName()
|
762 mike 1.21 {
763 String userName = String::EMPTY;
764 struct passwd* pwd = NULL;
765
|
766 kumpf 1.66 #if defined(PEGASUS_OS_SOLARIS) || \
767 defined(PEGASUS_OS_HPUX) || \
|
768 david 1.100 defined(PEGASUS_OS_LINUX) || \
769 defined(PEGASUS_OS_OS400)
|
770 kumpf 1.66
771 const unsigned int PWD_BUFF_SIZE = 1024;
|
772 kumpf 1.79 struct passwd local_pwd;
773 char buf[PWD_BUFF_SIZE];
774
775 if(getpwuid_r(geteuid(), &local_pwd, buf, PWD_BUFF_SIZE, &pwd) != 0)
776 {
777 String errorMsg = String("getpwuid_r failure : ") +
778 String(strerror(errno));
|
779 kumpf 1.97 PEG_TRACE_STRING(TRC_OS_ABSTRACTION, Tracer::LEVEL2, errorMsg);
|
780 kumpf 1.79 // L10N TODO - This message needs to be added.
781 //Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
782 // errorMsg);
|
783 keith.petley 1.62 }
|
784 marek 1.113 #elif defined(PEGASUS_OS_ZOS)
785 char effective_username[9];
786 __getuserid(effective_username, 9);
787 __etoa_l(effective_username,9);
788 userName.assign(effective_username);
789 return userName;
|
790 keith.petley 1.62 #else
|
791 mike 1.21 //
792 // get the currently logged in user's UID.
793 //
|
794 kumpf 1.38 pwd = getpwuid(geteuid());
|
795 keith.petley 1.62 #endif
|
796 mike 1.21 if ( pwd == NULL )
797 {
|
798 kumpf 1.79 // L10N TODO - This message needs to be added.
799 //Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
800 // "getpwuid_r failure, user may have been removed just after login");
801 Tracer::trace (TRC_OS_ABSTRACTION, Tracer::LEVEL4,
802 "getpwuid_r failure, user may have been removed just after login");
|
803 mike 1.21 }
804 else
805 {
|
806 chuck 1.65 #if defined(PEGASUS_OS_OS400)
|
807 kumpf 1.79 EtoA(pwd->pw_name);
|
808 chuck 1.65 #endif
|
809 mike 1.21 //
810 // get the user name
811 //
812 userName.assign(pwd->pw_name);
813 }
814
815 return(userName);
816 }
817
818 String System::encryptPassword(const char* password, const char* salt)
819 {
|
820 chuck 1.44 #if !defined(PEGASUS_OS_OS400)
|
821 mike 1.21 return ( String(crypt( password,salt)) );
|
822 chuck 1.44 #else
823 // Not supported on OS400, and we don't need it.
824 return ( String(password) );
825 #endif
|
826 mike 1.21 }
827
|
828 kumpf 1.47 Boolean System::isSystemUser(const char* userName)
|
829 mike 1.21 {
|
830 chuck 1.65 #if defined(PEGASUS_OS_OS400)
831 AtoE((char *)userName);
832 #endif
833
|
834 kumpf 1.66 #if defined(PEGASUS_OS_SOLARIS) || \
835 defined(PEGASUS_OS_HPUX) || \
|
836 david 1.100 defined(PEGASUS_OS_LINUX) || \
837 defined(PEGASUS_OS_OS400)
|
838 kumpf 1.66
839 const unsigned int PWD_BUFF_SIZE = 1024;
|
840 keith.petley 1.62 struct passwd pwd;
841 struct passwd *result;
|
842 kumpf 1.66 char pwdBuffer[PWD_BUFF_SIZE];
|
843 keith.petley 1.62
|
844 kumpf 1.66 if (getpwnam_r(userName, &pwd, pwdBuffer, PWD_BUFF_SIZE, &result) != 0)
|
845 kumpf 1.79 {
846 String errorMsg = String("getpwnam_r failure : ") +
847 String(strerror(errno));
|
848 kumpf 1.97 PEG_TRACE_STRING(TRC_OS_ABSTRACTION, Tracer::LEVEL2, errorMsg);
|
849 kumpf 1.79 // L10N TODO - This message needs to be added.
850 //Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
851 // errorMsg);
852 }
853 if (result == NULL)
854 {
855 return false;
856 }
|
857 keith.petley 1.62 #else
|
858 mike 1.21 //
859 // get the password entry for the user
860 //
861 if ( getpwnam(userName) == NULL )
862 {
|
863 chuck 1.65 #if defined(PEGASUS_OS_OS400)
|
864 kumpf 1.79 EtoA((char *)userName);
|
865 chuck 1.65 #endif
|
866 kumpf 1.79 return false;
|
867 mike 1.21 }
|
868 kumpf 1.79 #endif
|
869 chuck 1.65 #if defined(PEGASUS_OS_OS400)
870 EtoA((char *)userName);
871 #endif
|
872 kumpf 1.79
|
873 mike 1.21 return true;
874 }
875
|
876 david.dillard 1.93 Boolean System::isPrivilegedUser(const String& userName)
|
877 mike 1.21 {
878 //
|
879 kumpf 1.38 // Check if the given user is a privileged user
|
880 mike 1.21 //
|
881 chuck 1.51 #if !defined(PEGASUS_OS_OS400)
|
882 kumpf 1.38 struct passwd pwd;
883 struct passwd *result;
|
884 kumpf 1.79 const unsigned int PWD_BUFF_SIZE = 1024;
885 char pwdBuffer[PWD_BUFF_SIZE];
886
887 if (getpwnam_r(
888 userName.getCString(), &pwd, pwdBuffer, PWD_BUFF_SIZE, &result) != 0)
889 {
890 String errorMsg = String("getpwnam_r failure : ") +
891 String(strerror(errno));
|
892 kumpf 1.97 PEG_TRACE_STRING(TRC_OS_ABSTRACTION, Tracer::LEVEL2, errorMsg);
|
893 kumpf 1.79 // L10N TODO - This message needs to be added.
894 //Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
895 // errorMsg);
896 }
|
897 kumpf 1.25
|
898 kumpf 1.79 // Check if the requested entry was found. If not return false.
899 if ( result != NULL )
|
900 kumpf 1.25 {
|
901 kumpf 1.79 // Check if the uid is 0.
|
902 kumpf 1.38 if ( pwd.pw_uid == 0 )
|
903 kumpf 1.25 {
|
904 kumpf 1.38 return true;
|
905 kumpf 1.25 }
|
906 mike 1.21 }
|
907 kumpf 1.38 return false;
|
908 kumpf 1.79
|
909 chuck 1.51 #else
|
910 chuck 1.65 CString user = userName.getCString();
911 const char * tmp = (const char *)user;
912 AtoE((char *)tmp);
913 return ycmCheckUserCmdAuthorities(tmp);
|
914 chuck 1.51 #endif
|
915 kumpf 1.79
|
916 kumpf 1.26 }
917
918 String System::getPrivilegedUserName()
919 {
920 static String userName = String::EMPTY;
921
922 if (userName == String::EMPTY)
923 {
924 struct passwd* pwd = NULL;
|
925 kumpf 1.66 #if defined(PEGASUS_OS_SOLARIS) || \
926 defined(PEGASUS_OS_HPUX) || \
|
927 david 1.100 defined(PEGASUS_OS_LINUX) || \
928 defined(PEGASUS_OS_OS400)
|
929 kumpf 1.66 const unsigned int PWD_BUFF_SIZE = 1024;
|
930 kumpf 1.79 struct passwd local_pwd;
931 char buf[PWD_BUFF_SIZE];
932
933 if(getpwuid_r(0, &local_pwd, buf, PWD_BUFF_SIZE, &pwd) != 0)
934 {
935 String errorMsg = String("getpwuid_r failure : ") +
936 String(strerror(errno));
|
937 kumpf 1.97 PEG_TRACE_STRING(TRC_OS_ABSTRACTION, Tracer::LEVEL2, errorMsg);
|
938 kumpf 1.79 // L10N TODO - This message needs to be added.
939 //Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
940 // errorMsg);
941 }
|
942 keith.petley 1.62 #else
|
943 kumpf 1.26 //
944 // get the privileged user's UID.
945 //
|
946 kumpf 1.79 // (on OS/400, this is QSECOFR)
|
947 kumpf 1.26 pwd = getpwuid(0);
|
948 keith.petley 1.62 #endif
|
949 kumpf 1.26 if ( pwd != NULL )
950 {
|
951 chuck 1.65 #if defined(PEGASUS_OS_OS400)
|
952 kumpf 1.79 EtoA(pwd->pw_name);
|
953 chuck 1.65 #endif
|
954 kumpf 1.26 //
955 // get the user name
956 //
957 userName.assign(pwd->pw_name);
958 }
959 else
960 {
|
961 kumpf 1.79 Tracer::trace (TRC_OS_ABSTRACTION, Tracer::LEVEL4,
962 "Could not find entry.");
|
963 kumpf 1.26 PEGASUS_ASSERT(0);
964 }
965 }
966
967 return (userName);
|
968 mike 1.21 }
|
969 kumpf 1.22
|
970 kumpf 1.81 Boolean System::isGroupMember(const char* userName, const char* groupName)
971 {
972 struct group grp;
973 char *member;
974 Boolean retVal = false;
975 const unsigned int PWD_BUFF_SIZE = 1024;
976 const unsigned int GRP_BUFF_SIZE = 1024;
977 struct passwd pwd;
978 struct passwd *result;
979 struct group *grpresult;
980 char pwdBuffer[PWD_BUFF_SIZE];
981 char grpBuffer[GRP_BUFF_SIZE];
982
983 //
984 // Search Primary group information.
985 //
986
987 // Find the entry that matches "userName"
988
989 if (getpwnam_r(userName, &pwd, pwdBuffer, PWD_BUFF_SIZE, &result) != 0)
990 {
991 kumpf 1.81 String errorMsg = String("getpwnam_r failure : ") +
992 String(strerror(errno));
|
993 kumpf 1.97 PEG_TRACE_STRING(TRC_OS_ABSTRACTION, Tracer::LEVEL2, errorMsg);
|
994 kumpf 1.81 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
995 errorMsg);
996 throw InternalSystemError();
997 }
998
999 if ( result != NULL )
1000 {
1001 // User found, check for group information.
1002 gid_t group_id;
1003 group_id = pwd.pw_gid;
1004
1005 // Get the group name using group_id and compare with group passed.
1006 if ( getgrgid_r(group_id, &grp,
1007 grpBuffer, GRP_BUFF_SIZE, &grpresult) != 0)
1008 {
1009 String errorMsg = String("getgrgid_r failure : ") +
1010 String(strerror(errno));
|
1011 kumpf 1.97 PEG_TRACE_STRING(TRC_OS_ABSTRACTION, Tracer::LEVEL2, errorMsg);
|
1012 kumpf 1.81 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
1013 errorMsg);
1014 throw InternalSystemError();
1015 }
1016
1017 // Compare the user's group name to groupName.
1018 if ( strcmp (grp.gr_name, groupName) == 0 )
1019 {
1020 // User is a member of the group.
1021 return true;
1022 }
1023 }
1024
1025 //
1026 // Search supplemental groups.
1027 // Get a user group entry
1028 //
|
1029 konrad.r 1.86 #if defined(PEGASUS_OS_LSB)
1030 if ( getgrnam_r((char *)groupName, &grp,
1031 grpBuffer, GRP_BUFF_SIZE, &grpresult) != 0 )
1032 #else
|
1033 kumpf 1.81 if ( getgrnam_r(groupName, &grp,
1034 grpBuffer, GRP_BUFF_SIZE, &grpresult) != 0 )
|
1035 konrad.r 1.86
1036 #endif
|
1037 kumpf 1.81 {
1038 String errorMsg = String("getgrnam_r failure : ") +
1039 String(strerror(errno));
|
1040 kumpf 1.97 PEG_TRACE_STRING(TRC_OS_ABSTRACTION, Tracer::LEVEL2, errorMsg);
|
1041 kumpf 1.81 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
1042 errorMsg);
1043 throw InternalSystemError();
1044 }
1045
1046 // Check if the requested group was found.
1047 if (grpresult == NULL)
1048 {
1049 return false;
1050 }
1051
1052 Uint32 j = 0;
1053
1054 //
1055 // Get all the members of the group
1056 //
1057 member = grp.gr_mem[j++];
1058
1059 while (member)
1060 {
1061 //
1062 kumpf 1.81 // Check if the user is a member of the group
1063 //
1064 if ( strcmp(userName, member) == 0 )
1065 {
1066 retVal = true;
1067 break;
1068 }
1069 member = grp.gr_mem[j++];
1070 }
1071
1072 return retVal;
1073 }
|
1074 humberto 1.99 #ifndef PEGASUS_OS_OS400
|
1075 kumpf 1.94 Boolean System::changeUserContext(const char* userName)
1076 {
1077 const unsigned int PWD_BUFF_SIZE = 1024;
1078 struct passwd pwd;
1079 struct passwd *result;
1080 char pwdBuffer[PWD_BUFF_SIZE];
1081
1082 # if defined(PEGASUS_OS_OS400)
1083 AtoE((char *)userName);
1084 # endif
1085
1086 int rc = getpwnam_r(userName, &pwd, pwdBuffer, PWD_BUFF_SIZE, &result);
1087
1088 # if defined(PEGASUS_OS_OS400)
1089 EtoA((char *)userName);
1090 # endif
1091
1092 if (rc != 0)
1093 {
1094 PEG_TRACE_STRING(TRC_OS_ABSTRACTION, Tracer::LEVEL2,
1095 String("getpwnam_r failed: ") + String(strerror(errno)));
1096 kumpf 1.94 return false;
1097 }
1098
1099 if (result == 0)
1100 {
|
1101 kumpf 1.97 PEG_TRACE_STRING(TRC_OS_ABSTRACTION, Tracer::LEVEL2,
|
1102 kumpf 1.94 "getpwnam_r failed.");
1103 return false;
1104 }
1105
|
1106 kumpf 1.104 Tracer::trace(TRC_OS_ABSTRACTION, Tracer::LEVEL4,
|
1107 kumpf 1.94 "Changing user context to: uid = %d, gid = %d",
1108 (int)pwd.pw_uid, (int)pwd.pw_gid);
1109
1110 if (setgid(pwd.pw_gid) != 0)
1111 {
1112 PEG_TRACE_STRING(TRC_OS_ABSTRACTION, Tracer::LEVEL2,
1113 String("setgid failed: ") + String(strerror(errno)));
1114 return false;
1115 }
1116
1117 if (setuid(pwd.pw_uid) != 0)
1118 {
1119 PEG_TRACE_STRING(TRC_OS_ABSTRACTION, Tracer::LEVEL2,
1120 String("setuid failed: ") + String(strerror(errno)));
1121 return false;
1122 }
1123
1124 return true;
1125 }
|
1126 humberto 1.99 #endif
|
1127 kumpf 1.22 Uint32 System::getPID()
1128 {
1129 //
1130 // Get the Process ID
1131 //
1132 Uint32 pid = getpid();
1133
1134 return pid;
1135 }
|
1136 mike 1.28
1137 Boolean System::truncateFile(
|
1138 kumpf 1.104 const char* path,
|
1139 mike 1.28 size_t newSize)
1140 {
|
1141 chuck 1.44 #if !defined(PEGASUS_OS_OS400)
|
1142 kumpf 1.29 return (truncate(path, newSize) == 0);
|
1143 chuck 1.44 #else
|
1144 chuck 1.65 OS400_PNSTRUCT pathname;
1145 memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
1146 pathname.qlg_struct.CCSID = 1208;
1147 #pragma convert(37)
1148 memcpy(pathname.qlg_struct.Country_ID,"US",2);
1149 memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
1150 #pragma convert(0)
1151 pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
1152 pathname.qlg_struct.Path_Length = strlen(path);
1153 pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
1154 pathname.pn = (char *)path;
1155
1156 int fd = QlgOpen((Qlg_Path_Name_T *)&pathname, O_WRONLY);
|
1157 chuck 1.44 if (fd != -1)
1158 {
1159 int rc = ftruncate(fd, newSize);
1160 close(fd);
1161 return (rc == 0);
1162 }
|
1163 kumpf 1.104
|
1164 chuck 1.44 return false;
1165 #endif
|
1166 mike 1.28 }
|
1167 tony 1.52
1168 // Is absolute path?
1169 Boolean System::is_absolute_path(const char *path)
1170 {
1171 if (path == NULL)
1172 return false;
|
1173 kumpf 1.104
|
1174 tony 1.52 if (path[0] == '/')
1175 return true;
|
1176 kumpf 1.104
|
1177 tony 1.52 return false;
1178 }
|
1179 david 1.54
|
1180 kumpf 1.72 // Changes file permissions on the given file.
1181 Boolean System::changeFilePermissions(const char* path, mode_t mode)
1182 {
1183 Sint32 ret = 0;
1184
1185 const char * tmp = path;
1186
1187 #if defined(PEGASUS_OS_OS400)
1188 // ATTN: Update this code to handle UTF8 when path contains UTF8
1189 AtoE((char *)tmp);
1190 #endif
1191
1192 ret = ::chmod(tmp, mode);
1193
1194 return ( ret != -1 );
1195 }
1196
|
1197 kumpf 1.94 Boolean System::verifyFileOwnership(const char* path)
1198 {
1199 struct stat st;
1200
1201 #if defined(PEGASUS_OS_OS400)
1202 OS400_PNSTRUCT pathname;
1203 memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
1204 pathname.qlg_struct.CCSID = 1208;
1205 #pragma convert(37)
1206 memcpy(pathname.qlg_struct.Country_ID,"US",2);
1207 memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
1208 #pragma convert(0)
1209 pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
1210 pathname.qlg_struct.Path_Length = strlen(path);
1211 pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
1212 pathname.pn = (char *)path;
1213
1214 if (QlgStat((Qlg_Path_Name_T *)&pathname, &st) != 0)
1215 {
|
1216 kumpf 1.104 return false;
|
1217 kumpf 1.94 }
1218 #else
|
1219 kumpf 1.109 if (lstat(path, &st) != 0)
|
1220 kumpf 1.94 {
1221 return false;
1222 }
1223 #endif
1224
|
1225 kumpf 1.108 return ((st.st_uid == geteuid()) && // Verify the file owner
1226 S_ISREG(st.st_mode) && // Verify it is a regular file
1227 (st.st_nlink == 1)); // Verify it is not a hard link
|
1228 kumpf 1.94 }
1229
|
1230 kumpf 1.104 void System::syslog(const String& ident, Uint32 severity, const char* message)
|
1231 david 1.54 {
|
1232 kumpf 1.104 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX)
1233
1234 // Since the openlog(), syslog(), and closelog() function calls must be
1235 // coordinated (see below), we need a thread control.
1236
1237 static Mutex logMutex;
1238
1239 AutoMutex loglock(logMutex);
|
1240 david 1.54
|
1241 kumpf 1.104 // Get a const char* representation of the identifier string. Note: The
1242 // character string passed to the openlog() function must persist until
1243 // closelog() is called. The syslog() method uses this pointer directly
1244 // rather than a copy of the string it refers to.
1245
1246 CString identCString = ident.getCString();
1247 openlog(identCString, LOG_PID, LOG_DAEMON);
|
1248 david 1.54
|
1249 kumpf 1.104 // Map from the Logger log level to the system log level.
|
1250 david 1.54
|
1251 kumpf 1.104 Uint32 syslogLevel;
1252 if (severity & Logger::FATAL)
1253 {
1254 syslogLevel = LOG_CRIT;
1255 }
1256 else if (severity & Logger::SEVERE)
1257 {
1258 syslogLevel = LOG_ERR;
1259 }
1260 else if (severity & Logger::WARNING)
1261 {
1262 syslogLevel = LOG_WARNING;
1263 }
1264 else if (severity & Logger::INFORMATION)
1265 {
1266 syslogLevel = LOG_INFO;
1267 }
1268 else // if (severity & Logger::TRACE)
1269 {
1270 syslogLevel = LOG_DEBUG;
1271 }
|
1272 david 1.54
|
1273 kumpf 1.104 // Write the message to the system log.
|
1274 david 1.54
|
1275 kumpf 1.104 ::syslog(syslogLevel, "%s", message);
|
1276 david 1.54
|
1277 kumpf 1.104 closelog();
|
1278 david 1.54
1279 #elif defined(PEGASUS_OS_OS400)
1280
|
1281 kumpf 1.104 std::string replacementData = message;
|
1282 david 1.54 // All messages will go to the joblog. In the future
1283 // some messages may go to other message queues yet
1284 // to be determined.
1285 if ((severity & Logger::TRACE) ||
|
1286 kumpf 1.104 (severity & Logger::INFORMATION))
|
1287 david 1.54 {
1288
|
1289 kumpf 1.104 // turn into ycmMessage so we can put it in the job log
1290 # pragma convert(37)
1291 ycmMessage theMessage("CPIDF80",
1292 message,
1293 strlen(message),
1294 "Logger",
|
1295 david 1.67 ycmCTLCIMID,
|
1296 kumpf 1.104 TRUE);
1297 # pragma convert(0)
|
1298 david 1.54
|
1299 kumpf 1.104 // put the message in the joblog
1300 theMessage.joblogIt(UnitOfWorkError,
1301 ycmMessage::Informational);
|
1302 david 1.54 }
1303
1304 if ((severity & Logger::WARNING) ||
|
1305 kumpf 1.104 (severity & Logger::SEVERE) ||
1306 (severity & Logger::FATAL))
|
1307 david 1.54 {
|
1308 kumpf 1.104 // turn into ycmMessage so we can put it in the job log
1309 # pragma convert(37)
1310 ycmMessage theMessage("CPDDF82",
1311 message,
1312 strlen(message),
1313 "Logger",
|
1314 david 1.67 ycmCTLCIMID,
|
1315 kumpf 1.104 TRUE);
1316 # pragma convert(0)
1317 // put the message in the joblog
1318 theMessage.joblogIt(UnitOfWorkError,
1319 ycmMessage::Diagnostic);
|
1320 david 1.54 }
1321
1322 #endif
1323 }
1324
1325 // System ID constants for Logger::put and Logger::trace
1326 #if defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM)
1327 const String System::CIMSERVER = "qycmcimom"; // Server system ID
1328 #else
1329 const String System::CIMSERVER = "cimserver"; // Server system ID
1330 #endif
|
1331 kumpf 1.104
|
1332 david.dillard 1.107
1333
1334
1335 //
1336 // System Initializater for AIX
1337 //
1338 #ifdef PEGASUS_OS_AIX
1339 #include <cstdlib>
1340
1341 class SystemInitializer
1342 {
1343
1344 public:
1345 /**
1346 *
1347 * Default constructor.
1348 *
1349 */
1350 SystemInitializer();
1351 };
1352
1353 david.dillard 1.107
1354
1355 SystemInitializer::SystemInitializer()
1356 {
1357 putenv("XPG_SUS_ENV=ON");
1358 }
1359
1360 static SystemInitializer initializer;
1361
1362 #endif
1363
|
1364 mike 1.19 PEGASUS_NAMESPACE_END
|