[freetds] Bug #1759652 and resolution

ZIGLIO, Frediano, VF-IT Frediano.Ziglio at vodafone.com
Tue Aug 7 10:03:20 EDT 2007


> > 
> > the questions are:
> > - is it correct?
> > - should we call tds_read_conf_file even if these strange 
> syntaxes are
> > used?
> > - if is correct to call tds_read_conf_file after
> > parse_server_name_for_port which specifications should take 
> > precedence.
> > For instance if we specify foo:1234 and in section "foo" of 
> > freetds.conf
> > we have "port = 5678" which port should we use.
> > I think all these cases should be documented in our userguide.
> > 
> > Also I start thinking that perhaps name resolution should be done in
> > login.c or in net.c and not in config.c so to avoid double 
> > resolutions.
> > 
> 
> Well... I forgot to express my opinions...
> I never saw "server\instance" or "server:port" as freetds.conf
> servername so parse_server_name_for_port should be called before
> tds_read_conf_file. Is also useful to pass parsed servername to
> tds_read_conf_file to read additional infos (tds version, 
> charset and so
> on). tds_read_conf_file by itself try to resolve name from 
> servername to
> I would also remove name resolution from parse_server_name_for_port.
> 

This is the implementation



Index: src/tds/config.c
===================================================================
RCS file: /cvsroot/freetds/freetds/src/tds/config.c,v
retrieving revision 1.128
diff -u -1 -0 -r1.128 config.c
--- src/tds/config.c    3 Aug 2007 11:16:55 -0000       1.128
+++ src/tds/config.c    7 Aug 2007 13:53:24 -0000
@@ -162,33 +162,33 @@
                                        opened = tdsdump_open(path);
                                }
                                free(path);
                        }
                }
        }

        tdsdump_log(TDS_DBG_INFO1, "Getting connection information for
[%s].\n",
                            tds_dstr_cstr(&login->server_name));
/* (The server name is set in login.c.) */

+       if (parse_server_name_for_port(connection, login)) {
+               tdsdump_log(TDS_DBG_INFO1, "Parsed servername, now %s on
%d.\n",
+                           tds_dstr_cstr(&connection->server_name),
login->port);
+       }
+
        /* Read the config files. */
        tdsdump_log(TDS_DBG_INFO1, "Attempting to read conf files.\n");
        if (!tds_read_conf_file(connection,
tds_dstr_cstr(&login->server_name))) {
                /* fallback to interfaces file */
                tdsdump_log(TDS_DBG_INFO1, "Failed in reading conf file.
Trying interface files.\n");
                tds_read_interfaces(tds_dstr_cstr(&login->server_name),
connection);
        }

-       if (parse_server_name_for_port(connection, login)) {
-               tdsdump_log(TDS_DBG_INFO1, "Parsed servername, now %s on
%d.\n",
-                           tds_dstr_cstr(&connection->server_name),
login->port);
-       }
-
        /* Override config file settings with environment variables. */
        tds_fix_connection(connection);

        /* And finally apply anything from the login structure */
        tds_config_login(connection, login);

        if (opened) {
                tdsdump_log(TDS_DBG_INFO1, "Final connection
parameters:\n");
                tdsdump_log(TDS_DBG_INFO1, "\t%20s = %s\n",
"server_name", tds_dstr_cstr(&connection->server_name));
                tdsdump_log(TDS_DBG_INFO1, "\t%20s = %d\n", "port",
connection->port);
@@ -1024,21 +1024,20 @@
 /**
  * Check the server name to find port info first
  * Warning: connection-> & login-> are all modified when needed
  * \return 1 when found, else 0
  */
 static int
 parse_server_name_for_port(TDSCONNECTION * connection, TDSLOGIN *
login)
 {
        const char *pSep;
        const char *server;
-       char tmp[256];

        /* seek the ':' in login server_name */
        server = tds_dstr_cstr(&login->server_name);
        pSep = strrchr(server, ':');

        if (pSep && pSep != server) {   /* yes, i found it! */
                /* modify connection-> && login->server_name & ->port */
                login->port = connection->port = atoi(pSep + 1);
                tds_dstr_copy(&connection->instance_name, "");
        } else {
@@ -1048,25 +1047,20 @@
                        return 0;

                login->port = connection->port = 0;
                tds_dstr_copy(&connection->instance_name, pSep + 1);
        }

        tds_dstr_setlen(&login->server_name, pSep - server);
        if (!tds_dstr_dup(&connection->server_name,
&login->server_name))
                return 0;

-       /* connection->ip_addr needed */
-       tds_lookup_host(tds_dstr_cstr(&connection->server_name), tmp);
-       if (!tds_dstr_copy(&connection->ip_addr, tmp))
-               return 0;       /* FALSE */
-
        return 1;
 }


 /**
  * Return a structure capturing the compile-time settings provided to
the
  * configure script.
  */

 const TDS_COMPILETIME_SETTINGS *



freddy77


More information about the FreeTDS mailing list