imv_workitem.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. * Copyright (C) 2013 Andreas Steffen
  3. * HSR Hochschule fuer Technik Rapperswil
  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 "imv_workitem.h"
  16. #include <utils/debug.h>
  17. #include <tncif_names.h>
  18. typedef struct private_imv_workitem_t private_imv_workitem_t;
  19. ENUM(imv_workitem_type_names, IMV_WORKITEM_PACKAGES, IMV_WORKITEM_TPM_ATTEST,
  20. "PCKGS",
  21. "UNSRC",
  22. "FWDEN",
  23. "PWDEN",
  24. "FREFM",
  25. "FMEAS",
  26. "FMETA",
  27. "DREFM",
  28. "DMEAS",
  29. "DMETA",
  30. "TCPOP",
  31. "TCPBL",
  32. "UDPOP",
  33. "UDPBL",
  34. "SWIDT",
  35. "TPMRA"
  36. );
  37. /**
  38. * Private data of a imv_workitem_t object.
  39. *
  40. */
  41. struct private_imv_workitem_t {
  42. /**
  43. * Public imv_workitem_t interface.
  44. */
  45. imv_workitem_t public;
  46. /**
  47. * Primary workitem key
  48. */
  49. int id;
  50. /**
  51. * IMV ID
  52. */
  53. TNC_IMVID imv_id;
  54. /**
  55. * Workitem type
  56. */
  57. imv_workitem_type_t type;
  58. /**
  59. * Argument string
  60. */
  61. char *arg_str;
  62. /**
  63. * Argument integer
  64. */
  65. int arg_int;
  66. /**
  67. * Result string
  68. */
  69. char *result;
  70. /**
  71. * IMV action recommendation
  72. */
  73. TNC_IMV_Action_Recommendation rec_fail;
  74. /**
  75. * IMV action recommendation
  76. */
  77. TNC_IMV_Action_Recommendation rec_noresult;
  78. /**
  79. * IMV action recommendation
  80. */
  81. TNC_IMV_Action_Recommendation rec_final;
  82. };
  83. METHOD(imv_workitem_t, get_id, int,
  84. private_imv_workitem_t *this)
  85. {
  86. return this->id;
  87. }
  88. METHOD(imv_workitem_t, set_imv_id, void,
  89. private_imv_workitem_t *this, TNC_IMVID imv_id)
  90. {
  91. this->imv_id = imv_id;
  92. DBG2(DBG_IMV, "IMV %d handles %N workitem %d", imv_id,
  93. imv_workitem_type_names, this->type, this->id);
  94. }
  95. METHOD(imv_workitem_t, get_imv_id, TNC_IMVID,
  96. private_imv_workitem_t *this)
  97. {
  98. return this->imv_id;
  99. }
  100. METHOD(imv_workitem_t, get_type, imv_workitem_type_t,
  101. private_imv_workitem_t *this)
  102. {
  103. return this->type;
  104. }
  105. METHOD(imv_workitem_t, get_arg_str, char*,
  106. private_imv_workitem_t *this)
  107. {
  108. return this->arg_str;
  109. }
  110. METHOD(imv_workitem_t, get_arg_int, int,
  111. private_imv_workitem_t *this)
  112. {
  113. return this->arg_int;
  114. }
  115. METHOD(imv_workitem_t, set_result, TNC_IMV_Action_Recommendation,
  116. private_imv_workitem_t *this, char *result, TNC_IMV_Evaluation_Result eval)
  117. {
  118. this->result = strdup(result);
  119. switch (eval)
  120. {
  121. case TNC_IMV_EVALUATION_RESULT_COMPLIANT:
  122. this->rec_final = TNC_IMV_ACTION_RECOMMENDATION_ALLOW;
  123. break;
  124. case TNC_IMV_EVALUATION_RESULT_NONCOMPLIANT_MINOR:
  125. case TNC_IMV_EVALUATION_RESULT_NONCOMPLIANT_MAJOR:
  126. this->rec_final = this->rec_fail;
  127. break;
  128. case TNC_IMV_EVALUATION_RESULT_ERROR:
  129. case TNC_IMV_EVALUATION_RESULT_DONT_KNOW:
  130. default:
  131. this->rec_final = this->rec_noresult;
  132. break;
  133. }
  134. DBG2(DBG_IMV, "IMV %d handled %N workitem %d: %N%s%s", this->imv_id,
  135. imv_workitem_type_names, this->type, this->id,
  136. TNC_IMV_Action_Recommendation_names, this->rec_final,
  137. strlen(result) ? " - " : "", result);
  138. return this->rec_final;
  139. }
  140. METHOD(imv_workitem_t, get_result, TNC_IMV_Action_Recommendation,
  141. private_imv_workitem_t *this, char **result)
  142. {
  143. if (result)
  144. {
  145. *result = this->result;
  146. }
  147. return this->rec_final;
  148. }
  149. METHOD(imv_workitem_t, destroy, void,
  150. private_imv_workitem_t *this)
  151. {
  152. free(this->arg_str);
  153. free(this->result);
  154. free(this);
  155. }
  156. /**
  157. * See header
  158. */
  159. imv_workitem_t *imv_workitem_create(int id, imv_workitem_type_t type,
  160. char *arg_str, int arg_int,
  161. TNC_IMV_Action_Recommendation rec_fail,
  162. TNC_IMV_Action_Recommendation rec_noresult)
  163. {
  164. private_imv_workitem_t *this;
  165. INIT(this,
  166. .public = {
  167. .get_id = _get_id,
  168. .set_imv_id = _set_imv_id,
  169. .get_imv_id = _get_imv_id,
  170. .get_type = _get_type,
  171. .get_arg_str = _get_arg_str,
  172. .get_arg_int = _get_arg_int,
  173. .set_result = _set_result,
  174. .get_result = _get_result,
  175. .destroy = _destroy,
  176. },
  177. .id = id,
  178. .imv_id = TNC_IMVID_ANY,
  179. .type = type,
  180. .arg_str = arg_str ? strdup(arg_str) : NULL,
  181. .arg_int = arg_int,
  182. .rec_fail = rec_fail,
  183. .rec_noresult = rec_noresult,
  184. .rec_final = TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION,
  185. );
  186. return &this->public;
  187. }