summarylogtreecommitdiffstats
path: root/shutdown-wrapper.c
blob: 6708fa2f418c896c2738f106787a54bb93382f77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//
// Simple shutdown-wrapper with focus on security
//
// Version:	1.0	Thu Jul  9 16:28:42 CEST 2009
//
// Author:	Manuel Reimer <manuel.reimer@gmx.de>
//

#define REAL_PATH "/usr/lib/vdr/bin/shutdown.sh"

#include <unistd.h>

int main(int argc, char *argv[]){
  // We pass a secure environment to the called script.
  char *const envParms[4] = {
    "PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin",
    "HOME=/root",
    "TERM=linux",
    NULL
  };
  // Drop whatever working directory the caller set for us and go HOME
  chdir("/root");
  // Get root and execute shutdown.sh
  setuid(0);
  execve(REAL_PATH, argv, envParms);
  return 0;
}