amindexd.c
来自「开源备份软件源码 AMANDA, the Advanced Marylan」· C语言 代码 · 共 1,757 行 · 第 1/4 页
C
1,757 行
break; /* we have a whole line */ } if((len = strlen(line)) > 0 && line[len-1] == '\r') { line[len-1] = '\0'; /* zap the '\r' */ break; } /* * Hmmm. We got a "line" from agets(), which means it saw * a '\n' (or EOF, etc), but there was not a '\r' before it. * Put a '\n' back in the buffer and loop for more. */ strappend(line, "\n"); } dbprintf("> %s\n", line); if (arg != NULL) amfree(arg); s = line; ch = *s++; skip_whitespace(s, ch); if(ch == '\0') { reply(500, _("Command not recognised/incorrect: %s"), line); amfree(line); continue; } cmd = s - 1; skip_non_whitespace(s, ch); cmd_undo = s-1; /* for error message */ cmd_undo_ch = *cmd_undo; *cmd_undo = '\0'; if (ch) { skip_whitespace(s, ch); /* find the argument */ if (ch) { arg = s-1; skip_quoted_string(s, ch); arg = unquote_string(arg); } } amfree(errstr); if (!user_validated && strcmp(cmd, "SECURITY") == 0 && arg) { user_validated = amindexd_debug || check_security( (struct sockaddr_storage *)&his_addr, arg, 0, &errstr); if(user_validated) { reply(200, _("Access OK")); amfree(line); continue; } } if (!user_validated) { /* don't tell client the reason, just log it to debug log */ reply(500, _("Access not allowed")); if (errstr) { dbprintf("%s\n", errstr); } break; } if (strcmp(cmd, "QUIT") == 0) { amfree(line); break; } else if (strcmp(cmd, "HOST") == 0 && arg) { am_host_t *lhost; /* set host we are restoring */ s[-1] = '\0'; if ((lhost = is_dump_host_valid(arg)) != NULL) { dump_hostname = newstralloc(dump_hostname, lhost->hostname); reply(200, _("Dump host set to %s."), dump_hostname); amfree(qdisk_name); /* invalidate any value */ amfree(disk_name); /* invalidate any value */ } s[-1] = (char)ch; } else if (strcmp(cmd, "LISTHOST") == 0) { disk_t *disk, *diskdup; int nbhost = 0, found = 0; s[-1] = '\0'; if (config_name == NULL) { reply(501, _("Must set config before listhost")); } else { lreply(200, _(" List hosts for config %s"), config_name); for (disk = disk_list.head; disk!=NULL; disk = disk->next) { found = 0; for (diskdup = disk_list.head; diskdup!=disk; diskdup = diskdup->next) { if(strcmp(diskdup->host->hostname, disk->host->hostname) == 0) { found = 1; break; } } if(!found){ fast_lreply(201, " %s", disk->host->hostname); nbhost++; } } if(nbhost > 0) { reply(200, _(" List hosts for config %s"), config_name); } else { reply(200, _("No hosts for config %s"), config_name); } } s[-1] = (char)ch; } else if (strcmp(cmd, "DISK") == 0 && arg) { s[-1] = '\0'; if (is_disk_valid(arg) != -1) { disk_name = newstralloc(disk_name, arg); qdisk_name = quote_string(disk_name); if (build_disk_table() != -1) { reply(200, _("Disk set to %s."), qdisk_name); } } s[-1] = (char)ch; } else if (strcmp(cmd, "LISTDISK") == 0) { char *qname; disk_t *disk; int nbdisk = 0; s[-1] = '\0'; if (config_name == NULL) { reply(501, _("Must set config, host before listdisk")); } else if (dump_hostname == NULL) { reply(501, _("Must set host before listdisk")); } else if(arg) { lreply(200, _(" List of disk for device %s on host %s"), arg, dump_hostname); for (disk = disk_list.head; disk!=NULL; disk = disk->next) { if (strcasecmp(disk->host->hostname, dump_hostname) == 0 && ((disk->device && strcmp(disk->device, arg) == 0) || (!disk->device && strcmp(disk->name, arg) == 0))) { qname = quote_string(disk->name); fast_lreply(201, " %s", qname); amfree(qname); nbdisk++; } } if(nbdisk > 0) { reply(200, _("List of disk for device %s on host %s"), arg, dump_hostname); } else { reply(200, _("No disk for device %s on host %s"), arg, dump_hostname); } } else { lreply(200, _(" List of disk for host %s"), dump_hostname); for (disk = disk_list.head; disk!=NULL; disk = disk->next) { if(strcasecmp(disk->host->hostname, dump_hostname) == 0) { qname = quote_string(disk->name); fast_lreply(201, " %s", qname); amfree(qname); nbdisk++; } } if(nbdisk > 0) { reply(200, _("List of disk for host %s"), dump_hostname); } else { reply(200, _("No disk for host %s"), dump_hostname); } } s[-1] = (char)ch; } else if (strcmp(cmd, "SCNF") == 0 && arg) { s[-1] = '\0'; if (check_and_load_config(arg) != -1) { /* try to load the new config */ amfree(dump_hostname); /* invalidate any value */ amfree(qdisk_name); /* invalidate any value */ amfree(disk_name); /* invalidate any value */ reply(200, _("Config set to %s."), config_name); } /* check_and_load_config replies with any failure messages */ s[-1] = (char)ch; } else if (strcmp(cmd, "FEATURES") == 0 && arg) { char *our_feature_string = NULL; char *their_feature_string = NULL; s[-1] = '\0'; am_release_feature_set(our_features); am_release_feature_set(their_features); our_features = am_init_feature_set(); our_feature_string = am_feature_to_string(our_features); their_feature_string = newstralloc(their_feature_string, arg); their_features = am_string_to_feature(their_feature_string); reply(200, "FEATURES %s", our_feature_string); amfree(our_feature_string); amfree(their_feature_string); s[-1] = (char)ch; } else if (strcmp(cmd, "DATE") == 0 && arg) { s[-1] = '\0'; target_date = newstralloc(target_date, arg); reply(200, _("Working date set to %s."), target_date); s[-1] = (char)ch; } else if (strcmp(cmd, "DHST") == 0) { (void)disk_history_list(); } else if (strcmp(cmd, "OISD") == 0 && arg) { if (is_dir_valid_opaque(arg) != -1) { reply(200, _("\"%s\" is a valid directory"), arg); } } else if (strcmp(cmd, "OLSD") == 0 && arg) { (void)opaque_ls(arg,0); } else if (strcmp(cmd, "ORLD") == 0 && arg) { (void)opaque_ls(arg, 1); } else if (strcmp(cmd, "TAPE") == 0) { (void)tapedev_is(); } else if (strcmp(cmd, "DCMP") == 0) { (void)are_dumps_compressed(); } else { *cmd_undo = cmd_undo_ch; /* restore the command line */ reply(500, _("Command not recognised/incorrect: %s"), cmd); } amfree(line); } amfree(arg); uncompress_remove = remove_files(uncompress_remove); free_find_result(&output_find); reply(200, _("Good bye.")); dbclose(); return 0;}static char *amindexd_nicedate( char * datestamp){ static char nice[20]; int year, month, day; int hours, minutes, seconds; char date[9], atime[7]; int numdate, numtime; strncpy(date, datestamp, 8); date[8] = '\0'; numdate = atoi(date); year = numdate / 10000; month = (numdate / 100) % 100; day = numdate % 100; if(strlen(datestamp) <= 8) { g_snprintf(nice, SIZEOF(nice), "%4d-%02d-%02d", year, month, day); } else { strncpy(atime, &(datestamp[8]), 6); atime[6] = '\0'; numtime = atoi(atime); hours = numtime / 10000; minutes = (numtime / 100) % 100; seconds = numtime % 100; g_snprintf(nice, SIZEOF(nice), "%4d-%02d-%02d-%02d-%02d-%02d", year, month, day, hours, minutes, seconds); } return nice;}static intcmp_date( const char * date1, const char * date2){ return strncmp(date1, date2, strlen(date2));}static char *clean_backslash( char *line){ char *s = line, *s1, *s2; char *p = line; int i; while(*s != '\0') { if (*s == '\\') { s++; s1 = s+1; s2 = s+2; if (*s != '\0' && isdigit((int)*s) && *s1 != '\0' && isdigit((int)*s1) && *s2 != '\0' && isdigit((int)*s2)) { /* this is \000, an octal value */ i = ((*s)-'0')*64 + ((*s1)-'0')*8 + ((*s2)-'0'); *p++ = i; s += 3; } else if (*s == '\\') { /* we remove one / */ *p++ = *s++; } else { /* we keep the / */ *p++ = '\\'; *p++ = *s++; } } else { *p++ = *s++; } } *p = '\0'; return line;}static intget_index_dir( char *dump_hostname, char *hostname, char *diskname){ struct stat dir_stat; char *fn; char *s; char *lower_hostname; lower_hostname = stralloc(dump_hostname); for(s=lower_hostname; *s != '\0'; s++) *s = tolower(*s); fn = getindexfname(dump_hostname, diskname, NULL, 0); if (stat(fn, &dir_stat) == 0 && S_ISDIR(dir_stat.st_mode)) { amfree(lower_hostname); amfree(fn); return 1; } amfree(fn); if (hostname != NULL) { fn = getindexfname(hostname, diskname, NULL, 0); if (stat(fn, &dir_stat) == 0 && S_ISDIR(dir_stat.st_mode)) { amfree(lower_hostname); amfree(fn); return 1; } } amfree(fn); fn = getindexfname(lower_hostname, diskname, NULL, 0); if (stat(fn, &dir_stat) == 0 && S_ISDIR(dir_stat.st_mode)) { amfree(lower_hostname); amfree(fn); return 1; } amfree(fn); if(diskname != NULL) { fn = getoldindexfname(dump_hostname, diskname, NULL, 0); if (stat(fn, &dir_stat) == 0 && S_ISDIR(dir_stat.st_mode)) { amfree(lower_hostname); amfree(fn); return 1; } amfree(fn); if (hostname != NULL) { fn = getoldindexfname(hostname, diskname, NULL, 0); if (stat(fn, &dir_stat) == 0 && S_ISDIR(dir_stat.st_mode)) { amfree(lower_hostname); amfree(fn); return 1; } } amfree(fn); fn = getoldindexfname(lower_hostname, diskname, NULL, 0); if (stat(fn, &dir_stat) == 0 && S_ISDIR(dir_stat.st_mode)) { amfree(lower_hostname); amfree(fn); return 1; } amfree(fn); } amfree(lower_hostname); return -1;}static char *get_index_name( char *dump_hostname, char *hostname, char *diskname, char *timestamps, int level){ struct stat dir_stat; char *fn; char *s; char *lower_hostname; lower_hostname = stralloc(dump_hostname); for(s=lower_hostname; *s != '\0'; s++) *s = tolower(*s); fn = getindexfname(dump_hostname, diskname, timestamps, level); if (stat(fn, &dir_stat) == 0 && S_ISREG(dir_stat.st_mode)) { amfree(lower_hostname); return fn; } amfree(fn); if(hostname != NULL) { fn = getindexfname(hostname, diskname, timestamps, level); if (stat(fn, &dir_stat) == 0 && S_ISREG(dir_stat.st_mode)) { amfree(lower_hostname); return fn; } } amfree(fn); fn = getindexfname(lower_hostname, diskname, timestamps, level); if (stat(fn, &dir_stat) == 0 && S_ISREG(dir_stat.st_mode)) { amfree(lower_hostname); return fn; } amfree(fn); if(diskname != NULL) { fn = getoldindexfname(dump_hostname, diskname, timestamps, level); if (stat(fn, &dir_stat) == 0 && S_ISREG(dir_stat.st_mode)) { amfree(lower_hostname); return fn; } amfree(fn); if(hostname != NULL) { fn = getoldindexfname(hostname, diskname, timestamps, level); if (stat(fn, &dir_stat) == 0 && S_ISREG(dir_stat.st_mode)) { amfree(lower_hostname); return fn; } } amfree(fn); fn = getoldindexfname(lower_hostname, diskname, timestamps, level); if (stat(fn, &dir_stat) == 0 && S_ISREG(dir_stat.st_mode)) { amfree(lower_hostname); return fn; } } amfree(lower_hostname); return NULL;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?