auth_api.c File Reference


Detailed Description

Proxy-CSCF - Auth API.

Note:
Taken from the auth_db SER module

Definition in file auth_api.c.

#include <string.h>
#include "auth_api.h"
#include "../../dprint.h"
#include "../../parser/digest/digest.h"
#include "../../sr_module.h"

Go to the source code of this file.

Functions

int find_credentials (struct sip_msg *_m, str *_realm, hdr_types_t _hftype, struct hdr_field **_h)
 Find credentials with given realm in a SIP message header.
int find_credentials_noparse (struct sip_msg *_m, str *realm, hdr_types_t _hftype, struct hdr_field **_h)
 Find credentials with given realm in a SIP message header without parsing the credentials - just find the right authorize with stupid byte by byte comparison Find credentials with given realm in a SIP message header.

Variables

static str realm_par = {"realm=\"",7}


Function Documentation

int find_credentials ( struct sip_msg *  _m,
str *  _realm,
hdr_types_t  _hftype,
struct hdr_field **  _h 
) [inline]

Find credentials with given realm in a SIP message header.

Parameters:
_m - the SIP message to look into
_realm - the realm to match in the authorization header
_hftype - the header type (HDR_AUTHORIZATION_T,HDR_PROXYAUTH_T)
_h - header pointer to fill with the match
Returns:
0 on success, 1 if not found
Note:
This function is taken from the auth module

Definition at line 58 of file auth_api.c.

00060 {
00061     struct hdr_field** hook, *ptr, *prev;
00062     hdr_flags_t hdr_flags;
00063     int res;
00064     str* r;
00065 
00066          /*
00067           * Determine if we should use WWW-Authorization or
00068           * Proxy-Authorization header fields, this parameter
00069           * is set in www_authorize and proxy_authorize
00070           */
00071     switch(_hftype) {
00072     case HDR_AUTHORIZATION_T: 
00073                             hook = &(_m->authorization);
00074                             hdr_flags=HDR_AUTHORIZATION_F;
00075                             break;
00076     case HDR_PROXYAUTH_T:
00077                             hook = &(_m->proxy_auth);
00078                             hdr_flags=HDR_PROXYAUTH_F;
00079                             break;
00080     default:                
00081                             hook = &(_m->authorization);
00082                             hdr_flags=HDR_T2F(_hftype);
00083                             break;
00084     }
00085 
00086          /*
00087           * If the credentials haven't been parsed yet, do it now
00088           */
00089     if (*hook == 0) {
00090              /* No credentials parsed yet */
00091         if (parse_headers(_m, hdr_flags, 0) == -1) {
00092             LOG(L_ERR, "find_credentials(): Error while parsing headers\n");
00093             return -1;
00094         }
00095     }
00096 
00097     ptr = *hook;
00098 
00099          /*
00100           * Iterate through the credentials in the message and
00101           * find credentials with given realm
00102           */
00103     while(ptr) {
00104         res = parse_credentials(ptr);
00105         ptr->type = HDR_AUTHORIZATION_T;
00106         if (res < 0) {
00107             LOG(L_ERR, "find_credentials(): Error while parsing credentials\n");
00108             return (res == -1) ? -2 : -3;
00109         } else if (res == 0) {
00110             if (_realm->len) {
00111                 r = &(((auth_body_t*)(ptr->parsed))->digest.realm);
00112     
00113                 if (r->len == _realm->len) {
00114                     if (!strncasecmp(_realm->s, r->s, r->len)) {
00115                         *_h = ptr;
00116                         return 0;
00117                     }
00118                 }
00119             }
00120             else {
00121                 *_h = ptr;
00122                 return 0;
00123             }
00124             
00125         }
00126 
00127         prev = ptr;
00128         if (parse_headers(_m, hdr_flags, 1) == -1) {
00129             LOG(L_ERR, "find_credentials(): Error while parsing headers\n");
00130             return -4;
00131         } else {
00132             if (prev != _m->last_header) {
00133                 if (_m->last_header->type == _hftype) ptr = _m->last_header;
00134                 else break;
00135             } else break;
00136         }
00137     }
00138     
00139          /*
00140           * Credentials with given realm not found
00141           */
00142     return 1;
00143 }

int find_credentials_noparse ( struct sip_msg *  _m,
str *  realm,
hdr_types_t  _hftype,
struct hdr_field **  _h 
) [inline]

Find credentials with given realm in a SIP message header without parsing the credentials - just find the right authorize with stupid byte by byte comparison Find credentials with given realm in a SIP message header.

Parameters:
_m - the SIP message to look into
realm - the realm to match in the authorization header
_hftype - the header type (HDR_AUTHORIZATION_T,HDR_PROXYAUTH_T)
_h - header pointer to fill with the match
Returns:
0 on success, 1 if not found
Note:
This function is taken from the auth module

Definition at line 158 of file auth_api.c.

References if, and realm_par.

00160 {
00161     struct hdr_field** hook, *ptr, *prev;
00162     hdr_flags_t hdr_flags;
00163     int i,k;
00164 
00165          /*
00166           * Determine if we should use WWW-Authorization or
00167           * Proxy-Authorization header fields, this parameter
00168           * is set in www_authorize and proxy_authorize
00169           */
00170     switch(_hftype) {
00171     case HDR_AUTHORIZATION_T: 
00172                             hook = &(_m->authorization);
00173                             hdr_flags=HDR_AUTHORIZATION_F;
00174                             break;
00175     case HDR_PROXYAUTH_T:
00176                             hook = &(_m->proxy_auth);
00177                             hdr_flags=HDR_PROXYAUTH_F;
00178                             break;
00179     default:                
00180                             hook = &(_m->authorization);
00181                             hdr_flags=HDR_T2F(_hftype);
00182                             break;
00183     }
00184 
00185          /*
00186           * If the credentials haven't been parsed yet, do it now
00187           */
00188     if (*hook == 0) {
00189              /* No credentials parsed yet */
00190         if (parse_headers(_m, hdr_flags, 0) == -1) {
00191             LOG(L_ERR, "find_credentials(): Error while parsing headers\n");
00192             return -1;
00193         }
00194     }
00195 
00196     ptr = *hook;
00197 
00198          /*
00199           * Iterate through the credentials in the message and
00200           * find credentials with given realm
00201           */
00202     while(ptr) {
00203         k = ptr->body.len - realm_par.len - realm->len;
00204         for(i=0;i<k;i++)
00205          if (strncasecmp(ptr->body.s+i,realm_par.s,realm_par.len)==0){
00206             if (strncasecmp(ptr->body.s+i+realm_par.len,realm->s,realm->len)==0){
00207                 *_h = ptr;
00208                 return 0;       
00209             } 
00210             else 
00211                 break;      
00212          }
00213             
00214         
00215         prev = ptr;
00216         if (parse_headers(_m, hdr_flags, 1) == -1) {
00217             LOG(L_ERR, "find_credentials(): Error while parsing headers\n");
00218             return -4;
00219         } else {
00220             if (prev != _m->last_header) {
00221                 if (_m->last_header->type == _hftype) ptr = _m->last_header;
00222                 else break;
00223             } else break;
00224         }
00225     }
00226     
00227          /*
00228           * Credentials with given realm not found
00229           */
00230     return 1;
00231 }


Variable Documentation

str realm_par = {"realm=\"",7} [static]

Definition at line 145 of file auth_api.c.

Referenced by find_credentials_noparse().


Generated on Thu Oct 23 04:14:40 2008 for Open IMS Core CSCFs by  doxygen 1.5.2