r1802: start to support SASL in our ldap libraries
[gd/samba-autobuild/.git] / source4 / torture / ldap / common.c
1 #include "includes.h"
2
3 NTSTATUS torture_ldap_bind(struct ldap_connection *conn, const char *userdn, const char *password)
4 {
5         NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
6         int result;
7
8         if (!conn) {
9                 printf("We need a valid ldap_connection structure and be connected\n");
10                 return status;
11         }
12
13         result = ldap_bind_simple(conn, userdn, password);
14         if (result != LDAP_SUCCESS) {
15                 printf("Failed to bind with provided credentials\n");
16                 /* FIXME: what abut actually implementing an ldap_connection_free() function ?
17                           :-) sss */
18                 return status;
19         }
20  
21         return NT_STATUS_OK;
22 }
23
24 NTSTATUS torture_ldap_bind_sasl(struct ldap_connection *conn, const char *username, const char *domain, const char *password)
25 {
26         NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
27         int result;
28
29         if (!conn) {
30                 printf("We need a valid ldap_connection structure and be connected\n");
31                 return status;
32         }
33
34         result = ldap_bind_sasl(conn, username, domain, password);
35         if (result != LDAP_SUCCESS) {
36                 printf("Failed to bind with provided credentialsi and SASL mechanism\n");
37                 /* FIXME: what abut actually implementing an ldap_connection_free() function ?
38                           :-) sss */
39                 return status;
40         }
41  
42         return NT_STATUS_OK;
43 }
44
45 /* open a ldap connection to a server */
46 NTSTATUS torture_ldap_connection(struct ldap_connection **conn, 
47                                 const char *url, const char *userdn, const char *password)
48 {
49         NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
50         BOOL ret;
51
52         if (!url) {
53                 printf("You must specify a url string\n");
54                 return NT_STATUS_INVALID_PARAMETER;
55         }
56
57         *conn = new_ldap_connection();
58         if (!*conn) {
59                 printf("Failed to initialize ldap_connection structure\n");
60                 return status;
61         }
62
63         ret = ldap_setup_connection(*conn, url, userdn, password);
64         if (!ret) {
65                 printf("Failed to connect with url [%s]\n", url);
66                 /* FIXME: what abut actually implementing an ldap_connection_free() function ?
67                           :-) sss */
68                 return status;
69         }
70  
71         return NT_STATUS_OK;
72 }
73
74 /* close an ldap connection to a server */
75 NTSTATUS torture_ldap_close(struct ldap_connection *conn)
76 {
77         /* FIXME: what about actually implementing ldap_close() ?
78                   :-) sss */
79         return NT_STATUS_OK;
80 }
81