int CLuaACLDefs::aclListRights ( lua_State* luaVM ) { // table aclListRights ( acl theACL ) CAccessControlList* pACL; SString strType; bool bAll = true; CAccessControlListRight::ERightType eAllowed = (CAccessControlListRight::ERightType)-1; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pACL ); if ( argStream.NextIsString () ) { argStream.ReadString ( strType ); bAll = false; if ( strType == "command" ) eAllowed = CAccessControlListRight::RIGHT_TYPE_COMMAND; else if ( strType == "function" ) eAllowed = CAccessControlListRight::RIGHT_TYPE_FUNCTION; else if ( strType == "resource" ) eAllowed = CAccessControlListRight::RIGHT_TYPE_RESOURCE; else if ( strType == "general" ) eAllowed = CAccessControlListRight::RIGHT_TYPE_GENERAL; else bAll = true; } if ( !argStream.HasErrors () ) { // Create a table to return into lua_newtable ( luaVM ); // Loop through ACL char szRightName [128]; CAccessControlListRight::ERightType eType; unsigned int uiIndex = 0; list <CAccessControlListRight* > ::const_iterator iter = pACL->IterBegin (); for ( ; iter != pACL->IterEnd (); ++iter ) { // Type eType = (*iter)->GetRightType (); if ( !bAll && eType != eAllowed ) continue; switch ( eType ) { case CAccessControlListRight::RIGHT_TYPE_COMMAND: strcpy ( szRightName, "command." ); break; case CAccessControlListRight::RIGHT_TYPE_FUNCTION: strcpy ( szRightName, "function." ); break; case CAccessControlListRight::RIGHT_TYPE_RESOURCE: strcpy ( szRightName, "resource." ); break; case CAccessControlListRight::RIGHT_TYPE_GENERAL: strcpy ( szRightName, "general." ); break; default: strcpy ( szRightName, "unknown." ); break; } // Append right name strncat ( szRightName, (*iter)->GetRightName (), NUMELMS( szRightName ) - 1 ); // Push its name onto the table lua_pushnumber ( luaVM, ++uiIndex ); lua_pushstring ( luaVM, szRightName ); lua_settable ( luaVM, -3 ); } // Return the table return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
/////////////////////////////////////////////////////////////// // // CResource::GetAclRequests // // Get all acl requests for this resource // /////////////////////////////////////////////////////////////// void CResource::GetAclRequests ( std::vector < SAclRequest >& outResultList ) { outResultList.clear (); CAccessControlList* pAutoAcl = FindAutoAcl (); if ( !pAutoAcl ) return; // Get each right for ( std::list < CAccessControlListRight* >::const_iterator iter = pAutoAcl->IterBegin () ; iter != pAutoAcl->IterEnd () ; ++iter ) { CAccessControlListRight* pAclRight = *iter; // Create SAclRequest from ACL SAclRequest request ( CAclRightName ( pAclRight->GetRightType (), pAclRight->GetRightName () ) ); request.bAccess = StringToBool ( pAclRight->GetAttributeValue ( "access" ) ); request.bPending = StringToBool ( pAclRight->GetAttributeValue ( "pending" ) ); request.strWho = pAclRight->GetAttributeValue ( "who" ); request.strDate = pAclRight->GetAttributeValue ( "date" ); outResultList.push_back ( request ); } }
int CLuaACLDefs::aclListRights ( lua_State* luaVM ) { // Verify the arguents if ( lua_type ( luaVM, 1 ) == LUA_TLIGHTUSERDATA ) { // Grab and verify the ACL CAccessControlList* pACL = lua_toacl ( luaVM, 1 ); if ( pACL ) { // Create a table to return into lua_newtable ( luaVM ); // Loop through ACL char szRightName [128]; CAccessControlListRight::ERightType eType; unsigned int uiIndex = 0; list <CAccessControlListRight* > ::const_iterator iter = pACL->IterBegin (); for ( ; iter != pACL->IterEnd (); iter++ ) { // Type eType = (*iter)->GetRightType (); switch ( eType ) { case CAccessControlListRight::RIGHT_TYPE_COMMAND: strcpy ( szRightName, "command." ); break; case CAccessControlListRight::RIGHT_TYPE_FUNCTION: strcpy ( szRightName, "function." ); break; case CAccessControlListRight::RIGHT_TYPE_RESOURCE: strcpy ( szRightName, "resource." ); break; case CAccessControlListRight::RIGHT_TYPE_GENERAL: strcpy ( szRightName, "general." ); break; default: strcpy ( szRightName, "unknown." ); break; } // Append right name strncat ( szRightName, (*iter)->GetRightName (), 128 ); // Push its name onto the table lua_pushnumber ( luaVM, ++uiIndex ); lua_pushstring ( luaVM, szRightName ); lua_settable ( luaVM, -3 ); } // Return the table return 1; } } // Return true lua_pushboolean ( luaVM, false ); return 1; }