2
* Copyright (C), 2000-2006 by the monit project group.
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License as
7
* published by the Free Software Foundation; either version 2 of the
8
* License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful, but
11
* WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software Foundation,
17
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
39
* In the case that the anonymous login is possible,
40
* we will perform MySQL ping. If authentication failed
41
* we suppose the anonymous login is denied and we will
42
* return success, because the server at least performed
43
* authentication => it seems it works.
45
* @author Martin Pala, <martinp@tildeslash.com>
47
* @version \$Id: mysql.c,v 1.9 2006/04/27 20:16:03 martinp Exp $
51
int check_mysql(Socket_T s) {
53
unsigned char buf[STRLEN];
55
unsigned char requestLogin[10] = {
56
0x06, /** Packet Length */
60
0x01, /** Packet Number */
64
0x00, /** Max Packet */
73
unsigned char requestPing[5] = {
74
0x01, /** Packet Length */
78
0x00, /** Packet Number */
80
0x0E /** Command Ping */
83
unsigned char responsePing[5] = {
84
0x03, /** Packet Length */
88
0x01, /** Packet Number */
90
0x00 /** Response Code OK */
92
/** Padding Ignored */
95
unsigned char requestQuit[5] = {
96
0x01, /** Packet Length */
100
0x00, /** Packet Number */
102
0x01 /** Command Quit */
107
if(!socket_readln(s, (char *)buf, sizeof(buf))) {
108
LogError("MYSQL: error receiving greeting -- %s\n", STRERROR);
112
if(socket_write(s, requestLogin, sizeof(requestLogin)) < 0) {
113
LogError("MYSQL: error sending login -- %s\n", STRERROR);
117
/* read just first few bytes which contains enough information */
118
if(socket_read(s, buf, 7) <= 6) {
119
LogError("MYSQL: error receiving login response -- %s\n", STRERROR);
123
/* Compare Packet Number: */
125
LogError("MYSQL: invalid response packet number\n");
129
/* Compare Response Code: */
131
/* If OK, we are loged in and will perform MySQL ping */
133
if(socket_write(s, (unsigned char *)requestPing, sizeof(requestPing)) < 0) {
134
LogError("MYSQL: error sending ping -- %s\n", STRERROR);
138
if(socket_read(s, buf, sizeof(responsePing)) <= 0) {
139
LogError("MYSQL: error receiving ping response -- %s\n", STRERROR);
143
if(memcmp((unsigned char *)buf,
144
(unsigned char *)responsePing, sizeof(responsePing))) {
145
LogError("MYSQL: ping failed\n");
149
if(socket_write(s, (unsigned char *)requestQuit, sizeof(requestQuit)) < 0) {
150
LogError("MYSQL: error sending quit -- %s\n", STRERROR);
156
/* If Authentication Failed, return success immediately */
157
else if((buf[4] == 0xFF) && (buf[5] == 0x15 && buf[6] == 0x04)) {
161
LogError("MYSQL: login failed\n");