diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ec089e8 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,41 @@ +.DS_Store +.idea +*~ +ABOUT-NLS +ChangeLog +autom4te.cache +autoscan.log +autoscan-*.log +aclocal.m4 +compile +src/config.h.in +depcomp +install-sh +missing +src/stamp-h1 +**/*.o +.deps +m4/*.m4 +Makefile +Makefile.in +config.guess +config.rpath +config.sub +config.log +config.status +configure +configure.scan +po/Makevars.template +po/POTFILES +po/*.gmo +po/*.mo +po/*.pot +po/remove-potcdate.sed +src/macping +src/mactelnet +src/mactelnetd +src/mndp +src/.deps/ +src/config.h +doc/mactelnetd.1 +Dockerfile \ No newline at end of file diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index c6d4e54..b737767 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -17,22 +17,12 @@ jobs: attestations: write id-token: write name: Configure and Build - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - - matrix: - os: [ubuntu-latest, macos-14] + runs-on: ubuntu-latest steps: - - name: Prepare variables - id: vars - run: | - os=${{ matrix.os }} - platform="$(test \"$os\" = \"ubuntu-latest\" && echo linux/amd64 || echo linux/arm64)" - echo "platform=${platform}" >> $GITHUB_OUTPUT - echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV - uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 - name: Docker meta id: meta uses: docker/metadata-action@v5 @@ -47,65 +37,10 @@ jobs: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push by digest - id: build - uses: docker/build-push-action@v6 + - name: Build and push + uses: docker/build-push-action@v5 with: - platforms: ${{ steps.vars.outputs.platform }} - labels: ${{ steps.meta.outputs.labels }}, - outputs: type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true - - name: Export digest - run: | - mkdir -p /tmp/digests - digest="${{ steps.build.outputs.digest }}" - touch "/tmp/digests/${digest#sha256:}" - - name: Upload digest - uses: actions/upload-artifact@v4 - with: - name: digests-${{ env.PLATFORM_PAIR }} - path: /tmp/digests/* - if-no-files-found: error - retention-days: 1 - - merge: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - attestations: write - id-token: write - needs: - - build - steps: - - name: Download digests - uses: actions/download-artifact@v4 - with: - path: /tmp/digests - pattern: digests-* - merge-multiple: true - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Docker meta - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ env.IMAGE_NAME }} - - - name: Log in to the Container registry - uses: docker/login-action@v3 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Create manifest list and push - working-directory: /tmp/digests - run: | - docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ - $(printf '${{ env.IMAGE_NAME }}@sha256:%s ' *) - - - name: Inspect image - run: | - docker buildx imagetools inspect ${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }} \ No newline at end of file + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.version }},latest \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index f8f76ef..65c4f60 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,10 @@ -FROM alpine:3.19 AS builder +FROM debian:bookworm AS builder # Install build dependencies -RUN apk add --no-cache diffutils build-base automake autoconf git gettext gettext-dev linux-headers openssl-dev +RUN apt-get update && apt-get -y install \ + gettext autoconf automake libtool autopoint \ + libssl-dev git libbsd-dev build-essential && \ + apt-get clean && rm -rf /tmp/* /var/tmp/* # Copy everything to /src RUN mkdir /src @@ -9,17 +12,19 @@ WORKDIR /src ADD . /src/ # Build -ENV CFLAGS="-D_GNU_SOURCE" -RUN ./autogen.sh --prefix=/build +RUN ./autogen.sh --prefix=/build --sysconfdir=/config RUN make all install ## -FROM alpine:3.19 +FROM debian:bookworm-slim # Install runtime dependencies -RUN apk add --no-cache gettext-libs openssl-dev +RUN apt-get update && apt-get -y install gettext \ + libbsd0 openssl man-db && apt-get clean && \ + rm -rf /tmp/* /var/tmp/* # Copy build artifacts COPY --from=builder /build/ /usr/ +COPY --from=builder /config /config CMD ["/usr/bin/mactelnet"] diff --git a/config/mactelnetd.users b/config/mactelnetd.users index 4c1594b..73f01b6 100644 --- a/config/mactelnetd.users +++ b/config/mactelnetd.users @@ -9,4 +9,4 @@ # If you need to add a new user, use the -a option in mactelnetd. # # Format: -#username:hash:salt or username:password \ No newline at end of file +#username:hash:salt or username:password diff --git a/src/Makefile.am b/src/Makefile.am index c51cb10..25007a0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -16,10 +16,6 @@ mactelnetd_SOURCES = config.h mactelnetd.c protocol.c protocol.h interfaces.c in mactelnetd_CFLAGS = -DFROM_MACTELNETD -DUSERSFILE='"$(sysconfdir)/mactelnetd.users"' mactelnetd_LDADD = $(CRYPTO_LIBS) $(COREFOUNDATION_LIBS) $(SYSTEMCONFIGURATION_LIBS) -savepass_SOURCES = config.h savepass.c mtwei.c mtwei.h users.c users.h extra.h utlist.h -savepass_CFLAGS = -DUSERSFILE='"$(sysconfdir)/mactelnetd.users"' -savepass_LDADD = $(CRYPTO_LIBS) - mndp_SOURCES = config.h mndp.c mndp.h protocol.c protocol.h extra.h macping_SOURCES = config.h macping.c interfaces.c interfaces.h protocol.c protocol.h extra.h utlist.h diff --git a/src/mactelnetd.c b/src/mactelnetd.c index d335da8..2b5c8e6 100644 --- a/src/mactelnetd.c +++ b/src/mactelnetd.c @@ -1188,9 +1188,9 @@ int main(int argc, char **argv) { textdomain(PACKAGE); #if !defined(__APPLE__) - while ((c = getopt(argc, argv, "fnovh?")) != -1) { + while ((c = getopt(argc, argv, "fnovh?lau:p:d:")) != -1) { #else - while ((c = getopt(argc, argv, "novhlau:p:d:")) != -1) { + while ((c = getopt(argc, argv, "novh?lau:p:d:")) != -1) { #endif switch (c) { case 'f': @@ -1239,7 +1239,7 @@ int main(int argc, char **argv) { if (print_help) { print_version(); - fprintf(stderr, _("Usage: %s [-fnoh]|-a [-u |-p ]|[-d ]\n"), argv[0]); + fprintf(stderr, _("Usage: %s [-fnovh]|-l|-a [-u |-p ]|[-d ]\n"), argv[0]); if (print_help) { #if !defined(__APPLE__) diff --git a/src/mndp.c b/src/mndp.c index 26ee744..71b466b 100644 --- a/src/mndp.c +++ b/src/mndp.c @@ -41,6 +41,10 @@ char *ether_ntoa_z(const struct ether_addr *addr); +static void sig_term(int signo) { + exit(0); +} + /* This file is also used for the -l option in mactelnet */ #ifndef FROM_MACTELNET @@ -66,6 +70,9 @@ int mndp(int timeout, int batch_mode) { mt_direction_fromserver = 0; signal(SIGALRM, sig_alarm); #endif + // Add support for ctrl+c inside docker containers + signal(SIGTERM, sig_term); + signal(SIGINT, sig_term); setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR);