Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/detection/packages/packages.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ typedef struct FFPackagesResult {
uint32_t hpkgUser;
uint32_t installrelease;
uint32_t kiss;
uint32_t kuzpkg;
uint32_t linglong;
uint32_t lpkg;
uint32_t lpkgbuild;
Expand Down
40 changes: 40 additions & 0 deletions src/detection/packages/packages_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,43 @@ static uint32_t getPacmanPackages(FFstrbuf* baseDir) {
return getNumElements(baseDir, dbPath.chars, true);
}

static uint32_t getKuzpkgPackages(FFstrbuf* baseDir) {
FF_STRBUF_AUTO_DESTROY dbPath = ffStrbufCreate();
FF_STRBUF_AUTO_DESTROY rootDir = ffStrbufCreate();

// Get path to kuzpkg.conf
uint32_t baseDirLen = baseDir->length;
ffStrbufAppendS(baseDir, "/etc/kuzpkg.conf");

bool confFound = ffParsePropFileValues(baseDir->chars, 2, (FFpropquery[]) {
{ "DBPath =", &dbPath },
{ "RootDir =", &rootDir },
});

ffStrbufSubstrBefore(baseDir, baseDirLen);

if (confFound) {
if (dbPath.length > 0) {
// If DBPath is specified, use it
ffStrbufEnsureEndsWithC(&dbPath, '/');
ffStrbufAppendS(&dbPath, "local");
} else if (rootDir.length > 0) {
// Otherwise, use RootDir
ffStrbufDestroy(&dbPath);
ffStrbufInitMove(&dbPath, &rootDir);
ffStrbufEnsureEndsWithC(&dbPath, '/');
ffStrbufAppendS(&dbPath, "var/lib/kuzpkg/local");
}
}

// Default Kuzpkg database location
if (dbPath.length == 0) {
ffStrbufSetStatic(&dbPath, "/var/lib/kuzpkg/local");
}

return getNumElements(baseDir, dbPath.chars, true);
}

static uint32_t getEmergePackagesImpl(FFstrbuf* baseDir) {
FF_AUTO_CLOSE_DIR DIR* dirp = opendir(baseDir->chars);
if (dirp == nullptr)
Expand Down Expand Up @@ -508,6 +545,9 @@ static void getPackageCounts(FFstrbuf* baseDir, FFPackagesResult* packageCounts,
if (FF_PACKAGES_IS_ENABLED(options, KISS)) {
packageCounts->kiss += getNumElements(baseDir, "/var/db/kiss/installed", true);
}
if (FF_PACKAGES_IS_ENABLED(options, KUZPKG)) {
packageCounts->kuzpkg += getKuzpkgPackages(baseDir);
}
if (FF_PACKAGES_IS_ENABLED(options, NIX)) {
packageCounts->nixDefault += ffPackagesGetNix(baseDir, "/nix/var/nix/profiles/default");
packageCounts->nixSystem += ffPackagesGetNix(baseDir, "/run/current-system");
Expand Down
21 changes: 13 additions & 8 deletions src/modules/packages/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ typedef enum FFPackagesFlags: uint64_t {
FF_PACKAGES_FLAG_PISI_BIT = UINT64_C(1) << 29U,
FF_PACKAGES_FLAG_SOAR_BIT = UINT64_C(1) << 30U,
FF_PACKAGES_FLAG_KISS_BIT = UINT64_C(1) << 31U,
FF_PACKAGES_FLAG_MOSS_BIT = UINT64_C(1) << 32U,
FF_PACKAGES_FLAG_APPIMAGE_BIT = UINT64_C(1) << 33U,
FF_PACKAGES_FLAG_CARDS_BIT = UINT64_C(1) << 34U,
FF_PACKAGES_FLAG_PORG_BIT = UINT64_C(1) << 35U,
FF_PACKAGES_FLAG_INSTALLRELEASE_BIT = UINT64_C(1) << 36U,
FF_PACKAGES_FLAG_CRUX_BIT = UINT64_C(1) << 37U,
FF_PACKAGES_FLAG_RUM_BIT = UINT64_C(1) << 38U,
FF_PACKAGES_FLAG_KUZPKG_BIT = UINT64_C(1) << 32U,
FF_PACKAGES_FLAG_MOSS_BIT = UINT64_C(1) << 33U,
FF_PACKAGES_FLAG_APPIMAGE_BIT = UINT64_C(1) << 34U,
FF_PACKAGES_FLAG_CARDS_BIT = UINT64_C(1) << 35U,
FF_PACKAGES_FLAG_PORG_BIT = UINT64_C(1) << 36U,
FF_PACKAGES_FLAG_INSTALLRELEASE_BIT = UINT64_C(1) << 37U,
FF_PACKAGES_FLAG_CRUX_BIT = UINT64_C(1) << 38U,
FF_PACKAGES_FLAG_RUM_BIT = UINT64_C(1) << 39U,
} FFPackagesFlags;

static_assert(sizeof(FFPackagesFlags) == sizeof(uint64_t), "");

typedef struct FFPackagesOptions {
Expand All @@ -55,4 +57,7 @@ typedef struct FFPackagesOptions {
bool combined;
} FFPackagesOptions;

static_assert(sizeof(FFPackagesOptions) <= FF_OPTION_MAX_SIZE, "FFPackagesOptions size exceeds maximum allowed size");
static_assert(
sizeof(FFPackagesOptions) <= FF_OPTION_MAX_SIZE,
"FFPackagesOptions size exceeds maximum allowed size"
);
6 changes: 6 additions & 0 deletions src/modules/packages/packages.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ bool ffPrintPackages(FFPackagesOptions* options) {
}
FF_PRINT_PACKAGE_NAME(installrelease, "install-release")
FF_PRINT_PACKAGE(kiss)
FF_PRINT_PACKAGE(kuzpkg)
FF_PRINT_PACKAGE(linglong)
FF_PRINT_PACKAGE(lpkg)
FF_PRINT_PACKAGE(lpkgbuild)
Expand Down Expand Up @@ -169,6 +170,7 @@ bool ffPrintPackages(FFPackagesOptions* options) {
FF_ARG(counts.hpkgUser, "hpkg-user"),
FF_ARG(counts.installrelease, "install-release"),
FF_ARG(counts.kiss, "kiss"),
FF_ARG(counts.kuzpkg, "kuzpkg"),
FF_ARG(counts.linglong, "linglong"),
FF_ARG(counts.lpkg, "lpkg"),
FF_ARG(counts.lpkgbuild, "lpkgbuild"),
Expand Down Expand Up @@ -298,6 +300,7 @@ void ffParsePackagesJsonObject(FFPackagesOptions* options, yyjson_val* module) {
if (false)
;
FF_TEST_PACKAGE_NAME(KISS)
FF_TEST_PACKAGE_NAME(KUZPKG)
break;
case 'L':
if (false)
Expand Down Expand Up @@ -404,6 +407,7 @@ void ffGeneratePackagesJsonConfig(FFPackagesOptions* options, yyjson_mut_doc* do
FF_TEST_PACKAGE_NAME(GUIX)
FF_TEST_PACKAGE_NAME(HPKG)
FF_TEST_PACKAGE_NAME(KISS)
FF_TEST_PACKAGE_NAME(KUZPKG)
FF_TEST_PACKAGE_NAME(LINGLONG)
FF_TEST_PACKAGE_NAME(LPKG)
FF_TEST_PACKAGE_NAME(LPKGBUILD)
Expand Down Expand Up @@ -472,6 +476,7 @@ bool ffGeneratePackagesJsonResult(FFPackagesOptions* options, yyjson_mut_doc* do
FF_APPEND_PACKAGE_COUNT(hpkgUser)
FF_APPEND_PACKAGE_COUNT(installrelease)
FF_APPEND_PACKAGE_COUNT(kiss)
FF_APPEND_PACKAGE_COUNT(kuzpkg)
FF_APPEND_PACKAGE_COUNT(linglong)
FF_APPEND_PACKAGE_COUNT(lpkg)
FF_APPEND_PACKAGE_COUNT(lpkgbuild)
Expand Down Expand Up @@ -572,6 +577,7 @@ FFModuleBaseInfo ffPackagesModuleInfo = {
{ "Number of hpkg-user packages", "hpkg-user" },
{ "Number of install-release packages", "install-release" },
{ "Number of kiss packages", "kiss" },
{ "Number of kuzpkg packages", "kuzpkg" },
{ "Number of linglong packages", "linglong" },
{ "Number of lpkg packages", "lpkg" },
{ "Number of lpkgbuild packages", "lpkgbuild" },
Expand Down