diff options
author | unknown <konstantin@mysql.com> | 2004-03-17 20:04:50 +0300 |
---|---|---|
committer | unknown <konstantin@mysql.com> | 2004-03-17 20:04:50 +0300 |
commit | c6a059964271c2b1cb7dc9905d9b708770d1278f (patch) | |
tree | b125698d0619b2d35f6b0b36ad5b7aa33826012b /libmysql | |
parent | d7307566499fcb640e845231bcfa78af17cb1fc9 (diff) | |
download | mariadb-git-c6a059964271c2b1cb7dc9905d9b708770d1278f.tar.gz |
WL #1510 "Implement support for "commercial" binaries on handshake",
client library:
- implemented 'check_license' function
include/errmsg.h:
WL #1510: new error code
include/mysql_version.h.in:
WL #1510: fallback define for LICENSE
libmysql/errmsg.c:
WL #1510: error message to print in case when client and server license
mismatch.
libmysql/libmysql.c:
WL#1510: implementation of 'check_license' function
sql/set_var.cc:
removed unused variable 'license'
Diffstat (limited to 'libmysql')
-rw-r--r-- | libmysql/errmsg.c | 9 | ||||
-rw-r--r-- | libmysql/libmysql.c | 54 |
2 files changed, 60 insertions, 3 deletions
diff --git a/libmysql/errmsg.c b/libmysql/errmsg.c index 7accbf8f1d2..06d21cf36c3 100644 --- a/libmysql/errmsg.c +++ b/libmysql/errmsg.c @@ -51,7 +51,8 @@ const char *client_errors[]= "Error connecting to slave:", "Error connecting to master:", "SSL connection error", - "Malformed packet" + "Malformed packet", + "This client library is licensed only for use with MySQL servers having '%s' license" }; /* Start of code added by Roberto M. Serqueira - martinsc@uol.com.br - 05.24.2001 */ @@ -86,7 +87,8 @@ const char *client_errors[]= "Error connecting to slave:", "Error connecting to master:", "SSL connection error", - "Malformed packet" + "Malformed packet", + "This client library is licensed only for use with MySQL servers having '%s' license" }; #else /* ENGLISH */ @@ -119,7 +121,8 @@ const char *client_errors[]= "Error connecting to slave:", "Error connecting to master:", "SSL connection error", - "Malformed packet" + "Malformed packet", + "This client library is licensed only for use with MySQL servers having '%s' license" }; #endif diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index f2d77d495c9..6a4189b6b18 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -1612,6 +1612,56 @@ mysql_connect(MYSQL *mysql,const char *host, #endif +#ifdef CHECK_LICENSE +/* + Check server side variable 'license'. + If the variable does not exist or does not contain 'Commercial', + we're talking to non-commercial server from commercial client. + SYNOPSIS + check_license() + RETURN VALUE + 0 success + !0 network error or the server is not commercial. + Error code is saved in mysql->net.last_errno. +*/ + +static int check_license(MYSQL *mysql) +{ + MYSQL_ROW row; + MYSQL_RES *res; + NET *net= &mysql->net; + static const char query[]= "SELECT @@license"; + static const char required_license[]= LICENSE; + + if (mysql_real_query(mysql, query, sizeof(query)-1)) + { + if (net->last_errno == ER_UNKNOWN_SYSTEM_VARIABLE) + { + net->last_errno= CR_WRONG_LICENSE; + sprintf(net->last_error, ER(net->last_errno), required_license); + } + return 1; + } + if (!(res= mysql_use_result(mysql))) + return 1; + row= mysql_fetch_row(res); + /* + If no rows in result set, or column value is NULL (none of these + two is ever true for server variables now), or column value + mismatch, set wrong license error. + */ + if (!net->last_errno && + (!row || !row[0] || + strncmp(row[0], required_license, sizeof(required_license)))) + { + net->last_errno= CR_WRONG_LICENSE; + sprintf(net->last_error, ER(net->last_errno), required_license); + } + mysql_free_result(res); + return net->last_errno; +} +#endif /* CHECK_LICENSE */ + /* The following union is used to force a struct to be double allgined. This is to avoid warings with gethostname_r() on Linux itanium systems @@ -2048,6 +2098,10 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, net->compress=1; if (mysql->options.max_allowed_packet) net->max_packet_size= mysql->options.max_allowed_packet; +#ifdef CHECK_LICENSE + if (check_license(mysql)) + goto error; +#endif if (db && mysql_select_db(mysql,db)) goto error; if (mysql->options.init_command) |