FROM ubuntu:latest

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y \
    build-essential \
    git \
    gdb \
    vim \
    libpam0g-dev \
    libssl-dev \
    pkg-config \
    autoconf \
    automake \
    libtool \
    bison \
    flex \
    gettext \
    && rm -rf /var/lib/apt/lists/*

RUN git clone https://github.com/sudo-project/sudo.git /opt/sudo

WORKDIR /opt/sudo
RUN git checkout SUDO_1_9_5

RUN CFLAGS="-g -O0" ./configure --prefix=/usr/local \
    && make \
    && make install

RUN ln -sf /usr/local/bin/sudo /usr/local/bin/sudoedit

RUN chmod 4755 /usr/local/bin/sudo

RUN useradd -m -s /bin/bash testuser \
    && echo "testuser:password123" | chpasswd

RUN mkdir -p /etc/custom \
    && printf "[service]\nname=example\nport=8080\nenabled=true\n" > /etc/custom/service.conf

RUN printf "root ALL=(ALL:ALL) ALL\ntestuser ALL=(ALL:ALL) sudoedit /etc/custom/service.conf\n" \
    > /etc/sudoers \
    && chown root:root /etc/sudoers \
    && chmod 0440 /etc/sudoers

ENTRYPOINT ["sleep", "infinity"]
