コード例 #1
0
        private async void buttonServerTest_Click(object sender, EventArgs e)
        {
            string version = string.Empty;

            clam = new ClamClient(textBoxServer.Text, (int)numericUpDownServerPort.Value);

            try
            {
                logger.Info("Testing ClamAV server connection");
                version = await clam.GetVersionAsync(clamServerTestCancelToken.Token);
            }
            catch (Exception ex)
            {
                logger.Warn(
                    ex,
                    "ClamAV server connection test failed using server {0}:{1}",
                    textBoxServer.Text,
                    (int)numericUpDownServerPort.Value);

                textBoxServerPing.Text = "Connection Failed";
                return;
            }

            logger.Info("ClamAV server response: {0}", version);
            textBoxServerPing.Text = version;
        }
コード例 #2
0
 public static void TestClamd() => Task.Run(async() =>
 {
     try
     {
         clam = new ClamClient(Settings.Current.ClamdHost, Settings.Current.ClamdPort);
         Context.ClamdVersion = await clam.GetVersionAsync();
     }
     catch (SocketException) {}
 }).Wait();
コード例 #3
0
        public static async Task Run([BlobTrigger("staging/{name}")] Stream blob, string name, Uri uri,
                                     BlobProperties properties, IDictionary <string, string> metadata, TraceWriter log)
        {
            try
            {
                var clam        = new ClamClient("localhost", 3310);
                var clamVersion = await clam.GetVersionAsync();

                //Make sure we can connect to the ClamAV Server
                var pingResult = await clam.PingAsync();

                if (!pingResult)
                {
                    throw new ApplicationException(
                              "The client failed to connect to the ClamAV Server.  Please check to see if the server is running and accessible on the configured port.");
                }

                //Dont exceed this value.  ClamAV server can be increased to 4GB, but you must have the resources available.
                var maxStreamSize = clam.MaxStreamSize;
                if (blob.Length > maxStreamSize)
                {
                    log.Info($"Blob {name} is too large to be scanned in memory.  Moving to deadletter container");
                    throw new InsufficientMemoryException(
                              $"Blob {name} is too large to be scanned in memory.  Moving to deadletter container");
                }

                //We are going to limit ourselves to block blobs, append blobs, and unspecified blobs.
                var cloudBlob = new CloudBlob(uri);
                if (cloudBlob.BlobType == BlobType.PageBlob)
                {
                    throw new ApplicationException(
                              $"Blob {cloudBlob.Name} has an unsupported type. BlobType = {cloudBlob.BlobType.ToString()}");
                }

                var scanResult = await clam.SendAndScanFileAsync(blob);

                switch (scanResult.Result)
                {
                case ClamScanResults.Clean:
                    //The blob is clean.  Move to production
                    log.Info($"Blob {name}. ScannResult = Clean, ClamVersion = {0}", clamVersion);
                    break;

                case ClamScanResults.VirusDetected:
                    //Bad blob.  Move to quarantine.
                    log.Warning($"Blob {name} has a virus! Name = {0}", scanResult.InfectedFiles.First().VirusName);
                    break;

                case ClamScanResults.Unknown:
                    //Unknown.  Moving to deadletter
                    log.Warning($"Blob {name} scan results unknown! Name = {0}",
                                scanResult.InfectedFiles.First().VirusName);
                    break;

                case ClamScanResults.Error:
                    //Unknown.  Moving to deadletter
                    log.Warning($"Blob {name} has a virus! Name = {0}", scanResult.InfectedFiles.First().VirusName);
                    break;
                }

                log.Info($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {blob.Length} Bytes");
            }
            catch (SocketException ex)
            {
                log.Error(ex.Message, ex);
            }
            catch (InsufficientMemoryException ex)
            {
                log.Error(ex.Message, ex);
                //Todo: Move to deadletter
            }
            catch (ApplicationException ex)
            {
                log.Error(ex.Message, ex);
            }
            catch (Exception ex)
            {
            }
        }