]> git.sur5r.net Git - openldap/blob - servers/slapd/sasl.c
d1b195f4590b27e4802794fd860778346473dd82
[openldap] / servers / slapd / sasl.c
1 #include "portable.h"
2
3 #ifdef HAVE_CYRUS_SASL
4
5 #include <ac/stdlib.h>
6 #include <stdio.h>
7
8 #include "slap.h"
9 #include "proto-slap.h"
10
11 #include <lber.h>
12 #include <ldap_log.h>
13
14 #ifdef MAIN
15 #undef Debug
16 #define Debug(x,s,a,b,c) fprintf(stderr, s, a, b, c)
17 #endif
18
19 #include <sasl.h>
20
21 /* sasl server context */
22 static sasl_conn_t *server = NULL;
23
24 int sasl_init( void )
25 {
26         int rc;
27         char *data;
28         unsigned len, count;
29         sasl_security_properties_t secprops;
30
31         rc = sasl_server_init( NULL, "slapd" );
32
33         if( rc != SASL_OK ) {
34                 Debug( LDAP_DEBUG_ANY, "sasl_server_init failed\n",
35                         0, 0, 0 );
36                 return EXIT_FAILURE;
37         }
38
39         rc = sasl_server_new( "ldap", NULL, NULL, NULL,
40                 SASL_SECURITY_LAYER, 
41                 &server );
42
43         if( rc != SASL_OK ) {
44                 Debug( LDAP_DEBUG_ANY, "sasl_server_new failed\n",
45                         0, 0, 0 );
46                 return EXIT_FAILURE;
47         }
48
49         memset(&secprops, 0, sizeof(secprops));
50         secprops.security_flags = SASL_SEC_NOPLAINTEXT | SASL_SEC_NOANONYMOUS;
51         secprops.property_names = NULL;
52         secprops.property_values = NULL;
53         
54         rc = sasl_setprop( server, SASL_SEC_PROPS, &secprops );
55
56         if( rc != SASL_OK ) {
57                 Debug( LDAP_DEBUG_ANY, "sasl_setprop failed\n",
58                         0, 0, 0 );
59                 return EXIT_FAILURE;
60         }
61
62         rc = sasl_listmech( server, NULL, NULL, ",", NULL,
63                 &data, &len, &count);
64
65         if( rc != SASL_OK ) {
66                 Debug( LDAP_DEBUG_ANY, "sasl_listmech failed: %d\n",
67                         rc, 0, 0 );
68                 return EXIT_FAILURE;
69         }
70
71         Debug( LDAP_DEBUG_TRACE, "SASL mechanisms: %s\n",
72                 data, 0, 0 );
73
74         return EXIT_SUCCESS;
75 }
76
77 int sasl_destory( void )
78 {
79         if( server != NULL ) {
80                 sasl_dispose( &server );
81         }
82 }
83
84 #ifdef MAIN
85 int main( int argc, char* argv[] )
86 {
87         int rc = sasl_init();
88
89         sasl_destory();
90
91         exit(rc);
92 }
93 #endif
94 #endif