How do I configure my system to enable NFC over D-Bus?

Created by Alexander Knaub
dbus D-Bus name configuration conf file error AccessDenied security

The D-Bus object NFCDbusService is available via system wide D-Bus by the well-known D-Bus name "org.nfcpy.NFC".
By default, system bus denies requests of applications to own bus names and to receive method calls.

If you just download and try to start the D-Bus service, you are very likely to get error looking like this:

dbus.exceptions.DBusException: org.freedesktop.DBus.Error.AccessDenied: Connection ":1.xy" is not allowed to own the service "org.nfcpy.NFC" due to security policies in the configuration file

It means that before starting to use NFC via D-Bus, you have to configure your system to allow it. You can reach it with following steps:

1) Create a file with the name like "org.nfcpy.NFC.conf" with following content:

<?xml version="1.0" encoding="UTF-8"?> <!-- -*- XML -*- -->
<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
    <policy context="default">

        <!-- Holes are punched here for name ownership and sending method calls -->
        <allow own="org.nfcpy.NFC"/>
        <allow send_type="method_call"/>

2) Place this file in the folder "/etc/dbus-1/system.d/". Note that you will need root rights for this. You can use the following command:
sudo cp org.nfcpy.NFC.conf /etc/dbus-1/system.d/org.nfcpy.NFC.conf

3) Now you should be able to start the NFC D-Bus service.
If you still aren't, reboot your computer to start D-Bus with new configuration.