Imported Upstream version 2.5.1
[debian/amanda] / client-src / rundump.c
1 /*
2  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3  * Copyright (c) 1991-1998 University of Maryland at College Park
4  * All Rights Reserved.
5  *
6  * Permission to use, copy, modify, distribute, and sell this software and its
7  * documentation for any purpose is hereby granted without fee, provided that
8  * the above copyright notice appear in all copies and that both that
9  * copyright notice and this permission notice appear in supporting
10  * documentation, and that the name of U.M. not be used in advertising or
11  * publicity pertaining to distribution of the software without specific,
12  * written prior permission.  U.M. makes no representations about the
13  * suitability of this software for any purpose.  It is provided "as is"
14  * without express or implied warranty.
15  *
16  * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22  *
23  * Authors: the Amanda Development Team.  Its members are listed in a
24  * file named AUTHORS, in the root directory of this distribution.
25  */
26 /*
27  * $Id: rundump.c,v 1.33 2006/07/25 18:27:56 martinea Exp $
28  *
29  * runs DUMP program as root
30  *
31  * argv[0] is the rundump program name
32  * argv[1] is the config name or NOCONFIG
33  * argv[2] will be argv[0] of the DUMP program
34  * ...
35  */
36 #include "amanda.h"
37 #include "version.h"
38
39 int main(int argc, char **argv);
40
41 #if defined(VDUMP) || defined(XFSDUMP)
42 #  undef USE_RUNDUMP
43 #  define USE_RUNDUMP
44 #endif
45
46 #if !defined(USE_RUNDUMP)
47 #  define ERRMSG "rundump not enabled on this system.\n"
48 #else
49 #  if !defined(DUMP) && !defined(VXDUMP) && !defined(VDUMP) && !defined(XFSDUMP)
50 #    define ERRMSG "DUMP not available on this system.\n"
51 #  else
52 #    undef ERRMSG
53 #  endif
54 #endif
55
56 int
57 main(
58     int         argc,
59     char **     argv)
60 {
61 #ifndef ERRMSG
62     char *dump_program;
63     int i;
64     char *e;
65 #endif /* ERRMSG */
66
67     safe_fd(-1, 0);
68     safe_cd();
69
70     set_pname("rundump");
71
72     /* Don't die when child closes pipe */
73     signal(SIGPIPE, SIG_IGN);
74
75     dbopen(DBG_SUBDIR_CLIENT);
76     if (argc < 3) {
77         error("%s: Need at least 3 arguments\n", debug_prefix(NULL));
78         /*NOTREACHED*/
79     }
80
81     dbprintf(("%s: version %s\n", debug_prefix(NULL), version()));
82
83 #ifdef ERRMSG                                                   /* { */
84
85     fprintf(stderr, ERRMSG);
86     dbprintf(("%s: %s", argv[0], ERRMSG));
87     dbclose();
88     return 1;
89
90 #else                                                           /* } { */
91
92     if(client_uid == (uid_t) -1) {
93         error("error [cannot find user %s in passwd file]\n", CLIENT_LOGIN);
94         /*NOTREACHED*/
95     }
96
97 #ifdef FORCE_USERID
98     if (getuid() != client_uid) {
99         error("error [must be invoked by %s]\n", CLIENT_LOGIN);
100         /*NOTREACHED*/
101     }
102
103     if (geteuid() != 0) {
104         error("error [must be setuid root]\n");
105         /*NOTREACHED*/
106     }
107 #endif  /* FORCE_USERID */
108
109 #if !defined (DONT_SUID_ROOT)
110     setuid(0);
111 #endif
112
113     /* skip argv[0] */
114     argc--;
115     argv++;
116
117     dbprintf(("config: %s\n", argv[0]));
118     if (strcmp(argv[0], "NOCONFIG") != 0)
119         dbrename(argv[0], DBG_SUBDIR_CLIENT);
120     argc--;
121     argv++;
122
123 #ifdef XFSDUMP
124
125     if (strcmp(argv[0], "xfsdump") == 0)
126         dump_program = XFSDUMP;
127     else /* strcmp(argv[0], "xfsdump") != 0 */
128
129 #endif
130
131 #ifdef VXDUMP
132
133     if (strcmp(argv[0], "vxdump") == 0)
134         dump_program = VXDUMP;
135     else /* strcmp(argv[0], "vxdump") != 0 */
136
137 #endif
138
139 #ifdef VDUMP
140
141     if (strcmp(argv[0], "vdump") == 0)
142         dump_program = VDUMP;
143     else /* strcmp(argv[0], "vdump") != 0 */
144
145 #endif
146
147 #if defined(DUMP)
148         dump_program = DUMP;
149 #else
150 # if defined(XFSDUMP)
151         dump_program = XFSDUMP;
152 # else
153 #  if defined(VXDUMP)
154         dump_program = VXDUMP;
155 #  else
156         dump_program = "dump";
157 #  endif
158 # endif
159 #endif
160
161     dbprintf(("running: %s: ",dump_program));
162     for (i=0; argv[i]; i++)
163         dbprintf(("%s ", argv[i]));
164     dbprintf(("\n"));
165
166     execve(dump_program, argv, safe_env());
167
168     e = strerror(errno);
169     dbprintf(("failed (%s)\n", e));
170     dbclose();
171
172     fprintf(stderr, "rundump: could not exec %s: %s\n", dump_program, e);
173     return 1;
174 #endif                                                          /* } */
175 }