Skip to Content.
Sympa Menu

freetds - Patch for src/tds/config.c (configuration file selection fixed)

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Alexander Gutman" <agutman AT emc.com>
  • To: freetds AT franklin.oit.unc.edu
  • Subject: Patch for src/tds/config.c (configuration file selection fixed)
  • Date: Thu, 27 Jun 2002 14:50:22 -0400


BACKGROUND:

The appearing in the module
'src/tds/config.c' is faulty. The problem is that the algorithm
used by this function to select a configuration file doesn't
comply with what the User's Guide states. The intended mode of
operation is as follows:

1. Try to use the environment variable FREETDSCONF as a pointer
to a configuration file. On success, end selection.
2. Try to use ${HOME}/.freetds.conf. On success, end selection.
3. Try to use the system-wide default.

As implemented in freetds-0.53, the function 'tds_read_conf_file()'
does something else, namely:

1. Try to use the system-wide default.
2. Try to use ${HOME}/.freetds.conf.

This not only differs from what the documentation states but also
gives the user much less control (for example, it doesn't allow
to ignore the system-wide default configuration).

PATCH:

The following patch has been prepared against freetds-0.53:

Index: src/tds/config.c
===================================================================
RCS file: /emc/ucode/cvsroot_1/freetds-0.53/src/tds/config.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- src/tds/config.c 27 Jun 2002 17:54:40 -0000 1.1.1.1
+++ src/tds/config.c 27 Jun 2002 18:26:43 -0000 1.2
@@ -119,29 +119,48 @@
FILE *in;
char *section;
int i;
-char *home, *path;
-int found = 0;
+char *home, *path[3];
+int found = 0;

- in = fopen(FREETDS_SYSCONFFILE, "r");
- if (in) {
- tdsdump_log(TDS_DBG_INFO1, "%L Found conf file in %s reading
sections\n",FREETDS_SYSCONFFILE);
- found = tds_read_conf_sections(in, server, config);
- fclose(in);
+ /* Alternative locations of configuration file, in order of
preference:
+ * 0. ${FREETDSCONF}
+ * 1. ${HOME}/.freetds.conf
+ * 2. FREETDS_SYSCONFFILE
+ */
+
+ path[0] = getenv("FREETDSCONF");
+ if (path[0]!=NULL && *path[0]=='\0') {
+ path[0] = NULL;
}
-
+
+ path[1] = NULL;
home = getenv("HOME");
- if (home!=NULL && home[0]!='\0') {
- path = malloc(strlen(home) + 14 + 1); /*
strlen("/.freetds.conf")=14 */
- sprintf(path,"%s/.freetds.conf",home);
- in = fopen(path, "r");
+ if (home!=NULL && *home!='\0') {
+ path[1] = malloc(strlen(home) + 14 + 1); /*
strlen("/.freetds.conf")=14
*/
+ sprintf(path[1],"%s/.freetds.conf",home);
+ }
+
+ path[2] = FREETDS_SYSCONFFILE;
+
+
+ for (i=0;i<3;i++) {
+ if (path[i]==NULL) {
+ continue;
+ }
+ in = fopen(path[i], "r");
if (in) {
- tdsdump_log(TDS_DBG_INFO1, "%L Found conf file in
%s/.freetds.conf
reading sections\n",home);
+ tdsdump_log(TDS_DBG_INFO1, "%L Found conf file in %s;
reading
sections\n",path[i]);
found = tds_read_conf_sections(in, server, config);
fclose(in);
+ if (found) {
+ break;
+ }
}
- free(path);
}

+ if (path[1]!=NULL) {
+ free(path[1]);
+ }
return found;
}
static int tds_read_conf_sections(FILE *in, char *server, TDSCONFIGINFO
*config)



  • Patch for src/tds/config.c (configuration file selection fixed), Alexander Gutman, 06/27/2002

Archive powered by MHonArc 2.6.24.

Top of Page