summaryrefslogtreecommitdiff
path: root/src/libstddjb/prot.c
blob: 6714cfbf1ef151ae1fa11c217c08ca07c10dffa2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/* ISC license. */

/* MT-unsafe */

#include <unistd.h>
#include <pwd.h>
#include <errno.h>
#include <skalibs/djbunix.h>

int prot_setuidgid (char const *name)
{
  struct passwd *pw = getpwnam(name) ;
  if (!pw)
  {
    if (!errno) errno = ESRCH ;
    return 0 ;
  }
  return !prot_grps(name) && !setgid(pw->pw_gid) && !setuid(pw->pw_uid) ;
}