/** spool autotrust file */ static void spool_auto_file(FILE* in, int* lineno, FILE* cfg, char* id) { char line[MAX_LINE_LEN]; char* parse; FILE* spool; /* find filename for new file */ while(isspace((int)*id)) id++; if(strlen(id)==0) fatal_exit("AUTROTRUST_FILE must have id, line %d", *lineno); id[strlen(id)-1]=0; /* remove newline */ fake_temp_file("_auto_", id, line, sizeof(line)); /* add option for the file */ fprintf(cfg, "server: auto-trust-anchor-file: \"%s\"\n", line); /* open file and spool to it */ spool = fopen(line, "w"); if(!spool) fatal_exit("could not open %s: %s", line, strerror(errno)); fprintf(stderr, "testbound is spooling key file: %s\n", line); if(!cfg_strlist_insert(&cfgfiles, strdup(line))) fatal_exit("out of memory"); line[sizeof(line)-1] = 0; while(fgets(line, MAX_LINE_LEN-1, in)) { parse = line; (*lineno)++; while(isspace((int)*parse)) parse++; if(strncmp(parse, "AUTOTRUST_END", 13) == 0) { fclose(spool); return; } fputs(line, spool); } fatal_exit("no AUTOTRUST_END in input file"); }
/** check autotrust file contents */ static void autotrust_check(struct replay_runtime* runtime, struct replay_moment* mom) { char name[1024], line[1024]; FILE *in; int lineno = 0, oke=1; char* expanded; struct config_strlist* p; line[sizeof(line)-1] = 0; log_assert(mom->autotrust_id); fake_temp_file("_auto_", mom->autotrust_id, name, sizeof(name)); in = fopen(name, "r"); if(!in) fatal_exit("could not open %s: %s", name, strerror(errno)); for(p=mom->file_content; p; p=p->next) { lineno++; if(!fgets(line, (int)sizeof(line)-1, in)) { log_err("autotrust check failed, could not read line"); log_err("file %s, line %d", name, lineno); log_err("should be: %s", p->str); fatal_exit("autotrust_check failed"); } if(line[0]) line[strlen(line)-1] = 0; /* remove newline */ expanded = macro_process(runtime->vars, runtime, p->str); if(!expanded) fatal_exit("could not expand macro line %d", lineno); if(verbosity >= 7 && strcmp(p->str, expanded) != 0) log_info("expanded '%s' to '%s'", p->str, expanded); if(strcmp(expanded, line) != 0) { log_err("mismatch in file %s, line %d", name, lineno); log_err("file has : %s", line); log_err("should be: %s", expanded); free(expanded); oke = 0; continue; } free(expanded); fprintf(stderr, "%s:%2d ok : %s\n", name, lineno, line); } if(fgets(line, (int)sizeof(line)-1, in)) { log_err("autotrust check failed, extra lines in %s after %d", name, lineno); do { fprintf(stderr, "file has: %s", line); } while(fgets(line, (int)sizeof(line)-1, in)); oke = 0; } fclose(in); if(!oke) fatal_exit("autotrust_check STEP %d failed", mom->time_step); log_info("autotrust %s is OK", mom->autotrust_id); }
/** process config elements */ static void setup_config(FILE* in, int* lineno, int* pass_argc, char* pass_argv[]) { char configfile[MAX_LINE_LEN]; char line[MAX_LINE_LEN]; char* parse; FILE* cfg; fake_temp_file("_cfg", "", configfile, sizeof(configfile)); add_opts("-c", pass_argc, pass_argv); add_opts(configfile, pass_argc, pass_argv); cfg = fopen(configfile, "w"); if(!cfg) fatal_exit("could not open %s: %s", configfile, strerror(errno)); if(!cfg_strlist_insert(&cfgfiles, strdup(configfile))) fatal_exit("out of memory"); line[sizeof(line)-1] = 0; /* some basic settings to not pollute the host system */ fprintf(cfg, "server: use-syslog: no\n"); fprintf(cfg, " directory: \"\"\n"); fprintf(cfg, " chroot: \"\"\n"); fprintf(cfg, " username: \"\"\n"); fprintf(cfg, " pidfile: \"\"\n"); fprintf(cfg, " val-log-level: 2\n"); while(fgets(line, MAX_LINE_LEN-1, in)) { parse = line; (*lineno)++; while(isspace((int)*parse)) parse++; if(!*parse || parse[0] == ';') continue; if(strncmp(parse, "COMMANDLINE", 11) == 0) { parse[strlen(parse)-1] = 0; /* strip off \n */ add_opts(parse+11, pass_argc, pass_argv); continue; } if(strncmp(parse, "AUTOTRUST_FILE", 14) == 0) { spool_auto_file(in, lineno, cfg, parse+14); continue; } if(strncmp(parse, "CONFIG_END", 10) == 0) { fclose(cfg); return; } fputs(line, cfg); } fatal_exit("No CONFIG_END in input file"); }