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

Diff for /pegasus/src/Pegasus/Common/SystemUnix.cpp between version 1.80 and 1.81

version 1.80, 2004/05/13 13:29:02 version 1.81, 2004/05/26 17:04:39
Line 52 
Line 52 
 #include <unistd.h> #include <unistd.h>
 #include <dirent.h> #include <dirent.h>
 #include <pwd.h> #include <pwd.h>
   #include <grp.h>
  
 #include <errno.h> #include <errno.h>
 #if defined(PEGASUS_OS_SOLARIS) #if defined(PEGASUS_OS_SOLARIS)
Line 854 
Line 855 
     return (userName);     return (userName);
 } }
  
   Boolean System::isGroupMember(const char* userName, const char* groupName)
   {
       struct group                        grp;
       char                                *member;
       Boolean                             retVal = false;
       const unsigned int                  PWD_BUFF_SIZE = 1024;
       const unsigned int                  GRP_BUFF_SIZE = 1024;
       struct passwd                       pwd;
       struct passwd                       *result;
       struct group                        *grpresult;
       char                                pwdBuffer[PWD_BUFF_SIZE];
       char                                grpBuffer[GRP_BUFF_SIZE];
   
       //
       // Search Primary group information.
       //
   
       // Find the entry that matches "userName"
   
       if (getpwnam_r(userName, &pwd, pwdBuffer, PWD_BUFF_SIZE, &result) != 0)
       {
           String errorMsg = String("getpwnam_r failure : ") +
                               String(strerror(errno));
           Tracer::PEG_TRACE_STRING (TRC_OS_ABSTRACTION, Tracer::LEVEL2,
                                     errorMsg);
           Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
                                     errorMsg);
           throw InternalSystemError();
       }
   
       if ( result != NULL )
       {
           // User found, check for group information.
           gid_t           group_id;
           group_id = pwd.pw_gid;
   
           // Get the group name using group_id and compare with group passed.
           if ( getgrgid_r(group_id, &grp,
                    grpBuffer, GRP_BUFF_SIZE, &grpresult) != 0)
           {
               String errorMsg = String("getgrgid_r failure : ") +
                                    String(strerror(errno));
               Tracer::PEG_TRACE_STRING (TRC_OS_ABSTRACTION, Tracer::LEVEL2,
                                         errorMsg);
               Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
                                     errorMsg);
               throw InternalSystemError();
           }
   
           // Compare the user's group name to groupName.
           if ( strcmp (grp.gr_name, groupName) == 0 )
           {
                // User is a member of the group.
                return true;
           }
       }
   
       //
       // Search supplemental groups.
       // Get a user group entry
       //
       if ( getgrnam_r(groupName, &grp,
                 grpBuffer, GRP_BUFF_SIZE, &grpresult) != 0 )
       {
           String errorMsg = String("getgrnam_r failure : ") +
                               String(strerror(errno));
           Tracer::PEG_TRACE_STRING (TRC_OS_ABSTRACTION, Tracer::LEVEL2,
                                     errorMsg);
           Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
                                     errorMsg);
           throw InternalSystemError();
       }
   
       // Check if the requested group was found.
       if (grpresult == NULL)
       {
           return false;
       }
   
       Uint32 j = 0;
   
       //
       // Get all the members of the group
       //
       member = grp.gr_mem[j++];
   
       while (member)
       {
           //
           // Check if the user is a member of the group
           //
           if ( strcmp(userName, member) == 0 )
           {
               retVal = true;
               break;
           }
           member = grp.gr_mem[j++];
       }
   
       return retVal;
   }
   
 Uint32 System::getPID() Uint32 System::getPID()
 { {
     //     //


Legend:
Removed from v.1.80  
changed lines
  Added in v.1.81

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2