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