]> git.ipfire.org Git - pakfire.git/commitdiff
jail: Move pakfire_execute_shell/ldconfig
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 3 Aug 2022 10:22:27 +0000 (10:22 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 3 Aug 2022 10:22:27 +0000 (10:22 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c
src/libpakfire/execute.c
src/libpakfire/include/pakfire/execute.h
src/libpakfire/include/pakfire/jail.h
src/libpakfire/jail.c
src/libpakfire/transaction.c

index 769dbdee932e3ec829e1b8a921efd36ec4403e6a..afc3cadb58fec717c6adbca4f3bfecddbb5afa69 100644 (file)
@@ -736,7 +736,7 @@ static int pakfire_build_makefile(struct pakfire* pakfire, const char* path, con
                if (r) {
                        // Drop to a shell for debugging
                        if (pakfire_has_flag(pakfire, PAKFIRE_FLAGS_INTERACTIVE))
-                               pakfire_execute_shell(pakfire);
+                               pakfire_jail_shell(pakfire);
 
                        goto ERROR;
                }
@@ -944,7 +944,7 @@ PAKFIRE_EXPORT int pakfire_shell(struct pakfire* pakfire, const char** packages)
        if (r)
                return r;
 
-       return pakfire_execute_shell(pakfire);
+       return pakfire_jail_shell(pakfire);
 }
 
 int pakfire_build_clean(struct pakfire* pakfire, int flags) {
index 20aef735cce1f457244e24dfe4f81de643fb2a3e..b6304d4a058a85bbf56025e4e3a575ba2760fe64 100644 (file)
@@ -29,8 +29,6 @@
 #include <pakfire/private.h>
 #include <pakfire/util.h>
 
-#define LDCONFIG         "/sbin/ldconfig"
-
 PAKFIRE_EXPORT int pakfire_execute(struct pakfire* pakfire, const char* argv[], char* envp[],
                int flags, pakfire_execute_logging_callback logging_callback, void* data) {
        struct pakfire_jail* jail = NULL;
@@ -63,34 +61,3 @@ ERROR:
        return r;
 }
 
-int pakfire_execute_shell(struct pakfire* pakfire) {
-       const char* argv[] = {
-               "/bin/bash", "--login", NULL,
-       };
-
-       // Execute /bin/bash
-       return pakfire_jail_run(pakfire, argv, PAKFIRE_JAIL_INTERACTIVE, NULL);
-}
-
-int pakfire_execute_ldconfig(struct pakfire* pakfire) {
-       char path[PATH_MAX];
-
-       // Check if ldconfig exists before calling it to avoid overhead
-       int r = pakfire_make_path(pakfire, path, LDCONFIG);
-       if (r < 0)
-               return 1;
-
-       // Check if ldconfig is executable
-       r = access(path, X_OK);
-       if (r) {
-               DEBUG(pakfire, "%s is not executable. Skipping...\n", LDCONFIG);
-               return 0;
-       }
-
-       const char* argv[] = {
-               LDCONFIG, NULL,
-       };
-
-       // Run ldconfig
-       return pakfire_jail_run(pakfire, argv, 0, NULL);
-}
index 660c22e15987577415a4cf6bf6fc1cbfffe3d16e..69ba55819d48386f92a7e7b3d653b242b28c1fad 100644 (file)
@@ -35,11 +35,4 @@ enum {
        PAKFIRE_EXECUTE_INTERACTIVE     = (1 << 1),
 };
 
-#ifdef PAKFIRE_PRIVATE
-
-int pakfire_execute_shell(struct pakfire* pakfire);
-int pakfire_execute_ldconfig(struct pakfire* pakfire);
-
-#endif
-
 #endif /* PAKFIRE_EXECUTE_H */
index bda8d91d8951f8dc48d6fcdc3ee3888421d8608d..e5060925a8fc7849404c9bb4285003d314f0eb60 100644 (file)
@@ -59,6 +59,9 @@ int pakfire_jail_run(struct pakfire* pakfire, const char* argv[], int flags, cha
 int pakfire_jail_run_script(struct pakfire* pakfire,
        const char* script, const size_t length, const char* argv[], int flags, char*** output);
 
+int pakfire_jail_shell(struct pakfire* pakfire);
+int pakfire_jail_ldconfig(struct pakfire* pakfire);
+
 #endif
 
 #endif /* PAKFIRE_JAIL_H */
index 39362d477724ce2d76df37e46f0a15a9bbeda730..a5fdee074bafe5eeac57e53bc3228a43a7829985 100644 (file)
@@ -1270,3 +1270,38 @@ ERROR:
 
        return r;
 }
+
+
+int pakfire_jail_shell(struct pakfire* pakfire) {
+       const char* argv[] = {
+               "/bin/bash", "--login", NULL,
+       };
+
+       // Execute /bin/bash
+       return pakfire_jail_run(pakfire, argv, PAKFIRE_JAIL_INTERACTIVE, NULL);
+}
+
+int pakfire_jail_ldconfig(struct pakfire* pakfire) {
+       char path[PATH_MAX];
+
+       const char* ldconfig = "/sbin/ldconfig";
+
+       // Check if ldconfig exists before calling it to avoid overhead
+       int r = pakfire_make_path(pakfire, path, ldconfig);
+       if (r < 0)
+               return 1;
+
+       // Check if ldconfig is executable
+       r = access(path, X_OK);
+       if (r) {
+               DEBUG(pakfire, "%s is not executable. Skipping...\n", ldconfig);
+               return 0;
+       }
+
+       const char* argv[] = {
+               ldconfig, NULL,
+       };
+
+       // Run ldconfig
+       return pakfire_jail_run(pakfire, argv, 0, NULL);
+}
index 6e853207483611de6b1c34b19c3bd3be6058c44c..3070088ffa8f862c7295013bd26f768df4d52901 100644 (file)
 #include <pakfire/archive.h>
 #include <pakfire/db.h>
 #include <pakfire/downloader.h>
-#include <pakfire/execute.h>
 #include <pakfire/file.h>
 #include <pakfire/filelist.h>
 #include <pakfire/i18n.h>
+#include <pakfire/jail.h>
 #include <pakfire/logging.h>
 #include <pakfire/package.h>
 #include <pakfire/pakfire.h>
@@ -763,7 +763,7 @@ static int pakfire_transaction_extract(struct pakfire_transaction* transaction,
 
                // Update the runtime linker cache
                if (need_ldconfig)
-                       pakfire_execute_ldconfig(transaction->pakfire);
+                       pakfire_jail_ldconfig(transaction->pakfire);
 
                pakfire_filelist_unref(filelist);
        }
@@ -797,7 +797,7 @@ static int pakfire_transaction_erase(struct pakfire_transaction* transaction,
        }
 
        // Update the runtime linker cache after all files have been removed
-       pakfire_execute_ldconfig(transaction->pakfire);
+       pakfire_jail_ldconfig(transaction->pakfire);
 
 ERROR:
        if (filelist)