diff --git a/.gitignore b/.gitignore index a916d57..7555bc7 100644 --- a/.gitignore +++ b/.gitignore @@ -66,6 +66,7 @@ rootfs/boot/* !rootfs/README.txt !rootfs/etc/ !rootfs/root/ +!rootfs/home/ # CodeQL _codeql_detected_source_root diff --git a/rootfs/README.txt b/rootfs/README.txt index 65ebae4..a96ef10 100644 --- a/rootfs/README.txt +++ b/rootfs/README.txt @@ -18,7 +18,13 @@ Directory Structure: /usr - User programs /var - Variable data /root - Root home directory - /home - User home directories + /home/spark - Default user home directory + +Default User: + Username: spark (UID 1000) + Home: /home/spark + Sudo: Full access without password + Scripts: ~/clone-sparkos.sh for installing spark CLI Network Configuration: /etc/network/interfaces - Wired network (DHCP) @@ -26,10 +32,11 @@ Network Configuration: /sbin/init-network - Network initialization script Bootstrap Process: - 1. System boots with wired networking (DHCP) - 2. Use git to clone spark CLI repository + 1. System boots as 'spark' user with wired networking (DHCP) + 2. Run ~/clone-sparkos.sh to install spark CLI 3. Use spark CLI to configure WiFi and system 4. Install additional packages via spark CLI + 5. Use 'sudo' for any root-level operations Note: This is a minimal system. You'll need to populate /bin and /usr/bin with actual binaries (busybox, git, sudo) from a proper Linux system diff --git a/rootfs/etc/group b/rootfs/etc/group index 1dbf901..d027b5e 100644 --- a/rootfs/etc/group +++ b/rootfs/etc/group @@ -1 +1,3 @@ root:x:0: +spark:x:1000: +sudo:x:27:spark diff --git a/rootfs/etc/passwd b/rootfs/etc/passwd index eb85a55..c2b6d42 100644 --- a/rootfs/etc/passwd +++ b/rootfs/etc/passwd @@ -1 +1,2 @@ root:x:0:0:root:/root:/bin/sh +spark:x:1000:1000:SparkOS User:/home/spark:/bin/sh diff --git a/rootfs/etc/profile b/rootfs/etc/profile index ad08564..9740db9 100644 --- a/rootfs/etc/profile +++ b/rootfs/etc/profile @@ -2,9 +2,15 @@ export PATH=/bin:/sbin:/usr/bin:/usr/sbin export PS1='SparkOS:\w\$ ' -export HOME=/root export TERM=linux +# Set HOME based on user +if [ "$(id -u)" = "0" ]; then + export HOME=/root +else + export HOME=/home/$(whoami) +fi + # Welcome message echo "Welcome to SparkOS!" echo "Type 'help' for available commands" diff --git a/rootfs/etc/sudoers b/rootfs/etc/sudoers new file mode 100644 index 0000000..73d4f07 --- /dev/null +++ b/rootfs/etc/sudoers @@ -0,0 +1,15 @@ +# SparkOS Sudoers Configuration +# Allow spark user to run any command without password + +# Default settings +Defaults env_reset +Defaults secure_path="/bin:/sbin:/usr/bin:/usr/sbin" + +# Root can run anything +root ALL=(ALL:ALL) ALL + +# Spark user can run anything without password +spark ALL=(ALL:ALL) NOPASSWD: ALL + +# Include sudoers.d directory +@includedir /etc/sudoers.d diff --git a/rootfs/home/spark/.profile b/rootfs/home/spark/.profile new file mode 100644 index 0000000..ee18357 --- /dev/null +++ b/rootfs/home/spark/.profile @@ -0,0 +1,12 @@ +# SparkOS User Shell Configuration + +# Set prompt +PS1='SparkOS:\w\$ ' + +# Aliases +alias ll='ls -lah' +alias ..='cd ..' + +# Environment +export EDITOR=vi +export PAGER=less diff --git a/rootfs/home/spark/clone-sparkos.sh b/rootfs/home/spark/clone-sparkos.sh new file mode 100755 index 0000000..471ca6b --- /dev/null +++ b/rootfs/home/spark/clone-sparkos.sh @@ -0,0 +1,50 @@ +#!/bin/sh +# SparkOS CLI Installation Script +# This script clones the SparkOS CLI repository + +echo "SparkOS CLI Installation" +echo "========================" +echo "" + +SPARK_REPO="https://github.com/johndoe6345789/spark-cli.git" +INSTALL_DIR="$HOME/spark-cli" + +echo "This script will clone the SparkOS CLI to: $INSTALL_DIR" +echo "" + +# Check if git is available +if ! command -v git >/dev/null 2>&1; then + echo "Error: git is not installed" + echo "Please install git to continue" + exit 1 +fi + +# Check if directory already exists +if [ -d "$INSTALL_DIR" ]; then + echo "Warning: $INSTALL_DIR already exists" + echo -n "Do you want to remove it and re-clone? (y/N): " + read answer + if [ "$answer" = "y" ] || [ "$answer" = "Y" ]; then + rm -rf "$INSTALL_DIR" + else + echo "Installation cancelled" + exit 0 + fi +fi + +# Clone the repository +echo "Cloning spark CLI repository..." +if git clone "$SPARK_REPO" "$INSTALL_DIR"; then + echo "" + echo "SparkOS CLI cloned successfully!" + echo "" + echo "Next steps:" + echo " 1. cd $INSTALL_DIR" + echo " 2. Follow the installation instructions in the repository" + echo "" +else + echo "" + echo "Error: Failed to clone repository" + echo "Please check your network connection and try again" + exit 1 +fi diff --git a/scripts/setup_rootfs.sh b/scripts/setup_rootfs.sh index 7146b1f..6cb034a 100755 --- a/scripts/setup_rootfs.sh +++ b/scripts/setup_rootfs.sh @@ -19,10 +19,13 @@ echo "Creating directory structure..." mkdir -p "$ROOTFS_DIR"/{bin,sbin,etc,proc,sys,dev,tmp,usr/{bin,sbin,lib,lib64},var,root,home} mkdir -p "$ROOTFS_DIR/etc"/{init.d,network} mkdir -p "$ROOTFS_DIR/var"/{log,run} +mkdir -p "$ROOTFS_DIR/home/spark" +mkdir -p "$ROOTFS_DIR/etc/sudoers.d" # Set permissions chmod 1777 "$ROOTFS_DIR/tmp" chmod 700 "$ROOTFS_DIR/root" +chmod 755 "$ROOTFS_DIR/home/spark" # Create basic config files echo "Creating configuration files..." @@ -40,11 +43,14 @@ EOF # /etc/passwd cat > "$ROOTFS_DIR/etc/passwd" << 'EOF' root:x:0:0:root:/root:/bin/sh +spark:x:1000:1000:SparkOS User:/home/spark:/bin/sh EOF # /etc/group cat > "$ROOTFS_DIR/etc/group" << 'EOF' root:x:0: +spark:x:1000: +sudo:x:27:spark EOF # /etc/fstab @@ -66,6 +72,27 @@ nameserver 1.1.1.1 nameserver 1.0.0.1 EOF +# /etc/sudoers - Sudo configuration +cat > "$ROOTFS_DIR/etc/sudoers" << 'EOF' +# SparkOS Sudoers Configuration +# Allow spark user to run any command without password + +# Default settings +Defaults env_reset +Defaults secure_path="/bin:/sbin:/usr/bin:/usr/sbin" + +# Root can run anything +root ALL=(ALL:ALL) ALL + +# Spark user can run anything without password +spark ALL=(ALL:ALL) NOPASSWD: ALL + +# Include sudoers.d directory +@includedir /etc/sudoers.d +EOF + +chmod 0440 "$ROOTFS_DIR/etc/sudoers" + # /etc/network/interfaces - Wired network configuration cat > "$ROOTFS_DIR/etc/network/interfaces" << 'EOF' # SparkOS Network Configuration @@ -86,9 +113,15 @@ cat > "$ROOTFS_DIR/etc/profile" << 'EOF' export PATH=/bin:/sbin:/usr/bin:/usr/sbin export PS1='SparkOS:\w\$ ' -export HOME=/root export TERM=linux +# Set HOME based on user +if [ "$(id -u)" = "0" ]; then + export HOME=/root +else + export HOME=/home/$(whoami) +fi + # Welcome message echo "Welcome to SparkOS!" echo "Type 'help' for available commands" @@ -111,6 +144,78 @@ export EDITOR=vi export PAGER=less EOF +# Create .profile for spark user +cat > "$ROOTFS_DIR/home/spark/.profile" << 'EOF' +# SparkOS User Shell Configuration + +# Set prompt +PS1='SparkOS:\w\$ ' + +# Aliases +alias ll='ls -lah' +alias ..='cd ..' + +# Environment +export EDITOR=vi +export PAGER=less +EOF + +# Create clone-sparkos.sh script for spark user +cat > "$ROOTFS_DIR/home/spark/clone-sparkos.sh" << 'EOF' +#!/bin/sh +# SparkOS CLI Installation Script +# This script clones the SparkOS CLI repository + +echo "SparkOS CLI Installation" +echo "========================" +echo "" + +SPARK_REPO="https://github.com/johndoe6345789/spark-cli.git" +INSTALL_DIR="$HOME/spark-cli" + +echo "This script will clone the SparkOS CLI to: $INSTALL_DIR" +echo "" + +# Check if git is available +if ! command -v git >/dev/null 2>&1; then + echo "Error: git is not installed" + echo "Please install git to continue" + exit 1 +fi + +# Check if directory already exists +if [ -d "$INSTALL_DIR" ]; then + echo "Warning: $INSTALL_DIR already exists" + echo -n "Do you want to remove it and re-clone? (y/N): " + read answer + if [ "$answer" = "y" ] || [ "$answer" = "Y" ]; then + rm -rf "$INSTALL_DIR" + else + echo "Installation cancelled" + exit 0 + fi +fi + +# Clone the repository +echo "Cloning spark CLI repository..." +if git clone "$SPARK_REPO" "$INSTALL_DIR"; then + echo "" + echo "SparkOS CLI cloned successfully!" + echo "" + echo "Next steps:" + echo " 1. cd $INSTALL_DIR" + echo " 2. Follow the installation instructions in the repository" + echo "" +else + echo "" + echo "Error: Failed to clone repository" + echo "Please check your network connection and try again" + exit 1 +fi +EOF + +chmod +x "$ROOTFS_DIR/home/spark/clone-sparkos.sh" + # Create a simple help script cat > "$ROOTFS_DIR/bin/sparkos-help" << 'EOF' #!/bin/sh @@ -125,6 +230,14 @@ Default Packages: - Git (for installing spark CLI) - Sudo (privilege elevation) +Default User: + Username: spark + Home: /home/spark + Privileges: Full sudo access (no password required) + + To run commands as root: sudo + To become root: sudo -i + Available commands: ls, cd, pwd - Navigate filesystem cat, less - View files @@ -144,7 +257,7 @@ Network: To test DNS: ping google.com Next Steps: - 1. Install spark CLI: git clone + 1. Install spark CLI: ~/clone-sparkos.sh 2. Use spark CLI to configure WiFi and system 3. Install additional packages as needed @@ -213,7 +326,13 @@ Directory Structure: /usr - User programs /var - Variable data /root - Root home directory - /home - User home directories + /home/spark - Default user home directory + +Default User: + Username: spark (UID 1000) + Home: /home/spark + Sudo: Full access without password + Scripts: ~/clone-sparkos.sh for installing spark CLI Network Configuration: /etc/network/interfaces - Wired network (DHCP) @@ -221,10 +340,11 @@ Network Configuration: /sbin/init-network - Network initialization script Bootstrap Process: - 1. System boots with wired networking (DHCP) - 2. Use git to clone spark CLI repository + 1. System boots as 'spark' user with wired networking (DHCP) + 2. Run ~/clone-sparkos.sh to install spark CLI 3. Use spark CLI to configure WiFi and system 4. Install additional packages via spark CLI + 5. Use 'sudo' for any root-level operations Note: This is a minimal system. You'll need to populate /bin and /usr/bin with actual binaries (busybox, git, sudo) from a proper Linux system @@ -234,6 +354,12 @@ EOF echo "" echo "Root filesystem structure created at: $ROOTFS_DIR" echo "" +echo "User configuration:" +echo " - Default user: spark (UID 1000)" +echo " - Home directory: /home/spark" +echo " - Sudo access: Enabled (no password required)" +echo " - Clone script: /home/spark/clone-sparkos.sh" +echo "" echo "Network configuration:" echo " - Wired networking (DHCP) configured for eth0" echo " - DNS: 8.8.8.8, 1.1.1.1, 8.8.4.4, 1.0.0.1" diff --git a/src/init.c b/src/init.c index 1f4eb55..b979b45 100644 --- a/src/init.c +++ b/src/init.c @@ -28,16 +28,34 @@ static void spawn_shell() { } if (pid == 0) { - // Child process - exec shell + // Child process - exec shell as spark user (uid 1000, gid 1000) + + // Set user and group IDs to spark user + if (setgid(1000) != 0) { + perror("setgid failed"); + exit(1); + } + if (setuid(1000) != 0) { + perror("setuid failed"); + exit(1); + } + char *argv[] = {"/bin/sh", "-l", NULL}; char *envp[] = { - "HOME=/root", + "HOME=/home/spark", "PATH=/bin:/sbin:/usr/bin:/usr/sbin", "TERM=linux", - "PS1=SparkOS# ", + "PS1=SparkOS$ ", + "USER=spark", + "LOGNAME=spark", NULL }; + // Change to home directory + if (chdir("/home/spark") != 0) { + perror("chdir failed"); + } + execve("/bin/sh", argv, envp); perror("failed to exec shell");