static int auth_challenge(struct sip_msg *msg, char *p1, char *p2, int hftype) { int flags = 0; str realm = {0, 0}; int ret; str hf = {0, 0}; struct qp *qop = NULL; ret = -1; if (get_str_fparam(&realm, msg, (fparam_t*)p1) < 0) { LM_ERR("failed to get realm value\n"); goto error; } if(realm.len==0) { LM_ERR("invalid realm value - empty content\n"); goto error; } if (get_int_fparam(&flags, msg, (fparam_t*)p2) < 0) { LM_ERR("invalid flags value\n"); goto error; } if(flags&2) { qop = &auth_qauthint; } else if(flags&1) { qop = &auth_qauth; } if (get_challenge_hf(msg, 0, &realm, NULL, NULL, qop, hftype, &hf) < 0) { ERR("Error while creating challenge\n"); ret = -2; goto error; } ret = 1; switch(hftype) { case HDR_AUTHORIZATION_T: if(auth_send_reply(msg, 401, "Unauthorized", hf.s, hf.len) <0 ) ret = -3; break; case HDR_PROXYAUTH_T: if(auth_send_reply(msg, 407, "Proxy Authentication Required", hf.s, hf.len) <0 ) ret = -3; break; } if(hf.s) pkg_free(hf.s); return ret; error: if(hf.s) pkg_free(hf.s); if(!(flags&4)) { if(auth_send_reply(msg, 500, "Internal Server Error", 0, 0) <0 ) ret = -4; } return ret; }
int auth_challenge_helper(struct sip_msg *msg, str *realm, int flags, int hftype, str *res) { int ret, stale; str hf = {0, 0}; struct qp *qop = NULL; ret = -1; if(flags&2) { qop = &auth_qauthint; } else if(flags&1) { qop = &auth_qauth; } if (flags & 16) { stale = 1; } else { stale = 0; } if (get_challenge_hf(msg, stale, realm, NULL, NULL, qop, hftype, &hf) < 0) { ERR("Error while creating challenge\n"); ret = -2; goto error; } ret = 1; if(res!=NULL) { *res = hf; return ret; } switch(hftype) { case HDR_AUTHORIZATION_T: if(auth_send_reply(msg, 401, "Unauthorized", hf.s, hf.len) <0 ) ret = -3; break; case HDR_PROXYAUTH_T: if(auth_send_reply(msg, 407, "Proxy Authentication Required", hf.s, hf.len) <0 ) ret = -3; break; } if(hf.s) pkg_free(hf.s); return ret; error: if(hf.s) pkg_free(hf.s); if(!(flags&4)) { if(auth_send_reply(msg, 500, "Internal Server Error", 0, 0) <0 ) ret = -4; } return ret; }
static int www_challenge(struct sip_msg *msg, char* realm, char *flags) { int vflags = 0; str srealm = {0, 0}; if (get_str_fparam(&srealm, msg, (fparam_t*)realm) < 0) { LM_ERR("failed to get realm value\n"); goto error; } if(srealm.len==0) { LM_ERR("invalid realm value - empty content\n"); goto error; } if (get_int_fparam(&vflags, msg, (fparam_t*)flags) < 0) { LM_ERR("invalid flags value\n"); goto error; } return auth_challenge(msg, &srealm, vflags, HDR_AUTHORIZATION_T); error: if(!(vflags&4)) { if(auth_send_reply(msg, 500, "Internal Server Error", 0, 0) <0 ) return -4; } return -1; }
static int w_auth_challenge(struct sip_msg *msg, char* realm, char *flags) { int vflags = 0; str srealm = {0, 0}; if((msg->REQ_METHOD == METHOD_ACK) || (msg->REQ_METHOD == METHOD_CANCEL)) { return 1; } if(get_str_fparam(&srealm, msg, (fparam_t*)realm) < 0) { LM_ERR("failed to get realm value\n"); goto error; } if(srealm.len==0) { LM_ERR("invalid realm value - empty content\n"); goto error; } if(get_int_fparam(&vflags, msg, (fparam_t*)flags) < 0) { LM_ERR("invalid flags value\n"); goto error; } if(msg->REQ_METHOD==METHOD_REGISTER) return auth_challenge_hftype(msg, &srealm, vflags, HDR_AUTHORIZATION_T); else return auth_challenge_hftype(msg, &srealm, vflags, HDR_PROXYAUTH_T); error: if(!(vflags&4)) { if(auth_send_reply(msg, 500, "Internal Server Error", 0, 0) <0 ) return -4; } return -1; }