@@ -8,56 +8,55 @@ import (
88const (
99 // OS constants
1010 linuxOSName = "Linux"
11-
11+
1212 // Service names
1313 ufwService = "ufw"
1414 iptablesService = "iptables"
15-
15+
1616 // Command keywords
1717 ufwStatusActive = "status: active"
1818 cryptoLUKS = "crypto_luks"
1919 cryptKeyword = "crypt"
2020 trueKeyword = "true"
21-
21+
2222 // Firewall rule keywords
2323 allowKeyword = "ALLOW"
2424 denyKeyword = "DENY"
2525 acceptKeyword = "ACCEPT"
2626 dropKeyword = "DROP"
2727 rejectKeyword = "REJECT"
28-
28+
2929 // Table headers to ignore
3030 chainPrefix = "Chain"
3131 targetPrefix = "target"
3232 numPrefix = "num"
3333)
3434
35- var (
36- // Common Linux antivirus software
37- linuxAntivirusSoftware = []string {"clamav" , "sophos" , "avast" , "bitdefender" , "eset" }
38- )
35+ // Common Linux antivirus software
36+ var linuxAntivirusSoftware = []string {"clamav" , "sophos" , "avast" , "bitdefender" , "eset" }
3937
4038// LinuxCollector collects device posture on Linux systems
4139type LinuxCollector struct {}
4240
4341// CollectPosture collects device posture information on Linux
4442func (c * LinuxCollector ) CollectPosture () (* DevicePosture , error ) {
4543 posture := & DevicePosture {
46- OS : OperatingSystem {
44+ OS : & OperatingSystem {
4745 Name : linuxOSName ,
4846 Arch : runtime .GOARCH ,
4947 },
48+ Firewall : & FirewallStatus {},
5049 }
5150
5251 // Collect OS information
53- if err := c .collectOSInfo (& posture .OS ); err != nil {
52+ if err := c .collectOSInfo (posture .OS ); err != nil {
5453 return nil , err
5554 }
5655
5756 // Collect firewall status
58- if err := c .collectFirewallStatus (& posture .Firewall ); err != nil {
57+ if err := c .collectFirewallStatus (posture .Firewall ); err != nil {
5958 // Non-fatal error, continue with default values
60- posture .Firewall = FirewallStatus {Enabled : false , Service : UnknownService }
59+ * posture .Firewall = FirewallStatus {Service : UnknownService }
6160 }
6261
6362 // Collect other security posture information
@@ -132,8 +131,8 @@ func checkUFW(fw *FirewallStatus) bool {
132131 fw .Enabled = strings .Contains (strings .ToLower (output ), ufwStatusActive )
133132
134133 // Count rules (simplified)
135- lines := strings .Split (output , " \n " )
136- ruleCount := 0
134+ lines := strings .Split (output , newline )
135+ ruleCount := initialCapacity
137136 for _ , line := range lines {
138137 line = strings .TrimSpace (line )
139138 if line != "" && ! strings .HasPrefix (line , "Status:" ) &&
@@ -150,6 +149,7 @@ func checkUFW(fw *FirewallStatus) bool {
150149
151150// checkIptables checks iptables firewall status
152151func (c * LinuxCollector ) checkIptables (fw * FirewallStatus ) error {
152+ _ = c
153153 output , err := runCommand ("iptables" , "-L" )
154154 if err != nil {
155155 fw .Enabled = false
@@ -160,7 +160,7 @@ func (c *LinuxCollector) checkIptables(fw *FirewallStatus) error {
160160 fw .Service = iptablesService
161161 // If iptables returns without error and has rules, consider it enabled
162162 lines := strings .Split (output , "\n " )
163- ruleCount := 0
163+ ruleCount := initialCapacity
164164 for _ , line := range lines {
165165 line = strings .TrimSpace (line )
166166 if line != "" && ! strings .HasPrefix (line , chainPrefix ) &&
@@ -180,6 +180,7 @@ func (c *LinuxCollector) checkIptables(fw *FirewallStatus) error {
180180
181181// checkAntiVirus checks for antivirus software
182182func (c * LinuxCollector ) checkAntiVirus () bool {
183+ _ = c
183184 // Check for common Linux antivirus solutions
184185 antivirusSoftware := linuxAntivirusSoftware
185186
@@ -199,12 +200,14 @@ func (c *LinuxCollector) checkAntiVirus() bool {
199200
200201// checkSystemUpdated checks if system is up to date
201202func (c * LinuxCollector ) checkSystemUpdated () bool {
203+ _ = c
202204 // Check for pending updates (works on Debian/Ubuntu systems)
203205 output , err := runCommand ("apt" , "list" , "--upgradable" )
204206 if err == nil {
205- lines := strings .Split (output , " \n " )
207+ lines := strings .Split (output , newline )
206208 // If only header line, no updates available
207- return len (lines ) <= 2
209+ const headerAndFooterLines = 2
210+ return len (lines ) <= headerAndFooterLines
208211 }
209212
210213 // Try yum/dnf for Red Hat systems
@@ -214,11 +217,12 @@ func (c *LinuxCollector) checkSystemUpdated() bool {
214217 return true
215218 }
216219
217- return strings .TrimSpace (output ) == ""
220+ return strings .TrimSpace (output ) == emptyString
218221}
219222
220223// checkDiskEncryption checks if disk encryption is enabled
221224func (c * LinuxCollector ) checkDiskEncryption () bool {
225+ _ = c
222226 // Check for LUKS encrypted devices
223227 output , err := runCommand ("lsblk" , "-f" )
224228 if err != nil {
@@ -232,6 +236,7 @@ func (c *LinuxCollector) checkDiskEncryption() bool {
232236
233237// checkScreenLock checks if screen lock is configured
234238func (c * LinuxCollector ) checkScreenLock () bool {
239+ _ = c
235240 // Check GNOME settings
236241 if output , err := runCommand ("gsettings" , "get" , "org.gnome.desktop.screensaver" , "lock-enabled" ); err == nil {
237242 return strings .Contains (strings .ToLower (output ), trueKeyword )
@@ -248,6 +253,7 @@ func (c *LinuxCollector) checkScreenLock() bool {
248253
249254// isOSSupported checks if the OS version is supported
250255func (c * LinuxCollector ) isOSSupported (osName string ) bool {
256+ _ = c
251257 supportedDistros := []string {
252258 "ubuntu" , "debian" , "centos" , "rhel" , "fedora" ,
253259 "suse" , "opensuse" , "arch" , "mint" , "elementary" ,
0 commit comments