54 #include <sys/socket.h>
58 #include <sys/types.h>
62 #include <netinet/in.h>
66 #include <arpa/inet.h>
91 #define TDS_ISSPACE(c) isspace((unsigned char ) (c))
94 #if !defined(_WIN32) && !defined(DOS32X)
97 static const char location[] =
"(from $FREETDS/etc)";
103 static const char location[] =
"(from $FREETDS)";
104 static const char pid_logpath[] =
"c:\\freetds.log.%d";
142 int opened = 0, found;
152 s = getenv(
"TDSDUMPCONFIG");
216 for (addrs = connection->
ip_addrs; addrs !=
NULL; addrs = addrs->ai_next)
295 if ((
in = fopen(path,
"r")) ==
NULL) {
353 path = getenv(
"FREETDSCONF");
363 eptr = getenv(
"FREETDS");
430 static const struct {
451 return default_value;
500 char line[256], *
value;
509 while (fgets(line,
sizeof(line),
in)) {
517 if (*s ==
';' || *s ==
'#')
523 while (*s && *s !=
'=') {
552 while (*s && *s !=
';' && *s !=
'#') {
576 }
else if (insection) {
599 if (
val >= 512 &&
val < 65536)
613 if (*
value !=
'\0' && *end ==
'\0' &&
flags > INT_MIN
789 if ((s = getenv(
"TDSDUMP"))) {
811 if ((s = getenv(
"TDSPORT"))) {
823 if ((tdsver = getenv(
"TDSVER"))) {
839 if (!(tdshost = getenv(
"TDSHOST")))
855 #define TDS_FIND(k,b,c) tds_find(k, b, sizeof(b)/sizeof(b[0]), sizeof(b[0]), c)
859 tds_find(
const void *
key,
const void *base,
size_t nelem,
size_t width,
860 int (*compar)(
const void *,
const void *))
863 for (
i=0;
i < nelem;
i++) {
864 char *p = (
char*)base + width *
i;
865 if (0 == compar(
key, p)) {
940 if ((interf ==
NULL) || (interf[0] ==
'\0')) {
965 memset(&hints,
'\0',
sizeof(hints));
966 hints.ai_family = AF_UNSPEC;
967 hints.ai_socktype = SOCK_STREAM;
970 hints.ai_flags |= AI_ADDRCONFIG;
1001 int num = atoi(portname);
1011 if (c >=
'0' && c <=
'9')
1015 if (c >=
'a' && c <=
'f')
1016 return c -
'a' + 10;
1041 char tmp_ip[
sizeof(line)];
1042 char tmp_port[
sizeof(line)];
1043 char tmp_ver[
sizeof(line)];
1047 int server_found = 0;
1056 pathname =
tds_new(
char, strlen(dir) + strlen(
file) + 10);
1063 if (
file[0] ==
'\0') {
1066 if (dir[0] ==
'\0') {
1069 strcpy(pathname, dir);
1079 if ((
in = fopen(pathname,
"r")) ==
NULL) {
1086 while (fgets(line,
sizeof(line) - 1,
in)) {
1091 field =
strtok_r(line,
"\n\t ", &lasts);
1092 if (!
strcmp(field, host)) {
1098 field =
strtok_r(line,
"\n\t ", &lasts);
1099 if (field !=
NULL && !
strcmp(field,
"query")) {
1101 if (!
strcmp(field,
"tli")) {
1106 if (strlen(field) >= 18) {
1107 sprintf(tmp_port,
"%d",
hex2num(&field[6]) * 256 +
hex2num(&field[8]));
1108 sprintf(tmp_ip,
"%d.%d.%d.%d",
hex2num(&field[10]),
1114 strcpy(tmp_ver, field);
1116 strcpy(tmp_ip, field);
1119 strcpy(tmp_port, field);
1151 return server_found;
1166 if (!server || !server[0]) {
1167 server = getenv(
"TDSQUERY");
1168 if (!server || !server[0])
1200 const char *sybase = getenv(
"SYBASE");
1203 #include <unixlib.h>
1204 const char *unixspec = decc$translate_vms(sybase);
1205 if ( (
int)unixspec != 0 && (
int)unixspec != -1 ) sybase = unixspec;
1207 if (!sybase || !sybase[0])
1220 const char *env_port;
1239 if ((env_port = getenv(
"TDSPORT")) !=
NULL) {
1275 if (server[0] ==
'[') {
1276 pSep = strstr(server,
"]:");
1280 pSep = strrchr(server,
':');
1283 if (pSep && pSep != server) {
1289 pSep = strrchr(server,
'\\');
1290 if (!pSep || pSep == server)
1295 connection->
port = 0;
1321 # ifdef TDS_SYBASE_COMPAT
1365 # ifdef HAVE_OPENSSL
1375 # if ENABLE_ODBC_MARS
static const char pid_config_logpath[]
const char STD_DATETIME_FMT[]
static const char freetds_conf[]
static const char pid_logpath[]
static const char location[]
static const char interfaces_path[]
static char * interf_file
#define FREETDS_SYSCONFFILE
int tds_read_conf_file(TDSLOGIN *login, const char *server)
Read configuration info for given server return 0 on error.
TDSRET tds_lookup_host_set(const char *servername, struct addrinfo **addr)
static int tds_vernanme_cmp(const void *key, const void *pelem)
static int hex2num(char *hex)
static int tds_try_conf_file(const char *path, const char *how, const char *server, TDSLOGIN *login)
void tds_parse_conf_section(const char *option, const char *value, void *param)
static void tds_config_encryption(const char *value, TDSLOGIN *login)
static int tds_lookup_port(const char *portname)
Given a portname lookup the port.
static const struct @981 boolean_values[]
TDSRET tds_set_interfaces_file_loc(const char *interf)
Set the full name of interface file.
int tds_read_conf_section(FILE *in, const char *section, TDSCONFPARSE tds_conf_parse, void *param)
Read a section of configuration file (INI style file)
static int tds_read_interfaces(const char *server, TDSLOGIN *login)
Try to find the IP number and port for a (possibly) logical server name.
static void tds_config_env_tdsver(TDSLOGIN *login)
const TDS_COMPILETIME_SETTINGS * tds_get_compiletime_settings(void)
Return a structure capturing the compile-time settings provided to the configure script.
static int tds_config_env_tdsdump(TDSLOGIN *login)
static int tds_config_login(TDSLOGIN *connection, TDSLOGIN *login)
TDSLOGIN * tds_read_config_info(TDSSOCKET *tds, TDSLOGIN *login, TDSLOCALE *locale)
tds_read_config_info() will fill the tds connection structure based on configuration information gath...
static void tds_config_env_tdsport(TDSLOGIN *login)
static int hexdigit(int c)
struct addrinfo * tds_lookup_host(const char *servername)
Get the IP address for a hostname.
int tds_config_boolean(const char *option, const char *value, TDSLOGIN *login)
int tds_parse_boolean(const char *value, int default_value)
static int tds_read_conf_sections(FILE *in, const char *server, TDSLOGIN *login)
static int parse_server_name_for_port(TDSLOGIN *connection, TDSLOGIN *login)
Check the server name to find port info first Warning: connection-> & login-> are all modified when n...
static void * tds_find(const void *key, const void *base, size_t nelem, size_t width, int(*compar)(const void *, const void *))
static int tds_config_env_tdshost(TDSLOGIN *login)
static int search_interface_file(TDSLOGIN *login, const char *dir, const char *file, const char *host)
Open and read the file 'file' searching for a logical server by the name of 'host'.
#define TDS_FIND(k, b, c)
void tds_fix_login(TDSLOGIN *login)
Fix configuration after reading it.
TDS_USMALLINT * tds_config_verstr(const char *tdsver, TDSLOGIN *login)
Set TDS version from given string.
static char * tds_get_home_file(const char *file)
Return filename from HOME directory.
static const char * tds_dstr_cstr(DSTR *s)
Returns a C version (NUL terminated string) of dstr.
void tds_dstr_zero(DSTR *s)
clear all string filling with zeroes (mainly for security reason)
#define tds_dstr_empty(s)
Make a string empty.
DSTR * tds_dstr_dup(DSTR *s, const DSTR *src) TDS_WUR
Duplicate a string from another dynamic string.
#define DSTR_INITIALIZER
Initializer, used to initialize string like in the following example.
DSTR * tds_dstr_copyn(DSTR *s, const char *src, size_t length) TDS_WUR
Set string to a given buffer of characters.
DSTR * tds_dstr_set(DSTR *s, char *src) TDS_WUR
set a string from another buffer.
void tds_dstr_free(DSTR *s)
free string
DSTR * tds_dstr_copy(DSTR *s, const char *src) TDS_WUR
copy a string from another
static int tds_dstr_isempty(DSTR *s)
test if string is empty
unsigned int
A callback function used to compare two keys in a database.
static void hex(unsigned char c)
const struct ncbi::grid::netcache::search::fields::KEY key
int strcmp(const char *str1, const char *str2)
std::istream & in(std::istream &in_, double &x_)
#define tds_g_append_mode
#define getaddrinfo(n, s, h, r)
A structure to hold all the compile-time settings.
Structure to hold a string.
unsigned int use_new_password
DSTR crlfile
certificate revocation file
unsigned int check_ssl_hostname
DSTR server_realm_name
server realm name (in freetds.conf)
DSTR user_name
account for login
unsigned int gssapi_use_delegation
DSTR password
password of account login
DSTR db_filename
database filename to attach (MSSQL)
TDS_CAPABILITIES capabilities
unsigned int readonly_intent
TDS_TINYINT encryption_level
unsigned int valid_configuration
DSTR server_name
server name (in freetds.conf)
struct addrinfo * ip_addrs
ip(s) of server
DSTR server_charset
charset of server e.g.
TDS_USMALLINT tds_version
TDS version.
DSTR new_password
new password to set (TDS 7.2+)
unsigned int suppress_language
unsigned int emul_little_endian
unsigned int bulk_copy
if bulk copy should be enabled
DSTR cafile
certificate authorities file
DSTR server_spn
server SPN (in freetds.conf)
int port
port of database service
Information for a server connection.
#define FREETDS_SYSCONFDIR
#define TDS_SDIR_SEPARATOR
Main include file for libtds.
#define TDS_STR_READONLY_INTENT
#define TDS_STR_CLCHARSET
#define TDS_STR_CHECKSSLHOSTNAME
void(* TDSCONFPARSE)(const char *option, const char *value, void *param)
#define TDS_STR_ASA_DATABASE
#define TDS_STR_ENCRYPTION_REQUEST
#define TLS_STR_OPENSSL_CIPHERS
#define TDS_VECTOR_SIZE(x)
#define TDS_STR_ENCRYPTION_OFF
#define TDS_STR_DEBUGFLAGS
#define TDS_STR_ENCRYPTION
#define TDS_STR_USELANMAN
#define TDS_STR_CONNTIMEOUT
#define TDS_STR_APPENDMODE
#define TDS_STR_USENTLMV2
tds_sysdep_uint16_type TDS_USMALLINT
#define TDS_GSSAPI_DELEGATION
#define TDS_STR_DBFILENAME
#define TDS_STR_QUERY_TIMEOUT
#define TDS_STR_ENCRYPTION_REQUIRE
#define TDS_STR_USE_UTF_16
enum tds_encryption_level TDS_ENCRYPTION_LEVEL