openldap-ntlm.patch 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. Patch from evolution-exchange (2.10.3). The ldap_ntlm_bind function is
  2. actually called by evolution-data-server, checked at version 1.12.2.
  3. Without this patch, the Exchange addressbook integration uses simple binds
  4. with cleartext passwords.
  5. Russ checked with openldap-software for upstream's opinion on this patch
  6. on 2007-12-21. Upstream had never received it as a patch submission and
  7. given that it's apparently only for older Exchange servers that can't do
  8. SASL and DIGEST-MD5, it's not very appealing.
  9. Bug#457374 filed against evolution-data-server asking if this support is
  10. still required on 2007-12-21.
  11. Index: trunk/include/ldap.h
  12. ===================================================================
  13. --- trunk.orig/include/ldap.h
  14. +++ trunk/include/ldap.h
  15. @@ -2461,5 +2461,25 @@
  16. LDAPControl **ctrls,
  17. LDAPDerefRes **drp ));
  18. +/*
  19. + * hacks for NTLM
  20. + */
  21. +#define LDAP_AUTH_NTLM_REQUEST ((ber_tag_t) 0x8aU)
  22. +#define LDAP_AUTH_NTLM_RESPONSE ((ber_tag_t) 0x8bU)
  23. +LDAP_F( int )
  24. +ldap_ntlm_bind LDAP_P((
  25. + LDAP *ld,
  26. + LDAP_CONST char *dn,
  27. + ber_tag_t tag,
  28. + struct berval *cred,
  29. + LDAPControl **sctrls,
  30. + LDAPControl **cctrls,
  31. + int *msgidp ));
  32. +LDAP_F( int )
  33. +ldap_parse_ntlm_bind_result LDAP_P((
  34. + LDAP *ld,
  35. + LDAPMessage *res,
  36. + struct berval *challenge));
  37. +
  38. LDAP_END_DECL
  39. #endif /* _LDAP_H */
  40. Index: trunk/libraries/libldap/ntlm.c
  41. ===================================================================
  42. --- /dev/null
  43. +++ trunk/libraries/libldap/ntlm.c
  44. @@ -0,0 +1,138 @@
  45. +/* $OpenLDAP: pkg/ldap/libraries/libldap/ntlm.c,v 1.1.4.10 2002/01/04 20:38:21 kurt Exp $ */
  46. +/*
  47. + * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
  48. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  49. + */
  50. +
  51. +/* Mostly copied from sasl.c */
  52. +
  53. +#include "portable.h"
  54. +
  55. +#include <stdlib.h>
  56. +#include <stdio.h>
  57. +
  58. +#include <ac/socket.h>
  59. +#include <ac/string.h>
  60. +#include <ac/time.h>
  61. +#include <ac/errno.h>
  62. +
  63. +#include "ldap-int.h"
  64. +
  65. +int
  66. +ldap_ntlm_bind(
  67. + LDAP *ld,
  68. + LDAP_CONST char *dn,
  69. + ber_tag_t tag,
  70. + struct berval *cred,
  71. + LDAPControl **sctrls,
  72. + LDAPControl **cctrls,
  73. + int *msgidp )
  74. +{
  75. + BerElement *ber;
  76. + int rc;
  77. + ber_int_t id;
  78. +
  79. + Debug( LDAP_DEBUG_TRACE, "ldap_ntlm_bind\n", 0, 0, 0 );
  80. +
  81. + assert( ld != NULL );
  82. + assert( LDAP_VALID( ld ) );
  83. + assert( msgidp != NULL );
  84. +
  85. + if( msgidp == NULL ) {
  86. + ld->ld_errno = LDAP_PARAM_ERROR;
  87. + return ld->ld_errno;
  88. + }
  89. +
  90. + /* create a message to send */
  91. + if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
  92. + ld->ld_errno = LDAP_NO_MEMORY;
  93. + return ld->ld_errno;
  94. + }
  95. +
  96. + assert( LBER_VALID( ber ) );
  97. +
  98. + LDAP_NEXT_MSGID( ld, id );
  99. + rc = ber_printf( ber, "{it{istON}" /*}*/,
  100. + id, LDAP_REQ_BIND,
  101. + ld->ld_version, dn, tag,
  102. + cred );
  103. +
  104. + /* Put Server Controls */
  105. + if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
  106. + ber_free( ber, 1 );
  107. + return ld->ld_errno;
  108. + }
  109. +
  110. + if ( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
  111. + ld->ld_errno = LDAP_ENCODING_ERROR;
  112. + ber_free( ber, 1 );
  113. + return ld->ld_errno;
  114. + }
  115. +
  116. + /* send the message */
  117. + *msgidp = ldap_send_initial_request( ld, LDAP_REQ_BIND, dn, ber, id );
  118. +
  119. + if(*msgidp < 0)
  120. + return ld->ld_errno;
  121. +
  122. + return LDAP_SUCCESS;
  123. +}
  124. +
  125. +int
  126. +ldap_parse_ntlm_bind_result(
  127. + LDAP *ld,
  128. + LDAPMessage *res,
  129. + struct berval *challenge)
  130. +{
  131. + ber_int_t errcode;
  132. + ber_tag_t tag;
  133. + BerElement *ber;
  134. + ber_len_t len;
  135. +
  136. + Debug( LDAP_DEBUG_TRACE, "ldap_parse_ntlm_bind_result\n", 0, 0, 0 );
  137. +
  138. + assert( ld != NULL );
  139. + assert( LDAP_VALID( ld ) );
  140. + assert( res != NULL );
  141. +
  142. + if ( ld == NULL || res == NULL ) {
  143. + return LDAP_PARAM_ERROR;
  144. + }
  145. +
  146. + if( res->lm_msgtype != LDAP_RES_BIND ) {
  147. + ld->ld_errno = LDAP_PARAM_ERROR;
  148. + return ld->ld_errno;
  149. + }
  150. +
  151. + if ( ld->ld_error ) {
  152. + LDAP_FREE( ld->ld_error );
  153. + ld->ld_error = NULL;
  154. + }
  155. + if ( ld->ld_matched ) {
  156. + LDAP_FREE( ld->ld_matched );
  157. + ld->ld_matched = NULL;
  158. + }
  159. +
  160. + /* parse results */
  161. +
  162. + ber = ber_dup( res->lm_ber );
  163. +
  164. + if( ber == NULL ) {
  165. + ld->ld_errno = LDAP_NO_MEMORY;
  166. + return ld->ld_errno;
  167. + }
  168. +
  169. + tag = ber_scanf( ber, "{ioa" /*}*/,
  170. + &errcode, challenge, &ld->ld_error );
  171. + ber_free( ber, 0 );
  172. +
  173. + if( tag == LBER_ERROR ) {
  174. + ld->ld_errno = LDAP_DECODING_ERROR;
  175. + return ld->ld_errno;
  176. + }
  177. +
  178. + ld->ld_errno = errcode;
  179. +
  180. + return( ld->ld_errno );
  181. +}
  182. +
  183. Index: trunk/libraries/libldap/Makefile.in
  184. ===================================================================
  185. --- trunk.orig/libraries/libldap/Makefile.in
  186. +++ trunk/libraries/libldap/Makefile.in
  187. @@ -27,7 +27,7 @@
  188. init.c options.c print.c string.c util-int.c schema.c \
  189. charray.c os-local.c dnssrv.c utf-8.c utf-8-conv.c \
  190. tls2.c tls_o.c tls_g.c tls_m.c \
  191. - turn.c ppolicy.c dds.c txn.c ldap_sync.c stctrl.c \
  192. + turn.c ppolicy.c dds.c txn.c ldap_sync.c stctrl.c ntlm.c \
  193. assertion.c deref.c ldif.c fetch.c
  194. OBJS = bind.lo open.lo result.lo error.lo compare.lo search.lo \
  195. @@ -40,7 +40,7 @@
  196. init.lo options.lo print.lo string.lo util-int.lo schema.lo \
  197. charray.lo os-local.lo dnssrv.lo utf-8.lo utf-8-conv.lo \
  198. tls2.lo tls_o.lo tls_g.lo tls_m.lo \
  199. - turn.lo ppolicy.lo dds.lo txn.lo ldap_sync.lo stctrl.lo \
  200. + turn.lo ppolicy.lo dds.lo txn.lo ldap_sync.lo stctrl.lo ntlm.lo \
  201. assertion.lo deref.lo ldif.lo fetch.lo
  202. LDAP_INCDIR= ../../include
  203. Index: trunk/libraries/libldap_r/Makefile.in
  204. ===================================================================
  205. --- trunk.orig/libraries/libldap_r/Makefile.in
  206. +++ trunk/libraries/libldap_r/Makefile.in
  207. @@ -29,7 +29,7 @@
  208. init.c options.c print.c string.c util-int.c schema.c \
  209. charray.c os-local.c dnssrv.c utf-8.c utf-8-conv.c \
  210. tls2.c tls_o.c tls_g.c tls_m.c \
  211. - turn.c ppolicy.c dds.c txn.c ldap_sync.c stctrl.c \
  212. + turn.c ppolicy.c dds.c txn.c ldap_sync.c stctrl.c ntlm.c \
  213. assertion.c deref.c ldif.c fetch.c
  214. SRCS = threads.c rdwr.c rmutex.c tpool.c rq.c \
  215. thr_posix.c thr_cthreads.c thr_thr.c thr_lwp.c thr_nt.c \
  216. @@ -47,7 +47,7 @@
  217. init.lo options.lo print.lo string.lo util-int.lo schema.lo \
  218. charray.lo os-local.lo dnssrv.lo utf-8.lo utf-8-conv.lo \
  219. tls2.lo tls_o.lo tls_g.lo tls_m.lo \
  220. - turn.lo ppolicy.lo dds.lo txn.lo ldap_sync.lo stctrl.lo \
  221. + turn.lo ppolicy.lo dds.lo txn.lo ldap_sync.lo stctrl.lo ntlm.lo \
  222. assertion.lo deref.lo ldif.lo fetch.lo
  223. LDAP_INCDIR= ../../include