From: Michael Tremer Date: Wed, 22 Feb 2023 10:49:06 +0000 (+0000) Subject: Check if makefile name matches the package name X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b164a3dbba64c1d65f5b6b643c427bd72a0b59c9;p=people%2Fstevee%2Fpakfire.git Check if makefile name matches the package name This is quite important because the build process relies on it. Fixes: #13041 - pakfire-builder confuses on wrong .nm file name Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 8ba32a72..9f677756 100644 --- a/Makefile.am +++ b/Makefile.am @@ -232,6 +232,7 @@ libpakfire_la_SOURCES = \ src/libpakfire/jail.c \ src/libpakfire/key.c \ src/libpakfire/keystore.c \ + src/libpakfire/linter.c \ src/libpakfire/logging.c \ src/libpakfire/mount.c \ src/libpakfire/package.c \ @@ -272,6 +273,7 @@ pkginclude_HEADERS += \ src/libpakfire/include/pakfire/jail.h \ src/libpakfire/include/pakfire/key.h \ src/libpakfire/include/pakfire/keystore.h \ + src/libpakfire/include/pakfire/linter.h \ src/libpakfire/include/pakfire/logging.h \ src/libpakfire/include/pakfire/mount.h \ src/libpakfire/include/pakfire/package.h \ diff --git a/src/libpakfire/dist.c b/src/libpakfire/dist.c index a5a9feaf..61ed0a4f 100644 --- a/src/libpakfire/dist.c +++ b/src/libpakfire/dist.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -409,6 +410,11 @@ PAKFIRE_EXPORT int pakfire_dist(struct pakfire* pakfire, const char* path, if (r) goto ERROR; + // Perform some linting + r = pakfire_lint_makefile(pakfire, makefile, path, pkg); + if (r) + goto ERROR; + // Create a packager r = pakfire_packager_create(&packager, pakfire, pkg); if (r) diff --git a/src/libpakfire/include/pakfire/linter.h b/src/libpakfire/include/pakfire/linter.h new file mode 100644 index 00000000..3c3626a9 --- /dev/null +++ b/src/libpakfire/include/pakfire/linter.h @@ -0,0 +1,31 @@ +/*############################################################################# +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2023 Pakfire development team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +#############################################################################*/ + +#ifndef PAKFIRE_LINTER_H +#define PAKFIRE_LINTER_H + +#include +#include +#include + +int pakfire_lint_makefile(struct pakfire* pakfire, struct pakfire_parser* makefile, + const char* path, struct pakfire_package* pkg); + +#endif /* PAKFIRE_LINTER_H */ diff --git a/src/libpakfire/include/pakfire/util.h b/src/libpakfire/include/pakfire/util.h index 162235ca..f0742169 100644 --- a/src/libpakfire/include/pakfire/util.h +++ b/src/libpakfire/include/pakfire/util.h @@ -39,6 +39,8 @@ char* pakfire_unquote_in_place(char* s); int pakfire_path_exists(const char* path); time_t pakfire_path_age(const char* path); +int pakfire_path_strip_extension(char* path); + const char* pakfire_basename(const char* path); const char* pakfire_dirname(const char* path); diff --git a/src/libpakfire/linter.c b/src/libpakfire/linter.c new file mode 100644 index 00000000..f1c41f45 --- /dev/null +++ b/src/libpakfire/linter.c @@ -0,0 +1,75 @@ +/*############################################################################# +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2023 Pakfire development team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +#############################################################################*/ + +#include +#include +#include +#include +#include +#include +#include + +static int pakfire_lint_makefile_name(struct pakfire* pakfire, + const char* path, struct pakfire_package* pkg) { + char basename[PATH_MAX]; + int r; + + // Fetch the package name + const char* name = pakfire_package_get_string(pkg, PAKFIRE_PKG_NAME); + + // Check if the makefile ended on .nm + if (!pakfire_string_endswith(path, ".nm")) { + ERROR(pakfire, "Invalid extension for makefile: %s\n", path); + return 1; + } + + // Determine the basename of the file + r = pakfire_string_set(basename, pakfire_basename(path)); + if (r) + return r; + + // Remove the file extension + r = pakfire_path_strip_extension(basename); + if (r) { + ERROR(pakfire, "Could not strip extension from makefile: %m\n"); + return r; + } + + // Check if the package name matches + if (strcmp(basename, name) != 0) { + ERROR(pakfire, "%s: Makefile has a different package name (%s)\n", + path, name); + return 1; + } + + return 0; +} + +int pakfire_lint_makefile(struct pakfire* pakfire, struct pakfire_parser* makefile, + const char* path, struct pakfire_package* pkg) { + int r; + + // Check makefile name + r = pakfire_lint_makefile_name(pakfire, path, pkg); + if (r) + return r; + + return 0; +} diff --git a/src/libpakfire/util.c b/src/libpakfire/util.c index cc4fbdcc..442ddc0a 100644 --- a/src/libpakfire/util.c +++ b/src/libpakfire/util.c @@ -153,6 +153,19 @@ time_t pakfire_path_age(const char* path) { return -1; } +int pakfire_path_strip_extension(char* path) { + char* ext = strrchr(path, '.'); + + // If . could not be found, we return an error. + if (!ext) + return 1; + + // Otherwise, we will terminate the string + *ext = '\0'; + + return 0; +} + int pakfire_file_write(struct pakfire* pakfire, const char* path, uid_t owner, gid_t group, mode_t mode, const char* format, ...) { va_list args;