开发者

How to use a variable in an LDAP command in C?

I would like to use a variable in the ldap command ldap_search_s 开发者_运维技巧in C. I used strcat to create the string i needed. The error is "bad search filter". I'm pretty sure it has something to do with the string i have created. Here is my code:

char *numero = randomID1() ;
 char *var1="\"(studentID=";
 char *var2= numero;
 char *var3= ")\" ";
char var4[80];


 strcpy (var4,var1);
  strcat (var4, var2);
  strcat (var4,var3);
char *attr[] = { "cn","sn","studentID", NULL };



ldap_search_s( ld, "dc=******,dc=fr",
               LDAP_SCOPE_SUBTREE, var4, attr , 0 , &res )


I haven't tried it, but after looking at the documentation, I would suspect you should not include the double quotes in the filter:

char *var1="(studentID=";
char *var2= numero;
char *var3= ")";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜