1 karl 1.59 //%2006////////////////////////////////////////////////////////////////////////
|
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 karl 1.59 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 mike 1.13 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
15 mike 1.14 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
18 mike 1.13 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
|
20 karl 1.45 //
|
21 mike 1.14 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
22 mike 1.13 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
24 mike 1.14 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
27 mike 1.13 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
34 #ifndef Pegasus_System_h
35 #define Pegasus_System_h
36
37 #include <Pegasus/Common/Config.h>
38 #include <Pegasus/Common/String.h>
|
39 kumpf 1.26 #include <Pegasus/Common/Linkage.h>
|
40 david 1.32 #include <Pegasus/Common/Logger.h>
|
41 kumpf 1.36 #include <sys/stat.h>
|
42 mike 1.13
|
43 kumpf 1.37
|
44 kumpf 1.38 #if defined(PEGASUS_OS_TYPE_WINDOWS)
|
45 kumpf 1.37 #ifndef mode_t
|
46 kumpf 1.38 typedef unsigned long mode_t;
|
47 kumpf 1.37 #endif
48 #endif
49
|
50 carson.hovey 1.65 #if defined (PEGASUS_OS_TYPE_UNIX) || (PEGASUS_OS_VMS)
|
51 kumpf 1.60 # ifndef PEGASUS_OS_OS400
52 # include <unistd.h>
53 # endif
|
54 kumpf 1.63 # include <fcntl.h> // File locking
|
55 kumpf 1.60 # define PEGASUS_UID_T uid_t
56 # define PEGASUS_GID_T gid_t
57 #else
58 # define PEGASUS_UID_T Uint32
59 # define PEGASUS_GID_T Uint32
60 #endif
|
61 konrad.r 1.41
|
62 kumpf 1.17 //
63 // Protocal Type
64 //
65 #define TCP "tcp"
66
|
67 mike 1.13 PEGASUS_NAMESPACE_BEGIN
68
69 /** The System class defines wrappers for operating system related calls.
70 These are only placed here if they are extremely light. These are
71 usually just direct wrappers which map more or less one to one to the
72 underlying function.
73 */
74 class PEGASUS_COMMON_LINKAGE System
75 {
76 public:
77 /** getCurrentTime - Gets the current time as seconds and milliseconds
78 into the provided variables using system functions.
79 @param seconds Return for the seconds component of the time.
80 @param milliseconds Return for the milliseconds component of the time.
81 @return The value is returned in the parameters.
82 The time returned is as defined in number of seconds and milliseconds
83 since 00:00 Coordinated Universal Time (UTC), January 1, 1970,
|
84 mike 1.14
|
85 mike 1.13 */
86 static void getCurrentTime(Uint32& seconds, Uint32& milliseconds);
87
|
88 jim.wunderlich 1.58 /** Similar to getCurrentTime() above but get microseconds (rather than
89 milliseconds).
90 */
91 static void getCurrentTimeUsec(Uint32& seconds, Uint32& microseconds);
92
|
93 mike 1.13 /** getCurrentASCIITime Gets time/date in a fixed format. The format is
94 YY MM DD-HH:MM:SS
95 @return Returns String with the ASCII time date.
96 */
97 static String getCurrentASCIITime();
98
99 static void sleep(Uint32 seconds);
100
101 static Boolean exists(const char* path);
102
103 static Boolean canRead(const char* path);
104
105 static Boolean canWrite(const char* path);
106
107 static Boolean getCurrentDirectory(char* path, Uint32 size);
108
109 static Boolean isDirectory(const char* path);
110
111 static Boolean changeDirectory(const char* path);
112
113 static Boolean makeDirectory(const char* path);
114 mike 1.13
115 static Boolean getFileSize(const char* path, Uint32& size);
116
117 static Boolean removeDirectory(const char* path);
118
119 static Boolean removeFile(const char* path);
120
121 static Boolean renameFile(const char* oldPath, const char* newPath);
122
|
123 mike 1.21 static Boolean copyFile(const char* fromPath, const char* toPath);
124
|
125 mike 1.13 static String getHostName();
|
126 kumpf 1.22 static String getFullyQualifiedHostName ();
127 static String getSystemCreationClassName ();
|
128 marek 1.47 static String getHostIP(const String &hostName);
|
129 kumpf 1.17
|
130 r.kieninger 1.44 static Uint32 _acquireIP(const char* hostname);
131
|
132 kumpf 1.17 static Uint32 lookupPort(
133 const char * serviceName,
134 Uint32 defaultPort);
|
135 mike 1.14
|
136 carolann.graves 1.56 /**
137 Attempts to validate that the input hostName represents the same host as
138 the host represented by the value returned by the
139 getFullyQualifiedHostName() method.
140
141 @param hostName the host name to validate
142
143 @return True if the input hostName can be validated to represent the
144 same host;
145 False otherwise
146 */
147 static Boolean sameHost (const String & hostName);
148
|
149 marek 1.66 /**
150 * Attempts to find the given IP address(32bit) on any of the local defined
151 * network interfaces
152 */
153 static Boolean isIpOnNetworkInterface(Uint32 inIP);
154
155 /**
156 * Attempts to resolve a given hostname
157 * this function possibly can take some as it can request information
158 * from the DNS
159 *
160 * Return: return value == true if successful, false if not successful
161 * the IP address that was determined resides in resolvedNameIP
162 */
163 static Boolean resolveHostNameAtDNS(const char* hostname, Uint32 * resolvedNameIP);
164
165 /**
166 * Attempts to resolve a given IP address
167 * this function possibly can take some as it can request information
168 * from the DNS
169 * Return: return value == true if successful, false if not successful
170 marek 1.66 * the IP address that was determined resides in resolvedNameIP
171 */
172 static Boolean resolveIPAtDNS(Uint32 ip_addr, Uint32 * resolvedIP);
173
174 /**
175 * Bundling function used to determine if a given hostname or IP address
176 * belongs to the local host
177 * this function has the potential to take some time as it will possibly
178 * use the DNS
179 */
180 static Boolean isLocalHost(const String &hostName);
181
|
182 kumpf 1.24 static String getEffectiveUserName();
|
183 mike 1.14
184 /**
185 This function is used to input a password with echo disabled.
186 The function reads up to a newline and returns a password of at most
187 8 characters.
188
189 @param prompt String containing the message prompt to be displayed
190 @return password obtained from the user
191 */
192 static String getPassword(const char* prompt);
193
194 /**
|
195 r.kieninger 1.44 This function is used to encrypt the user's password.
|
196 mike 1.14 The encryption is compatible with Apache's password file (generated using
197 the htpasswd command )
198
199 @param password Password to be encrypted.
200 @param salt Two character string chosen from the set [a-zA-Z0-9./].
201
202 @return Encrypted password.
203 */
204 static String encryptPassword(const char* password, const char* salt);
205
206 /**
|
207 r.kieninger 1.44 This function is used to verify whether specified user is a user
|
208 mike 1.14 on the local system.
209
210 @param userName User name to be verified.
211
212 @return true if the username is valid, else false
213 */
|
214 kumpf 1.28 static Boolean isSystemUser(const char* userName);
|
215 mike 1.14
216 /**
|
217 kumpf 1.24 Checks whether the given user is a privileged user.
|
218 mike 1.14
|
219 kumpf 1.18 @param userName User name to be checked.
220 @return true if the user is a privileged user, else false
|
221 mike 1.14 */
|
222 david.dillard 1.46 static Boolean isPrivilegedUser(const String& userName);
|
223 mike 1.14
|
224 kumpf 1.16 /**
|
225 kumpf 1.19 This function returns the privileged user name on the system.
226
227 @return the privileged user name
228 */
229 static String getPrivilegedUserName();
230
231 /**
|
232 kumpf 1.39 This function is used to verify whether the specified user is a member
233 of the specified user group.
234
235 @param userName User name to be verified.
236
237 @param groupName User group name.
238
239 @return true if the user is a member of the user group,
240 false otherwise.
241
242 @throw InternalSystemError - If there is an error
243 accessing the specified user or group information.
244 */
245 static Boolean isGroupMember(const char* userName, const char* groupName);
246
247 /**
|
248 kumpf 1.60 Gets the user and group IDs associated with the specified user.
249 @param userName User name for which to look up user and group IDs.
250 @param uid User ID for the specified user name.
251 @param gid Group ID for the specified user name.
252 @return True if the user and group IDs were retrieved
253 successfully, false otherwise.
254 */
255 #ifndef PEGASUS_OS_OS400
256 static Boolean lookupUserId(
257 const char* userName,
258 PEGASUS_UID_T& uid,
259 PEGASUS_GID_T& gid);
260 #endif
|
261 kumpf 1.48
|
262 kumpf 1.60 /**
263 Changes the process user context to the specified user and group ID.
264 @param uid User ID to set as the process user context.
265 @param gid Group ID to set as the process group context.
266 @return True if the user context is successfully changed,
267 false otherwise.
|
268 kumpf 1.48 */
|
269 humberto 1.52 #ifndef PEGASUS_OS_OS400
|
270 kumpf 1.60 static Boolean changeUserContext(
271 const PEGASUS_UID_T& uid,
272 const PEGASUS_GID_T& gid);
|
273 humberto 1.52 #endif
|
274 kumpf 1.60
|
275 kumpf 1.48 /**
|
276 kumpf 1.16 This function is used to get the process ID of the calling process.
277
278 @return Process ID
279 */
280 static Uint32 getPID();
281
|
282 mike 1.21 static Boolean truncateFile(const char* path, size_t newSize);
|
283 kumpf 1.23
|
284 kumpf 1.29 /** Compare two strings but ignore any case differences.
285 This method is provided only because some platforms lack a strcasecmp
286 function in the standard library.
287 */
288 static Sint32 strcasecmp(const char* s1, const char* s2);
|
289 r.kieninger 1.44
|
290 tony 1.30 /** Return just the file or directory name from the path into basename.
291 This method returns a file or directory name at the end of a path.
292 The path can be relative or absolute. If the path is the root,
|
293 r.kieninger 1.44 then empty string is returned.
|
294 tony 1.30 */
|
295 kumpf 1.31 static char *extract_file_name(const char *fullpath, char *basename);
|
296 tony 1.30
297 /** Return just the pathname into dirname. The fullpath can be relative
298 or absolute. This method returns a path minus the file or
299 directory name at the end of a supplied path (fullpath).
300 If the fullpath is the root, then fullpath is returned.
301 The resulting path will contain a trailing slash unless fullpath is
302 a file or directory name, in which case, just the file or directory
|
303 r.kieninger 1.44 name is returned.
|
304 tony 1.30 */
|
305 kumpf 1.31 static char *extract_file_path(const char *fullpath, char *dirname);
|
306 tony 1.30
307 // Is absolute path?
|
308 kumpf 1.31 static Boolean is_absolute_path(const char *path);
|
309 kumpf 1.36
310 /** Changes file permissions on the given file.
311 @param path path of the file.
|
312 r.kieninger 1.44 @param mode the bit-wise inclusive OR of the values for the desired
|
313 kumpf 1.36 permissions.
314 @return true on success, false on error and errno is set appropriately.
315 */
316 static Boolean changeFilePermissions(const char* path, mode_t mode);
|
317 kumpf 1.29
|
318 kumpf 1.57 /** Checks whether the specified file is a regular file owned by the
319 effective user for the current process.
|
320 kumpf 1.48 @param path Path of the file to check.
321 @return True if the file is owned by the effective user for the
322 current process, false otherwise.
323 */
324 static Boolean verifyFileOwnership(const char* path);
325
|
326 kumpf 1.40 /**
327 Flag indicating whether shared libraries are loaded with the
328 BIND_VERBOSE option.
329
330 THIS FLAG IS USED ON HP-UX ONLY.
331 */
|
332 kumpf 1.23 static Boolean bindVerbose;
|
333 david 1.32
|
334 kumpf 1.53 /**
335 Writes a message to the system log. This method encapsulates the
336 semantics of opening the system log, writing the specified message,
337 and closing the log.
338
339 @param ident An identifier to be prepended to the log messages
340 (typically a program name).
341 @param severity A severity value to be associated with the message.
342 Severity values are defined in Logger.h.
343 @param message A message to be written to the system log.
344 */
345 static void syslog(
346 const String& ident,
347 Uint32 severity,
348 const char* message);
|
349 david 1.32
|
350 marek 1.67 static void openlog(
351 const char *ident,
352 int logopt,
353 int facility);
354
355 static void closelog();
356
|
357 david 1.32 // System ID constants for Logger::put and Logger::trace
358 static const String CIMSERVER;
|
359 tony 1.34
360 // System ID constants for Logger::put and Logger::trace
361 static const String CIMLISTENER;
|
362 gs.keenan 1.50
|
363 mike 1.13 };
364
|
365 kumpf 1.63 /**
366 The AutoFileLock class uses an advisory file lock to allow access to a
367 resource to be controlled.
368 */
|
369 kumpf 1.64 class PEGASUS_COMMON_LINKAGE AutoFileLock
|
370 kumpf 1.63 {
371 public:
372
373 AutoFileLock(const char* fileName);
374 ~AutoFileLock();
375
376 private:
377
378 AutoFileLock();
379 AutoFileLock(const AutoFileLock&);
380 AutoFileLock& operator=(const AutoFileLock&);
381
382 #ifdef PEGASUS_OS_TYPE_UNIX
383 struct flock _fl;
384 int _fd;
385 #endif
386 };
387
|
388 mike 1.13 PEGASUS_NAMESPACE_END
389
390 #endif /* Pegasus_System_h */
|