NCBI C++ ToolKit
Classes | Macros | Typedefs | Functions
login.c File Reference
#include <config.h>
#include <stdarg.h>
#include <stdio.h>
#include <assert.h>
#include <freetds/tds.h>
#include <freetds/iconv.h>
#include <freetds/string.h>
#include <freetds/bytes.h>
#include <freetds/tls.h>
#include <freetds/stream.h>
#include <freetds/checks.h>
#include "replacements.h"
+ Include dependency graph for login.c:

Go to the source code of this file.

Go to the SVN repository for this file.

Classes

struct  tds_save_msg
 
struct  tds_save_env
 
struct  tds_save_context
 

Macros

#define MIN(a, b)   (((a) < (b)) ? (a) : (b))
 
#define COPY(name)   if (msg->name) dest_msg->msg.name = strdup(msg->name);
 
#define SET_FIELD_DSTR(field, dstr)
 
#define PUT_STRING_FIELD_PTR(field)
 
#define START_POS   21
 
#define UI16BE(n)   ((n) >> 8), ((n) & 0xffu)
 
#define SET_UI16BE(i, n)   TDS_PUT_UA2BE(&buf[i],n)
 
#define START_POS   26
 

Typedefs

typedef struct tds_save_context TDSSAVECONTEXT
 

Functions

static TDSRET tds_send_login (TDSSOCKET *tds, TDSLOGIN *login)
 
static TDSRET tds71_do_login (TDSSOCKET *tds, TDSLOGIN *login)
 
static TDSRET tds7_send_login (TDSSOCKET *tds, TDSLOGIN *login)
 tds7_send_login() – Send a TDS 7.0 login packet TDS 7.0 login packet is vastly different and so gets its own function More...
 
static void tds7_crypt_pass (const unsigned char *clear_pass, size_t len, unsigned char *crypt_pass)
 tds7_crypt_pass() – 'encrypt' TDS 7.0 style passwords. More...
 
void tds_set_version (TDSLOGIN *tds_login, TDS_TINYINT major_ver, TDS_TINYINT minor_ver)
 
void tds_set_packet (TDSLOGIN *tds_login, int packet_size)
 
void tds_set_port (TDSLOGIN *tds_login, int port)
 
bool tds_set_passwd (TDSLOGIN *tds_login, const char *password)
 
void tds_set_bulk (TDSLOGIN *tds_login, TDS_TINYINT enabled)
 
bool tds_set_user (TDSLOGIN *tds_login, const char *username)
 
bool tds_set_host (TDSLOGIN *tds_login, const char *hostname)
 
bool tds_set_app (TDSLOGIN *tds_login, const char *application)
 
bool tds_set_server (TDSLOGIN *tds_login, const char *server)
 Set the servername in a TDSLOGIN structure. More...
 
bool tds_set_library (TDSLOGIN *tds_login, const char *library)
 
bool tds_set_client_charset (TDSLOGIN *tds_login, const char *charset)
 
bool tds_set_language (TDSLOGIN *tds_login, const char *language)
 
static void tds_save (TDSSAVECONTEXT *ctx, char type, TDSMESSAGE *msg)
 
static int tds_save_msg (const TDSCONTEXT *ctx, TDSSOCKET *tds, TDSMESSAGE *msg)
 
static int tds_save_err (const TDSCONTEXT *ctx, TDSSOCKET *tds, TDSMESSAGE *msg)
 
static void tds_save_env (TDSSOCKET *tds, int type, char *oldval, char *newval)
 
static void init_save_context (TDSSAVECONTEXT *ctx, const TDSCONTEXT *old_ctx)
 
static void replay_save_context (TDSSOCKET *tds, TDSSAVECONTEXT *ctx)
 
static void reset_save_context (TDSSAVECONTEXT *ctx)
 
static void free_save_context (TDSSAVECONTEXT *ctx)
 
static TDSRET tds_set_spid (TDSSOCKET *tds)
 Retrieve and set @spid \tds. More...
 
static int tds_connect (TDSSOCKET *tds, TDSLOGIN *login, int *p_oserr)
 Do a connection to socket. More...
 
int tds_connect_and_login (TDSSOCKET *tds, TDSLOGIN *login)
 
static int tds_put_login_string (TDSSOCKET *tds, const char *buf, int n)
 

Macro Definition Documentation

◆ COPY

#define COPY (   name)    if (msg->name) dest_msg->msg.name = strdup(msg->name);

◆ MIN

#define MIN (   a,
  b 
)    (((a) < (b)) ? (a) : (b))

Definition at line 64 of file login.c.

◆ PUT_STRING_FIELD_PTR

#define PUT_STRING_FIELD_PTR (   field)
Value:
do { \
TDS_PUT_SMALLINT(tds, data_fields[field].pos); \
TDS_PUT_SMALLINT(tds, data_fields[field].len / 2u); \
} while(0)
static TDSSOCKET * tds
Definition: collations.c:37
int len

◆ SET_FIELD_DSTR

#define SET_FIELD_DSTR (   field,
  dstr 
)
Value:
do { \
data_fields[field].ptr = tds_dstr_cstr(&(dstr)); \
data_fields[field].len = MIN(tds_dstr_len(&(dstr)), 128); \
} while(0)
#define MIN(a, b)
Definition: login.c:64
static const char * tds_dstr_cstr(DSTR *s)
Returns a C version (NUL terminated string) of dstr.
Definition: string.h:66
static size_t tds_dstr_len(DSTR *s)
Returns the length of the string in bytes.
Definition: string.h:73

◆ SET_UI16BE

#define SET_UI16BE (   i,
  n 
)    TDS_PUT_UA2BE(&buf[i],n)

◆ START_POS [1/2]

#define START_POS   21

◆ START_POS [2/2]

#define START_POS   26

◆ UI16BE

#define UI16BE (   n)    ((n) >> 8), ((n) & 0xffu)

Typedef Documentation

◆ TDSSAVECONTEXT

Function Documentation

◆ free_save_context()

static void free_save_context ( TDSSAVECONTEXT ctx)
static

Definition at line 302 of file login.c.

References ctx, and reset_save_context().

Referenced by tds_connect().

◆ init_save_context()

static void init_save_context ( TDSSAVECONTEXT ctx,
const TDSCONTEXT old_ctx 
)
static

Definition at line 254 of file login.c.

References ctx, tds_context::locale, tds_save_err(), and tds_save_msg().

Referenced by tds_connect().

◆ replay_save_context()

static void replay_save_context ( TDSSOCKET tds,
TDSSAVECONTEXT ctx 
)
static

Definition at line 263 of file login.c.

References ctx, tds_socket::env_chg_func, err_handler(), msg_handler(), n, tds, and tds_get_ctx.

Referenced by tds_connect().

◆ reset_save_context()

static void reset_save_context ( TDSSAVECONTEXT ctx)
static

Definition at line 284 of file login.c.

References ctx, free(), n, and tds_free_msg.

Referenced by free_save_context(), and tds_connect().

◆ tds71_do_login()

static TDSRET tds71_do_login ( TDSSOCKET tds,
TDSLOGIN login 
)
static

◆ tds7_crypt_pass()

static void tds7_crypt_pass ( const unsigned char *  clear_pass,
size_t  len,
unsigned char *  crypt_pass 
)
static

tds7_crypt_pass() – 'encrypt' TDS 7.0 style passwords.

the calling function is responsible for ensuring crypt_pass is at least 'len' characters

Definition at line 1130 of file login.c.

References i, and len.

Referenced by tds7_send_login().

◆ tds7_send_login()

static TDSRET tds7_send_login ( TDSSOCKET tds,
TDSLOGIN login 
)
static

tds7_send_login() – Send a TDS 7.0 login packet TDS 7.0 login packet is vastly different and so gets its own function

Returns
the return value is ignored by the caller. :-/

Definition at line 849 of file login.c.

References tds_login::app_name, assert, tds_connection::authentication, tds_login::block_size, tds_login::bulk_copy, tds_connection::char_convs, client2ucs2, tds_login::client_host_name, tds_socket::conn, data, tds_login::database, tds_login::db_filename, free(), input(), IS_TDS71_PLUS, IS_TDS72_PLUS, IS_TDS73_PLUS, tds_login::language, len, tds_login::library, login, tds_login::new_password, NULL, tds_login::option_flag2, tds_socket::out_buf_max, tds_socket::out_flag, tds_authentication::packet, tds_authentication::packet_len, tds_login::password, PASSWORD, PUT_STRING_FIELD_PTR, tds_login::readonly_intent, tds_login::server_name, SET_FIELD_DSTR, tds_dynamic_stream::size, tds_dynamic_stream::stream, tds, tds7_crypt_pass(), TDS7_LOGIN, TDS_CHANGE_PASSWORD, tds_convert_stream, TDS_DBG_ERROR, TDS_DBG_INFO2, tds_dstr_cstr(), TDS_DUMPLOAD_OFF, tds_dynamic_stream_init, TDS_FAIL, TDS_FAILED, tds_flush_packet, tds_get_s, tds_getmac, tds_gss_get_auth, TDS_INIT_DB_FATAL, TDS_INTEGRATED_SECURITY_ON, tds_ntlm_get_auth, tds_put_byte, TDS_PUT_INT, tds_put_int, tds_put_n, TDS_PUT_SMALLINT, tds_put_smallint, TDS_READONLY_INTENT, tds_realloc_socket, TDS_SET_LANG_ON, tds_staticin_stream_init, TDS_UNKNOWN_COLLATION_HANDLING, TDS_USE_DB_NOTIFY, TDS_VECTOR_SIZE, tds_login::tds_version, tdsdump_elided, tdsdump_log, to_server, tds_login::use_new_password, and tds_login::user_name.

Referenced by tds71_do_login(), and tds_connect().

◆ tds_connect()

static int tds_connect ( TDSSOCKET tds,
TDSLOGIN login,
int p_oserr 
)
static

Do a connection to socket.

Parameters
tdsconnection structure. This should be a non-connected connection.
Returns
TDS_FAIL or TDS_SUCCESS if a connection was made to the server's port.
TDSERROR enumerated type if no TCP/IP connection could be formed.
Parameters
logininfo for login
Remarks
Possible error conditions:
  • TDSESOCK: socket(2) failed: insufficient local resources
    • TDSECONN: connect(2) failed: invalid hostname or port (ETIMEDOUT, ECONNREFUSED, ENETUNREACH)
    • TDSEFCON: connect(2) succeeded, login packet not acknowledged.
  • TDS_FAIL: connect(2) succeeded, login failed.

Definition at line 367 of file login.c.

References addrinfo, tds_connection::authentication, tds_env::block_size, tds_login::capabilities, tds_connection::capabilities, tds_connection::char_convs, client2ucs2, tds_login::client_charset, tds_socket::conn, tds_login::connect_timeout, tds_login::connected_addr, tds_save_context::ctx, tds_login::database, tds_login::debug_flags, tds_login::dump_file, tds_login::emul_little_endian, tds_connection::emul_little_endian, tds_connection::env, tds_socket::env_chg_func, err_handler(), tds_context::err_handler, free(), tds_authentication::free, free_save_context(), i, init_save_context(), tds_login::instance_name, tds_login::ip_addrs, IS_TDS42, IS_TDS50, IS_TDS71_PLUS, IS_TDS72_PLUS, IS_TDS7_PLUS, len, tds_socket::login, login, tds_login::mars, NULL, tds_socket::out_flag, tds_login::port, tds_connection::product_name, tds_login::query_timeout, tds_socket::query_timeout, replay_save_context(), reset_save_context(), tds_login::routing_address, tds_login::routing_port, tds_login::server_name, tds_connection::spid, str(), strcasecmp, strcat, tds, tds71_do_login(), tds7_get_instance_port, tds7_send_login(), tds_close_socket, TDS_DBG_ERROR, tds_debug_flags, tds_dstr_cstr(), tds_dstr_free(), tds_dstr_isempty(), TDS_FAIL, TDS_FAILED, tds_get_ctx, tds_iconv_open, TDS_IDLE, tds_init_write_buf, TDS_LOGIN, tds_lookup_host_set, TDS_MAJOR, tds_new, tds_open_socket, tds_process_login_tokens, tds_process_simple_query, tds_quote_id, tds_realloc_socket, tds_save_env(), tds_send_login(), tds_set_ctx, tds_set_spid(), tds_set_state, tds_submit_query, TDS_SUCCEED, TDS_SUCCESS, TDS_VECTOR_SIZE, tds_login::tds_version, tds_connection::tds_version, tdsdump_isopen, tdsdump_log, tdsdump_open, TDSECONF, TDSECONN, TDSEFCON, TDSEINTF, TDSEMEM, TDSEOK, tdserror, TDSEUHST, tds_login::text_size, type, tds_login::use_utf16, and tds_login::valid_configuration.

Referenced by tds_connect_and_login().

◆ tds_connect_and_login()

int tds_connect_and_login ( TDSSOCKET tds,
TDSLOGIN login 
)

Definition at line 657 of file login.c.

References login, tds, and tds_connect().

◆ tds_put_login_string()

static int tds_put_login_string ( TDSSOCKET tds,
const char *  buf,
int  n 
)
static

Definition at line 664 of file login.c.

References buf, int, n, tds, and tds_put_buf.

Referenced by tds_send_login().

◆ tds_save()

static void tds_save ( TDSSAVECONTEXT ctx,
char  type,
TDSMESSAGE msg 
)
static

Definition at line 199 of file login.c.

References COPY, ctx, tds_save_msg::msg, NULL, tds_message::osstr, TDS_VECTOR_SIZE, type, and tds_save_msg::type.

Referenced by tds_save_err(), and tds_save_msg().

◆ tds_save_env()

static void tds_save_env ( TDSSOCKET tds,
int  type,
char *  oldval,
char *  newval 
)
static

Definition at line 234 of file login.c.

References ctx, env, msg_handler(), tds_save_env::newval, NULL, tds_save_env::oldval, strdup, tds, tds_get_ctx, TDS_VECTOR_SIZE, and type.

Referenced by tds_connect().

◆ tds_save_err()

static int tds_save_err ( const TDSCONTEXT ctx,
TDSSOCKET tds,
TDSMESSAGE msg 
)
static

Definition at line 227 of file login.c.

References ctx, tds_save_msg::msg, TDS_INT_CANCEL, and tds_save().

Referenced by init_save_context().

◆ tds_save_msg()

static int tds_save_msg ( const TDSCONTEXT ctx,
TDSSOCKET tds,
TDSMESSAGE msg 
)
static

Definition at line 220 of file login.c.

References ctx, tds_save_msg::msg, and tds_save().

Referenced by init_save_context().

◆ tds_send_login()

static TDSRET tds_send_login ( TDSSOCKET tds,
TDSLOGIN login 
)
static

◆ tds_set_app()

bool tds_set_app ( TDSLOGIN tds_login,
const char *  application 
)

Definition at line 112 of file login.c.

References tds_login::app_name, and tds_dstr_copy().

◆ tds_set_bulk()

void tds_set_bulk ( TDSLOGIN tds_login,
TDS_TINYINT  enabled 
)

Definition at line 94 of file login.c.

References tds_login::bulk_copy.

◆ tds_set_client_charset()

bool tds_set_client_charset ( TDSLOGIN tds_login,
const char *  charset 
)

Definition at line 162 of file login.c.

References tds_login::client_charset, and tds_dstr_copy().

◆ tds_set_host()

bool tds_set_host ( TDSLOGIN tds_login,
const char *  hostname 
)

Definition at line 106 of file login.c.

References tds_login::client_host_name, and tds_dstr_copy().

◆ tds_set_language()

bool tds_set_language ( TDSLOGIN tds_login,
const char *  language 
)

Definition at line 168 of file login.c.

References tds_login::language, and tds_dstr_copy().

◆ tds_set_library()

bool tds_set_library ( TDSLOGIN tds_login,
const char *  library 
)

Definition at line 156 of file login.c.

References tds_login::library, and tds_dstr_copy().

◆ tds_set_packet()

void tds_set_packet ( TDSLOGIN tds_login,
int  packet_size 
)

Definition at line 73 of file login.c.

References tds_login::block_size.

◆ tds_set_passwd()

bool tds_set_passwd ( TDSLOGIN tds_login,
const char *  password 
)

Definition at line 85 of file login.c.

References tds_login::password, tds_dstr_copy(), and tds_dstr_zero().

◆ tds_set_port()

void tds_set_port ( TDSLOGIN tds_login,
int  port 
)

Definition at line 79 of file login.c.

References tds_login::port.

◆ tds_set_server()

bool tds_set_server ( TDSLOGIN tds_login,
const char *  server 
)

Set the servername in a TDSLOGIN structure.

Normally copies server into tds_login. If server does not point to a plausible name, the environment variables TDSQUERY and DSQUERY are used, in that order. If they don't exist, the "default default" servername is "SYBASE" (although the utility of that choice is a bit murky).

Parameters
tds_loginpoints to a TDSLOGIN structure
serverthe servername, or NULL, or a zero-length string

Definition at line 129 of file login.c.

References i, names, tds_login::server_name, rapidjson::source, TDS_DBG_INFO1, tds_dstr_copy(), TDS_VECTOR_SIZE, and tdsdump_log.

◆ tds_set_spid()

static TDSRET tds_set_spid ( TDSSOCKET tds)
static

◆ tds_set_user()

bool tds_set_user ( TDSLOGIN tds_login,
const char *  username 
)

Definition at line 100 of file login.c.

References tds_dstr_copy(), and tds_login::user_name.

◆ tds_set_version()

void tds_set_version ( TDSLOGIN tds_login,
TDS_TINYINT  major_ver,
TDS_TINYINT  minor_ver 
)

Definition at line 67 of file login.c.

References tds_login::tds_version.

Modified on Sun Jun 16 04:36:15 2024 by modify_doxy.py rev. 669887