LCOV - code coverage report
Current view: top level - src/server/protocol2 - clist.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 32 38 84.2 %
Date: 2019-12-31 08:05:25 Functions: 2 2 100.0 %

          Line data    Source code
       1             : #include "../../burp.h"
       2             : #include "../../alloc.h"
       3             : #include "../../conf.h"
       4             : #include "../../cstat.h"
       5             : #include "../../fsops.h"
       6             : #include "../../log.h"
       7             : #include "../../prepend.h"
       8             : #include "clist.h"
       9             : 
      10           1 : int get_client_list(
      11             :         struct cstat **clist,
      12             :         const char *cdir,
      13             :         struct conf **conf
      14             : ) {
      15           1 :         int i=0;
      16           1 :         int ret=-1;
      17           1 :         int count=0;
      18           1 :         char *fullpath=NULL;
      19           1 :         char **clients=NULL;
      20           1 :         struct cstat *cnew=NULL;
      21           1 :         const char *clientconfdir=get_string(conf[OPT_CLIENTCONFDIR]);
      22           1 :         if(entries_in_directory_alphasort(
      23             :                 cdir,
      24             :                 &clients,
      25             :                 &count,
      26             :                 1/*atime*/,
      27             :                 1/*follow_symlinks*/))
      28             :                         goto error;
      29           4 :         for(i=0; i<count; i++)
      30             :         {
      31           4 :                 free_w(&fullpath);
      32           4 :                 if(!(fullpath=prepend_s(cdir, clients[i])))
      33             :                         goto end;
      34           4 :                 switch(is_dir_lstat(fullpath))
      35             :                 {
      36           1 :                         case 0: continue;
      37             :                         case 1: break;
      38           0 :                         default: logp("is_dir(%s): %s\n",
      39           0 :                                  fullpath, strerror(errno));
      40           0 :                                         goto error;
      41             :                 }
      42             : 
      43           3 :                 if(set_string(conf[OPT_CNAME], clients[i]))
      44             :                         goto error;
      45             : 
      46             :                 // Have a good entry. Add it to the list.
      47           3 :                 if(!(cnew=cstat_alloc())
      48           3 :                   || !(cnew->sdirs=sdirs_alloc())
      49           3 :                   || (sdirs_init_from_confs((struct sdirs *)cnew->sdirs, conf))
      50           3 :                   || cstat_init(cnew, clients[i], clientconfdir))
      51             :                         goto error;
      52           3 :                 cstat_add_to_list(clist, cnew);
      53           3 :                 cnew=NULL;
      54             :         }
      55             :         ret=0;
      56             :         goto end;
      57             : error:
      58           0 :         cstat_list_free(clist);
      59             : end:
      60           5 :         for(i=0; i<count; i++)
      61           4 :                 free_w(&(clients[i]));
      62           1 :         free_v((void **)&clients);
      63           1 :         free_w(&fullpath);
      64           1 :         if(cnew)
      65             :         {
      66           0 :                 sdirs_free((struct sdirs **)&cnew->sdirs);
      67           0 :                 cstat_free(&cnew);
      68             :         }
      69           1 :         return ret;
      70             : }
      71             : 
      72           1 : void clist_free(struct cstat **clist)
      73             : {
      74             :         struct cstat *c;
      75           1 :         if(!clist || !*clist)
      76             :                 return;
      77           3 :         for(c=*clist; c; c=c->next)
      78           3 :                 sdirs_free((struct sdirs **)&c->sdirs);
      79           1 :         cstat_list_free(clist);
      80             : }

Generated by: LCOV version 1.13