I have a strange behavior at my raspberry pi.
I wrote a small C-Program to update the RPi. It just calls via system() "apt-get update && apt-get dist-upgrade && apt-get upgrade && rpi-update && reboot"
With the setuid-bit the program will be running as root.
Why a c program ? Because the setuid-bit don't works with bash scripts.
As a super user there is no problem.
If I run the program as an normal user I got this error after "apt-get update" (sorry for the german version):
E: Unable to write to /var/cache/apt/
E: The package lists or status file could not be parsed or opened.
The setuid-bit is set and the owner of the executable is root. So why I have another behavior ?
Here is the code:
main.c:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main () {
int status = 0;
if (status == 0) {
status = system("apt-get -y update"); }
if (status == 0) {
status = system("apt-get -y dist-upgrade");
}
if (status == 0) {
status = system("apt-get -y upgrade");
}
if (status == 0) {
status = system("rpi-update");
}
if (status == 0) {
status = system("reboot");
}
return status;
}
Makefile:
CC=gcc
TARGET=update-system
PREFIX=/usr/bin
all: main.o
${CC} -o ${TARGET} main.c
make clean
main.o: main.c
${CC} -c main.c
.PHONY: clean
clean:
rm ./*.o
install:
chown root ${TARGET}
chgrp root ${TARGET}
chmod +s ${TARGET}
mv ${TARGET} ${PREFIX}