/** * Try to find the IP number and port for a (possibly) logical server name. * * @note This function uses only the interfaces file and is deprecated. */ static int tds_read_interfaces(const char *server, TDSLOGIN * login) { int found = 0; /* read $SYBASE/interfaces */ if (!server || !server[0]) { server = getenv("TDSQUERY"); if (!server || !server[0]) server = "SYBASE"; tdsdump_log(TDS_DBG_INFO1, "Setting server to %s from $TDSQUERY.\n", server); } tdsdump_log(TDS_DBG_INFO1, "Looking for server %s....\n", server); /* * Look for the server in the interf_file iff interf_file has been set. */ if (interf_file) { tdsdump_log(TDS_DBG_INFO1, "Looking for server in file %s.\n", interf_file); found = search_interface_file(login, "", interf_file, server); } /* * if we haven't found the server yet then look for a $HOME/.interfaces file */ if (!found) { char *path = tds_get_home_file(".interfaces"); if (path) { tdsdump_log(TDS_DBG_INFO1, "Looking for server in %s.\n", path); found = search_interface_file(login, "", path, server); free(path); } } /* * if we haven't found the server yet then look in $SYBBASE/interfaces file */ if (!found) { const char *sybase = getenv("SYBASE"); #ifdef __VMS /* We've got to be in unix syntax for later slash-joined concatenation. */ #include <unixlib.h> const char *unixspec = decc$translate_vms(sybase); if ( (int)unixspec != 0 && (int)unixspec != -1 ) sybase = unixspec; #endif if (!sybase || !sybase[0]) sybase = interfaces_path; tdsdump_log(TDS_DBG_INFO1, "Looking for server in %s/interfaces.\n", sybase); found = search_interface_file(login, sybase, "interfaces", server); } /* * If we still don't have the server and port then assume the user * typed an actual server host name. */ if (!found) { int ip_port; const char *env_port; /* * Make a guess about the port number */ if (login->port == 0) { /* * Not set in the [global] section of the * configure file, take a guess. */ ip_port = TDS_DEF_PORT; } else { /* * Preserve setting from the [global] section * of the configure file. */ ip_port = login->port; } if ((env_port = getenv("TDSPORT")) != NULL) { ip_port = tds_lookup_port(env_port); tdsdump_log(TDS_DBG_INFO1, "Setting 'ip_port' to %s from $TDSPORT.\n", env_port); } else tdsdump_log(TDS_DBG_INFO1, "Setting 'ip_port' to %d as a guess.\n", ip_port); /* * look up the host */ if (TDS_SUCCEED(tds_lookup_host_set(server, &login->ip_addrs))) if (!tds_dstr_copy(&login->server_host_name, server)) return 0; if (ip_port) login->port = ip_port; } return found; }
/** * Try to find the IP number and port for a (possibly) logical server name. * * @note This function uses only the interfaces file and is deprecated. * * =========================================================================== */ static void tds_read_interfaces(const char *server, TDSCONNECTINFO * connect_info) { int founded = 0; /* read $SYBASE/interfaces */ if (!server || strlen(server) == 0) { server = getenv("TDSQUERY"); if (!server || strlen(server) == 0) { server = "SYBASE"; } tdsdump_log(TDS_DBG_INFO1, "%L Setting server to %s from $TDSQUERY.\n", server); } tdsdump_log(TDS_DBG_INFO1, "%L Looking for server %s....\n", server); /* * Look for the server in the interf_file iff interf_file has been set. */ if (interf_file) { tdsdump_log(TDS_DBG_INFO1, "%L Looking for server in file %s.\n", interf_file); founded = search_interface_file(connect_info, "", interf_file, server); } /* * if we haven't found the server yet then look for a $HOME/.interfaces file */ if (!founded) { char *path = tds_get_home_file(".interfaces"); if (path) { tdsdump_log(TDS_DBG_INFO1, "%L Looking for server in %s.\n", path); founded = search_interface_file(connect_info, "", path, server); free(path); } } /* * if we haven't found the server yet then look in $SYBBASE/interfaces file */ if (!founded) { const char *sybase = getenv("SYBASE"); if (!sybase || !sybase[0]) sybase = "/etc/freetds"; tdsdump_log(TDS_DBG_INFO1, "%L Looking for server in %s/interfaces.\n", sybase); founded = search_interface_file(connect_info, sybase, "interfaces", server); } /* * If we still don't have the server and port then assume the user * typed an actual server name. */ if (!founded) { char ip_addr[255]; int ip_port; const char *env_port; /* * Make a guess about the port number */ #ifdef TDS50 ip_port = 4000; #else ip_port = 1433; #endif if ((env_port = getenv("TDSPORT")) != NULL) { ip_port = tds_lookup_port(env_port); tdsdump_log(TDS_DBG_INFO1, "%L Setting 'ip_port' to %s from $TDSPORT.\n", env_port); } else tdsdump_log(TDS_DBG_INFO1, "%L Setting 'ip_port' to %d as a guess.\n", ip_port); /* * lookup the host */ tds_lookup_host(server, ip_addr); if (ip_addr[0]) tds_dstr_copy(&connect_info->ip_addr, ip_addr); if (ip_port) connect_info->port = ip_port; } }