forked from bruceg/daemontools-encore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
envuidgid.c
35 lines (28 loc) · 771 Bytes
/
envuidgid.c
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
28
29
30
31
32
33
34
35
#include <sys/types.h>
#include <pwd.h>
#include "fmt.h"
#include "strerr.h"
#include "pathexec.h"
#define FATAL "envuidgid: fatal: "
void nomem(void)
{
strerr_die2x(111,FATAL,"out of memory");
}
char strnum[FMT_ULONG];
const char *account;
struct passwd *pw;
int main(int argc,const char *const *argv)
{
account = *++argv;
if (!account || !*++argv)
strerr_die1x(100,"envuidgid: usage: envuidgid account child");
pw = getpwnam(account);
if (!pw)
strerr_die3x(111,FATAL,"unknown account ",account);
strnum[fmt_ulong(strnum,pw->pw_gid)] = 0;
if (!pathexec_env("GID",strnum)) nomem();
strnum[fmt_ulong(strnum,pw->pw_uid)] = 0;
if (!pathexec_env("UID",strnum)) nomem();
pathexec(argv);
strerr_die3sys(111,FATAL,"unable to run ",*argv);
}