Software Developers Guide
Software Developers Guide
Legal Notice
Copyright © 2008 Symantec Corporation. All rights reserved.
The product described in this document is distributed under licenses restricting its use,
copying, distribution, and decompilation/reverse engineering. No part of this document
may be reproduced in any form by any means without prior written authorization of
Symantec Corporation and its licensors, if any.
THE DOCUMENTATION IS PROVIDED "AS IS" AND ALL EXPRESS OR IMPLIED CONDITIONS,
REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT,
ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO
BE LEGALLY INVALID. SYMANTEC CORPORATION SHALL NOT BE LIABLE FOR INCIDENTAL
OR CONSEQUENTIAL DAMAGES IN CONNECTION WITH THE FURNISHING,
PERFORMANCE, OR USE OF THIS DOCUMENTATION. THE INFORMATION CONTAINED
IN THIS DOCUMENTATION IS SUBJECT TO CHANGE WITHOUT NOTICE.
The Licensed Software and Documentation are deemed to be commercial computer software
as defined in FAR 12.212 and subject to restricted rights as defined in FAR Section 52.227-19
"Commercial Computer Software - Restricted Rights" and DFARS 227.7202, "Rights in
Commercial Computer Software or Commercial Computer Software Documentation", as
applicable, and any successor regulations. Any use, modification, reproduction release,
performance, display or disclosure of the Licensed Software and Documentation by the U.S.
Government shall be solely in accordance with the terms of this Agreement.
Symantec Corporation
20330 Stevens Creek Blvd.
Cupertino, CA 95014
http://www.symantec.com
Technical Support
Symantec Technical Support maintains support centers globally. Technical
Support’s primary role is to respond to specific queries about product feature and
function. The Technical Support group also authors content for our online
Knowledge Base. The Technical Support group works collaboratively with the
other functional areas within Symantec to answer your questions in a timely
fashion. For example, the Technical Support group works with Product Engineering
and Symantec Security Response to provide alerting services and virus definition
updates.
Symantec’s maintenance offerings include the following:
■ A range of support options that give you the flexibility to select the right
amount of service for any size organization
■ A telephone and web-based support that provides rapid response and
up-to-the-minute information
■ Upgrade assurance that delivers automatic software upgrade protection
■ Global support that is available 24 hours a day, 7 days a week
■ Advanced features, including Account Management Services
For information about Symantec’s Maintenance Programs, you can visit our Web
site at the following URL:
www.symantec.com/techsupp/
Customer service
Customer service information is available at the following URL:
www.symantec.com/techsupp/
Customer Service is available to assist with the following types of issues:
■ Questions regarding product licensing or serialization
■ Product registration updates such as address or name changes
■ General product information (features, language availability, local dealers)
■ Latest information about product updates and upgrades
■ Information about upgrade assurance and maintenance contracts
■ Information about the Symantec Buying Programs
■ Advice about Symantec's technical support options
■ Nontechnical presales questions
■ Issues that are related to CD-ROMs or manuals
Maintenance agreement resources
If you want to contact Symantec regarding an existing maintenance agreement,
please contact the maintenance agreement administration team for your region
as follows:
■ Asia-Pacific and Japan: [email protected]
■ Europe, Middle-East, and Africa: [email protected]
■ North America and Latin America: [email protected]
Symantec Early Warning Solutions These solutions provide early warning of cyber attacks, comprehensive threat
analysis, and countermeasures to prevent attacks before they occur.
Managed Security Services These services remove the burden of managing and monitoring security devices
and events, ensuring rapid response to real threats.
Consulting Services Symantec Consulting Services provide on-site technical expertise from
Symantec and its trusted partners. Symantec Consulting Services offer a variety
of prepackaged and customizable options that include assessment, design,
implementation, monitoring and management capabilities, each focused on
establishing and maintaining the integrity and availability of your IT resources.
Educational Services Educational Services provide a full array of technical training, security
education, security certification, and awareness communication programs.
To access more information about Enterprise services, please visit our Web site
at the following URL:
www.symantec.com
Select your country or language from the site index.
Contents
■ What’s new
■ About licensing
■ Where to start
What’s new
If you have constructed your own ICAP 1.0 client for Symantec Scan Engine, you
can take advantage of the following new features:
Ability to construct an ICAP client If your environment has Java, you can use the
connector using Java API Java API plug-in (SymJavaAPI.jar) to integrate
with Symantec Scan Engine. The Java API
provides client antivirus scanning and repair
services using the ICAP protocol. The Java API
supports the FILEMOD and RESPMOD scanning
modes, and it contains the built-in ability to
stream files.
Ability to construct an ICAP client If your environment has .NET Framework, you
connector using .NET API can use the .NET API plug-in (symcsmsnetapi.dll)
to integrate with Scan Engine. The .NET API
provides client antivirus scanning and repair
services using the ICAP protocol. The .NET API
supports the FILEMOD and RESPMOD scanning
modes, and it contains the built-in ability to
stream files.
Support for gcc 3.4.6 Symantec Scan Engine software developer's kit
now provides support for gcc-3.4.6 for SPARC
Solaris 10 and Red Hat Enterprise Linux 3.
Use the basic client-side antivirus If you plan to integrate antivirus scanning only,
application program interface (API) C you can use the basic antivirus API. URL filtering
library. is not available using the antivirus API. The
antivirus API includes 12 libraries which includes
static and dynamic libraries for each supported
platform. The API library consists of 10 functions
that provide scanning and repair services to client
applications.
Construct your own ICAP 1.0 client for If you construct your own ICAP client, you can
the Symantec Scan Engine. specify whether to perform antivirus scanning
and URL filtering for outgoing and incoming
requests.
About ICAP
ICAP is a lightweight protocol that was originally created to execute a remote
procedure call on HTTP messages. ICAP is part of an evolving architecture that
lets corporations, data communication companies, and Internet service providers
(ISPs) dynamically scan, change, and augment data as it flows through ICAP
servers. The protocol lets ICAP clients pass data to ICAP servers for adaptation
(some type of transformation or other processing, such as virus or URL filtering).
The server executes its transformation service on the data and responds to the
client, possibly with modified content.
In a typical integration for processing HTTP traffic, a caching proxy server
retrieves the requested information from the Web. At the same time, it caches
the information (stores a copy on disk) and, where possible, serves multiple
requests for the same Web content from the cache. A caching proxy server can
use ICAP to communicate with Symantec Scan Engine and request that content
that is retrieved from the Web be scanned and repaired, if necessary.
About licensing
Key features for Symantec Scan Engine are activated by license. After you install
Symantec Scan Engine, you install licenses through the Symantec Scan Engine
administrative interface.
The content scanning features, including antivirus and URL filtering, are activated
by product licenses. Subscription licenses let you obtain updates to virus
definitions and URL filtering content updates. When a license expires, a new
license must be installed.
When no product license is installed, Symantec Scan Engine is not operational.
After you install a product license, you can access the relevant portions of the
administrative interface, and Symantec Scan Engine is operational. For example,
if you activate a product license for antivirus scanning only (with no URL filtering),
you are not able to access those portions of the administrative interface that relate
to URL filtering.
When no subscription license is installed or a subscription license expires,
Symantec Scan Engine is operational, but updates are not permitted. New virus
definitions updates are not downloaded to keep protection current, and
URL-filtering updates to the URL lists and DDR dictionaries are not permitted.
For more information about licensing, see the Symantec Scan Engine
Implementation Guide.
Windows Server platforms. You can run Symantec Scan Engine on the same
computer or a different computer than the client application.
For more information about Symantec Scan Engine system requirements, see the
Symantec Scan Engine Implementation Guide.
Use the basic client-side antivirus If you plan to integrate antivirus scanning only,
application program interface (API) C you can use the basic antivirus API. URL filtering
library. is not available using the antivirus API. The
antivirus API includes 12 libraries, which includes
static and dynamic libraries for each supported
platform. The API library consists of 10 functions
that provide scanning and repair services to client
applications.
Construct your own ICAP 1.0 client for If you construct your own ICAP client, you can
Symantec Scan Engine. specify whether to perform antivirus scanning
and URL filtering for outgoing and incoming
requests.
Scan Engine, and Symantec Scan Engine can open the file and scan it in place on
the computer.
See “Local file scanning (FILEMOD)” on page 64.
Where to start
Configuring client applications to use ICAP 1.0 to pass files to Symantec Scan
Engine for scanning involves the following process:
■ Become familiar with the design and features of the software.
See also the Symantec Scan Engine Implementation Guide.
■ Decide how to deploy Symantec Scan Engine to meet your specific
requirements.
See “Considerations for custom integration” on page 19.
■ Install and configure Symantec Scan Engine to use ICAP as the communication
protocol.
For more information, see the Symantec Scan Engine Implementation Guide.
■ Install the API libraries.
See “About the C API” on page 13.
Getting started 17
Where to start
■ Configure the client applications that will send files to Symantec Scan Engine
for scanning.
18 Getting started
Where to start
Chapter 2
Configuring Symantec Scan
Engine for custom
integrations
This chapter includes the following topics:
You must decide how to configure the client application and Symantec Scan Engine
to ensure that scanning is handled appropriately. This decision can depend on
the capabilities of the third-party application.
For example, for antivirus scanning, the client application can decide which file
types to scan and pass only the appropriate files to Symantec Scan Engine. In
other cases, you can configure the client application to pass all files to Symantec
Scan Engine. Then configure Symantec Scan Engine to scan those file types that
are likely to contain viruses.
You must configure the client application to communicate with Symantec Scan
Engine and to handle the results that are returned from Symantec Scan Engine.
How the application is configured to handle the results that are returned from
Symantec Scan Engine can also depend on the capabilities of the third-party
application, which includes, but is not limited to, the following:
■ Blocking access to infected files or files that violate other configured policies
■ Quarantining unrepairable files
For example, for content scanning, Symantec Scan Engine returns only the lookup
results when you use audit mode. The client application applies the blocking policy
based on the results. You can obtain information about configuring the client
application to work with Symantec Scan Engine in audit mode by contacting
Symantec Service and Support.
Setting Description
Select the ICAP You must configure Symantec Scan Engine to use ICAP to
protocol and configure communicate with clients that are running the proprietary version
protocol options 1.0 of ICAP (RFC 3507, April 2003). Any appropriate client can use
ICAP to communicate with Symantec Scan Engine to request
scanning and repairing of files.
Setting Description
Configure antivirus You can configure certain aspects of antivirus scanning, including
settings the following options:
Specify processing You can impose restrictions on the amount of resources that are
limits used to handle individual files. These processing limits let you
manage resources and protect your network against
denial-of-service attacks.
Configure content You can configure content-filtering settings, which includes the
filtering settings following options:
For more information about how to configure these options, see the Symantec
Scan Engine Implementation Guide.
If your client application closely follows the ICAP 1.0 standard, you might need
to change Symantec Scan Engine default ICAP response setting to receive an ICAP
403 response instead of a replacement file. Symantec Scan Engine sends a 403
response if the file is denied based on Symantec Scan Engine policy setting. If the
file is acceptable, Symantec Scan Engine returns a 200 OK response. You should
change the default ICAP response setting only if you are sure that the client
application supports this behavior.
To make this change, you must edit the configuration.xml file using the XML
modifier tool. The XML modifier tool is provided on the Symantec Scan Engine
product CD. This tool is automatically installed when you install the product.
For more information, see the Symantec Scan Engine Implementation Guide.
To change the ICAP response
1 In the XML modifier tool, at the command line, type the following command:
/configuration/protocol/ICAP/ICAPResponse/@value
A single transport can be used for multiple request/response pairs. Requests are
matched with responses by allowing only one outstanding request on a connection
at a time. Multiple connections can be used.
Header Description
Connection Specifies options that the message sender wants to use only for that
connection and not for proxies over other connections.
For example:
Connection: close
Date Provides the date and time that the message was created using
standard HTTP date and time format.
For example:
Uniform Resource Identifier (URI) Complete host name of the ICAP server and the path
of the resource that is being requested
ICAP version Version string for the current version of ICAP using
the format ICAP/version number (for example
ICAP/1.0)
The request line specifies the ICAP resource that is being requested. Header fields
follow with information, such as cache control and preview size. The header fields
end with a blank line followed by the message body. The message body contains
the encapsulated HTTP message sections that are being sent for scanning and
modification.
Table 3-2 lists the request headers that are allowed in ICAP requests.
Header Description
Allow Lists the methods that the resource supports. For example, a client
request can include an Allow: 204 header, which indicates that it will
allow the server to reply to the message with a 204 No Content
response if the file does not need modification. The client must buffer
the message.
From Provides the Internet email address for the user who is sending the
client request. The address should use the standard HTTP mailbox
format.
For example:
From: [email protected]
Host Specifies the host name and port number of the resource being
requested.
Referer Specifies the path that the client followed to obtain the URI. This
optional header lets the server generate lists of backwards navigation
links to resources and trace invalid links.
26 Constructing clients using ICAP 1.0
How ICAP works
Header Description
User-Agent Identifies the software program that is used by the client that
originated the request. This information is used for statistical
purposes, to trace protocol violations, and to tailor responses to the
software capabilities.
Preview Lets the client send a portion of a file to Symantec Scan Engine for
scanning. The client uses this header to specify the amount of data,
(ICAP-specific
in bytes, that will be sent for preview.
header)
Encapsulated Lists offsets of the start of each encapsulated section from the start
of the message body.
X-URL-Blocked-Domain Specifies the domain name for a URL request that Symantec Scan
Engine has blocked.
This header is an optional field for a URL filtering request. This header
is sent only when a URL is blocked at the domain level. For example,
if Symantec Scan Engine is configured to block uninvitedads.com,
then all URL scanning requests from uninvitedads.com domain receive
this header in the ICAP response.
URL filtering requests are identified by following ICAP services:
■ SYMCScanReq-URL
■ SYMCScanReq-AV-URL
OPTIONS (options mode) Lets the client obtain information from an ICAP
server about available services.
REQMOD (request modification mode) Lets the client send URLs to Symantec Scan
Engine for scanning services.
RESPMOD (response modification Lets the client send files to Symantec Scan Engine
mode) for scanning services.
FILEMOD (file modification mode) Lets the client pass a file name and path to
Symantec Scan Engine so that Symantec Scan
Engine can scan the file in place (rather than
streaming the file to Symantec Scan Engine for
scanning).
Note: File modification mode deviates from the
ICAP 1.0 specification that is presented in RFC
3507 (April 2003).
The ICAP service argument is used to specify the antivirus scanning policy. The
action=repairpolicy argument can override the antivirus scanning repair policy
for Symantec Scan Engine. For services that do not perform antivirus scanning,
Constructing clients using ICAP 1.0 29
How ICAP works
SYMCSCANRESP-AV?action=scanrepairdelete
ICAP/1.0 200 OK
Table 3-4 lists the response codes that Symantec Scan Engine uses (response codes
vary depending on the type of request).
201 Created A violation was detected, and the file has been
repaired or replaced. The response also
includes the modified data.
204 No content necessary Scanning is not required, and the client sent
an Allow: 204 header, which indicates that
Symantec Scan Engine does not need to return
data to the client.
403 Forbidden not repaired The data contained a scanning violation and
cannot be repaired, or Symantec Scan Engine
is configured for scan-only mode.
Note: This response is the standard ICAP
behavior, as documented in the ICAP 1.0
specification. Symantec Scan Engine does not
follow this behavior by default. If your client
application follows the ICAP 1.0 standard, you
might need to change the default setting for
an ICAP response.
404 Not found The URI in the request does not correspond to
an available service.
500 Internal server error There is a generic problem with the server.
502 Bad gateway The server cannot access a file at the specified
location ( X-Filepath: ).
505 Version not supported Only ICAP 1.0 is supported with this method.
506 Server too busy. Lets the client application know that the
Symantec Scan Engine has reached its
threshold for scanning requests and that the
server is too busy to process the request.
The status line is followed by one or more response headers that let the server
pass additional information (for example, information that cannot be placed in
the status line) to the client.
Table 3-5 lists the response headers that Symantec Scan Engine uses (response
headers vary depending on the type of request).
Header Description
Date Specifies the date and time as set on the server clock.
Constructing clients using ICAP 1.0 31
How ICAP works
Header Description
ISTag: "B3C20CFCACEDA72CF16F6AEC119B2981"
Allow Lists the optional ICAP features that the server supports.
Header Description
YYYYMMDD.RRR
X-ICAP-Attribute-<serviceid>
Header Description
■ Violation type
An integer value for the violation. Zero (0) indicates
a virus, one (1) indicates a mail policy violation, and
two (2) indicates a container violation or malformity.
■ Resolution
An integer value that indicates what action was
taken on the file. Zero (0) indicates that the file was
not fixed, one (1) indicates that the file was repaired,
and two (2) indicates that access to the file was
blocked.
■ Threat value
String that describes the virus or violation that was
found.
Header Description
■ File name
The name of the scanned file or the name of a nested
component within the scanned file. Each component
name is separated by a forward slash mark (/).
■ Violation name
The English-readable name of the violation.
■ Violation ID
A numeric code for the violation.
■ Disposition
An integer value that indicates what action was
taken to fix the file. Zero (0) indicates that the file
was not fixed, one (1) indicates that the file was
repaired, and two (2) indicates that the file was
deleted.
■ SYMCScanReq-URL
■ SYMCScanReq-AV-URL
Note: The chunked transfer encoding modifies the body of a message so that it
can be transferred as a series of chunks, each with its own (hexadecimal) size
indicator, followed by an optional footer that contains entity-header fields. For
more information, see the HTTP/1.1 specification (RFC 2616, section 3.6.1).
The encapsulated header must be included in every ICAP message, except for
OPTIONS requests. This header provides information about where each
encapsulated section and message body starts and ends.
For example:
This example indicates that the message encapsulates a group of request headers,
response headers, and a response body at 0, 45, and 100 byte offsets. Byte offsets
use a decimal format. Chunk sizes within an encapsulated body use a hexadecimal
format. If no message body is sent, a null-body entity is used.
Encapsulated headers use the following syntax:
Encapsulated headers must end with a blank line to make them readable and to
terminate line-by-line HTTP parsers.
36 Constructing clients using ICAP 1.0
About the scanning process
content-filtering results based on the URL, Symantec Scan Engine must also scan
the URL in the HTTP request headers.
The ICAP RFC specifies that these headers are optional for a response modification
request, but for clients that use Symantec Scan Engine, they are required. It is
possible to get URL filtering on a RESPMOD request, but it is more efficient to
block URLs during the request before expending resources to retrieve the data.
Symantec Scan Engine can be used to scan non-HTTP data, such as files on disk,
email messages, and FTP traffic. You can scan non-HTTP data by creating an ICAP
RESPMOD request with a minimal set of fabricated HTTP request headers and
HTTP response headers. Typically the HTTP request headers include an HTTP
request line that contains the file name (Symantec Scan Engine provides features
based on file name, so this is required) and a Host header. The HTTP response
headers contain an HTTP response line: HTTP/1.1 200 OK.
Symantec Scan Engine also supports an extension to ICAP (FILEMOD), which lets
the client send a request to have a file scanned on-disk to avoid sending the file
across the network. An ICAP client requests on-disk scanning by sending an ICAP
FILEMOD request to Symantec Scan Engine. This request is composed of ICAP
headers only and no ICAP body (Encapsulated: null-body=0). Included in the
headers is the path that Symantec Scan Engine can use to access the file. The
ICAP response will be similar to a network scan, except that no data will be
returned. Any modification is done on the actual file.
Before sending ICAP requests, the client can query the ICAP server by using the
OPTIONS method to determine which services are supported.
See “How to determine which services are supported (OPTIONS)” on page 41.
Host: client.symantecdomain.com
icap://server.name:port/servicename
where server.name is the name of the server on which Symantec Scan Engine is
running. The port number is optional if Symantec Scan Engine is running on port
1344, which is the default ICAP port. Servicename is one of the ICAP services.
See “About ICAP services” on page 27.
Preview Indicates the preferred number of bytes of data that can be sent
See “How to determine which services are supported (OPTIONS)” on page 41.
Table 3-6 details Symantec Scan Engine scanning behavior that is based on the
scanning policies that you configure.
Previews all files Not used Asterisk (*) character All files are previewed
for unwanted content.
Constructing clients using ICAP 1.0 39
About non-viral threat category responses
Scan all files Asterisk (*) character Not used Symantec Scan Engine
regardless of extension scans every file in its
entirety without
previewing it first.
Scan all files except Asterisk (*) character List of file extensions Symantec Scan Engine
those with the previews the file types
following extensions that are listed in the
(exclusion list) Transfer-Preview
header for unwanted
content. All other file
types, including
unidentified file types,
are scanned in their
entirety.
For more information, see the Symantec Scan Engine Implementation Guide.
If an OPTIONS response indicates that a file is suitable for preview, the client
should include a Preview header in the request message that indicates the portion
of data, in bytes, that is being sent for preview. Symantec Scan Engine evaluates
the initial chunk of data to determine whether a full scan is required. If so,
Symantec Scan Engine requests the remainder of the data. Scan results are
returned in the RESPMOD response message.
appended to the virus name with a delimiter pipe. For example, ThreatDescription
= <VirusName> | NonViralThreat=<CategoryName>.
The following is a list of all the values currently supported for categories for
non-viral threats:
■ Adware
■ Spyware
■ Reserved Malicious
■ Malicious
■ Heuristic
■ Hack Tools
■ Trackware
■ Dialers
■ Joke Programs
■ Remote Access
■ Security Risks
By default, Symantec Scan Engine does not send the threat category name in the
header. To configure Symantec Scan Engine to send the threat category name,
you must change the EnableNonViralThreatCategoryResp value in the
configuration.xml file to true. For more information about how to modify the
configuration.xml file using the XML modifier command-line tool, see the Symantec
Scan Engine Implementation Guide.
An example of an X-Violations-Found response header with a NonViralTreat
category is as follows:
that the server has reached the queued request threshold. The client can then
adjust the load balancing, which prevents the server from being overloaded with
scan requests. This feature lets the client applications that pass files to Symantec
Scan Engine benefit from load-balanced scanning without any additional effort.
You can use the OPTIONS request to determine if Symantec Scan Engine is
overloaded. Send an OPTIONS request to the Symantec Scan Engine. If Symantec
Scan Engine is not busy, it will send the standard OPTIONS response to the
connector and will keep the connection open. If Symantec Scan Engine is too busy
to process the request, it will reply with 506 response “Server too busy” and will
close the connection. In this case, the load balancing decision should be made by
the connector.
A sample ICAP response body for code 506 is as follows:
The request must include a file (uploading) and use the HTTP
POST method. Otherwise, an ICAP 200 OK response is returned.
The request must include a file (uploading) and use the HTTP
POST method. Otherwise, an ICAP 200 OK response is returned.
The request must include a file (uploading) and use the HTTP
POST method. Otherwise, an ICAP 200 OK response is returned.
The request must include a file (uploading) and use the HTTP
POST method. Otherwise, an ICAP 200 OK response is returned.
Constructing clients using ICAP 1.0 43
How to determine which services are supported (OPTIONS)
This service will also examine the URL if the optional HTTP
request headers are included in the ICAP request. To enhance
performance, URLs should be scanned by the
SYMCScanReq-URL service before retrieving the content from
the origin server.
44 Constructing clients using ICAP 1.0
How to determine which services are supported (OPTIONS)
For more information about how URL and DDR filtering work, see the Symantec
Scan Engine Implementation Guide.
Examples of OPTIONS requests for URL filtering are as follows:
Examples of OPTIONS requests for antivirus and content filtering are as follows:
OPTIONS examples
Examples of OPTIONS services are as follows:
■ OPTIONS antivirus-scanning example
■ OPTIONS content-filtering scanning example
■ OPTIONS antivirus and content-filtering scanning example
icap://<Server>/<service>
Constructing clients using ICAP 1.0 45
How to determine which services are supported (OPTIONS)
C:
S: ICAP/1.0 200 OK
S: Date: Mon Jun 27 11:50:34 2005 GMT
S: Methods: RESPMOD, FILEMOD
S: Service: Symantec Scan Engine/5.0.0.23
S: Service-ID: SYMCSCANRESP-AV
S: ISTag: "B3C20CFCACEDA72CF16F6AEC119B2981"
S: X-Definition-Info: 20050622.017
S: Max-Connections: 128
S: X-Allow-Out: X-Outer-Container-Is-Mime, X-Infection-Found
S: X-Allow-Out: X-Definition-Info, X-AV-License
S: X-Allow-Out: X-Violations-Found
S: Allow: 204
S: Options-TTL: 3600
S: Preview: 4
S: Transfer-Preview: *
S: X-AV-License: 1
S: Encapsulated: null-body=0
S:
icap://<Server>/<service>
S: Occult/New Age
S: Prescription Medicine
S: Real Estate
S: Religion
S: Sex/Acts
S: Sex/Attire
S: Sex/Nudity
S: Sex/Personals
S: Sex Education/Advanced
S: Sex Education/Basic
S: Sex Education/Sexuality
S: Travel
S: Vehicles
S: Violence
S: Weapons
S: AllowURLsCategory
S: AllowURLsWithDDRCategory
S: ;
S:
S: 0
S:
C: Encapsulated: null-body=0
C:
S: ICAP/1.0 200 OK
S: Date: Mon Jun 27 11:50:43 2005 GMT
S: Methods: RESPMOD, FILEMOD
S: Service: Symantec Scan Engine/5.0.0.23
S: Service-ID: SYMCSCANRESP-DDR
S: ISTag: "E67C87BA7D981353864B63F6001E8D53"
S: X-Definition-Info: 20050622.017
S: Max-Connections: 128
S: X-Allow-Out: X-Outer-Container-Is-Mime, X-Infection-Found
S: X-Allow-Out: X-Definition-Info, X-AV-License
S: X-Allow-Out: X-Violations-Found
S: Allow: 204
S: Options-TTL: 3600
S: Preview: 4
S: Transfer-Preview: *
S: X-AV-License: 1
S: Encapsulated: opt-body=0
S: X-Allow-Out: X-Attribute
S: Opt-Body-Type: Attribute-List
S:
S: 20e
S: X-ICAP-Attribute-SYMCSCANRESP-DDR
S: Adult Humor
S: Alcohol-Tobacco
S: Anonymous Proxies
S: Crime
S: Drugs/Advocacy
S: Drugs/Non-medical
S: Entertainment/Games
S: Entertainment/Sports
S: Finance
S: Gambling
S: Humor
S: Interactive/Chat
S: Interactive/Mail
S: Intolerance
S: Job Search
S: News
S: Occult/New Age
S: Prescription Medicine
S: Real Estate
50 Constructing clients using ICAP 1.0
How to determine which services are supported (OPTIONS)
S: Religion
S: Sex/Acts
S: Sex/Attire
S: Sex/Nudity
S: Sex/Personals
S: Sex Education/Advanced
S: Sex Education/Basic
S: Sex Education/Sexuality
S: Travel
S: Vehicles
S: Violence
S: Weapons
S: AllowURLsCategory
S: AllowURLsWithDDRCategory
S: ;
S:
S: 0
S:
icap://<Server>/<service>
S: Intolerance
S: Job Search
S: News
S: Occult/New Age
S: Prescription Medicine
S: Real Estate
S: Religion
S: Sex/Acts
S: Sex/Attire
S: Sex/Nudity
S: Sex/Personals
S: Sex Education/Advanced
S: Sex Education/Basic
S: Sex Education/Sexuality
S: Travel
S: Vehicles
S: Violence
S: Weapons
S: AllowURLsCategory
S: AllowURLsWithDDRCategory
S: ;
S:
S: 0
S:
S: Occult/New Age
S: Prescription Medicine
S: Real Estate
S: Religion
S: Sex/Acts
S: Sex/Attire
S: Sex/Nudity
S: Sex/Personals
S: Sex Education/Advanced
S: Sex Education/Basic
S: Sex Education/Sexuality
S: Travel
S: Vehicles
S: Violence
S: Weapons
S: AllowURLsCategory
S: AllowURLsWithDDRCategory
S: ;
S:
S: 0
S:
icap://server.name:port/symcscanreq-av-url
where server.name is the name of the server on which Symantec Scan Engine is
running. The port number is optional if Symantec Scan Engine is running on port
1344, which is the default ICAP port.
See “About ICAP responses” on page 29.
REQMOD examples
The ICAP client sends an HTTP request to Symantec Scan Engine, which then
returns any of the following responses:
■ An unmodified version of the original request
■ An HTTP response indicating success or forbidden (for example, virus found
or content blocked)
■ Error condition (for example, bad gateway)
Examples of REQMOD services are as follows:
■ REQMOD antivirus-scanning example
■ REQMOD content-filtering scanning example
■ REQMOD antivirus and content-filtering scanning example
This response returns a 201 Created status, which indicates that a problem was
found. In this example, a virus was found, which is indicated in the
X-Violations-Found section.
This response returns a 201 Created status, which indicates that a problem was
found. In this example, a block message response is returned because the threshold
was exceeded for a content category that was configured to be denied in the
Symantec Scan Engine administrative interface. In this example, the threshold
exceeded the value set for the News category.
C: Connection: close
C: Encapsulated: req-hdr=0, req-body=114
C:
C: POST / HTTP/1.1
C: Host:icheck.Symantec.com
C: Accept: text/html, text/plain
C: Accept-Encoding: compress
C: Pragma: no-cache
C:
C: 3ef7
C: Sending chunk of size 16119 bytes
C:
C: 0
C:
S: ICAP/1.0 201 Created
S: ISTag: "29FC058C5B98F78BAB6204F0DF8CE7AA"
S: Date: Tue Jul 05 17:25:05 2005 GMT
S: Service: Symantec Scan Engine/5.0.0.24
S: Service-ID: SYMCSCANREQ-AV-URL
S: X-Violations-Found: 1
S: index.html/frere.exe
S: Jeru.1808.Frere Jac
S: 755
S: 0
S: X-Outer-Container-Is-Mime: 0
S: Encapsulated: res-hdr=0, res-body=110
S: X-Attribute: Sex/Acts
S:
S: HTTP/1.1 403 Forbidden.
S: Connection: close
S: Content-Length: 558
S: Pragma: no-cache
S: Content-Type: text/html
S:
S: 22e
S: Getting chunk of size 558 bytes
S:
S: 0
S:
This response returns a 201 Created status, which indicates that a problem was
found. In this example, a virus was found, which is indicated in the
X-Violations-Found section. A block message response is returned because the
Constructing clients using ICAP 1.0 59
Scanning HTTP responses (RESPMOD)
threshold was exceeded for a content category that was configured to be denied
in the Symantec Scan Engine administrative interface. In this example, the
threshold exceeded the value set for the Sex/Acts category.
icap://server.name:port/symcscanresp-av-ddr
where server.name is the name of the server on which Symantec Scan Engine is
running. The port number is optional if Symantec Scan Engine is running on port
1344, which is the default ICAP port.
See “About ICAP responses” on page 29.
RESPMOD examples
The ICAP client sends an HTTP response (including the HTTP request headers)
to Symantec Scan Engine, which then returns any of the following responses:
■ An unmodified version of the original response
■ A modified response, indicating what was found
■ Error condition (for example, bad gateway)
Examples of RESPMOD services are as follows:
■ RESPMOD antivirus-scanning example
■ RESPMOD content-filtering scanning example
■ RESPMOD antivirus and content-filtering scanning example
This response returns a 201 Created status, which indicates that a problem was
found. In this example, a virus was found, which is indicated in the
X-Violations-Found section.
C: Connection: close
C: Encapsulated: req-hdr=0, res-hdr=44, res-body=63
C:
C: get / HTTP/1.1
C: Host:icheck.symantec.com
C:
C: HTTP/1.1 200 OK
C:
C: 3ef7
C: Sending chunk of size 16119 bytes
C:
C: 0
C:
S: ICAP/1.0 201 Created
S: ISTag: "7E823734E7070EECD74143AF7CCA7447"
S: Date: Tue Jul 05 15:38:56 2005 GMT
S: Service: Symantec Scan Engine/5.0.0.24
S: Service-ID: SYMCSCANRESP-DDR
S: X-Outer-Container-Is-Mime: 0
S: Encapsulated: res-hdr=0, res-body=83
S: X-Attribute: Sex/Acts
S:
S: HTTP/1.1 200 OK
S: Content-Length: 559
S: Pragma: no-cache
S: Content-Type: text/html
S:
S: 22f
S: Getting chunk of size 559 bytes
S:
S: 0
S:
This response returns a 201 Created status, which indicates that a problem was
found. In this example, a block message response is returned because the threshold
was exceeded for a content category that was configured to be denied in the
Symantec Scan Engine administrative interface. This example returns a block
message response because the threshold exceeded the value that was set for the
Sex/Acts category.
This response returns a 201 Created status, which indicates that a problem was
found. In this example, a virus was found, which is indicated in the
X-Violations-Found section. A block message response is returned because the
Constructing clients using ICAP 1.0 63
Scanning non-HTTP data (RESPMOD and FILEMOD)
threshold was exceeded for a content category that was configured to be denied
in the Symantec Scan Engine administrative interface. In this example, the
threshold exceeded the value that was set for the Sex/Acts category.
C:
C: 0
C:
S: ICAP/1.0 201 Created
S: ISTag: "334BBC9BDBF997CA16883036DFD9DB81"
S: Date: Mon Jun 27 12:37:13 2005 GMT
S: Service: Symantec Scan Engine/5.0.0.23
S: Service-ID: SYMCSCANRESP-AV-DDR
S: X-Violations-Found: 1
S: frere.exe
S: Jeru.1808.Frere Jac
S: 755
S: 2
S: X-Outer-Container-Is-Mime: 0
S: Encapsulated: res-hdr=0, res-body=83
S:
S: HTTP/1.1 200 OK
S: Content-Length: 673
S: Pragma: no-cache
S: Content-Type: text/html
S:
S: 2a1
S: Getting chunk of size 673 bytes
S:
S: 0
S:
This response returns a 201 Created status, which indicates that a problem was
found. In this example, a virus was found, which is indicated in the
X-Violations-Found section.
FILEMOD examples
Examples of RESPMOD services are as follows:
■ FILEMOD antivirus-scanning example
■ FILEMOD content-filtering scanning example
■ FILEMOD antivirus and content-filtering scanning example
This response returns a 403 Forbidden status, which indicates that a problem was
found. In this example, a virus was found, which is indicated in the
X-Violations-Found section.
This response returns a 403 Forbidden status, which indicates that a problem was
found. In this example, a block message response is returned because the threshold
was exceeded for a content category that was configured to be denied in the
Symantec Scan Engine administrative interface. In this example, the threshold
exceeded the value that was set for the Sex/Acts category.
S: X-Violations-Found: 1
S: frere.exe
S: Jeru.1808.Frere Jac
S: 755
S: 2
S: X-Outer-Container-Is-Mime: 0
S: Encapsulated: null-body=0
S: X-Attribute: Sex/Acts
S:
This response returns a 403 Forbidden status, which indicates that a problem was
found. In this example, a virus was found, which is indicated in the
X-Violations-Found section. A block message response is returned because the
threshold was exceeded for a content category that was configured to be denied
in the Symantec Scan Engine administrative interface. In this example, the
threshold exceeded the value that was set for the Sex/Acts category.
68 Constructing clients using ICAP 1.0
Scanning non-HTTP data (RESPMOD and FILEMOD)
Chapter 4
Constructing clients using
the antivirus client-side API
library
This chapter includes the following topics:
■ API functions
Sample code is included in the Symantec Scan Engine Software Developer’s Guide
for convenience. The sample code is also included in the distribution package.
The sample program demonstrates how to use Symantec Scan Engine API
192.168.1.2 to scan files.
Note: The code (in all versions of all supported platforms) is compiled with
position-independent code so that it can be used in shared libraries.
Note: You must link to the winsock library (WS2_32.LIB) and initialize winsock
in the source code before scanning files. You must release winsock when all
network access is complete (usually just before exiting the program).
Constructing clients using the antivirus client-side API library 71
Compiling and linking
Initializing winsock
The client application must initialize winsock before scanning files. The following
example demonstrates winsock initialization:
#include <windows.h>
.
.
.
// start up winsock
WORD wVersionRequested;
WSADATA wsaData;
int err;
if (WSACleanup() == SOCKET_ERROR)
;// ERROR
Solaris
If you are using Solaris 9, use gcc compiler version 2.95 or 3.2. If you are using
Solaris 10, use gcc compiler version 3.4.6.
The source code that makes calls to the library should include the symcsapi.h
header file. In the makefile (or command line) that compiles the program,
72 Constructing clients using the antivirus client-side API library
API functions
libsymcsapi.a should be added and, if it is not already used, -lnsl -lsocket should
be added. For example:
gcc mycode.c libsymcsapi.a -lsocket -lnsl
Note: If you are compiling your own multithreaded application, you must define
the reentrant symbol (-D_REENTRANT) so that multithreading functions properly.
The API libraries are already compiled in this manner.
Note: If you are compiling your own multithreaded application, you must define
the reentrant symbol (-D_REENTRANT) so that multithreading functions properly.
The API libraries are already compiled in this manner.
API functions
The API functions are as follows:
■ ScanClientStartUp
■ ScanClientScanFile
■ ScanResultGetNumProblems
■ ScanResultGetProblem
■ SC_DECODE_DISPOSITION
■ ScanResultsFree
Constructing clients using the antivirus client-side API library 73
API functions
■ ScanClientShutDown
■ ScanClientStreamStart
■ ScanClientStreamSendBytes
■ ScanClientStreamFinish
■ ScanClientStreamAbort
■ ScanGetNumConnectErrors
■ ScanGetConnectError
File-based scanning
If you are developing a file-based-scanning client, you should use the following
functions:
■ ScanClientStartUp()
■ ScanClientScanFile()
■ ScanResultGetNumProblems()
■ ScanResultGetProblem()
■ ScanResultsFree()
■ ScanClientShutDown()
Stream-based scanning
If you are developing a stream-based-scanning client, you should use the following
functions:
■ ScanClientStartUp()
■ ScanClientStreamStart()
■ ScanClientStreamSendBytes()
■ ScanClientStreamFinish()
■ ScanClientStreamAbort()
■ ScanResultGetNumProblems()
■ ScanResultGetProblem()
■ ScanResultsFree()
■ ScanClientShutDown()
74 Constructing clients using the antivirus client-side API library
API functions
ScanClientStartUp
The ScanClientStartUp function lets a new client begin submitting files to
Symantec Scan Engine.
SC_ERROR ScanClientStartUp
(
HSCANCLIENT*client,
LPSTRpszClientConfiguration
)
ScanClientStartUp parameters
Table 4-2 lists the parameters that are used.
Parameter Description
Parameter Description
■ Server:ipaddress:port;;;...
All Symantec Scan Engines that are used should be listed.
At least one server must be listed.
■ FailRetryTime:<seconds>
If the client fails to connect to a Symantec Scan Engine,
wait <seconds> before trying to connect to that server
again (use only the other servers in the meantime, unless
they have all failed recently). The default setting is 30
seconds.
■ ReadWriteTime:<seconds>
If after <seconds> no response is received from Symantec
Scan Engine (when data is being transmitted to Symantec
Scan Engine), or if the transmission of data does not
complete (when data is being receiving from Symantec
Scan Engine), return an error message.
0 SC_OK Success.
ScanClientStartUp description
In a multithreaded environment, the client should make a single call to
ScanClientStartUp on behalf of all of its threads. This way, all threads use
scheduling through a single scheduler rather than through multiple schedulers.
76 Constructing clients using the antivirus client-side API library
API functions
Note: When multiple scan engines are specified, the API provides automatic
scheduling across any number of scan engines. The API determines the appropriate
scan engine to receive the next file to be scanned, based on the scheduling
algorithm. If a scan engine is unreachable or stops responding during a scan,
another scan engine is called and the faulty scan engine is taken out of rotation
for a period of time (30 seconds is the default setting). If all of the Symantec Scan
Engines are out of rotation, the faulty scan engines are called again. The API does
not stop trying to contact the Symantec Scan Engines unless five engines do not
respond or it appears that a file that is being scanned might have caused more
than one engine to stop responding.
ScanClientScanFile
The ScanClientScanFile function is called to have Symantec Scan Engine scan a
file for viruses.
ScanClientScanFile parameters
Table 4-4 lists the parameters that are used.
Constructing clients using the antivirus client-side API library 77
API functions
Parameter Description
pszOriginalFileName The name of the file to be scanned. (The original name of the
file on the user’s computer.)
pszActualFileName The name (path) of the file to scan on the client’s computer.
pszOutputFileName The storage location for the repaired file. (No output file is
created unless the input file is infected and the infection is
repairable.)
This parameter can be any of the following:
Parameter Description
ScanClientScanFile description
The ScanClientScanFile function determines the appropriate Symantec Scan
Engine (when multiple scan engines are running) based on the scheduling
algorithm. If a scan engine is unreachable or goes down during a scan, another
server is called and the faulty server is taken out of rotation for a period of time.
If all scan engines are out of rotation, the faulty servers are called again. The
ScanClientScanFile function does not stop trying to contact a scan engine unless
five servers are not functioning or it appears that a file that is being scanned
might have caused two servers to go down.
ScanResultGetNumProblems
The ScanResultGetNumProblems function indicates the number of infections
that are contained in an HSCANRESULT after scanning a file. Use the
ScanResultGetProblem() function to get information about the infections that are
reported in an HSCANRESULT after scanning a file.
SC_ERROR ScanResultGetNumProblems
(
HSCANRESULT hScanResult,
int *nNumProblems
)
ScanResultGetNumProblems parameters
Table 4-6 lists the parameters that are used.
Parameter Description
Parameter Description
nNumProblems When the function returns, this parameter is set to the number of
infections in the scanned file. If the AlwaysReportDefInfo:1 scan policy
option is used, at least one (blank) incident is reported, along with the
virus definitions date and revision number.
0 SC_OK Success.
ScanResultGetProblem
The ScanResultGetProblem function is used to get specific information about a
virus.
SC_ERROR ScanResultGetProblem
(
HSCANRESULT hScanResult,
int nProblemNum,
int nAttribute,
LPSTR pszValueOut,
LPINT pnValueLengthInOut
)
ScanResultGetProblem parameters
Table 4-8 lists the parameters that are used.
82 Constructing clients using the antivirus client-side API library
API functions
Parameter Description
■ SC_PROBLEM_FILENAME
The file name in which the infection occurred.
■ SC_PROBLEM_VIRUSNAME
The name of the virus that has infected the file.
■ SC_PROBLEM_NONVIRAL_THREAT_CATEGORY
The name of the non-viral threat category.
This attribute is sent only if you configure Symantec Scan
Engine to send it. For more information, see the Symantec
Scan Engine Implementation Guide.
■ SC_PROBLEM_VIRUSID
The unique numerical ID of the virus.
■ SC_PROBLEM_DISPOSITION
Problem resolution. This value is a number (in a string
format) that indicates whether the virus was cleaned from
the file.
■ SC_PROBLEM_DEFINITION_DATE
The date stamp on the virus definitions.
■ SC_PROBLEM_DEFINITION_REV
Revision number of the definitions.
pnValueLengthInOut Pointer to the variable that holds the size of the pszValueOut
buffer. When the function returns, the size of the attribute
string is placed in this variable. You can determine if the buffer
was large enough to hold the entire string by seeing whether
pnValueLengthInOut is smaller after the call than before. (If
the value is smaller, the buffer was large enough.)
0 SC_OK Success.
ScanResultGetProblem description
A buffer is supplied to hold the information about the virus, and a pointer is
supplied to an integer that holds the size of the buffer. When the function returns,
the integer holds the amount of data that was placed in the buffer. If the buffer
is not large enough to hold the information, as much information as possible is
copied into the buffer. If the value of the integer is the same after the call as it
was before the call, the buffer most likely was not large enough to hold the
information. See the description of the nAttribute parameter for the type of
information that can be retrieved.
SC_DECODE_DISPOSITION
The problem disposition is retrieved with ScanResultGetProblem() in the form of
a string. The SC_DECODE_DISPOSITION function is a macro that converts the
string to an integer and defines the result codes as integers for easier processing.
SC_DECODE_DISPOSITION parameters
Table 4-10 lists the parameters that are used.
Parameter Description
ScanResultsFree
The ScanResultsFree function is used to free the HSCANRESULT structure. This
function must be called when the result structure is no longer needed to free the
allocated memory.
0 SC_OK Success.
ScanClientShutDown
The ScanClientShutDown function is called to clean up after all scanning is
complete (for example, before program termination).
0 SC_OK Success.
ScanClientStreamStart
The ScanClientStreamStart function is used for scanning streams. It can also be
used when you want to accept an input stream for scanning rather than an entire
file at one time. For example, if a file is being received through an HTTP stream
as a user uploads a file to a Web site, stream scanning can be used.
ScanClientStreamStart parameters
Table 4-14 lists the ScanClientStreamStart parameters that are used.
Parameter Description
0 SC_OK Success.
ScanClientStreamSendBytes
The ScanClientStreamSendBytes function is used to send chunks of data after
HSCANSTREAM has been initialized with ScanClientStreamStart().
Constructing clients using the antivirus client-side API library 87
API functions
SC_ERROR ScanClientStreamSendBytes
(
HSCANSTREAM hStream,
LPBYTE lpabyData,
DWORD dwLength
)
ScanClientStreamSendBytes parameters
Table 4-16 lists the parameters that are used.
Parameter Description
lpabyData Pointer to a buffer that contains the next chunk of data to be sent.
0 SC_OK Success.
ScanClientStreamFinish
The ScanClientStreamFinish function must be called after an entire file has been
sent to Symantec Scan Engine to be scanned using ScanClientStreamSendBytes().
See “ScanClientStreamStart” on page 85.
88 Constructing clients using the antivirus client-side API library
API functions
SCSCANFILE_RESULT ScanClientStreamFinish
(
HSCANSTREAMhStream,
LPSTRpszOutputFileName,
LPHSCANRESULTSphScanResults
)
ScanClientStreamFinish parameters
Table 4-18 lists the parameters that are used.
Parameter Description
pszOutputFileName The storage location for the repaired file. (No output file is
created unless the input file is infected and the infection is
repairable.)
This parameter can be any of the following:
ScanClientStreamAbort
The ScanClientStreamAbort function is called to abort a scan between calls to
ScanClientStreamStart() and ScanClientStreamFinish().
SC_ERROR ScanClientStreamAbort
(
HSCANSTREAM hStream
)
0 SC_OK Success.
■ Sample code
Sample code
The usage and syntax is as follows:
example <Scan Engine ip>:<Scan Engine port> <input file> [<input file>...]
On Solaris, you should compile the code using code similar to the following:
ws2_32.lib
#if defined( WIN32 )
#pragma warning(push,3)
#endif
#include <stdio.h>
92 Using the antivirus API
Sample code
#include <string>
#include "symcsapi.h"
#if defined( WIN32 )
#include <windows.h>
#endif
#if defined( WIN32 )
#include <windows.h>
#endif
// Function Prototypes
void print_prob_info( HSCANRESULTS hResults, int iWhichProblem );
int scanfile( HSCANCLIENT scanclient, char *orig_name, char
*actual_name);
int main( int argc, char *argv[])
{
HSCANCLIENT scanclient=NULL;
char pszStartUpString[MAX_STRING];
int i;
#if defined( WIN32 )
// start up winsock
WORD wVersionRequested;
WSADATA wsaData;
int err;
// Load WinSock, request version 1.0.
wVersionRequested = MAKEWORD(1, 0);
err = WSAStartup(wVersionRequested, &wsaData);
if (err != 0)
{
return 3;// ERROR
}
// Confirm WinSock supports the version we requested.
if (LOBYTE(wsaData.wVersion) != 1 ||
HIBYTE(wsaData.wVersion) != 0)
{
WSACleanup();
return 3;// ERROR
}
#endif // defined( WIN32 )
if( argc < 3 )
{
printf( "Usage: %s <ipaddress>:<port> <input-file> [<input-
file>...]\n", argv[0] );
return 1;
}
Using the antivirus API 93
Sample code
#if defined(SCANWHOLEFILE)
// Perform the scan
SCSCANFILE_RESULT answer = ScanClientScanFile( scanclient,
orig_name,
actual_name,
repair_file,
"",
&results
);
#else // SCANWHOLEFILE
char sendbuff[8 * 1024];
HSCANSTREAM hScanStream = NULL;
if (SC_OK != ScanClientStreamStart(scanclient, orig_name, "",
&hScanStream))
return 0;
// Open the file and send it
#if defined (WIN32)
HANDLE fd = CreateFile( actual_name, GENERIC_READ, 0, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (fd == INVALID_HANDLE_VALUE)
{
ScanClientStreamAbort(hScanStream);
return 0;
}
DWORD iChunkSize;
if (!ReadFile( fd, (void *) sendbuff, sizeof(sendbuff),
&iChunkSize, NULL))
{
CloseHandle( fd );
ScanClientStreamAbort(hScanStream);
return 0;
}
if (iChunkSize < 0)
{
CloseHandle( fd );
ScanClientStreamAbort(hScanStream);
return 0;
}
while ( iChunkSize > 0 )
{
if (SC_OK != ScanClientStreamSendBytes(hScanStream,
(LPBYTE)sendbuff, iChunkSize))
{
Using the antivirus API 95
Sample code
CloseHandle( fd );
// Do not call ScanClientStreamAbort here
return 0;
}
// Keep reading the file
if (!ReadFile( fd, (void *) sendbuff, sizeof(sendbuff),
&iChunkSize, NULL))
{
CloseHandle( fd );
ScanClientStreamAbort(hScanStream);
return 0;
}
if (iChunkSize < 0)
{
CloseHandle( fd );
ScanClientStreamAbort(hScanStream):
return 0;
}
}
CloseHandle( fd );
#else // if defined(WIN32)
int fd = open(actual_name, O_RDONLY);
if(fd < 0)
{
ScanClientStreamAbort(hScanStream);
return 0;
}
int iChunkSize = read( fd, sendbuff, sizeof( sendbuff));
if( iChunkSize < 0 )
{
close( fd );
ScanClientStreamAbort(hScanStream);
return 0;
}
while ( iChunkSize > 0 )
{
if (SC_OK != ScanClientStreamSendBytes(hScanStream,
(LPBYTE)sendbuff, iChunkSize))
{
close( fd );
// Do not call ScanClientStreamAbort here
return 0;
}
96 Using the antivirus API
Sample code
else
{
printf( "No repair file generated\n");
}
if( ScanResultGetNumProblems( results, &numproblems ) > 0 )
{
printf( "Error getting number of problems\n");
return 2;
}
printf( "%s had %d infection(s):\n",actual_name,
numproblems );
}
else
{
numproblems = 0;
}
for( int i=0; i<numproblems; i++ )
{
print_prob_info( results, i );
}
// Be sure to free the results when done!
ScanResultsFree( results );
return 1;
}
/*
** Prints scan related information
**
** Parameters:
** hResults: structure containing the scan results
** iWhichProblem: scan file problem ID
*/
void print_prob_info( HSCANRESULTS hResults, int iWhichProblem )
{
char attrib[MAX_STRING];
int attrib_size;
int iDisposition;
attrib_size = MAX_STRING;
ScanResultGetProblem( hResults,
iWhichProblem,
SC_PROBLEM_FILENAME,
attrib,
&attrib_size );
printf( "File Name: %s\n", attrib );
98 Using the antivirus API
Sample code
attrib_size = MAX_STRING;
ScanResultGetProblem( hResults,
iWhichProblem,
SC_PROBLEM_VIRUSNAME,
attrib,
&attrib_size );
printf( "Virus Name: %s\n", attrib );
attrib_size = MAX_STRING;
ScanResultGetProblem( hResults,
iWhichProblem,
SC_PROBLEM_VIRUSID,
attrib,
&attrib_size );
printf( "Virus ID: %s\n", attrib );
attrib_size = MAX_STRING;
ScanResultGetProblem( hResults,
iWhichProblem,
SC_PROBLEM_DISPOSITION,
attrib,
&attrib_size );
iDisposition = SC_DECODE_DISPOSITION( attrib );
switch( iDisposition )
{
case SC_DISP_UNREPAIRED:
printf( "This infection could not be repaired\n");
break;
case SC_DISP_REPAIRED:
printf( "This infection was repaired\n");
break;
case SC_DISP_DELETED:
printf( "The file with this infection should be deleted\n");
break;
default:
printf( "Unknown Disposition\n");
break;
}
attrib_size = MAX_STRING;
ScanResultGetProblem( hResults,
iWhichProblem,
SC_PROBLEM_DEFINITION_DATE,
attrib,
&attrib_size );
printf( "Virus Definitions dated: %s\n", attrib );
Using the antivirus API 99
Sample code
attrib_size = MAX_STRING;
ScanResultGetProblem( hResults,
iWhichProblem,
SC_PROBLEM_DEFINITION_REV,
attrib,
&attrib_size );
printf( "Virus Definitions Revision: %s\n", attrib );
}
100 Using the antivirus API
Sample code
Index
A D
antivirus scanning deployment 15
API libraries 69
ICAP 36 E
load balancing 16
encapsulated messages 34
querying services 42, 44
encapsulation 34
setting policies 76
error codes.
API functions
API functions[error codes!] 72
about 72
error handling 72
sample code 91
exceptions 72
SC_DECODE_DISPOSITION 83
ScanClientScanFile 76
ScanClientShutDown 84 F
ScanClientStartUp 74 file scanning
ScanClientStreamAbort 90 local 15, 64
ScanClientStreamFinish 87 functions (API)
ScanClientStreamSendBytes 86 file-based scanning 73
ScanClientStreamStart 85 list of 72
ScanResultGetNumProblems 80 stream-based scanning 73
ScanResultGetProblem 81
ScanResultsFree 84 H
API library header fields
about 69 ICAP
compiling 70 general 24
error handling 72 request messages 24
linking 70 HTTP requests
scanning 55
C HTTP responses
cache servers 13 scanning 59
client applications
about 13 I
configuring ICAP
with API libraries 69 about 13, 23
with ICAP 36 API libraries 69
deploying files 15 methods 26
code samples querying services 41
for API library 91 scanning files 36, 38
compiling services 27
API libraries 70 ICAP messages
connectors. about 24
. See client applications encapsulation 34
102 Index
N U
network scanning 63 Uniform Resource Identifier.. See URI syntax
No Content responses 39 URI syntax 24
non-HTTP data URL scanning 37
scanning 63 querying services 43
O V
OPTIONS method virus definitions
querying services 41 licensing 14
P
parameters.. See API functions
Index 103
W
winsock
initializing 71
shutting down 71, 76
X
XML modifier tool 21