(file) Return to System.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2