auditlib.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*##############################################################################
  2. Copyright (C) 2011 HPCC Systems.
  3. All rights reserved. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ############################################################################## */
  14. #include "jlog.hpp"
  15. #include "auditlib.hpp"
  16. #define AUDITLIB_VERSION "AUDITLIB 1.0.1"
  17. static const char * compatibleVersions[] = {
  18. "AUDITLIB 1.0.0 [29933bc38c1f07bcf70f938ad18775c1]", // linux version
  19. AUDITLIB_VERSION,
  20. NULL };
  21. const char * EclDefinition =
  22. "export AuditLib := SERVICE\n"
  23. " boolean Audit(const string atype, const string msg) : c, action, volatile, entrypoint='alAudit', hole; \n"
  24. " boolean AuditData(const string atype, const string msg, const data datablock) : c, action, volatile, entrypoint='alAuditData', hole; \n"
  25. "END;";
  26. AUDITLIB_API bool getECLPluginDefinition(ECLPluginDefinitionBlock *pb)
  27. {
  28. if (pb->size == sizeof(ECLPluginDefinitionBlockEx))
  29. {
  30. ECLPluginDefinitionBlockEx * pbx = (ECLPluginDefinitionBlockEx *) pb;
  31. pbx->compatibleVersions = compatibleVersions;
  32. }
  33. else if (pb->size != sizeof(ECLPluginDefinitionBlock))
  34. return false;
  35. pb->magicVersion = PLUGIN_VERSION;
  36. pb->version = AUDITLIB_VERSION;
  37. pb->moduleName = "lib_auditlib";
  38. pb->ECL = EclDefinition;
  39. pb->flags = PLUGIN_IMPLICIT_MODULE;
  40. pb->description = "AuditLib event log audit functions";
  41. return true;
  42. }
  43. #define AUDIT_TYPES_BEGIN char const * auditTypeNameMap[NUM_AUDIT_TYPES+1] = {
  44. #define MAKE_AUDIT_TYPE(name, type, categoryid, eventid, level) #name ,
  45. #define AUDIT_TYPES_END 0 };
  46. #include "jelogtype.hpp"
  47. #undef AUDIT_TYPES_BEGIN
  48. #undef MAKE_AUDIT_TYPE
  49. #undef AUDIT_TYPES_END
  50. AuditType findAuditType(char const * typeString)
  51. {
  52. unsigned i;
  53. for(i=0; i<NUM_AUDIT_TYPES; i++)
  54. if(strcmp(typeString, auditTypeNameMap[i])==0) return static_cast<AuditType>(i);
  55. return NUM_AUDIT_TYPES;
  56. }
  57. bool alAudit(unsigned typeLen, char const * type, unsigned msgLen, char const * msg)
  58. {
  59. return alAuditData(typeLen, type, msgLen, msg, 0, 0);
  60. }
  61. bool alAuditData(unsigned typeLen, char const * type, unsigned msgLen, char const * msg, unsigned dataLen, void const * dataBlock)
  62. {
  63. StringBuffer typeString(typeLen, type);
  64. typeString.toUpperCase();
  65. StringBuffer msgString(msgLen, msg);
  66. AuditType typeValue = findAuditType(typeString.str());
  67. if(typeValue >= NUM_AUDIT_TYPES)
  68. return false;
  69. return AUDIT(typeValue, msgString.str(), dataLen, dataBlock);
  70. }