Overview of rsync_func.inc

Public Function Summary

Public functions are intended to be called by the code that imports this library.

Name Summary
authentication_required
get_file
get_module_list
rsync_connect

Public Function Details

authentication_required

Named Parameters

module
port

Code

function authentication_required( module, port )
{
    local_var sock, port;

    if( ! port ) return FALSE;

    sock = rsync_connect( port:port );
    if (! sock)
        return 'unknown';

    send(socket : sock, data : string(module + '\r\n'));
    line = recv_line(socket : sock, length : 8096);

    if (strstr(line, '@RSYNCD: OK'))
        return 'no';
    else if (strstr(line, '@RSYNCD: AUTHREQD'))
        return 'yes';
    else
        return 'unknown';
}

function get_file( soc, module, file )

		
top

get_file

Named Parameters

file
module
soc

Code

function get_file( soc, module, file )
{
  local_var soc, module, file;

  if( isnull( soc ) ) return FALSE;
  if( isnull( module ) ) return FALSE;
  if( isnull( file ) ) return FALSE;

  set_byte_order( BYTE_ORDER_LITTLE_ENDIAN );

  send( socket:soc, data:module + '\n' );
  buf = recv_line( socket:soc, length:4096 );

  if( "@RSYNCD: OK" >!< buf ) return FALSE;

  send( socket:soc, data:'--server\n--sender\n-L\n.\n' + module +'/' + file + '\n\n' );
  buf = recv( socket:soc, length:4096 );

  send( socket:soc, data: raw_string( 0,0,0,0 ) );
  buf = recv( socket:soc, length:4096 );

  if( ! buf || buf == "" ) return FALSE;

  s = hex2raw( s:'0000000000a000000000000000000000000000000000' );

  send( socket:soc, data:s );
  while( b  = recv(socket:soc, length:1024) )
    ret += b;

  plen  = strlen( s ) + 4;
  pfile = strlen( s ) + 8;

  if( isnull( ret ) || strlen( ret ) < ( pfile + 4 ) ) return FALSE;

  flen = getdword( blob:ret, pos:plen );
  file_end = pfile + ( flen - 1 );

  if( strlen( ret ) < file_end ) return FALSE;

  return substr( ret, pfile, file_end );
}




		
top

get_module_list

Named Parameters

port

Code

function get_module_list( port )
{
    local_var sock, port;

    if( ! port ) return FALSE;

    sock = rsync_connect( port:port );
    if (! sock)
        return NULL;

    num = 0;
    send(socket : sock, data : '#list\r\n');
    while (1) {
        line = recv_line(socket : sock, length : 8096, timeout : 1);
        if (! line || strstr(line, '@RSYNCD'))
            break;

        ret[num++] = line;
    }

    return ret;
}

function authentication_required( module, port )

		
top

rsync_connect

Named Parameters

port

Code

function rsync_connect( port )
{
    local_var sock, banner, port;

    if( ! port ) return FALSE;

    sock = open_sock_tcp( port );
    if( ! sock )
        return NULL;

    banner = recv_line( socket:sock, length:8096 );
    if( isnull( banner ) )
    {
      close( sock );
      return FALSE;
    }

    replace_kb_item( name:"rsync/" + port + "/banner", value:chomp(banner ) );
    send( socket:sock, data:'@RSYNCD: 29.0\n' );

    # skip MOTD

    for (i = 0; i < motd_lines; ++i)
        recv_line(socket : sock, length : 8096);

    return sock;
}

function get_module_list( port )

		
top