Solved

#ifdef HAVE_OPENSSL is failed

Posted on 2006-11-19
5
882 Views
Last Modified: 2008-02-01
Hi Experts,
I am trying to connect MySQL through C code on SSL. I have written like:

==========================================
MYSQL *mysql_conn(connection_info *conn_info)
{
    MYSQL *connect;
    connect=mysql_init(NULL);
   if(connect==NULL)
   {
       printf("FAILED\n[-] init mysql failed:%s\n",mysql_error(connect));
       return NULL;
   }
 
  #ifdef HAVE_OPENSSL                                                                       // IFDEF CONDITION
   int in = mysql_ssl_set(connect,"certs/client-key.pem",
    "certs/client-cert.pem",
    "certs/ca-cert.pem", 0, 0);
     // printf("%d\n", in);
   #endif

   /* Connect to database */
   if(mysql_real_connect(connect,conn_info->server,conn_info->user,conn_info->password,conn_info->database,conn_info->port,NULL,0)==NULL)
   {
          printf("FAILED\n[-] Error: %s\n",mysql_error(connect));
          return NULL;
    }
    return connect;
}
================================================

It's giving error on "IFDEF CONDITION". When I remove this condition, code is working fine. However, it has suggested in tutorial that I should use that IFDEF CONDITION.
What is the problem with that condition, which approach would be better for me, I don't have have idea about that.
Please provide some solution for this problem.
0
Comment
Question by:rrahulgupta
  • 2
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 17976772
Since you're trying to keep your actual problem a secret (it is always nice to know what is going wrong, error message, compiler/linker/runtime error etc.), i can just guess that your compiler is very strict about C and does not like the declaration of 'in' at that place. Try

MYSQL *mysql_conn(connection_info *conn_info)
{
  #ifdef HAVE_OPENSSL                                                                      
    int in;
  #endif

    MYSQL *connect;
    connect=mysql_init(NULL);
   if(connect==NULL)
   {
       printf("FAILED\n[-] init mysql failed:%s\n",mysql_error(connect));
       return NULL;
   }
 
  #ifdef HAVE_OPENSSL                                                                       // IFDEF CONDITION
   in = mysql_ssl_set(connect,"certs/client-key.pem",
    "certs/client-cert.pem",
    "certs/ca-cert.pem", 0, 0);
     // printf("%d\n", in);
   #endif

   /* Connect to database */
   if(mysql_real_connect(connect,conn_info->server,conn_info->user,conn_info->password,conn_info->database,conn_info->port,NULL,0)==NULL)
   {
          printf("FAILED\n[-] Error: %s\n",mysql_error(connect));
          return NULL;
    }
    return connect;
}
0
 
LVL 1

Assisted Solution

by:i_mahesh
i_mahesh earned 50 total points
ID: 17978045
as jkr as suggested
one of the causes could be the due to the place where the declaration of the int variable is happening.

but it would be helpful to give out the error information you are getting (Like the error string and error code)
0
 

Author Comment

by:rrahulgupta
ID: 17979759
when i set
#define HAVE_OPENSSL 1
then it's working fine.
Does MySQL Client API not defined this macro?
0
 
LVL 86

Expert Comment

by:jkr
ID: 17980376
Yes.
0
 

Author Comment

by:rrahulgupta
ID: 17982114
thanks :)
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now