~ubuntu-branches/ubuntu/trusty/uucp/trusty

« back to all changes in this revision

Viewing changes to unix/uid.c

  • Committer: Bazaar Package Importer
  • Author(s): Peter Palfrader
  • Date: 2004-12-30 15:30:22 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20041230153022-mx4cdr9j3u9bldo3
Tags: 1.07-12
Add cs localisation for debconf templates (closes: #287305).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* uid.c
2
2
   Switch back and forth between UUCP and user permissions.
3
3
 
4
 
   Copyright (C) 1992, 1995 Ian Lance Taylor
 
4
   Copyright (C) 1992, 1995, 2002 Ian Lance Taylor
5
5
 
6
6
   This file is part of the Taylor UUCP package.
7
7
 
17
17
 
18
18
   You should have received a copy of the GNU General Public License
19
19
   along with this program; if not, write to the Free Software
20
 
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
20
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
21
21
 
22
 
   The author of the program may be contacted at ian@airs.com or
23
 
   c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144.
 
22
   The author of the program may be contacted at ian@airs.com.
24
23
   */
25
24
 
26
25
#include "uucp.h"
40
39
/* Switch to permissions of the invoking user.  */
41
40
 
42
41
boolean
43
 
fsuser_perms (pieuid)
 
42
fsuser_perms (pieuid, piegid)
44
43
     uid_t *pieuid;
 
44
     gid_t *piegid;
45
45
{
46
46
  uid_t ieuid, iuid;
 
47
  gid_t iegid, igid;
47
48
 
48
49
  ieuid = geteuid ();
49
50
  iuid = getuid ();
50
51
  if (pieuid != NULL)
51
52
    *pieuid = ieuid;
52
53
 
 
54
  iegid = getegid ();
 
55
  igid = getgid ();
 
56
  if (piegid != NULL)
 
57
    *piegid = iegid;
 
58
 
53
59
#if HAVE_SETREUID
54
60
  /* Swap the effective user id and the real user id.  We can then
55
61
     swap them back again when we want to return to the uucp user's
56
62
     permissions.  */
 
63
  if (setregid (iegid, igid) < 0)
 
64
    {
 
65
      ulog (LOG_ERROR, "setregid (%ld, %ld): %s",
 
66
            (long) iegid, (long) igid, strerror (errno));
 
67
      return FALSE;
 
68
    }
57
69
  if (setreuid (ieuid, iuid) < 0)
58
70
    {
59
71
      ulog (LOG_ERROR, "setreuid (%ld, %ld): %s",
68
80
     be able to switch back and forth, so don't even try.  */
69
81
  if (iuid != 0)
70
82
    {
 
83
      if (setgid (igid) < 0)
 
84
        {
 
85
          ulog (LOG_ERROR, "setgid (%ld): %s", (long) igid, strerror (errno));
 
86
          return FALSE;
 
87
        }
71
88
      if (setuid (iuid) < 0)
72
89
        {
73
90
          ulog (LOG_ERROR, "setuid (%ld): %s", (long) iuid, strerror (errno));
88
105
 
89
106
/*ARGSUSED*/
90
107
boolean
91
 
fsuucp_perms (ieuid)
92
 
     long ieuid;
 
108
fsuucp_perms (ieuid, iegid)
 
109
     long ieuid ATTRIBUTE_UNUSED;
 
110
     long iegid ATTRIBUTE_UNUSED;
93
111
{
94
112
#if HAVE_SETREUID
95
113
  /* Swap effective and real user id's back to what they were.  */
96
 
  if (! fsuser_perms ((uid_t *) NULL))
 
114
  if (! fsuser_perms ((uid_t *) NULL, (gid_t *) NULL))
97
115
    return FALSE;
98
116
#else /* ! HAVE_SETREUID */
99
117
#if HAVE_SAVED_SETUID
100
118
  /* Set ourselves back to our original effective user id.  */
 
119
  if (setgid ((gid_t) iegid) < 0)
 
120
    {
 
121
      ulog (LOG_ERROR, "setgid (%ld): %s", (long) iegid, strerror (errno));
 
122
      /* Is this error message helpful or confusing?  */
 
123
      if (errno == EPERM)
 
124
        ulog (LOG_ERROR,
 
125
              "Probably HAVE_SAVED_SETUID in policy.h should be set to 0");
 
126
      return FALSE;
 
127
    }
101
128
  if (setuid ((uid_t) ieuid) < 0)
102
129
    {
103
130
      ulog (LOG_ERROR, "setuid (%ld): %s", (long) ieuid, strerror (errno));