auditlib.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #include "jlog.hpp"
  14. #include "auditlib.hpp"
  15. #define AUDITLIB_VERSION "AUDITLIB 1.0.1"
  16. static const char * compatibleVersions[] = {
  17. "AUDITLIB 1.0.0 [29933bc38c1f07bcf70f938ad18775c1]", // linux version
  18. AUDITLIB_VERSION,
  19. NULL };
  20. static const char * EclDefinition =
  21. "export AuditLib := SERVICE\n"
  22. " boolean Audit(const string atype, const string msg) : c, action, volatile, entrypoint='alAudit', hole; \n"
  23. " boolean AuditData(const string atype, const string msg, const data datablock) : c, action, volatile, entrypoint='alAuditData', hole; \n"
  24. "END;";
  25. AUDITLIB_API bool getECLPluginDefinition(ECLPluginDefinitionBlock *pb)
  26. {
  27. if (pb->size == sizeof(ECLPluginDefinitionBlockEx))
  28. {
  29. ECLPluginDefinitionBlockEx * pbx = (ECLPluginDefinitionBlockEx *) pb;
  30. pbx->compatibleVersions = compatibleVersions;
  31. }
  32. else if (pb->size != sizeof(ECLPluginDefinitionBlock))
  33. return false;
  34. pb->magicVersion = PLUGIN_VERSION;
  35. pb->version = AUDITLIB_VERSION;
  36. pb->moduleName = "lib_auditlib";
  37. pb->ECL = EclDefinition;
  38. pb->flags = PLUGIN_IMPLICIT_MODULE;
  39. pb->description = "AuditLib event log audit functions";
  40. return true;
  41. }
  42. #define AUDIT_TYPES_BEGIN char const * auditTypeNameMap[NUM_AUDIT_TYPES+1] = {
  43. #define MAKE_AUDIT_TYPE(name, type, categoryid, eventid, level) #name ,
  44. #define AUDIT_TYPES_END 0 };
  45. #include "jelogtype.hpp"
  46. #undef AUDIT_TYPES_BEGIN
  47. #undef MAKE_AUDIT_TYPE
  48. #undef AUDIT_TYPES_END
  49. AuditType findAuditType(char const * typeString)
  50. {
  51. unsigned i;
  52. for(i=0; i<NUM_AUDIT_TYPES; i++)
  53. if(strcmp(typeString, auditTypeNameMap[i])==0) return static_cast<AuditType>(i);
  54. return NUM_AUDIT_TYPES;
  55. }
  56. bool alAudit(unsigned typeLen, char const * type, unsigned msgLen, char const * msg)
  57. {
  58. return alAuditData(typeLen, type, msgLen, msg, 0, 0);
  59. }
  60. bool alAuditData(unsigned typeLen, char const * type, unsigned msgLen, char const * msg, unsigned dataLen, void const * dataBlock)
  61. {
  62. StringBuffer typeString(typeLen, type);
  63. typeString.toUpperCase();
  64. StringBuffer msgString(msgLen, msg);
  65. AuditType typeValue = findAuditType(typeString.str());
  66. if(typeValue >= NUM_AUDIT_TYPES)
  67. return false;
  68. return AUDIT(typeValue, msgString.str(), dataLen, dataBlock);
  69. }