/** get old RR entry from Dns Server */ DnsRR* DNSUpdate::get_oldDnsRR(){ DnsRR* RemoteDnsRR= NULL; DnsMessage *q = NULL, *a = NULL; int sockid = -1; try { q = create_query(*zoneroot, QTYPE_AXFR); pos_cliresolver res; sockid = res.tcpconnect(&server); res.tcpsendmessage(q, sockid); res.tcpwaitanswer(a, sockid); if (a->RCODE != RCODE_NOERROR){ throw PException((char*)str_rcode(a->RCODE).c_str()); } if (!a->answers.empty()) { RemoteDnsRR = new DnsRR(); if (this->DnsRR_avail(a,*RemoteDnsRR) == false) { delete RemoteDnsRR; RemoteDnsRR = NULL; } } if (a) { // delete a; // FIXME: Why is this commented out? Memory leak! a = 0; } if (q) { delete q; q = 0; } if (sockid != -1) tcpclose(sockid); return RemoteDnsRR; } catch (PException p) { if (q) { delete q; q = NULL; } if (a) { delete a; a = NULL; } if (sockid != -1) tcpclose(sockid); if (RemoteDnsRR) delete RemoteDnsRR; Log(Error) << "DDNS: Attempt to get old DNS record failed." << LogEnd; return 0; } }
static int query_command(const char *data, char *digest, const EVP_MD *md, const char *policy, int no_nonce, int cert, const char *in, const char *out, int text) { int ret = 0; TS_REQ *query = NULL; BIO *in_bio = NULL; BIO *data_bio = NULL; BIO *out_bio = NULL; /* Build query object either from file or from scratch. */ if (in != NULL) { if ((in_bio = BIO_new_file(in, "rb")) == NULL) goto end; query = d2i_TS_REQ_bio(in_bio, NULL); } else { /* Open the file if no explicit digest bytes were specified. */ if (!digest && !(data_bio = BIO_open_with_default(data, "rb", stdin))) goto end; /* Creating the query object. */ query = create_query(data_bio, digest, md, policy, no_nonce, cert); /* Saving the random number generator state. */ } if (query == NULL) goto end; /* Write query either in ASN.1 or in text format. */ if ((out_bio = BIO_open_with_default(out, "wb", stdout)) == NULL) goto end; if (text) { /* Text output. */ if (!TS_REQ_print_bio(out_bio, query)) goto end; } else { /* ASN.1 output. */ if (!i2d_TS_REQ_bio(out_bio, query)) goto end; } ret = 1; end: ERR_print_errors(bio_err); /* Clean up. */ BIO_free_all(in_bio); BIO_free_all(data_bio); BIO_free_all(out_bio); TS_REQ_free(query); return ret; }
int main (int argc, char *argv[]) { struct queryopt opt; struct ofields *fields; struct select_doc *s_doc; struct query_doc *qu_doc; struct db_connect *db_conn; struct output *out; struct db_cursor *db_c; struct results *res; opt.e_skip = 0; // standard opt.e_ret = 0; // standard opt.bsever = 0; opt.blevel = 0; opt.bdate = 0; opt.bdateu = 0; opt.bdatef = 0; opt.bmsg = 0; opt.bskip = 0; opt.bsys = 0; getoptions(argc, argv, &opt); qu_doc = create_query(&opt); // crate query s_doc = create_select(); db_conn = create_conn(); // create connection out = launch_query(&opt, s_doc, qu_doc, db_conn); // launch the query db_c = open_cursor(db_conn, out); // open cursor while (cursor_next(db_c)) { res = read_data(db_c); fields = get_data(res); formater(fields); // formate output free(fields); free(res); } free_cursor(db_c); close_conn(db_conn); free(out); free(s_doc); free(qu_doc); return (0); }
/* * Query-related method definitions. */ static int query_command(const char *data, char *digest, const EVP_MD *md, const char *policy, int no_nonce, int cert, const char *in, const char *out, int text) { int ret = 0; TS_REQ *query = NULL; BIO *in_bio = NULL; BIO *data_bio = NULL; BIO *out_bio = NULL; /* Build query object. */ if (in != NULL) { if ((in_bio = bio_open_default(in, 'r', FORMAT_ASN1)) == NULL) goto end; query = d2i_TS_REQ_bio(in_bio, NULL); } else { if (digest == NULL && (data_bio = bio_open_default(data, 'r', FORMAT_ASN1)) == NULL) goto end; query = create_query(data_bio, digest, md, policy, no_nonce, cert); } if (query == NULL) goto end; if (text) { if ((out_bio = bio_open_default(out, 'w', FORMAT_TEXT)) == NULL) goto end; if (!TS_REQ_print_bio(out_bio, query)) goto end; } else { if ((out_bio = bio_open_default(out, 'w', FORMAT_ASN1)) == NULL) goto end; if (!i2d_TS_REQ_bio(out_bio, query)) goto end; } ret = 1; end: ERR_print_errors(bio_err); BIO_free_all(in_bio); BIO_free_all(data_bio); BIO_free_all(out_bio); TS_REQ_free(query); return ret; }
/* * Function: parse_options() * * Description: * This function parse the options * * Argument: * argc: the number of argument * argv: arguments * info_p: pointer to data of querier information * bg_p: pointer to the flag of working in backgrond * * Return value: * None */ void parse_options(int argc, char *argv[], struct igmp_info *info_p, int *bg_p) { int optc; /* option */ unsigned long opt_ul; /* option value in unsigned long */ double opt_d; /* option value in double */ uint8_t max_resp; /* Max Resp Code */ char *maddr; /* multicast address */ char *saddrs; /* comma separated array of source addresses */ max_resp = IGMP_MAX_HOST_REPORT_DELAY; maddr = NULL; saddrs = NULL; while ((optc = getopt(argc, argv, "I:m:s:r:t:i:obdh")) != EOF) { switch (optc) { case 'I': info_p->ifindex = if_nametoindex(optarg); if (info_p->ifindex == 0) { fprintf(stderr, "specified interface is incorrect\n"); usage(program_name, EXIT_FAILURE); } break; case 'm': maddr = strdup(optarg); if (maddr == NULL) fatal_error("strdup()"); break; case 's': saddrs = strdup(optarg); if (saddrs == NULL) fatal_error("strdup()"); break; case 'r': opt_ul=strtoul(optarg, NULL, 0); if (opt_ul > 255) { fprintf(stderr, "Max Resp Code should be less then 256\n"); usage(program_name, EXIT_FAILURE); } max_resp = opt_ul; break; case 't': opt_d = strtod(optarg, NULL); if (opt_d < 0.0) { fprintf(stderr, "Timeout should be positive value\n"); usage(program_name, EXIT_FAILURE); } info_p->timeout = opt_d; break; case 'i': if (strtotimespec(optarg, &info_p->interval)) { fprintf(stderr, "Interval is something wrong\n"); usage(program_name, EXIT_FAILURE); } break; case 'o': info_p->timeout = -1.0; break; case 'b': *bg_p = 1; break; case 'd': debug = 1; break; case 'h': usage(program_name, EXIT_SUCCESS); break; default: usage(program_name, EXIT_FAILURE); } } if (info_p->ifindex == 0) { fprintf(stderr, "specified interface seems incorrect\n"); usage(program_name, EXIT_FAILURE); } if ((info_p->query = create_query(max_resp, maddr, saddrs)) == NULL) usage(program_name, EXIT_FAILURE); if (maddr) free(maddr); if (saddrs) free(saddrs); }