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 kumpf 1.24 static String getEffectiveUserName();
|
150 mike 1.14
151 /**
152 This function is used to input a password with echo disabled.
153 The function reads up to a newline and returns a password of at most
154 8 characters.
155
156 @param prompt String containing the message prompt to be displayed
157 @return password obtained from the user
158 */
159 static String getPassword(const char* prompt);
160
161 /**
|
162 r.kieninger 1.44 This function is used to encrypt the user's password.
|
163 mike 1.14 The encryption is compatible with Apache's password file (generated using
164 the htpasswd command )
165
166 @param password Password to be encrypted.
167 @param salt Two character string chosen from the set [a-zA-Z0-9./].
168
169 @return Encrypted password.
170 */
171 static String encryptPassword(const char* password, const char* salt);
172
173 /**
|
174 r.kieninger 1.44 This function is used to verify whether specified user is a user
|
175 mike 1.14 on the local system.
176
177 @param userName User name to be verified.
178
179 @return true if the username is valid, else false
180 */
|
181 kumpf 1.28 static Boolean isSystemUser(const char* userName);
|
182 mike 1.14
183 /**
|
184 kumpf 1.24 Checks whether the given user is a privileged user.
|
185 mike 1.14
|
186 kumpf 1.18 @param userName User name to be checked.
187 @return true if the user is a privileged user, else false
|
188 mike 1.14 */
|
189 david.dillard 1.46 static Boolean isPrivilegedUser(const String& userName);
|
190 mike 1.14
|
191 kumpf 1.16 /**
|
192 kumpf 1.19 This function returns the privileged user name on the system.
193
194 @return the privileged user name
195 */
196 static String getPrivilegedUserName();
197
198 /**
|
199 kumpf 1.39 This function is used to verify whether the specified user is a member
200 of the specified user group.
201
202 @param userName User name to be verified.
203
204 @param groupName User group name.
205
206 @return true if the user is a member of the user group,
207 false otherwise.
208
209 @throw InternalSystemError - If there is an error
210 accessing the specified user or group information.
211 */
212 static Boolean isGroupMember(const char* userName, const char* groupName);
213
214 /**
|
215 kumpf 1.60 Gets the user and group IDs associated with the specified user.
216 @param userName User name for which to look up user and group IDs.
217 @param uid User ID for the specified user name.
218 @param gid Group ID for the specified user name.
219 @return True if the user and group IDs were retrieved
220 successfully, false otherwise.
221 */
222 #ifndef PEGASUS_OS_OS400
223 static Boolean lookupUserId(
224 const char* userName,
225 PEGASUS_UID_T& uid,
226 PEGASUS_GID_T& gid);
227 #endif
|
228 kumpf 1.48
|
229 kumpf 1.60 /**
230 Changes the process user context to the specified user and group ID.
231 @param uid User ID to set as the process user context.
232 @param gid Group ID to set as the process group context.
233 @return True if the user context is successfully changed,
234 false otherwise.
|
235 kumpf 1.48 */
|
236 humberto 1.52 #ifndef PEGASUS_OS_OS400
|
237 kumpf 1.60 static Boolean changeUserContext(
238 const PEGASUS_UID_T& uid,
239 const PEGASUS_GID_T& gid);
|
240 humberto 1.52 #endif
|
241 kumpf 1.60
|
242 kumpf 1.48 /**
|
243 kumpf 1.16 This function is used to get the process ID of the calling process.
244
245 @return Process ID
246 */
247 static Uint32 getPID();
248
|
249 mike 1.21 static Boolean truncateFile(const char* path, size_t newSize);
|
250 kumpf 1.23
|
251 kumpf 1.29 /** Compare two strings but ignore any case differences.
252 This method is provided only because some platforms lack a strcasecmp
253 function in the standard library.
254 */
255 static Sint32 strcasecmp(const char* s1, const char* s2);
|
256 r.kieninger 1.44
|
257 tony 1.30 /** Return just the file or directory name from the path into basename.
258 This method returns a file or directory name at the end of a path.
259 The path can be relative or absolute. If the path is the root,
|
260 r.kieninger 1.44 then empty string is returned.
|
261 tony 1.30 */
|
262 kumpf 1.31 static char *extract_file_name(const char *fullpath, char *basename);
|
263 tony 1.30
264 /** Return just the pathname into dirname. The fullpath can be relative
265 or absolute. This method returns a path minus the file or
266 directory name at the end of a supplied path (fullpath).
267 If the fullpath is the root, then fullpath is returned.
268 The resulting path will contain a trailing slash unless fullpath is
269 a file or directory name, in which case, just the file or directory
|
270 r.kieninger 1.44 name is returned.
|
271 tony 1.30 */
|
272 kumpf 1.31 static char *extract_file_path(const char *fullpath, char *dirname);
|
273 tony 1.30
274 // Is absolute path?
|
275 kumpf 1.31 static Boolean is_absolute_path(const char *path);
|
276 kumpf 1.36
277 /** Changes file permissions on the given file.
278 @param path path of the file.
|
279 r.kieninger 1.44 @param mode the bit-wise inclusive OR of the values for the desired
|
280 kumpf 1.36 permissions.
281 @return true on success, false on error and errno is set appropriately.
282 */
283 static Boolean changeFilePermissions(const char* path, mode_t mode);
|
284 kumpf 1.29
|
285 kumpf 1.57 /** Checks whether the specified file is a regular file owned by the
286 effective user for the current process.
|
287 kumpf 1.48 @param path Path of the file to check.
288 @return True if the file is owned by the effective user for the
289 current process, false otherwise.
290 */
291 static Boolean verifyFileOwnership(const char* path);
292
|
293 kumpf 1.40 /**
294 Flag indicating whether shared libraries are loaded with the
295 BIND_VERBOSE option.
296
297 THIS FLAG IS USED ON HP-UX ONLY.
298 */
|
299 kumpf 1.23 static Boolean bindVerbose;
|
300 david 1.32
|
301 kumpf 1.53 /**
302 Writes a message to the system log. This method encapsulates the
303 semantics of opening the system log, writing the specified message,
304 and closing the log.
305
306 @param ident An identifier to be prepended to the log messages
307 (typically a program name).
308 @param severity A severity value to be associated with the message.
309 Severity values are defined in Logger.h.
310 @param message A message to be written to the system log.
311 */
312 static void syslog(
313 const String& ident,
314 Uint32 severity,
315 const char* message);
|
316 david 1.32
317 // System ID constants for Logger::put and Logger::trace
318 static const String CIMSERVER;
|
319 tony 1.34
320 // System ID constants for Logger::put and Logger::trace
321 static const String CIMLISTENER;
|
322 gs.keenan 1.50
|
323 mike 1.13 };
324
|
325 kumpf 1.63 /**
326 The AutoFileLock class uses an advisory file lock to allow access to a
327 resource to be controlled.
328 */
|
329 kumpf 1.64 class PEGASUS_COMMON_LINKAGE AutoFileLock
|
330 kumpf 1.63 {
331 public:
332
333 AutoFileLock(const char* fileName);
334 ~AutoFileLock();
335
336 private:
337
338 AutoFileLock();
339 AutoFileLock(const AutoFileLock&);
340 AutoFileLock& operator=(const AutoFileLock&);
341
342 #ifdef PEGASUS_OS_TYPE_UNIX
343 struct flock _fl;
344 int _fd;
345 #endif
346 };
347
|
348 mike 1.13 PEGASUS_NAMESPACE_END
349
350 #endif /* Pegasus_System_h */
|