Back to index

nagios-plugins  1.4.16
radiusd.h
Go to the documentation of this file.
00001 /*
00002  *
00003  *     RADIUS
00004  *     Remote Authentication Dial In User Service
00005  *
00006  *
00007  *     Livingston Enterprises, Inc.
00008  *     6920 Koll Center Parkway
00009  *     Pleasanton, CA        94566
00010  *
00011  *     Copyright 1992 Livingston Enterprises, Inc.
00012  *     Copyright 1997 Cistron Internet Services B.V.
00013  *
00014  *     Permission to use, copy, modify, and distribute this software for any
00015  *     purpose and without fee is hereby granted, provided that this
00016  *     copyright and permission notice appear on all copies and supporting
00017  *     documentation, the name of Livingston Enterprises, Inc. not be used
00018  *     in advertising or publicity pertaining to distribution of the
00019  *     program without specific prior permission, and notice be given
00020  *     in supporting documentation that copying and distribution is by
00021  *     permission of Livingston Enterprises, Inc.   
00022  *
00023  *     Livingston Enterprises, Inc. makes no representations about
00024  *     the suitability of this software for any purpose.  It is
00025  *     provided "as is" without express or implied warranty.
00026  *
00027  */
00028 
00029 /*
00030  *     @(#)radiusd.h 2.1  04-Feb-1997
00031  */
00032 
00033 #include "sysdep.h"
00034 #include "radius.h"
00035 #include "conf.h"
00036 
00037 /* Server data structures */
00038 
00039 typedef struct dict_attr {
00040        char                 name[32];
00041        int                  value;
00042        int                  type;
00043        int                  vendor;
00044        struct dict_attr     *next;
00045 } DICT_ATTR;
00046 
00047 typedef struct dict_value {
00048        char                 attrname[32];
00049        char                 name[32];
00050        int                  value;
00051        struct dict_value    *next;
00052 } DICT_VALUE;
00053 
00054 typedef struct dict_vendor {
00055        char                 vendorname[32];
00056        int                  vendorpec;
00057        int                  vendorcode;
00058        struct dict_vendor   *next;
00059 } DICT_VENDOR;
00060 
00061 typedef struct value_pair {
00062        char                 name[32];
00063        int                  attribute;
00064        int                  type;
00065        int                  length; /* of strvalue */
00066        UINT4                lvalue;
00067        int                  operator;
00068        char                 strvalue[AUTH_STRING_LEN];
00069        struct value_pair    *next;
00070 } VALUE_PAIR;
00071 
00072 typedef struct auth_req {
00073        UINT4                ipaddr;
00074        u_short                     udp_port;
00075        u_char               id;
00076        u_char               code;
00077        u_char               vector[16];
00078        u_char               secret[16];
00079        u_char               username[AUTH_STRING_LEN];
00080        VALUE_PAIR           *request;
00081        int                  child_pid;    /* Process ID of child */
00082        UINT4                timestamp;
00083        u_char               *data;        /* Raw received data */
00084        int                  data_len;
00085        VALUE_PAIR           *proxy_pairs;
00086        /* Proxy support fields */
00087        u_char               realm[32];
00088        int                  validated;    /* Already md5 checked */
00089        UINT4                server_ipaddr;
00090        UINT4                server_id;
00091        VALUE_PAIR           *server_reply;       /* Reply from other server */
00092        int                  server_code;  /* Reply code from other srv */
00093        struct auth_req             *next;        /* Next active request */
00094 } AUTH_REQ;
00095 
00096 typedef struct client {
00097        UINT4                ipaddr;
00098        char                 longname[256];
00099        u_char               secret[16];
00100        char                 shortname[32];
00101        struct client        *next;
00102 } CLIENT;
00103 
00104 typedef struct nas {
00105        UINT4                ipaddr;
00106        char                 longname[256];
00107        char                 shortname[32];
00108        char                 nastype[32];
00109        struct nas           *next;
00110 } NAS;
00111 
00112 typedef struct realm {
00113        char                 realm[64];
00114        char                 server[64];
00115        UINT4                ipaddr;
00116        int                  auth_port;
00117        int                  acct_port;
00118        int                  striprealm;
00119        int                  dohints;
00120        struct realm         *next;
00121 } REALM;
00122 
00123 enum {
00124   PW_OPERATOR_EQUAL = 0,    /* = */
00125   PW_OPERATOR_NOT_EQUAL,    /* != */
00126   PW_OPERATOR_LESS_THAN,    /* < */
00127   PW_OPERATOR_GREATER_THAN, /* > */
00128   PW_OPERATOR_LESS_EQUAL,   /* <= */
00129   PW_OPERATOR_GREATER_EQUAL,       /* >= */
00130 };
00131 
00132 #define DEBUG if(debug_flag)log_debug
00133 #define DEBUG2  if (debug_flag > 1)log_debug
00134 
00135 #define SECONDS_PER_DAY            86400
00136 #define MAX_REQUEST_TIME    30
00137 #define CLEANUP_DELAY              5
00138 #define MAX_REQUESTS        255
00139 
00140 #define L_DBG               1
00141 #define L_AUTH                     2
00142 #define L_INFO                     3
00143 #define L_ERR               4
00144 #define L_PROXY                    5
00145 #define L_CONS                     128
00146 
00147 #if defined(DBM) || defined(NDBM)
00148 #define USE_DBM 1
00149 #endif
00150 
00151 #define VENDOR(x) (x >> 16)
00152 
00153 /*
00154  *     Global variables.
00155  */
00156 extern char          *recv_buffer;
00157 extern char          *send_buffer;
00158 extern char          *progname;
00159 extern int           debug_flag;
00160 extern char          *radacct_dir;
00161 extern char          *radius_dir;
00162 extern UINT4         expiration_seconds;
00163 extern UINT4         warning_seconds;
00164 extern int           radius_pid;
00165 extern int           use_dbm;
00166 extern int           log_stripped_names;
00167 extern int           cache_passwd;
00168 extern UINT4         myip;
00169 extern UINT4         warning_seconds;
00170 extern int           log_auth_detail;
00171 extern int           log_auth;
00172 extern int           log_auth_pass;
00173 extern int           auth_port;
00174 extern int           acct_port;
00175 
00176 /*
00177  *     Function prototypes.
00178  */
00179 
00180 /* acct.c */
00181 int           rad_accounting(AUTH_REQ *, int);
00182 int           rad_accounting_orig(AUTH_REQ *, int, char *);
00183 int           radzap(UINT4 nas, int port, char *user, time_t t);
00184 char          *uue(void *);
00185 int           rad_check_multi(char *name, VALUE_PAIR *request, int maxsimul);
00186 
00187 /* attrprint.c */
00188 void          fprint_attr_list(FILE *, VALUE_PAIR *);
00189 void          fprint_attr_val(FILE *, VALUE_PAIR *);
00190 
00191 /* dict.c */
00192 int           dict_init(char *);
00193 DICT_ATTR     *dict_attrget(int);
00194 DICT_ATTR     *dict_attrfind(char *);
00195 DICT_VALUE    *dict_valfind(char *);
00196 DICT_VALUE    *dict_valget(UINT4 value, char *);
00197 int           dict_vendorcode(int);
00198 int           dict_vendorpec(int);
00199 
00200 /* md5.c */
00201 
00202 void          md5_calc(u_char *, u_char *, u_int);
00203 
00204 /* radiusd.c */
00205 int           radius_exec_program(char *, VALUE_PAIR *, VALUE_PAIR **, int, char **user_msg);
00206 void          debug_pair(FILE *, VALUE_PAIR *);
00207 int           log_err (char *);
00208 void          sig_cleanup(int);
00209 
00210 /* util.c */
00211 char *        ip_hostname (UINT4);
00212 UINT4         get_ipaddr (char *);
00213 int           good_ipaddr(char *);
00214 void          ipaddr2str(char *, UINT4);
00215 void          pairfree(VALUE_PAIR *);
00216 UINT4         ipstr2long(char *);
00217 struct passwd *rad_getpwnam(char *);
00218 VALUE_PAIR    *pairfind(VALUE_PAIR *, int);
00219 void          pairdelete(VALUE_PAIR **, int);
00220 void          pairadd(VALUE_PAIR **, VALUE_PAIR *);
00221 void          authfree(AUTH_REQ *authreq);
00222 #if defined (sun) && defined(__svr4__)
00223 void          (*sun_signal(int signo, void (*func)(int)))(int);
00224 #define signal sun_signal
00225 #endif
00226 char          *strNcpy(char *dest, char *src, int n);
00227 
00228 /* radius.c */
00229 int           rad_send_reply(int, AUTH_REQ *, VALUE_PAIR *, char *, int);
00230 AUTH_REQ      *radrecv (UINT4, u_short, u_char *, int);
00231 int           calc_digest (u_char *, AUTH_REQ *);
00232 int           calc_acctdigest(u_char *digest, AUTH_REQ *authreq);
00233 
00234 /* files.c */
00235 int           user_find(char *name, VALUE_PAIR *,
00236                             VALUE_PAIR **, VALUE_PAIR **);
00237 int           userparse(char *buffer, VALUE_PAIR **first_pair);
00238 void          presuf_setup(VALUE_PAIR *request_pairs);
00239 int           hints_setup(VALUE_PAIR *request_pairs);
00240 int           huntgroup_access(VALUE_PAIR *request_pairs);
00241 CLIENT        *client_find(UINT4 ipno);
00242 char          *client_name(UINT4 ipno);
00243 int           read_clients_file(char *);
00244 REALM         *realm_find(char *);
00245 NAS           *nas_find(UINT4 ipno);
00246 char          *nas_name(UINT4 ipno);
00247 char          *nas_name2(AUTH_REQ *r);
00248 char          *auth_name(AUTH_REQ *authreq, int do_cid);
00249 int           read_naslist_file(char *);
00250 int           read_config_files(void);
00251 int           presufcmp(VALUE_PAIR *check, char *name, char *rest, int rl);
00252 void          pairmove(VALUE_PAIR **to, VALUE_PAIR **from);
00253 void          pairmove2(VALUE_PAIR **to, VALUE_PAIR **from, int attr);
00254 
00255 /* version.c */
00256 void          version();
00257 
00258 /* log.c */
00259 int           log(int, char *, ...);
00260 int           log_debug(char *, ...);
00261 
00262 /* pam.c */
00263 #ifdef PAM
00264 int           pam_pass(char *name, char *passwd, const char *pamauth);
00265 #define PAM_DEFAULT_TYPE    "radius"
00266 #endif
00267 
00268 /* proxy.c */
00269 int proxy_send(AUTH_REQ *authreq, int activefd);
00270 int proxy_receive(AUTH_REQ *authreq, int activefd);
00271 
00272 /* auth.c */
00273 int           rad_auth_init(AUTH_REQ *authreq, int activefd);
00274 int           rad_authenticate (AUTH_REQ *, int);
00275 
00276 /* exec.c */
00277 char          *radius_xlate(char *, VALUE_PAIR *req, VALUE_PAIR *reply);
00278 
00279 /* timestr.c */
00280 int           timestr_match(char *, time_t);
00281