static int init_finish(adns_state ads) { struct in_addr ia; struct protoent *proto; int r; if (!ads->nservers) { if (ads->diagfile && ads->iflags & adns_if_debug) fprintf(ads->diagfile,"adns: no nameservers, using localhost\n"); ia.s_addr= htonl(INADDR_LOOPBACK); addserver(ads,ia); } proto= getprotobyname("udp"); if (!proto) { r= ENOPROTOOPT; goto x_free; } ads->udpsocket= socket(AF_INET,SOCK_DGRAM,proto->p_proto); if (ads->udpsocket<0) { r= errno; goto x_free; } r= adns__setnonblock(ads,ads->udpsocket); if (r) { r= errno; goto x_closeudp; } return 0; x_closeudp: close(ads->udpsocket); x_free: free(ads); return r; }
static int init_finish(adns_state ads) { struct in_addr ia; int r; if (!ads->nservers) { #if 0 if (ads->diagfile && ads->iflags & adns_if_debug) fprintf(ads->diagfile,"adns: no nameservers, using localhost\n"); #endif ia.s_addr= htonl(INADDR_LOOPBACK); addserver(ads,ia); } ads->udpsocket = comm_open(AF_INET, SOCK_DGRAM, 0, "UDP Resolver socket"); if (ads->udpsocket<0) { ilog(L_CRIT, "Failed to open socket"); r= errno; goto x_free; } r= adns__setnonblock(ads,ads->udpsocket); if (r) { ilog(L_CRIT, "Failed to make socket non-blocking"); r= errno; goto x_closeudp; } return 0; x_closeudp: fd_close(ads->udpsocket); x_free: MyFree(ads); ilog(L_CRIT, "Returning from init_finish: r = %d", r); return r; }
static void ccf_nameserver(adns_state ads, const char *fn, int lno, const char *buf) { struct in_addr ia; if (!inet_aton(buf,&ia)) { configparseerr(ads,fn,lno,"invalid nameserver address `%s'",buf); return; } adns__debug(ads,-1,0,"using nameserver %s",inet_ntoa(ia)); addserver(ads,ia); }
int adns__rereadconfig(adns_state ads) { struct in_addr ia; adns__consistency(ads,0,cc_entex); ads->nservers = 0; readconfig(ads,"/etc/resolv.conf",0); if (!ads->nservers) { ia.s_addr= htonl(INADDR_LOOPBACK); addserver(ads,ia); } adns__consistency(ads,0,cc_entex); return 0; }
void connectserv(const char *name, int port, const char *password) { abortconnect(); if(!port) port = ENG_SERVER_PORT; ENetAddress address; address.port = port; setsvar("serveraddress", ""); setvar("serverconport", 0); if(name && *name) { addserver(name, port); conoutft(CON_MESG, "\faattempting to connect to %s:[%d]", name, port); if(!resolverwait(name, &address)) { conoutft(CON_MESG, "\frcould not resolve host %s", name); connectfail(); return; } setsvar("serveraddress", name); setvar("serverconport", port); } else { conoutft(CON_MESG, "\faattempting to connect to a local server"); address.host = ENET_HOST_BROADCAST; } if(!clienthost) clienthost = enet_host_create(NULL, 2, server::numchannels(), rate, rate); if(clienthost) { connpeer = enet_host_connect(clienthost, &address, server::numchannels(), 0); enet_host_flush(clienthost); connmillis = totalmillis; connattempts = 0; client::connectattempt(name ? name : "", port, password ? password : "", address); conoutft(CON_MESG, "\fgconnecting to %s:[%d]", name != NULL ? name : "local server", port); } else { conoutft(CON_MESG, "\frfailed creating client socket"); connectfail(); } }
void connectserv(const char *servername, int serverport, const char *serverpassword) { if(connpeer) { conoutf("aborting connection attempt"); abortconnect(); } if(serverport <= 0) serverport = server::serverport(); ENetAddress address; address.port = serverport; if(servername) { if(strcmp(servername, GETSV(connectname))) SETVF(connectname, servername); if(serverport != GETIV(connectport)) SETVF(connectport, serverport); addserver(servername, serverport, serverpassword && serverpassword[0] ? serverpassword : NULL); // INTENSITY: Remove? conoutf("attempting to connect to %s:%d", servername, serverport); if(!resolverwait(servername, &address)) { conoutf("\f3could not resolve server %s", servername); return; } } else { SETVF(connectname, ""); SETVF(connectport, 0); conoutf("attempting to connect over LAN"); address.host = ENET_HOST_BROADCAST; } if(!clienthost) clienthost = enet_host_create(NULL, 2, server::numchannels(), GETIV(rate), GETIV(rate)); if(clienthost) { connpeer = enet_host_connect(clienthost, &address, server::numchannels(), 0); enet_host_flush(clienthost); connmillis = totalmillis; connattempts = 0; game::connectattempt(servername ? servername : "", serverpassword ? serverpassword : "", address); } else conoutf("\f3could not connect to server"); }
int adns__rereadconfig(adns_state ads) { struct in_addr ia; adns__consistency(ads,0,cc_entex); ads->nservers = 0; ads->servers[0].addr.s_addr = 0; #ifndef VMS readconfig(ads,"/etc/resolv.conf",1); readconfig(ads,"/etc/resolv-adns.conf",0); #else readconfig(ads,"[]resolv.conf",0); #endif if (!ads->nservers) { ia.s_addr= htonl(INADDR_LOOPBACK); addserver(ads,ia); } adns__consistency(ads,0,cc_entex); return 0; }
int adns_init(adns_state *ads_r, adns_initflags flags, FILE *diagfile) { adns_state ads; const char *res_options, *adns_res_options; int r; #ifdef ADNS_JGAA_WIN32 #define SECURE_PATH_LEN (MAX_PATH - 64) char PathBuf[MAX_PATH]; struct in_addr addr; #define ADNS_PFIXED_INFO_BLEN (2048) PFIXED_INFO network_info = (PFIXED_INFO)alloca(ADNS_PFIXED_INFO_BLEN); ULONG network_info_blen = ADNS_PFIXED_INFO_BLEN; DWORD network_info_result; PIP_ADDR_STRING pip; const char *network_err_str = ""; #endif r= init_begin(&ads, flags, diagfile ? diagfile : stderr); if (r) return r; res_options= instrum_getenv(ads,"RES_OPTIONS"); adns_res_options= instrum_getenv(ads,"ADNS_RES_OPTIONS"); ccf_options(ads,"RES_OPTIONS",-1,res_options); ccf_options(ads,"ADNS_RES_OPTIONS",-1,adns_res_options); #ifdef ADNS_JGAA_WIN32 GetWindowsDirectory(PathBuf, SECURE_PATH_LEN); strcat(PathBuf,"\\resolv.conf"); readconfig(ads,PathBuf,1); GetWindowsDirectory(PathBuf, SECURE_PATH_LEN); strcat(PathBuf,"\\resolv-adns.conf"); readconfig(ads,PathBuf,0); GetWindowsDirectory(PathBuf, SECURE_PATH_LEN); strcat(PathBuf,"\\System32\\Drivers\\etc\\resolv.conf"); readconfig(ads,PathBuf,1); GetWindowsDirectory(PathBuf, SECURE_PATH_LEN); strcat(PathBuf,"\\System32\\Drivers\\etc\\resolv-adns.conf"); readconfig(ads,PathBuf,0); network_info_result = GetNetworkParams(network_info, &network_info_blen); if (network_info_result != ERROR_SUCCESS){ switch(network_info_result) { case ERROR_BUFFER_OVERFLOW: network_err_str = "ERROR_BUFFER_OVERFLOW"; break; case ERROR_INVALID_PARAMETER: network_err_str = "ERROR_INVALID_PARAMETER"; break; case ERROR_NO_DATA: network_err_str = "ERROR_NO_DATA"; break; case ERROR_NOT_SUPPORTED: network_err_str = "ERROR_NOT_SUPPORTED"; break;} adns__diag(ads,-1,0,"GetNetworkParams() failed with error [%d] %s", network_info_result,network_err_str); } else { for(pip = &(network_info->DnsServerList); pip; pip = pip->Next) { addr.s_addr = inet_addr(pip->IpAddress.String); if ((addr.s_addr != INADDR_ANY) && (addr.s_addr != INADDR_NONE)) addserver(ads, addr); } } #else readconfig(ads,"/etc/resolv.conf",1); readconfig(ads,"/etc/resolv-adns.conf",0); #endif readconfigenv(ads,"RES_CONF"); readconfigenv(ads,"ADNS_RES_CONF"); readconfigenvtext(ads,"RES_CONF_TEXT"); readconfigenvtext(ads,"ADNS_RES_CONF_TEXT"); ccf_options(ads,"RES_OPTIONS",-1,res_options); ccf_options(ads,"ADNS_RES_OPTIONS",-1,adns_res_options); ccf_search(ads,"LOCALDOMAIN",-1,instrum_getenv(ads,"LOCALDOMAIN")); ccf_search(ads,"ADNS_LOCALDOMAIN",-1,instrum_getenv(ads,"ADNS_LOCALDOMAIN")); if (ads->configerrno && ads->configerrno != EINVAL) { r= ads->configerrno; init_abort(ads); return r; } r= init_finish(ads); if (r) return r; adns__consistency(ads,0,cc_entex); *ads_r= ads; return 0; }
int main(int argc, char *argv[]) { int ch; dns_client_t *client = NULL; char *zonenamestr = NULL; char *keyfilename = NULL; char *prereqstr = NULL; isc_sockaddr_t sa_auth[10], sa_recursive[10]; unsigned int nsa_auth = 0, nsa_recursive = 0; isc_sockaddrlist_t rec_servers; isc_sockaddrlist_t auth_servers; isc_result_t result; isc_boolean_t isdelete; isc_buffer_t b, *buf; dns_fixedname_t zname0, pname0, uname0; unsigned int namelen; dns_name_t *zname = NULL, *uname, *pname; dns_rdataset_t *rdataset; dns_rdatalist_t *rdatalist; dns_rdata_t *rdata; dns_namelist_t updatelist, prereqlist, *prereqlistp = NULL; isc_mem_t *umctx = NULL; ISC_LIST_INIT(auth_servers); ISC_LIST_INIT(rec_servers); while ((ch = isc_commandline_parse(argc, argv, "a:k:p:P:r:z:")) != EOF) { switch (ch) { case 'k': keyfilename = isc_commandline_argument; break; case 'a': if (nsa_auth < sizeof(sa_auth)/sizeof(*sa_auth) && addserver(isc_commandline_argument, &auth_servers, &sa_auth[nsa_auth])) nsa_auth++; break; case 'p': prereqstr = isc_commandline_argument; break; case 'P': port = isc_commandline_argument; break; case 'r': if (nsa_recursive < sizeof(sa_recursive)/sizeof(*sa_recursive) && addserver(isc_commandline_argument, &rec_servers, &sa_recursive[nsa_recursive])) nsa_recursive++; break; case 'z': zonenamestr = isc_commandline_argument; break; default: usage(); } } argc -= isc_commandline_index; argv += isc_commandline_index; if (argc < 2) usage(); /* command line argument validation */ if (strcmp(argv[0], "delete") == 0) isdelete = ISC_TRUE; else if (strcmp(argv[0], "add") == 0) isdelete = ISC_FALSE; else { fprintf(stderr, "invalid update command: %s\n", argv[0]); exit(1); } if (ISC_LIST_HEAD(auth_servers) == NULL && ISC_LIST_HEAD(rec_servers) == NULL) { fprintf(stderr, "authoritative or recursive servers " "must be specified\n"); usage(); } /* Initialization */ ISC_LIST_INIT(usedbuffers); ISC_LIST_INIT(usedrdatalists); ISC_LIST_INIT(prereqlist); isc_lib_register(); result = dns_lib_init(); if (result != ISC_R_SUCCESS) { fprintf(stderr, "dns_lib_init failed: %d\n", result); exit(1); } result = isc_mem_create(0, 0, &umctx); if (result != ISC_R_SUCCESS) { fprintf(stderr, "failed to crate mctx\n"); exit(1); } result = dns_client_create(&client, 0); if (result != ISC_R_SUCCESS) { fprintf(stderr, "dns_client_create failed: %d\n", result); exit(1); } /* Construct zone name */ zname = NULL; if (zonenamestr != NULL) { namelen = strlen(zonenamestr); isc_buffer_init(&b, zonenamestr, namelen); isc_buffer_add(&b, namelen); dns_fixedname_init(&zname0); zname = dns_fixedname_name(&zname0); result = dns_name_fromtext(zname, &b, dns_rootname, 0, NULL); if (result != ISC_R_SUCCESS) fprintf(stderr, "failed to convert zone name: %d\n", result); } /* Construct prerequisite name (if given) */ if (prereqstr != NULL) { dns_fixedname_init(&pname0); pname = dns_fixedname_name(&pname0); evaluate_prereq(umctx, prereqstr, pname); ISC_LIST_APPEND(prereqlist, pname, link); prereqlistp = &prereqlist; } /* Construct update name */ ISC_LIST_INIT(updatelist); dns_fixedname_init(&uname0); uname = dns_fixedname_name(&uname0); update_addordelete(umctx, argv[1], isdelete, uname); ISC_LIST_APPEND(updatelist, uname, link); /* Set up TSIG/SIG(0) key (if given) */ if (keyfilename != NULL) setup_tsec(keyfilename, umctx); /* Perform update */ result = dns_client_update(client, default_rdataclass, /* XXX: fixed */ zname, prereqlistp, &updatelist, (ISC_LIST_HEAD(auth_servers) == NULL) ? NULL : &auth_servers, tsec, 0); if (result != ISC_R_SUCCESS) { fprintf(stderr, "update failed: %s\n", dns_result_totext(result)); } else fprintf(stderr, "update succeeded\n"); /* Cleanup */ while ((pname = ISC_LIST_HEAD(prereqlist)) != NULL) { while ((rdataset = ISC_LIST_HEAD(pname->list)) != NULL) { ISC_LIST_UNLINK(pname->list, rdataset, link); dns_rdataset_disassociate(rdataset); isc_mem_put(umctx, rdataset, sizeof(*rdataset)); } ISC_LIST_UNLINK(prereqlist, pname, link); } while ((uname = ISC_LIST_HEAD(updatelist)) != NULL) { while ((rdataset = ISC_LIST_HEAD(uname->list)) != NULL) { ISC_LIST_UNLINK(uname->list, rdataset, link); dns_rdataset_disassociate(rdataset); isc_mem_put(umctx, rdataset, sizeof(*rdataset)); } ISC_LIST_UNLINK(updatelist, uname, link); } while ((rdatalist = ISC_LIST_HEAD(usedrdatalists)) != NULL) { while ((rdata = ISC_LIST_HEAD(rdatalist->rdata)) != NULL) { ISC_LIST_UNLINK(rdatalist->rdata, rdata, link); isc_mem_put(umctx, rdata, sizeof(*rdata)); } ISC_LIST_UNLINK(usedrdatalists, rdatalist, link); isc_mem_put(umctx, rdatalist, sizeof(*rdatalist)); } while ((buf = ISC_LIST_HEAD(usedbuffers)) != NULL) { ISC_LIST_UNLINK(usedbuffers, buf, link); isc_buffer_free(&buf); } if (tsec != NULL) dns_tsec_destroy(&tsec); isc_mem_destroy(&umctx); dns_client_destroy(&client); dns_lib_shutdown(); return (0); }
int main(int argc, char *argv[]) { dns_client_t *client = NULL; isc_result_t result; dns_fixedname_t qfn; dns_name_t *query_name, *response_name; dns_rdataset_t *rdataset; dns_namelist_t namelist; unsigned int resopt, clopt; isc_appctx_t *actx = NULL; isc_taskmgr_t *taskmgr = NULL; isc_socketmgr_t *socketmgr = NULL; isc_timermgr_t *timermgr = NULL; dns_master_style_t *style = NULL; #ifndef WIN32 struct sigaction sa; #endif progname = argv[0]; preparse_args(argc, argv); argc--; argv++; isc_lib_register(); result = dns_lib_init(); if (result != ISC_R_SUCCESS) fatal("dns_lib_init failed: %d", result); result = isc_mem_create(0, 0, &mctx); if (result != ISC_R_SUCCESS) fatal("failed to create mctx"); CHECK(isc_appctx_create(mctx, &actx)); CHECK(isc_taskmgr_createinctx(mctx, actx, 1, 0, &taskmgr)); CHECK(isc_socketmgr_createinctx(mctx, actx, &socketmgr)); CHECK(isc_timermgr_createinctx(mctx, actx, &timermgr)); parse_args(argc, argv); CHECK(setup_style(&style)); setup_logging(stderr); CHECK(isc_app_ctxstart(actx)); #ifndef WIN32 /* Unblock SIGINT if it's been blocked by isc_app_ctxstart() */ memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_DFL; if (sigfillset(&sa.sa_mask) != 0 || sigaction(SIGINT, &sa, NULL) < 0) fatal("Couldn't set up signal handler"); #endif /* Create client */ clopt = DNS_CLIENTCREATEOPT_USECACHE; result = dns_client_createx2(mctx, actx, taskmgr, socketmgr, timermgr, clopt, &client, srcaddr4, srcaddr6); if (result != ISC_R_SUCCESS) { delv_log(ISC_LOG_ERROR, "dns_client_create: %s", isc_result_totext(result)); goto cleanup; } /* Set the nameserver */ if (server != NULL) addserver(client); else findserver(client); CHECK(setup_dnsseckeys(client)); /* Construct QNAME */ CHECK(convert_name(&qfn, &query_name, qname)); /* Set up resolution options */ resopt = DNS_CLIENTRESOPT_ALLOWRUN | DNS_CLIENTRESOPT_NOCDFLAG; if (no_sigs) resopt |= DNS_CLIENTRESOPT_NODNSSEC; if (!root_validation && !dlv_validation) resopt |= DNS_CLIENTRESOPT_NOVALIDATE; if (cdflag) resopt &= ~DNS_CLIENTRESOPT_NOCDFLAG; /* Perform resolution */ ISC_LIST_INIT(namelist); result = dns_client_resolve(client, query_name, dns_rdataclass_in, qtype, resopt, &namelist); if (result != ISC_R_SUCCESS) delv_log(ISC_LOG_ERROR, "resolution failed: %s", isc_result_totext(result)); for (response_name = ISC_LIST_HEAD(namelist); response_name != NULL; response_name = ISC_LIST_NEXT(response_name, link)) { for (rdataset = ISC_LIST_HEAD(response_name->list); rdataset != NULL; rdataset = ISC_LIST_NEXT(rdataset, link)) { result = printdata(rdataset, response_name, style); if (result != ISC_R_SUCCESS) delv_log(ISC_LOG_ERROR, "print data failed"); } } dns_client_freeresanswer(client, &namelist); cleanup: if (dlv_anchor != NULL) isc_mem_free(mctx, dlv_anchor); if (trust_anchor != NULL) isc_mem_free(mctx, trust_anchor); if (anchorfile != NULL) isc_mem_free(mctx, anchorfile); if (qname != NULL) isc_mem_free(mctx, qname); if (style != NULL) dns_master_styledestroy(&style, mctx); if (client != NULL) dns_client_destroy(&client); if (taskmgr != NULL) isc_taskmgr_destroy(&taskmgr); if (timermgr != NULL) isc_timermgr_destroy(&timermgr); if (socketmgr != NULL) isc_socketmgr_destroy(&socketmgr); if (actx != NULL) isc_appctx_destroy(&actx); if (lctx != NULL) isc_log_destroy(&lctx); isc_mem_detach(&mctx); dns_lib_shutdown(); return (0); }