2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1998 University of Maryland at College Park
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.
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.
23 * Authors: the Amanda Development Team. Its members are listed in a
24 * file named AUTHORS, in the root directory of this distribution.
27 * $Id: runtar.c,v 1.24 2006/08/25 11:41:31 martinea Exp $
29 * runs GNUTAR program as root
31 * argv[0] is the runtar program name
32 * argv[1] is the config name or NOCONFIG
33 * argv[2] will be argv[0] of the gtar program
40 int main(int argc, char **argv);
58 /* Don't die when child closes pipe */
59 signal(SIGPIPE, SIG_IGN);
61 dbopen(DBG_SUBDIR_CLIENT);
63 error("%s: Need at least 3 arguments\n", debug_prefix_time(NULL));
67 dbprintf(("%s: version %s\n", debug_prefix_time(NULL), version()));
69 if (strcmp(argv[3], "--create") != 0) {
70 error("%s: Can only be used to create tar archives\n",
71 debug_prefix_time(NULL));
77 fprintf(stderr,"gnutar not available on this system.\n");
78 dbprintf(("%s: gnutar not available on this system.\n", argv[0]));
85 * Print out version information for tar.
91 if ((version_file = popen(GNUTAR " --version 2>&1", "r")) != NULL) {
92 if (fgets(version_buf, (int)sizeof(version_buf), version_file) != NULL) {
93 dbprintf((GNUTAR " version: %s\n", version_buf));
95 if (ferror(version_file)) {
96 dbprintf((GNUTAR " version: Read failure: %s\n", strerror(errno)));
98 dbprintf((GNUTAR " version: Read failure; EOF\n"));
102 dbprintf((GNUTAR " version: unavailable: %s\n", strerror(errno)));
106 if(client_uid == (uid_t) -1) {
107 error("error [cannot find user %s in passwd file]\n", CLIENT_LOGIN);
112 if (getuid() != client_uid) {
113 error("error [must be invoked by %s]\n", CLIENT_LOGIN);
117 if (geteuid() != 0) {
118 error("error [must be setuid root]\n");
123 #if !defined (DONT_SUID_ROOT)
131 dbprintf(("config: %s\n", argv[0]));
132 if (strcmp(argv[0], "NOCONFIG") != 0)
133 dbrename(argv[0], DBG_SUBDIR_CLIENT);
138 dbprintf(("running: %s: ",GNUTAR));
139 for (i=0; argv[i]; i++) {
142 quoted = quote_string(argv[i]);
143 dbprintf(("'%s' ", quoted));
153 execve(GNUTAR, argv, safe_env());
156 dbreopen(dbf, "more");
158 dbprintf(("execve of %s failed (%s)\n", GNUTAR, e));
161 fprintf(stderr, "runtar: could not exec %s: %s\n", GNUTAR, e);