###############################################################################
# OpenVAS Vulnerability Test
# $Id: gb_avg_av_detect_lin.nasl 1566 2009-04-13 15:21:24Z apr $
#
# AVG Anti-Virus Version Detection (Linux)
#
# Authors:
# Sharath S <sharaths@secpod.com>
#
# Script modified by Sujit Ghosal (Date: 2009-05-27)
# NOTE: Patterns and variables used previously were wrong.
#
# Copyright:
# Copyright (c) 2009 Intevation GmbH, http://www.intevation.net
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
# (or any later version), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
###############################################################################

if(description)
{
  script_id(800394);
  script_version("Revision: 1.0 ");
  script_tag(name:"risk_factor", value:"None");
  script_name("AVG Anti-Virus Version Detection (Linux)");
  desc = "
  Overview : This script detect the installed version of AVG Anti-Virus and
  sets the result in KB.

  Risk factor : None";

  script_description(desc);
  script_summary("Set KB for the version of AVG Anti-Virus");
  script_category(ACT_GATHER_INFO);
  script_copyright("Copyright (C) 2009 Intevation GmbH");
  script_family("Service detection");
  exit(0);
}


include("ssh_func.inc");
include("version_func.inc");

sock = ssh_login_or_reuse_connection();
if(!sock){
  exit(0);
}

avgPaths = find_file(file_name:"avgupdate", file_path:"/", useregex:TRUE,
                     regexpar:"$", sock:sock);
foreach avgBin (avgPaths)
{
  filter = get_bin_version(full_prog_name:chomp(avgBin), sock:sock,
                           version_argv:"-v",
                           ver_pattern:"version:? ([0-9.]+)\.([0-9]+)[^.]?");

  # The below steps are carried out to append/increment build by one
  # (since it gets build version alwasy reduced by one.
  if(filter[1] != NULL && filter[2] != NULL)
  {
    end = int(filter[2]) + 1;
    avgVer = filter[1] + "." + end;
    if(avgVer != NULL)
    {
      set_kb_item(name:"AVG/AV/Linux/Ver", value:avgVer);
      security_note(data:"AVG Anti-Virus version " + avgVer + " running at" +
                         " location " + avgBin +  " was detected on the host");
      ssh_close_connection();
      exit(0);
    }
  }
}
ssh_close_connection();
