1/* uudir.c
2   Create a directory owned by uucp.  This is Unix specific.
3
4   Copyright (C) 1992, 1993 Ian Lance Taylor
5
6   This file is part of the Taylor UUCP package.
7
8   This program is free software; you can redistribute it and/or
9   modify it under the terms of the GNU General Public License as
10   published by the Free Software Foundation; either version 2 of the
11   License, or (at your option) any later version.
12
13   This program is distributed in the hope that it will be useful, but
14   WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16   General Public License for more details.
17
18   You should have received a copy of the GNU General Public License
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.
21
22   The author of the program may be contacted at ian@airs.com.
23   */
24
25#include "uucp.h"
26
27#if USE_RCS_ID
28const char uudir_rcsid[] = "$Id: uudir.c,v 1.8 2002/03/05 19:10:42 ian Rel $";
29#endif
30
31#include "sysdep.h"
32
33#include <pwd.h>
34
35/* External functions.  */
36#if GETPWNAM_DECLARATION_OK
37#ifndef getpwnam
38extern struct passwd *getpwnam ();
39#endif
40#endif
41
42/* This is a simple program which sets its real uid to uucp and then
43   invokes /bin/mkdir.  It is only used if the system does not support
44   the mkdir system call.  It must be installed suid to root.
45
46   This program is needed because the UUCP programs will be run suid
47   to uucp.  On a system without the mkdir system call, /bin/mkdir is
48   a suid root program.  This means that /bin/mkdir always creates
49   directories using the real uid, rather than the effective uid.
50   This is wrong, since the UUCP programs always want to create
51   directories that are owned by uucp.  Therefore, this simple suid
52   root program is used to force /bin/mkdir into making a directory
53   owned by uucp.
54
55   If we made the program publically executable, this would mean that
56   anybody could create a directory owned by uucp.  This is probably
57   not a good thing, but since the program must be owned by root we
58   can't simply make it executable only by uucp.  Therefore, the
59   Makefile hides the program away in /usr/lib/uucp/util, and makes
60   that directory searchable only by uucp.  This should prevent
61   anybody else from getting to the program.
62
63   This is not a perfect solution, since any suid root program is by
64   definition a potential security hole.  I really can't see any way
65   to avoid this, though.  */
66
67int
68main (argc, argv)
69     int argc;
70     char **argv;
71{
72  struct passwd *q;
73  const char *zprog, *zname;
74
75  /* We don't print any error messages, since this program should
76     never be run directly by a user.  */
77
78  if (argc != 2)
79    exit (EXIT_FAILURE);
80
81  /* OWNER is passed in from the Makefile.  It will normally be
82     "uucp".  */
83  q = getpwnam (OWNER);
84  if (q == NULL)
85    exit (EXIT_FAILURE);
86
87  if (setuid (q->pw_uid) < 0)
88    exit (EXIT_FAILURE);
89
90  zprog = MKDIR_PROGRAM;
91  zname = strrchr (zprog, '/');
92  if (zname == NULL)
93    zname = zprog;
94  else
95    ++zname;
96
97  (void) execl (zprog, zname, argv[1], (char *) NULL);
98  exit (EXIT_FAILURE);
99}
100