Info/Layer3/Sophos.pm untested

filter: Statementstmt 0.0% 0 / 47 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 110 CC 9 SCAR 19.2
CC
9
Cov
0%
name
12.0
layers
12.0
_is_sfos
6.0
CRAP 6.8
1 # SNMP::Info::Layer3::Sophos
2 #
3 # Copyright (c) 2026 The SNMP::Info Developers
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
8 #
9 # * Redistributions of source code must retain the above copyright notice,
10 # this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # * Neither the name of the University of California, Santa Cruz nor the
15 # names of its contributors may be used to endorse or promote products
16 # derived from this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 # LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 # POSSIBILITY OF SUCH DAMAGE.
29  
30 package SNMP::Info::Layer3::Sophos;
31  
32 use strict;
33 use warnings;
34 use Exporter;
35 use SNMP::Info::Layer3;
36  
37 @SNMP::Info::Layer3::Sophos::ISA = qw/SNMP::Info::Layer3 Exporter/;
38 @SNMP::Info::Layer3::Sophos::EXPORT_OK = qw//;
39  
40 our ($VERSION, %GLOBALS, %MIBS, %FUNCS, %MUNGE);
41  
42 $VERSION = '3.985003';
43  
44 %MIBS = (%SNMP::Info::Layer3::MIBS);
45  
46 my $name_oid_override = $ENV{SNMP_INFO_SOPHOS_NAME_OID};
47  
48 # Numeric OIDs from the sfosXGDeviceInfo group of SFOS-FIREWALL-MIB, so that
49 # the class still works where the vendor MIB is not installed.
50 %GLOBALS = (
51 %SNMP::Info::Layer3::GLOBALS,
52 'sfos_name' => ( $name_oid_override
53 || '.1.3.6.1.4.1.2604.5.1.1.1.0' ), # sfosDeviceName
54 'os_ver' => '.1.3.6.1.4.1.2604.5.1.1.3.0', # sfosDeviceFWVersion
55 'serial1' => '.1.3.6.1.4.1.2604.5.1.1.4.0', # sfosDeviceAppKey
56 'sfos_model' => '.1.3.6.1.4.1.2604.5.1.1.2.0', # sfosDeviceType
57 );
58  
59 %FUNCS = (%SNMP::Info::Layer3::FUNCS);
60  
61 %MUNGE = (%SNMP::Info::Layer3::MUNGE);
62  
63 sub vendor {
64 return 'sophos';
65 }
66  
67 # Only SFOS lives under .1.3.6.1.4.1.2604.5. %l3sysoidmap keys on the bare
68 # enterprise number, so other Sophos appliances under 2604 reach this class as
69 # well; they must keep the inherited behaviour instead of these fixed strings.
70 sub _is_sfos {
71 my $sophos = shift;
72  
73 return ( ( $sophos->id() || '' )
74 =~ /^\.1\.3\.6\.1\.4\.1\.2604\.5(?:\.|$)/ ) ? 1 : 0;
75 }
76  
77 # The CS-series switch MIBs place every model under .1.3.6.1.4.1.2604.6.
78 sub _is_cs_switch {
79 my $sophos = shift;
80  
81 return ( ( $sophos->id() || '' )
82 =~ /^\.1\.3\.6\.1\.4\.1\.2604\.6(?:\.|$)/ ) ? 1 : 0;
83 }
84  
85 sub os {
86 my $sophos = shift;
87  
88 return 'sfos' if $sophos->_is_sfos();
89 return $sophos->SUPER::os();
90 }
91  
92 sub name {
93 my $sophos = shift;
94  
95 if ( $name_oid_override || $sophos->_is_sfos() ) {
96 my $name = $sophos->sfos_name();
97 return $name if defined $name and $name =~ /\S/;
98 }
99  
100 return $sophos->SUPER::name();
101 }
102  
103 sub model {
104 my $sophos = shift;
105  
106 # sysObjectID is the MIB module node on SFOS, the same value on every
107 # model, so the inherited translation of it is of no use here.
108 my $model = $sophos->sfos_model();
109 return $model if defined $model and $model =~ /\S/;
110  
111 # %l3sysoidmap keys on the bare enterprise number, so older Astaro and
112 # UTM appliances under other 2604 subtrees reach this class as well.
113 # They do not serve sfosDeviceType, and returning nothing there would be
114 # a regression against the inherited method, which at least hands back
115 # the raw sysObjectID.
116 return $sophos->SUPER::model();
117 }
118  
119 sub layers {
120 my $sophos = shift;
121  
122 return '01001100' if $sophos->_is_sfos();
123  
124 my $layers = $sophos->SUPER::layers();
125  
126 # CS-series access switches report sysServices 72, without layer 2.
127 if ( $layers and $sophos->_is_cs_switch() ) {
128 substr $layers, 6, 1, '1';
129 }
130  
131 return $layers;
132 }
133  
134 1;
135  
136 __END__