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: 2020-01-30 09:32:05 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             :                 // Have a good entry. Add it to the list.
      44           3 :                 if(!(cnew=cstat_alloc())
      45           3 :                   || !(cnew->sdirs=sdirs_alloc()))
      46             :                         goto error;
      47             :                 // Cannot just set OPT_CNAME to clients[i] on conf, as it
      48             :                 // overrides our current settings, which are needed later.
      49             :                 // Pass clients[i] through.
      50           6 :                 if((sdirs_init_from_confs_plus_cname(
      51           6 :                   (struct sdirs *)cnew->sdirs, conf, clients[i])))
      52             :                         goto error;
      53           3 :                 if(cstat_init(cnew, clients[i], clientconfdir))
      54             :                         goto error;
      55           3 :                 cstat_add_to_list(clist, cnew);
      56           3 :                 cnew=NULL;
      57             :         }
      58             :         ret=0;
      59             :         goto end;
      60             : error:
      61           0 :         cstat_list_free(clist);
      62             : end:
      63           5 :         for(i=0; i<count; i++)
      64           4 :                 free_w(&(clients[i]));
      65           1 :         free_v((void **)&clients);
      66           1 :         free_w(&fullpath);
      67           1 :         if(cnew)
      68             :         {
      69           0 :                 sdirs_free((struct sdirs **)&cnew->sdirs);
      70           0 :                 cstat_free(&cnew);
      71             :         }
      72           1 :         return ret;
      73             : }
      74             : 
      75           1 : void clist_free(struct cstat **clist)
      76             : {
      77             :         struct cstat *c;
      78           1 :         if(!clist || !*clist)
      79             :                 return;
      80           3 :         for(c=*clist; c; c=c->next)
      81           3 :                 sdirs_free((struct sdirs **)&c->sdirs);
      82           1 :         cstat_list_free(clist);
      83             : }

Generated by: LCOV version 1.13