1

I hava e program called outlet in which I communicate out on wiring pin 2 corresponding to BCM-PIN 27 on my Pi:

#include "NewRemoteTransmitter.h"
#include <stdlib.h>
#include <stdio.h>

NewRemoteTransmitter transmitter(0, 27, 263, 4);

int main(int argc, char *argv[])
{
    int unitCode = atoi(argv[1]);
    int command  = atoi(argv[2]);
    if(unitCode > 15 || unitCode < 0 || command > 1 || command < 0) return 1;

    if (wiringPiSetupSys() == -1) return 1;

    transmitter.sendUnit(unitCode, command);
    return 0;
}

In order to run the small program without being root, I have run gpio export 27 out and use wiringPiSetupSys() in my program. Running the script as user pi@raspberrypi works fine.

But I can't execute the script using a program running as other@raspberrypi.

I have unsuccessfully tried to export the pin as other@raspberrypi using the following commands:

pi@raspberrypi ~/ $ sudo -H -u other gpio exports
pi@raspberrypi ~/ $ sudo -H -u other gpio export 27 out
pi@raspberrypi ~/ $ sudo -H -u other gpio exports
GPIO Pins exported:
    27: out  0  none
pi@raspberrypi ~ $ ls -l /sys/class/gpio/gpio27/value
-rw-r--r-- 1 other other 4096 feb  1 07:00 /sys/class/gpio/gpio27/value

After doing so, I can't execute the script nor as user pi or as other.

Any idea of how to make the script executable by user ´other´?

  • Are you running a script or a compiled program? More detail will help. – Milliways Jan 31 '16 at 22:50
  • A small program is probably the correct definition. Se edit of original post. – sehlstrom Feb 1 '16 at 6:12
  • I noticed the edit to your post which included the code. There is no point in checking the return code for any of the wiringPiSetup functions - it is always 0. – Milliways Feb 1 '16 at 6:34
  • @Milliways, thanks for pointing that out. I'll remove that if-statement. – sehlstrom Feb 2 '16 at 19:23
0

You could set SUID permission. This allows any user to have permission to owner privileges. There is also a guid option. (This won't work for scripts.)

The gpio program has this set.

sudo chmod u+s yourprogram

| improve this answer | |
  • Thanks! Don't know what it means but it works :D – sehlstrom Feb 2 '16 at 19:22
  • Well, after som thoughts put into this it's a bad solution. The change make the program root which is a possible security issue. – sehlstrom Feb 2 '16 at 20:14
  • @sehlstrom There is no security risk. The reason this capability is there is to allow users to run ONLY THIS PROGRAM with elevated privileges. There are already many programs on your Pi which do this e.g. gpio and passwd. Without suid users would be unable to change their own passwords! You write the program so you know what it does! NOTE You cannot set the suid on script files, because that may be a security risk as they can be easily changed. – Milliways Feb 2 '16 at 22:31
  • I have written the program. However, I have not written the wiringpi et al library that I reference. So potentially the libraries can be updated with bad and mean code using it to do bad things with my Pi. – sehlstrom Feb 8 '16 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.