-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathdetector_all.go
More file actions
1507 lines (1300 loc) · 37.1 KB
/
detector_all.go
File metadata and controls
1507 lines (1300 loc) · 37.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1
package detector
import (
"bytes"
"io"
"regexp"
"runtime"
"strings"
"github.com/rs/zerolog/log"
"github.com/spf13/afero"
"go.mondoo.com/mql/v13/providers-sdk/v1/inventory"
"go.mondoo.com/mql/v13/providers/os/connection/shared"
)
const (
LabelDistroID = "distro-id"
)
// Operating Systems
var macOS = &PlatformResolver{
Name: "macos",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
// when we reach here, we know it is darwin
// check xml /System/Library/CoreServices/SystemVersion.plist
f, err := conn.FileSystem().Open("/System/Library/CoreServices/SystemVersion.plist")
if err != nil {
return false, nil
}
defer f.Close()
c, err := io.ReadAll(f)
if err != nil || len(c) == 0 {
return false, nil
}
sv, err := ParseMacOSSystemVersion(string(c))
if err != nil || len(c) == 0 {
return false, nil
}
pf.Name = "macos"
pf.Title = sv["ProductName"]
pf.Version = sv["ProductVersion"]
pf.Build = sv["ProductBuildVersion"]
return true, nil
},
}
// is part of the darwin platform and fallback for non-known darwin systems
var otherDarwin = &PlatformResolver{
Name: "darwin",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
return true, nil
},
}
var alpine = &PlatformResolver{
Name: "alpine",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
// check if we are on edge
osrd := NewOSReleaseDetector(conn)
osr, err := osrd.osrelease()
if err != nil {
return false, nil
}
if osr["PRETTY_NAME"] == "Alpine Linux edge" {
pf.Name = "alpine"
pf.Version = "edge"
pf.Build = osr["VERSION_ID"]
}
// if we are on alpine, the release was detected properly from parent check
if pf.Name == "alpine" {
return true, nil
}
f, err := conn.FileSystem().Open("/etc/alpine-release")
if err != nil {
return false, nil
}
defer f.Close()
c, err := io.ReadAll(f)
if err != nil || len(c) == 0 {
return false, nil
}
pf.Name = "alpine"
return true, nil
},
}
var arch = &PlatformResolver{
Name: "arch",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "arch" {
return true, nil
}
return false, nil
},
}
var manjaro = &PlatformResolver{
Name: "manjaro",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "manjaro" {
return true, nil
}
return false, nil
},
}
var azurelinux = &PlatformResolver{
Name: "azurelinux",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "azurelinux" {
osrd := NewOSReleaseDetector(conn)
osr, err := osrd.osrelease()
if err == nil {
pf.Title = osr["NAME"]
pf.Build = osr["VERSION"]
}
return true, nil
}
return false, nil
},
}
var flatcar = &PlatformResolver{
Name: "flatcar",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "flatcar" {
osrd := NewOSReleaseDetector(conn)
osr, err := osrd.osrelease()
if err == nil {
pf.Title = osr["NAME"]
}
return true, nil
}
return false, nil
},
}
var debian = &PlatformResolver{
Name: "debian",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
osrd := NewOSReleaseDetector(conn)
f, err := conn.FileSystem().Open("/etc/debian_version")
if err != nil {
return false, nil
}
defer f.Close()
c, err := io.ReadAll(f)
if err != nil || len(c) == 0 {
return false, nil
}
osr, err := osrd.osrelease()
if err != nil {
return false, nil
}
if osr["ID"] != "debian" {
return false, nil
}
// gardenlinux identifies itself as debian, but we want to set the proper name / version
if osr["GARDENLINUX_VERSION"] != "" {
pf.Name = "gardenlinux"
pf.Version = osr["GARDENLINUX_VERSION"]
} else {
pf.Version = strings.TrimSpace(string(c))
}
unamem, err := osrd.unamem()
if err == nil {
pf.Arch = unamem
}
return true, nil
},
}
var gardenlinux = &PlatformResolver{
Name: "gardenlinux",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name != "gardenlinux" {
return false, nil
}
osrd := NewOSReleaseDetector(conn)
osr, err := osrd.osrelease()
if err != nil {
return false, nil
}
pf.Version = osr["GARDENLINUX_VERSION"]
return true, nil
},
}
var ubuntu = &PlatformResolver{
Name: "ubuntu",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "ubuntu" {
return true, nil
}
return false, nil
},
}
var zorin = &PlatformResolver{
Name: "zorin",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "zorin" {
return true, nil
}
return false, nil
},
}
var cumulus = &PlatformResolver{
Name: "cumulus-linux",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name != "cumulus-linux" {
return false, nil
}
osrd := NewOSReleaseDetector(conn)
image, err := osrd.imagerelease()
if err != nil {
return false, nil
}
// Notice from the docs:
// The /etc/image-release file updates only when you run a Cumulus Linux image install.
// Therefore, if you run a Cumulus Linux image install of Cumulus Linux 5.13, followed by a package upgrade to 5.15, the /etc/image-release file continues to display Cumulus Linux 5.13, which is the originally installed base image.
pf.Build = image["IMAGE_BUILD_SERIAL_ID"]
return true, nil
},
}
var parrot = &PlatformResolver{
Name: "parrot",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "parrot" {
return true, nil
}
return false, nil
},
}
var raspbian = &PlatformResolver{
Name: "raspbian",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "raspbian" {
return true, nil
}
return false, nil
},
}
var kali = &PlatformResolver{
Name: "kali",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "kali" {
return true, nil
}
return false, nil
},
}
var linuxmint = &PlatformResolver{
Name: "linuxmint",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "linuxmint" {
return true, nil
}
return false, nil
},
}
var popos = &PlatformResolver{
Name: "pop",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "pop" {
return true, nil
}
return false, nil
},
}
var endeavouros = &PlatformResolver{
Name: "endeavouros",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "endeavouros" {
return true, nil
}
return false, nil
},
}
var elementary = &PlatformResolver{
Name: "elementary",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "elementary" {
return true, nil
}
return false, nil
},
}
var steamos = &PlatformResolver{
Name: "steamos",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "steamos" {
return true, nil
}
return false, nil
},
}
var cachyos = &PlatformResolver{
Name: "cachyos",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "cachyos" {
return true, nil
}
return false, nil
},
}
var nobara = &PlatformResolver{
Name: "nobara",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "nobara" {
return true, nil
}
return false, nil
},
}
var qubes = &PlatformResolver{
Name: "qubes",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "qubes" {
return true, nil
}
return false, nil
},
}
var netscoutHardenedOS = &PlatformResolver{
Name: "netscout-hardened-os",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "NetScout Hardened OS" {
pf.Name = "netscout-hardened-os"
return true, nil
}
return false, nil
},
}
var tails = &PlatformResolver{
Name: "tails",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "tails" {
return true, nil
}
return false, nil
},
}
var kdeneon = &PlatformResolver{
Name: "neon",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "neon" {
return true, nil
}
return false, nil
},
}
// rhel PlatformResolver only detects redhat and no derivatives
var rhel = &PlatformResolver{
Name: "redhat",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
// etc redhat release was parsed by the family already,
// we reuse that information here
// e.g. Red Hat Linux, Red Hat Enterprise Linux Server
if strings.Contains(pf.Title, "Red Hat") || pf.Name == "redhat" {
pf.Name = "redhat"
return true, nil
}
// fallback to /etc/redhat-release file
f, err := conn.FileSystem().Open("/etc/redhat-release")
if err != nil {
return false, nil
}
defer f.Close()
c, err := io.ReadAll(f)
if err != nil || len(c) == 0 {
return false, nil
}
if strings.Contains(string(c), "Red Hat") {
pf.Name = "redhat"
return true, nil
}
return false, nil
},
}
var eurolinux = &PlatformResolver{
Name: "eurolinux",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "eurolinux" {
return true, nil
}
return false, nil
},
}
// The centos platform resolver finds CentOS and CentOS-like platforms like alma and rocky
var centos = &PlatformResolver{
Name: "centos",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
// works for centos 5+
if strings.Contains(pf.Title, "CentOS") || pf.Name == "centos" {
pf.Name = "centos"
return true, nil
}
// adapt the name for rocky to align it with amazonlinux, almalinux etc.
if pf.Name == "rocky" {
pf.Name = "rockylinux"
}
// newer alma linux do not have /etc/centos-release, check for alma linux
afs := &afero.Afero{Fs: conn.FileSystem()}
if pf.Name == "almalinux" {
if ok, err := afs.Exists("/etc/almalinux-release"); err == nil && ok {
return true, nil
}
}
// newer rockylinux do not have /etc/centos-release
if pf.Name == "rockylinux" {
if ok, err := afs.Exists("/etc/rocky-release"); err == nil && ok {
return true, nil
}
}
// NOTE: CentOS 5 does not have /etc/centos-release
// fallback to /etc/centos-release file
if ok, err := afs.Exists("/etc/centos-release"); err != nil || !ok {
return false, nil
}
if len(pf.Name) == 0 {
pf.Name = "centos"
}
return true, nil
},
}
var fedora = &PlatformResolver{
Name: "fedora",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if strings.Contains(pf.Title, "Fedora") || pf.Name == "fedora" {
pf.Name = "fedora"
return true, nil
}
// fallback to /etc/fedora-release file
f, err := conn.FileSystem().Open("/etc/fedora-release")
if err != nil {
return false, nil
}
defer f.Close()
c, err := io.ReadAll(f)
if err != nil || len(c) == 0 {
return false, nil
}
if len(pf.Name) == 0 {
pf.Name = "fedora"
}
return true, nil
},
}
var oracle = &PlatformResolver{
Name: "oracle",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
// works for oracle 7+
if pf.Name == "ol" {
pf.Name = "oraclelinux"
return true, nil
}
// check if we have /etc/oracle-release file
f, err := conn.FileSystem().Open("/etc/oracle-release")
if err != nil {
return false, nil
}
defer f.Close()
c, err := io.ReadAll(f)
if err != nil || len(c) == 0 {
return false, nil
}
if len(pf.Name) == 0 {
pf.Name = "oraclelinux"
}
return true, nil
},
}
var scientific = &PlatformResolver{
Name: "scientific",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
// works for oracle 7+
if pf.Name == "scientific" {
return true, nil
}
// we only get here if this is a rhel distribution
if strings.Contains(pf.Title, "Scientific Linux") {
pf.Name = "scientific"
return true, nil
}
return false, nil
},
}
var amazonlinux = &PlatformResolver{
Name: "amazonlinux",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "amzn" {
pf.Name = "amazonlinux"
return true, nil
}
return false, nil
},
}
var bottlerocket = &PlatformResolver{
Name: "bottlerocket",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
f, err := conn.FileSystem().Open("/etc/bottlerocket-release")
if err != nil {
return false, nil
}
defer f.Close()
c, err := io.ReadAll(f)
if err != nil || len(c) == 0 {
log.Debug().Err(err)
return false, nil
}
osr, err := ParseOsRelease(strings.TrimSpace(string(c)))
if err == nil {
if len(osr["ID"]) > 0 {
pf.Name = osr["ID"]
}
if len(osr["PRETTY_NAME"]) > 0 {
pf.Title = osr["PRETTY_NAME"]
}
if len(osr["VERSION_ID"]) > 0 {
pf.Version = osr["VERSION_ID"]
}
if len(osr["BUILD_ID"]) > 0 {
pf.Build = osr["BUILD_ID"]
}
}
if pf.Name == "bottlerocket" {
return true, nil
}
return false, nil
},
}
var windriver = &PlatformResolver{
Name: "wrlinux",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "wrlinux" {
return true, nil
}
return false, nil
},
}
var opensuse = &PlatformResolver{
Name: "opensuse",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "opensuse" || pf.Name == "opensuse-leap" || pf.Name == "opensuse-tumbleweed" {
return true, nil
}
return false, nil
},
}
var sles = &PlatformResolver{
Name: "sles",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "sles" {
// SLES can have various modules/repos activated, identify them via filesystem
modules := getActivatedSlesModules(conn)
pf.Metadata["suse/modules"] = strings.Join(modules, ",")
baseproduct := getSlesBaseProduct(conn)
if len(baseproduct) > 0 {
pf.Metadata["suse/baseproduct"] = baseproduct
}
return true, nil
}
return false, nil
},
}
var suseMicroOs = &PlatformResolver{
Name: "suse-microos",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "suse-microos" {
return true, nil
}
return false, nil
},
}
var gentoo = &PlatformResolver{
Name: "gentoo",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "gentoo" {
return true, nil
}
return false, nil
},
}
var busybox = &PlatformResolver{
Name: "busybox",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
busyboxExists, err := afero.Exists(conn.FileSystem(), "/bin/busybox")
if !busyboxExists || err != nil {
return false, nil
}
// we need to read this file because all others show up as zero size
// This fille seems to be the "original"
// all others are hardlinks
f, err := conn.FileSystem().Open("/bin/[")
if err != nil {
return false, nil
}
defer f.Close()
content, err := io.ReadAll(f)
if err != nil {
return false, err
}
// strings are \0 terminated
rodataByteStrings := bytes.Split(content, []byte("\x00"))
if rodataByteStrings == nil {
return false, nil
}
releaseRegex := regexp.MustCompile(`^(.+)\s(v[\d\.]+)\s*\((.*)\).*$`)
for _, rodataByteString := range rodataByteStrings {
rodataString := string(rodataByteString)
m := releaseRegex.FindStringSubmatch(rodataString)
if len(m) >= 2 {
title := m[1]
release := m[2]
if strings.ToLower(title) == "busybox" {
pf.Name = "busybox"
pf.Title = title
pf.Version = release
return true, nil
}
}
}
return false, nil
},
}
var photon = &PlatformResolver{
Name: "photon",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "photon" {
return true, nil
}
return false, nil
},
}
var mageia = &PlatformResolver{
Name: "mageia",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "mageia" {
return true, nil
}
return false, nil
},
}
var mxlinux = &PlatformResolver{
Name: "mxlinux",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
osrd := NewOSReleaseDetector(conn)
lsb, err := osrd.lsbconfig()
// we're not on mx if we can't read lsb
if err != nil {
return false, nil
}
if len(lsb["DISTRIB_ID"]) > 0 && strings.ToLower(lsb["DISTRIB_ID"]) == "mx" {
pf.Name = "mx"
pf.Version = lsb["DISTRIB_RELEASE"]
pf.Title = lsb["DISTRIB_DESCRIPTION"]
return true, nil
}
return false, nil
},
}
var openwrt = &PlatformResolver{
Name: "openwrt",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
// modern releases of openwrt include /etc/os-release but legacy versions do not
f, err := conn.FileSystem().Open("/etc/openwrt_release")
if err != nil {
return false, err
}
defer f.Close()
content, err := io.ReadAll(f)
if err != nil {
return false, err
}
lsb, err := ParseLsbRelease(string(content))
if err == nil {
if len(lsb["DISTRIB_ID"]) > 0 {
pf.Name = strings.ToLower(lsb["DISTRIB_ID"])
pf.Title = lsb["DISTRIB_ID"]
}
if len(lsb["DISTRIB_RELEASE"]) > 0 {
pf.Version = lsb["DISTRIB_RELEASE"]
}
return true, nil
}
return false, nil
},
}
var (
plcnextVersion = regexp.MustCompile(`(?m)^Arpversion:\s+(.*)$`)
plcnextBuildVersion = regexp.MustCompile(`(?m)^GIT Commit Hash:\s+(.*)$`)
)
var plcnext = &PlatformResolver{
Name: "plcnext",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
// No clue why they are not using either lsb-release or os-release
f, err := conn.FileSystem().Open("/etc/plcnext/arpversion")
if err != nil {
return false, err
}
defer f.Close()
content, err := io.ReadAll(f)
if err != nil {
return false, err
}
m := plcnextVersion.FindStringSubmatch(string(content))
if len(m) >= 2 {
pf.Name = "plcnext"
pf.Title = "PLCnext"
pf.Version = m[1]
bm := plcnextBuildVersion.FindStringSubmatch(string(content))
if len(bm) >= 2 {
pf.Build = bm[1]
}
return true, err
}
return false, nil
},
}
var openeuler = &PlatformResolver{
Name: "openeuler",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "openEuler" {
pf.Name = "openeuler"
return true, nil
}
return false, nil
},
}
var hce = &PlatformResolver{
Name: "hce",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if pf.Name == "hce" {
return true, nil
}
return false, nil
},
}
var euleros = &PlatformResolver{
Name: "euleros",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
// EulerOS includes /etc/os-release file, but version information in this file is not reliable
// So, we need to check whether /etc/euleros-release file exists
f, err := conn.FileSystem().Open("/etc/euleros-release")
if err != nil {
return false, nil
}
defer f.Close()
content, err := io.ReadAll(f)
if err != nil {
return false, err
}
prettyName := strings.Trim(string(content), "\n")
if len(prettyName) > 0 {
// align with title from /etc/os-release
// EulerOS release 2.0 (SP9x86_64) => EulerOS 2.0 (SP9x86_64)
prettyName = strings.Replace(prettyName, " release", "", 1)
pf.Title = prettyName
}
if pf.Name == "euleros" {
return true, nil
}
return false, nil
},
}
// fallback linux detection, since we do not know the system, the family detection may not be correct
var defaultLinux = &PlatformResolver{
Name: "generic-linux",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
// if we reach here, we know that we detected linux already
log.Debug().Msg("platform> we do not know the linux system, but we do our best in guessing")
return true, nil
},
}
var netbsd = &PlatformResolver{
Name: "netbsd",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if !strings.Contains(strings.ToLower(pf.Name), "netbsd") {
return false, nil
}
osrd := NewOSReleaseDetector(conn)
release, err := osrd.unamer()
if err == nil {
pf.Version = release
}
return true, nil
},
}
var freebsd = &PlatformResolver{
Name: "freebsd",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if !strings.Contains(strings.ToLower(pf.Name), "freebsd") {
return false, nil
}
osrd := NewOSReleaseDetector(conn)
release, err := osrd.unamer()
if err == nil {
pf.Version = release
}
return true, nil
},
}
var openbsd = &PlatformResolver{
Name: "openbsd",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if !strings.Contains(strings.ToLower(pf.Name), "openbsd") {
return false, nil
}
osrd := NewOSReleaseDetector(conn)
release, err := osrd.unamer()
if err == nil {
pf.Version = release
}
return true, nil
},
}
var dragonflybsd = &PlatformResolver{
Name: "dragonflybsd",
IsFamily: false,
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
if !strings.Contains(strings.ToLower(pf.Name), "dragonfly") {
return false, nil
}
pf.Name = "dragonflybsd"
osrd := NewOSReleaseDetector(conn)
release, err := osrd.unamer()
if err == nil {