1 /* 2 * WLDAP32 - LDAP support for Wine 3 * 4 * Copyright 2005 Hans Leidekker 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 19 */ 20 21 #include "config.h" 22 #include "wine/port.h" 23 24 #include <stdarg.h> 25 #ifdef HAVE_LDAP_H 26 #include <ldap.h> 27 #endif 28 29 #include "windef.h" 30 #include "winbase.h" 31 #include "winnls.h" 32 33 #include "winldap_private.h" 34 #include "wldap32.h" 35 #include "wine/debug.h" 36 37 WINE_DEFAULT_DEBUG_CHANNEL(wldap32); 38 39 #ifdef HAVE_LDAP 40 static LDAPMod *nullattrs[] = { NULL }; 41 #endif 42 43 /*********************************************************************** 44 * ldap_addA (WLDAP32.@) 45 * 46 * See ldap_addW. 47 */ 48 ULONG CDECL ldap_addA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[] ) 49 { 50 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED; 51 #ifdef HAVE_LDAP 52 WCHAR *dnW = NULL; 53 LDAPModW **attrsW = NULL; 54 55 ret = WLDAP32_LDAP_NO_MEMORY; 56 57 TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), attrs ); 58 59 if (!ld) return ~0u; 60 61 if (dn) { 62 dnW = strAtoW( dn ); 63 if (!dnW) goto exit; 64 } 65 if (attrs) { 66 attrsW = modarrayAtoW( attrs ); 67 if (!attrsW) goto exit; 68 } 69 70 ret = ldap_addW( ld, dnW, attrsW ); 71 72 exit: 73 strfreeW( dnW ); 74 modarrayfreeW( attrsW ); 75 76 #endif 77 return ret; 78 } 79 80 /*********************************************************************** 81 * ldap_addW (WLDAP32.@) 82 * 83 * Add an entry to a directory tree (asynchronous operation). 84 * 85 * PARAMS 86 * ld [I] Pointer to an LDAP context. 87 * dn [I] DN of the entry to add. 88 * attrs [I] Pointer to an array of LDAPModW structures, each 89 * specifying an attribute and its values to add. 90 * 91 * RETURNS 92 * Success: Message ID of the add operation. 93 * Failure: An LDAP error code. 94 * 95 * NOTES 96 * Call ldap_result with the message ID to get the result of 97 * the operation. Cancel the operation by calling ldap_abandon 98 * with the message ID. 99 */ 100 ULONG CDECL ldap_addW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[] ) 101 { 102 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED; 103 #ifdef HAVE_LDAP 104 char *dnU = NULL; 105 LDAPMod **attrsU = NULL; 106 int msg; 107 108 ret = WLDAP32_LDAP_NO_MEMORY; 109 110 TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), attrs ); 111 112 if (!ld) return WLDAP32_LDAP_PARAM_ERROR; 113 114 if (dn) { 115 dnU = strWtoU( dn ); 116 if (!dnU) goto exit; 117 } 118 if (attrs) { 119 attrsU = modarrayWtoU( attrs ); 120 if (!attrsU) goto exit; 121 } 122 123 ret = ldap_add_ext( ld, dn ? dnU : "", attrs ? attrsU : nullattrs, NULL, NULL, &msg ); 124 125 if (ret == LDAP_SUCCESS) 126 ret = msg; 127 else 128 ret = ~0u; 129 130 exit: 131 strfreeU( dnU ); 132 modarrayfreeU( attrsU ); 133 134 #endif 135 return ret; 136 } 137 138 /*********************************************************************** 139 * ldap_add_extA (WLDAP32.@) 140 * 141 * See ldap_add_extW. 142 */ 143 ULONG CDECL ldap_add_extA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[], 144 PLDAPControlA *serverctrls, PLDAPControlA *clientctrls, ULONG *message ) 145 { 146 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED; 147 #ifdef HAVE_LDAP 148 WCHAR *dnW = NULL; 149 LDAPModW **attrsW = NULL; 150 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL; 151 152 ret = WLDAP32_LDAP_NO_MEMORY; 153 154 TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn), attrs, 155 serverctrls, clientctrls, message ); 156 157 if (!ld) return WLDAP32_LDAP_PARAM_ERROR; 158 159 if (dn) { 160 dnW = strAtoW( dn ); 161 if (!dnW) goto exit; 162 } 163 if (attrs) { 164 attrsW = modarrayAtoW( attrs ); 165 if (!attrsW) goto exit; 166 } 167 if (serverctrls) { 168 serverctrlsW = controlarrayAtoW( serverctrls ); 169 if (!serverctrlsW) goto exit; 170 } 171 if (clientctrls) { 172 clientctrlsW = controlarrayAtoW( clientctrls ); 173 if (!clientctrlsW) goto exit; 174 } 175 176 ret = ldap_add_extW( ld, dnW, attrsW, serverctrlsW, clientctrlsW, message ); 177 178 exit: 179 strfreeW( dnW ); 180 modarrayfreeW( attrsW ); 181 controlarrayfreeW( serverctrlsW ); 182 controlarrayfreeW( clientctrlsW ); 183 184 #endif 185 return ret; 186 } 187 188 /*********************************************************************** 189 * ldap_add_extW (WLDAP32.@) 190 * 191 * Add an entry to a directory tree (asynchronous operation). 192 * 193 * PARAMS 194 * ld [I] Pointer to an LDAP context. 195 * dn [I] DN of the entry to add. 196 * attrs [I] Pointer to an array of LDAPModW structures, each 197 * specifying an attribute and its values to add. 198 * serverctrls [I] Array of LDAP server controls. 199 * clientctrls [I] Array of LDAP client controls. 200 * message [O] Message ID of the add operation. 201 * 202 * RETURNS 203 * Success: LDAP_SUCCESS 204 * Failure: An LDAP error code. 205 * 206 * NOTES 207 * Call ldap_result with the message ID to get the result of 208 * the operation. The serverctrls and clientctrls parameters are 209 * optional and should be set to NULL if not used. 210 */ 211 ULONG CDECL ldap_add_extW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[], 212 PLDAPControlW *serverctrls, PLDAPControlW *clientctrls, ULONG *message ) 213 { 214 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED; 215 #ifdef HAVE_LDAP 216 char *dnU = NULL; 217 LDAPMod **attrsU = NULL; 218 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL; 219 int dummy; 220 221 ret = WLDAP32_LDAP_NO_MEMORY; 222 223 TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_w(dn), attrs, 224 serverctrls, clientctrls, message ); 225 226 if (!ld) return WLDAP32_LDAP_PARAM_ERROR; 227 228 if (dn) { 229 dnU = strWtoU( dn ); 230 if (!dnU) goto exit; 231 } 232 if (attrs) { 233 attrsU = modarrayWtoU( attrs ); 234 if (!attrsU) goto exit; 235 } 236 if (serverctrls) { 237 serverctrlsU = controlarrayWtoU( serverctrls ); 238 if (!serverctrlsU) goto exit; 239 } 240 if (clientctrls) { 241 clientctrlsU = controlarrayWtoU( clientctrls ); 242 if (!clientctrlsU) goto exit; 243 } 244 245 ret = map_error( ldap_add_ext( ld, dn ? dnU : "", attrs ? attrsU : nullattrs, serverctrlsU, 246 clientctrlsU, message ? (int *)message : &dummy )); 247 248 exit: 249 strfreeU( dnU ); 250 modarrayfreeU( attrsU ); 251 controlarrayfreeU( serverctrlsU ); 252 controlarrayfreeU( clientctrlsU ); 253 254 #endif 255 return ret; 256 } 257 258 /*********************************************************************** 259 * ldap_add_ext_sA (WLDAP32.@) 260 * 261 * See ldap_add_ext_sW. 262 */ 263 ULONG CDECL ldap_add_ext_sA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[], 264 PLDAPControlA *serverctrls, PLDAPControlA *clientctrls ) 265 { 266 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED; 267 #ifdef HAVE_LDAP 268 WCHAR *dnW = NULL; 269 LDAPModW **attrsW = NULL; 270 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL; 271 272 ret = WLDAP32_LDAP_NO_MEMORY; 273 274 TRACE( "(%p, %s, %p, %p, %p)\n", ld, debugstr_a(dn), attrs, 275 serverctrls, clientctrls ); 276 277 if (!ld) return WLDAP32_LDAP_PARAM_ERROR; 278 279 if (dn) { 280 dnW = strAtoW( dn ); 281 if (!dnW) goto exit; 282 } 283 if (attrs) { 284 attrsW = modarrayAtoW( attrs ); 285 if (!attrsW) goto exit; 286 } 287 if (serverctrls) { 288 serverctrlsW = controlarrayAtoW( serverctrls ); 289 if (!serverctrlsW) goto exit; 290 } 291 if (clientctrls) { 292 clientctrlsW = controlarrayAtoW( clientctrls ); 293 if (!clientctrlsW) goto exit; 294 } 295 296 ret = ldap_add_ext_sW( ld, dnW, attrsW, serverctrlsW, clientctrlsW ); 297 298 exit: 299 strfreeW( dnW ); 300 modarrayfreeW( attrsW ); 301 controlarrayfreeW( serverctrlsW ); 302 controlarrayfreeW( clientctrlsW ); 303 304 #endif 305 return ret; 306 } 307 308 /*********************************************************************** 309 * ldap_add_ext_sW (WLDAP32.@) 310 * 311 * Add an entry to a directory tree (synchronous operation). 312 * 313 * PARAMS 314 * ld [I] Pointer to an LDAP context. 315 * dn [I] DN of the entry to add. 316 * attrs [I] Pointer to an array of LDAPModW structures, each 317 * specifying an attribute and its values to add. 318 * serverctrls [I] Array of LDAP server controls. 319 * clientctrls [I] Array of LDAP client controls. 320 * 321 * RETURNS 322 * Success: LDAP_SUCCESS 323 * Failure: An LDAP error code. 324 * 325 * NOTES 326 * The serverctrls and clientctrls parameters are optional and 327 * should be set to NULL if not used. 328 */ 329 ULONG CDECL ldap_add_ext_sW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[], 330 PLDAPControlW *serverctrls, PLDAPControlW *clientctrls ) 331 { 332 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED; 333 #ifdef HAVE_LDAP 334 char *dnU = NULL; 335 LDAPMod **attrsU = NULL; 336 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL; 337 338 ret = WLDAP32_LDAP_NO_MEMORY; 339 340 TRACE( "(%p, %s, %p, %p, %p)\n", ld, debugstr_w(dn), attrs, 341 serverctrls, clientctrls ); 342 343 if (!ld) return WLDAP32_LDAP_PARAM_ERROR; 344 345 if (dn) { 346 dnU = strWtoU( dn ); 347 if (!dnU) goto exit; 348 } 349 if (attrs) { 350 attrsU = modarrayWtoU( attrs ); 351 if (!attrsU) goto exit; 352 } 353 if (serverctrls) { 354 serverctrlsU = controlarrayWtoU( serverctrls ); 355 if (!serverctrlsU) goto exit; 356 } 357 if (clientctrls) { 358 clientctrlsU = controlarrayWtoU( clientctrls ); 359 if (!clientctrlsU) goto exit; 360 } 361 362 ret = map_error( ldap_add_ext_s( ld, dn ? dnU : "", attrs ? attrsU : nullattrs, 363 serverctrlsU, clientctrlsU )); 364 365 exit: 366 strfreeU( dnU ); 367 modarrayfreeU( attrsU ); 368 controlarrayfreeU( serverctrlsU ); 369 controlarrayfreeU( clientctrlsU ); 370 371 #endif 372 return ret; 373 } 374 375 /*********************************************************************** 376 * ldap_add_sA (WLDAP32.@) 377 * 378 * See ldap_add_sW. 379 */ 380 ULONG CDECL ldap_add_sA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[] ) 381 { 382 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED; 383 #ifdef HAVE_LDAP 384 WCHAR *dnW = NULL; 385 LDAPModW **attrsW = NULL; 386 387 ret = WLDAP32_LDAP_NO_MEMORY; 388 389 TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), attrs ); 390 391 if (!ld) return WLDAP32_LDAP_PARAM_ERROR; 392 393 if (dn) { 394 dnW = strAtoW( dn ); 395 if (!dnW) goto exit; 396 } 397 if (attrs) { 398 attrsW = modarrayAtoW( attrs ); 399 if (!attrsW) goto exit; 400 } 401 402 ret = ldap_add_sW( ld, dnW, attrsW ); 403 404 exit: 405 strfreeW( dnW ); 406 modarrayfreeW( attrsW ); 407 408 #endif 409 return ret; 410 } 411 412 /*********************************************************************** 413 * ldap_add_sW (WLDAP32.@) 414 * 415 * Add an entry to a directory tree (synchronous operation). 416 * 417 * PARAMS 418 * ld [I] Pointer to an LDAP context. 419 * dn [I] DN of the entry to add. 420 * attrs [I] Pointer to an array of LDAPModW structures, each 421 * specifying an attribute and its values to add. 422 * 423 * RETURNS 424 * Success: LDAP_SUCCESS 425 * Failure: An LDAP error code. 426 */ 427 ULONG CDECL ldap_add_sW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[] ) 428 { 429 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED; 430 #ifdef HAVE_LDAP 431 char *dnU = NULL; 432 LDAPMod **attrsU = NULL; 433 434 ret = WLDAP32_LDAP_NO_MEMORY; 435 436 TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), attrs ); 437 438 if (!ld) return WLDAP32_LDAP_PARAM_ERROR; 439 440 if (dn) { 441 dnU = strWtoU( dn ); 442 if (!dnU) goto exit; 443 } 444 if (attrs) { 445 attrsU = modarrayWtoU( attrs ); 446 if (!attrsU) goto exit; 447 } 448 449 ret = map_error( ldap_add_ext_s( ld, dn ? dnU : "", attrs ? attrsU : nullattrs, NULL, NULL )); 450 451 exit: 452 strfreeU( dnU ); 453 modarrayfreeU( attrsU ); 454 455 #endif 456 return ret; 457 } 458