X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=client-src%2Fruntar.c;h=144d6bfc777052b87a39298b20c4c7331b818b69;hb=94a044f90357edefa6f4ae9f0b1d5885b0e34aee;hp=da6d9fc741c674dbdbc4072d8909bc48a0ffbcac;hpb=2df780bff19c457b0debb7adc29972a0bc2a5dc2;p=debian%2Famanda diff --git a/client-src/runtar.c b/client-src/runtar.c index da6d9fc..144d6bf 100644 --- a/client-src/runtar.c +++ b/client-src/runtar.c @@ -24,64 +24,130 @@ * 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" -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 + /* + * 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); + 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); + + if(get_client_uid() == (uid_t) -1) { + error(_("error [cannot find user %s in passwd file]\n"), CLIENT_LOGIN); + /*NOTREACHED*/ } -#ifdef FORCE_USERID - if (getuid() != client_uid) { - error("error [must be invoked by %s]\n", CLIENT_LOGIN); - } - - if (geteuid() != 0) { - error("error [must be setuid root]\n"); +#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 !defined (DONT_SUID_ROOT) - setuid(0); -#endif + /* skip argv[0] */ + argc--; + argv++; + + dbprintf(_("config: %s\n"), argv[0]); + if (strcmp(argv[0], "NOCONFIG") != 0) + dbrename(argv[0], DBG_SUBDIR_CLIENT); + argc--; + argv++; + + 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); @@ -93,10 +159,10 @@ char **argv; 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 }