develop #5

Merged
wt merged 2 commits from develop into main 2026-02-07 19:44:31 +07:00
6 changed files with 87 additions and 38 deletions
+45 -8
View File
@@ -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
+5 -1
View File
@@ -1,4 +1,8 @@
bin
.vscode
sudo.pkg
sudo.pkg.gz
sudo.pkg.gz
build
.cache
*.o
sudo
+16
View File
@@ -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)
+15 -23
View File
@@ -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
rm -f $(OBJS) $(TARGET) $(shell find . -type f -name '*.log') users.db
+3
View File
@@ -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)
+3 -6
View File
@@ -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);
}
}