如何在 C 语言的 LDAP 命令中使用变量?
我想在 C 中的 ldap 命令 ldap_search_s 中使用变量。我使用 strcat 创建我需要的字符串。错误是“错误的搜索过滤器”。我很确定这与我创建的字符串有关。这是我的代码:
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 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 )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还没有尝试过,但在查看文档后,我怀疑您不应该在过滤器中包含双引号:
I haven't tried it, but after looking at the documentation, I would suspect you should not include the double quotes in the filter: