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

Generated by: LCOV version 1.13