auth.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include "auth.h"
  2. #include "../../parser/parse_event.h"
  3. #include "pa_mod.h"
  4. #include <string.h>
  5. #include <xcap/pres_rules.h>
  6. #include <cds/logger.h>
  7. /* Authorization */
  8. static watcher_status_t xcap_authorize(presentity_t *p, str *w_uri)
  9. {
  10. sub_handling_t sh;
  11. if (!p->authorization_info) {
  12. /* DBG("got empty set of authorization rules for %.*s\n",
  13. p->uri.len, ZSW(p->uri.s)); */
  14. return WS_PENDING;
  15. }
  16. /* process rules for given watcher's uri (w_uri) */
  17. sh = sub_handling_confirm;
  18. get_pres_rules_action(p->authorization_info, w_uri, &sh);
  19. switch (sh) {
  20. case sub_handling_block:
  21. DBG("XCAP AUTH: block\n");
  22. return WS_REJECTED;
  23. case sub_handling_confirm:
  24. DBG("XCAP AUTH: confirm\n");
  25. return WS_PENDING;
  26. case sub_handling_polite_block:
  27. DBG("XCAP AUTH: polite block\n");
  28. return WS_REJECTED;
  29. case sub_handling_allow:
  30. DBG("XCAP AUTH: allow\n");
  31. return WS_ACTIVE;
  32. }
  33. return WS_PENDING;
  34. }
  35. static watcher_status_t winfo_implicit_auth(presentity_t *p, watcher_t *w)
  36. {
  37. /* implicit authorization rules for watcher info */
  38. /*str_t p_user, w_user;
  39. if (get_user_from_uri(&p->uri, p_user) != 0) return WS_REJECTED;
  40. if (get_user_from_uri(&w->uri, w_user) != 0) return WS_REJECTED;*/
  41. if (str_case_equals(&p->data.uri, &w->uri) == 0) {
  42. DBG("winfo_implicit_auth(%.*s): enabled for %.*s\n",
  43. FMT_STR(p->data.uri), FMT_STR(w->uri));
  44. return WS_ACTIVE;
  45. }
  46. else {
  47. DBG("winfo_implicit_auth(%.*s): disabled for %.*s\n",
  48. FMT_STR(p->data.uri), FMT_STR(w->uri));
  49. return WS_REJECTED;
  50. }
  51. }
  52. watcher_status_t authorize_watcher(presentity_t *p, watcher_t *w)
  53. {
  54. if (w->event_package == EVENT_PRESENCE_WINFO) {
  55. switch (winfo_auth_params.type) {
  56. case auth_none: return WS_ACTIVE;
  57. case auth_implicit: return winfo_implicit_auth(p, w);
  58. case auth_xcap:
  59. ERROR_LOG("XCAP authorization for winfo is not implemented! "
  60. "Using \'implicit\' auth.\n");
  61. return winfo_implicit_auth(p, w);
  62. }
  63. }
  64. else {
  65. switch (pa_auth_params.type) {
  66. case auth_none: return WS_ACTIVE;
  67. case auth_implicit: return WS_PENDING;
  68. case auth_xcap: return xcap_authorize(p, &w->uri);
  69. }
  70. }
  71. return WS_PENDING;
  72. }
  73. watcher_status_t authorize_internal_watcher(presentity_t *p, internal_pa_subscription_t *is)
  74. {
  75. switch (pa_auth_params.type) {
  76. case auth_none: return WS_ACTIVE;
  77. case auth_implicit: return WS_PENDING;
  78. case auth_xcap: return xcap_authorize(p,
  79. get_subscriber_id(is->subscription));
  80. }
  81. return WS_PENDING;
  82. }