source: trunk/debathena/config/reactivate/session-wrapper.c @ 25671

Revision 25671, 720 bytes checked in by jdreed, 12 years ago (diff)
In reactivate: * Ship a session wrapper that runs initgroups(3) and stop abusing sudo (Trac: #928) * Stop depending on kexec-tools, which hasn't been needed since 2.0.25 * Wrap Depends line for easier reading
Line 
1#include <sys/types.h>
2#include <unistd.h>
3#include <stdlib.h>
4#include <errno.h>
5#include <stdio.h>
6#include <pwd.h>
7#include <grp.h>
8
9int main (int argc, char **argv) {
10  struct passwd *pw;
11  if (argc < 2) {
12    fprintf(stderr, "Usage: %s command-to-wrap [args]\n", argv[0]);
13    exit(255);
14  }
15  pw = getpwuid(getuid());
16  if (pw == NULL) {
17    perror("getpwuid() failed");
18    exit(1);
19  }
20  if (initgroups(pw->pw_name, pw->pw_gid) == -1) {
21    perror("initgroups() failed");
22    exit(1);
23  }
24  if (setgid(pw->pw_gid)) {
25    perror("setgid() failed");
26    exit(1);
27  }
28  if (setuid(pw->pw_uid)) {
29    perror("setuid() failed");
30    exit(1);
31  }
32  execvp(argv[1], &argv[1]);
33  perror("execvp() failed");
34  exit(1);
35}
Note: See TracBrowser for help on using the repository browser.