diff --git a/debian/authd-example-broker.examples b/debian/authd-example-broker.examples new file mode 100644 index 0000000000..ed62a0e05d --- /dev/null +++ b/debian/authd-example-broker.examples @@ -0,0 +1,3 @@ +examplebroker/ExampleBroker.conf +debian/authd-example-broker.service +debian/authd-example-broker.installer.sh diff --git a/debian/authd-example-broker.install b/debian/authd-example-broker.install new file mode 100755 index 0000000000..0f36ccc399 --- /dev/null +++ b/debian/authd-example-broker.install @@ -0,0 +1,6 @@ +#!/usr/bin/dh-exec + +usr/bin/examplebroker-bin => ${env:AUTHD_DAEMONS_PATH}/authd-examplebroker + +examplebroker/com.ubuntu.authd.ExampleBroker.conf /usr/share/dbus-1/system.d +examplebroker/com.ubuntu.authd.ExampleBroker.service /usr/share/dbus-1/system-services diff --git a/debian/authd-example-broker.installer.sh b/debian/authd-example-broker.installer.sh new file mode 100755 index 0000000000..37e99956f9 --- /dev/null +++ b/debian/authd-example-broker.installer.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +set -eu + +usage() { + echo "$0 [install | uninstall | help]" +} + +if [ -z "$0" ]; then + usage + exit 1 +fi + +if [ "$(id -u)" != 0 ]; then + echo "Need to run as root" + exit +fi + +SYSTEMD_SERVICE=authd-example-broker.service +CONFIG_FILE=ExampleBroker.conf + +if [ "$1" = "install" ]; then + install -m644 \ + /usr/share/doc/authd-example-broker/examples/"${CONFIG_FILE}" \ + -Dt /etc/authd/brokers.d + + install -m644 \ + /usr/share/doc/authd-example-broker/examples/"${SYSTEMD_SERVICE}" \ + -Dt /usr/lib/systemd/system + + systemctl daemon-reload +elif [ "$1" = "uninstall" ]; then + rm -fv /etc/authd/brokers.d/"${CONFIG_FILE}" + rmdir -v /etc/authd/brokers.d 2>/dev/null || true + rm -fv /usr/lib/systemd/system/"${SYSTEMD_SERVICE}" + + systemctl daemon-reload +elif [ "$1" = "help" ]; then + usage + exit 0 +else + echo "unknown command '$1'" + usage + exit 1 +fi diff --git a/debian/authd-example-broker.service.in b/debian/authd-example-broker.service.in new file mode 100644 index 0000000000..d1c2af4bec --- /dev/null +++ b/debian/authd-example-broker.service.in @@ -0,0 +1,20 @@ +[Unit] +Description=Authd Example Broker +After=authd.service +Requires=authd.service + +[Service] +Type=dbus +BusName=com.ubuntu.authd.ExampleBroker +ExecStart=@AUTHD_DAEMONS_PATH@/authd-examplebroker +Restart=on-failure + +# Some daemon restrictions +ProtectSystem=strict +ProtectControlGroups=true +ProtectHome=true +ProtectKernelModules=true +PrivateTmp=true +RestrictAddressFamilies=AF_UNIX AF_LOCAL AF_NETLINK +MemoryDenyWriteExecute=true +RestrictRealtime=true diff --git a/debian/apport b/debian/authd.apport similarity index 100% rename from debian/apport rename to debian/authd.apport diff --git a/debian/docs b/debian/authd.docs similarity index 100% rename from debian/docs rename to debian/authd.docs diff --git a/debian/install b/debian/authd.install similarity index 75% rename from debian/install rename to debian/authd.install index 180aa90b86..cb97181145 100755 --- a/debian/install +++ b/debian/authd.install @@ -11,4 +11,4 @@ ${env:BUILT_PAM_LIBS_PATH}/pam_authd.so ${env:AUTHD_PAM_MODULES_PATH} ${env:BUILT_PAM_LIBS_PATH}/go-loader/pam_go_loader.so ${env:AUTHD_PAM_MODULES_PATH} # Install NSS library with right soname -target/${DEB_HOST_RUST_TYPE}/release/libnss_authd.so => /usr/lib/${DEB_TARGET_GNU_TYPE}/libnss_authd.so.2 +target/${env:DEB_HOST_RUST_TYPE}/release/libnss_authd.so => /usr/lib/${env:DEB_TARGET_GNU_TYPE}/libnss_authd.so.2 diff --git a/debian/lintian-overrides b/debian/authd.lintian-overrides similarity index 100% rename from debian/lintian-overrides rename to debian/authd.lintian-overrides diff --git a/debian/postinst b/debian/authd.postinst similarity index 100% rename from debian/postinst rename to debian/authd.postinst diff --git a/debian/postrm b/debian/authd.postrm similarity index 100% rename from debian/postrm rename to debian/authd.postrm diff --git a/debian/prerm b/debian/authd.prerm similarity index 100% rename from debian/prerm rename to debian/authd.prerm diff --git a/debian/control b/debian/control index 4c18714cf6..fd0e005e37 100644 --- a/debian/control +++ b/debian/control @@ -6,7 +6,7 @@ Build-Depends: debhelper-compat (= 13), dbus , dh-apport, dh-cargo, - dh-exec, + dh-exec (>= 0.29), dh-golang, dctrl-tools, golang-go (>= 2:1.22~), @@ -41,3 +41,14 @@ Description: ${source:Synopsis} . This package contains the authentication daemon together with the PAM & NSS modules. + +Package: authd-example-broker +Recommends: authd +Architecture: any +Built-Using: ${misc:Built-Using}, +Depends: ${shlibs:Depends}, + ${misc:Depends}, +Description: ${source:Synopsis} - Example broker + ${source:Extended-Description} + . + This package contains an example broker for testing and autopkgtests purposes. diff --git a/debian/rules b/debian/rules index 3002aea430..aa137fdae6 100755 --- a/debian/rules +++ b/debian/rules @@ -49,10 +49,10 @@ export AUTHD_SKIP_ROOT_TESTS := 1 export DH_GOLANG_BUILDPKG := $(AUTHD_GO_PACKAGE)/... \ $(NULL) -BUILDDIR := $(CURDIR)/obj-$(DEB_HOST_GNU_TYPE) - export BUILT_PAM_LIBS_PATH := obj-$(DEB_HOST_GNU_TYPE)/src/$(AUTHD_GO_PACKAGE)/pam +EXAMPLE_BROKER_BUILD_TAG := with_standalone_examplebroker + %: # --without=single-binary can be removed with dh 15. dh $@ --buildsystem=golang --with=golang,apport --without=single-binary @@ -93,6 +93,11 @@ override_dh_auto_build: # Build the daemon dh_auto_build -- $(AUTHD_GO_PACKAGE)/cmd/authd + # Build the example broker because otherwise it's not + # part of the normal install. + dh_auto_build -- -tags $(EXAMPLE_BROKER_BUILD_TAG) \ + $(AUTHD_GO_PACKAGE)/examplebroker/examplebroker-bin + override_dh_auto_install: dh_auto_install --destdir=debian/tmp -- --no-source @@ -101,3 +106,7 @@ override_dh_auto_install: # Install gdm-PAM config file dh_installpam -pauthd --name=gdm-authd + +override_dh_installsystemd: + # Install example-broker service file only by default + dh_installsystemd -pauthd diff --git a/examplebroker/ExampleBroker b/examplebroker/ExampleBroker.conf similarity index 72% rename from examplebroker/ExampleBroker rename to examplebroker/ExampleBroker.conf index 7db07d6506..4c494d004e 100644 --- a/examplebroker/ExampleBroker +++ b/examplebroker/ExampleBroker.conf @@ -1,4 +1,4 @@ -# Add this to /etc/authd/broker.d to configure the ExampleBroker +# Add this to /etc/authd/brokers.d to configure the ExampleBroker [authd] name = ExampleBroker brand_icon = /usr/share/backgrounds/warty-final-ubuntu.png diff --git a/examplebroker/com.ubuntu.auth.ExampleBroker.conf b/examplebroker/com.ubuntu.authd.ExampleBroker.conf similarity index 100% rename from examplebroker/com.ubuntu.auth.ExampleBroker.conf rename to examplebroker/com.ubuntu.authd.ExampleBroker.conf diff --git a/examplebroker/com.ubuntu.authd.ExampleBroker.service b/examplebroker/com.ubuntu.authd.ExampleBroker.service new file mode 100644 index 0000000000..8684d4736d --- /dev/null +++ b/examplebroker/com.ubuntu.authd.ExampleBroker.service @@ -0,0 +1,5 @@ +[D-BUS Service] +Name=com.ubuntu.authd.ExampleBroker +Exec=/bin/false +User=root +SystemdService=authd-example-broker.service diff --git a/examplebroker/com.ubuntu.auth.ExampleBroker.xml b/examplebroker/com.ubuntu.authd.ExampleBroker.xml similarity index 100% rename from examplebroker/com.ubuntu.auth.ExampleBroker.xml rename to examplebroker/com.ubuntu.authd.ExampleBroker.xml diff --git a/examplebroker/examplebroker-bin/main.go b/examplebroker/examplebroker-bin/main.go new file mode 100644 index 0000000000..52f2aa1b7f --- /dev/null +++ b/examplebroker/examplebroker-bin/main.go @@ -0,0 +1,28 @@ +//go:build with_standalone_examplebroker + +package main + +import ( + "context" + "log" + "os" + + "github.com/ubuntu/authd/examplebroker" +) + +func main() { + // Create the directory for the broker configuration files. + cfgPath, err := os.MkdirTemp(os.TempDir(), "standalonebroker.d") + if err != nil { + log.Fatal(err) + } + defer os.RemoveAll(cfgPath) + + conn, err := examplebroker.StartBus(cfgPath) + if err != nil { + log.Fatal("Error starting standalone broker:", err) + } + defer conn.Close() + + <-context.Background().Done() +}