From d6db18e8ae719b97ac2bcebe520e710b601014e7 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 3 Jun 2004 01:55:47 +0300 Subject: Added authentication code that was missed in merge Added new windows configuration VC++Files/client/mysqlclient.dsp: Added new configuration VC++Files/zlib/zlib.dsp: Added new configuration libmysql/libmysql.c: Moved check function from libmysql.c to client.c sql-common/client.c: Moved check function from libmysql.c to client.c --- sql-common/client.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) (limited to 'sql-common/client.c') diff --git a/sql-common/client.c b/sql-common/client.c index 591a0b9f0cb..87e62b5cd11 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -751,6 +751,58 @@ static my_bool is_NT(void) } #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[]= STRINGIFY_ARG(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 */ + + /************************************************************************** Shut down connection **************************************************************************/ @@ -1996,10 +2048,14 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, goto error; } - if (client_flag & CLIENT_COMPRESS) /* We will use compression */ net->compress=1; +#ifdef CHECK_LICENSE + if (check_license(mysql)) + goto error; +#endif + if (db && mysql_select_db(mysql,db)) goto error; -- cgit v1.2.1