[freetds] FreeTDS and FreeRadius - Problems Writing a Driver

Chris Spears Chris.Spears at harrynorman.com
Mon Apr 28 12:25:32 EDT 2003


Hello,  I am working with Freeradius [freeradius.org] and trying to
update/fix 
the freetds driver that comes along with it.

The problem I am having write now is in the connection code to the server. 
My connection code is basically a replication of the tsql.c connection 
code.  

tsql -S Test -U Administrator logs in fine on my box with this config file.

[Test]
        host = sql-test
        port = 1433
        tds version = 8.0
        try domain login = yes
        try server login = no
        nt domain = MYDOMAIN

-- My Driver Connection Code -- 

static int sql_init_socket(SQLSOCK *sqlsocket, SQL_CONFIG *config) {
    const char *locale = NULL;
    TDSSOCKET *tds;
    TDSLOGIN *login;
    TDSCONTEXT *context;
    TDSCONNECTINFO *connect_info;
    char *charset = "iso_1";

    /* Setting connection parameters */
    login = tds_alloc_login();
    context = tds_alloc_context();
    if(context->locale && !context->locale->date_fmt) {
        context->locale->date_fmt = strdup("%b %e %Y %I:%M%p");
    }

    context->msg_handler = handle_message;
    context->err_handler = handle_message;

    /* populate_login(login, argc, argv); */
    setlocale(LC_ALL, "");
    locale = setlocale(LC_ALL, NULL);

    tds_set_user    (login, config->sql_login);
    tds_set_app     (login, "FREERADIUS");
    tds_set_library (login, "TDS-Library");
    tds_set_server  (login, "Test");
    tds_set_port    (login, 1433);
    tds_set_charset (login, charset);
    tds_set_language(login, "us_english");
    tds_set_packet  (login, 512);
    tds_set_passwd  (login, config->sql_password);

    tds = tds_alloc_socket(context, 512);
    tds_set_parent(tds, NULL);

    /* Do connection */
    connect_info = tds_read_config_info(NULL, login, context->locale);
    if (!connect_info || tds_connect(tds, connect_info) == TDS_FAIL)
    {
        tds_free_connect(connect_info);
        radlog(L_ERR, "rlm_sql_freetds: Can't connect to the database
server");
        return -1;
    }
    tds_free_connect(connect_info);

    /* some other code that I have commented out atm */
}

The Config file refrenced (config->sql_login and config->sql_password) both
return fine.

When I run that code above I get a segfault or Illegal Instruction at the
tds_connect(*) line.  The Interesting part
about the error is that I believe it is happening in tds7_send_login().  The
reason I 
belief that is because if I go up to my config file and change "tds version"
from 8.0 to 4.2 or 5.0 
then I get no error.

Where is the error?  The above block of code is almost identical to the
tsql.c main/populate_login code.
Based on the fact that I am setting server to "Test"  the attempted login
should function just like
a tsql -S Test.  If anyone has any insight into the problem or see something
wrong with the code please
let me know.

thanks,
Chris Spears



More information about the FreeTDS mailing list