2005-08-03 12:58:14 +02:00
|
|
|
/*
|
|
|
|
* WLDAP32 - LDAP support for Wine
|
|
|
|
*
|
|
|
|
* Copyright 2005 Hans Leidekker
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-08-03 12:58:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnls.h"
|
2021-04-19 10:04:54 +02:00
|
|
|
#include "winldap.h"
|
2005-08-03 12:58:14 +02:00
|
|
|
|
2011-09-05 17:23:34 +02:00
|
|
|
#include "wine/debug.h"
|
2021-04-15 12:20:06 +02:00
|
|
|
#include "winldap_private.h"
|
2005-08-03 12:58:14 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
|
|
|
|
|
2005-12-02 11:26:19 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_dn2ufnA (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* See ldap_dn2ufnW.
|
|
|
|
*/
|
2021-04-15 12:20:06 +02:00
|
|
|
char * CDECL ldap_dn2ufnA( char *dn )
|
2005-08-03 12:58:14 +02:00
|
|
|
{
|
2021-04-15 12:20:06 +02:00
|
|
|
char *ret;
|
2005-08-03 12:58:14 +02:00
|
|
|
WCHAR *dnW, *retW;
|
|
|
|
|
|
|
|
TRACE( "(%s)\n", debugstr_a(dn) );
|
|
|
|
|
2021-04-15 12:20:06 +02:00
|
|
|
if (!(dnW = strAtoW( dn ))) return NULL;
|
2005-08-03 12:58:14 +02:00
|
|
|
|
|
|
|
retW = ldap_dn2ufnW( dnW );
|
|
|
|
ret = strWtoA( retW );
|
|
|
|
|
2021-04-19 10:04:52 +02:00
|
|
|
free( dnW );
|
2005-08-03 12:58:14 +02:00
|
|
|
ldap_memfreeW( retW );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-12-02 11:26:19 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_dn2ufnW (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Convert a DN to a user-friendly name.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* dn [I] DN to convert.
|
|
|
|
*
|
|
|
|
* RETURNS
|
2021-04-15 12:20:06 +02:00
|
|
|
* Success: Pointer to a string containing the user-friendly name.
|
2005-12-02 11:26:19 +01:00
|
|
|
* Failure: NULL
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Free the string with ldap_memfree.
|
|
|
|
*/
|
2021-04-15 12:20:06 +02:00
|
|
|
WCHAR * CDECL ldap_dn2ufnW( WCHAR *dn )
|
2005-08-03 12:58:14 +02:00
|
|
|
{
|
2021-11-04 11:09:04 +01:00
|
|
|
WCHAR *ret = NULL;
|
2005-08-03 12:58:14 +02:00
|
|
|
char *dnU, *retU;
|
|
|
|
|
|
|
|
TRACE( "(%s)\n", debugstr_w(dn) );
|
|
|
|
|
2021-11-04 11:09:04 +01:00
|
|
|
if ((dnU = strWtoU( dn )))
|
|
|
|
{
|
|
|
|
struct ldap_dn2ufn_params params = { dnU, &retU };
|
|
|
|
LDAP_CALL( ldap_dn2ufn, ¶ms );
|
2005-08-03 12:58:14 +02:00
|
|
|
|
2021-11-04 11:09:04 +01:00
|
|
|
ret = strUtoW( retU );
|
2005-08-03 12:58:14 +02:00
|
|
|
|
2021-11-04 11:09:04 +01:00
|
|
|
free( dnU );
|
|
|
|
LDAP_CALL( ldap_memfree, retU );
|
|
|
|
}
|
2005-08-03 12:58:14 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-12-02 11:26:19 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_explode_dnA (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* See ldap_explode_dnW.
|
|
|
|
*/
|
2021-04-15 12:20:06 +02:00
|
|
|
char ** CDECL ldap_explode_dnA( char *dn, ULONG notypes )
|
2005-08-03 12:58:14 +02:00
|
|
|
{
|
2021-04-15 12:20:06 +02:00
|
|
|
char **ret;
|
2005-08-03 12:58:14 +02:00
|
|
|
WCHAR *dnW, **retW;
|
|
|
|
|
2006-09-30 12:07:23 +02:00
|
|
|
TRACE( "(%s, 0x%08x)\n", debugstr_a(dn), notypes );
|
2005-08-03 12:58:14 +02:00
|
|
|
|
2021-04-15 12:20:06 +02:00
|
|
|
if (!(dnW = strAtoW( dn ))) return NULL;
|
2005-08-03 12:58:14 +02:00
|
|
|
|
|
|
|
retW = ldap_explode_dnW( dnW, notypes );
|
|
|
|
ret = strarrayWtoA( retW );
|
|
|
|
|
2021-04-19 10:04:52 +02:00
|
|
|
free( dnW );
|
2005-08-03 12:58:14 +02:00
|
|
|
ldap_value_freeW( retW );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-12-02 11:26:19 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_explode_dnW (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Break up a DN into its components.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* dn [I] DN to break up.
|
|
|
|
* notypes [I] Remove attribute type information from the components.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Pointer to a NULL-terminated array that contains the DN
|
2021-04-15 12:20:06 +02:00
|
|
|
* components.
|
2005-12-02 11:26:19 +01:00
|
|
|
* Failure: NULL
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Free the string array with ldap_value_free.
|
|
|
|
*/
|
2021-04-15 12:20:06 +02:00
|
|
|
WCHAR ** CDECL ldap_explode_dnW( WCHAR *dn, ULONG notypes )
|
2005-08-03 12:58:14 +02:00
|
|
|
{
|
2021-11-04 11:09:04 +01:00
|
|
|
WCHAR **ret = NULL;
|
2005-08-03 12:58:14 +02:00
|
|
|
char *dnU, **retU;
|
|
|
|
|
2006-09-30 12:07:23 +02:00
|
|
|
TRACE( "(%s, 0x%08x)\n", debugstr_w(dn), notypes );
|
2005-08-03 12:58:14 +02:00
|
|
|
|
2021-11-04 11:09:04 +01:00
|
|
|
if ((dnU = strWtoU( dn )))
|
|
|
|
{
|
|
|
|
struct ldap_explode_dn_params params = { dnU, notypes, &retU };
|
|
|
|
LDAP_CALL( ldap_explode_dn, ¶ms );
|
|
|
|
ret = strarrayUtoW( retU );
|
2005-08-03 12:58:14 +02:00
|
|
|
|
2021-11-04 11:09:04 +01:00
|
|
|
free( dnU );
|
|
|
|
LDAP_CALL( ldap_memvfree, retU );
|
|
|
|
}
|
2005-08-03 12:58:14 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-12-02 11:26:19 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_get_dnA (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* See ldap_get_dnW.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
char * CDECL ldap_get_dnA( LDAP *ld, LDAPMessage *entry )
|
2005-08-03 12:58:14 +02:00
|
|
|
{
|
2021-04-15 12:20:06 +02:00
|
|
|
char *ret;
|
|
|
|
WCHAR *retW;
|
2005-08-03 12:58:14 +02:00
|
|
|
|
|
|
|
TRACE( "(%p, %p)\n", ld, entry );
|
|
|
|
|
|
|
|
if (!ld || !entry) return NULL;
|
|
|
|
|
|
|
|
retW = ldap_get_dnW( ld, entry );
|
|
|
|
|
|
|
|
ret = strWtoA( retW );
|
|
|
|
ldap_memfreeW( retW );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-12-02 11:26:19 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_get_dnW (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Retrieve the DN from a given LDAP message.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* ld [I] Pointer to an LDAP context.
|
|
|
|
* entry [I] LDAPMessage structure to retrieve the DN from.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Pointer to a string that contains the DN.
|
|
|
|
* Failure: NULL
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Free the string with ldap_memfree.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
WCHAR * CDECL ldap_get_dnW( LDAP *ld, LDAPMessage *entry )
|
2005-08-03 12:58:14 +02:00
|
|
|
{
|
2021-11-04 11:09:04 +01:00
|
|
|
WCHAR *ret = NULL;
|
2005-08-03 12:58:14 +02:00
|
|
|
char *retU;
|
|
|
|
|
|
|
|
TRACE( "(%p, %p)\n", ld, entry );
|
|
|
|
|
2021-11-04 11:09:04 +01:00
|
|
|
if (ld && entry)
|
|
|
|
{
|
|
|
|
struct ldap_get_dn_params params = { CTX(ld), MSG(entry), &retU };
|
|
|
|
LDAP_CALL( ldap_get_dn, ¶ms );
|
2005-08-03 12:58:14 +02:00
|
|
|
|
2021-11-04 11:09:04 +01:00
|
|
|
ret = strUtoW( retU );
|
|
|
|
LDAP_CALL( ldap_memfree, retU );
|
|
|
|
}
|
2005-08-03 12:58:14 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-12-02 11:26:19 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_ufn2dnA (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* See ldap_ufn2dnW.
|
|
|
|
*/
|
2021-04-15 12:20:06 +02:00
|
|
|
ULONG CDECL ldap_ufn2dnA( char *ufn, char **dn )
|
2005-08-03 12:58:14 +02:00
|
|
|
{
|
2021-04-15 12:20:06 +02:00
|
|
|
ULONG ret;
|
|
|
|
WCHAR *ufnW = NULL, *dnW = NULL;
|
2005-08-03 12:58:14 +02:00
|
|
|
|
|
|
|
TRACE( "(%s, %p)\n", debugstr_a(ufn), dn );
|
|
|
|
|
2021-04-19 10:04:54 +02:00
|
|
|
if (!dn) return LDAP_PARAM_ERROR;
|
2005-08-03 12:58:14 +02:00
|
|
|
|
|
|
|
*dn = NULL;
|
2021-04-19 10:04:54 +02:00
|
|
|
if (ufn && !(ufnW = strAtoW( ufn ))) return LDAP_NO_MEMORY;
|
2005-08-03 12:58:14 +02:00
|
|
|
|
|
|
|
ret = ldap_ufn2dnW( ufnW, &dnW );
|
2021-04-15 12:20:06 +02:00
|
|
|
if (dnW)
|
|
|
|
{
|
|
|
|
char *str;
|
2021-04-19 10:04:54 +02:00
|
|
|
if (!(str = strWtoA( dnW ))) ret = LDAP_NO_MEMORY;
|
2021-04-15 12:20:06 +02:00
|
|
|
else *dn = str;
|
2005-08-03 12:58:14 +02:00
|
|
|
}
|
|
|
|
|
2021-04-19 10:04:52 +02:00
|
|
|
free( ufnW );
|
2005-08-03 12:58:14 +02:00
|
|
|
ldap_memfreeW( dnW );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-12-02 11:26:19 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_ufn2dnW (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Convert a user-friendly name to a DN.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* ufn [I] User-friendly name to convert.
|
2021-04-15 12:20:06 +02:00
|
|
|
* dn [O] Receives a pointer to a string containing the DN.
|
2005-12-02 11:26:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: LDAP_SUCCESS
|
|
|
|
* Failure: An LDAP error code.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Free the string with ldap_memfree.
|
|
|
|
*/
|
2021-04-15 12:20:06 +02:00
|
|
|
ULONG CDECL ldap_ufn2dnW( WCHAR *ufn, WCHAR **dn )
|
2005-08-03 12:58:14 +02:00
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
ULONG ret = LDAP_SUCCESS;
|
2005-08-03 12:58:14 +02:00
|
|
|
char *ufnU = NULL;
|
|
|
|
|
|
|
|
TRACE( "(%s, %p)\n", debugstr_w(ufn), dn );
|
|
|
|
|
2021-04-19 10:04:54 +02:00
|
|
|
if (!dn) return LDAP_PARAM_ERROR;
|
2005-08-03 12:58:14 +02:00
|
|
|
|
|
|
|
*dn = NULL;
|
2021-04-15 12:20:06 +02:00
|
|
|
if (ufn)
|
|
|
|
{
|
|
|
|
WCHAR *str;
|
2021-04-19 10:04:54 +02:00
|
|
|
if (!(ufnU = strWtoU( ufn ))) return LDAP_NO_MEMORY;
|
2005-08-03 12:58:14 +02:00
|
|
|
|
|
|
|
/* FIXME: do more than just a copy */
|
2021-04-19 10:04:54 +02:00
|
|
|
if (!(str = strUtoW( ufnU ))) ret = LDAP_NO_MEMORY;
|
2021-04-15 12:20:06 +02:00
|
|
|
else *dn = str;
|
2005-08-03 12:58:14 +02:00
|
|
|
}
|
|
|
|
|
2021-04-19 10:04:52 +02:00
|
|
|
free( ufnU );
|
2005-08-03 12:58:14 +02:00
|
|
|
return ret;
|
|
|
|
}
|