2007-12-21 20:57:34 +03:00
/*
Unix SMB / CIFS implementation .
2010-02-13 15:42:56 +03:00
Winbind client asynchronous API , utility functions
2007-12-21 20:57:34 +03:00
2008-04-17 20:06:10 +04:00
Copyright ( C ) Gerald ( Jerry ) Carter 2007 - 2008
2007-12-21 20:57:34 +03:00
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 3 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
Library General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
/* Required Headers */
2009-06-05 00:32:21 +04:00
# include "replace.h"
2007-12-21 20:57:34 +03:00
# include "libwbclient.h"
2010-04-05 00:26:40 +04:00
# include "../winbind_client.h"
2007-12-21 20:57:34 +03:00
/** @brief Ping winbindd to see if the daemon is running
2015-02-22 01:30:11 +03:00
*
* @ param * ctx wbclient Context
2007-12-21 20:57:34 +03:00
*
* @ return # wbcErr
* */
2021-10-12 15:30:09 +03:00
_PUBLIC_
2015-02-22 01:30:11 +03:00
wbcErr wbcCtxPing ( struct wbcContext * ctx )
2007-12-21 20:57:34 +03:00
{
2007-12-23 02:33:44 +03:00
struct winbindd_request request ;
struct winbindd_response response ;
/* Initialize request */
ZERO_STRUCT ( request ) ;
ZERO_STRUCT ( response ) ;
2015-02-22 01:30:11 +03:00
return wbcRequestResponse ( ctx , WINBINDD_PING , & request , & response ) ;
}
2021-10-12 15:30:09 +03:00
_PUBLIC_
2015-02-22 01:30:11 +03:00
wbcErr wbcPing ( void )
{
return wbcCtxPing ( NULL ) ;
2007-12-21 20:57:34 +03:00
}
2010-04-03 16:59:07 +04:00
static void wbcInterfaceDetailsDestructor ( void * ptr )
{
struct wbcInterfaceDetails * i = ( struct wbcInterfaceDetails * ) ptr ;
free ( i - > winbind_version ) ;
free ( i - > netbios_name ) ;
free ( i - > netbios_domain ) ;
free ( i - > dns_domain ) ;
}
2009-02-15 13:01:44 +03:00
/**
* @ brief Query useful information about the winbind service
*
* @ param * _details pointer to hold the struct wbcInterfaceDetails
*
* @ return # wbcErr
*/
2021-10-12 15:30:09 +03:00
_PUBLIC_
2015-02-22 01:30:11 +03:00
wbcErr wbcCtxInterfaceDetails ( struct wbcContext * ctx ,
struct wbcInterfaceDetails * * _details )
2008-03-28 18:52:18 +03:00
{
wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE ;
struct wbcInterfaceDetails * info ;
struct wbcDomainInfo * domain = NULL ;
struct winbindd_request request ;
struct winbindd_response response ;
/* Initialize request */
ZERO_STRUCT ( request ) ;
ZERO_STRUCT ( response ) ;
2010-04-03 16:59:07 +04:00
info = ( struct wbcInterfaceDetails * ) wbcAllocateMemory (
2010-11-27 21:07:40 +03:00
1 , sizeof ( struct wbcInterfaceDetails ) ,
2010-04-03 16:59:07 +04:00
wbcInterfaceDetailsDestructor ) ;
2008-03-28 18:52:18 +03:00
BAIL_ON_PTR_ERROR ( info , wbc_status ) ;
/* first the interface version */
2015-02-22 01:30:11 +03:00
wbc_status = wbcRequestResponse ( ctx , WINBINDD_INTERFACE_VERSION ,
NULL , & response ) ;
2008-03-28 18:52:18 +03:00
BAIL_ON_WBC_ERROR ( wbc_status ) ;
info - > interface_version = response . data . interface_version ;
/* then the samba version and the winbind separator */
2015-02-22 01:30:11 +03:00
wbc_status = wbcRequestResponse ( ctx , WINBINDD_INFO , NULL , & response ) ;
2008-03-28 18:52:18 +03:00
BAIL_ON_WBC_ERROR ( wbc_status ) ;
2010-04-03 16:59:07 +04:00
info - > winbind_version = strdup ( response . data . info . samba_version ) ;
2008-03-28 18:52:18 +03:00
BAIL_ON_PTR_ERROR ( info - > winbind_version , wbc_status ) ;
info - > winbind_separator = response . data . info . winbind_separator ;
/* then the local netbios name */
2015-02-22 01:30:11 +03:00
wbc_status = wbcRequestResponse ( ctx , WINBINDD_NETBIOS_NAME ,
NULL , & response ) ;
2008-03-28 18:52:18 +03:00
BAIL_ON_WBC_ERROR ( wbc_status ) ;
2010-04-03 16:59:07 +04:00
info - > netbios_name = strdup ( response . data . netbios_name ) ;
2008-03-28 18:52:18 +03:00
BAIL_ON_PTR_ERROR ( info - > netbios_name , wbc_status ) ;
/* then the local workgroup name */
2015-02-22 01:30:11 +03:00
wbc_status = wbcRequestResponse ( ctx , WINBINDD_DOMAIN_NAME ,
NULL , & response ) ;
2008-03-28 18:52:18 +03:00
BAIL_ON_WBC_ERROR ( wbc_status ) ;
2010-04-03 16:59:07 +04:00
info - > netbios_domain = strdup ( response . data . domain_name ) ;
2008-03-28 18:52:18 +03:00
BAIL_ON_PTR_ERROR ( info - > netbios_domain , wbc_status ) ;
2015-02-22 01:30:11 +03:00
wbc_status = wbcCtxDomainInfo ( ctx , info - > netbios_domain , & domain ) ;
2008-03-28 18:52:18 +03:00
if ( wbc_status = = WBC_ERR_DOMAIN_NOT_FOUND ) {
/* maybe it's a standalone server */
domain = NULL ;
} else {
BAIL_ON_WBC_ERROR ( wbc_status ) ;
}
if ( domain ) {
2010-04-03 16:59:07 +04:00
info - > dns_domain = strdup ( domain - > dns_name ) ;
2008-03-28 18:52:18 +03:00
wbcFreeMemory ( domain ) ;
BAIL_ON_PTR_ERROR ( info - > dns_domain , wbc_status ) ;
} else {
info - > dns_domain = NULL ;
}
* _details = info ;
info = NULL ;
wbc_status = WBC_ERR_SUCCESS ;
done :
2010-04-03 16:59:07 +04:00
wbcFreeMemory ( info ) ;
2008-03-28 18:52:18 +03:00
return wbc_status ;
}
2021-10-12 15:30:09 +03:00
_PUBLIC_
2015-02-22 01:30:11 +03:00
wbcErr wbcInterfaceDetails ( struct wbcInterfaceDetails * * _details )
{
return wbcCtxInterfaceDetails ( NULL , _details ) ;
}
2010-04-03 17:02:40 +04:00
static void wbcDomainInfoDestructor ( void * ptr )
{
struct wbcDomainInfo * i = ( struct wbcDomainInfo * ) ptr ;
free ( i - > short_name ) ;
free ( i - > dns_name ) ;
}
2009-02-14 12:06:05 +03:00
/** @brief Lookup the current status of a trusted domain, sync wrapper
*
* @ param domain Domain to query
* @ param * dinfo Pointer to returned struct wbcDomainInfo
*
* @ return # wbcErr
*/
2008-03-28 18:52:18 +03:00
2021-10-12 15:30:09 +03:00
_PUBLIC_
2015-02-22 01:30:11 +03:00
wbcErr wbcCtxDomainInfo ( struct wbcContext * ctx ,
const char * domain ,
struct wbcDomainInfo * * dinfo )
2007-12-21 20:57:34 +03:00
{
struct winbindd_request request ;
struct winbindd_response response ;
wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE ;
struct wbcDomainInfo * info = NULL ;
2008-01-03 14:10:27 +03:00
2007-12-21 20:57:34 +03:00
if ( ! domain | | ! dinfo ) {
wbc_status = WBC_ERR_INVALID_PARAM ;
BAIL_ON_WBC_ERROR ( wbc_status ) ;
}
/* Initialize request */
ZERO_STRUCT ( request ) ;
ZERO_STRUCT ( response ) ;
2008-01-03 14:10:27 +03:00
strncpy ( request . domain_name , domain ,
2007-12-21 20:57:34 +03:00
sizeof ( request . domain_name ) - 1 ) ;
2015-02-22 01:30:11 +03:00
wbc_status = wbcRequestResponse ( ctx , WINBINDD_DOMAIN_INFO ,
2007-12-21 20:57:34 +03:00
& request ,
& response ) ;
BAIL_ON_WBC_ERROR ( wbc_status ) ;
2010-04-03 17:02:40 +04:00
info = ( struct wbcDomainInfo * ) wbcAllocateMemory (
2010-11-27 21:07:40 +03:00
1 , sizeof ( struct wbcDomainInfo ) , wbcDomainInfoDestructor ) ;
2007-12-21 20:57:34 +03:00
BAIL_ON_PTR_ERROR ( info , wbc_status ) ;
2010-04-03 17:02:40 +04:00
info - > short_name = strdup ( response . data . domain_info . name ) ;
2007-12-21 20:57:34 +03:00
BAIL_ON_PTR_ERROR ( info - > short_name , wbc_status ) ;
2010-04-03 17:02:40 +04:00
info - > dns_name = strdup ( response . data . domain_info . alt_name ) ;
2007-12-21 20:57:34 +03:00
BAIL_ON_PTR_ERROR ( info - > dns_name , wbc_status ) ;
2008-01-03 14:10:27 +03:00
wbc_status = wbcStringToSid ( response . data . domain_info . sid ,
2007-12-21 20:57:34 +03:00
& info - > sid ) ;
BAIL_ON_WBC_ERROR ( wbc_status ) ;
if ( response . data . domain_info . native_mode )
2008-04-22 21:22:59 +04:00
info - > domain_flags | = WBC_DOMINFO_DOMAIN_NATIVE ;
2007-12-21 20:57:34 +03:00
if ( response . data . domain_info . active_directory )
2008-04-22 21:22:59 +04:00
info - > domain_flags | = WBC_DOMINFO_DOMAIN_AD ;
2007-12-21 20:57:34 +03:00
if ( response . data . domain_info . primary )
2008-04-22 21:22:59 +04:00
info - > domain_flags | = WBC_DOMINFO_DOMAIN_PRIMARY ;
2007-12-21 20:57:34 +03:00
* dinfo = info ;
2010-04-03 17:02:40 +04:00
info = NULL ;
2008-01-03 14:10:27 +03:00
2007-12-21 20:57:34 +03:00
wbc_status = WBC_ERR_SUCCESS ;
done :
2010-04-03 17:02:40 +04:00
wbcFreeMemory ( info ) ;
2007-12-21 20:57:34 +03:00
return wbc_status ;
}
2008-04-14 11:31:46 +04:00
2021-10-12 15:30:09 +03:00
_PUBLIC_
2015-02-22 01:30:11 +03:00
wbcErr wbcDomainInfo ( const char * domain , struct wbcDomainInfo * * dinfo )
{
return wbcCtxDomainInfo ( NULL , domain , dinfo ) ;
}
2011-01-10 19:25:00 +03:00
/* Get the list of current DCs */
2021-10-12 15:30:09 +03:00
_PUBLIC_
2015-02-22 01:30:11 +03:00
wbcErr wbcCtxDcInfo ( struct wbcContext * ctx ,
const char * domain , size_t * num_dcs ,
const char * * * dc_names , const char * * * dc_ips )
2011-01-10 19:25:00 +03:00
{
struct winbindd_request request ;
struct winbindd_response response ;
const char * * names = NULL ;
const char * * ips = NULL ;
wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE ;
size_t extra_len ;
int i ;
char * p ;
/* Initialise request */
ZERO_STRUCT ( request ) ;
ZERO_STRUCT ( response ) ;
if ( domain ! = NULL ) {
strncpy ( request . domain_name , domain ,
sizeof ( request . domain_name ) - 1 ) ;
}
2015-02-22 01:30:11 +03:00
wbc_status = wbcRequestResponse ( ctx , WINBINDD_DC_INFO ,
2011-01-10 19:25:00 +03:00
& request , & response ) ;
BAIL_ON_WBC_ERROR ( wbc_status ) ;
names = wbcAllocateStringArray ( response . data . num_entries ) ;
BAIL_ON_PTR_ERROR ( names , wbc_status ) ;
ips = wbcAllocateStringArray ( response . data . num_entries ) ;
2011-03-27 22:57:45 +04:00
BAIL_ON_PTR_ERROR ( ips , wbc_status ) ;
2011-01-10 19:25:00 +03:00
wbc_status = WBC_ERR_INVALID_RESPONSE ;
p = ( char * ) response . extra_data . data ;
if ( response . length < ( sizeof ( struct winbindd_response ) + 1 ) ) {
goto done ;
}
extra_len = response . length - sizeof ( struct winbindd_response ) ;
if ( p [ extra_len - 1 ] ! = ' \0 ' ) {
goto done ;
}
for ( i = 0 ; i < response . data . num_entries ; i + + ) {
char * q ;
q = strchr ( p , ' \n ' ) ;
if ( q = = NULL ) {
goto done ;
}
names [ i ] = strndup ( p , q - p ) ;
BAIL_ON_PTR_ERROR ( names [ i ] , wbc_status ) ;
p = q + 1 ;
q = strchr ( p , ' \n ' ) ;
if ( q = = NULL ) {
goto done ;
}
ips [ i ] = strndup ( p , q - p ) ;
BAIL_ON_PTR_ERROR ( ips [ i ] , wbc_status ) ;
p = q + 1 ;
}
if ( p [ 0 ] ! = ' \0 ' ) {
goto done ;
}
wbc_status = WBC_ERR_SUCCESS ;
done :
if ( response . extra_data . data )
free ( response . extra_data . data ) ;
if ( WBC_ERROR_IS_OK ( wbc_status ) ) {
* num_dcs = response . data . num_entries ;
* dc_names = names ;
names = NULL ;
* dc_ips = ips ;
ips = NULL ;
}
wbcFreeMemory ( names ) ;
wbcFreeMemory ( ips ) ;
return wbc_status ;
}
2008-04-14 11:31:46 +04:00
2021-10-12 15:30:09 +03:00
_PUBLIC_
2015-02-22 01:30:11 +03:00
wbcErr wbcDcInfo ( const char * domain , size_t * num_dcs ,
const char * * * dc_names , const char * * * dc_ips )
{
return wbcCtxDcInfo ( NULL , domain , num_dcs , dc_names , dc_ips ) ;
}
2008-12-09 15:18:06 +03:00
/* Resolve a NetbiosName via WINS */
2021-10-12 15:30:09 +03:00
_PUBLIC_
2015-02-22 01:30:11 +03:00
wbcErr wbcCtxResolveWinsByName ( struct wbcContext * ctx ,
const char * name , char * * ip )
2008-04-14 11:31:46 +04:00
{
struct winbindd_request request ;
struct winbindd_response response ;
wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE ;
2008-04-21 00:13:40 +04:00
char * ipaddr ;
2008-04-14 11:31:46 +04:00
ZERO_STRUCT ( request ) ;
ZERO_STRUCT ( response ) ;
/* Send request */
strncpy ( request . data . winsreq , name ,
sizeof ( request . data . winsreq ) - 1 ) ;
2015-02-22 01:30:11 +03:00
wbc_status = wbcRequestResponse ( ctx , WINBINDD_WINS_BYNAME ,
2008-04-14 11:31:46 +04:00
& request ,
& response ) ;
BAIL_ON_WBC_ERROR ( wbc_status ) ;
/* Display response */
2010-04-03 17:03:20 +04:00
ipaddr = wbcStrDup ( response . data . winsresp ) ;
2008-04-14 11:31:46 +04:00
BAIL_ON_PTR_ERROR ( ipaddr , wbc_status ) ;
* ip = ipaddr ;
wbc_status = WBC_ERR_SUCCESS ;
done :
return wbc_status ;
}
2021-10-12 15:30:09 +03:00
_PUBLIC_
2015-02-22 01:30:11 +03:00
wbcErr wbcResolveWinsByName ( const char * name , char * * ip )
{
return wbcCtxResolveWinsByName ( NULL , name , ip ) ;
}
2008-12-09 15:18:06 +03:00
/* Resolve an IP address via WINS into a NetbiosName */
2021-10-12 15:30:09 +03:00
_PUBLIC_
2015-02-22 01:30:11 +03:00
wbcErr wbcCtxResolveWinsByIP ( struct wbcContext * ctx ,
const char * ip , char * * name )
2008-04-14 11:31:46 +04:00
{
struct winbindd_request request ;
struct winbindd_response response ;
wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE ;
2008-04-21 00:17:39 +04:00
char * name_str ;
2008-04-14 11:31:46 +04:00
ZERO_STRUCT ( request ) ;
ZERO_STRUCT ( response ) ;
/* Send request */
strncpy ( request . data . winsreq , ip ,
sizeof ( request . data . winsreq ) - 1 ) ;
2015-02-22 01:30:11 +03:00
wbc_status = wbcRequestResponse ( ctx , WINBINDD_WINS_BYIP ,
2008-04-14 11:31:46 +04:00
& request ,
& response ) ;
BAIL_ON_WBC_ERROR ( wbc_status ) ;
/* Display response */
2010-04-03 17:03:49 +04:00
name_str = wbcStrDup ( response . data . winsresp ) ;
2008-04-14 11:31:46 +04:00
BAIL_ON_PTR_ERROR ( name_str , wbc_status ) ;
* name = name_str ;
wbc_status = WBC_ERR_SUCCESS ;
done :
return wbc_status ;
}
2008-04-17 20:06:10 +04:00
2021-10-12 15:30:09 +03:00
_PUBLIC_
2015-02-22 01:30:11 +03:00
wbcErr wbcResolveWinsByIP ( const char * ip , char * * name )
{
return wbcCtxResolveWinsByIP ( NULL , ip , name ) ;
}
2008-04-17 20:06:10 +04:00
/**
*/
2010-04-04 00:11:08 +04:00
static wbcErr process_domain_info_string ( struct wbcDomainInfo * info ,
2008-04-17 20:06:10 +04:00
char * info_string )
{
wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE ;
char * r = NULL ;
char * s = NULL ;
r = info_string ;
/* Short Name */
if ( ( s = strchr ( r , ' \\ ' ) ) = = NULL ) {
wbc_status = WBC_ERR_INVALID_RESPONSE ;
BAIL_ON_WBC_ERROR ( wbc_status ) ;
}
* s = ' \0 ' ;
s + + ;
2010-04-04 00:11:08 +04:00
info - > short_name = strdup ( r ) ;
2008-04-17 20:06:10 +04:00
BAIL_ON_PTR_ERROR ( info - > short_name , wbc_status ) ;
/* DNS Name */
r = s ;
if ( ( s = strchr ( r , ' \\ ' ) ) = = NULL ) {
wbc_status = WBC_ERR_INVALID_RESPONSE ;
BAIL_ON_WBC_ERROR ( wbc_status ) ;
}
* s = ' \0 ' ;
s + + ;
2010-04-04 00:11:08 +04:00
info - > dns_name = strdup ( r ) ;
2008-04-17 20:06:10 +04:00
BAIL_ON_PTR_ERROR ( info - > dns_name , wbc_status ) ;
/* SID */
r = s ;
if ( ( s = strchr ( r , ' \\ ' ) ) = = NULL ) {
wbc_status = WBC_ERR_INVALID_RESPONSE ;
BAIL_ON_WBC_ERROR ( wbc_status ) ;
}
* s = ' \0 ' ;
s + + ;
wbc_status = wbcStringToSid ( r , & info - > sid ) ;
BAIL_ON_WBC_ERROR ( wbc_status ) ;
2008-12-16 11:30:16 +03:00
2008-04-17 20:06:10 +04:00
/* Trust type */
r = s ;
if ( ( s = strchr ( r , ' \\ ' ) ) = = NULL ) {
wbc_status = WBC_ERR_INVALID_RESPONSE ;
BAIL_ON_WBC_ERROR ( wbc_status ) ;
}
* s = ' \0 ' ;
s + + ;
2018-03-01 13:43:39 +03:00
if ( strncmp ( r , " Routed " , strlen ( " Routed " ) ) = = 0 ) {
2017-12-13 18:01:50 +03:00
info - > trust_type = WBC_DOMINFO_TRUSTTYPE_NONE ;
info - > trust_routing = strdup ( r ) ;
BAIL_ON_PTR_ERROR ( info - > trust_routing , wbc_status ) ;
} else if ( strcmp ( r , " Local " ) = = 0 ) {
info - > trust_type = WBC_DOMINFO_TRUSTTYPE_LOCAL ;
} else if ( strcmp ( r , " Workstation " ) = = 0 ) {
info - > trust_type = WBC_DOMINFO_TRUSTTYPE_WKSTA ;
} else if ( strcmp ( r , " RWDC " ) = = 0 ) {
info - > trust_type = WBC_DOMINFO_TRUSTTYPE_RWDC ;
} else if ( strcmp ( r , " RODC " ) = = 0 ) {
info - > trust_type = WBC_DOMINFO_TRUSTTYPE_RODC ;
} else if ( strcmp ( r , " PDC " ) = = 0 ) {
info - > trust_type = WBC_DOMINFO_TRUSTTYPE_PDC ;
2008-04-17 20:06:10 +04:00
} else if ( strcmp ( r , " External " ) = = 0 ) {
info - > trust_type = WBC_DOMINFO_TRUSTTYPE_EXTERNAL ;
} else if ( strcmp ( r , " Forest " ) = = 0 ) {
info - > trust_type = WBC_DOMINFO_TRUSTTYPE_FOREST ;
} else if ( strcmp ( r , " In Forest " ) = = 0 ) {
info - > trust_type = WBC_DOMINFO_TRUSTTYPE_IN_FOREST ;
} else {
wbc_status = WBC_ERR_INVALID_RESPONSE ;
BAIL_ON_WBC_ERROR ( wbc_status ) ;
}
/* Transitive */
r = s ;
if ( ( s = strchr ( r , ' \\ ' ) ) = = NULL ) {
wbc_status = WBC_ERR_INVALID_RESPONSE ;
BAIL_ON_WBC_ERROR ( wbc_status ) ;
}
* s = ' \0 ' ;
s + + ;
if ( strcmp ( r , " Yes " ) = = 0 ) {
2008-12-16 11:30:16 +03:00
info - > trust_flags | = WBC_DOMINFO_TRUST_TRANSITIVE ;
2008-04-17 20:06:10 +04:00
}
2008-12-16 11:30:16 +03:00
2008-04-17 20:06:10 +04:00
/* Incoming */
r = s ;
if ( ( s = strchr ( r , ' \\ ' ) ) = = NULL ) {
wbc_status = WBC_ERR_INVALID_RESPONSE ;
BAIL_ON_WBC_ERROR ( wbc_status ) ;
}
* s = ' \0 ' ;
s + + ;
if ( strcmp ( r , " Yes " ) = = 0 ) {
2008-12-16 11:30:16 +03:00
info - > trust_flags | = WBC_DOMINFO_TRUST_INCOMING ;
2008-04-17 20:06:10 +04:00
}
/* Outgoing */
r = s ;
2008-04-23 00:29:53 +04:00
if ( ( s = strchr ( r , ' \\ ' ) ) = = NULL ) {
2008-04-17 20:06:10 +04:00
wbc_status = WBC_ERR_INVALID_RESPONSE ;
BAIL_ON_WBC_ERROR ( wbc_status ) ;
}
2008-04-23 00:29:53 +04:00
* s = ' \0 ' ;
s + + ;
2008-04-17 20:06:10 +04:00
if ( strcmp ( r , " Yes " ) = = 0 ) {
2008-12-16 11:30:16 +03:00
info - > trust_flags | = WBC_DOMINFO_TRUST_OUTGOING ;
2008-04-17 20:06:10 +04:00
}
2008-04-23 00:29:53 +04:00
/* Online/Offline status */
r = s ;
if ( strcmp ( r , " Offline " ) = = 0 ) {
info - > domain_flags | = WBC_DOMINFO_DOMAIN_OFFLINE ;
}
2008-04-17 20:06:10 +04:00
wbc_status = WBC_ERR_SUCCESS ;
done :
return wbc_status ;
}
2010-04-04 00:11:08 +04:00
static void wbcDomainInfoListDestructor ( void * ptr )
{
struct wbcDomainInfo * i = ( struct wbcDomainInfo * ) ptr ;
while ( i - > short_name ! = NULL ) {
free ( i - > short_name ) ;
free ( i - > dns_name ) ;
i + = 1 ;
}
}
2008-12-09 15:18:06 +03:00
/* Enumerate the domain trusts known by Winbind */
2021-10-12 15:30:09 +03:00
_PUBLIC_
2015-02-22 01:30:11 +03:00
wbcErr wbcCtxListTrusts ( struct wbcContext * ctx ,
struct wbcDomainInfo * * domains , size_t * num_domains )
2008-04-17 20:06:10 +04:00
{
struct winbindd_response response ;
wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE ;
char * p = NULL ;
2008-12-16 11:30:16 +03:00
char * extra_data = NULL ;
2008-04-17 20:06:10 +04:00
struct wbcDomainInfo * d_list = NULL ;
int i = 0 ;
2008-12-16 11:30:16 +03:00
2008-04-17 20:06:10 +04:00
* domains = NULL ;
* num_domains = 0 ;
2008-12-16 11:30:16 +03:00
2008-04-17 20:06:10 +04:00
ZERO_STRUCT ( response ) ;
/* Send request */
2015-02-22 01:30:11 +03:00
wbc_status = wbcRequestResponse ( ctx , WINBINDD_LIST_TRUSTDOM ,
2008-04-17 20:06:10 +04:00
NULL ,
& response ) ;
BAIL_ON_WBC_ERROR ( wbc_status ) ;
/* Decode the response */
p = ( char * ) response . extra_data . data ;
2009-08-16 00:04:13 +04:00
if ( ( p = = NULL ) | | ( strlen ( p ) = = 0 ) ) {
2008-05-13 21:52:20 +04:00
/* We should always at least get back our
2008-04-17 20:06:10 +04:00
own SAM domain */
2008-12-16 11:30:16 +03:00
2008-04-17 20:06:10 +04:00
wbc_status = WBC_ERR_DOMAIN_NOT_FOUND ;
BAIL_ON_WBC_ERROR ( wbc_status ) ;
}
2010-04-04 00:11:08 +04:00
d_list = ( struct wbcDomainInfo * ) wbcAllocateMemory (
2010-11-27 21:07:40 +03:00
response . data . num_entries + 1 , sizeof ( struct wbcDomainInfo ) ,
2010-04-04 00:11:08 +04:00
wbcDomainInfoListDestructor ) ;
2008-04-17 20:06:10 +04:00
BAIL_ON_PTR_ERROR ( d_list , wbc_status ) ;
extra_data = strdup ( ( char * ) response . extra_data . data ) ;
BAIL_ON_PTR_ERROR ( extra_data , wbc_status ) ;
2008-12-16 11:30:16 +03:00
p = extra_data ;
2008-04-17 20:06:10 +04:00
/* Outer loop processes the list of domain information */
2010-04-04 00:11:08 +04:00
for ( i = 0 ; i < response . data . num_entries & & p ; i + + ) {
2008-04-17 20:06:10 +04:00
char * next = strchr ( p , ' \n ' ) ;
2008-12-16 11:30:16 +03:00
2008-04-17 20:06:10 +04:00
if ( next ) {
* next = ' \0 ' ;
next + + ;
}
2010-04-04 00:11:08 +04:00
wbc_status = process_domain_info_string ( & d_list [ i ] , p ) ;
2008-04-17 20:06:10 +04:00
BAIL_ON_WBC_ERROR ( wbc_status ) ;
p = next ;
}
2008-12-16 11:30:16 +03:00
* domains = d_list ;
2010-04-05 00:49:38 +04:00
d_list = NULL ;
2008-12-16 11:30:16 +03:00
* num_domains = i ;
2008-04-17 20:06:10 +04:00
done :
2010-04-05 00:26:40 +04:00
winbindd_free_response ( & response ) ;
2010-04-04 00:11:08 +04:00
wbcFreeMemory ( d_list ) ;
2010-04-05 00:49:38 +04:00
free ( extra_data ) ;
2008-04-17 20:06:10 +04:00
return wbc_status ;
}
2008-05-13 21:52:20 +04:00
2021-10-12 15:30:09 +03:00
_PUBLIC_
2015-02-22 01:30:11 +03:00
wbcErr wbcListTrusts ( struct wbcDomainInfo * * domains , size_t * num_domains )
{
return wbcCtxListTrusts ( NULL , domains , num_domains ) ;
}
2010-04-17 21:57:11 +04:00
static void wbcDomainControllerInfoDestructor ( void * ptr )
{
struct wbcDomainControllerInfo * i =
( struct wbcDomainControllerInfo * ) ptr ;
free ( i - > dc_name ) ;
}
2008-12-09 15:18:06 +03:00
/* Enumerate the domain trusts known by Winbind */
2021-10-12 15:30:09 +03:00
_PUBLIC_
2015-02-22 01:30:11 +03:00
wbcErr wbcCtxLookupDomainController ( struct wbcContext * ctx ,
const char * domain , uint32_t flags ,
struct wbcDomainControllerInfo * * dc_info )
2008-05-13 21:52:20 +04:00
{
wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE ;
struct winbindd_request request ;
struct winbindd_response response ;
struct wbcDomainControllerInfo * dc = NULL ;
/* validate input params */
if ( ! domain | | ! dc_info ) {
wbc_status = WBC_ERR_INVALID_PARAM ;
BAIL_ON_WBC_ERROR ( wbc_status ) ;
}
ZERO_STRUCT ( request ) ;
ZERO_STRUCT ( response ) ;
2009-10-19 18:55:15 +04:00
strncpy ( request . data . dsgetdcname . domain_name , domain ,
sizeof ( request . data . dsgetdcname . domain_name ) - 1 ) ;
2008-05-13 21:52:20 +04:00
request . flags = flags ;
2010-04-17 21:57:11 +04:00
dc = ( struct wbcDomainControllerInfo * ) wbcAllocateMemory (
2010-11-27 21:07:40 +03:00
1 , sizeof ( struct wbcDomainControllerInfo ) ,
2010-04-17 21:57:11 +04:00
wbcDomainControllerInfoDestructor ) ;
2008-05-13 21:52:20 +04:00
BAIL_ON_PTR_ERROR ( dc , wbc_status ) ;
/* Send request */
2015-02-22 01:30:11 +03:00
wbc_status = wbcRequestResponse ( ctx , WINBINDD_DSGETDCNAME ,
2008-05-13 21:52:20 +04:00
& request ,
& response ) ;
BAIL_ON_WBC_ERROR ( wbc_status ) ;
2010-04-17 21:57:11 +04:00
dc - > dc_name = strdup ( response . data . dsgetdcname . dc_unc ) ;
2008-05-13 21:52:20 +04:00
BAIL_ON_PTR_ERROR ( dc - > dc_name , wbc_status ) ;
* dc_info = dc ;
2010-04-17 21:57:11 +04:00
dc = NULL ;
2008-05-13 21:52:20 +04:00
done :
2010-04-17 21:57:11 +04:00
wbcFreeMemory ( dc ) ;
2008-05-13 21:52:20 +04:00
return wbc_status ;
}
2008-09-27 05:29:01 +04:00
2021-10-12 15:30:09 +03:00
_PUBLIC_
2015-02-22 01:30:11 +03:00
wbcErr wbcLookupDomainController ( const char * domain , uint32_t flags ,
struct wbcDomainControllerInfo * * dc_info )
{
return wbcCtxLookupDomainController ( NULL , domain , flags , dc_info ) ;
}
2010-04-03 21:57:48 +04:00
static void wbcDomainControllerInfoExDestructor ( void * ptr )
{
struct wbcDomainControllerInfoEx * i =
( struct wbcDomainControllerInfoEx * ) ptr ;
2011-05-05 01:57:37 +04:00
free ( discard_const_p ( char , i - > dc_unc ) ) ;
free ( discard_const_p ( char , i - > dc_address ) ) ;
free ( discard_const_p ( char , i - > domain_guid ) ) ;
free ( discard_const_p ( char , i - > domain_name ) ) ;
free ( discard_const_p ( char , i - > forest_name ) ) ;
free ( discard_const_p ( char , i - > dc_site_name ) ) ;
free ( discard_const_p ( char , i - > client_site_name ) ) ;
2010-04-03 21:57:48 +04:00
}
static wbcErr wbc_create_domain_controller_info_ex ( const struct winbindd_response * resp ,
2008-09-27 05:29:01 +04:00
struct wbcDomainControllerInfoEx * * _i )
{
wbcErr wbc_status = WBC_ERR_SUCCESS ;
struct wbcDomainControllerInfoEx * i ;
struct wbcGuid guid ;
2010-04-03 21:57:48 +04:00
i = ( struct wbcDomainControllerInfoEx * ) wbcAllocateMemory (
2010-11-27 21:07:40 +03:00
1 , sizeof ( struct wbcDomainControllerInfoEx ) ,
2010-04-03 21:57:48 +04:00
wbcDomainControllerInfoExDestructor ) ;
2008-09-27 05:29:01 +04:00
BAIL_ON_PTR_ERROR ( i , wbc_status ) ;
2010-04-03 21:57:48 +04:00
i - > dc_unc = strdup ( resp - > data . dsgetdcname . dc_unc ) ;
2008-09-27 05:29:01 +04:00
BAIL_ON_PTR_ERROR ( i - > dc_unc , wbc_status ) ;
2010-04-03 21:57:48 +04:00
i - > dc_address = strdup ( resp - > data . dsgetdcname . dc_address ) ;
2008-09-27 05:29:01 +04:00
BAIL_ON_PTR_ERROR ( i - > dc_address , wbc_status ) ;
i - > dc_address_type = resp - > data . dsgetdcname . dc_address_type ;
wbc_status = wbcStringToGuid ( resp - > data . dsgetdcname . domain_guid , & guid ) ;
if ( WBC_ERROR_IS_OK ( wbc_status ) ) {
2010-04-03 21:57:48 +04:00
i - > domain_guid = ( struct wbcGuid * ) malloc (
sizeof ( struct wbcGuid ) ) ;
2008-09-27 05:29:01 +04:00
BAIL_ON_PTR_ERROR ( i - > domain_guid , wbc_status ) ;
* i - > domain_guid = guid ;
}
2010-04-03 21:57:48 +04:00
i - > domain_name = strdup ( resp - > data . dsgetdcname . domain_name ) ;
2008-09-27 05:29:01 +04:00
BAIL_ON_PTR_ERROR ( i - > domain_name , wbc_status ) ;
if ( resp - > data . dsgetdcname . forest_name [ 0 ] ! = ' \0 ' ) {
2010-04-03 21:57:48 +04:00
i - > forest_name = strdup ( resp - > data . dsgetdcname . forest_name ) ;
2008-09-27 05:29:01 +04:00
BAIL_ON_PTR_ERROR ( i - > forest_name , wbc_status ) ;
}
i - > dc_flags = resp - > data . dsgetdcname . dc_flags ;
if ( resp - > data . dsgetdcname . dc_site_name [ 0 ] ! = ' \0 ' ) {
2010-04-03 21:57:48 +04:00
i - > dc_site_name = strdup ( resp - > data . dsgetdcname . dc_site_name ) ;
2008-09-27 05:29:01 +04:00
BAIL_ON_PTR_ERROR ( i - > dc_site_name , wbc_status ) ;
}
if ( resp - > data . dsgetdcname . client_site_name [ 0 ] ! = ' \0 ' ) {
2010-04-03 21:57:48 +04:00
i - > client_site_name = strdup (
2008-09-27 05:29:01 +04:00
resp - > data . dsgetdcname . client_site_name ) ;
BAIL_ON_PTR_ERROR ( i - > client_site_name , wbc_status ) ;
}
* _i = i ;
i = NULL ;
done :
2010-04-03 21:57:48 +04:00
if ( i ! = NULL ) {
wbcFreeMemory ( i ) ;
}
2008-09-27 05:29:01 +04:00
return wbc_status ;
}
2008-12-09 15:18:06 +03:00
/* Get extended domain controller information */
2021-10-12 15:30:09 +03:00
_PUBLIC_
2015-02-22 01:30:11 +03:00
wbcErr wbcCtxLookupDomainControllerEx ( struct wbcContext * ctx ,
const char * domain ,
struct wbcGuid * guid ,
const char * site ,
uint32_t flags ,
struct wbcDomainControllerInfoEx * * dc_info )
2008-09-27 05:29:01 +04:00
{
wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE ;
struct winbindd_request request ;
struct winbindd_response response ;
/* validate input params */
if ( ! domain | | ! dc_info ) {
wbc_status = WBC_ERR_INVALID_PARAM ;
BAIL_ON_WBC_ERROR ( wbc_status ) ;
}
ZERO_STRUCT ( request ) ;
ZERO_STRUCT ( response ) ;
request . data . dsgetdcname . flags = flags ;
strncpy ( request . data . dsgetdcname . domain_name , domain ,
sizeof ( request . data . dsgetdcname . domain_name ) - 1 ) ;
if ( site ) {
strncpy ( request . data . dsgetdcname . site_name , site ,
sizeof ( request . data . dsgetdcname . site_name ) - 1 ) ;
}
if ( guid ) {
char * str = NULL ;
wbc_status = wbcGuidToString ( guid , & str ) ;
BAIL_ON_WBC_ERROR ( wbc_status ) ;
strncpy ( request . data . dsgetdcname . domain_guid , str ,
sizeof ( request . data . dsgetdcname . domain_guid ) - 1 ) ;
wbcFreeMemory ( str ) ;
}
/* Send request */
2015-02-22 01:30:11 +03:00
wbc_status = wbcRequestResponse ( ctx , WINBINDD_DSGETDCNAME ,
2008-09-27 05:29:01 +04:00
& request ,
& response ) ;
BAIL_ON_WBC_ERROR ( wbc_status ) ;
if ( dc_info ) {
2010-04-03 21:57:48 +04:00
wbc_status = wbc_create_domain_controller_info_ex ( & response ,
2008-09-27 05:29:01 +04:00
dc_info ) ;
BAIL_ON_WBC_ERROR ( wbc_status ) ;
}
wbc_status = WBC_ERR_SUCCESS ;
done :
return wbc_status ;
}
2008-09-25 03:31:12 +04:00
2021-10-12 15:30:09 +03:00
_PUBLIC_
2015-02-22 01:30:11 +03:00
wbcErr wbcLookupDomainControllerEx ( const char * domain ,
struct wbcGuid * guid ,
const char * site ,
uint32_t flags ,
struct wbcDomainControllerInfoEx * * dc_info )
{
return wbcCtxLookupDomainControllerEx ( NULL , domain , guid , site ,
flags , dc_info ) ;
}
2010-04-03 21:50:25 +04:00
static void wbcNamedBlobDestructor ( void * ptr )
{
struct wbcNamedBlob * b = ( struct wbcNamedBlob * ) ptr ;
while ( b - > name ! = NULL ) {
2011-05-05 01:57:37 +04:00
free ( discard_const_p ( char , b - > name ) ) ;
2010-04-03 21:50:25 +04:00
free ( b - > blob . data ) ;
b + = 1 ;
}
}
2008-12-09 15:18:06 +03:00
/* Initialize a named blob and add to list of blobs */
2021-10-12 15:30:09 +03:00
_PUBLIC_
2008-09-25 03:31:12 +04:00
wbcErr wbcAddNamedBlob ( size_t * num_blobs ,
2010-04-03 21:50:25 +04:00
struct wbcNamedBlob * * pblobs ,
2008-09-25 03:31:12 +04:00
const char * name ,
uint32_t flags ,
uint8_t * data ,
size_t length )
{
wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE ;
2010-04-03 21:50:25 +04:00
struct wbcNamedBlob * blobs , * blob ;
2008-09-25 03:31:12 +04:00
2010-04-03 21:50:25 +04:00
if ( name = = NULL ) {
return WBC_ERR_INVALID_PARAM ;
}
2008-09-25 03:31:12 +04:00
2010-04-03 21:50:25 +04:00
/*
* Overallocate the b - > name = = NULL terminator for
* wbcNamedBlobDestructor
*/
blobs = ( struct wbcNamedBlob * ) wbcAllocateMemory (
2010-11-27 21:07:40 +03:00
* num_blobs + 2 , sizeof ( struct wbcNamedBlob ) ,
2010-04-03 21:50:25 +04:00
wbcNamedBlobDestructor ) ;
2011-03-15 13:19:57 +03:00
if ( blobs = = NULL ) {
return WBC_ERR_NO_MEMORY ;
}
2010-04-03 21:50:25 +04:00
if ( * pblobs ! = NULL ) {
struct wbcNamedBlob * old = * pblobs ;
memcpy ( blobs , old , sizeof ( struct wbcNamedBlob ) * ( * num_blobs ) ) ;
if ( * num_blobs ! = 0 ) {
/* end indicator for wbcNamedBlobDestructor */
old [ 0 ] . name = NULL ;
}
wbcFreeMemory ( old ) ;
}
* pblobs = blobs ;
blob = & blobs [ * num_blobs ] ;
blob - > name = strdup ( name ) ;
BAIL_ON_PTR_ERROR ( blob - > name , wbc_status ) ;
blob - > flags = flags ;
2008-09-25 03:31:12 +04:00
2010-04-03 21:50:25 +04:00
blob - > blob . length = length ;
blob - > blob . data = ( uint8_t * ) malloc ( length ) ;
BAIL_ON_PTR_ERROR ( blob - > blob . data , wbc_status ) ;
memcpy ( blob - > blob . data , data , length ) ;
* num_blobs + = 1 ;
* pblobs = blobs ;
blobs = NULL ;
2008-09-25 03:31:12 +04:00
wbc_status = WBC_ERR_SUCCESS ;
done :
2010-04-03 21:50:25 +04:00
wbcFreeMemory ( blobs ) ;
2008-09-25 03:31:12 +04:00
return wbc_status ;
}
2018-11-02 20:57:05 +03:00
2021-10-12 15:30:09 +03:00
_PUBLIC_
2018-11-02 20:57:05 +03:00
void wbcSetClientProcessName ( const char * name )
{
winbind_set_client_name ( name ) ;
}