📄 amindexd.c
字号:
uncompress_remove = remove_files(uncompress_remove); exit(1); } dbprintf("< %03d-%s\n", n, reply_buffer);}/* send one line of a multi-line response */printf_arglist_function1(static void fast_lreply, int, n, char *, fmt){ va_list args; int len; if(!reply_buffer) reply_buffer = alloc(reply_buffer_size); while(1) { arglist_start(args, fmt); len = g_vsnprintf(reply_buffer, reply_buffer_size, fmt, args); arglist_end(args); if (len > -1 && (size_t)len < reply_buffer_size-1) break; reply_buffer_size *= 2; amfree(reply_buffer); reply_buffer = alloc(reply_buffer_size); } if (g_fprintf(cmdout,"%03d-%s\r\n", n, reply_buffer) < 0) { dbprintf(_("! error %d (%s) in printf\n"), errno, strerror(errno)); uncompress_remove = remove_files(uncompress_remove); exit(1); } dbprintf("< %03d-%s\n", n, reply_buffer);}/* see if hostname is valid *//* valid is defined to be that there is an index directory for it *//* also do a security check on the requested dump hostname *//* to restrict access to index records if required *//* return -1 if not okay */static am_host_t *is_dump_host_valid( char * host){ am_host_t *ihost; disk_t *diskp; if (config_name == NULL) { reply(501, _("Must set config before setting host.")); return NULL; } /* check that the config actually handles that host */ ihost = lookup_host(host); if(ihost == NULL) { reply(501, _("Host %s is not in your disklist."), host); return NULL; } /* check if an index dir exist */ if(get_index_dir(host, ihost->hostname, NULL)) { return ihost; } /* check if an index dir exist for at least one DLE */ for(diskp = ihost->disks; diskp != NULL; diskp = diskp->hostnext) { if (get_index_dir(diskp->hostname, NULL, NULL)) { return ihost; } } reply(501, _("No index records for host: %s. Have you enabled indexing?"), host); return NULL;}static intis_disk_valid( char *disk){ disk_t *idisk; char *qdisk; if (config_name == NULL) { reply(501, _("Must set config,host before setting disk.")); return -1; } else if (dump_hostname == NULL) { reply(501, _("Must set host before setting disk.")); return -1; } /* check that the config actually handles that disk */ idisk = lookup_disk(dump_hostname, disk); if(idisk == NULL) { qdisk = quote_string(disk); reply(501, _("Disk %s:%s is not in your disklist."), dump_hostname, qdisk); amfree(qdisk); return -1; } /* assume an index dir already */ if (get_index_dir(dump_hostname, idisk->hostname, disk) == 0) { qdisk = quote_string(disk); reply(501, _("No index records for disk: %s. Invalid?"), qdisk); amfree(qdisk); return -1; } return 0;}static intcheck_and_load_config( char * config){ char *conf_diskfile; char *conf_tapelist; char *conf_indexdir; struct stat dir_stat; /* check that the config actually exists */ if (config == NULL) { reply(501, _("Must set config first.")); return -1; } /* (re-)initialize configuration with the new config name */ if (!config_init(CONFIG_INIT_EXPLICIT_NAME, config)) { reply(501, _("Could not read config file for %s!"), config); return -1; } check_running_as(RUNNING_AS_DUMPUSER_PREFERRED); conf_diskfile = config_dir_relative(getconf_str(CNF_DISKFILE)); if (read_diskfile(conf_diskfile, &disk_list) < 0) { reply(501, _("Could not read disk file %s!"), conf_diskfile); amfree(conf_diskfile); return -1; } amfree(conf_diskfile); conf_tapelist = config_dir_relative(getconf_str(CNF_TAPELIST)); if(read_tapelist(conf_tapelist)) { reply(501, _("Could not read tapelist file %s!"), conf_tapelist); amfree(conf_tapelist); return -1; } amfree(conf_tapelist); dbrename(config_name, DBG_SUBDIR_SERVER); output_find = find_dump(&disk_list); sort_find_result("DLKHpB", &output_find); conf_indexdir = config_dir_relative(getconf_str(CNF_INDEXDIR)); if (stat (conf_indexdir, &dir_stat) != 0 || !S_ISDIR(dir_stat.st_mode)) { reply(501, _("Index directory %s does not exist"), conf_indexdir); amfree(conf_indexdir); return -1; } amfree(conf_indexdir); return 0;}static intbuild_disk_table(void){ char *date; char *last_timestamp; off_t last_filenum; int last_level; int last_partnum; find_result_t *find_output; if (config_name == NULL) { reply(590, _("Must set config,host,disk before building disk table")); return -1; } else if (dump_hostname == NULL) { reply(590, _("Must set host,disk before building disk table")); return -1; } else if (disk_name == NULL) { reply(590, _("Must set disk before building disk table")); return -1; } clear_list(); last_timestamp = NULL; last_filenum = (off_t)-1; last_level = -1; last_partnum = -1; for(find_output = output_find; find_output != NULL; find_output = find_output->next) { if(strcasecmp(dump_hostname, find_output->hostname) == 0 && strcmp(disk_name , find_output->diskname) == 0 && strcmp("OK" , find_output->status) == 0) { int partnum = -1; int maxpart = -1; if (strcmp("1/1", find_output->partnum) == 0) { partnum = -1; } else if (strcmp("1/-1", find_output->partnum) == 0) { if (find_output->next && strcmp(dump_hostname, find_output->next->hostname) == 0 && strcmp(disk_name, find_output->next->diskname) == 0 && strcmp(find_output->timestamp, find_output->next->timestamp) == 0 && strcmp("OK", find_output->next->status) == 0 && strcmp("2/-1", find_output->next->partnum) == 0) { partnum = 1; } else { partnum = -1; } } else if (strcmp("--", find_output->partnum)) { char *c; partnum = atoi(find_output->partnum); c = strchr(find_output->partnum,'/'); if (c) maxpart = atoi(c+1); else maxpart = -1; } /* * The sort order puts holding disk entries first. We want to * use them if at all possible, so ignore any other entries * for the same datestamp after we see a holding disk entry * (as indicated by a filenum of zero). */ if(last_timestamp && strcmp(find_output->timestamp, last_timestamp) == 0 && find_output->level == last_level && partnum == last_partnum && last_filenum == 0) { continue; } /* ignore duplicate partnum */ if(last_timestamp && strcmp(find_output->timestamp, last_timestamp) == 0 && find_output->level == last_level && partnum == last_partnum) { continue; } last_timestamp = find_output->timestamp; last_filenum = find_output->filenum; last_level = find_output->level; last_partnum = partnum; date = amindexd_nicedate(find_output->timestamp); add_dump(find_output->hostname, date, find_output->level, find_output->label, find_output->filenum, partnum, maxpart); dbprintf("- %s %d %s %lld %d %d\n", date, find_output->level, find_output->label, (long long)find_output->filenum, partnum, maxpart); } } clean_dump(); return 0;}static intdisk_history_list(void){ DUMP_ITEM *item; char date[20]; if (config_name == NULL) { reply(502, _("Must set config,host,disk before listing history")); return -1; } else if (dump_hostname == NULL) { reply(502, _("Must set host,disk before listing history")); return -1; } else if (disk_name == NULL) { reply(502, _("Must set disk before listing history")); return -1; } lreply(200, _(" Dump history for config \"%s\" host \"%s\" disk %s"), config_name, dump_hostname, qdisk_name); for (item=first_dump(); item!=NULL; item=next_dump(item)){ char *tapelist_str = marshal_tapelist(item->tapes, 1); strncpy(date, item->date, 20); date[19] = '\0'; if(!am_has_feature(their_features,fe_amrecover_timestamp)) date[10] = '\0'; if(am_has_feature(their_features, fe_amindexd_marshall_in_DHST)){ lreply(201, " %s %d %s", date, item->level, tapelist_str); } else{ lreply(201, " %s %d %s %lld", date, item->level, tapelist_str, (long long)item->file); } amfree(tapelist_str); } reply(200, _("Dump history for config \"%s\" host \"%s\" disk %s"), config_name, dump_hostname, qdisk_name); return 0;}/* * is the directory dir backed up - dir assumed complete relative to * disk mount point *//* opaque version of command */static intis_dir_valid_opaque( char *dir){ DUMP_ITEM *item; char line[STR_SIZE]; FILE *fp; int last_level; char *ldir = NULL; char *filename_gz = NULL; char *filename = NULL; size_t ldir_len; static char *emsg = NULL; if (config_name == NULL || dump_hostname == NULL || disk_name == NULL) { reply(502, _("Must set config,host,disk before asking about directories")); return -1; } else if (dump_hostname == NULL) { reply(502, _("Must set host,disk before asking about directories")); return -1; } else if (disk_name == NULL) { reply(502, _("Must set disk before asking about directories")); return -1; } else if (target_date == NULL) { reply(502, _("Must set date before asking about directories")); return -1; } /* scan through till we find first dump on or before date */ for (item=first_dump(); item!=NULL; item=next_dump(item)) if (cmp_date(item->date, target_date) <= 0) break; if (item == NULL) { /* no dump for given date */ reply(500, _("No dumps available on or before date \"%s\""), target_date); return -1; } if(strcmp(dir, "/") == 0) { ldir = stralloc(dir); } else { ldir = stralloc2(dir, "/"); } ldir_len = strlen(ldir); /* go back till we hit a level 0 dump */ do { amfree(filename); filename_gz = get_index_name(dump_hostname, item->hostname, disk_name, item->date, item->level); if (filename_gz == NULL) { reply(599, "index not found"); amfree(ldir); return -1; } if((filename = uncompress_file(filename_gz, &emsg)) == NULL) { reply(599, _("System error %s"), emsg); amfree(filename_gz); amfree(emsg); amfree(ldir); return -1; } amfree(filename_gz); dbprintf("f %s\n", filename); if ((fp = fopen(filename, "r")) == NULL) { reply(599, _("System error %s"), strerror(errno)); amfree(filename); amfree(ldir); return -1; } while (fgets(line, STR_SIZE, fp) != NULL) { if (line[0] == '\0') continue; if(line[strlen(line)-1] == '\n') line[strlen(line)-1] = '\0'; if (strncmp(line, ldir, ldir_len) != 0) { continue; /* not found yet */ } amfree(filename); amfree(ldir); afclose(fp); return 0; } afclose(fp); last_level = item->level; do { item=next_dump(item); } while ((item != NULL) && (item->level >= last_level)); } while (item != NULL); amfree(filename); amfree(ldir); reply(500, _("\"%s\" is an invalid directory"), dir); return -1;}static intopaque_ls( char * dir, int recursive){ DUMP_ITEM *dump_item; DIR_ITEM *dir_item; int level, last_level;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -