Skip to content

Commit

Permalink
clusterd: Move some declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
donald committed Jan 29, 2025
1 parent 189ec26 commit 0b93ca8
Showing 1 changed file with 30 additions and 36 deletions.
66 changes: 30 additions & 36 deletions clusterd/clusterd
Original file line number Diff line number Diff line change
@@ -1,41 +1,5 @@
#! /usr/local/system/perl/bin/perl

use warnings;
use strict;

use POSIX;
use IO::Pipe;
use Digest::MD5;
use Storable;

sub encode {
return Storable::nfreeze([@_]);
}

sub sign {
my ($password,$data)=@_;
return Digest::MD5::md5($password.$data).$data; # 16 byte prefix
}

sub check_sign { # signed-data -> undef or signed-data -> data
my ($password,$data)=@_;
length $data>16 or return undef;
my $rx_digest=substr($data,0,16);
my $signature=Digest::MD5::md5($password.substr($data,16));
$rx_digest eq $signature or return undef;
return substr($data,16);
}

sub decode {
my ($data)=@_;
my $msg;
eval {
$msg=Storable::thaw($data);
};
$@ and return undef;
return @$msg;
}

#-------------------------------------
package Donald::FileInfo;

Expand Down Expand Up @@ -657,11 +621,13 @@ sub init {

#------------------------------------------------------------------------
package main;
use warnings;
use strict;
use IO::File;
use Sys::Syslog;
use IO::Socket::INET;
use Data::Dumper;
use Digest::MD5;

our $UDP_MAX=1472;
our $UDP_PORT=234;
Expand Down Expand Up @@ -702,6 +668,34 @@ our $CLUSTER_PW_TIMESTAMP=0;

$ENV{'PATH'} = '/usr/local/bin:/sbin:/usr/sbin:/bin'.($ENV{PATH}?':'.$ENV{PATH}:''); # for ps , tar (gnu!)

sub encode {
return Storable::nfreeze([@_]);
}

sub sign {
my ($password,$data)=@_;
return Digest::MD5::md5($password.$data).$data; # 16 byte prefix
}

sub check_sign { # signed-data -> undef or signed-data -> data
my ($password,$data)=@_;
length $data>16 or return undef;
my $rx_digest=substr($data,0,16);
my $signature=Digest::MD5::md5($password.substr($data,16));
$rx_digest eq $signature or return undef;
return substr($data,16);
}

sub decode {
my ($data)=@_;
my $msg;
eval {
$msg=Storable::thaw($data);
};
$@ and return undef;
return @$msg;
}

#---------------------------------------------------------- UDP

our ($udp_peer_addr,$udp_peer_port); # ('141.14.12.12',1234)
Expand Down

0 comments on commit 0b93ca8

Please sign in to comment.