static void keypair(FILE *in, FILE *out) { char buf[1024]; char lbuf[1024]; char *keyword, *value; int dsa2, L, N; while(fgets(buf,sizeof buf,in) != NULL) { if (!parse_line(&keyword, &value, lbuf, buf)) { continue; } if(!strcmp(keyword,"[mod")) { if (!parse_mod(value, &dsa2, &L, &N, NULL)) { fprintf(stderr, "Mod Parse Error\n"); exit (1); } fputs(buf,out); } else if(!strcmp(keyword,"N")) { DSA *dsa; int n=atoi(value); dsa = FIPS_dsa_new(); if (!dsa2 && !dsa_builtin_paramgen(dsa, L, N, NULL, NULL, 0, NULL, NULL, NULL, NULL)) { fprintf(stderr, "Parameter Generation error\n"); exit(1); } if (dsa2 && dsa_builtin_paramgen2(dsa, L, N, NULL, NULL, 0, -1, NULL, NULL, NULL, NULL) <= 0) { fprintf(stderr, "Parameter Generation error\n"); exit(1); } do_bn_print_name(out, "P",dsa->p); do_bn_print_name(out, "Q",dsa->q); do_bn_print_name(out, "G",dsa->g); fputs(RESP_EOL, out); while(n--) { if (!DSA_generate_key(dsa)) exit(1); do_bn_print_name(out, "X",dsa->priv_key); do_bn_print_name(out, "Y",dsa->pub_key); fputs(RESP_EOL, out); } if (dsa) FIPS_dsa_free(dsa); } } }
void parse_term(void) { Token t; parse_mod(); for(;;) { t = get_token(); if (t.type != T_MUL && t.type != T_DIV) { unget_token(); break; } parse_mod(); Opcode op; if (t.type == T_MUL) { op = OP_MUL; } else if (t.type == T_DIV) { op = OP_DIV; } vm_add_opcode(op); } }
void parse_mod(void) { Token t; parse_pow(); for (;;) { t = get_token(); if (t.type != T_MOD) { unget_token(); break; } parse_mod(); if (t.type == T_MOD) { vm_add_opcode(OP_MOD); } } }
static void sigver(FILE *in, FILE *out) { DSA *dsa=NULL; char buf[1024]; char lbuf[1024]; unsigned char msg[1024]; char *keyword, *value; int n=0; int dsa2, L, N; const EVP_MD *md = NULL; DSA_SIG sg, *sig = &sg; sig->r = NULL; sig->s = NULL; while(fgets(buf,sizeof buf,in) != NULL) { if (!parse_line(&keyword, &value, lbuf, buf)) { fputs(buf,out); continue; } fputs(buf,out); if(!strcmp(keyword,"[mod")) { if (!parse_mod(value, &dsa2, &L, &N, &md)) { fprintf(stderr, "Mod Parse Error\n"); exit (1); } if (dsa) FIPS_dsa_free(dsa); dsa = FIPS_dsa_new(); } else if(!strcmp(keyword,"P")) dsa->p=hex2bn(value); else if(!strcmp(keyword,"Q")) dsa->q=hex2bn(value); else if(!strcmp(keyword,"G")) dsa->g=hex2bn(value); else if(!strcmp(keyword,"Msg")) n=hex2bin(value,msg); else if(!strcmp(keyword,"Y")) dsa->pub_key=hex2bn(value); else if(!strcmp(keyword,"R")) sig->r=hex2bn(value); else if(!strcmp(keyword,"S")) { EVP_MD_CTX mctx; int r; FIPS_md_ctx_init(&mctx); sig->s=hex2bn(value); FIPS_digestinit(&mctx, md); FIPS_digestupdate(&mctx, msg, n); no_err = 1; r = FIPS_dsa_verify_ctx(dsa, &mctx, sig); no_err = 0; FIPS_md_ctx_cleanup(&mctx); fprintf(out, "Result = %c\n\n", r == 1 ? 'P' : 'F'); } } }
static void siggen(FILE *in, FILE *out) { char buf[1024]; char lbuf[1024]; char *keyword, *value; int dsa2, L, N; const EVP_MD *md = NULL; DSA *dsa=NULL; while(fgets(buf,sizeof buf,in) != NULL) { if (!parse_line(&keyword, &value, lbuf, buf)) { fputs(buf,out); continue; } fputs(buf,out); if(!strcmp(keyword,"[mod")) { if (!parse_mod(value, &dsa2, &L, &N, &md)) { fprintf(stderr, "Mod Parse Error\n"); exit (1); } if (dsa) FIPS_dsa_free(dsa); dsa = FIPS_dsa_new(); if (!dsa2 && !dsa_builtin_paramgen(dsa, L, N, md, NULL, 0, NULL, NULL, NULL, NULL)) { fprintf(stderr, "Parameter Generation error\n"); exit(1); } if (dsa2 && dsa_builtin_paramgen2(dsa, L, N, md, NULL, 0, NULL, NULL, NULL, NULL) <= 0) { fprintf(stderr, "Parameter Generation error\n"); exit(1); } do_bn_print_name(out, "P",dsa->p); do_bn_print_name(out, "Q",dsa->q); do_bn_print_name(out, "G",dsa->g); fputs("\n", out); } else if(!strcmp(keyword,"Msg")) { unsigned char msg[1024]; int n; EVP_MD_CTX mctx; DSA_SIG *sig; FIPS_md_ctx_init(&mctx); n=hex2bin(value,msg); if (!DSA_generate_key(dsa)) exit(1); do_bn_print_name(out, "Y",dsa->pub_key); FIPS_digestinit(&mctx, md); FIPS_digestupdate(&mctx, msg, n); sig = FIPS_dsa_sign_ctx(dsa, &mctx); do_bn_print_name(out, "R",sig->r); do_bn_print_name(out, "S",sig->s); fputs("\n", out); FIPS_dsa_sig_free(sig); FIPS_md_ctx_cleanup(&mctx); } } if (dsa) FIPS_dsa_free(dsa); }
static void keyver(FILE *in, FILE *out) { char buf[1024]; char lbuf[1024]; char *keyword, *value; BIGNUM *p = NULL, *q = NULL, *g = NULL, *X = NULL, *Y = NULL; BIGNUM *Y2; BN_CTX *ctx = NULL; int dsa2, L, N; int paramcheck = 0; ctx = BN_CTX_new(); Y2 = BN_new(); while(fgets(buf,sizeof buf,in) != NULL) { if (!parse_line(&keyword, &value, lbuf, buf)) { fputs(buf,out); continue; } if(!strcmp(keyword,"[mod")) { if (p) BN_free(p); p = NULL; if (q) BN_free(q); q = NULL; if (g) BN_free(g); g = NULL; paramcheck = 0; if (!parse_mod(value, &dsa2, &L, &N, NULL)) { fprintf(stderr, "Mod Parse Error\n"); exit (1); } } else if(!strcmp(keyword,"P")) p=hex2bn(value); else if(!strcmp(keyword,"Q")) q=hex2bn(value); else if(!strcmp(keyword,"G")) g=hex2bn(value); else if(!strcmp(keyword,"X")) X=hex2bn(value); else if(!strcmp(keyword,"Y")) { Y=hex2bn(value); if (!p || !q || !g || !X || !Y) { fprintf(stderr, "Parse Error\n"); exit (1); } do_bn_print_name(out, "P",p); do_bn_print_name(out, "Q",q); do_bn_print_name(out, "G",g); do_bn_print_name(out, "X",X); do_bn_print_name(out, "Y",Y); if (!paramcheck) { if (dss_paramcheck(L, N, p, q, g, ctx)) paramcheck = 1; else paramcheck = -1; } if (paramcheck != 1) fprintf(out, "Result = F\n"); else { if (!BN_mod_exp(Y2, g, X, p, ctx) || BN_cmp(Y2, Y)) fprintf(out, "Result = F\n"); else fprintf(out, "Result = P\n"); } BN_free(X); BN_free(Y); X = NULL; Y = NULL; } } if (p) BN_free(p); if (q) BN_free(q); if (g) BN_free(g); if (Y2) BN_free(Y2); }
static void pqgver(FILE *in, FILE *out) { char buf[1024]; char lbuf[1024]; char *keyword, *value; BIGNUM *p = NULL, *q = NULL, *g = NULL; int counter=-1, counter2; unsigned long h=0, h2; DSA *dsa=NULL; int dsa2, L, N, part_test = 0; const EVP_MD *md = NULL; int seedlen=-1; unsigned char seed[1024]; while(fgets(buf,sizeof buf,in) != NULL) { if (!parse_line(&keyword, &value, lbuf, buf)) { if (p && q) { part_test = 1; goto partial; } fputs(buf,out); continue; } fputs(buf, out); if(!strcmp(keyword,"[mod")) { if (!parse_mod(value, &dsa2, &L, &N, &md)) { fprintf(stderr, "Mod Parse Error\n"); exit (1); } } else if(!strcmp(keyword,"P")) p=hex2bn(value); else if(!strcmp(keyword,"Q")) q=hex2bn(value); else if(!strcmp(keyword,"G")) g=hex2bn(value); else if(!strcmp(keyword,"Seed")) { seedlen = hex2bin(value, seed); if (!dsa2 && seedlen != 20) { fprintf(stderr, "Seed parse length error\n"); exit (1); } } else if(!strcmp(keyword,"c")) counter =atoi(buf+4); partial: if(!strcmp(keyword,"H") || part_test) { if (!part_test) h = atoi(value); if (!p || !q || (!g && !part_test)) { fprintf(stderr, "Parse Error\n"); exit (1); } dsa = FIPS_dsa_new(); if (!dsa2 && !dsa_builtin_paramgen(dsa, L, N, md, seed, seedlen, NULL, &counter2, &h2, NULL)) { fprintf(stderr, "Parameter Generation error\n"); exit(1); } if (dsa2 && dsa_builtin_paramgen2(dsa, L, N, md, seed, seedlen, NULL, &counter2, &h2, NULL) < 0) { fprintf(stderr, "Parameter Generation error\n"); exit(1); } if (BN_cmp(dsa->p, p) || BN_cmp(dsa->q, q) || (!part_test && ((BN_cmp(dsa->g, g) || (counter != counter2) || (h != h2))))) fprintf(out, "Result = F\n"); else fprintf(out, "Result = P\n"); BN_free(p); BN_free(q); BN_free(g); p = NULL; q = NULL; g = NULL; FIPS_dsa_free(dsa); dsa = NULL; if (part_test) { fputs(buf,out); part_test = 0; } } } }
static void pqg(FILE *in, FILE *out) { char buf[1024]; char lbuf[1024]; char *keyword, *value; int dsa2, L, N; const EVP_MD *md = NULL; while(fgets(buf,sizeof buf,in) != NULL) { if (!parse_line(&keyword, &value, lbuf, buf)) { fputs(buf,out); continue; } if(!strcmp(keyword,"[mod")) { fputs(buf,out); if (!parse_mod(value, &dsa2, &L, &N, &md)) { fprintf(stderr, "Mod Parse Error\n"); exit (1); } } else if(!strcmp(keyword,"N")) { int n=atoi(value); while(n--) { unsigned char seed[EVP_MAX_MD_SIZE]; DSA *dsa; int counter; unsigned long h; dsa = FIPS_dsa_new(); if (!dsa2 && !dsa_builtin_paramgen(dsa, L, N, md, NULL, 0, seed, &counter, &h, NULL)) { fprintf(stderr, "Parameter Generation error\n"); exit(1); } if (dsa2 && dsa_builtin_paramgen2(dsa, L, N, md, NULL, 0, seed, &counter, &h, NULL) <= 0) { fprintf(stderr, "Parameter Generation error\n"); exit(1); } do_bn_print_name(out, "P",dsa->p); do_bn_print_name(out, "Q",dsa->q); do_bn_print_name(out, "G",dsa->g); OutputValue("Seed",seed, M_EVP_MD_size(md), out, 0); fprintf(out, "c = %d\n",counter); fprintf(out, "H = %lx\n\n",h); } } else fputs(buf,out); } }
/* parse every config line */ static int parse_line(char *buff) { char *token; int i; if ((token = strtok(buff, W_SPACE)) == NULL) { /* ignore empty lines */ (void) 0; } else if (token[0] == '#') { /* ignore comment lines */ (void) 0; } else if (strstr(token, "mod_")) { parse_mod(token); } else if (strstr(token, "spec_")) { special_mod(token); } else if (!strcmp(token, "output_interface")) { parse_string(conf.output_interface); } else if (!strcmp(token, "output_file_path")) { parse_string(conf.output_file_path); } else if (!strcmp(token, "output_db_addr")) { parse_string(conf.output_db_addr); } else if (!strcmp(token, "output_db_mod")) { parse_add_string(conf.output_db_mod); } else if (!strcmp(token, "output_tcp_mod")) { parse_add_string(conf.output_tcp_mod); } else if (!strcmp(token, "output_tcp_addr")) { for(i = 0; i < MAX_TCP_ADDR_NUM; i++){ parse_string(conf.output_tcp_addr[i]); if(conf.output_tcp_addr[i][0] != 0){ conf.output_tcp_addr_num++; } else { break; } } } else if (!strcmp(token, "output_tcp_merge")) { parse_string(conf.output_tcp_merge); } else if (!strcmp(token, "output_nagios_mod")) { parse_add_string(conf.output_nagios_mod); } else if (!strcmp(token, "output_stdio_mod")) { parse_add_string(conf.output_stdio_mod); } else if (!strcmp(token, "debug_level")) { set_debug_level(); } else if (!strcmp(token, "include")) { get_include_conf(); } else if (!strcmp(token, "server_addr")) { parse_string(conf.server_addr); } else if (!strcmp(token, "server_port")) { parse_int(&conf.server_port); } else if (!strcmp(token, "cycle_time")) { parse_int(&conf.cycle_time); } else if (!strcmp(token, "max_day")) { parse_int(&conf.print_max_day); } else if (!strcmp(token, "send_nsca_cmd")) { parse_string(conf.send_nsca_cmd); } else if (!strcmp(token, "send_nsca_conf")) { parse_string(conf.send_nsca_conf); } else if (!strcmp(token, "threshold")) { get_threshold(); } else { return 0; } return 1; }
static void sigver(FILE *in, FILE *out) { DSA *dsa=NULL; char buf[1024]; char lbuf[1024]; unsigned char msg[1024]; char *keyword, *value; int n=0; int dsa2, L, N; const EVP_MD *md = NULL; DSA_SIG sg, *sig = &sg; sig->r = NULL; sig->s = NULL; while(fgets(buf,sizeof buf,in) != NULL) { if (!parse_line(&keyword, &value, lbuf, buf)) { fputs(buf,out); continue; } fputs(buf,out); if(!strcmp(keyword,"[mod")) { if (!parse_mod(value, &dsa2, &L, &N, &md)) { fprintf(stderr, "Mod Parse Error\n"); exit (1); } if (dsa) FIPS_dsa_free(dsa); dsa = FIPS_dsa_new(); } else if(!strcmp(keyword,"P")) do_hex2bn(&dsa->p, value); else if(!strcmp(keyword,"Q")) do_hex2bn(&dsa->q, value); else if(!strcmp(keyword,"G")) do_hex2bn(&dsa->g, value); else if(!strcmp(keyword,"Msg")) n=hex2bin(value,msg); else if(!strcmp(keyword,"Y")) do_hex2bn(&dsa->pub_key, value); else if(!strcmp(keyword,"R")) sig->r=hex2bn(value); else if(!strcmp(keyword,"S")) { int r; sig->s=hex2bn(value); no_err = 1; r = FIPS_dsa_verify(dsa, msg, n, md, sig); no_err = 0; if (sig->s) { BN_free(sig->s); sig->s = NULL; } if (sig->r) { BN_free(sig->r); sig->r = NULL; } fprintf(out, "Result = %c" RESP_EOL RESP_EOL, r == 1 ? 'P' : 'F'); } } if (dsa) FIPS_dsa_free(dsa); }
static void pqgver(FILE *in, FILE *out) { char buf[1024]; char lbuf[1024]; char *keyword, *value; BIGNUM *p = NULL, *q = NULL, *g = NULL; int counter=-1, counter2; unsigned long h=0, h2; DSA *dsa=NULL; int dsa2, L, N, part_test = 0; const EVP_MD *md = NULL; int seedlen=-1, idxlen, idx = -1; unsigned char seed[1024], idtmp[1024]; while(fgets(buf,sizeof buf,in) != NULL) { if (!parse_line(&keyword, &value, lbuf, buf)) { if (p && q) { part_test = 1; goto partial; } fputs(buf,out); continue; } fputs(buf, out); if(!strcmp(keyword,"[mod")) { if (!parse_mod(value, &dsa2, &L, &N, &md)) { fprintf(stderr, "Mod Parse Error\n"); exit (1); } } else if(!strcmp(keyword,"P")) p=hex2bn(value); else if(!strcmp(keyword,"Q")) q=hex2bn(value); else if(!strcmp(keyword,"G")) g=hex2bn(value); else if(!strcmp(keyword,"firstseed")) seedlen = hex2bin(value, seed); else if(!strcmp(keyword,"pseed")) seedlen += hex2bin(value, seed + seedlen); else if(!strcmp(keyword,"qseed")) seedlen += hex2bin(value, seed + seedlen); else if(!strcmp(keyword,"Seed") || !strcmp(keyword,"domain_parameter_seed")) { seedlen = hex2bin(value, seed); if (!dsa2 && seedlen != 20) { fprintf(stderr, "Seed parse length error\n"); exit (1); } if (idx > 0) part_test = 1; } else if(!strcmp(keyword,"index")) { idxlen = hex2bin(value, idtmp); if (idxlen != 1) { fprintf(stderr, "Index value error\n"); exit (1); } idx = idtmp[0]; } else if(!strcmp(keyword,"c")) counter = atoi(buf+4); partial: if (part_test && idx < 0 && h == 0 && g) { dsa = FIPS_dsa_new(); dsa->p = BN_dup(p); dsa->q = BN_dup(q); dsa->g = BN_dup(g); if (dsa_paramgen_check_g(dsa)) fprintf(out, "Result = P" RESP_EOL); else fprintf(out, "Result = F" RESP_EOL); BN_free(p); BN_free(q); BN_free(g); p = NULL; q = NULL; g = NULL; FIPS_dsa_free(dsa); dsa = NULL; part_test = 0; } else if(!strcmp(keyword,"H") || part_test) { if (!part_test) h = atoi(value); if (!p || !q || (!g && !part_test)) { fprintf(stderr, "Parse Error\n"); exit (1); } dsa = FIPS_dsa_new(); if (idx >= 0) { dsa->p = BN_dup(p); dsa->q = BN_dup(q); } no_err = 1; if (!dsa2 && !dsa_builtin_paramgen(dsa, L, N, md, seed, seedlen, NULL, &counter2, &h2, NULL)) { fprintf(stderr, "Parameter Generation error\n"); exit(1); } if (dsa2 && dsa_builtin_paramgen2(dsa, L, N, md, seed, seedlen, idx, NULL, &counter2, &h2, NULL) < 0) { fprintf(stderr, "Parameter Generation error\n"); exit(1); } no_err = 0; if (idx >= 0) { if (BN_cmp(dsa->g, g)) fprintf(out, "Result = F" RESP_EOL); else fprintf(out, "Result = P" RESP_EOL); } else if (BN_cmp(dsa->p, p) || BN_cmp(dsa->q, q) || (!part_test && ((BN_cmp(dsa->g, g) || (counter != counter2) || (h != h2))))) fprintf(out, "Result = F" RESP_EOL); else fprintf(out, "Result = P" RESP_EOL); BN_free(p); BN_free(q); BN_free(g); p = NULL; q = NULL; g = NULL; FIPS_dsa_free(dsa); dsa = NULL; if (part_test) { if (idx == -1) fputs(buf,out); part_test = 0; } idx = -1; } } }
static void pqg(FILE *in, FILE *out) { char buf[1024]; char lbuf[1024]; char *keyword, *value; int dsa2, L, N; const EVP_MD *md = NULL; BIGNUM *p = NULL, *q = NULL; enum pqtype { PQG_NONE, PQG_PQ, PQG_G, PQG_GCANON} pqg_type = PQG_NONE; int seedlen=-1, idxlen, idx = -1; unsigned char seed[1024], idtmp[1024]; while(fgets(buf,sizeof buf,in) != NULL) { if (buf[0] == '[') { if (strstr(buf, "Probable")) pqg_type = PQG_PQ; else if (strstr(buf, "Unverifiable")) pqg_type = PQG_G; else if (strstr(buf, "Canonical")) pqg_type = PQG_GCANON; } if (!parse_line(&keyword, &value, lbuf, buf)) { fputs(buf,out); continue; } if (strcmp(keyword, "Num")) fputs(buf,out); if(!strcmp(keyword,"[mod")) { if (!parse_mod(value, &dsa2, &L, &N, &md)) { fprintf(stderr, "Mod Parse Error\n"); exit (1); } } else if(!strcmp(keyword,"N") || (!strcmp(keyword, "Num") && pqg_type == PQG_PQ)) { int n=atoi(value); while(n--) { DSA *dsa; int counter; unsigned long h; dsa = FIPS_dsa_new(); if (!dsa2 && !dsa_builtin_paramgen(dsa, L, N, md, NULL, 0, seed, &counter, &h, NULL)) { fprintf(stderr, "Parameter Generation error\n"); exit(1); } if (dsa2 && dsa_builtin_paramgen2(dsa, L, N, md, NULL, 0, -1, seed, &counter, &h, NULL) <= 0) { fprintf(stderr, "Parameter Generation error\n"); exit(1); } do_bn_print_name(out, "P",dsa->p); do_bn_print_name(out, "Q",dsa->q); if (!dsa2) do_bn_print_name(out, "G",dsa->g); OutputValue(dsa2 ? "domain_parameter_seed" : "Seed", seed, M_EVP_MD_size(md), out, 0); if (!dsa2) { fprintf(out, "c = %d" RESP_EOL, counter); fprintf(out, "H = %lx" RESP_EOL RESP_EOL,h); } else { fprintf(out, "counter = %d" RESP_EOL RESP_EOL, counter); } FIPS_dsa_free(dsa); } } else if(!strcmp(keyword,"P")) p=hex2bn(value); else if(!strcmp(keyword,"Q")) q=hex2bn(value); else if(!strcmp(keyword,"domain_parameter_seed")) seedlen = hex2bin(value, seed); else if(!strcmp(keyword,"firstseed")) seedlen = hex2bin(value, seed); else if(!strcmp(keyword,"pseed")) seedlen += hex2bin(value, seed + seedlen); else if(!strcmp(keyword,"qseed")) seedlen += hex2bin(value, seed + seedlen); else if(!strcmp(keyword,"index")) { idxlen = hex2bin(value, idtmp); if (idxlen != 1) { fprintf(stderr, "Index value error\n"); exit (1); } idx = idtmp[0]; } if ((idx >= 0 && pqg_type == PQG_GCANON) || (q && pqg_type == PQG_G)) { DSA *dsa; dsa = FIPS_dsa_new(); dsa->p = p; dsa->q = q; p = q = NULL; if (dsa_builtin_paramgen2(dsa, L, N, md, seed, seedlen, idx, NULL, NULL, NULL, NULL) <= 0) { fprintf(stderr, "Parameter Generation error\n"); exit(1); } do_bn_print_name(out, "G",dsa->g); FIPS_dsa_free(dsa); idx = -1; } } }
void read_value(char *name, char *value) { //The *name and *value are derived from sargv which is given one by one through //a loop from conf_init() if (name != NULL && value != NULL) { if (name[0] == '#') return; g_strstrip(name); g_strstrip(value); if (!strcmp("font", name) || !strcmp("-fn", name)) strcpy(_font, value); else if (!strcmp("background", name) || !strcmp("-bg", name)) { if (!parse_hex_color(value, &_bg)) gdk_color_parse("black", &_bg); } else if (!strcmp("foreground", name) || !strcmp("-fg", name)) { if (!parse_hex_color(value, &_fg)) gdk_color_parse("white", &_fg); } else if (!strcmp("scrollbar", name) || !strcmp("-s", name)) { if (!strcmp(value, "true")) _scrollpos = POS_RIGHT; else if (!strcmp(value, "left")) _scrollpos = POS_LEFT; else if (!strcmp(value, "right")) _scrollpos = POS_RIGHT; else _scrollpos = -1; } else if (!strcmp("border", name) || !strcmp("-b", name)) set_border(value); else if (!strcmp("opacity", name) || !strcmp("-o", name)) _opacity = atof(value); else if (!strcmp("bgimage", name) || !strcmp("-bgimg", name)) strcpy(_bgimage, value); else if (!strcmp("width", name) || !strcmp("-w", name)) _width = atoi(value); else if (!strcmp("height", name) || !strcmp("-h", name)) _height = atoi(value); else if (!strcmp("position", name) || !strcmp("-p", name)) set_pos(value); else if (!strcmp("mod", name) || !strcmp("-m", name)) set_mod(value); else if (!strcmp("key", name) || !strcmp("-k", name)) set_key(value); else if (!strcmp("shell", name) || !strcmp("-sh", name)) strcpy(_shell, value); else if (!strcmp("lines", name) || !strcmp("-l", name)) _lines = atoi(value); else if (!strcmp("showtab", name) || !strcmp("-showtab", name)) { if (!strcasecmp(value, "always")) _showtab = TABS_ALWAYS; else if (!strcasecmp(value, "never")) _showtab = TABS_NEVER; } else if (!strcmp("tabpos", name) || !strcmp("-tabpos", name)) _tabpos = read_pos(value); else if (!strcmp("tablabel", name) || !strcmp("-tablabel", name)) strcpy(_termname, value); else if (!strcmp("cursorblink", name) || !strcmp("-cb", name)) set_cursor_blink(value); else if (!strcmp("cursorshape", name) || !strcmp("-cs", name)) set_cursor_shape(value); else if (g_str_has_prefix(name, "color") || g_str_has_prefix(name, "-c")) { g_strcanon(name, "0123456789", ' '); g_strchug(name); parse_hex_color(value, &_palette[atoi(name)]); read_colors++; } else if (!strcmp("tabfill", name) || !strcmp("-tf", name)) _tabfill = parse_bool_str(value, _tabfill); else if (!strcmp("allowbold", name) || !strcmp("-ab", name)) _allowbold = parse_bool_str(value, _allowbold); else if (!strcmp("keymod", name) || !strcmp("-km", name)) { char **list; list = g_strsplit_set(value, "+", -1); GdkModifierType tmp = 0; int i = 0; while (list[i] != NULL) tmp = tmp | parse_mod(list[i++]); g_strfreev(list); if (tmp != 0) _keymod = tmp; } else if (!strcmp("autohide", name) || !strcmp("-ah", name)) _autohide = parse_bool_str(value, _autohide); else if (!strcmp("scroll", name) || !strcmp("-sc", name)) _scrolloutput = parse_bool_str(value, _scrolloutput); else if (!strcmp("bell", name) || !strcmp("-bell", name)) if (!strcasecmp(value, "false")) _bell = FALSE; } }
/* parse every config line */ static int parse_line(char *buff) { char *token; if ((token = strtok(buff, W_SPACE)) == NULL) { /* ignore empty lines */ (void) 0; } else if (strstr(token, "mod_")) { parse_mod(token); } else if (strstr(token, "spec_")) { special_mod(token); } else if (!strcmp(token, "output_interface")) { parse_string(conf.output_interface); } else if (!strcmp(token, "output_file_path")) { parse_string(conf.output_file_path); } else if (!strcmp(token, "output_db_addr")) { parse_string(conf.output_db_addr); } else if (!strcmp(token, "output_db_mod")) { parse_add_string(conf.output_db_mod); } else if (!strcmp(token, "output_nagios_mod")) { parse_add_string(conf.output_nagios_mod); } else if (!strcmp(token, "output_stdio_mod")) { parse_add_string(conf.output_stdio_mod); } else if (!strcmp(token, "debug_level")) { set_debug_level(); } else if (!strcmp(token, "include")) { get_include_conf(); } else if (!strcmp(token, "server_addr")) { parse_string(conf.server_addr); } else if (!strcmp(token, "server_port")) { parse_int(conf.server_port); } else if (!strcmp(token, "cycle_time")) { parse_int(conf.cycle_time); } else if (!strcmp(token, "send_nsca_cmd")) { parse_string(conf.send_nsca_cmd); } else if (!strcmp(token, "send_nsca_conf")) { parse_string(conf.send_nsca_conf); } else if (!strcmp(token, "threshold")) { get_threshold(); } else { return 0; } return 1; }