Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
diff -urN monit-4.7.org/l.l monit-4.7/l.l --- monit-4.7.org/l.l 2006-01-09 06:36:30.000000000 +0900 +++ monit-4.7/l.l 2006-02-22 17:55:12.000000000 +0900 @@ -201,6 +201,7 @@ rdate { return RDATE; } rsync { return RSYNC; } tns { return TNS; } +pgsql { return PGSQL; } mode { return MODE; } active { return ACTIVE; } passive { return PASSIVE; } diff -urN monit-4.7.org/protocols/pgsql.c monit-4.7/protocols/pgsql.c --- monit-4.7.org/protocols/pgsql.c 1970-01-01 09:00:00.000000000 +0900 +++ monit-4.7/protocols/pgsql.c 2006-02-22 18:55:51.000000000 +0900 @@ -0,0 +1,143 @@ +/* + * Copyright (C), 2000-2006 by the monit project group. + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#ifdef HAVE_STDIO_H +#include +#endif + +#ifdef HAVE_ERRNO_H +#include +#endif + +#ifdef HAVE_STRING_H +#include +#endif + +#include "protocol.h" + +/** + * PostgreSQL test. + * + * @author Tatsuya Nonogaki, + * + * @version \$Id: pgsql.c,v 0.4 2006/02/22 18:55:00 $ + * + * @file + */ +int check_pgsql(Socket_T s) { + + unsigned char buf[STRLEN]; + + unsigned char requestLogin[33] = { + 0x00, /** Length */ + 0x00, + 0x00, + 0x21, + + 0x00, /** ProtoVer 3.0 */ + 0x03, + 0x00, + 0x00, + + 0x75, 0x73, 0x65, 0x72, 0x00, /** user */ + 0x72, 0x6f, 0x6f, 0x74, 0x00, /** root */ + + 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x00, /** database */ + 0x72, 0x6f, 0x6f, 0x74, 0x00, /** root */ + + 0x00 + }; + + /** Doing this is too suspicious maybe. + * Type Q, Length 20 and QUERY select 1 as a; */ + /** + unsigned char requestQuery[20] = { + 0x51, + + 0x00, + 0x00, + 0x00, + 0x13, + + 0x73, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x20, + 0x31, 0x20, 0x61, 0x73, 0x20, 0x61, 0x3b, + + 0x00 + }; + */ + + unsigned char requestTerm[5] = { + 0x58, /** Type X */ + + 0x00, /** Length */ + 0x00, + 0x00, + 0x04 + }; + + unsigned char responseAuthOk[9] = { + 0x52, /** Type R */ + + 0x00, /** Length */ + 0x00, + 0x00, + 0x08, + + 0x00, /** OK code 0 */ + 0x00, + 0x00, + 0x00 + }; + + ASSERT(s); + + if(socket_write(s, (unsigned char *)requestLogin, sizeof(requestLogin)) <= 0) { + log("PGSQL: error sending data -- %s\n", STRERROR); + return FALSE; + } + + /** Nine-byte is enough to hold Auth-Ok */ + if(socket_read(s, buf, 9) <= 0) { + log("PGSQL: error receiving data -- %s\n", STRERROR); + return FALSE; + } + + /** If server insists on auth error it is working anyway */ + if(*buf=='E') { + return TRUE; + } + + /** Successful connection */ + if(!memcmp((unsigned char *)buf, (unsigned char *)responseAuthOk, 9)) { + /** This is where suspicious people can do SELECT query that I dont */ + socket_write(s, (unsigned char *)requestTerm, sizeof(requestTerm)); + return TRUE; + } + + /** The last possibility must be that server is demanding password */ + if(*buf=='R') { + return TRUE; + } + + log("PGSQL: unknown error\n"); + return FALSE; +} + diff -urN monit-4.7.org/protocols/protocol.c monit-4.7/protocols/protocol.c --- monit-4.7.org/protocols/protocol.c 2006-01-09 06:36:31.000000000 +0900 +++ monit-4.7/protocols/protocol.c 2006-02-22 17:55:12.000000000 +0900 @@ -54,6 +54,7 @@ static Protocol_T myrdate= NULL; static Protocol_T myrsync= NULL; static Protocol_T mytns= NULL; +static Protocol_T mypgsql= NULL; /** @@ -93,6 +94,7 @@ FREE(myrdate); FREE(myrsync); FREE(mytns); + FREE(mypgsql); } @@ -296,3 +298,13 @@ return mytns; } + +void *create_pgsql() { + if(mypgsql == NULL) { + NEW(mypgsql); + mypgsql->name= "PGSQL"; + mypgsql->check= check_pgsql; + } + return mypgsql; +} + diff -urN monit-4.7.org/protocols/protocol.h monit-4.7/protocols/protocol.h --- monit-4.7.org/protocols/protocol.h 2006-01-09 06:36:32.000000000 +0900 +++ monit-4.7/protocols/protocol.h 2006-02-22 17:55:12.000000000 +0900 @@ -47,6 +47,7 @@ #define P_DNS 18 #define P_POSTFIXPOLICY 19 #define P_TNS 20 +#define P_PGSQL 21 void gc_protocols(); @@ -71,6 +72,7 @@ void* create_rdate(); void* create_rsync(); void* create_tns(); +void* create_pgsql(); /* "Package" locale Protocol routines */ int check_apache_status(Socket_T); @@ -93,6 +95,7 @@ int check_rdate(Socket_T); int check_rsync(Socket_T); int check_tns(Socket_T); +int check_pgsql(Socket_T); #endif diff -urN monit-4.7.org/p.y monit-4.7/p.y --- monit-4.7.org/p.y 2006-01-09 06:36:31.000000000 +0900 +++ monit-4.7/p.y 2006-02-22 17:55:12.000000000 +0900 @@ -253,7 +253,7 @@ %token ALERT MAILFORMAT UNIXSOCKET SIGNATURE %token TIMEOUT RESTART CHECKSUM EXPECT EVERY %token DEFAULT HTTP APACHESTATUS FTP SMTP POP IMAP NNTP NTP3 MYSQL DNS -%token SSH DWP LDAP2 LDAP3 RDATE RSYNC TNS POSTFIXPOLICY +%token SSH DWP LDAP2 LDAP3 RDATE RSYNC TNS PGSQL POSTFIXPOLICY %token STRING PATH MAILADDR MAILFROM MAILSUBJECT %token MAILBODY SERVICENAME STRINGNAME %token NUMBER PERCENT LOGLIMIT CLOSELIMIT DNSLIMIT KEEPALIVELIMIT @@ -923,6 +923,9 @@ | PROTOCOL TNS { portset.protocol= addprotocol(P_TNS); } + | PROTOCOL PGSQL { + portset.protocol= addprotocol(P_PGSQL); + } | sendexpectlist { portset.protocol= addprotocol(P_GENERIC); } @@ -2428,6 +2431,7 @@ case P_RDATE: return create_rdate(); case P_RSYNC: return create_rsync(); case P_TNS: return create_tns(); + case P_PGSQL: return create_pgsql(); } return create_default();