[OpenSER-Users] Hints about to capture codes negative www_authorize??

Bogdan-Andrei Iancu bogdan at voice-system.ro
Fri May 30 22:49:17 CEST 2008


Hi Marcio,

yes, your guess is correct - the $rc pv changes after each command you 
run, so in switch() it will contain the return code of log().

Try something like:
  
 www_authorize("rio.voip.br <http://rio.voip.br>", "subscriber");
$var(x) = $rc;

if ($rc<0) {
    xlog("L_ALERT", "REGISTER ($fU)($ru) nao autorizado - Return Code 
DEPOIS.0 ($var(x))\n");

    switch($var(x)){
            case -1:
                log(1,"Invalid User\n");
    .........
}

regards,
Bogdan

Marcio wrote:
> Hi,
>
> Thx for the answer, I tested and worked....but with errors...in 
> relation to return codes of the Authentication's Module...
>
> In my xlite I just changed the password...should have returned the 
> code (-2)...but returned the codes (-4) and (-5).....pls see below the 
> log....in red
>
> ......
> May 30 15:29:28 i206529 openser[24649]: Return Code - ANTES (1)
> May 30 15:29:28 i206529 openser[24649]: REGISTER 
> (12141)(sip:rio.voip.br <http://rio.voip.br>) nao autorizado - Return 
> Code DEPOIS.0 (-4)
> May 30 15:29:28 i206529 openser[24649]: Enviando 401 - Unauthorized
> May 30 15:29:28 i206529 openser[24649]: Process Other Requests Here
> May 30 15:29:28 i206529 openser[24649]: REGISTER - Codigo Ret (1)
> May 30 15:29:28 i206529 openser[24649]: REGISTER 
> (12141)(sip:rio.voip.br <http://rio.voip.br>) nao autorizado - Return 
> Code DEPOIS.1 (1)
> May 30 15:29:28 i206529 openser[24651]: Return Code - ANTES (1)
> May 30 15:29:28 i206529 openser[24651]: REGISTER 
> (12141)(sip:rio.voip.br <http://rio.voip.br>) nao autorizado - Return 
> Code DEPOIS.0 (-5)
> May 30 15:29:28 i206529 openser[24651]: Enviando 401 - Unauthorized
> May 30 15:29:28 i206529 openser[24651]: Process Other Requests Here
> May 30 15:29:28 i206529 openser[24651]: REGISTER - Codigo Ret (1)
> May 30 15:29:28 i206529 openser[24651]: REGISTER 
> (12141)(sip:rio.voip.br <http://rio.voip.br>) nao autorizado - Return 
> Code DEPOIS.1 (1)
>
> and config script...
> ........
> if (is_method("REGISTER")) {
>         xlog("L_ALERT", "Chegou um REGISTER ($fU)($ru)($retcode)\n");
>         route(2);
>         return;
> ........
> route[2]
>     xlog("L_ALERT", "Return Code - ANTES ($rc)\n");
>
>     if (!www_authorize("rio.voip.br <http://rio.voip.br>", 
> "subscriber")) {
>         xlog("L_ALERT", "REGISTER ($fU)($ru) nao autorizado - Return 
> Code DEPOIS.0 ($rc)\n");
>         log(1, "Enviando 401 - Unauthorized\n");
>
>         switch($rc){
>             case -1:
>                 log(1,"Invalid User\n");
>             break;
>             case -2:
>                 log(1, "Invalid Password\n");
>             break;
>             case -3:
>                 log(1, "Stale Nonce\n");
>             break;
>             case -4:
>                 log(1, "No Credentials\n");
>             break;
>             case -5:
>                 log(1, "Generic Error\n");
>             break;
>             default:
>                 log(1, "Process Other Requests Here\n");
>                 xlog("L_ALERT","REGISTER - Codigo Ret ($rc)\n");
>         }
>         xlog("L_ALERT", "REGISTER ($fU)($ru) nao autorizado - Return 
> Code DEPOIS.1 ($rc)\n");
>         www_challenge("rio.voip.br <http://rio.voip.br>", "1");
>         return;
>     }
>     if (!check_to()) {
> ............
>
> I believe it is due to the use of the functions log() and 
> xlog().....that changed the value of ($rc)....
>
> regards,
> Marcio
>
>
> 2008/5/30 Bogdan-Andrei Iancu <bogdan at voice-system.ro 
> <mailto:bogdan at voice-system.ro>>:
>
>     Hi Marcio,
>
>     Actually, the correct pseudo variable is $retcode or $rc.
>
>     See:
>     http://www.openser.org/dokuwiki/doku.php/pseudovariables:1.3.x#returned_code
>
>     Regards,
>     Bogdan
>
>     Marcio wrote:
>
>         Hi.....
>
>         I'm grateful for the tip but within the Openser's Config the
>         variable "$retval"  is not recognized....
>
>         Below the log....
>          ERROR:core:pv_parse_spec: error searching pvar "retval"
>         May 28 08:18:57 i206529 openser: ERROR:core:pv_parse_spec:
>         wrong char [
>         May 28 08:18:57 i206529 openser: CRITICAL:core:yyerror: parse
>         error in config file, line 385, column 12-20: unknown script
>         variable
>
>         and the config script...
>         ............................omitted output.......................
>                if (!www_authorize("rio.voip.br <http://rio.voip.br>
>         <http://rio.voip.br>", "subscriber")) {
>
>                        xlog("L_ALERT", "REGISTER ($fU) ($ru) nao
>         autorizado\n");
>                        log(1, "Enviando 401 - Unauthorized (Username)\n");
>         #               perl_exec("chkval"); # check retval but still
>         not working...
>                        switch ($retval){
>                                case 1:
>                                        log("process authentication
>         success");
>                                break;
>                                case -1:
>                                        log("Non Existent User");
>                                break;
>                                case -2:
>                                        log("Invalid Password");
>                                break;
>                                case -3:
>                                        log("Stale Nonce");
>                                break;
>                                case -4:
>                                        log("No Credentials");
>                                break;
>                                default:
>                                        log("Process Other Requests Here");
>                        }
>                        www_challenge("rio.voip.br <http://rio.voip.br>
>         <http://rio.voip.br>", "1");
>
>                        return;
>         ........................omitted output................
>
>         Any hint of how I can make the Openser's config recognize the
>         pvar "$retval"??
>
>         regards,
>         Marcio
>
>         2008/5/28 Daniel-Constantin Mierla <miconda at gmail.com
>         <mailto:miconda at gmail.com> <mailto:miconda at gmail.com
>         <mailto:miconda at gmail.com>>>:
>
>
>            Hello,
>
>
>            On 05/27/08 22:13, Marcio wrote:
>
>                Hi,
>
>                Who would have tips on how to capture the return codes
>                negative of the function "www_authorize" ???
>                I read somewhere that said to use $retval........but ...How
>                can I to use it ("$retval") ??
>
>                -1 - Non existent user;
>                -2 - invalid passwd;
>                -3 - stale nonce;
>                -4 - no credentials;
>                -5 - error;
>
>                Any help will be greatly appreciated.
>
>            one mode is with switch statement:
>
>            www_authorize(...);
>            switch($retval)
>            {
>              case -1:
>                    ........
>              break;
>              case -2:
>                    .......
>              break;
>              ....
>            }
>          
>          http://www.openser.org/dokuwiki/doku.php/core-cookbook:devel#switch
>
>            Daniel
>
>                 thx,
>
>                Marcio
>              
>          ------------------------------------------------------------------------
>
>                _______________________________________________
>                Users mailing list
>                Users at lists.openser.org
>         <mailto:Users at lists.openser.org>
>         <mailto:Users at lists.openser.org <mailto:Users at lists.openser.org>>
>
>                http://lists.openser.org/cgi-bin/mailman/listinfo/users
>                
>
>            --    http://www.asipto.com
>
>
>         ------------------------------------------------------------------------
>
>         _______________________________________________
>         Users mailing list
>         Users at lists.openser.org <mailto:Users at lists.openser.org>
>         http://lists.openser.org/cgi-bin/mailman/listinfo/users
>          
>
>
>





More information about the sr-users mailing list