Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

separated install and prepare, install is now root #110

Merged
merged 3 commits into from
Aug 27, 2024
Merged
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
3 changes: 3 additions & 0 deletions src/get.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@
int get_repos(char** list)
{
dbg(3, "checking for repos");
DIR *d;

Check warning on line 37 in src/get.c

View workflow job for this annotation

GitHub Actions / c-linter

src/get.c:37:10 [cppcoreguidelines-init-variables]

variable 'd' is not initialized
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 All @@ -47,10 +50,10 @@
printf("Error : too many elements in list , reallocating\n");
list = realloc(list,(count+512) * sizeof(char*));
}
if (dir->d_type != DT_DIR || dir->d_name[0] == '.') continue;

Check warning on line 53 in src/get.c

View workflow job for this annotation

GitHub Actions / c-linter

src/get.c:53:64 [readability-braces-around-statements]

statement should be inside braces

list[count] = calloc(strlen(dir->d_name) + 1, sizeof(char));
strcpy(list[count], dir->d_name);

Check warning on line 56 in src/get.c

View workflow job for this annotation

GitHub Actions / c-linter

src/get.c:56:13 [clang-analyzer-security.insecureAPI.strcpy]

Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119
count++;
}
}
Expand All @@ -72,7 +75,7 @@
}
}

closedir(d);

Check warning on line 78 in src/get.c

View workflow job for this annotation

GitHub Actions / c-linter

src/get.c:78:5 [clang-analyzer-core.NonNullParamChecker]

Null pointer passed to 1st parameter expecting 'nonnull'

dbg(3, "done checking for repos");
return count;
Expand All @@ -94,7 +97,7 @@
// Check if the repository directory exists
if (access(repo_dir, F_OK) != 0) {
// Create the repository directory if it doesn't exist
snprintf(cmd, sizeof(cmd), "mkdir -p %s", repo_dir);

Check warning on line 100 in src/get.c

View workflow job for this annotation

GitHub Actions / c-linter

src/get.c:100:9 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]

Call to function 'snprintf' 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 'snprintf_s' in case of C11
if (system(cmd) != 0) {
printf("Failed to create directory %s\n", repo_dir);
return 1;
Expand All @@ -119,10 +122,10 @@
}

// Check if submodule exists
snprintf(cmd, sizeof(cmd), "git submodule status %s | grep -qF ' %s '", repo_dir, submodule_name);

Check warning on line 125 in src/get.c

View workflow job for this annotation

GitHub Actions / c-linter

src/get.c:125:9 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]

Call to function 'snprintf' 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 'snprintf_s' in case of C11
if (system(cmd) != 0) {
// Add the submodule
snprintf(cmd, sizeof(cmd), "git submodule add --depth 1 %s %s", repo_url, submodule_name);

Check warning on line 128 in src/get.c

View workflow job for this annotation

GitHub Actions / c-linter

src/get.c:128:13 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]

Call to function 'snprintf' 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 'snprintf_s' in case of C11
if (system(cmd) != 0) {
printf("Failed to add submodule %s\n", submodule_name);
return 2;
Expand Down
25 changes: 22 additions & 3 deletions src/install.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define _GNU_SOURCE

Check warning on line 1 in src/install.c

View workflow job for this annotation

GitHub Actions / c-linter

src/install.c:1:9 [bugprone-reserved-identifier]

declaration uses identifier '_GNU_SOURCE', which is a reserved identifier

#include <stdio.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -155,6 +155,10 @@
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 @@
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 @@

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 @@
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
18 changes: 18 additions & 0 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@

void test_make(char* spm_path) {

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

msg(INFO,"Testing 'make()'..");

init();
Expand All @@ -159,6 +162,21 @@

assert(make(legacy_dir,&p) == 0);

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

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

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

Check failure on line 176 in test/test.c

View workflow job for this annotation

GitHub Actions / c-linter

test/test.c:176:9 [clang-diagnostic-return-type]

void function 'test_make' should not return a value
}
dbg(1, "Install command executed!");

dbg(1,"Getting locations for %s",p.name);
p.locationsCount = get_locations(&p.locations,getenv("SOVIET_BUILD_DIR"));
assert(p.locationsCount > 0);
Expand Down
Loading