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 mreddy 1.73 #include <windows.h>
|
49 kumpf 1.37 #endif
50
|
51 carson.hovey 1.65 #if defined (PEGASUS_OS_TYPE_UNIX) || (PEGASUS_OS_VMS)
|
52 ouyang.jian 1.70 # include <unistd.h>
|
53 kumpf 1.63 # include <fcntl.h> // File locking
|
54 kumpf 1.60 # define PEGASUS_UID_T uid_t
55 # define PEGASUS_GID_T gid_t
56 #else
57 # define PEGASUS_UID_T Uint32
58 # define PEGASUS_GID_T Uint32
59 #endif
|
60 konrad.r 1.41
|
61 kumpf 1.17 //
62 // Protocal Type
63 //
64 #define TCP "tcp"
65
|
66 mike 1.13 PEGASUS_NAMESPACE_BEGIN
67
68 /** The System class defines wrappers for operating system related calls.
69 These are only placed here if they are extremely light. These are
70 usually just direct wrappers which map more or less one to one to the
71 underlying function.
72 */
73 class PEGASUS_COMMON_LINKAGE System
74 {
75 public:
76 /** getCurrentTime - Gets the current time as seconds and milliseconds
77 into the provided variables using system functions.
78 @param seconds Return for the seconds component of the time.
79 @param milliseconds Return for the milliseconds component of the time.
80 @return The value is returned in the parameters.
81 The time returned is as defined in number of seconds and milliseconds
82 since 00:00 Coordinated Universal Time (UTC), January 1, 1970,
|
83 mike 1.14
|
84 mike 1.13 */
85 static void getCurrentTime(Uint32& seconds, Uint32& milliseconds);
86
|
87 jim.wunderlich 1.58 /** Similar to getCurrentTime() above but get microseconds (rather than
|
88 kumpf 1.68 milliseconds).
|
89 jim.wunderlich 1.58 */
90 static void getCurrentTimeUsec(Uint32& seconds, Uint32& microseconds);
91
|
92 mike 1.13 /** getCurrentASCIITime Gets time/date in a fixed format. The format is
93 YY MM DD-HH:MM:SS
|
94 kumpf 1.68 @return Returns String with the ASCII time date.
|
95 mike 1.13 */
96 static String getCurrentASCIITime();
97
98 static void sleep(Uint32 seconds);
99
100 static Boolean exists(const char* path);
101
102 static Boolean canRead(const char* path);
103
104 static Boolean canWrite(const char* path);
105
106 static Boolean getCurrentDirectory(char* path, Uint32 size);
107
108 static Boolean isDirectory(const char* path);
109
110 static Boolean changeDirectory(const char* path);
111
112 static Boolean makeDirectory(const char* path);
113
114 static Boolean getFileSize(const char* path, Uint32& size);
115
116 mike 1.13 static Boolean removeDirectory(const char* path);
117
118 static Boolean removeFile(const char* path);
119
120 static Boolean renameFile(const char* oldPath, const char* newPath);
121
|
122 mike 1.21 static Boolean copyFile(const char* fromPath, const char* toPath);
123
|
124 mike 1.13 static String getHostName();
|
125 kumpf 1.22 static String getFullyQualifiedHostName ();
126 static String getSystemCreationClassName ();
|
127 kumpf 1.17
|
128 dave.sudlik 1.71 // Gets IP address assosiated with hostName. af indicates the
129 // type of address (ipv4 or ipv6) returned.
130 static Boolean getHostIP(const String &hostName, int *af, String &hostIP);
131
132 // Gets IP address in binary form. af indicates the type of
133 // address (ipv4 or ipv6) returned. Address will be copied to dst.
134 static Boolean _acquireIP(const char* hostname, int *af, void *dst);
|
135 r.kieninger 1.44
|
136 venkat.puvvada 1.72 /**
137 Returns true if IPv6 stack is active by checking return code from
138 Socket::createSocket() and getSocketError() calls.
139
140 ATTN: We return true if some error other than
141 PEGASUS_INVALID_ADDRESS_FAMILY is returned while creating the socket
142 because we will not be sure whether the IPv6 stack is active or not
143 from the returned error code. Return value of "true" from this method
144 should not be trusted absolutely.
145 */
146 #ifdef PEGASUS_ENABLE_IPV6
147 static Boolean isIPv6StackActive();
148 #endif
149
|
150 kumpf 1.17 static Uint32 lookupPort(
151 const char * serviceName,
152 Uint32 defaultPort);
|
153 mike 1.14
|
154 carolann.graves 1.56 /**
|
155 kumpf 1.68 Attempts to find the given IP address(32bit) on any of the local defined
156 network interfaces
|
157 marek 1.66 */
158 static Boolean isIpOnNetworkInterface(Uint32 inIP);
|
159 kumpf 1.68
|
160 marek 1.66 /**
|
161 kumpf 1.68 Attempts to resolve a given hostname
162 this function possibly can take some as it can request information
163 from the DNS
164
165 @param resolvedNameIP On successful hostname resolution, this output
166 parameter contains the IP address that was determined.
167 @return true if successful, false if not successful.
|
168 marek 1.66 */
|
169 kumpf 1.68 static Boolean resolveHostNameAtDNS(
170 const char* hostname,
171 Uint32* resolvedNameIP);
|
172 marek 1.66
173 /**
|
174 kumpf 1.68 Attempts to resolve a given IP address
175 this function possibly can take some as it can request information
176 from the DNS
177 @param resolvedIP On successful hostname resolution, this output
178 parameter contains the IP address that was determined.
179 @return true if successful, false if not successful.
|
180 marek 1.66 */
181 static Boolean resolveIPAtDNS(Uint32 ip_addr, Uint32 * resolvedIP);
182
|
183 kumpf 1.68 /**
184 Bundling function used to determine if a given hostname or IP address
185 belongs to the local host
186 this function has the potential to take some time as it will possibly
187 use the DNS
|
188 marek 1.66 */
|
189 kumpf 1.68 static Boolean isLocalHost(const String& hostName);
|
190 marek 1.66
|
191 dave.sudlik 1.71 /**
192 Checks binIPAddress represented by address family and returns true
193 if binary representation matches with loopback ip address. binIPAddress
194 must be in host-byte order.
195 */
196 static Boolean isLoopBack(int af, void *binIPAddress);
197
|
198 kumpf 1.24 static String getEffectiveUserName();
|
199 mike 1.14
200 /**
|
201 kumpf 1.68 This function is used to input a password with echo disabled.
202 The function reads up to a newline and returns a password of at most
203 8 characters.
|
204 mike 1.14
|
205 kumpf 1.68 @param prompt String containing the message prompt to be displayed
206 @return password obtained from the user
|
207 mike 1.14 */
208 static String getPassword(const char* prompt);
209
210 /**
|
211 kumpf 1.68 This function is used to encrypt the user's password.
212 The encryption is compatible with Apache's password file (generated
213 using the htpasswd command)
|
214 mike 1.14
|
215 kumpf 1.68 @param password Password to be encrypted.
216 @param salt Two character string chosen from the set [a-zA-Z0-9./].
|
217 mike 1.14
|
218 kumpf 1.68 @return Encrypted password.
|
219 mike 1.14 */
220 static String encryptPassword(const char* password, const char* salt);
221
222 /**
|
223 kumpf 1.68 This function is used to verify whether specified user is a user
224 on the local system.
|
225 mike 1.14
|
226 kumpf 1.68 @param userName User name to be verified.
|
227 mike 1.14
|
228 kumpf 1.68 @return true if the username is valid, else false
|
229 mike 1.14 */
|
230 kumpf 1.28 static Boolean isSystemUser(const char* userName);
|
231 mike 1.14
232 /**
|
233 kumpf 1.68 Checks whether the given user is a privileged user.
|
234 mike 1.14
|
235 kumpf 1.68 @param userName User name to be checked.
236 @return true if the user is a privileged user, else false
|
237 mike 1.14 */
|
238 david.dillard 1.46 static Boolean isPrivilegedUser(const String& userName);
|
239 mike 1.14
|
240 kumpf 1.16 /**
|
241 kumpf 1.68 This function returns the privileged user name on the system.
242 @return the privileged user name
|
243 kumpf 1.19 */
244 static String getPrivilegedUserName();
245
246 /**
|
247 kumpf 1.68 This function is used to verify whether the specified user is a member
248 of the specified user group.
|
249 kumpf 1.39
|
250 kumpf 1.68 @param userName User name to be verified.
251 @param groupName User group name.
|
252 kumpf 1.39
|
253 kumpf 1.68 @return true if the user is a member of the user group, false otherwise.
254 @throw InternalSystemError - If there is an error accessing the
255 specified user or group information.
|
256 kumpf 1.39 */
257 static Boolean isGroupMember(const char* userName, const char* groupName);
258
259 /**
|
260 kumpf 1.60 Gets the user and group IDs associated with the specified user.
261 @param userName User name for which to look up user and group IDs.
262 @param uid User ID for the specified user name.
263 @param gid Group ID for the specified user name.
264 @return True if the user and group IDs were retrieved
265 successfully, false otherwise.
266 */
267 static Boolean lookupUserId(
268 const char* userName,
269 PEGASUS_UID_T& uid,
270 PEGASUS_GID_T& gid);
|
271 kumpf 1.48
|
272 kumpf 1.60 /**
|
273 kumpf 1.69 Changes the process user context to the specified user and group.
274 IMPORTANT: This method uses non-reentrant functions and should only
275 be called in a single-threaded program.
276 @param userName User name to set as the process user context.
|
277 kumpf 1.60 @param uid User ID to set as the process user context.
278 @param gid Group ID to set as the process group context.
279 @return True if the user context is successfully changed,
280 false otherwise.
|
281 kumpf 1.48 */
|
282 kumpf 1.69 static Boolean changeUserContext_SingleThreaded(
283 const char* userName,
|
284 kumpf 1.60 const PEGASUS_UID_T& uid,
285 const PEGASUS_GID_T& gid);
286
|
287 kumpf 1.48 /**
|
288 kumpf 1.68 This function is used to get the process ID of the calling process.
289 @return Process ID
|
290 kumpf 1.16 */
291 static Uint32 getPID();
292
|
293 mike 1.21 static Boolean truncateFile(const char* path, size_t newSize);
|
294 kumpf 1.23
|
295 kumpf 1.29 /** Compare two strings but ignore any case differences.
296 This method is provided only because some platforms lack a strcasecmp
297 function in the standard library.
298 */
299 static Sint32 strcasecmp(const char* s1, const char* s2);
|
300 r.kieninger 1.44
|
301 tony 1.30 /** Return just the file or directory name from the path into basename.
302 This method returns a file or directory name at the end of a path.
303 The path can be relative or absolute. If the path is the root,
|
304 r.kieninger 1.44 then empty string is returned.
|
305 tony 1.30 */
|
306 kumpf 1.31 static char *extract_file_name(const char *fullpath, char *basename);
|
307 tony 1.30
308 /** Return just the pathname into dirname. The fullpath can be relative
309 or absolute. This method returns a path minus the file or
310 directory name at the end of a supplied path (fullpath).
311 If the fullpath is the root, then fullpath is returned.
312 The resulting path will contain a trailing slash unless fullpath is
313 a file or directory name, in which case, just the file or directory
|
314 r.kieninger 1.44 name is returned.
|
315 tony 1.30 */
|
316 kumpf 1.31 static char *extract_file_path(const char *fullpath, char *dirname);
|
317 tony 1.30
318 // Is absolute path?
|
319 kumpf 1.31 static Boolean is_absolute_path(const char *path);
|
320 kumpf 1.36
321 /** Changes file permissions on the given file.
322 @param path path of the file.
|
323 r.kieninger 1.44 @param mode the bit-wise inclusive OR of the values for the desired
|
324 kumpf 1.36 permissions.
325 @return true on success, false on error and errno is set appropriately.
326 */
327 static Boolean changeFilePermissions(const char* path, mode_t mode);
|
328 kumpf 1.29
|
329 kumpf 1.57 /** Checks whether the specified file is a regular file owned by the
330 effective user for the current process.
|
331 kumpf 1.48 @param path Path of the file to check.
332 @return True if the file is owned by the effective user for the
333 current process, false otherwise.
334 */
335 static Boolean verifyFileOwnership(const char* path);
336
|
337 kumpf 1.40 /**
338 Flag indicating whether shared libraries are loaded with the
339 BIND_VERBOSE option.
340
341 THIS FLAG IS USED ON HP-UX ONLY.
342 */
|
343 kumpf 1.23 static Boolean bindVerbose;
|
344 david 1.32
|
345 kumpf 1.53 /**
346 Writes a message to the system log. This method encapsulates the
347 semantics of opening the system log, writing the specified message,
348 and closing the log.
349
350 @param ident An identifier to be prepended to the log messages
351 (typically a program name).
352 @param severity A severity value to be associated with the message.
353 Severity values are defined in Logger.h.
354 @param message A message to be written to the system log.
355 */
356 static void syslog(
357 const String& ident,
358 Uint32 severity,
359 const char* message);
|
360 david 1.32
|
361 marek 1.67 static void openlog(
|
362 kumpf 1.68 const char *ident,
363 int logopt,
|
364 marek 1.67 int facility);
365
366 static void closelog();
367
|
368 david 1.32 // System ID constants for Logger::put and Logger::trace
369 static const String CIMSERVER;
|
370 tony 1.34
371 // System ID constants for Logger::put and Logger::trace
372 static const String CIMLISTENER;
|
373 gs.keenan 1.50
|
374 mike 1.13 };
375
|
376 kumpf 1.63 /**
377 The AutoFileLock class uses an advisory file lock to allow access to a
378 resource to be controlled.
379 */
|
380 kumpf 1.64 class PEGASUS_COMMON_LINKAGE AutoFileLock
|
381 kumpf 1.63 {
382 public:
383
384 AutoFileLock(const char* fileName);
385 ~AutoFileLock();
386
387 private:
388
389 AutoFileLock();
390 AutoFileLock(const AutoFileLock&);
391 AutoFileLock& operator=(const AutoFileLock&);
392
393 #ifdef PEGASUS_OS_TYPE_UNIX
394 struct flock _fl;
395 int _fd;
396 #endif
|
397 mreddy 1.73 #ifdef PEGASUS_OS_TYPE_WINDOWS
398 HANDLE _hFile;
399 #endif
|
400 kumpf 1.63 };
401
|
402 mike 1.13 PEGASUS_NAMESPACE_END
403
404 #endif /* Pegasus_System_h */
|