LCOV - code coverage report
Current view: top level - src/client - auth.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 39 40 97.5 %
Date: 2015-11-30 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include "../burp.h"
       2             : #include "../alloc.h"
       3             : #include "../asfd.h"
       4             : #include "../cmd.h"
       5             : #include "../cntr.h"
       6             : #include "../handy.h"
       7             : #include "../iobuf.h"
       8             : #include "../log.h"
       9             : 
      10           9 : int authorise_client(struct asfd *asfd,
      11             :         char **server_version, const char *cname, const char *password,
      12             :         struct cntr *cntr)
      13             : {
      14           9 :         int ret=-1;
      15           9 :         char hello[256]="";
      16           9 :         struct iobuf *rbuf=asfd->rbuf;
      17             : 
      18           9 :         snprintf(hello, sizeof(hello), "hello:%s", VERSION);
      19           9 :         if(asfd->write_str(asfd, CMD_GEN, hello))
      20             :         {
      21           1 :                 logp("problem with auth\n");
      22           1 :                 goto end;
      23             :         }
      24             : 
      25          16 :         if(asfd->read(asfd)
      26           7 :           || rbuf->cmd!=CMD_GEN
      27          15 :           || strncmp_w(rbuf->buf, "whoareyou"))
      28             :         {
      29           1 :                 logp("problem with auth\n");
      30           1 :                 goto end;
      31             :         }
      32           7 :         if(rbuf->buf)
      33             :         {
      34           7 :                 char *cp=NULL;
      35           7 :                 if((cp=strchr(rbuf->buf, ':')))
      36             :                 {
      37           4 :                         cp++;
      38           4 :                         if(cp && !(*server_version=strdup_w(cp, __func__)))
      39           0 :                                 goto end;
      40             :                 }
      41           7 :                 iobuf_free_content(rbuf);
      42             :         }
      43             : 
      44          14 :         if(asfd->write_str(asfd, CMD_GEN, cname)
      45           7 :           || asfd->read_expect(asfd, CMD_GEN, "okpassword")
      46           6 :           || asfd->write_str(asfd, CMD_GEN, password)
      47          13 :           || asfd->read(asfd))
      48             :         {
      49           1 :                 logp("problem with auth\n");
      50           1 :                 goto end;
      51             :         }
      52             : 
      53           6 :         if(rbuf->cmd==CMD_WARNING) // special case for the version warning
      54             :         {
      55             :                 //logw(conf->p1cntr, rbuf->buf);
      56           2 :                 logp("WARNING: %s\n", rbuf->buf);
      57           2 :                 cntr_add(cntr, rbuf->cmd, 0);
      58           2 :                 iobuf_free_content(rbuf);
      59           2 :                 if(asfd->read(asfd))
      60             :                 {
      61           1 :                         logp("problem with auth\n");
      62           1 :                         goto end;
      63             :                 }
      64             :         }
      65           5 :         if(rbuf->cmd==CMD_GEN && !strcmp(rbuf->buf, "ok"))
      66             :         {
      67             :                 // It is OK.
      68           4 :                 logp("auth ok\n");
      69             :         }
      70             :         else
      71             :         {
      72           1 :                 iobuf_log_unexpected(rbuf, __func__);
      73           1 :                 goto end;
      74             :         }
      75             : 
      76           4 :         ret=0;
      77             : end:
      78           9 :         iobuf_free_content(rbuf);
      79           9 :         return ret;
      80             : }

Generated by: LCOV version 1.10