00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef API_H
00031 #define API_H
00032
00033
00034 #include "../../parser/msg_parser.h"
00035 #include "../../parser/digest/digest.h"
00036 #include "../../sr_module.h"
00037 #include "../../usr_avp.h"
00038 #include "../../parser/hf.h"
00039 #include "../../str.h"
00040 #include "challenge.h"
00041 #include "rfc2617.h"
00042
00046 typedef enum auth_cfg_result {
00047 AUTH_USER_MISMATCH = -8,
00048 AUTH_NONCE_REUSED = -6,
00049 AUTH_NO_CREDENTIALS = -5,
00050 AUTH_STALE_NONCE = -4,
00051 AUTH_USER_UNKNOWN = -3,
00052 AUTH_INVALID_PASSWORD = -2,
00053 AUTH_ERROR = -1,
00054 AUTH_DROP = 0,
00055 AUTH_OK = 1
00056 } auth_cfg_result_t;
00057
00058
00062 typedef enum auth_result {
00063 NONCE_REUSED = -5,
00064 NO_CREDENTIALS,
00065 STALE_NONCE,
00066 ERROR,
00067 NOT_AUTHENTICATED,
00068 DO_AUTHENTICATION,
00069 AUTHENTICATED,
00070 BAD_CREDENTIALS,
00071 CREATE_CHALLENGE,
00072
00073
00074 DO_RESYNCHRONIZATION
00075
00076 } auth_result_t;
00077
00078
00079 typedef int (*check_auth_hdr_t)(struct sip_msg* msg, auth_body_t* auth_body,
00080 auth_result_t* auth_res);
00081 int check_auth_hdr(struct sip_msg* msg, auth_body_t* auth_body,
00082 auth_result_t* auth_res);
00083
00084
00085
00086
00087
00088
00089
00090 typedef auth_result_t (*pre_auth_t)(struct sip_msg* msg, str* realm,
00091 hdr_types_t hftype, struct hdr_field** hdr,
00092 check_auth_hdr_t check_auth_hdr);
00093 auth_result_t pre_auth(struct sip_msg* msg, str* realm, hdr_types_t hftype,
00094 struct hdr_field** hdr, check_auth_hdr_t check_auth_hdr);
00095
00096
00097
00098
00099
00100
00101 typedef auth_result_t (*post_auth_t)(struct sip_msg* msg,
00102 struct hdr_field* hdr);
00103 auth_result_t post_auth(struct sip_msg* msg, struct hdr_field* hdr);
00104
00105 typedef int (*check_response_t)(dig_cred_t* cred, str* method, char* ha1);
00106 int auth_check_response(dig_cred_t* cred, str* method, char* ha1);
00107
00108 typedef int (*auth_challenge_f)(struct sip_msg *msg, str *realm, int flags,
00109 int hftype);
00110 int auth_challenge(struct sip_msg *msg, str *realm, int flags,
00111 int hftype);
00112
00113 typedef int (*pv_authenticate_f)(struct sip_msg *msg, str *realm, str *passwd,
00114 int flags, int hftype);
00115 int pv_authenticate(struct sip_msg *msg, str *realm, str *passwd,
00116 int flags, int hftype);
00117
00118 typedef int (*consume_credentials_f)(struct sip_msg* msg);
00119 int consume_credentials(struct sip_msg* msg);
00120
00121
00122
00123
00124 typedef struct auth_api_s {
00125 pre_auth_t pre_auth;
00126 post_auth_t post_auth;
00127 build_challenge_hf_t build_challenge;
00128 struct qp* qop;
00129 calc_HA1_t calc_HA1;
00130 calc_response_t calc_response;
00131 check_response_t check_response;
00132 auth_challenge_f auth_challenge;
00133 pv_authenticate_f pv_authenticate;
00134 consume_credentials_f consume_credentials;
00135 } auth_api_s_t;
00136
00137 typedef int (*bind_auth_s_t)(auth_api_s_t* api);
00138 int bind_auth_s(auth_api_s_t* api);
00139
00143 static inline int auth_load_api(auth_api_s_t* api)
00144 {
00145 bind_auth_s_t bind_auth;
00146
00147
00148 bind_auth = (bind_auth_s_t)find_export("bind_auth_s", 0, 0);
00149 if (!bind_auth) {
00150 LM_ERR("unable to find bind_auth function. Check if you load"
00151 " the auth module.\n");
00152 return -1;
00153 }
00154
00155 if (bind_auth(api) < 0) {
00156 LM_ERR("unable to bind auth module\n");
00157 return -1;
00158 }
00159 return 0;
00160 }
00161
00162 #endif