diff --git a/.gitea/workflows/actions.yaml b/.gitea/workflows/actions.yaml index 6080ca2..0497311 100644 --- a/.gitea/workflows/actions.yaml +++ b/.gitea/workflows/actions.yaml @@ -3,14 +3,51 @@ run-name: ${{ gitea.actor }} on: [push] jobs: - Prepare-Build-Testing: - runs-on: alpine-sdk + Prepare-Build-Testing-With-Make: + runs-on: ubuntu-latest steps: - - name: prepare-container - run: echo "185.130.83.26 gitea.home.com" >> /etc/hosts - name: Check out repository code uses: actions/checkout@v3 - - name: Building binary - run: make - - name: Testing to run binary - run: ./bin/sudo ls + - name: Building binary with make + run: | + make -j$(nproc) && \ + chown 0:0 sudo && \ + chmod 4755 sudo + - name: Testing binary + run: ./sudo ls + + Prepare-Build-Testing-With-CMake: + runs-on: ubuntu-latest + steps: + - name: prepare-container + run: | + apt install -y cmake + - name: Check out repository code + uses: actions/checkout@v3 + - name: Building binary with CMake + run: | + mkdir build && \ + cd build && \ + cmake .. && \ + make -j$(nproc) && \ + chown 0:0 sudo && \ + chmod 4755 sudo + - name: Testing binary + run: ./build/sudo ls + + Prepare-Build-Testing-With-Meson: + runs-on: ubuntu-latest + steps: + - name: prepare-container + run: | + apt install -y meson + - name: Check out repository code + uses: actions/checkout@v3 + - name: Building binary with meson + run: | + meson setup build && \ + meson compile -C build && \ + chown 0:0 build/sudo && \ + chmod 4755 build/sudo + - name: Testing binary + run: ./build/sudo ls diff --git a/.gitignore b/.gitignore index 9b6cedc..789ab96 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,8 @@ bin .vscode sudo.pkg -sudo.pkg.gz \ No newline at end of file +sudo.pkg.gz +build +.cache +*.o +sudo diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..cf9ce12 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required (VERSION 3.6) +project(sudo LANGUAGES C) + +set(CMAKE_C_STANDARD 23) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +# include_directories(./src/libs/) +FILE(GLOB_RECURSE SOURCES src/*.c) + +# find_package(package-name REQUIRED) + +add_executable( + sudo + ${SOURCES} +) +# target_link_libraries(project_name package-name::package-name) diff --git a/Makefile b/Makefile index 8790478..77ec485 100644 --- a/Makefile +++ b/Makefile @@ -1,28 +1,20 @@ -CC=gcc -CFLAGS=-Wall -SOURCES=src/sudo.c -TARGET=bin/sudo +CC = gcc +CFLAGS = -Wall -g -std=gnu2x +LDFLAGS = +LIBS = +INCLUDES = -I./src/lib -I./src +SRCS = $(wildcard src/*.c src/lib/*.c) +OBJS = $(SRCS:.c=.o) +TARGET = sudo +CROSS_COMPILE = -default: all +all: $(TARGET) -all: build +$(TARGET): $(OBJS) + $(CROSS_COMPILE)$(CC) $(LDFLAGS) $^ -o $@ $(LIBS) -build: - @if [ ! -d bin ]; then \ - mkdir bin; \ - fi - $(CC) -o $(TARGET) $(SOURCES) $(CFLAGS) - chown -v 0:0 $(TARGET) - chmod 4755 $(TARGET) +%.o: %.c + $(CROSS_COMPILE)$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@ clean: - rm -v $(TARGET) - -package: - mkdir -pv sudo.pkg/usr/bin - cp -v $(TARGET) sudo.pkg/usr/bin/sudo - echo "/usr/bin/sudo" > sudo.pkg/list - printf "#!/bin/sh\nchown -v 0:0 /usr/bin/sudo\nchmod 4755 /usr/bin/sudo" > sudo.pkg/post_install - chmod +x sudo.pkg/post_install - tar -czvf sudo.pkg.gz sudo.pkg - \ No newline at end of file + rm -f $(OBJS) $(TARGET) $(shell find . -type f -name '*.log') users.db diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..1494f78 --- /dev/null +++ b/meson.build @@ -0,0 +1,3 @@ +project('sudo', 'c', default_options: ['cpp_std=c20']) +include_dirs = include_directories('src') +executable('sudo', 'src/main.c', include_directories: include_dirs, install: true) diff --git a/src/sudo.c b/src/main.c similarity index 80% rename from src/sudo.c rename to src/main.c index f4297f1..3c1fc63 100644 --- a/src/sudo.c +++ b/src/main.c @@ -16,17 +16,14 @@ void die(char *argv0, char *obj, char *msg) { int main(int argc, char *argv[]) { uid_t uid; gid_t gid; - // char *endp; /* Command line parsing */ if (argc <= 1) { fprintf(stderr, "Usage: %s COMMAND [ARG...]\n", argv[0]==NULL ? "sugexec" : argv[0]); exit(127); } - uid = 0;//strtoul(argv[1], &endp, 0); - // if (*endp) die(argv[0], argv[1], "Bad uid"); - gid = 0;//strtoul(argv[2], &endp, 0); - // if (*endp) die(argv[0], argv[2], "Bad gid"); + uid = 0; + gid = 0; /* Drop to specified user and group */ if (setgid(gid)) die(argv[0], "setgid", NULL); if (setgroups(0, NULL)) die(argv[0], "setgroups", NULL); @@ -34,4 +31,4 @@ int main(int argc, char *argv[]) { /* Execute the command */ execvp(argv[1], argv+1); die(argv[0], argv[1], NULL); -} \ No newline at end of file +}