Solved

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

Posted on 2010-09-15
3
872 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

757 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

21 Experts available now in Live!

Get 1:1 Help Now