authrad_mod.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * $Id$
  3. *
  4. * Digest Authentication - Radius support
  5. *
  6. * Copyright (C) 2001-2003 FhG Fokus
  7. *
  8. * This file is part of ser, a free SIP server.
  9. *
  10. * ser is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version
  14. *
  15. * For a license to use the ser software under conditions
  16. * other than those described here, or to purchase support for this
  17. * software, please contact iptel.org by e-mail at the following addresses:
  18. * [email protected]
  19. *
  20. * ser is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  28. *
  29. * History:
  30. * -------
  31. * 2003-03-09: Based on auth_mod.c from radius_auth (janakj)
  32. * 2003-03-11: New module interface (janakj)
  33. * 2003-03-16: flags export parameter added (janakj)
  34. * 2003-03-19 all mallocs/frees replaced w/ pkg_malloc/pkg_free (andrei)
  35. */
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include <string.h>
  39. #include "../../sr_module.h"
  40. #include "../../error.h"
  41. #include "../../dprint.h"
  42. #include "../../mem/mem.h"
  43. #include "../../config.h"
  44. #include "authrad_mod.h"
  45. #include "authorize.h"
  46. #ifdef RADIUSCLIENT_NG_4
  47. # include <radiusclient.h>
  48. # else
  49. # include <radiusclient-ng.h>
  50. #endif
  51. MODULE_VERSION
  52. struct attr attrs[A_MAX];
  53. struct val vals[V_MAX];
  54. void *rh;
  55. auth_api_s_t auth_api;
  56. static int mod_init(void); /* Module initialization function */
  57. int use_did = 1;
  58. int use_ruri_flag = -1;
  59. /*
  60. * Module parameter variables
  61. */
  62. static char* radius_config = "/usr/local/etc/radiusclient/radiusclient.conf";
  63. static int service_type = -1;
  64. /*
  65. * Exported functions
  66. */
  67. static cmd_export_t cmds[] = {
  68. {"radius_www_authorize", radius_www_authorize, 1, fixup_var_str_1, REQUEST_ROUTE},
  69. {"radius_proxy_authorize", radius_proxy_authorize, 1, fixup_var_str_1, REQUEST_ROUTE},
  70. {"radius_www_authenticate", radius_www_authorize, 1, fixup_var_str_1, REQUEST_ROUTE},
  71. {"radius_proxy_authenticate", radius_proxy_authorize, 1, fixup_var_str_1, REQUEST_ROUTE},
  72. {0, 0, 0, 0, 0}
  73. };
  74. /*
  75. * Exported parameters
  76. */
  77. static param_export_t params[] = {
  78. {"radius_config", PARAM_STRING, &radius_config },
  79. {"service_type", PARAM_INT, &service_type },
  80. {"use_did", PARAM_INT, &use_did },
  81. {"use_ruri_flag", PARAM_INT, &use_ruri_flag },
  82. {0, 0, 0}
  83. };
  84. /*
  85. * Module interface
  86. */
  87. struct module_exports exports = {
  88. "auth_radius",
  89. cmds, /* Exported functions */
  90. 0, /* RPC methods */
  91. params, /* Exported parameters */
  92. mod_init, /* module initialization function */
  93. 0, /* response function */
  94. 0, /* destroy function */
  95. 0, /* oncancel function */
  96. 0 /* child initialization function */
  97. };
  98. /*
  99. * Module initialization function
  100. */
  101. static int mod_init(void)
  102. {
  103. DICT_VENDOR *vend;
  104. bind_auth_s_t bind_auth;
  105. DBG("auth_radius - Initializing\n");
  106. memset(attrs, 0, sizeof(attrs));
  107. memset(vals, 0, sizeof(vals));
  108. /* RFC2865, RFC2866 */
  109. attrs[A_USER_NAME].n = "User-Name";
  110. attrs[A_SERVICE_TYPE].n = "Service-Type";
  111. /* draft-sterman-aaa-sip-00 */
  112. attrs[A_DIGEST_RESPONSE].n = "Digest-Response";
  113. attrs[A_DIGEST_REALM].n = "Digest-Realm";
  114. attrs[A_DIGEST_NONCE].n = "Digest-Nonce";
  115. attrs[A_DIGEST_METHOD].n = "Digest-Method";
  116. attrs[A_DIGEST_URI].n = "Digest-URI";
  117. attrs[A_DIGEST_QOP].n = "Digest-QOP";
  118. attrs[A_DIGEST_ALGORITHM].n = "Digest-Algorithm";
  119. attrs[A_DIGEST_BODY_DIGEST].n = "Digest-Body-Digest";
  120. attrs[A_DIGEST_CNONCE].n = "Digest-CNonce";
  121. attrs[A_DIGEST_NONCE_COUNT].n = "Digest-Nonce-Count";
  122. attrs[A_DIGEST_USER_NAME].n = "Digest-User-Name";
  123. /* SER-specific */
  124. attrs[A_SER_URI_USER].n = "SER-Uri-User";
  125. attrs[A_SER_ATTR].n = "SER-Attr";
  126. attrs[A_SER_UID].n = "SER-UID";
  127. attrs[A_SER_SERVICE_TYPE].n = "SER-Service-Type";
  128. /* SER-Service-Type */
  129. vals[V_DIGEST_AUTHENTICATION].n = "Digest-Authentication";
  130. attrs[A_CISCO_AVPAIR].n = "Cisco-AVPair";
  131. /* draft-schulzrinne-sipping-radius-accounting-00 */
  132. vals[V_SIP_SESSION].n = "Sip-Session";
  133. if ((rh = rc_read_config(radius_config)) == NULL) {
  134. LOG(L_ERR, "auth_radius: Error opening configuration file \n");
  135. return -1;
  136. }
  137. if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary")) != 0) {
  138. LOG(L_ERR, "auth_radius: Error opening dictionary file \n");
  139. return -2;
  140. }
  141. vend = rc_dict_findvend(rh, "Cisco");
  142. if (vend == NULL) {
  143. DBG("auth_radius: No `Cisco' vendor in Radius "
  144. "dictionary\n");
  145. attrs[A_CISCO_AVPAIR].n = NULL;
  146. }
  147. vend = rc_dict_findvend(rh, "iptelorg");
  148. if (vend == NULL) {
  149. ERR("RADIUS dictionary is missing required vendor 'iptelorg'\n");
  150. return -1;
  151. }
  152. bind_auth = (bind_auth_s_t)find_export("bind_auth_s", 0, 0);
  153. if (!bind_auth) {
  154. LOG(L_ERR, "auth_radius: Unable to find bind_auth function\n");
  155. return -1;
  156. }
  157. if (bind_auth(&auth_api) < 0) {
  158. LOG(L_ERR, "auth_radius: Cannot bind to auth module\n");
  159. return -4;
  160. }
  161. INIT_AV(rh, attrs, vals, "auth_radius", -5, -6);
  162. if (service_type != -1) {
  163. vals[V_SIP_SESSION].v = service_type;
  164. }
  165. return 0;
  166. }