2022-05-11 11:38:45 +02:00
/*
2005-06-07 22:09:18 +00:00
Unix SMB / CIFS implementation .
handling for browsing dgram requests
Copyright ( C ) Jelmer Vernooij 2005
Heavily based on ntlogon . c
2022-05-11 11:38:45 +02:00
2005-06-07 22:09:18 +00:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-10 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2005-06-07 22:09:18 +00:00
( at your option ) any later version .
2022-05-11 11:38:45 +02:00
2005-06-07 22:09:18 +00:00
This program 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 General Public License for more details .
2022-05-11 11:38:45 +02:00
2005-06-07 22:09:18 +00:00
You should have received a copy of the GNU General Public License
2007-07-10 02:07:03 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2005-06-07 22:09:18 +00:00
*/
# include "includes.h"
2024-04-10 13:02:39 +02:00
# include "lib/util/util_file.h"
2005-06-07 22:09:18 +00:00
# include "libcli/dgram/libdgram.h"
2006-01-09 22:12:53 +00:00
# include "lib/socket/socket.h"
2006-03-07 11:07:23 +00:00
# include "libcli/resolve/resolve.h"
2006-03-16 00:23:11 +00:00
# include "librpc/gen_ndr/ndr_nbt.h"
2007-09-08 12:42:09 +00:00
# include "param/param.h"
2005-06-07 22:09:18 +00:00
NTSTATUS dgram_mailslot_browse_send ( struct nbt_dgram_socket * dgmsock ,
2006-01-14 10:03:18 +00:00
struct nbt_name * dest_name ,
struct socket_address * dest ,
struct nbt_name * src_name ,
struct nbt_browse_packet * request )
2005-06-07 22:09:18 +00:00
{
NTSTATUS status ;
2007-11-09 19:24:51 +01:00
enum ndr_err_code ndr_err ;
2005-06-07 22:09:18 +00:00
DATA_BLOB blob ;
TALLOC_CTX * tmp_ctx = talloc_new ( dgmsock ) ;
2010-05-09 17:20:01 +02:00
ndr_err = ndr_push_struct_blob ( & blob , tmp_ctx , request ,
2005-06-07 22:09:18 +00:00
( ndr_push_flags_fn_t ) ndr_push_nbt_browse_packet ) ;
2007-11-09 19:24:51 +01:00
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_err ) ) {
2005-06-07 22:09:18 +00:00
talloc_free ( tmp_ctx ) ;
2007-11-09 19:24:51 +01:00
return ndr_map_error2ntstatus ( ndr_err ) ;
2005-06-07 22:09:18 +00:00
}
2022-05-11 11:38:45 +02:00
status = dgram_mailslot_send ( dgmsock , DGRAM_DIRECT_UNIQUE ,
2005-06-07 22:09:18 +00:00
NBT_MAILSLOT_BROWSE ,
2022-05-11 11:38:45 +02:00
dest_name , dest ,
2005-06-07 22:09:18 +00:00
src_name , & blob ) ;
talloc_free ( tmp_ctx ) ;
return status ;
}
NTSTATUS dgram_mailslot_browse_reply ( struct nbt_dgram_socket * dgmsock ,
2006-01-14 10:03:18 +00:00
struct nbt_dgram_packet * request ,
const char * mailslot_name ,
2007-12-02 16:20:29 +01:00
const char * my_netbios_name ,
2006-01-14 10:03:18 +00:00
struct nbt_browse_packet * reply )
2005-06-07 22:09:18 +00:00
{
NTSTATUS status ;
2007-11-09 19:24:51 +01:00
enum ndr_err_code ndr_err ;
2005-06-07 22:09:18 +00:00
DATA_BLOB blob ;
TALLOC_CTX * tmp_ctx = talloc_new ( dgmsock ) ;
struct nbt_name myname ;
2006-01-09 22:12:53 +00:00
struct socket_address * dest ;
2005-06-07 22:09:18 +00:00
2010-05-09 17:20:01 +02:00
ndr_err = ndr_push_struct_blob ( & blob , tmp_ctx , reply ,
2005-06-07 22:09:18 +00:00
( ndr_push_flags_fn_t ) ndr_push_nbt_browse_packet ) ;
2007-11-09 19:24:51 +01:00
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_err ) ) {
2005-06-07 22:09:18 +00:00
talloc_free ( tmp_ctx ) ;
2007-11-09 19:24:51 +01:00
return ndr_map_error2ntstatus ( ndr_err ) ;
2005-06-07 22:09:18 +00:00
}
2007-12-02 16:20:29 +01:00
make_nbt_name_client ( & myname , my_netbios_name ) ;
2005-06-07 22:09:18 +00:00
2022-05-11 11:38:45 +02:00
dest = socket_address_from_strings ( tmp_ctx , dgmsock - > sock - > backend_name ,
2006-01-09 22:12:53 +00:00
request - > src_addr , request - > src_port ) ;
if ( ! dest ) {
talloc_free ( tmp_ctx ) ;
return NT_STATUS_NO_MEMORY ;
}
2022-05-11 11:38:45 +02:00
status = dgram_mailslot_send ( dgmsock , DGRAM_DIRECT_UNIQUE ,
2005-06-07 22:09:18 +00:00
mailslot_name ,
& request - > data . msg . source_name ,
2006-01-09 22:12:53 +00:00
dest ,
2005-06-07 22:09:18 +00:00
& myname , & blob ) ;
talloc_free ( tmp_ctx ) ;
return status ;
}
NTSTATUS dgram_mailslot_browse_parse ( struct dgram_mailslot_handler * dgmslot ,
2006-01-14 10:03:18 +00:00
TALLOC_CTX * mem_ctx ,
struct nbt_dgram_packet * dgram ,
struct nbt_browse_packet * pkt )
2005-06-07 22:09:18 +00:00
{
DATA_BLOB data = dgram_mailslot_data ( dgram ) ;
2007-11-09 19:24:51 +01:00
enum ndr_err_code ndr_err ;
2005-06-07 22:09:18 +00:00
2010-05-09 17:20:01 +02:00
ndr_err = ndr_pull_struct_blob ( & data , mem_ctx , pkt ,
2005-06-07 22:09:18 +00:00
( ndr_pull_flags_fn_t ) ndr_pull_nbt_browse_packet ) ;
2007-11-09 19:24:51 +01:00
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_err ) ) {
NTSTATUS status = ndr_map_error2ntstatus ( ndr_err ) ;
DEBUG ( 0 , ( " Failed to parse browse packet of length %d: %s \n " ,
( int ) data . length , nt_errstr ( status ) ) ) ;
2005-06-07 22:09:18 +00:00
if ( DEBUGLVL ( 10 ) ) {
2022-05-11 11:39:28 +02:00
( void ) file_save ( " browse.dat " , data . data , data . length ) ;
2005-06-07 22:09:18 +00:00
}
2007-11-03 09:42:18 +01:00
return status ;
2005-06-07 22:09:18 +00:00
}
2007-11-03 09:40:32 +01:00
return NT_STATUS_OK ;
2005-06-07 22:09:18 +00:00
}