You are not logged in.

#1 2016-07-20 15:32:37

FillFeile
Member
Registered: 2013-08-07
Posts: 21

[SOLVED] Run bluez hciconfig/hcitool as unprivileged user

Hi there,

I'm currently writing a little Python software that let's you emulate an BLE Beacon on a bluetooth capable linux device.

Due to a lack of good BLE Python librarys I use hcitool and hciconfig to control the bluetooth device.

Both binarys hcitool and hciconfig only do their job while running as root user. Otherwise this error pops up:

hciconfig hci0 up
Can't init device hci0: Operation not permitted (1)

Currently I use a workaround to run the Python software as unprivileged user: I set the setuid bit on the hcitool & hciconfig executable.

Is there a way to privilege a normal user to use hcitool and hciconfig without this workaround?

Thanks in advance!

Cheers,

FillFeile

Last edited by FillFeile (2016-07-20 16:27:50)

Offline

#2 2016-07-20 16:01:06

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,774

Re: [SOLVED] Run bluez hciconfig/hcitool as unprivileged user

Sudo?


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#3 2016-07-20 16:07:07

FillFeile
Member
Registered: 2013-08-07
Posts: 21

Re: [SOLVED] Run bluez hciconfig/hcitool as unprivileged user

.. yeah. Of course.

But I don't want the users to start the whole program with "sudo". GUI etc. don't need to run as root.

Offline

#4 2016-07-20 16:18:04

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,774

Re: [SOLVED] Run bluez hciconfig/hcitool as unprivileged user

I was actually thinking of putting hcitool and hciconfig into sudoers with permissions set to allow users (or perhaps members of a group) to run them without passwords.  Then, your Python program would spawn them through sudo rather than invoking them directly.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#5 2016-07-20 16:27:30

FillFeile
Member
Registered: 2013-08-07
Posts: 21

Re: [SOLVED] Run bluez hciconfig/hcitool as unprivileged user

After searching on BLE scan rather that send I found this one on StackExchange: http://unix.stackexchange.com/questions … s-non-root

sudo setcap 'cap_net_raw,cap_net_admin+eip' `which hcitool`
sudo setcap 'cap_net_raw,cap_net_admin+eip' `which hciconfig`

These two make it possible to invoke the executables without the need for sudo/root.

Offline

Board footer

Powered by FluxBB