LCOV - code coverage report
Current view: top level - src/server - autoupgrade.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 0 66 0.0 %
Date: 2016-02-29 Functions: 0 1 0.0 %

          Line data    Source code
       1             : #include "../burp.h"
       2             : #include "../asfd.h"
       3             : #include "../async.h"
       4             : #include "../cmd.h"
       5             : #include "../handy.h"
       6             : #include "../log.h"
       7             : #include "../prepend.h"
       8             : 
       9             : // Return -1 on error or success, 0 to continue normally.
      10           0 : int autoupgrade_server(struct async *as,
      11             :         long ser_ver, long cli_ver, const char *os, struct cntr *cntr,
      12             :         const char *autoupgrade_dir)
      13             : {
      14           0 :         int ret=-1;
      15           0 :         char *path=NULL;
      16           0 :         char *base_path=NULL;
      17           0 :         char *script_path=NULL;
      18           0 :         char *package_path=NULL;
      19           0 :         char *script_path_top=NULL;
      20           0 :         char *script_path_specific=NULL;
      21             :         struct stat stats;
      22             :         struct stat statp;
      23             :         struct asfd *asfd;
      24           0 :         asfd=as->asfd;
      25             : 
      26           0 :         if(!autoupgrade_dir)
      27             :         {
      28             :                 // Autoupgrades not turned on on the server.
      29           0 :                 ret=0;
      30           0 :                 asfd->write_str(asfd, CMD_GEN, "do not autoupgrade");
      31           0 :                 goto end;
      32             :         }
      33             : 
      34           0 :         if(cli_ver>=ser_ver)
      35             :         {
      36             :                 // No need to upgrade - client is same version as server,
      37             :                 // or newer.
      38           0 :                 ret=0;
      39           0 :                 asfd->write_str(asfd, CMD_GEN, "do not autoupgrade");
      40           0 :                 goto end;
      41             :         }
      42             : 
      43           0 :         if(!(base_path=prepend_s(autoupgrade_dir, os))
      44           0 :           || !(path=prepend_s(base_path, VERSION))
      45           0 :           || !(script_path_top=prepend_s(base_path, "script"))
      46           0 :           || !(script_path_specific=prepend_s(path, "script"))
      47           0 :           || !(package_path=prepend_s(path, "package")))
      48             :         {
      49           0 :                 asfd->write_str(asfd, CMD_GEN, "do not autoupgrade");
      50           0 :                 goto end;
      51             :         }
      52             : 
      53           0 :         if(!stat(script_path_specific, &stats))
      54           0 :                 script_path=script_path_specific;
      55           0 :         else if(!stat(script_path_top, &stats))
      56           0 :                 script_path=script_path_top;
      57             :         else
      58             :         {
      59           0 :                 logp("Want to autoupgrade client, but no file at:\n");
      60           0 :                 logp("%s\n", script_path_top);
      61           0 :                 logp("or:\n");
      62           0 :                 logp("%s\n", script_path_specific);
      63           0 :                 ret=0; // this is probably OK
      64           0 :                 asfd->write_str(asfd, CMD_GEN, "do not autoupgrade");
      65           0 :                 goto end;
      66             :         }
      67           0 :         if(stat(package_path, &statp))
      68             :         {
      69           0 :                 logp("Want to autoupgrade client, but no file available at:\n");
      70           0 :                 logp("%s\n", package_path);
      71           0 :                 ret=0; // this is probably OK
      72           0 :                 asfd->write_str(asfd, CMD_GEN, "do not autoupgrade");
      73           0 :                 goto end;
      74             :         }
      75             : 
      76           0 :         if(!S_ISREG(stats.st_mode))
      77             :         {
      78           0 :                 logp("%s is not a regular file\n", script_path);
      79           0 :                 asfd->write_str(asfd, CMD_GEN, "do not autoupgrade");
      80           0 :                 goto end;
      81             :         }
      82           0 :         if(!S_ISREG(statp.st_mode))
      83             :         {
      84           0 :                 logp("%s is not a regular file\n", package_path);
      85           0 :                 asfd->write_str(asfd, CMD_GEN, "do not autoupgrade");
      86           0 :                 goto end;
      87             :         }
      88             : 
      89           0 :         if(asfd->write_str(asfd, CMD_GEN, "autoupgrade ok"))
      90             :                 goto end;
      91             : 
      92           0 :         if(send_a_file(asfd, script_path, cntr))
      93             :         {
      94           0 :                 logp("Problem sending %s\n", script_path);
      95           0 :                 goto end;
      96             :         }
      97           0 :         if(send_a_file(asfd, package_path, cntr))
      98             :         {
      99           0 :                 logp("Problem sending %s\n", package_path);
     100           0 :                 goto end;
     101             :         }
     102           0 :         if(asfd_flush_asio(asfd))
     103             :                 goto end;
     104             :         /* Clients currently exit after forking, so exit ourselves. */
     105           0 :         logp("Expecting client to upgrade - now exiting\n");
     106           0 :         asfd_free(&as->asfd);
     107           0 :         exit(0);
     108             : end:
     109           0 :         free_w(&path);
     110           0 :         free_w(&base_path);
     111           0 :         free_w(&script_path_specific);
     112           0 :         free_w(&script_path_top);
     113           0 :         free_w(&package_path);
     114           0 :         return ret;
     115             : }

Generated by: LCOV version 1.10