File: saslconn.c

package info (click to toggle)
libldap-ruby 0.6.1-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 484 kB
  • ctags: 343
  • sloc: ansic: 2,298; ruby: 613; sh: 125; makefile: 59
file content (104 lines) | stat: -rw-r--r-- 2,270 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * saslconn.c
 * $Id: saslconn.c,v 1.7 2002/03/12 05:36:05 ttate Exp $
 */

#include "ruby.h"
#include "rbldap.h"
#include <sys/time.h>
#include <unistd.h>


VALUE rb_cLDAP_SASLConn;

void
Init_ldap_saslconn()
{
  rb_cLDAP_SASLConn = rb_define_class_under(rb_mLDAP, "SASLConn", rb_cLDAP_Conn);
  rb_define_method(rb_cLDAP_SASLConn, "bind", rb_ldap_saslconn_bind, -1);
};


#if defined(HAVE_LDAP_SASL_BIND_S)
VALUE
rb_ldap_saslconn_bind(int argc, VALUE argv[], VALUE self)
{
  RB_LDAP_DATA *ldapdata;

  VALUE arg1, arg2, arg3, arg4, arg5, arg6;
  VALUE result;
  char *dn = NULL;
  char *mechanism = NULL;
  struct berval *cred = ALLOCA_N(struct berval, 1);
  LDAPControl **serverctrls = NULL;
  LDAPControl **clientctrls = NULL;
  struct berval *servercred;

  GET_LDAP_DATA(self,ldapdata);
  switch( rb_scan_args(argc, argv, "32", &arg1, &arg2, &arg3, &arg4, &arg5) ){
  case 3:
    if( arg1 == Qnil ){
      dn = NULL;
    }
    else{
      dn = STR2CSTR(arg1);
    };
    mechanism = STR2CSTR(arg2);
    cred->bv_val = STR2CSTR(arg3);
    cred->bv_len = RSTRING(arg3)->len;
    break;
  case 4:
    if( arg1 == Qnil ){
      dn = NULL;
    }
    else{
      dn = STR2CSTR(arg1);
    };
    mechanism = STR2CSTR(arg2);
    cred->bv_val = STR2CSTR(arg3);
    cred->bv_len = RSTRING(arg3)->len;
    serverctrls = rb_ldap_get_controls(arg4);
    break;
  case 5:
    if( arg1 == Qnil ){
      dn = NULL;
    }
    else{
      dn = STR2CSTR(arg1);
    };
    mechanism = STR2CSTR(arg2);
    cred->bv_val = STR2CSTR(arg3);
    cred->bv_len = RSTRING(arg3)->len;
    serverctrls = rb_ldap_get_controls(arg4);
    clientctrls = rb_ldap_get_controls(arg5);
    break;
  default:
    rb_bug("rb_ldap_conn_bind_s");
  }

  ldapdata->err = ldap_sasl_bind_s(ldapdata->ldap, dn, mechanism, cred,
				   serverctrls, clientctrls, &servercred);
  Check_LDAP_Result(ldapdata->err);

  if( rb_block_given_p() ){
    VALUE val;
    val = rb_assoc_new(self,
		       rb_tainted_str_new(servercred->bv_val, servercred->bv_len));
    result = rb_ensure(rb_yield, val, rb_ldap_conn_unbind, self);
  };

  return self;
};

#else /* HAVE_LDAP_SASL_BIND_S */

VALUE
rb_ldap_saslconn_bind(int argc, VALUE argv[], VALUE self)
{
  rb_notimplement();
};

#endif /* HAVE_LDAP_SASL_BIND_S */