diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml new file mode 100644 index 0000000..e7856bb --- /dev/null +++ b/.gitea/workflows/build.yml @@ -0,0 +1,36 @@ +name: Build Docker images + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + docker: + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + version: + - "1" + steps: + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push image + uses: docker/build-push-action@v5 + with: + push: true + tags: eumau/dovecot:${{ matrix.version }} + platforms: linux/amd64,linux/arm64 diff --git a/confd/conf.d/add_ldap_group.toml b/confd/conf.d/add_ldap_group.toml new file mode 100644 index 0000000..8b601d8 --- /dev/null +++ b/confd/conf.d/add_ldap_group.toml @@ -0,0 +1,11 @@ +[template] +src = "add_ldap_group.tmpl" +prefix = "/ldap" +dest = "/usr/local/bin/add_ldap_group" +mode = "0755" +keys = [ +"/admin/cn", +"/admin/password", +"/domain", +"/domain/dn", +] diff --git a/confd/templates/add_ldap_group.tmpl b/confd/templates/add_ldap_group.tmpl new file mode 100644 index 0000000..0162c72 --- /dev/null +++ b/confd/templates/add_ldap_group.tmpl @@ -0,0 +1,100 @@ +#!/bin/bash +assert(){ [[ $? -eq 0 ]] || { [[ -n ${1} ]] && echo ${@} ; exit 1 ; } } +usage() { + cat < " + read USER_UID +} + +# echo "Check if uid=${USER_UID},ou=People,${LDAP_DOMAIN_DN} exists" +RES_DN=$(ldapsearch -LLL -H ldap:/// -D cn=${LDAP_ADMIN_CN},${LDAP_DOMAIN_DN} \ + -w "${LDAP_ADMIN_PASSWORD}" -s base \ + -b "uid=${USER_UID},ou=People,${LDAP_DOMAIN_DN}" \ + "(objectClass=*)" 2>/dev/null \ + | egrep '^dn: ' | sed -e 's/^dn: //g' ) +[[ -z ${RES_DN} ]] +assert "User already present. Please choose a different UID." + +[[ -n ${COMMON_NAME} ]] || { + echo -n "Enter user CN (e.g. John Doe) > " + read COMMON_NAME +} +[[ -n ${SURNAME} ]] || { + echo -n "Enter user SN (e.g. Doe) > " + read SURNAME +} +[[ -n ${USER_PASS} ]] || { + echo -n "Enter user password (will not be echoed) > " + read -s USER_PASS + echo "" +} +[[ -n ${USER_EMAIL} ]] || { + echo -n "Enter user email (leave blank for ${USER_UID}@${LDAP_DOMAIN}) > " + read USER_EMAIL +} +USER_EMAIL="${USER_EMAIL:=${USER_UID}@${LDAP_DOMAIN}}" + + +PWHASH=$(slappasswd -h "{SSHA}" -s "${USER_PASS}") + +echo "Creating user uid=${USER_UID},ou=People,${LDAP_DOMAIN_DN}" +ldapadd -H ldap:/// -D cn=${LDAP_ADMIN_CN},${LDAP_DOMAIN_DN} \ + -w "${LDAP_ADMIN_PASSWORD}" <<-EOF + dn: uid=${USER_UID},ou=People,${LDAP_DOMAIN_DN} + objectClass: inetOrgPerson + objectClass: organizationalPerson + objectClass: person + objectClass: top + cn: ${COMMON_NAME} + sn: ${SURNAME} + uid: ${USER_UID} + userPassword: ${PWHASH} + mail: ${USER_EMAIL} + + EOF + +assert "Error adding user!" diff --git a/confd/templates/add_ldap_user.tmpl b/confd/templates/add_ldap_user.tmpl index f1eecc7..ddfbeaa 100644 --- a/confd/templates/add_ldap_user.tmpl +++ b/confd/templates/add_ldap_user.tmpl @@ -70,6 +70,7 @@ assert "User already present. Please choose a different UID." [[ -n ${USER_PASS} ]] || { echo -n "Enter user password (will not be echoed) > " read -s USER_PASS + echo "" } [[ -n ${USER_EMAIL} ]] || { echo -n "Enter user email (leave blank for ${USER_UID}@${LDAP_DOMAIN}) > "