9 Commits
Author SHA1 Message Date
wt 17ce6b287d Merge pull request 'Update .gitea/workflows/actions.yaml' (#6) from develop into main
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Successful in 6s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Successful in 19s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Successful in 17s
Reviewed-on: #6
2026-09-17 17:07:09 +07:00
wt 68e60e9615 Update .gitea/workflows/actions.yaml
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Successful in 6s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Successful in 18s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Successful in 17s
2026-09-17 17:05:56 +07:00
wt 6e6e0b91fd Merge pull request 'develop' (#5) from develop into main
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Successful in 5s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Successful in 8s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Successful in 8s
Reviewed-on: https://gitea.home.com:3000/TolaMironcenko/sudo/pulls/5
2026-02-07 19:44:29 +07:00
wt 9d9c73debb updated .gitignore and main.c
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Successful in 5s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Successful in 10s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Successful in 8s
2026-02-07 19:43:28 +07:00
wt a820f1f032 added cmake meson update makefile and update actions
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Successful in 5s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Successful in 11s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Successful in 9s
2026-02-07 19:38:52 +07:00
wt bce5ba8ef5 Merge pull request 'Update actions.yaml' (#4) from fix-actions into main
Prepare Build and Testing executable binary / Prepare-Build-Testing (push) Successful in 3s
Reviewed-on: https://gitea.home.com:3000/TolaMironcenko/sudo/pulls/4
2025-07-18 21:27:02 +07:00
wt 4ad5dc92ca Update actions.yaml
Prepare Build and Testing executable binary / Prepare-Build-Testing (push) Successful in 4s
2025-07-18 21:26:10 +07:00
wt 4b3a29078e Merge pull request 'added README and LICENSE' (#3) from docs-and-license into main
Prepare Build and Testing executable binary / Prepare-Build-Testing (push) Failing after 38s
Reviewed-on: https://gitea.home.com:3000/TolaMironcenko/sudo/pulls/3
2025-07-16 17:08:51 +07:00
wt 0a40c775ac added README and LICENSE
Prepare Build and Testing executable binary / Prepare-Build-Testing (push) Failing after 30s
2025-07-16 17:08:29 +07:00
8 changed files with 272 additions and 39 deletions
+35 -9
View File
@@ -3,14 +3,40 @@ run-name: ${{ gitea.actor }}
on: [push] on: [push]
jobs: jobs:
Prepare-Build-Testing: Prepare-Build-Testing-With-Make:
runs-on: alpine-sdk runs-on: ubuntu-latest
steps: steps:
- name: prepare-container
run: echo "83.172.39.220 gitea.home.com" >> /etc/hosts
- name: Check out repository code - name: Check out repository code
uses: actions/checkout@v3 uses: actions/checkout@v4
- name: Building binary - name: Building binary with make
run: make run: make -j$(nproc)
- name: Testing to run binary - name: Testing binary
run: ./bin/sudo ls run: chown 0:0 sudo && chmod 4755 sudo && ./sudo ls
Prepare-Build-Testing-With-CMake:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Install build tools
run: apt update && apt install -y cmake
- name: Configure CMake
run: cmake -B ${{gitea.workspace}}/build
- name: Build project
run: cmake --build ${{gitea.workspace}}/build
- name: Testing binary
run: chown 0:0 ./build/sudo && chmod 4755 ./build/sudo && ./build/sudo ls
Prepare-Build-Testing-With-Meson:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Install build tools
run: apt update && apt install -y meson
- name: Configure Project
run: meson setup build --buildtype=release
- name: Build Project
run: meson compile -C build
- name: Testing binary
run: chown 0:0 build/sudo && chmod 4755 build/sudo && ./build/sudo ls
+4
View File
@@ -2,3 +2,7 @@ bin
.vscode .vscode
sudo.pkg 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)
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2025 [Your Name]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+14 -22
View File
@@ -1,28 +1,20 @@
CC = gcc CC = gcc
CFLAGS=-Wall CFLAGS = -Wall -g -std=gnu2x
SOURCES=src/sudo.c LDFLAGS =
TARGET=bin/sudo 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: %.o: %.c
@if [ ! -d bin ]; then \ $(CROSS_COMPILE)$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
mkdir bin; \
fi
$(CC) -o $(TARGET) $(SOURCES) $(CFLAGS)
chown -v 0:0 $(TARGET)
chmod 4755 $(TARGET)
clean: clean:
rm -v $(TARGET) rm -f $(OBJS) $(TARGET) $(shell find . -type f -name '*.log') users.db
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
+174
View File
@@ -0,0 +1,174 @@
# sudo - A Simple Sudo Implementation
A lightweight implementation of the `sudo` command for Unix-like systems, written in C.
## Overview
This project provides a minimal yet functional `sudo` replacement that allows users to execute commands with root privileges. It's designed to be simple, secure, and easy to understand.
## Features
- Execute commands as root user
- Minimal dependencies (standard C library only)
- Cross-platform support (Linux focused)
- Proper error handling and reporting
- Package creation for easy distribution
## Building
### Prerequisites
- GCC compiler
- Make utility
- Root access (for installation)
### Compilation
```bash
make build
```
This will:
- Create the `bin/` directory if it doesn't exist
- Compile the source code with appropriate flags
- Set the binary owner to root (0:0)
- Set the setuid bit (4755 permissions)
### Cleaning
```bash
make clean
```
Removes the compiled binary from the `bin/` directory.
## Installation
### Manual Installation
After building, you can manually copy the binary to your system:
```bash
sudo cp bin/sudo /usr/bin/sudo
sudo chown root:root /usr/bin/sudo
sudo chmod 4755 /usr/bin/sudo
```
### Package Installation
Create a package for distribution:
```bash
make package
```
This creates a `sudo.pkg.gz` archive containing:
- The binary
- Installation files
- Post-installation script for proper permissions
## Usage
```bash
sudo COMMAND [ARG...]
```
### Examples
```bash
# Edit a system file
sudo nano /etc/hosts
# Install a package
sudo apt update
# View system logs
sudo tail -f /var/log/syslog
# Run a command as root
sudo whoami
```
## Security Considerations
⚠️ **Important Security Notes:**
1. **Setuid Root**: This binary runs with setuid root permissions, which is necessary for privilege escalation but comes with security risks.
2. **No Authentication**: This implementation does not include password authentication. In a production environment, you should implement proper authentication mechanisms.
3. **No Access Control**: There are no restrictions on which users can use this sudo implementation or which commands they can run.
4. **Audit Logging**: This version does not log command execution. Consider adding logging for security auditing.
## Architecture
The implementation consists of:
- **Command Line Parsing**: Validates arguments and displays usage information
- **Privilege Escalation**: Uses `setuid()`, `setgid()`, and `setgroups()` to gain root privileges
- **Command Execution**: Uses `execvp()` to execute the target command
- **Error Handling**: Comprehensive error reporting with proper exit codes
## Code Structure
```
sudo/
├── src/
│ └── sudo.c # Main implementation
├── bin/ # Compiled binary (created during build)
├── Makefile # Build configuration
├── LICENSE # MIT License
└── README.md # This file
```
## Development
### Building for Development
```bash
# Build the project
make build
# Test the binary
./bin/sudo whoami
```
### Debugging
For debugging, you can modify the `CFLAGS` in the Makefile to include debug symbols:
```makefile
CFLAGS=-Wall -g -DDEBUG
```
## Limitations
This is a simplified implementation and lacks many features of the full sudo:
- No configuration file (`/etc/sudoers`)
- No password authentication
- No user/group restrictions
- No command logging
- No timeout functionality
- No environment variable handling
## Contributing
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Test thoroughly
5. Submit a pull request
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Disclaimer
This software is provided for educational and development purposes. Use in production environments should be done with careful consideration of security implications. The authors are not responsible for any security vulnerabilities or system damage resulting from the use of this software.
## Support
For questions, issues, or contributions, please refer to the project's issue tracker or contact the maintainers.
+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)
+2 -5
View File
@@ -16,17 +16,14 @@ void die(char *argv0, char *obj, char *msg) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
uid_t uid; uid_t uid;
gid_t gid; gid_t gid;
// char *endp;
/* Command line parsing */ /* Command line parsing */
if (argc <= 1) { if (argc <= 1) {
fprintf(stderr, "Usage: %s COMMAND [ARG...]\n", fprintf(stderr, "Usage: %s COMMAND [ARG...]\n",
argv[0]==NULL ? "sugexec" : argv[0]); argv[0]==NULL ? "sugexec" : argv[0]);
exit(127); exit(127);
} }
uid = 0;//strtoul(argv[1], &endp, 0); uid = 0;
// if (*endp) die(argv[0], argv[1], "Bad uid"); gid = 0;
gid = 0;//strtoul(argv[2], &endp, 0);
// if (*endp) die(argv[0], argv[2], "Bad gid");
/* Drop to specified user and group */ /* Drop to specified user and group */
if (setgid(gid)) die(argv[0], "setgid", NULL); if (setgid(gid)) die(argv[0], "setgid", NULL);
if (setgroups(0, NULL)) die(argv[0], "setgroups", NULL); if (setgroups(0, NULL)) die(argv[0], "setgroups", NULL);