X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=client-src%2Fruntar.c;h=cc4705faada555cdd4a4bfd6fd85268e7f5c2d72;hb=2627875b7d18858bc1f9f7652811e4d8c15a23eb;hp=c8e9e6b4f504fb6278ff6e34a372f852964ac185;hpb=3ab887b9bc819a846c75dd7f2ee5d41fac22b19f;p=debian%2Famanda diff --git a/client-src/runtar.c b/client-src/runtar.c index c8e9e6b..cc4705f 100644 --- a/client-src/runtar.c +++ b/client-src/runtar.c @@ -24,81 +24,140 @@ * file named AUTHORS, in the root directory of this distribution. */ /* - * $Id: runtar.c,v 1.11.4.2.6.1 2002/10/27 14:31:18 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; -#endif - int fd; char *e; + char *dbf; + char *cmdline; +#endif - 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("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); + +#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; - dbprintf(("running: %s: ",GNUTAR)); - for (i=0; argv[i]; i++) - dbprintf(("%s ", argv[i])); - dbprintf(("\n")); + quoted = quote_string(argv[i]); + cmdline = vstrextend(&cmdline, " ", quoted, NULL); + amfree(quoted); + } + dbprintf(_("running: %s\n"), cmdline); + amfree(cmdline); + + dbf = dbfn(); + if (dbf) { + dbf = stralloc(dbf); + } + dbclose(); execve(GNUTAR, argv, safe_env()); e = strerror(errno); - dbprintf(("execve of %s failed (%s)\n", GNUTAR, e)); + dbreopen(dbf, "more"); + amfree(dbf); + 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 }