~ubuntu-branches/ubuntu/trusty/postfix/trusty-proposed

« back to all changes in this revision

Viewing changes to src/util/set_eugid.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2005-02-27 09:33:07 UTC
  • Revision ID: james.westby@ubuntu.com-20050227093307-cn789t27ibnlh6tf
Tags: upstream-2.1.5
ImportĀ upstreamĀ versionĀ 2.1.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*++
 
2
/* NAME
 
3
/*      set_eugid 3
 
4
/* SUMMARY
 
5
/*      set effective user and group attributes
 
6
/* SYNOPSIS
 
7
/*      #include <set_eugid.h>
 
8
/*
 
9
/*      void    set_eugid(euid, egid)
 
10
/*      uid_t   euid;
 
11
/*      gid_t   egid;
 
12
/* DESCRIPTION
 
13
/*      set_eugid() sets the effective user and group process attributes
 
14
/*      and updates the process group access list to be just the specified
 
15
/*      effective group id.
 
16
/* DIAGNOSTICS
 
17
/*      All system call errors are fatal.
 
18
/* SEE ALSO
 
19
/*      seteuid(2), setegid(2), setgroups(2)
 
20
/* LICENSE
 
21
/* .ad
 
22
/* .fi
 
23
/*      The Secure Mailer license must be distributed with this software.
 
24
/* AUTHOR(S)
 
25
/*      Wietse Venema
 
26
/*      IBM T.J. Watson Research
 
27
/*      P.O. Box 704
 
28
/*      Yorktown Heights, NY 10598, USA
 
29
/*--*/
 
30
 
 
31
/* System library. */
 
32
 
 
33
#include <sys_defs.h>
 
34
#include <unistd.h>
 
35
#include <grp.h>
 
36
#include <errno.h>
 
37
 
 
38
/* Utility library. */
 
39
 
 
40
#include "msg.h"
 
41
#include "set_eugid.h"
 
42
 
 
43
/* set_eugid - set effective user and group attributes */
 
44
 
 
45
void    set_eugid(uid_t euid, gid_t egid)
 
46
{
 
47
    int     saved_errno = errno;
 
48
 
 
49
    if (geteuid() != 0)
 
50
        if (seteuid(0))
 
51
            msg_fatal("set_eugid: seteuid(0): %m");
 
52
    if (setegid(egid) < 0)
 
53
        msg_fatal("set_eugid: setegid(%ld): %m", (long) egid);
 
54
    if (setgroups(1, &egid) < 0)
 
55
        msg_fatal("set_eugid: setgroups(%ld): %m", (long) egid);
 
56
    if (euid != 0 && seteuid(euid) < 0)
 
57
        msg_fatal("set_eugid: seteuid(%ld): %m", (long) euid);
 
58
    if (msg_verbose)
 
59
        msg_info("set_eugid: euid %ld egid %ld", (long) euid, (long) egid);
 
60
    errno = saved_errno;
 
61
}