radlib_private.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*-
  2. * SPDX-License-Identifier: BSD-2-Clause
  3. *
  4. * Copyright 1998 Juniper Networks, Inc.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  17. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  20. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  22. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  23. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  24. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  25. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  26. * SUCH DAMAGE.
  27. */
  28. #ifndef RADLIB_PRIVATE_H
  29. #define RADLIB_PRIVATE_H
  30. #include <sys/types.h>
  31. #include <netinet/in.h>
  32. #include "radlib.h"
  33. #include "radlib_vs.h"
  34. /* Handle types */
  35. #define RADIUS_AUTH 0 /* RADIUS authentication, default */
  36. #define RADIUS_ACCT 1 /* RADIUS accounting */
  37. #define RADIUS_SERVER 2 /* RADIUS server */
  38. /* Defaults */
  39. #define MAXTRIES 3
  40. #define PATH_RADIUS_CONF "/etc/radius.conf"
  41. #define RADIUS_PORT 1812
  42. #define RADACCT_PORT 1813
  43. #define TIMEOUT 3 /* In seconds */
  44. #define DEAD_TIME 0
  45. /* Limits */
  46. #define ERRSIZE 128 /* Maximum error message length */
  47. #define MAXCONFLINE 1024 /* Maximum config file line length */
  48. #define MAXSERVERS 10 /* Maximum number of servers to try */
  49. #define MSGSIZE 4096 /* Maximum RADIUS message */
  50. #define PASSSIZE 128 /* Maximum significant password chars */
  51. /* Positions of fields in RADIUS messages */
  52. #define POS_CODE 0 /* Message code */
  53. #define POS_IDENT 1 /* Identifier */
  54. #define POS_LENGTH 2 /* Message length */
  55. #define POS_AUTH 4 /* Authenticator */
  56. #define LEN_AUTH 16 /* Length of authenticator */
  57. #define POS_ATTRS 20 /* Start of attributes */
  58. struct rad_server {
  59. struct sockaddr_in addr; /* Address of server */
  60. char *secret; /* Shared secret */
  61. int timeout; /* Timeout in seconds */
  62. int max_tries; /* Number of tries before giving up */
  63. int num_tries; /* Number of tries so far */
  64. int is_dead; /* The server did not answer last time */
  65. time_t dead_time; /* Don't try this server for the time period if it is dead */
  66. time_t next_probe; /* Time of a next probe after failure */
  67. in_addr_t bindto; /* Bind to address */
  68. };
  69. struct rad_handle {
  70. int fd; /* Socket file descriptor */
  71. struct rad_server servers[MAXSERVERS]; /* Servers to contact */
  72. int num_servers; /* Number of valid server entries */
  73. int ident; /* Current identifier value */
  74. char errmsg[ERRSIZE]; /* Most recent error message */
  75. unsigned char out[MSGSIZE]; /* Request to send */
  76. char out_created; /* rad_create_request() called? */
  77. int out_len; /* Length of request */
  78. char pass[PASSSIZE]; /* Cleartext password */
  79. int pass_len; /* Length of cleartext password */
  80. int pass_pos; /* Position of scrambled password */
  81. char chap_pass; /* Have we got a CHAP_PASSWORD ? */
  82. int authentic_pos; /* Position of message authenticator */
  83. char eap_msg; /* Are we an EAP Proxy? */
  84. unsigned char in[MSGSIZE]; /* Response received */
  85. int in_len; /* Length of response */
  86. int in_pos; /* Current position scanning attrs */
  87. int srv; /* Server number we did last */
  88. int type; /* Handle type */
  89. in_addr_t bindto; /* Current bind address */
  90. };
  91. struct vendor_attribute {
  92. u_int32_t vendor_value;
  93. u_char attrib_type;
  94. u_char attrib_len;
  95. u_char attrib_data[1];
  96. };
  97. #endif