/* * Copyright (C), 2000-2002 by Contributors to the monit codebase. * 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 #include #include #ifdef HAVE_STRING_H #include #endif #include "protocol.h" /** * Simple LDAPv3 protocol test. * * Try anonymous bind to the server. * * BindRequest based on RFC2251. Request and response are ASN.1 * BER encoded strings. To make the test as simple as possible * we work with BER encoded data. * * The test checks only if the bind was successfull - in the * case of failure it don't provide any erroneous message * analysis. * * @author Jan-Henrik Haukeland, * @author Martin Pala, * * @version \$Id: ldap3.c,v 1.1 2003/02/06 23:33:06 martinp Exp $ * * @file */ int check_ldap3(Port_T p) { unsigned char buf[STRLEN]; unsigned char request[14] = { 0x30, /** Universal Sequence TAG */ 0x0c, /** Length of the packet's data part */ 0x02, /** Universal Integer TAG */ 0x01, /** Integer length */ 0x00, /** MessageID */ 0x60, /** Application BindRequest TAG */ 0x07, /** Length of the data part */ 0x02, /** Universal Integer TAG */ 0x01, /** Integer length */ 0x03, /** Protocol version */ 0x04, /** Universal Octet string TAG */ 0x00, /** Octet string length */ /* NULL */ /** Anonymous BindDN */ 0x80, /** Context specific SimpleAuth TAG */ 0x00 /** SimpleAuth (octet string) length */ /* NULL */ /** Anonymous Credentials */ }; unsigned char response[14] = { 0x30, /** Universal Sequence TAG */ 0x0c, /** Length of the packet's data part */ 0x02, /** Universal Integer TAG */ 0x01, /** Integer length */ 0x00, /** MessageID */ 0x61, /** Application BindResponse TAG */ 0x07, /** Length of the data part */ 0x0a, /** Universal Enumerated TAG */ 0x01, /** Enumerated length */ 0x00, /** Success */ 0x04, /** Universal Octet string TAG */ 0x00, /** Octet string length */ /* NULL */ /** MatchedDN */ 0x04, /** Universal Octet string TAG */ 0x00 /** Octet string length */ /* NULL */ /** ErrorMessage */ }; ASSERT(p); if(port_send(p, (unsigned char *)request, sizeof(request), 0) < 0) { log("LDAP: error sending data -- %s\n", STRERROR); return FALSE; } if(port_recv(p, (unsigned char *)buf, sizeof(buf), 0) <= 0) { log("LDAP: error receiving data -- %s\n", STRERROR); return FALSE; } if(strncmp((unsigned char *)buf, (unsigned char *)response, sizeof(response))) { log("LDAP: anonymous bind failed\n"); return FALSE; } return TRUE; }