Solved

How do I convert a char * to a struct berval for ldap_sasl_bind_s?

Posted on 2010-09-15
3
878 Views
Last Modified: 2013-12-24
I am new to C so any guidance will be greatly appreciated.  ldap_simple_bind_s is depricated in favor of ldap_sasl_bind_s.  I need to recompile a program that previously used ldap_simple_bind_s.  The password value is passed to the function that is calling ldap_sasl_bind_s as a char *, but sasl_bind_s is wanting a struct berval.  Do I need to convert it, and if so, how?

LDAP_F( int )
ldap_simple_bind_s LDAP_P(( /* deprecated, use ldap_sasl_bind_s */
        LDAP *ld,
        LDAP_CONST char *who,
        LDAP_CONST char *passwd ));

LDAP_F( int )
ldap_sasl_bind_s LDAP_P((
        LDAP                    *ld,
        LDAP_CONST char *dn,
        LDAP_CONST char *mechanism,
        struct berval   *cred,
        LDAPControl             **serverctrls,
        LDAPControl             **clientctrls,
        struct berval   **servercredp ));
0
Comment
Question by:ssbb123
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 33683248
Since a 'strunct berval' is

struct berval {
  unsigned long bv_len;
  char *bv_val;
};

you could use


#include <string.h>



void string_to_berval(const char* pstr, struct berval* pbv) {



  pbv->bv_len = strlen(pstr);

  pbv->bv_val = pstr;

}



//...



char* passwd = "TopSecret";

struct berval bv;



string_to_berval(passwd,&bv);

Open in new window

0
 

Author Comment

by:ssbb123
ID: 33683855
That works! I was trying to make it much more complicated than that =).  Thanks!!!
0
 
LVL 86

Expert Comment

by:jkr
ID: 33684304
Good to know ;o)

BTW, you should close your questions when they're resolved.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MarkLogic 1 68
Need a replacement data type in Oracle 6 65
Best RAID for a BDD Oracle 4 61
Default Mailbox Database on Exchange became dismounted due to carelessness 11 62
SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

912 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

27 Experts available now in Live!

Get 1:1 Help Now