ldap2.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C), 2000-2003 by Contributors to the monit codebase. 
00003  * All Rights Reserved.
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License as
00007  * published by the Free Software Foundation; either version 2 of the
00008  * License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software Foundation,
00017  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00018  */
00019 
00020 #include <config.h>
00021 
00022 #include <stdio.h>
00023 #include <errno.h>
00024 
00025 #ifdef HAVE_STRING_H
00026 #include <string.h>
00027 #endif
00028 
00029 #include "protocol.h"
00030 
00051 int check_ldap2(Port_T p) {
00052 
00053   unsigned char buf[STRLEN];
00054 
00055   unsigned char request[14] = {
00056     0x30,                    
00057     0x0c,          
00059     0x02,                     
00060     0x01,                
00061     0x00,                         
00063     0x60,           
00064     0x07,               
00066     0x02,                         
00067     0x01,                    
00068     0x02,                  
00070     0x04,                    
00071     0x00,                   
00072     /* NULL */                     
00074     0x80,           
00075     0x00               
00076     /* NULL */                
00077   };
00078     
00079   unsigned char response[14] = {
00080     0x30,                    
00081     0x0c,          
00083     0x02,                     
00084     0x01,                
00085     0x00,                         
00087     0x61,          
00088     0x07,               
00090     0x0a,                      
00091     0x01,                 
00092     0x00,                           
00094     0x04,                    
00095     0x00,                   
00096     /* NULL */                            
00098     0x04,                    
00099     0x00                    
00100     /* NULL */                         
00101   };
00102 
00103   ASSERT(p);
00104 
00105 
00106   if(port_send(p, (unsigned char *)request, sizeof(request), 0) < 0) {
00107     log("LDAP: error sending data -- %s\n", STRERROR);
00108     return FALSE;
00109   }
00110 
00111   if(port_recv(p, (unsigned char *)buf, sizeof(buf), 0) <= 0) {
00112     log("LDAP: error receiving data -- %s\n", STRERROR);
00113     return FALSE;
00114   }
00115 
00116   if(strncmp((unsigned char *)buf, (unsigned char *)response, sizeof(response))) {
00117     log("LDAP: anonymous bind failed\n");
00118     return FALSE;
00119   }
00120 
00121 
00122   return TRUE;
00123     
00124 }
00125