Skip to content

Commit

Permalink
separated install and prepare, install is now root
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksArt000 committed Aug 24, 2024
1 parent 2c5cc1f commit 7c3c91a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 28 deletions.
3 changes: 3 additions & 0 deletions src/get.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ int get_repos(char** list)
struct dirent *dir;

Check warning on line 38 in src/get.c

View workflow job for this annotation

GitHub Actions / c-linter

src/get.c:38:20 [cppcoreguidelines-init-variables]

variable 'dir' is not initialized
d = opendir(getenv("SOVIET_REPOS_DIR"));
int count = 0;
list[count] = calloc(strlen("local") + 1, 1);
sprintf(list[count], "local");

Check warning on line 42 in src/get.c

View workflow job for this annotation

GitHub Actions / c-linter

src/get.c:42:5 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]

Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11
count++;
if (d)
{
while ((dir = readdir(d)) != NULL)
Expand Down
25 changes: 22 additions & 3 deletions src/install.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ int f_install_package_source(const char* spm_path, int as_dep, char* repo) {
setenv("SHA256", pkg.sha256, 1);
}

// Set environment variables for building
setenv("BUILD_ROOT", build_dir, 1);


// Check if a package is a collection
if(strcmp(pkg.type, "con") != 0)
{
Expand All @@ -174,11 +178,11 @@ int f_install_package_source(const char* spm_path, int as_dep, char* repo) {
if (getuid() == 0)
{
/* process is running as root, drop privileges */
if (setgid(1000) != 0)
if (setgid(65534) != 0)
{
msg(ERROR, "setgid: Unable to drop group privileges");
}
if (setuid(1000) != 0)
if (setuid(65534) != 0)
{
msg(ERROR, "setuid: Unable to drop user privileges");
}
Expand All @@ -200,6 +204,21 @@ int f_install_package_source(const char* spm_path, int as_dep, char* repo) {

dbg(1, "Making %s done", pkg.name);

// Run 'install' command
if (pkg.info.install == NULL && strlen(pkg.info.install) == 0) {
msg(FATAL, "No install command!");
}

char install_cmd[64 + strlen(legacy_dir) + strlen(pkg.info.install)];
sprintf(install_cmd, "( cd %s && %s )", legacy_dir, pkg.info.install);

dbg(2, "Executing install command: %s", install_cmd);
if (system(install_cmd) != 0) {
msg(FATAL, "Failed to install %s", pkg.name);
return -2;
}
dbg(1, "Install command executed!");

// Get package locations
dbg(1, "Getting locations for %s", pkg.name);
pkg.locationsCount = get_locations(&pkg.locations, getenv("SOVIET_BUILD_DIR"));
Expand Down Expand Up @@ -448,7 +467,7 @@ int free_pkg(struct package* pkg) {
if (pkg->info.special != NULL) free(pkg->info.special);
if (pkg->info.download != NULL) free(pkg->info.download);
if (pkg->info.install != NULL) free(pkg->info.install);
if (pkg->info.prepare != NULL) free(pkg->info.install);
if (pkg->info.prepare != NULL) free(pkg->info.prepare);
if (pkg->info.test != NULL) free(pkg->info.test);

if (pkg->locations) {
Expand Down
23 changes: 2 additions & 21 deletions src/make.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ int make(char* package_dir, struct package* pkg) {
cmd_params = "";
}

// Set environment variables for building
setenv("BUILD_ROOT", build_dir, 1);


// TODO: this
// Thinking about putting the package caching here
// Maybe it will check if the installed version matches $VERSION
Expand Down Expand Up @@ -168,7 +164,8 @@ int make(char* package_dir, struct package* pkg) {

dbg(2, "Executing prepare command: %s", prepare_cmd);
if (system(prepare_cmd) != 0) {
return 1;
msg(FATAL, "Failed to prepare %s", pkg->name);
return -2;
}
dbg(1, "Prepare command executed!");
}
Expand Down Expand Up @@ -197,22 +194,6 @@ int make(char* package_dir, struct package* pkg) {
dbg(1, "Test command executed!");
}

// Run 'install' command
if (pkg->info.install == NULL && strlen(pkg->info.install) == 0) {
msg(ERROR, "No install command!");
return -3;
}

char install_cmd[64 + strlen(package_dir) + strlen(pkg->info.install) + strlen(cmd_params)];
sprintf(install_cmd, "( cd %s && %s ) %s", package_dir, pkg->info.install, cmd_params);

dbg(2, "Executing install command: %s", install_cmd);
if (system(install_cmd) != 0) {
msg(FATAL, "Failed to install %s", pkg->name);
return -2;
}
dbg(1, "Install command executed!");

return 0;
}

Expand Down
4 changes: 0 additions & 4 deletions src/uninstall.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ int uninstall(char* name)
int REPO_COUNT = get_repos(REPOS);
char* dataSpmPath = calloc(MAX_PATH, sizeof(char));

// add local repo
REPOS[REPO_COUNT] = "local";
REPO_COUNT++;

for (int j = 0; j < REPO_COUNT; j++)
{
// Generate the path to the package's SPM file
Expand Down

0 comments on commit 7c3c91a

Please sign in to comment.