46 parseUserInfoString(pcUserInfo);
94 int UserInfo::access(
const int iUid,
const int iGid,
const unsigned int uiRawMode,
const int iMask)
const
96 int iRet((m_iUid == 0 && m_iGid == 0) ? 0 : EACCES);
99 iRet = testAccesss((uiRawMode & S_IRWXU) >> 6, iMask);
100 else if (belongs2Group(iGid))
101 iRet = testAccesss((uiRawMode & S_IRWXG) >> 3, iMask);
103 iRet = testAccesss(uiRawMode & S_IRWXO, iMask);
117 return(m_iGid == iGuid || m_Groups.find(iGuid) != m_Groups.end());
128 int iTestMode(iMode & iMask);
129 return(iTestMode == iMask ? 0 : EACCES);
148 const char* pcEqualDelim =
"= ";
149 const char* pcUid =
"uid";
150 const char* pcGroups =
"groups";
152 const int iLen(::strlen(pcUserInfo) + 1);
155 ::strncpy(acTokens, pcUserInfo, iLen);
158 char* pch = ::strtok_r(acTokens, pcEqualDelim, &pcSave);
159 if (pch && ::strcmp(pch, pcUid) == 0)
161 pch = ::strtok_r(NULL, pcEqualDelim, &pcSave);
164 m_iUid = ::atoi(pch);
165 pch = ::strtok_r(NULL, pcEqualDelim, &pcSave);
166 const char* pcGid =
"gid";
167 if (pch && ::strcmp(pch, pcGid) == 0)
169 pch = ::strtok_r(NULL, pcEqualDelim, &pcSave);
172 m_iGid = ::atoi(pch);
173 pch = ::strtok_r(NULL, pcEqualDelim, &pcSave);
179 if (pch && ::strcmp(pch, pcGroups) == 0)
181 const char* pcCommaDelim =
",";
182 pch = ::strtok_r(NULL, pcCommaDelim, &pcSave);
185 m_Groups.insert(::atoi(pch));
186 pch = ::strtok_r(NULL, pcCommaDelim, &pcSave);
bool belongs2Group(const int iGuid) const
Tests if this user belongs to the specified group,.
int testAccesss(const int iMode, const int iMask) const
Test requested access permissions against the mode;.
int access(const int iUid, const int iGid, const unsigned int uiRawMode, const int iMask) const
This is the similar to the access(2) system call.
void parseUserInfoString(const char *pcUserInfo)
Parse the specified user info string and store the results in the corresponding member variables...