⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 amcheck.c

📁 开源备份软件源码 AMANDA, the Advanced Maryland Automatic Network Disk Archiver, is a backup system that a
💻 C
📖 第 1 页 / 共 4 页
字号:
		continue;	    strappend(extra_info, line);	    strappend(extra_info, "\n");	}	afclose(ferr);	errfd = -1;	rc = 0;	while (wait(&retstat) != -1) {	    if (!WIFEXITED(retstat) || WEXITSTATUS(retstat) != 0) {		char *mailer_error = str_exit_status("mailer", retstat);		strappend(err, mailer_error);		amfree(mailer_error);		rc = 1;	    }	}	if (rc != 0) {	    if(extra_info) {		fputs(extra_info, stderr);		amfree(extra_info);	    }	    error(_("error running mailer %s: %s"), MAILER, err?err:"(unknown)");	    /*NOTREACHED*/	}    }#endif    dbclose();    return (server_probs || client_probs);}/* --------------------------------------------------- */static char *datestamp;static FILE *errf = NULL;int check_tapefile(    FILE *outf,    char *tapefile){    struct stat statbuf;    char *quoted;    int tapebad = 0;    if (stat(tapefile, &statbuf) == 0) {	if (!S_ISREG(statbuf.st_mode)) {	    quoted = quote_string(tapefile);	    g_fprintf(outf, _("ERROR: tapelist %s: should be a regular file.\n"),		    quoted);	    tapebad = 1;	    amfree(quoted);	} else if (access(tapefile, F_OK) != 0) {	    quoted = quote_string(tapefile);	    g_fprintf(outf, _("ERROR: can't access tapelist %s\n"), quoted);	    tapebad = 1;	    amfree(quoted);	} else if (access(tapefile, W_OK) != 0) {	    quoted = quote_string(tapefile);	    g_fprintf(outf, _("ERROR: tapelist %s: not writable\n"), quoted);	    tapebad = 1;	    amfree(quoted);	}    }    return tapebad;}inttest_server_pgm(    FILE *	outf,    char *	dir,    char *	pgm,    int		suid,    uid_t	dumpuid){    struct stat statbuf;    int pgmbad = 0;    char *quoted;    pgm = vstralloc(dir, "/", pgm, versionsuffix(), NULL);    quoted = quote_string(pgm);    if(stat(pgm, &statbuf) == -1) {	g_fprintf(outf, _("ERROR: program %s: does not exist\n"),		quoted);	pgmbad = 1;    } else if (!S_ISREG(statbuf.st_mode)) {	g_fprintf(outf, _("ERROR: program %s: not a file\n"),		quoted);	pgmbad = 1;    } else if (access(pgm, X_OK) == -1) {	g_fprintf(outf, _("ERROR: program %s: not executable\n"),		quoted);	pgmbad = 1;#ifndef SINGLE_USERID    } else if (suid \	       && dumpuid != 0	       && (statbuf.st_uid != 0 || (statbuf.st_mode & 04000) == 0)) {	g_fprintf(outf, _("ERROR: program %s: not setuid-root\n"),		quoted);	pgmbad = 1;#else    /* Quiet unused parameter warnings */    (void)suid;    (void)dumpuid;#endif /* SINGLE_USERID */    }    amfree(quoted);    amfree(pgm);    return pgmbad;}/* check that the tape is a valid amanda tape   Returns TRUE if all tests passed; FALSE otherwise. */static gboolean test_tape_status(FILE * outf) {    int tape_status;    Device * device;    GValue property_value;    char * label = NULL;    char * tapename = NULL;    ReadLabelStatusFlags label_status;    bzero(&property_value, sizeof(property_value));        tapename = getconf_str(CNF_TAPEDEV);    g_return_val_if_fail(tapename != NULL, FALSE);    device_api_init();        if (!getconf_seen(CNF_TPCHANGER) && getconf_int(CNF_RUNTAPES) != 1) {        g_fprintf(outf,                _("WARNING: if a tape changer is not available, runtapes "                  "must be set to 1\n"));        g_fprintf(outf, _("Change the value of the \"runtapes\" parameter in "                         "amanda.conf or configure a tape changer\n"));    }        tape_status = taper_scan(NULL, &label, &datestamp, &tapename, NULL,                             FILE_taperscan_output_callback, outf,                             NULL, NULL);    if (tape_status < 0) {        tape_t *exptape = lookup_last_reusable_tape(0);        g_fprintf(outf, _("       (expecting "));        if(exptape != NULL) g_fprintf(outf, _("tape %s or "), exptape->label);        g_fprintf(outf, _("a new tape)\n"));        amfree(label);        return FALSE;    }    device = device_open(tapename);    if (device == NULL) {        g_fprintf(outf, "ERROR: Could not open tape device.\n");        amfree(label);        return FALSE;    }        device_set_startup_properties_from_config(device);    label_status = device_read_label(device);    if (tape_status == 3 &&         !(label_status & READ_LABEL_STATUS_VOLUME_UNLABELED)) {        if (label_status == READ_LABEL_STATUS_SUCCESS) {            g_fprintf(outf, "WARNING: Volume was unlabeled, but now "                    "is labeled \"%s\".\n", device->volume_label);        }    } else if (label_status != READ_LABEL_STATUS_SUCCESS && tape_status != 3) {        char * errstr =             g_english_strjoinv_and_free                (g_flags_nick_to_strv(label_status &                                       (~READ_LABEL_STATUS_VOLUME_UNLABELED),                                       READ_LABEL_STATUS_FLAGS_TYPE), "or");        g_fprintf(outf, "WARNING: Reading label the second time failed: "                "One of %s.\n", errstr);        g_free(errstr);    } else if (tape_status != 3 &&               (device->volume_label == NULL || label == NULL ||                strcmp(device->volume_label, label) != 0)) {        g_fprintf(outf, "WARNING: Label mismatch on re-read: "                "Got %s first, then %s.\n", label, device->volume_label);    }        /* If we can't get this property, it's not an error. Maybe the device     * doesn't support this property, or needs an actual volume to know     * for sure. */    if (device_property_get(device, PROPERTY_MEDIUM_TYPE, &property_value)) {        g_assert(G_VALUE_TYPE(&property_value) == MEDIA_ACCESS_MODE_TYPE);        if (g_value_get_enum(&property_value) ==            MEDIA_ACCESS_MODE_WRITE_ONLY) {            g_fprintf(outf, "WARNING: Media access mode is WRITE_ONLY, "                    "dumps will be thrown away.\n");        }    }        if (overwrite) {	char *timestamp = get_undef_timestamp();        if (!device_start(device, ACCESS_WRITE, label, timestamp)) {            if (tape_status == 3) {                g_fprintf(outf, "ERROR: Could not label brand new tape.\n");            } else {                g_fprintf(outf,                        "ERROR: tape %s label ok, but is not writable.\n",                        label);            }	    amfree(timestamp);            amfree(label);            g_object_unref(device);            return FALSE;        } else { /* Write succeeded. */            if (tape_status != 3) {                g_fprintf(outf, "Tape %s is writable; rewrote label.\n", label);            } else {                g_fprintf(outf, "Wrote label %s to brand new tape.\n", label);            }        }	amfree(timestamp);    } else { /* !overwrite */        g_fprintf(outf, "NOTE: skipping tape-writable test\n");        if (tape_status == 3) {            g_fprintf(outf,                    "Found a brand new tape, will label it %s.\n",                     label);        } else {            g_fprintf(outf, "Tape %s label ok\n", label);        }                        }    g_object_unref(device);    amfree(label);    return TRUE;}pid_tstart_server_check(    int		fd,    int		do_localchk,    int		do_tapechk){    struct fs_usage fsusage;    FILE *outf = NULL;    holdingdisk_t *hdp;    pid_t pid G_GNUC_UNUSED;    int confbad = 0, tapebad = 0, disklow = 0, logbad = 0;    int userbad = 0, infobad = 0, indexbad = 0, pgmbad = 0;    int testtape = do_tapechk;    tapetype_t *tp = NULL;    char *quoted;    int res;    intmax_t kb_avail;    switch(pid = fork()) {    case -1:    	error(_("could not spawn a process for checking the server: %s"), strerror(errno));        g_assert_not_reached();            case 0:    	break;            default:	return pid;    }        dup2(fd, 1);    dup2(fd, 2);        set_pname("amcheck-server");        startclock();    if((outf = fdopen(fd, "w")) == NULL) {	error(_("fdopen %d: %s"), fd, strerror(errno));	/*NOTREACHED*/    }    errf = outf;    g_fprintf(outf, _("Amanda Tape Server Host Check\n"));    g_fprintf(outf, "-----------------------------\n");    if (do_localchk || testtape) {        tp = lookup_tapetype(getconf_str(CNF_TAPETYPE));    }    /*     * Check various server side config file settings.     */    if(do_localchk) {	char *ColumnSpec;	char *errstr = NULL;	char *lbl_templ;	ColumnSpec = getconf_str(CNF_COLUMNSPEC);	if(SetColumnDataFromString(ColumnData, ColumnSpec, &errstr) < 0) {	    g_fprintf(outf, _("ERROR: %s\n"), errstr);	    amfree(errstr);	    confbad = 1;	}	lbl_templ = tapetype_get_lbl_templ(tp);	if(strcmp(lbl_templ, "") != 0) {	    lbl_templ = config_dir_relative(lbl_templ);	    if(access(lbl_templ, R_OK) == -1) {		g_fprintf(outf,			_("ERROR: cannot read label template (lbl-templ) file %s: %s. Check permissions\n"),			lbl_templ,			strerror(errno));		confbad = 1;	    }#if !defined(LPRCMD)	    g_fprintf(outf, _("ERROR:lbl-templ  set but no LPRCMD defined. You should reconfigure amanda\n       and make sure it finds a lpr or lp command.\n"));	    confbad = 1;#endif	}	if (getconf_int(CNF_FLUSH_THRESHOLD_SCHEDULED) <				 getconf_int(CNF_FLUSH_THRESHOLD_DUMPED)) {	    g_fprintf(outf, _("WARNING: flush_threshold_dumped (%d) must be less than or equal to flush_threshold_scheduled (%d).\n"), 		      getconf_int(CNF_FLUSH_THRESHOLD_DUMPED),		      getconf_int(CNF_FLUSH_THRESHOLD_SCHEDULED));	}	if (getconf_int(CNF_FLUSH_THRESHOLD_SCHEDULED) <				 getconf_int(CNF_TAPERFLUSH)) {	    g_fprintf(outf, _("WARNING: taperflush (%d) must be less than or equal to flush_threshold_scheduled (%d).\n"), 		      getconf_int(CNF_TAPERFLUSH),		      getconf_int(CNF_FLUSH_THRESHOLD_SCHEDULED));	}	if (getconf_int(CNF_TAPERFLUSH) > 0 &&	    !getconf_boolean(CNF_AUTOFLUSH)) {	    g_fprintf(outf, _("WARNING: autoflush must be set to 'yes' if taperflush (%d) is greater that 0.\n"),		      getconf_int(CNF_TAPERFLUSH));	}	/* Double-check that 'localhost' resolves properly */	if ((res = resolve_hostname("localhost", 0, NULL, NULL) != 0)) {	    g_fprintf(outf, _("ERROR: Cannot resolve `localhost': %s\n"), gai_strerror(res));	    confbad = 1;	}    }    /*     * Look up the programs used on the server side.     */    if(do_localchk) {	/* 	 * entreprise version will do planner/dumper suid check	 */	if(access(amlibexecdir, X_OK) == -1) {	    quoted = quote_string(amlibexecdir);	    g_fprintf(outf, _("ERROR: Directory %s containing Amanda tools is not accessible\n."),		    quoted);	    g_fprintf(outf, _("Check permissions\n"));	    pgmbad = 1;	    amfree(quoted);	} else {	    if(test_server_pgm(outf, amlibexecdir, "planner", 1, uid_dumpuser))		pgmbad = 1;	    if(test_server_pgm(outf, amlibexecdir, "dumper", 1, uid_dumpuser))		pgmbad = 1;	    if(test_server_pgm(outf, amlibexecdir, "driver", 0, uid_dumpuser))		pgmbad = 1;	    if(test_server_pgm(outf, amlibexecdir, "taper", 0, uid_dumpuser))		pgmbad = 1;	    if(test_server_pgm(outf, amlibexecdir, "amtrmidx", 0, uid_dumpuser))		pgmbad = 1;	    if(test_server_pgm(outf, amlibexecdir, "amlogroll", 0, uid_dumpuser))		pgmbad = 1;	}	if(access(sbindir, X_OK) == -1) {	    quoted = quote_string(sbindir);	    g_fprintf(outf, _("ERROR: Directory %s containing Amanda tools is not accessible\n"),		    sbindir);	    g_fprintf(outf, _("Check permissions\n"));	    pgmbad = 1;	    amfree(quoted);	} else {	    if(test_server_pgm(outf, sbindir, "amgetconf", 0, uid_dumpuser))		pgmbad = 1;	    if(test_server_pgm(outf, sbindir, "amcheck", 1, uid_dumpuser))		pgmbad = 1;	    if(test_server_pgm(outf, sbindir, "amdump", 0, uid_dumpuser))		pgmbad = 1;	    if(test_server_pgm(outf, sbindir, "amreport", 0, uid_dumpuser))		pgmbad = 1;	}	if(access(COMPRESS_PATH, X_OK) == -1) {	    quoted = quote_string(COMPRESS_PATH);	    g_fprintf(outf, _("WARNING: %s is not executable, server-compression "			    "and indexing will not work. \n"),quoted);	    g_fprintf(outf, _("Check permissions\n"));	    amfree(quoted);	}    }    /*     * Check that the directory for the tapelist file is writable, as well     * as the tapelist file itself (if it already exists).  Also, check for     * a "hold" file (just because it is convenient to do it here) and warn     * if tapedev is set to the null device.     */    if(do_localchk || do_tapechk) {	char *tapefile;	char *newtapefile;	char *tape_dir;	char *lastslash;	char *holdfile;        char * tapename;	struct stat statbuf;		tapefile = config_dir_relative(getconf_str(CNF_TAPELIST));	/*	 * XXX There Really Ought to be some error-checking here... dhw	 */	tape_dir = stralloc(tapefile);	if ((lastslash = strrchr((const char *)tape_dir, '/')) != NULL) {	    *lastslash = '\0';	/*	 * else whine Really Loudly about a path with no slashes??!?	 */	}	if(access(tape_dir, W_OK) == -1) {	    quoted = quote_string(tape_dir);	    g_fprintf(outf, _("ERROR: tapelist dir %s: not writable.\nCheck permissions\n"), 		    quoted);	    tapebad = 1;	    amfree(quoted);	}	else if(stat(tapefile, &statbuf) == -1) {	    quoted = quote_string(tape_dir);	    g_fprintf(outf, _("ERROR: tapelist %s (%s), "		    "you must create an empty file.\n"),		    quoted, strerror(errno));	    tapebad = 1;	    amfree(quoted);	}	else {	    tapebad |= check_tapefile(outf, tapefile);	    if (tapebad == 0 && read_tapelist(tapefile)) {		quoted = quote_string(tapefile);		g_fprintf(outf, _("ERROR: tapelist %s: parse error\n"), quoted);		tapebad = 1;		amfree(quoted);	    }	    newtapefile = stralloc2(tapefile, ".new");	    tapebad |= check_tapefile(outf, newtapefile);	    amfree(newtapefile);	    newtapefile = stralloc2(tapefile, ".amlabel");	    tapebad |= check_tapefile(outf, newtapefile);	    amfree(newtapefile);	    newtapefile = stralloc2(tapefile, ".amlabel.new");	    tapebad |= check_tapefile(outf, newtapefile);	    amfree(newtapefile);	    newtapefile = stralloc2(tapefile, ".yesterday");	    tapebad |= check_tapefile(outf, newtapefile);	    amfree(newtapefile);	    newtapefile = stralloc2(tapefile, ".yesterday.new");	    tapebad |= check_tapefile(outf, newtapefile);	    amfree(newtapefile);	}	holdfile = config_dir_relative("hold");	if(access(holdfile, F_OK) != -1) {	    quoted = quote_string(holdfile);	    g_fprintf(outf, _("WARNING: hold file %s exists."), holdfile);	    g_fprintf(outf, _("Amdump will sleep as long as this file exists.\n"));	    g_fprintf(outf, _("You might want to delete the existing hold file\n"));	    amfree(quoted);	}	amfree(tapefile);	amfree(tape_dir);	amfree(holdfile);	tapename = getconf_str(CNF_TAPEDEV);	if (tapename == NULL) {	    if (getconf_str(CNF_TPCHANGER) == NULL) {		g_fprintf(outf, _("WARNING:Parameter \"tapedev\" or \"tpchanger\" not specified in amanda.conf.\n"));		testtape = 0;		do_tapechk = 0;	    }	}    }    /* check available disk space */    if(do_localchk) {	for(hdp = getconf_holdingdisks(); hdp != NULL; hdp = holdingdisk_next(hdp)) {    	    quoted = quote_string(holdingdisk_get_diskdir(hdp));	    if(get_fs_usage(holdingdisk_get_diskdir(hdp), NULL, &fsusage) == -1) {		g_fprintf(outf, _("ERROR: holding dir %s (%s), "			"you must create a directory.\n"),

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -