coupling_plugin.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (C) 2011 Martin Willi
  3. * Copyright (C) 2011 revosec AG
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  12. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. * for more details.
  14. */
  15. #include "coupling_plugin.h"
  16. #include "coupling_validator.h"
  17. #include <daemon.h>
  18. typedef struct private_coupling_plugin_t private_coupling_plugin_t;
  19. /**
  20. * private data of coupling plugin
  21. */
  22. struct private_coupling_plugin_t {
  23. /**
  24. * implements plugin interface
  25. */
  26. coupling_plugin_t public;
  27. /**
  28. * validator controlling couplings
  29. */
  30. coupling_validator_t *validator;
  31. };
  32. METHOD(plugin_t, get_name, char*,
  33. private_coupling_plugin_t *this)
  34. {
  35. return "coupling";
  36. }
  37. /**
  38. * Since the validator instantiates a hasher we create it as plugin feature.
  39. * The default is SHA1 which we soft depend but depending on the plugin order
  40. * there is no guarantee that the configured algorithm is registered.
  41. */
  42. static bool plugin_cb(private_coupling_plugin_t *this,
  43. plugin_feature_t *feature, bool reg, void *cb_data)
  44. {
  45. if (reg)
  46. {
  47. this->validator = coupling_validator_create();
  48. if (!this->validator)
  49. {
  50. return FALSE;
  51. }
  52. lib->credmgr->add_validator(lib->credmgr, &this->validator->validator);
  53. }
  54. else
  55. {
  56. lib->credmgr->remove_validator(lib->credmgr,
  57. &this->validator->validator);
  58. this->validator->destroy(this->validator);
  59. }
  60. return TRUE;
  61. }
  62. METHOD(plugin_t, get_features, int,
  63. private_coupling_plugin_t *this, plugin_feature_t *features[])
  64. {
  65. static plugin_feature_t f[] = {
  66. PLUGIN_CALLBACK((plugin_feature_callback_t)plugin_cb, NULL),
  67. PLUGIN_PROVIDE(CUSTOM, "coupling"),
  68. PLUGIN_SDEPEND(HASHER, HASH_SHA1),
  69. };
  70. *features = f;
  71. return countof(f);
  72. }
  73. METHOD(plugin_t, destroy, void,
  74. private_coupling_plugin_t *this)
  75. {
  76. free(this);
  77. }
  78. /**
  79. * Plugin constructor
  80. */
  81. plugin_t *coupling_plugin_create()
  82. {
  83. private_coupling_plugin_t *this;
  84. INIT(this,
  85. .public = {
  86. .plugin = {
  87. .get_name = _get_name,
  88. .get_features = _get_features,
  89. .destroy = _destroy,
  90. },
  91. },
  92. );
  93. return &this->public.plugin;
  94. }