Symantec™ Protection Engine For Network Attached Storage 8.1 C SDK Guide
Symantec™ Protection Engine For Network Attached Storage 8.1 C SDK Guide
Symantec™ Protection Engine For Network Attached Storage 8.1 C SDK Guide
Symantec, the Symantec Logo, the Checkmark Logo and are trademarks or registered trademarks of
Symantec Corporation or its affiliates in the U.S. and other countries. Other names may be trademarks
of their respective owners.
This Symantec product may contain third party software for which Symantec is required to provide attribution
to the third party (“Third Party Programs”). Some of the Third Party Programs are available under open
source or free software licenses. The License Agreement accompanying the Software does not alter any
rights or obligations you may have under those open source or free software licenses. Please see the
Third Party Legal Notice Appendix to this Documentation or TPIP ReadMe File accompanying this Symantec
product for more information on the Third Party Programs.
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, et seq. "Commercial Computer Software and
Commercial Computer Software Documentation," as applicable, and any successor regulations, whether
delivered by Symantec as on premises or hosted services. 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
350 Ellis Street
Mountain View, CA 94043
https://www.symantec.com
Symantec Support
All support services will be delivered in accordance with your support agreement and the
then-current Enterprise Technical Support policy.
ScanResultsFree ................................................................... 46
ScanClientShutDown .............................................................. 46
ScanClientSecureShutDown .................................................... 47
ScanClientStreamStart ............................................................ 47
ScanClientStreamSendBytes .................................................... 51
ScanClientStreamFinish .......................................................... 52
ScanClientStreamAbort ........................................................... 54
ScanGetNumConnectErrors ..................................................... 55
ScanGetConnectError ............................................................. 56
Index .................................................................................................................... 74
Chapter 1
Getting started
This chapter includes the following topics:
Feature Description
Support for non-archive files Symantec Protection Engine 8.1 supports the scanning of the
larger than 2 GB non-archive files that are larger than 2 GB. The support is limited to
2 GB in previous releases.
Latest Symantec technologies Symantec Protection Engine 8.1 is integrated with latest internal
Symantec scanning technologies.
Enhanced LiveUpdate Internal critical fixes are now delivered through LiveUpdate.
Improved in-memory file system Symantec Protection Engine uses the system memory to stream and
scan the files. Now, the memory size is no more limited to 4 GB.
You can create a custom integration using any of the following methods:
Construct an ICAP If you plan to integrate antivirus scanning only, you can use the antivirus C API.
client connector using URL filtering is not available using the antivirus API.
application program
The antivirus API includes static and dynamic libraries for each supported
interface (API) C library.
platform. The API library consists of functions that provide scanning and repair
services to client applications. The C API supports the FILEMOD and RESPMOD
scanning modes, and it contains the built-in ability to stream files.
Construct an ICAP If your environment has Java, you can use the Java API plug-in
client connector using (SymJavaAPI.jar) to integrate with Symantec Protection Engine. The Java API
Java API library. 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.
Construct an ICAP If your environment has .NET Framework, you can use the .NET API plug-in
client connector using (symcsmsnetapi.dll) to integrate with Symantec Protection Engine. The .NET
.NET API library. 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.
Construct your own If you construct your own ICAP client, you can specify whether to perform
ICAP 1.0 client for the antivirus scanning and URL filtering for outgoing and incoming requests.
Symantec Protection
For more information, see Symantec™ Protection Engine Software Developer's
Engine.
Guide.
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.
Getting started 10
Enhanced categorization of threats
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 Protection
Engine and request that content that is retrieved from the Web be scanned and repaired, if
necessary.
one sub-category assigned to it. In addition, Symantec Protection Engine also provides
sub-category ID and a short description about the sub-category.
Symantec measures each viral and non-viral threat using risk rating factors along with their
impact levels. The risk rating factors and their impact levels defines the degree to which a
threat can harm the computer.
Symantec Protection Engine calculates the overall impact (Cumulative Risk Rating) of a
detected threat based on the impact levels of individual risk rating factors. The detailed
information for each detected threat is logged to all configured logging destinations and as
part of the ICAP response.
Following is the sample uber category information in ICAP extension header X-Violations-Found
when unrepairable virus Eicar is scanned:
EICAR Test String| ViralThreat=Virus| UberCategoryName=Malware| SubCategoryID=0|
CumulativeRiskRating=High| PerformanceImpact=High| PrivacyImpact=High |
EaseOfRemoval=High| Stealth=High| SubCategoryDescription= Programs that infect other
programs, files, or areas of a computer by inserting themselves or attaching themselves to
that medium
Getting started 12
Enhanced categorization of threats
■ SC_PROBLEM_EX_FILENAME
■ SC_PROBLEM_EX_VIOLATION_NAME
■ SC_PROBLEM_EX_VIOLATION_ID
■ SC_PROBLEM_EX_DISPOSITION
■ SC_PROBLEM_EX_DEFINITION_DATE
■ SC_PROBLEM_EX_DEFINITION_REV
■ SC_PROBLEM_EX_NONVIRAL_THREAT_CATEGORY
■ SC_PROBLEM_EX_FILE_UNSCANABLE
■ SC_PROBLEM_EX_VIRAL_THREAT_CATEGORY
■ SC_PROBLEM_EX_UBERCATEGORIES
■ SC_PROBLEM_EX_SUBCATEGORY_ID
■ SC_PROBLEM_EX_CUMULATIVE_RISK_RATING
■ SC_PROBLEM_EX_PERFORMANCE_IMPACT
■ SC_PROBLEM_EX_PRIVACY_IMPACT
■ SC_PROBLEM_EX_EASE_OF_REMOVAL
■ SC_PROBLEM_EX_STEALTH
■ SC_PROBLEM_EX_SUBCATEGORY_DESCRIPTION
■ SC_PROBLEM_EX_EXTRA_THREAT_INFO
■ SC_PROBLEM_EX_INSIGHT_CACHE_DATE
■ SC_PROBLEM_EX_INSIGHT_CACHE_REV
■ SC_PROBLEM_EX_INSIGHT_SETTINGS_DATE
■ SC_PROBLEM_EX_INSIGHT_SETTINGS_REV
■ SC_PROBLEM_EX_INSIGHT_SYMVT_DATE
■ SC_PROBLEM_EX_INSIGHT_SYMVT_REV
■ SC_PROBLEM_EX_INSIGHT_RESULT
■ SC_PROBLEM_EX_REPUTATION
■ SC_PROBLEM_EX_AGE
■ SC_PROBLEM_EX_PREVALENCE
■ SC_PROBLEM_EX_FILETYPE
■ SC_PROBLEM_EX_SHA256
■ SC_PROBLEM_EX_EXTRA_INSIGHT_INFO
■ SC_PROBLEM_EX_EXTRA_APK_ RESULT_INFO
■ SC_PROBLEM_EX_APK_RESULT_ID
■ SC_PROBLEM_EX_INTERNAL_SERVER_ERR_REASON
Now, from version 7.0 onwards, the C API library additionally supports ICAP persistent
connections, also known as ICAP keep-alive, which uses the same TCP connection to send
and receive multiple ICAP requests/responses. When the client sends another request, it uses
the same connection. This will continue until either the client or the server drops the connection,
or, the connection times out due to no activity on the connection.
The keep-alive connection reduces frequent opening and closing connections, resulting in
lesser CPU/memory usage, lesser network congestion and reduced latency in subsequent
requests when compared to the legacy method.
The client application provides the maximum required persistent connection pool size to the
server during initialization. Depending on the scan request load, the number of persistent
connections will dynamically increase to the specified maximum number. If all connections
are busy and no more connections can be created (more than the specified keep-alive
connection), and the client tries to send a scan request, the API will return an error
(SCSCANFILE_CONNPOOLSIZE_EXCEEDED or SC_CONNPOOLSIZE_EXCEEDED). In
case the client does not send scanning requests or persistent connections remain idle for more
than 5 minutes, Symantec Protection Engine will close the connection and free up the server
resources.
To implement the keep-alive connection method, you must meet the following guidelines:
■ Client connector must have multi-threaded support.
■ Configure the maximum number of threads on Symantec Protection Engine to be more
than or equal to the total number of keep- alive connections configured on the client(s).
For more information on how to configure the “MaxThreads” see, Symantec Protection
Engine Implementation Guide.
■ To ensure that all scan requests are served immediately upon arrival, configure the minimum
number of threads on Symantec Protection Engine (MinThreads) to be equal to the number
of persistent connections (NumberOfKeepAliveConnections). This is required to handle
scenarios where there is a sudden increase in scan requests, as there is a time lag for
increasing the number of available threads from the configured minimum number.
For more information on how to configure the “MinThreads” see, Symantec Protection
Engine Implementation Guide.
Chapter 2
Constructing clients using
the antivirus client-side API
library
This chapter includes the following topics:
■ API functions
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: For gcc 3.x, you must link to the Standard C++ library (-lstdc++).
Studio, under Project Settings, click the C/C++ tab, click Code Generation, and click
Multithreaded 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).
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
Constructing clients using the antivirus client-side API library 19
Compiling and linking
Solaris
Table 2-2 describes the different versions of gcc compilers for different version of Solaris.
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, 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
On the x64 platform, a new flag -m64 should be added. For example:
gcc -m64 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.
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, libsymcsapi.a should be added
and, if it is not already used, -lnsl should be added. For example:
gcc mycode.c libsymcsapi.a -lnsl
On the x64 platform, a new flag -m64 should be added. For example:
gcc -m64 mycode.c libsymcsapi.a -lnsl
Constructing clients using the antivirus client-side API library 20
API functions
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
■ ScanClientSecureStartUp
■ ScanClientScanFile
■ ScanClientScanFileEx
■ ScanClientScanFileInsight
■ ScanResultGetNumProblems
■ ScanResultGetProblem
■ SC_DECODE_DISPOSITION
■ ScanResultsFree
■ ScanClientShutDown
■ ScanClientSecureShutDown
■ ScanClientStreamStart
■ ScanClientStreamStartEx
■ ScanClientStreamStartInsight
■ ScanClientStreamSendBytes
■ ScanClientStreamFinish
■ ScanClientStreamAbort
■ ScanGetNumConnectErrors
■ ScanGetConnectError
Constructing clients using the antivirus client-side API library 21
API functions
File-based scanning
If you are developing a file-based-scanning client, you should use the following functions:
■ ScanClientStartUp()
■ ScanClientScanFile()
-or-
ScanClientScanFileEx()
-or-
ScanClientScanFileInsight
■ ScanResultGetNumProblems()
■ ScanResultGetProblem()
■ ScanResultsFree()
■ ScanClientShutDown()
Stream-based scanning
If you are developing a stream-based-scanning client, you should use the following functions:
■ ScanClientStartUp()
■ ScanClientStreamStart()
-or-
ScanClientStreamStartEx()
-or-
ScanClientStreamStartInsight
■ ScanClientStreamSendBytes()
■ ScanClientStreamFinish()
■ ScanClientStreamAbort()
■ ScanResultGetNumProblems()
■ ScanResultGetProblem()
■ ScanResultsFree()
■ ScanClientShutDown()
ScanClientStartUp
The ScanClientStartUp function lets a new client begin submitting files to Symantec Protection
Engine.
Constructing clients using the antivirus client-side API library 22
API functions
SC_ERROR ScanClientStartUp
(
HSCANCLIENT*client,
LPSTRpszClientConfiguration
)
ScanClientStartUp parameters
Table 2-4 lists the parameters that are used.
Parameter Description
Parameter Description
0 SC_OK Success.
Constructing clients using the antivirus client-side API library 24
API functions
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.
Parameter pszClientConfiguration should look like the following:
Server:1.2.3.4:1344;;;Server:1.2.3.5:1344
At least one Symantec Protection Engine must be specified. Entries are separated with three
semicolons. No spaces are allowed. If the default port (1344) is used, the port number (and
the colon) can be omitted.
In case of persistent (keep-alive) connections, the parameter pszClientConfiguration should
look like the following:
Server:1.2.3.4:1344:16;;;Server:1.2.3.5:1344:8
In this example, the API will maintain 16 and 8 connections with the Symantec Protection
Engine server 1.2.3.4 and 1.2.3.5 respectively.
Note: When multiple protection engines are specified, the API provides automatic scheduling
across any number of protection engines. The API determines the appropriate protection
engine to receive the next file to be scanned, based on the scheduling algorithm. If a protection
engine is unreachable or stops responding during a scan, another protection engine is called
and the faulty protection engine is taken out of rotation for a period of time (30 seconds is the
default setting). If all of the Symantec Protection Engines are out of rotation, the faulty protection
engines are called again. The API does not stop trying to contact the Symantec Protection
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.
ScanClientSecureStartUp
The ScanClientSecureStartUp function lets you configure Symantec Protection Engine ser
ScanClientSecureStartUp parameters
Table 2-6 lists the parameters that are used.
Constructing clients using the antivirus client-side API library 25
API functions
Parameters Description
Parameters Description
■ Server
Following are the three supported formats for configuring Server
information in this API.
■ server:ipaddress:port:NumberOfKeepAliveConnections:<true/false>
List all the Symantec Protection Engines that are used. At least one
server must be listed.
Where, NumberOfKeepAliveConnections is per Symantec Protection
Engine server. true indicates that secure ICAP is enabled at server
and communication should be done using secure ICAP. false
indicates that secure ICAP is not enabled and communication should
be done using plain ICAP.
For secure ICAP communication, you must specify port and
NumberOfKeepAliveConnections.
If persistent connection feature is not required with secure ICAP,
pass 0 as NumberOfKeepAliveConnections in Server information,
that is, "ipaddress:port:0:<true/false>"
■ Server:ipaddress:port:NumberOfKeepAliveConnections(keep-alive
format)
Where, NumberOfKeepAliveConnections is per Symantec Protection
Engine server. List all the Symantec Protection Engines that are
used. At least one server must be listed.
Note: For legacy behavior, specifying port is optional, but for
keep-alive (persistent) connection feature, port is required.
■ Server: ipaddress:port (legacy format)
List all the Symantec Protection Engines that are used. At least one
server must be listed.
■ FailRetryTime:<seconds>
If the client fails to connect to a Symantec Protection 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 Protection
Engine (when data is being transmitted to Symantec Protection Engine),
or if the transmission of data does not complete (when data is being
receiving from Symantec Protection Engine), return an error message.
The default setting is 30 seconds.
Constructing clients using the antivirus client-side API library 27
API functions
Parameters Description
SecureConnectionInfo You must fill certificate file specific information to use secure ICAP feature.
If you have no any specific information, initialize pointers with NULL. In that
case, this API will only be able to connect to server with plain ICAP.
SecureConnectionInfo structure:
0 SC_OK Success.
ScanClientSecureStartUp description
In a multithreaded environment, the client should make a single call to ScanClientSecureStartUp
on behalf of all its threads. This way, all threads use scheduling through a single scheduler
rather than through multiple schedulers.
In case of secure ICAP configuration, the parameter pszClientConfiguration should look like
the following:
■ server:ipaddress:port:NumberOfKeepAliveConnections:<true/false>;;;
FailRetryTime:30;;;ReadWriteTime:30 (Secure ICAP format)
■ server:ipaddress:port:NumberOfKeepAliveConnections:<true/false>;;;server:ipaddress:port:
NumberOfKeepAliveConnections:<true/false>;;;FailRetryTime:30;;;ReadWriteTime:30
(Secure ICAP format if there are 2 servers)
At least one Symantec Protection Engine must be specified. Entries are separated with three
semicolons. No spaces are allowed.
true indicates that secure ICAP is enabled at server and communication should be done using
secure ICAP. false indicates that secure ICAP is not enabled and communication should be
done using plain ICAP.
For secure ICAP communication, specifying port and NumberOfKeepAliveConnections is must.
If persistent connection feature is not required with secure ICAP, just pass 0 as
NumberOfKeepAliveConnections in Server information, that is, "ipaddress:port:0:<true/false>"
ScanClientScanFile
The ScanClientScanFile function is called to have Symantec Protection Engine scan a file for
viruses.
LPSTR pszActualFileName,
LPSTR pszOutputFileName,
LPSTR pszConfigPolicy,
LPHSCANRESULTS phScanResults
)
ScanClientScanFileEx
The ScanClientScanFile and ScanClientScanFileEx function have same parameters.
ScanClientScanFileInsight
The ScanClientScanFileInsight has the following parameters:
ScanClientScanFile parameters
Table 2-8 lists the parameters that are used.
Constructing clients using the antivirus client-side API library 30
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:
Note: If this parameter is NULL, the API has Symantec Protection Engine
scan the file for viruses but not attempt repair. However, this is not the
recommended method for forcing Symantec Protection Engine to scan files
for viruses but not attempt repair. You should set the pszConfigPolicy to
ScanOnly instead.
Parameter Description
phScanResults When the function returns, this handle points at a structure that contains
information about any problems (infections) found during the scan. If none
were found, this parameter is NULL unless the AlwaysReportDefInfo:1 policy
is used in the scan. Information about problems is extracted using the
described functions. If this parameter is not NULL, the memory must be
released using ScanResultsFree().
Parameter Description
ScanClientScanFile description
The ScanClientScanFile function determines the appropriate Symantec Protection Engine
(when multiple protection engines are running) based on the scheduling algorithm. If a protection
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 protection engines are out of rotation,
the faulty servers are called again. The ScanClientScanFile function does not stop trying to
contact a protection 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.
ScanClientScanFileEx description
If the ScanClientScanFiletEx() function is used (instead of ScanClientScanFile()), then an
extended problem attribute set will be available from Symantec Protection Engine, provided
the required parameters are enabled on the server. This extended problem attribute set contains
enhanced categorization information about the detected threat.
The ScanClientScanFile() and ScanClientScanFileEx() function have same parameters and
return codes.
Constructing clients using the antivirus client-side API library 34
API functions
ScanClientScanFileInsight description
If the ScanClientScanFileInsight() function is used, then Symantec Protection Engine will
additionally query Symantec Reputation servers to get the additional reputation result for
specified file. The ScanClientScanFileInsight() function has 2 additional optional parameters
compared to ScanClientScanFile() and ScanClientScanFileEx() functions.
disableInsightCall specifies whether to enable or disable insight server query. By default
disableInsight is 0.
Attributes configured in InsightOptions structure can be used to query the reputation server
for file reputation result. Following are the attributes :
■ insightAggressionLevel - Insight aggression level used by SPE to convict file using reputation
result.
■ MD5Hash – MD5 hash of file
■ SHA256Hash – SHA256 Hash of file.
■ fileSourceIP – Source IP of the file.
■ fileSourceURL- Source URL of the file.
■ IsDigitallySigned – whether the fie being sent for scanning is digitally signed.
The return codes for ScanClientScanFileInsight() function are same as ScanClientScanFile()
and ScanClientScanFileEx() functions.
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 2-10 lists the parameters that are used.
Constructing clients using the antivirus client-side API library 35
API functions
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.
ScanResultGetNumProblemsEx
The ScanResultGetNumProblemsEx function gives additional information about the data
scanned and the total files scanned in a scan request.
To run this function, you must add the following parameters to the category3.xml file with the
value as True.
ScanResultGetNumProblemsEx parameters
Table 2-13 lists the parameters that are used.
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.
DataScannedBytes This parameter returns the amount of data in bytes that is scanned
by the scan engine.
TotalFilesScanned This parameter returns the total number of files that are scanned. In
the case of a container file such as a zip or an archive, the total
number of files scanned includes the container file and the files
contained within it. For example, if file.zip contains 4 files, then
the total number of files scanned will be 5.
0 SC_OK Success.
-1 SC_NULL_PARAMETER The parameters that were passed to the function do not exist.
Header Description
X-Data-Scanned-Bytes This parameter returns the amount of data in bytes that is scanned by the
scan engine.
X-Total-Files-Scanned This parameter returns the total number of files that are scanned. In the case
of a container file such as a zip or an archive, the total number of files scanned
includes the container file and the files contained within it. For example, if
file.zip contains 4 files, then the total number of files scanned will be 5.
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 2-16 lists the parameters that are used.
Constructing clients using the antivirus client-side API library 38
API functions
Parameter Description
Parameter Description
nAttribute
Constructing clients using the antivirus client-side API library 40
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.
In the case of violation, the value of this attribute returns the violation name.
■ SC_PROBLEM_NONVIRAL_THREAT_CATEGORY
The name of the non-viral threat category.
This attribute is sent only if you configure Symantec Protection Engine to send
it. For more information, see the Symantec Protection Engine Implementation
Guide.
■ SC_PROBLEM_VIRUSID
The unique numerical ID of the virus.
In the case of violation, the value of this attribute returns the violation ID.
■ 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.
■ SC_PROBLEM_FILE_UNSCANABLE
In the case of unscannable file, the value of this attribute returns true else false.
File-based scanning
■ ScanClientScanFileEx()
■ ScanClientScanFileInsight()
Stream-based scanning
■ ScanClientStreamStartEx()
■ ScanClientStreamStartInsight()
■ SC_PROBLEM_EX_FILENAME
The file name in which the infection occurred.
■ SC_PROBLEM_EX_VIOLATION_NAME
The name of the virus that has infected the file. In the case of violation, the
Constructing clients using the antivirus client-side API library 41
API functions
Parameter Description
Parameter Description
Constructing clients using the antivirus client-side API library 43
API functions
Parameter Description
Continued...
■ SC_PROBLEM_EX_FILE_UNSCANABLE
In the case of unscannable file, the value of this attribute returns true else false.
■ SC_PROBLEM_EX_VIRAL_THREAT_CATEGORY
This parameter provides viral threat category under which a non-viral threat is
been categorized in ICAP response.
■ SC_PROBLEM_EX_UBERCATEGORIES
■ SC_PROBLEM_EX_SUBCATEGORY_ID
■ SC_PROBLEM_EX_CUMULATIVE_RISK_RATING
This parameter provides cumulative risk rating of threat.
■ SC_PROBLEM_EX_PERFORMANCE_IMPACT
This parameter provides performance impact of threat.
■ SC_PROBLEM_EX_PRIVACY_IMPACT
This parameter provides privacy impact of threat.
■ SC_PROBLEM_EX_EASE_OF_REMOVAL
This parameter provides ease of removal impact of threat.
■ SC_PROBLEM_EX_STEALTH
This parameter provides stealth impact of threat.
■ SC_PROBLEM_EX_SUBCATEGORY_DESCRIPTION
■ SC_PROBLEM_EX_EXTRA_THREAT_INFO
The value of this attribute returns true if ICAP response contains extra
information about threats (viral, non viral) else false is returned.
■ SC_PROBLEM_EX_INSIGHT_CACHE_DATE
This parameter provides the Insight cache revocation date.
■ SC_PROBLEM_EX_INSIGHT_CACHE_REV
This parameter provides the Insight cache revocation revision.
■ SC_PROBLEM_EX_INSIGHT_SETTINGS_DATE
This parameter provides the Insight settings date.
■ SC_PROBLEM_EX_INSIGHT_SETTINGS_REV
This parameter provides the Insight settings revision.
■ SC_PROBLEM_EX_INSIGHT_SYMVT_DATE
This parameter provides the Insight SymVT date.
■ SC_PROBLEM_EX_INSIGHT_SYMVT_REV
This parameter provides the Insight SymVT revision.
■ SC_PROBLEM_EX_INSIGHT_RESULT
This parameter provides the Insight result of the file.
■ SC_PROBLEM_EX_REPUTATION
This parameter provides the reputation score of the file.
■ SC_PROBLEM_EX_AGE
Constructing clients using the antivirus client-side API library 44
API functions
Parameter Description
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 2-18 lists the parameters that are used.
Parameter Description
pszDisposition The pszValueOut that is returned from ScanResultGetProblem with nAttribute equal
to SC_PROBLEM_DISPOSITION.
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.
ScanClientSecureShutDown
The ScanClientSecureShutDown 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.
HSCANSTREAM *phScanStream
)
ScanClientStreamStartEx
If the ScanClientStreamStartEx() function is used (instead of ScanClientStreamStart()),then
an extended problem attribute set will be available from Symantec Protection Engine, provided
the required parameters are enabled on the server.This extended problem attribute set contains
enhanced categorization information about the detected threat.
The ScanClientStreamStart() and ScanClientStreamStartEx() function have same parameters
and return codes.
ScanClientStreamStartInsight
If the ScanClientStreamStartInsight() function is used, then Symantec Protection Engine will
additionally query Symantec Reputation servers to get the additional reputation result for
specified file. The ScanClientStreamStartInsight() function has 2 additional optional parameters
compared to ScanClientStreamStart() and ScanClientStreamStartEx() functions.
disableInsightCall specifies whether to enable or disable insight server query. By default
disableInsight is 0.
Attributes configured in InsightOptions structure can be used to query the reputation server
for file reputation result. Following are the attributes :
■ insightAggressionLevel - Insight aggression level used by SPE to convict file using reputation
result.
■ MD5Hash – MD5 hash of file
■ SHA256Hash – SHA256 Hash of file.
■ fileSourceIP – Source IP of the file.
■ fileSourceURL- Source URL of the file.
■ IsDigitallySigned – whether the fie being sent for scanning is digitally signed.
The return codes for ScanClientStreamStartInsight() function are same as
ScanClientStreamStart() and ScanClientStreamStartEx() functions.
Constructing clients using the antivirus client-side API library 49
API functions
ScanClientStreamStart parameters
Table 2-23 lists the ScanClientStreamStart parameters that are used.
Parameter Description
pszOriginalFileName The original name of the file to be scanned as it was named on the user’s
computer.
0 SC_OK Success.
ScanClientStreamSendBytes
The ScanClientStreamSendBytes function is used to send chunks of data after HSCANSTREAM
has been initialized with ScanClientStreamStart().
See “ScanClientStreamStart” on page 47.
SC_ERROR ScanClientStreamSendBytes
(
HSCANSTREAM hStream,
LPBYTE lpabyData,
DWORD dwLength
)
ScanClientStreamSendBytes parameters
Table 2-25 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 Protection Engine to be scanned using ScanClientStreamSendBytes().
See “ScanClientStreamStart” on page 47.
SCSCANFILE_RESULT ScanClientStreamFinish
(
HSCANSTREAMhStream,
LPSTRpszOutputFileName,
LPHSCANRESULTSphScanResults
)
ScanClientStreamFinish parameters
Table 2-27 lists the parameters that are used.
Parameter Description
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:
Note: If this parameter is NULL, the API has Symantec Protection Engine
scan the file for viruses but not attempt repair. However, this is not the
recommended method for forcing Symantec Protection Engine to scan files
for viruses but not attempt repair. You should set the pszConfigPolicy to
ScanOnly instead.
phScanResults When the function returns, this handle points at a structure that contains
information about any problems (infections) found during the scan. If none
were found, this parameter is NULL unless the AlwaysReportDefInfo:1 policy
is used in the scan. Information about problems is extracted using the
described functions. If this parameter is not NULL, the memory must be
released using ScanResultsFree().
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.
Constructing clients using the antivirus client-side API library 55
API functions
ScanGetNumConnectErrors
Use this function to determine how Symantec Protection Engine IP addresses were tried when
attempting to connect in an HSCANRESULT.
SC_ERROR ScanGetNumConnectErrors
(
HSCANRESULT hScanResult,
int * nNumIPs
)
ScanGetNumConnectErrors parameters
Table 2-30 lists the ScanGetNumConnectErrors parameters that are used.
Parameter Description
nNumIPs The number of Symantec Protection Engine IP addresses to which the client
tried to connect. If the AlwaysReportDefInfo: 1 scan policy option is used,
there will always be at least one (blank) incident reported that contains the
virus definitions date and version.
SC_OUTOFRANGE_PARAMETER At least one parameter passed to the function was out of range.
SC_OK Success.
SC_NULL_PARAMETER A parameter that was passed to the function is NULL but should not
have been.
ScanGetConnectError
Use this function to find out specific information about a Symantec Protection Engine connection
failure or success. When you connect to Symantec Protection Engine, you must supply a buffer
to hold the retrieved IP address and a pointer to an integer that holds the port number and
error return.
SC_ERROR ScanGetConnectError
(
HSCANRESULT hScanResult,
int nIPNum,
LPSTR nIPAddr,
int *nPort,
SC_ERROR *nConnectError
)
ScanGetConnectError parameters
Table 2-32 lists the ScanGetConnectError parameters that are used.
Parameter Description
nIPAddr IP address of the Symantec Protection Engine to which the client tried to
connect. .
nPort Port number of the Symantec Protection Engine to which the client tried to
connect.
Constructing clients using the antivirus client-side API library 57
API functions
Parameter Description
nConnectError Integer return value received while connecting to Symantec Protection Engine.
SC_OUTOFRANGE_PARAMETER At least one parameter passed to the function was out of range.
SC_OK Success.
SC_NULL_PARAMETER A parameter that was passed to the function is NULL but should not
have been.
Appendix A
Using the antivirus API
This appendix includes the following topics:
ws2_32.lib
#if defined( WIN32 )
#pragma warning(push,3)
#endif
#include <stdio.h>
#include <string>
#include "symcsapi.h"
#if defined(UNIX)
#include <string.h>
#endif
// Function Prototypes
void print_prob_info( HSCANRESULTS hResults, int iWhichProblem, int api);
int scanfile( HSCANCLIENT scanclient,
char *orig_name, char *actual_name, int api);
// Usage
void printUsage(char* progName)
{
printf( "Usage: %s <ipaddress>:<port> [-api:<0|1>]
<input-file> [<input-file>...]\n", progName );
printf( "\n-api<0|1> \n");
printf( "\tUse 1 to scan file with new API's,
provides more information about threat detected.\n");
printf( "\tUse 0 to scan file with legacy API's.Defaults to 0.\n");
}
int main( int argc, char *argv[])
{
HSCANCLIENT scanclient=NULL;
char pszStartUpString[MAX_STRING];
int i;
int api = 0;
int apiSwitchPresent = 0;
WSADATA wsaData;
int err;
{
// Use legacy API for scanning
api = 0;
apiSwitchPresent = 1;
}
else
if(strcmp(argv[2],"-api:1") == 0 )
{
// Use extended API for scanning
api = 1;
apiSwitchPresent = 1;
}
else
{
// Use legacy API.
api = 0;
}
}
sprintf( pszStartUpString, "server:%s", argv[1] );
if(apiSwitchPresent == 1)
i = 3;
else
i = 2;
for( ; i<argc; i++ )
{
printf( "============================\n");
printf( "Scanning file: %s\n", argv[i] );
printf( "============================\n");
scanfile( scanclient, argv[i], argv[i], api );
}
ScanClientShutDown( scanclient );
// ERROR
}
#endif
return 0;
}
/*
** Scans a file
**
** Parameters:
** scanclient: Symantec Protection Engine client connection
** orig_name: Original name of the file
** actual_name: Name of the file on this machine
**
** Returns:
** 1 for success
** 0 for failure
*/
int scanfile( HSCANCLIENT scanclient, char *orig_name,
char *actual_name, int api)
{
HSCANRESULTS results=NULL;
SCSCANFILE_RESULT answer;
char repair_file[MAX_STRING];
int numproblems=0;
#define SCANWHOLEFILE
#if defined(SCANWHOLEFILE)
// Perform the scan
if( api == 1)
{
// Use extended API for scanning
answer = ScanClientScanFileEx( scanclient,
orig_name,
actual_name,
repair_file,
//"Default:1",
//"ScanOnly:1",
//"RepairOnly:1",
Using the antivirus API 63
About the sample code
"",
&results
);
}
else
{
// Use legacy API for scanning
answer = ScanClientScanFile( scanclient,
orig_name,
actual_name,
repair_file,
//"Default:1",
//"ScanOnly:1",
//"RepairOnly:1",
"",
&results
);
}
#else // SCANWHOLEFILE
char sendbuff[8 * 1024];
if (SC_OK != scanClientStreamStartResult)
{
if (scanClientStreamStartResult == SC_SERVER_TOO_BUSY)
printf( "\nError: Server too busy.\n");
return 0;
}
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;
}
if (iChunkSize < 0)
{
Using the antivirus API 65
About the sample code
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;
}
close( fd );
#endif // if defined(WIN32)
if( results )
{
ScanResultsFree( results );
}
return 0;
}
switch( answer )
{
case SCSCANFILE_INF_NO_REP:
printf( "File is infected and cannot be repaired\n");
break;
case SCSCANFILE_INF_REPAIRED:
printf( "File was infected, and has been repaired\n");
break;
case SCSCANFILE_CLEAN:
printf( "File is clean\n");
break;
default:
printf( "ScanClientScanFile returned an unexpected value\n");
break;
}
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, int api )
{
char attrib[MAX_STRING];
int attrib_size;
int iDisposition;
char* ptrStrTrue = NULL;
Using the antivirus API 68
About the sample code
ptrStrTrue = "true";
attrib_size = MAX_STRING;
ScanResultGetProblem( hResults,
iWhichProblem,
SC_PROBLEM_FILENAME,
attrib,
&attrib_size );
printf( "File Name: %s\n", attrib );
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_NONVIRAL_THREAT_CATEGORY,
Using the antivirus API 69
About the sample code
attrib,
&attrib_size );
if( attrib_size > 0)
{
printf( "Threat Category: %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_FILE_UNSCANABLE,
attrib,
&attrib_size );
if(strcmp(attrib,ptrStrTrue) == 0)
printf("Unscannable: true\n");
else
printf("Unscannable: false\n");
iWhichProblem,
SC_PROBLEM_EX_VIRAL_THREAT_CATEGORY,
attrib,
&attrib_size );
// uber categoriess
attrib_size = MAX_STRING;
ScanResultGetProblem( hResults,
iWhichProblem,
SC_PROBLEM_EX_UBERCATEGORIES,
attrib,
&attrib_size );
if (attrib_size > 0)
{
printf( "Uber Categories: %s\n", attrib);
}
// sub cat id
attrib_size = MAX_STRING;
ScanResultGetProblem( hResults,
iWhichProblem,
SC_PROBLEM_EX_SUBCATEGORY_ID,
attrib,
&attrib_size );
if (attrib_size > 0)
{
printf( "Sub Category ID: %s\n", attrib);
}
if (attrib_size > 0)
{
printf( "Cumulative Risk Rating: %s\n", attrib);
}
// performance impact
attrib_size = MAX_STRING;
ScanResultGetProblem( hResults,
iWhichProblem,
SC_PROBLEM_EX_PERFORMANCE_IMPACT,
attrib,
&attrib_size );
if (attrib_size > 0)
{
printf( "Performance Impact: %s\n", attrib);
}
// privacy impact
attrib_size = MAX_STRING;
ScanResultGetProblem( hResults,
iWhichProblem,
SC_PROBLEM_EX_PRIVACY_IMPACT,
attrib,
&attrib_size );
if (attrib_size > 0)
{
printf( "Privacy Impact: %s\n", attrib);
}
// ease of removal
attrib_size = MAX_STRING;
ScanResultGetProblem( hResults,
iWhichProblem,
SC_PROBLEM_EX_EASE_OF_REMOVAL,
attrib,
&attrib_size );
if (attrib_size > 0)
{
printf( "Ease of Removal: %s\n", attrib);
}
Using the antivirus API 72
About the sample code
// stealth
attrib_size = MAX_STRING;
ScanResultGetProblem( hResults,
iWhichProblem,
SC_PROBLEM_EX_STEALTH,
attrib,
&attrib_size );
if (attrib_size > 0)
{
printf( "Stealth: %s\n", attrib);
}
// subcategory description
attrib_size = MAX_STRING;
ScanResultGetProblem( hResults,
iWhichProblem,
SC_PROBLEM_EX_SUBCATEGORY_DESCRIPTION,
attrib,
&attrib_size );
if (attrib_size > 0)
{
printf( "Sub Category Description: %s\n", attrib);
}
}
}
// End of extended threat info
attrib_size = MAX_STRING;
ScanResultGetProblem( hResults,
iWhichProblem,
SC_PROBLEM_DISPOSITION,
attrib,
&attrib_size );
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 );
attrib_size = MAX_STRING;
ScanResultGetProblem( hResults,
iWhichProblem,
SC_PROBLEM_DEFINITION_REV,
attrib,
&attrib_size );
printf( "Virus Definitions Revision: %s\n", attrib );
}
Index
B L
backward compatibility 14 linking
API libraries 17
C load balancing
cache servers 9 ScanClientScanFile 28
client applications
about 8 M
configuring makefile
with API libraries 16 Red Hat Linux 19
Index 75
makefile (continued) W
Solaris 19 winsock
initializing 18
P shutting down 18, 29
parameters.. See API functions
Protection Engine
about 7
proxy servers 9
R
return codes.. See API functions
risks 10, 12
S
SC_DECODE_DISPOSITION 45
scan policies
setting
API 29
ScanClientScanFile 28, 33
ScanClientScanFileEx 33
ScanClientScanFileInsight 29
ScanClientShutDown 46
ScanClientStartUp 21
ScanClientStreamAbort 54
ScanClientStreamFinish 52
ScanClientStreamSendBytes 51
ScanClientStreamStart 47
ScanClientStreamStartEx 48
ScanClientStreamStartInsight 48
ScanGetConnectError 56
ScanGetNumConnectErrors 55
ScanResultGetNumProblems 34
ScanResultGetProblem 37
ScanResultsFree 46
stream scanning
ScanClientStreamStart() 50
ScanClientStreamStartEx() 50
ScanClientStreamStartInsight() 50
T
threats 10, 12
U
unscannable files 14