/*
* Amanda, The Advanced Maryland Automatic Network Disk Archiver
* Copyright (c) 1991-1998 University of Maryland at College Park
+ * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved.
* All Rights Reserved.
*
* Permission to use, copy, modify, distribute, and sell this software and its
* file named AUTHORS, in the root directory of this distribution.
*/
/*
- * $Id: runtar.c,v 1.11.4.2.6.1.2.3 2005/09/30 19:08:04 martinea Exp $
+ * $Id: runtar.c,v 1.24 2006/08/25 11:41:31 martinea Exp $
*
* runs GNUTAR program as root
+ *
+ * argv[0] is the runtar program name
+ * argv[1] is the config name or NOCONFIG
+ * argv[2] will be argv[0] of the gtar program
+ * ...
*/
#include "amanda.h"
-#include "version.h"
+#include "util.h"
+#include "conffile.h"
-int main P((int argc, char **argv));
+int main(int argc, char **argv);
-int main(argc, argv)
-int argc;
-char **argv;
+int
+main(
+ int argc,
+ char ** argv)
{
#ifdef GNUTAR
int i;
char *e;
char *dbf;
+ char *cmdline;
#endif
+ if (argc > 1 && argv && argv[1] && g_str_equal(argv[1], "--version")) {
+ printf("runtar-%s\n", VERSION);
+ return (0);
+ }
+
+ /*
+ * Configure program for internationalization:
+ * 1) Only set the message locale for now.
+ * 2) Set textdomain for all amanda related programs to "amanda"
+ * We don't want to be forced to support dozens of message catalogs.
+ */
+ setlocale(LC_MESSAGES, "C");
+ textdomain("amanda");
+
safe_fd(-1, 0);
safe_cd();
set_pname("runtar");
- dbopen();
- dbprintf(("%s: version %s\n", argv[0], version()));
+ /* Don't die when child closes pipe */
+ signal(SIGPIPE, SIG_IGN);
+
+ dbopen(DBG_SUBDIR_CLIENT);
+ config_init(CONFIG_INIT_CLIENT, NULL);
+
+ if (argc < 3) {
+ error(_("Need at least 3 arguments\n"));
+ /*NOTREACHED*/
+ }
+
+ dbprintf(_("version %s\n"), VERSION);
+
+ if (strcmp(argv[3], "--create") != 0) {
+ error(_("Can only be used to create tar archives\n"));
+ /*NOTREACHED*/
+ }
#ifndef GNUTAR
- fprintf(stderr,"gnutar not available on this system.\n");
- dbprintf(("%s: gnutar not available on this system.\n", argv[0]));
+ g_fprintf(stderr,_("gnutar not available on this system.\n"));
+ dbprintf(_("%s: gnutar not available on this system.\n"), argv[0]);
dbclose();
return 1;
#else
- if(client_uid == (uid_t) -1) {
- error("error [cannot find user %s in passwd file]\n", CLIENT_LOGIN);
+ /*
+ * Print out version information for tar.
+ */
+ do {
+ FILE * version_file;
+ char version_buf[80];
+
+ if ((version_file = popen(GNUTAR " --version 2>&1", "r")) != NULL) {
+ if (fgets(version_buf, (int)sizeof(version_buf), version_file) != NULL) {
+ dbprintf(_(GNUTAR " version: %s\n"), version_buf);
+ } else {
+ if (ferror(version_file)) {
+ dbprintf(_(GNUTAR " version: Read failure: %s\n"), strerror(errno));
+ } else {
+ dbprintf(_(GNUTAR " version: Read failure; EOF\n"));
+ }
+ }
+ } else {
+ dbprintf(_(GNUTAR " version: unavailable: %s\n"), strerror(errno));
+ }
+ } while(0);
+
+#ifdef WANT_SETUID_CLIENT
+ check_running_as(RUNNING_AS_CLIENT_LOGIN | RUNNING_AS_UID_ONLY);
+ if (!become_root()) {
+ error(_("error [%s could not become root (is the setuid bit set?)]\n"), get_pname());
+ /*NOTREACHED*/
}
+#else
+ check_running_as(RUNNING_AS_CLIENT_LOGIN);
+#endif
-#ifdef FORCE_USERID
- if (getuid() != client_uid) {
- error("error [must be invoked by %s]\n", CLIENT_LOGIN);
- }
+ /* skip argv[0] */
+ argc--;
+ argv++;
- if (geteuid() != 0) {
- error("error [must be setuid root]\n");
- }
-#endif
+ dbprintf(_("config: %s\n"), argv[0]);
+ if (strcmp(argv[0], "NOCONFIG") != 0)
+ dbrename(argv[0], DBG_SUBDIR_CLIENT);
+ argc--;
+ argv++;
-#if !defined (DONT_SUID_ROOT)
- setuid(0);
-#endif
+ cmdline = stralloc(GNUTAR);
+ for (i = 1; argv[i]; i++) {
+ char *quoted;
+
+ quoted = quote_string(argv[i]);
+ cmdline = vstrextend(&cmdline, " ", quoted, NULL);
+ amfree(quoted);
+ }
+ dbprintf(_("running: %s\n"), cmdline);
+ amfree(cmdline);
- dbprintf(("running: %s: ",GNUTAR));
- for (i=0; argv[i]; i++)
- dbprintf(("%s ", argv[i]));
- dbprintf(("\n"));
dbf = dbfn();
if (dbf) {
dbf = stralloc(dbf);
e = strerror(errno);
dbreopen(dbf, "more");
amfree(dbf);
- dbprintf(("execve of %s failed (%s)\n", GNUTAR, e));
+ dbprintf(_("execve of %s failed (%s)\n"), GNUTAR, e);
dbclose();
- fprintf(stderr, "runtar: could not exec %s: %s\n", GNUTAR, e);
+ g_fprintf(stderr, _("runtar: could not exec %s: %s\n"), GNUTAR, e);
return 1;
#endif
}