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 kumpf 1.68 milliseconds).
|
90 jim.wunderlich 1.58 */
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 kumpf 1.68 @return Returns String with the ASCII time date.
|
96 mike 1.13 */
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
115 static Boolean getFileSize(const char* path, Uint32& size);
116
117 mike 1.13 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 kumpf 1.17
|
129 dave.sudlik 1.68.4.2 // Gets IP address assosiated with hostName. af indicates the
130 // type of address (ipv4 or ipv6) returned.
131 static Boolean getHostIP(const String &hostName, int *af, String &hostIP);
132
133 // Gets IP address in binary form. af indicates the type of
134 // address (ipv4 or ipv6) returned. Address will be copied to dst.
135 static Boolean _acquireIP(const char* hostname, int *af, void *dst);
|
136 r.kieninger 1.44
|
137 kumpf 1.17 static Uint32 lookupPort(
138 const char * serviceName,
139 Uint32 defaultPort);
|
140 mike 1.14
|
141 carolann.graves 1.56 /**
|
142 kumpf 1.68 Attempts to find the given IP address(32bit) on any of the local defined
143 network interfaces
|
144 marek 1.66 */
145 static Boolean isIpOnNetworkInterface(Uint32 inIP);
|
146 kumpf 1.68
|
147 marek 1.66 /**
|
148 kumpf 1.68 Attempts to resolve a given hostname
149 this function possibly can take some as it can request information
150 from the DNS
151
152 @param resolvedNameIP On successful hostname resolution, this output
153 parameter contains the IP address that was determined.
154 @return true if successful, false if not successful.
|
155 marek 1.66 */
|
156 kumpf 1.68 static Boolean resolveHostNameAtDNS(
157 const char* hostname,
158 Uint32* resolvedNameIP);
|
159 marek 1.66
160 /**
|
161 kumpf 1.68 Attempts to resolve a given IP address
162 this function possibly can take some as it can request information
163 from the DNS
164 @param resolvedIP On successful hostname resolution, this output
165 parameter contains the IP address that was determined.
166 @return true if successful, false if not successful.
|
167 marek 1.66 */
168 static Boolean resolveIPAtDNS(Uint32 ip_addr, Uint32 * resolvedIP);
169
|
170 kumpf 1.68 /**
171 Bundling function used to determine if a given hostname or IP address
172 belongs to the local host
173 this function has the potential to take some time as it will possibly
174 use the DNS
|
175 marek 1.66 */
|
176 kumpf 1.68 static Boolean isLocalHost(const String& hostName);
|
177 marek 1.66
|
178 dave.sudlik 1.68.4.2 /**
179 Checks binIPAddress represented by address family and returns true
180 if binary representation matches with loopback ip address. binIPAddress
181 must be in host-byte order.
182 */
183 static Boolean isLoopBack(int af, void *binIPAddress);
184
|
185 kumpf 1.24 static String getEffectiveUserName();
|
186 mike 1.14
187 /**
|
188 kumpf 1.68 This function is used to input a password with echo disabled.
189 The function reads up to a newline and returns a password of at most
190 8 characters.
|
191 mike 1.14
|
192 kumpf 1.68 @param prompt String containing the message prompt to be displayed
193 @return password obtained from the user
|
194 mike 1.14 */
195 static String getPassword(const char* prompt);
196
197 /**
|
198 kumpf 1.68 This function is used to encrypt the user's password.
199 The encryption is compatible with Apache's password file (generated
200 using the htpasswd command)
|
201 mike 1.14
|
202 kumpf 1.68 @param password Password to be encrypted.
203 @param salt Two character string chosen from the set [a-zA-Z0-9./].
|
204 mike 1.14
|
205 kumpf 1.68 @return Encrypted password.
|
206 mike 1.14 */
207 static String encryptPassword(const char* password, const char* salt);
208
209 /**
|
210 kumpf 1.68 This function is used to verify whether specified user is a user
211 on the local system.
|
212 mike 1.14
|
213 kumpf 1.68 @param userName User name to be verified.
|
214 mike 1.14
|
215 kumpf 1.68 @return true if the username is valid, else false
|
216 mike 1.14 */
|
217 kumpf 1.28 static Boolean isSystemUser(const char* userName);
|
218 mike 1.14
219 /**
|
220 kumpf 1.68 Checks whether the given user is a privileged user.
|
221 mike 1.14
|
222 kumpf 1.68 @param userName User name to be checked.
223 @return true if the user is a privileged user, else false
|
224 mike 1.14 */
|
225 david.dillard 1.46 static Boolean isPrivilegedUser(const String& userName);
|
226 mike 1.14
|
227 kumpf 1.16 /**
|
228 kumpf 1.68 This function returns the privileged user name on the system.
229 @return the privileged user name
|
230 kumpf 1.19 */
231 static String getPrivilegedUserName();
232
233 /**
|
234 kumpf 1.68 This function is used to verify whether the specified user is a member
235 of the specified user group.
|
236 kumpf 1.39
|
237 kumpf 1.68 @param userName User name to be verified.
238 @param groupName User group name.
|
239 kumpf 1.39
|
240 kumpf 1.68 @return true if the user is a member of the user group, false otherwise.
241 @throw InternalSystemError - If there is an error accessing the
242 specified user or group information.
|
243 kumpf 1.39 */
244 static Boolean isGroupMember(const char* userName, const char* groupName);
245
246 /**
|
247 kumpf 1.60 Gets the user and group IDs associated with the specified user.
248 @param userName User name for which to look up user and group IDs.
249 @param uid User ID for the specified user name.
250 @param gid Group ID for the specified user name.
251 @return True if the user and group IDs were retrieved
252 successfully, false otherwise.
253 */
254 #ifndef PEGASUS_OS_OS400
255 static Boolean lookupUserId(
256 const char* userName,
257 PEGASUS_UID_T& uid,
258 PEGASUS_GID_T& gid);
259 #endif
|
260 kumpf 1.48
|
261 kumpf 1.60 /**
|
262 kumpf 1.68.4.1 Changes the process user context to the specified user and group.
263 IMPORTANT: This method uses non-reentrant functions and should only
264 be called in a single-threaded program.
265 @param userName User name to set as the process user context.
|
266 kumpf 1.60 @param uid User ID to set as the process user context.
267 @param gid Group ID to set as the process group context.
268 @return True if the user context is successfully changed,
269 false otherwise.
|
270 kumpf 1.48 */
|
271 humberto 1.52 #ifndef PEGASUS_OS_OS400
|
272 kumpf 1.68.4.1 static Boolean changeUserContext_SingleThreaded(
273 const char* userName,
|
274 kumpf 1.60 const PEGASUS_UID_T& uid,
275 const PEGASUS_GID_T& gid);
|
276 humberto 1.52 #endif
|
277 kumpf 1.60
|
278 kumpf 1.48 /**
|
279 kumpf 1.68 This function is used to get the process ID of the calling process.
280 @return Process ID
|
281 kumpf 1.16 */
282 static Uint32 getPID();
283
|
284 mike 1.21 static Boolean truncateFile(const char* path, size_t newSize);
|
285 kumpf 1.23
|
286 kumpf 1.29 /** Compare two strings but ignore any case differences.
287 This method is provided only because some platforms lack a strcasecmp
288 function in the standard library.
289 */
290 static Sint32 strcasecmp(const char* s1, const char* s2);
|
291 r.kieninger 1.44
|
292 tony 1.30 /** Return just the file or directory name from the path into basename.
293 This method returns a file or directory name at the end of a path.
294 The path can be relative or absolute. If the path is the root,
|
295 r.kieninger 1.44 then empty string is returned.
|
296 tony 1.30 */
|
297 kumpf 1.31 static char *extract_file_name(const char *fullpath, char *basename);
|
298 tony 1.30
299 /** Return just the pathname into dirname. The fullpath can be relative
300 or absolute. This method returns a path minus the file or
301 directory name at the end of a supplied path (fullpath).
302 If the fullpath is the root, then fullpath is returned.
303 The resulting path will contain a trailing slash unless fullpath is
304 a file or directory name, in which case, just the file or directory
|
305 r.kieninger 1.44 name is returned.
|
306 tony 1.30 */
|
307 kumpf 1.31 static char *extract_file_path(const char *fullpath, char *dirname);
|
308 tony 1.30
309 // Is absolute path?
|
310 kumpf 1.31 static Boolean is_absolute_path(const char *path);
|
311 kumpf 1.36
312 /** Changes file permissions on the given file.
313 @param path path of the file.
|
314 r.kieninger 1.44 @param mode the bit-wise inclusive OR of the values for the desired
|
315 kumpf 1.36 permissions.
316 @return true on success, false on error and errno is set appropriately.
317 */
318 static Boolean changeFilePermissions(const char* path, mode_t mode);
|
319 kumpf 1.29
|
320 kumpf 1.57 /** Checks whether the specified file is a regular file owned by the
321 effective user for the current process.
|
322 kumpf 1.48 @param path Path of the file to check.
323 @return True if the file is owned by the effective user for the
324 current process, false otherwise.
325 */
326 static Boolean verifyFileOwnership(const char* path);
327
|
328 kumpf 1.40 /**
329 Flag indicating whether shared libraries are loaded with the
330 BIND_VERBOSE option.
331
332 THIS FLAG IS USED ON HP-UX ONLY.
333 */
|
334 kumpf 1.23 static Boolean bindVerbose;
|
335 david 1.32
|
336 kumpf 1.53 /**
337 Writes a message to the system log. This method encapsulates the
338 semantics of opening the system log, writing the specified message,
339 and closing the log.
340
341 @param ident An identifier to be prepended to the log messages
342 (typically a program name).
343 @param severity A severity value to be associated with the message.
344 Severity values are defined in Logger.h.
345 @param message A message to be written to the system log.
346 */
347 static void syslog(
348 const String& ident,
349 Uint32 severity,
350 const char* message);
|
351 david 1.32
|
352 marek 1.67 static void openlog(
|
353 kumpf 1.68 const char *ident,
354 int logopt,
|
355 marek 1.67 int facility);
356
357 static void closelog();
358
|
359 david 1.32 // System ID constants for Logger::put and Logger::trace
360 static const String CIMSERVER;
|
361 tony 1.34
362 // System ID constants for Logger::put and Logger::trace
363 static const String CIMLISTENER;
|
364 gs.keenan 1.50
|
365 mike 1.13 };
366
|
367 kumpf 1.63 /**
368 The AutoFileLock class uses an advisory file lock to allow access to a
369 resource to be controlled.
370 */
|
371 kumpf 1.64 class PEGASUS_COMMON_LINKAGE AutoFileLock
|
372 kumpf 1.63 {
373 public:
374
375 AutoFileLock(const char* fileName);
376 ~AutoFileLock();
377
378 private:
379
380 AutoFileLock();
381 AutoFileLock(const AutoFileLock&);
382 AutoFileLock& operator=(const AutoFileLock&);
383
384 #ifdef PEGASUS_OS_TYPE_UNIX
385 struct flock _fl;
386 int _fd;
387 #endif
388 };
389
|
390 mike 1.13 PEGASUS_NAMESPACE_END
391
392 #endif /* Pegasus_System_h */
|