Commit 4cdf63eb authored by Pekka Pessi's avatar Pekka Pessi

iptsec module: added <auth_common.c> and <sofia_sip/auth_common.h>

Moved auth_get_params() and auth_struct_copy() from auth_digest.c to
auth_common.c. prototypes from <auth_digest.h> and <auth_plugin.h> to
<auth_common.h>

darcs-hash:20060519130756-65a35-82b788afc9e8769c387aef1208f926a3890cde64.gz
parent 4421c665
...@@ -43,151 +43,6 @@ ...@@ -43,151 +43,6 @@
#include "iptsec_debug.h" #include "iptsec_debug.h"
static inline int has_token(char const *qstring, char const *token);
/**
* Parse authentication parameters.
*
* The function auth_get_params() searches for the authentication parameters
* in @a params. The parameter list @a params is seached for each parameter
* given in in vararg section, and if it is found, its value is assigned to
* the given address.
*
* @note The field name should contain the equal ("=") sign.
*
* @return
* The function auth_get_params() returns number of parameters found in
* params, or -1 upon an error.
*/
int auth_get_params(su_home_t *home,
char const * const params[], ...
/* char const *fmt, char const **return_value */)
{
int n, j, len, namelen;
char const *fmt, *expected;
char const *value, *p, **return_value;
va_list(ap);
assert(params);
if (!params) return -1;
va_start(ap, params);
for (n = 0; (fmt = va_arg(ap, char const *));) {
return_value = va_arg(ap, char const **);
len = strlen(fmt);
if (!len)
continue;
namelen = strcspn(fmt, "=");
expected = fmt + namelen + 1;
value = NULL;
if (expected[0]) {
/* value match: format is name=expected,
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) {
/* Matched the whole parameter with fmt name=expected */
value = p;
break;
}
else if (strncasecmp(p, fmt, namelen) ||
p[namelen] != '=')
continue;
p = p + namelen + 1;
if (p[0] == '"' && has_token(p, expected)) {
/* Quoted parameter value has expected value,
* e.g., qop=auth matches qop="auth,auth-int" */
value = p;
break;
}
else if (strcasecmp(p, expected) == 0) {
/* Parameter value matches with extected value
* e.g., qop=auth matches qop=auth */
value = p;
break;
}
}
}
else {
/* format is name= , return unquoted parameter value after = */
for (j = 0; (p = params[j++]);) {
if (strncasecmp(p, fmt, len))
continue;
if (p[len] == '"')
value = msg_unquote_dup(home, p + len);
else
value = su_strdup(home, p + len);
if (value == NULL)
return -1;
break;
}
}
if (value) {
*return_value = value;
n++;
}
}
va_end(ap);
return n;
}
int auth_struct_copy(void *dst, void const *src, int s_size)
{
int d_size = *(int *)dst;
if (d_size > s_size) {
memcpy(dst, src, s_size);
memset((char *)dst + s_size, 0, d_size - s_size);
}
else {
memcpy(dst, src, d_size);
*(int *)dst = d_size;
}
return 0;
}
#if !HAVE_STRCASESTR
static inline char const *strcasestr(char const *haystack, char const *pin)
{
int i, m ,n;
m = strlen(haystack);
n = strlen(pin);
for (i = 0; i + n <= m; i++)
if (strncasecmp(haystack + i, pin, n) == 0)
break;
if (i + n <= m)
return haystack + i;
else
return NULL;
}
#endif
static inline int has_token(char const *qstring, char const *token)
{
int n = strlen(token);
char const *q;
q = strcasestr(qstring, token);
return (q &&
(q[n] == 0 || strchr("\", \t", q[n])) &&
(q == qstring || strchr("\", \t", q[-1])));
}
/**Get digest-challenge parameters. /**Get digest-challenge parameters.
* *
* The function digest_challenge_get() searches for the digest authentication * The function digest_challenge_get() searches for the digest authentication
......
/*
* This file is part of the Sofia-SIP package
*
* Copyright (C) 2005 Nokia Corporation.
*
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#ifndef AUTH_COMMON_H
/** Defined when <sofia-sip/auth_common.h> has been included. */
#define AUTH_COMMON_H
/**@file sofia-sip/auth_common.h
*
* Functions common for client/server.
*
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
*
* @date Created: Fri May 19 15:54:08 EEST 2006 ppessi
*/
#ifndef SU_ALLOC_H
#include <sofia-sip/su_alloc.h>
#endif
SOFIA_BEGIN_DECLS
SOFIAPUBFUN int auth_get_params(su_home_t *home,
char const * const params[], ...
/* char const * name,
char const **return_value */);
SOFIAPUBFUN int auth_struct_copy(void *dst, void const *src, int s_size);
SOFIAPUBFUN int auth_strcmp(char const *quoted, char const *unquoted);
SOFIA_END_DECLS
#endif
...@@ -160,6 +160,8 @@ SOFIAPUBFUN int auth_digest_response(auth_response_t *, auth_hexmd5_t response, ...@@ -160,6 +160,8 @@ SOFIAPUBFUN int auth_digest_response(auth_response_t *, auth_hexmd5_t response,
SOFIAPUBFUN int auth_struct_copy(void *dst, void const *src, int s_size); SOFIAPUBFUN int auth_struct_copy(void *dst, void const *src, int s_size);
SOFIAPUBFUN int auth_strcmp(char const *quoted, char const *unquoted);
SOFIA_END_DECLS SOFIA_END_DECLS
#endif #endif
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
/** Defined when <sofia-sip/auth_plugin.h> has been included. */ /** Defined when <sofia-sip/auth_plugin.h> has been included. */
#define AUTH_PLUGIN_H #define AUTH_PLUGIN_H
/**@file sofia-sip/auth_plugin.h /**@file sofia-sip/auth_plugin.h
* @brief Plugin interface for authentication verification modules. * @brief Plugin interface for authentication verification modules.
* *
...@@ -43,6 +42,10 @@ ...@@ -43,6 +42,10 @@
#include "sofia-sip/auth_digest.h" #include "sofia-sip/auth_digest.h"
#endif #endif
#ifndef AUTH_COMMON_H
#include "sofia-sip/auth_common.h"
#endif
#ifndef MSG_DATE_H #ifndef MSG_DATE_H
#include <sofia-sip/msg_date.h> #include <sofia-sip/msg_date.h>
#endif #endif
...@@ -252,11 +255,6 @@ int auth_validate_digest_nonce(auth_mod_t *am, ...@@ -252,11 +255,6 @@ int auth_validate_digest_nonce(auth_mod_t *am,
SOFIAPUBFUN int auth_allow_check(auth_mod_t *am, auth_status_t *as); SOFIAPUBFUN int auth_allow_check(auth_mod_t *am, auth_status_t *as);
SOFIAPUBFUN
int auth_get_params(su_home_t *home,
char const * const params[], ...
/* char const * name, char const **return_value */);
/** Init md5 for MD5-based HMAC */ /** Init md5 for MD5-based HMAC */
SOFIAPUBFUN void auth_md5_hmac_init(auth_mod_t *am, su_md5_t *md5); SOFIAPUBFUN void auth_md5_hmac_init(auth_mod_t *am, su_md5_t *md5);
SOFIAPUBFUN void auth_md5_hmac_digest(auth_mod_t *am, su_md5_t *md5, SOFIAPUBFUN void auth_md5_hmac_digest(auth_mod_t *am, su_md5_t *md5,
......
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