1 karl 1.49 //%2005////////////////////////////////////////////////////////////////////////
|
2 mike 1.13 //
|
3 karl 1.45 // 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.35 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.45 // 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.49 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 mike 1.13 //
12 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
13 mike 1.14 // 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.13 // 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.45 //
|
19 mike 1.14 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
20 mike 1.13 // 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.14 // 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.13 // 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 kumpf 1.53 // Modified By: Nag Boranna, Hewlett-Packard Company (nagaraja_boranna@hp.com)
33 // Dave Rosckes (rosckes@us.ibm.com)
|
34 r.kieninger 1.44 // Robert Kieninger, IBM (kieningr@de.ibm.com) for Bug#667
|
35 david.dillard 1.46 // David Dillard, VERITAS Software Corp.
36 // (david.dillard@veritas.com)
|
37 gs.keenan 1.50 // Sean Keenan, Hewlett-Packard Company (sean.keenan@hp.com)
|
38 kumpf 1.53 // Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
|
39 david 1.32 //
|
40 mike 1.13 //%/////////////////////////////////////////////////////////////////////////////
41
42 #ifndef Pegasus_System_h
43 #define Pegasus_System_h
44
45 #include <Pegasus/Common/Config.h>
46 #include <Pegasus/Common/String.h>
|
47 kumpf 1.26 #include <Pegasus/Common/Linkage.h>
|
48 david 1.32 #include <Pegasus/Common/Logger.h>
|
49 kumpf 1.36 #include <sys/stat.h>
|
50 mike 1.13
|
51 kumpf 1.37
|
52 kumpf 1.38 #if defined(PEGASUS_OS_TYPE_WINDOWS)
|
53 kumpf 1.37 #ifndef mode_t
|
54 kumpf 1.38 typedef unsigned long mode_t;
|
55 kumpf 1.37 #endif
56 #endif
57
|
58 konrad.r 1.41
|
59 kumpf 1.17 //
60 // Protocal Type
61 //
62 #define TCP "tcp"
63
|
64 mike 1.13 PEGASUS_NAMESPACE_BEGIN
65
|
66 kumpf 1.23
|
67 mike 1.13 /** This is an opaque type which is used to represent dynamic library
68 handles returned by the System::loadDynamicLibrary() method and
69 accepted by the System::loadDynamicProcedure() method.
70 */
71 typedef struct DynamicLibraryHandle_* DynamicLibraryHandle;
72
73 /** This is an opaque type which is returned by System::loadDynamicSymbol().
74 Values of this type may be casted to the appropriate target type.
75 */
|
76 kv.le 1.43 #if !defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) && !defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM) && !defined(PEGASUS_PLATFORM_AIX_RS_IBMCXX)
|
77 r.kieninger 1.44 typedef struct DynamicSymbolHandle_* DynamicSymbolHandle;
78 #else
79 extern "C" {typedef int (* DynamicSymbolHandle)(void);}
80 #endif
|
81 sage 1.20
|
82 mike 1.14
|
83 david 1.32
|
84 mike 1.13 /** The System class defines wrappers for operating system related calls.
85 These are only placed here if they are extremely light. These are
86 usually just direct wrappers which map more or less one to one to the
87 underlying function.
88 */
89 class PEGASUS_COMMON_LINKAGE System
90 {
91 public:
92 /** getCurrentTime - Gets the current time as seconds and milliseconds
93 into the provided variables using system functions.
94 @param seconds Return for the seconds component of the time.
95 @param milliseconds Return for the milliseconds component of the time.
96 @return The value is returned in the parameters.
97 The time returned is as defined in number of seconds and milliseconds
98 since 00:00 Coordinated Universal Time (UTC), January 1, 1970,
|
99 mike 1.14
|
100 mike 1.13 */
101 static void getCurrentTime(Uint32& seconds, Uint32& milliseconds);
102
103 /** getCurrentASCIITime Gets time/date in a fixed format. The format is
104 YY MM DD-HH:MM:SS
105 @return Returns String with the ASCII time date.
106 */
107 static String getCurrentASCIITime();
108
109 static void sleep(Uint32 seconds);
110
111 static Boolean exists(const char* path);
112
113 static Boolean canRead(const char* path);
114
115 static Boolean canWrite(const char* path);
116
117 static Boolean getCurrentDirectory(char* path, Uint32 size);
118
119 static Boolean isDirectory(const char* path);
120
121 mike 1.13 static Boolean changeDirectory(const char* path);
122
123 static Boolean makeDirectory(const char* path);
124
125 static Boolean getFileSize(const char* path, Uint32& size);
126
127 static Boolean removeDirectory(const char* path);
128
129 static Boolean removeFile(const char* path);
130
131 static Boolean renameFile(const char* oldPath, const char* newPath);
132
|
133 mike 1.21 static Boolean copyFile(const char* fromPath, const char* toPath);
134
|
135 konrad.r 1.54 /** Unix issue:<br><br><b>RTLD_<blah></b> issue. Currently Pegasus uses RTLD_GLOBAL during
136 loading of the library if supported by OS. Previous to 2.2, Pegasus used RTLD_GLOBAL on Linux. In between 2.3 and 2.4, it used RTDL_NOW. In 2.5 it is using RTLD_GLOBAL. Please consult doc/ProviderLoading.txt for more information.
|
137 konrad.r 1.33 */
|
138 mike 1.13 static DynamicLibraryHandle loadDynamicLibrary(const char* fileName);
139
|
140 mike 1.15 static void unloadDynamicLibrary(DynamicLibraryHandle libraryHandle);
|
141 mike 1.14
|
142 mike 1.13 static String dynamicLoadError(void);
143
144 static DynamicSymbolHandle loadDynamicSymbol(
145 DynamicLibraryHandle libraryHandle,
146 const char* symbolName);
147
148 static String getHostName();
|
149 kumpf 1.22 static String getFullyQualifiedHostName ();
150 static String getSystemCreationClassName ();
|
151 marek 1.47 static String getHostIP(const String &hostName);
|
152 kumpf 1.17
|
153 r.kieninger 1.44 static Uint32 _acquireIP(const char* hostname);
154
|
155 kumpf 1.17 static Uint32 lookupPort(
156 const char * serviceName,
157 Uint32 defaultPort);
|
158 mike 1.14
|
159 kumpf 1.24 static String getEffectiveUserName();
|
160 mike 1.14
161 /**
162 This function is used to input a password with echo disabled.
163 The function reads up to a newline and returns a password of at most
164 8 characters.
165
166 @param prompt String containing the message prompt to be displayed
167 @return password obtained from the user
168 */
169 static String getPassword(const char* prompt);
170
171 /**
|
172 r.kieninger 1.44 This function is used to encrypt the user's password.
|
173 mike 1.14 The encryption is compatible with Apache's password file (generated using
174 the htpasswd command )
175
176 @param password Password to be encrypted.
177 @param salt Two character string chosen from the set [a-zA-Z0-9./].
178
179 @return Encrypted password.
180 */
181 static String encryptPassword(const char* password, const char* salt);
182
183 /**
|
184 r.kieninger 1.44 This function is used to verify whether specified user is a user
|
185 mike 1.14 on the local system.
186
187 @param userName User name to be verified.
188
189 @return true if the username is valid, else false
190 */
|
191 kumpf 1.28 static Boolean isSystemUser(const char* userName);
|
192 mike 1.14
193 /**
|
194 kumpf 1.24 Checks whether the given user is a privileged user.
|
195 mike 1.14
|
196 kumpf 1.18 @param userName User name to be checked.
197 @return true if the user is a privileged user, else false
|
198 mike 1.14 */
|
199 david.dillard 1.46 static Boolean isPrivilegedUser(const String& userName);
|
200 mike 1.14
|
201 kumpf 1.16 /**
|
202 kumpf 1.19 This function returns the privileged user name on the system.
203
204 @return the privileged user name
205 */
206 static String getPrivilegedUserName();
207
208 /**
|
209 kumpf 1.39 This function is used to verify whether the specified user is a member
210 of the specified user group.
211
212 @param userName User name to be verified.
213
214 @param groupName User group name.
215
216 @return true if the user is a member of the user group,
217 false otherwise.
218
219 @throw InternalSystemError - If there is an error
220 accessing the specified user or group information.
221 */
222 static Boolean isGroupMember(const char* userName, const char* groupName);
223
224 /**
|
225 kumpf 1.48 Changes the process user context to the specified user.
226
227 @param userName User name to set as the process user context.
228
229 @return True if the user context is successfully changed,
230 false otherwise.
231 */
|
232 humberto 1.52 #ifndef PEGASUS_OS_OS400
|
233 kumpf 1.48 static Boolean changeUserContext(const char* userName);
|
234 humberto 1.52 #endif
|
235 kumpf 1.48 /**
|
236 kumpf 1.16 This function is used to get the process ID of the calling process.
237
238 @return Process ID
239 */
240 static Uint32 getPID();
241
|
242 mike 1.21 static Boolean truncateFile(const char* path, size_t newSize);
|
243 kumpf 1.23
|
244 kumpf 1.29 /** Compare two strings but ignore any case differences.
245 This method is provided only because some platforms lack a strcasecmp
246 function in the standard library.
247 */
248 static Sint32 strcasecmp(const char* s1, const char* s2);
|
249 r.kieninger 1.44
|
250 tony 1.30 /** Return just the file or directory name from the path into basename.
251 This method returns a file or directory name at the end of a path.
252 The path can be relative or absolute. If the path is the root,
|
253 r.kieninger 1.44 then empty string is returned.
|
254 tony 1.30 */
|
255 kumpf 1.31 static char *extract_file_name(const char *fullpath, char *basename);
|
256 tony 1.30
257 /** Return just the pathname into dirname. The fullpath can be relative
258 or absolute. This method returns a path minus the file or
259 directory name at the end of a supplied path (fullpath).
260 If the fullpath is the root, then fullpath is returned.
261 The resulting path will contain a trailing slash unless fullpath is
262 a file or directory name, in which case, just the file or directory
|
263 r.kieninger 1.44 name is returned.
|
264 tony 1.30 */
|
265 kumpf 1.31 static char *extract_file_path(const char *fullpath, char *dirname);
|
266 tony 1.30
267 // Is absolute path?
|
268 kumpf 1.31 static Boolean is_absolute_path(const char *path);
|
269 kumpf 1.36
270 /** Changes file permissions on the given file.
271 @param path path of the file.
|
272 r.kieninger 1.44 @param mode the bit-wise inclusive OR of the values for the desired
|
273 kumpf 1.36 permissions.
274 @return true on success, false on error and errno is set appropriately.
275 */
276 static Boolean changeFilePermissions(const char* path, mode_t mode);
|
277 kumpf 1.29
|
278 kumpf 1.48 /** Checks whether the specified file is owned by the effective user for
279 the current process.
280 @param path Path of the file to check.
281 @return True if the file is owned by the effective user for the
282 current process, false otherwise.
283 */
284 static Boolean verifyFileOwnership(const char* path);
285
|
286 kumpf 1.40 /**
287 Flag indicating whether shared libraries are loaded with the
288 BIND_VERBOSE option.
289
290 THIS FLAG IS USED ON HP-UX ONLY.
291 */
|
292 kumpf 1.23 static Boolean bindVerbose;
|
293 david 1.32
|
294 kumpf 1.53 /**
295 Writes a message to the system log. This method encapsulates the
296 semantics of opening the system log, writing the specified message,
297 and closing the log.
298
299 @param ident An identifier to be prepended to the log messages
300 (typically a program name).
301 @param severity A severity value to be associated with the message.
302 Severity values are defined in Logger.h.
303 @param message A message to be written to the system log.
304 */
305 static void syslog(
306 const String& ident,
307 Uint32 severity,
308 const char* message);
|
309 david 1.32
310 // System ID constants for Logger::put and Logger::trace
311 static const String CIMSERVER;
|
312 tony 1.34
313 // System ID constants for Logger::put and Logger::trace
314 static const String CIMLISTENER;
|
315 gs.keenan 1.50
|
316 mike 1.13 };
317
318 PEGASUS_NAMESPACE_END
319
320 #endif /* Pegasus_System_h */
|