How to extract A/V pairs from an Access-Request packet

classic Classic list List threaded Threaded
4 messages Options
| Threaded
Open this post in threaded view
|

How to extract A/V pairs from an Access-Request packet

Maria Ripolles
Hy all,
 
I am developing a custom module and I am a bit lost with the code. I am not a C programmer so sorry if my question is very stupid.
 
I want to extract the differents A/V pairs contained in the Access-Request packets and check if any of them is the attribute "Connect-Info". In that case I would like to pass the value of the "Connect-Info" attribute to a function called auxiliar.
Here is my code:
 
static int auxiliar (char * value) { ..... }
 
static int mymodule_authorize (void *instance, REQUEST *request) {
     ....
 
     VALUE_PAIR *request_pairs;
     request_pairs=request->packet->vps;
 
     VALUE_PAIR *aux = NULL;
 
     char * Attribute_Name = NULL;
     char *Attribute_Value = NULL;
     int type = 0;
 
     for ( aux=request_pairs; aux; aux=aux->next)
     {
          Attribute_Name = aux->name;
          Attribute_Value = aux->strvalue;
 
          if (aux->attribute == PW_CONNECT_INFO)
          {
               type=auxiliar(aux->strvalue); /* is this correct? I mean, is aux->strvalue a char * type? */
          }
 
          .....
     }
 
 
 
Am I on the right track?
 
Thank you a lot for your help and best regards



LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y moviles desde 1 centimo por minuto.
http://es.voice.yahoo.com

-
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html
| Threaded
Open this post in threaded view
|

Re: How to extract A/V pairs from an Access-Request packet

Joe Maimon


Maria Ripolles wrote:

>
> Hy all,
>  
> I am developing a custom module

Perhaps what you are doing can be done via a shell script called with
the exec module?

> and I am a bit lost with the code. I am
> not a C programmer so sorry if my question is very stupid.

Well its not going to be peaches and cream for you then.

>  
> I want to extract the differents A/V pairs contained in the
> Access-Request packets and check if any of them is the attribute
> "Connect-Info". In that case I would like to pass the value of the
> "Connect-Info" attribute to a function called auxiliar.
> Here is my code:
>  
> static int auxiliar (char * value) { ..... }
>  
> static int mymodule_authorize (void *instance, REQUEST *request) {
>      ....
>  
>      VALUE_PAIR *request_pairs;
>      request_pairs=request->packet->vps;
>  
>      VALUE_PAIR *aux = NULL;
>  
>      char * Attribute_Name = NULL;
>      char *Attribute_Value = NULL;
>      int type = 0;
>  
>      for ( aux=request_pairs; aux; aux=aux->next)
>      {
>           Attribute_Name = aux->name;
>           Attribute_Value = aux->strvalue;
>  
>           if (aux->attribute == PW_CONNECT_INFO)
>           {
>                type=auxiliar(aux->strvalue); /* is this correct? I mean,
> is aux->strvalue a char * type? */
>           }
>  
>           .....
>      }
>  
>  
>  

strvalue is a char * in older versions. In CVS head its a union and you
can access it (due to a compatibility macro) by vp->vp_strvalue the last
time I looked.

you can use the pairfind() function to find the attribute you are
looking for.

Consider that Connect-info may appear zero or more times in a request.

> Am I on the right track?

Eyeball review suggests that your code might work.

>  
> Thank you a lot for your help and best regards
>
>
> LLama Gratis a cualquier PC del Mundo.
> Llamadas a fijos y moviles desde 1 centimo por minuto.
> http://es.voice.yahoo.com 
> <http://us.rd.yahoo.com/mail/es/tagline/messenger/*http://es.voice.yahoo.com/>
>
>
>
> ------------------------------------------------------------------------
>
> -
> List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html
-
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html
| Threaded
Open this post in threaded view
|

Re: How to extract A/V pairs from an Access-Request packet

Maria Ripolles
Thank you very much Joe for your very very fast response :-)

Joe Maimon <[hidden email]> escribió:


Maria Ripolles wrote:

>
> Hy all,
>
> I am developing a custom module

Perhaps what you are doing can be done via a shell script called with
the exec module?

> and I am a bit lost with the code. I am
> not a C programmer so sorry if my question is very stupid.

Well its not going to be peaches and cream for you then.

>
> I want to extract the differents A/V pairs contained in the
> Access-Request packets and check if any of them is the attribute
> "Connect-Info". In that case I would like to pass the value of the
> "Connect-Info" attribute to a function called auxiliar.
> Here is my code:
>
> static int ! auxiliar (char * value) { ..... }
>
> static int mymodule_authorize (void *instance, REQUEST *request) {
> ....
>
> VALUE_PAIR *request_pairs;
> request_pairs=request->packet->vps;
>
> VALUE_PAIR *aux = NULL;
>
> char * Attribute_Name = NULL;
> char *Attribute_Value = NULL;
> int type = 0;
>
> for ( aux=request_pairs; aux; aux=aux->next)
> {
> Attribute_Name = aux->name;
> Attribute_Value = aux->strvalue;
>
> if (aux->attribute == PW_CONNECT_INFO)
> {
> type=auxiliar(aux->strvalue); /* is this correct? I mean,
> is aux->strvalue a char * type? */
> }
>
> .....
> }
>
>
>

strvalue is a char * in older versions. In CVS head its a union and you
can access it (due to a compatibility macro) by vp->vp_strvalue the last
time I looked.

you can use the pairfind()! function to find the attribute you are
looking for.

Consider that Connect-info may appear zero or more times in a request.

> Am I on the right track?

Eyeball review suggests that your code might work.

>
> Thank you a lot for your help and best regards
>
>
> LLama Gratis a cualquier PC del Mundo.
> Llamadas a fijos y moviles desde 1 centimo por minuto.
> http://es.voice.yahoo.com
>
>
>
>
> ------------------------------------------------------------------------
>
> -
> List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html
-
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html



LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y moviles desde 1 centimo por minuto.
http://es.voice.yahoo.com

-
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html
| Threaded
Open this post in threaded view
|

Re: How to extract A/V pairs from an Access-Request packet

Alan DeKok
In reply to this post by Maria Ripolles
Maria Ripolles <[hidden email]> wrote:
>        for ( aux=request_pairs; aux; aux=aux->next)
>        {
>             Attribute_Name = aux->name;
>             Attribute_Value = aux->strvalue;
>    
>             if (aux->attribute == PW_CONNECT_INFO)

  Use the "pairfind" function.  See the existing code for examples.

static int mymodule_authorize (void *instance, REQUEST *request) {
   VALUE_PAIR *vp;
   ...

  vp = pairfind(request->packet->vps, PW_CONNECT_INFO);
  if (vp) {
     type = auxiliar (vp->strvalue);
  }


  Alan DeKok.
-
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html