* file named AUTHORS, in the root directory of this distribution.
*/
/*
- * $Id: rundump.c,v 1.23.2.3.6.1 2002/10/27 14:31:18 martinea Exp $
+ * $Id: rundump.c,v 1.33 2006/07/25 18:27:56 martinea Exp $
*
* runs DUMP program as root
+ *
+ * argv[0] is the rundump program name
+ * argv[1] is the config name or NOCONFIG
+ * argv[2] will be argv[0] of the DUMP 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);
#if defined(VDUMP) || defined(XFSDUMP)
+# undef USE_RUNDUMP
# define USE_RUNDUMP
#endif
#if !defined(USE_RUNDUMP)
-# define ERRMSG "rundump not enabled on this system.\n"
+# define ERRMSG _("rundump not enabled on this system.\n")
#else
# if !defined(DUMP) && !defined(VXDUMP) && !defined(VDUMP) && !defined(XFSDUMP)
-# define ERRMSG "DUMP not available on this system.\n"
+# define ERRMSG _("DUMP not available on this system.\n")
# else
# undef ERRMSG
# endif
#endif
-int main(argc, argv)
-int argc;
-char **argv;
+int
+main(
+ int argc,
+ char ** argv)
{
#ifndef ERRMSG
char *dump_program;
int i;
char *e;
+ char *cmdline;
#endif /* ERRMSG */
- int fd;
-
- for(fd = 3; fd < FD_SETSIZE; fd++) {
- /*
- * Make sure nobody spoofs us with a lot of extra open files
- * that would cause an open we do to get a very high file
- * descriptor, which in turn might be used as an index into
- * an array (e.g. an fd_set).
- */
- close(fd);
- }
+ /*
+ * 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("rundump");
- 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);
#ifdef ERRMSG /* { */
- fprintf(stderr, ERRMSG);
- dbprintf(("%s: %s", argv[0], ERRMSG));
+ g_fprintf(stderr, ERRMSG);
+ dbprintf("%s: %s", argv[0], ERRMSG);
dbclose();
return 1;
#else /* } { */
- if(client_uid == (uid_t) -1) {
- error("error [cannot find user %s in passwd file]\n", CLIENT_LOGIN);
- }
-
-#ifdef FORCE_USERID
- if (getuid() != client_uid) {
- error("error [must be invoked by %s]\n", CLIENT_LOGIN);
+#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
- if (geteuid() != 0) {
- error("error [must be setuid root]\n");
- }
-#endif /* FORCE_USERID */
+ /* skip argv[0] */
+ argc--;
+ argv++;
-#if !defined (DONT_SUID_ROOT)
- setuid(0);
-#endif
+ dbprintf(_("config: %s\n"), argv[0]);
+ if (strcmp(argv[0], "NOCONFIG") != 0)
+ dbrename(argv[0], DBG_SUBDIR_CLIENT);
+ argc--;
+ argv++;
#ifdef XFSDUMP
# endif
#endif
- dbprintf(("running: %s: ",dump_program));
- for (i=0; argv[i]; i++)
- dbprintf(("%s ", argv[i]));
- dbprintf(("\n"));
+ cmdline = stralloc(dump_program);
+ 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);
execve(dump_program, argv, safe_env());
e = strerror(errno);
- dbprintf(("execve of %s failed (%s)\n", dump_program, e));
+ dbprintf(_("failed (%s)\n"), e);
dbclose();
- fprintf(stderr, "rundump: could not exec %s: %s\n", dump_program, e);
+ g_fprintf(stderr, _("rundump: could not exec %s: %s\n"), dump_program, e);
return 1;
#endif /* } */
}