Commit 1a6820b0 authored by Pekka Pessi's avatar Pekka Pessi

iptsec: using <sofia-sip/su_string.h> functions

darcs-hash:20090108195053-db55f-957f59b5698aa3311458fc039f4c0c46de8c3c6e.gz
parent 582cbd3b
......@@ -47,7 +47,7 @@
#include <sofia-sip/base64.h>
#include <sofia-sip/su_uniqueid.h>
#include <sofia-sip/string0.h>
#include <sofia-sip/su_string.h>
#include <sofia-sip/su_debug.h>
......@@ -166,9 +166,9 @@ int ca_challenge(auth_client_t *ca,
if (!ca || !ch)
return -1;
if (strcasecmp(ca->ca_scheme, scheme))
if (!su_casematch(ca->ca_scheme, scheme))
return 0;
if (strcmp(ca->ca_realm, realm))
if (!su_strmatch(ca->ca_realm, realm))
return 0;
if (ca->ca_credential_class &&
......@@ -390,13 +390,13 @@ int ca_credentials(auth_client_t *ca,
if (!ca || !ca->ca_scheme || !ca->ca_realm)
return -1;
if ((scheme != NULL && strcasecmp(scheme, ca->ca_scheme)) ||
(realm != NULL && strcmp(realm, ca->ca_realm)))
if ((scheme != NULL && !su_casematch(scheme, ca->ca_scheme)) ||
(realm != NULL && !su_strmatch(realm, ca->ca_realm)))
return 0;
old_user = ca->ca_user, old_pass = ca->ca_pass;
if (str0cmp(user, old_user) == 0 && str0cmp(pass, old_pass) == 0)
if (su_strmatch(user, old_user) && su_strmatch(pass, old_pass))
return 0;
new_user = su_strdup(ca->ca_home, user);
......@@ -440,14 +440,14 @@ int auc_copy_credentials(auth_client_t **dst,
continue;
if (AUTH_CLIENT_IS_EXTENDED(ca) && ca->ca_clear)
continue;
if (!ca->ca_scheme[0] || strcasecmp(ca->ca_scheme, d->ca_scheme))
if (!ca->ca_scheme[0] || !su_casematch(ca->ca_scheme, d->ca_scheme))
continue;
if (!ca->ca_realm[0] || strcmp(ca->ca_realm, d->ca_realm))
if (!ca->ca_realm || !su_strmatch(ca->ca_realm, d->ca_realm))
continue;
if (!(AUTH_CLIENT_IS_EXTENDED(d) && d->ca_clear) &&
d->ca_user && strcmp(d->ca_user, ca->ca_user) == 0 &&
d->ca_pass && strcmp(d->ca_pass, ca->ca_pass) == 0) {
su_strmatch(d->ca_user, ca->ca_user) &&
su_strmatch(d->ca_pass, ca->ca_pass)) {
retval++;
break;
}
......@@ -497,8 +497,8 @@ int auc_clear_credentials(auth_client_t **auc_list,
if (!AUTH_CLIENT_IS_EXTENDED(ca))
continue;
if ((scheme != NULL && strcasecmp(scheme, ca->ca_scheme)) ||
(realm != NULL && strcmp(realm, ca->ca_realm)))
if ((scheme != NULL && !su_casematch(scheme, ca->ca_scheme)) ||
(realm != NULL && !su_strmatch(realm, ca->ca_realm)))
continue;
match = ca->ca_auc->auc_clear(*auc_list);
......@@ -990,7 +990,7 @@ int auc_register_plugin(auth_client_plugin_t const *plugin)
for (i = 0; i < MAX_AUC; i++) {
if (ca_plugins[i] == NULL ||
strcmp(plugin->auc_name, ca_plugins[i]->auc_name) == 0) {
su_strmatch(plugin->auc_name, ca_plugins[i]->auc_name) == 0) {
ca_plugins[i] = plugin;
return 0;
}
......@@ -1018,7 +1018,7 @@ auth_client_t *ca_create(su_home_t *home,
for (i = 0; i < MAX_AUC; i++) {
auc = ca_plugins[i];
if (!auc || strcasecmp(auc->auc_name, scheme) == 0)
if (!auc || su_casematch(auc->auc_name, scheme))
break;
}
......
......@@ -44,7 +44,7 @@
#include <sofia-sip/base64.h>
#include <sofia-sip/su_uniqueid.h>
#include <sofia-sip/string0.h>
#include <sofia-sip/su_string.h>
#include <sofia-sip/su_debug.h>
......
......@@ -36,16 +36,13 @@
#include "sofia-sip/auth_common.h"
#include "sofia-sip/msg_header.h"
#include <sofia-sip/su_string.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <assert.h>
#if !HAVE_STRCASESTR
char *strcasestr(char const *haystack, char const *needle);
#endif
su_inline int has_token(char const *qstring, char const *token);
/**
......@@ -92,12 +89,12 @@ issize_t auth_get_params(su_home_t *home,
if expected is found in parameter value,
return non-NULL pointer in *return_value */
for (j = 0; (p = params[j++]);) {
if (strcasecmp(p, fmt) == 0) {
if (su_casematch(p, fmt)) {
/* Matched the whole parameter with fmt name=expected */
value = p;
break;
}
else if (strncasecmp(p, fmt, namelen) ||
else if (!su_casenmatch(p, fmt, namelen) ||
p[namelen] != '=')
continue;
......@@ -109,7 +106,7 @@ issize_t auth_get_params(su_home_t *home,
value = p;
break;
}
else if (strcasecmp(p, expected) == 0) {
else if (su_casematch(p, expected)) {
/* Parameter value matches with extected value
* e.g., qop=auth matches qop=auth */
value = p;
......@@ -120,7 +117,7 @@ issize_t auth_get_params(su_home_t *home,
else {
/* format is name= , return unquoted parameter value after = */
for (j = 0; (p = params[j++]);) {
if (strncasecmp(p, fmt, len))
if (!su_casenmatch(p, fmt, len))
continue;
if (p[len] == '"')
......@@ -169,7 +166,8 @@ su_inline int has_token(char const *qstring, char const *token)
size_t n = strlen(token);
char const *q;
q = strcasestr(qstring, token);
q = su_strcasestr(qstring, token);
return (q &&
(q[n] == 0 || strchr("\", \t", q[n])) &&
(q == qstring || strchr("\", \t", q[-1])));
......
......@@ -61,6 +61,7 @@ static char const __func__[] = "auth_mod";
#include <sofia-sip/su_wait.h>
#include <sofia-sip/su_alloc.h>
#include <sofia-sip/su_string.h>
#include <sofia-sip/su_tagarg.h>
#include <sofia-sip/base64.h>
......@@ -181,7 +182,7 @@ int auth_init_default(auth_mod_t *am,
am->am_fake = fake;
am->am_remote = url_hdup(am->am_home, (url_t *)remote);
am->am_algorithm = algorithm ? su_strdup(am->am_home, algorithm) : "MD5";
am->am_nextnonce = !algorithm || strcasecmp(algorithm, "MD5") == 0;
am->am_nextnonce = !algorithm || su_casematch(algorithm, "MD5");
if (next_expires == 0)
am->am_nextnonce = 0;
am->am_qop = su_strdup(am->am_home, qop);
......@@ -694,11 +695,11 @@ void auth_check_digest(auth_mod_t *am,
/* Check for qop */
(ar->ar_qop &&
((ar->ar_auth &&
strcasecmp(ar->ar_qop, "auth") &&
strcasecmp(ar->ar_qop, "\"auth\"")) ||
!su_casematch(ar->ar_qop, "auth") &&
!su_casematch(ar->ar_qop, "\"auth\"")) ||
(ar->ar_auth_int &&
strcasecmp(ar->ar_qop, "auth-int") &&
strcasecmp(ar->ar_qop, "\"auth-int\"")))
!su_casematch(ar->ar_qop, "auth-int") &&
!su_casematch(ar->ar_qop, "\"auth-int\"")))
&& (phrase = PA "has invalid qop"))) {
assert(phrase);
SU_DEBUG_5(("auth_method_digest: 400 %s\n", phrase));
......@@ -1249,7 +1250,7 @@ msg_auth_t *auth_mod_credentials(msg_auth_t *auth,
char const *arealm;
for (;auth; auth = auth->au_next) {
if (strcasecmp(auth->au_scheme, scheme))
if (!su_casematch(auth->au_scheme, scheme))
continue;
if (!realm)
......@@ -1290,7 +1291,7 @@ msg_auth_t *auth_digest_credentials(msg_auth_t *auth,
char const *arealm, *aopaque;
for (;auth; auth = auth->au_next) {
if (strcasecmp(auth->au_scheme, "Digest"))
if (!su_casematch(auth->au_scheme, "Digest"))
continue;
if (realm) {
......
......@@ -91,7 +91,7 @@ issize_t auth_ntlm_challenge_get(su_home_t *home,
if (n < 0)
return n;
if (ac->ac_stale && strcasecmp(ac->ac_stale, "true") != 0)
if (ac->ac_stale && !su_casematch(ac->ac_stale, "true"))
ac->ac_stale = NULL;
ac->ac_md5 = md5 != NULL || ac->ac_algorithm == NULL;
......
......@@ -52,6 +52,7 @@ static char const __func__[] = "auth_plugin";
#include <sofia-sip/su_wait.h>
#include <sofia-sip/su_alloc.h>
#include <sofia-sip/su_string.h>
#include <sofia-sip/su_tagarg.h>
#include "sofia-sip/auth_module.h"
......@@ -130,16 +131,16 @@ auth_mod_t *auth_mod_create(su_root_t *root,
if (base == NULL)
;
else if (strcasecmp(base, "Basic") == 0)
else if (su_casematch(base, "Basic"))
bscheme = auth_scheme_basic;
else if (strcasecmp(base, "Digest") == 0)
else if (su_casematch(base, "Digest"))
bscheme = auth_scheme_digest;
if (base == NULL || bscheme) {
int i;
for (i = 0; schemes[i] && i < N; i++) {
if (strncasecmp(schemes[i]->asch_method, method, len) == 0 &&
if (su_casenmatch(schemes[i]->asch_method, method, len) &&
schemes[i]->asch_method[len] == 0) {
am = auth_mod_alloc(schemes[i], ta_tags(ta));
if (schemes[i]->asch_init(am, bscheme, root, ta_tags(ta)) == -1) {
......
......@@ -170,7 +170,7 @@ msg_auth_t *auth_ntlm_credentials(msg_auth_t *auth,
char const *agssapidata, *atargetname;
for (;auth; auth = auth_mod_credentials(auth->au_next)) {
if (strcasecmp(auth->au_scheme, "NTLM"))
if (!su_casematch(auth->au_scheme, "NTLM"))
continue;
if (gssapidata) {
......@@ -224,11 +224,11 @@ void auth_check_ntlm(auth_mod_t *am,
/* Check for qop */
(ar->ar_qop &&
((ar->ar_auth &&
strcasecmp(ar->ar_qop, "auth") &&
strcasecmp(ar->ar_qop, "\"auth\"")) ||
!su_casematch(ar->ar_qop, "auth") &&
!su_casematch(ar->ar_qop, "\"auth\"")) ||
(ar->ar_auth_int &&
strcasecmp(ar->ar_qop, "auth-int") &&
strcasecmp(ar->ar_qop, "\"auth-int\"")))
!su_casematch(ar->ar_qop, "auth-int") &&
!su_casematch(ar->ar_qop, "\"auth-int\"")))
&& (phrase = PA "has invalid qop"))) {
assert(phrase);
SU_DEBUG_5(("auth_method_ntlm: 400 %s\n", phrase));
......
......@@ -73,6 +73,7 @@
#include <sofia-sip/auth_client.h>
#include <sofia-sip/msg_header.h>
#include <sofia-sip/su_wait.h>
#include <sofia-sip/su_string.h>
int tstflags;
char *argv0;
......@@ -349,8 +350,11 @@ Authorization: Digest username="Mufasa",
TEST_SIZE(auth_digest_challenge_get(home, ac, pa->au_params), 6);
TEST0(pz = sip_proxy_authorization_make(home, cred));
TEST_SIZE(auth_digest_response_get(home, ar, pz->au_params), 8);
{
size_t n = auth_digest_response_get(home, ar, pz->au_params);
TEST_SIZE(n, 8);
}
ar->ar_md5 = ac->ac_md5 || ac->ac_algorithm == NULL;
TEST(auth_digest_sessionkey(ar, sessionkey, "test1"), 0);
......@@ -702,7 +706,7 @@ int test_digest_client()
if (au->au_params)
for (i = 0; au->au_params[i]; i++) {
if (strncasecmp(au->au_params[i], "realm=", 6) == 0)
if (su_casenmatch(au->au_params[i], "realm=", 6))
continue;
equal = strchr(au->au_params[i], '=');
if (equal)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment