Skip to content

Commit

Permalink
11.05: encapsulated commands in TS6 are no longer hard-coded. the new…
Browse files Browse the repository at this point in the history
… master ENCAP handler fires virtual commands in the form of ENCAP_*. #29.             updated LOGIN and SU handlers appropriately.             added outgoing commands su_login and su_logout, as well as the respective TS6/JELP handlers.             more work on SASL propagation. #9.             added message ->forward_to_mask() method which forwards the message to all servers matching a mask.
  • Loading branch information
cooper committed Jul 5, 2016
1 parent 5e53153 commit 3b4df7f
Show file tree
Hide file tree
Showing 13 changed files with 236 additions and 114 deletions.
7 changes: 7 additions & 0 deletions INDEV
Expand Up @@ -3198,3 +3198,10 @@ CHANGES:

04. partially reimplemented SASL for external service packages.
this is not complete. #9.

05. encapsulated commands in TS6 are no longer hard-coded.
the new master ENCAP handler fires virtual commands in the form of ENCAP_*. #29.
updated LOGIN and SU handlers appropriately.
added outgoing commands su_login and su_logout, as well as the respective TS6/JELP handlers.
more work on SASL propagation. #9.
added message ->forward_to_mask() method which forwards the message to all servers matching a mask.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
11.04
11.05
2 changes: 1 addition & 1 deletion modules/JELP/Outgoing.module/Outgoing.json
Expand Up @@ -9,5 +9,5 @@
"description" : "basic set of JELP outgoing commands",
"name" : "JELP::Outgoing",
"package" : "M::JELP::Outgoing",
"version" : "17.55"
"version" : "17.65"
}
8 changes: 7 additions & 1 deletion modules/JELP/Outgoing.module/Outgoing.pm
Expand Up @@ -46,7 +46,8 @@ my %ocommands = (
time => \&_time,
snotice => \&snotice,
version => \&version,
login => \&login,
login => \&login, # TODO: logout
su_login => \&su_login, # TODO: logout
part_all => \&partall,
invite => \&invite,

Expand Down Expand Up @@ -441,6 +442,11 @@ sub version {
":$$user{uid} VERSION \$$$t_server{sid}"
}

sub su_login {
my ($to_server, $source_serv, $user, $actname) = @_;
return login($to_server, $user, $actname);
}

# :uid LOGIN accountname,others,...
# the comma-separated list is passed as a list here.
sub login {
Expand Down
2 changes: 1 addition & 1 deletion modules/SASL/SASL.module/SASL.json
Expand Up @@ -12,5 +12,5 @@
"description" : "Provides SASL authentication",
"name" : "SASL",
"package" : "M::SASL",
"version" : "1.7"
"version" : "1.8"
}
2 changes: 1 addition & 1 deletion modules/TS6/Base.module/Base.json
Expand Up @@ -12,5 +12,5 @@
"description" : "programming interface for TS6",
"name" : "TS6::Base",
"package" : "M::TS6::Base",
"version" : "1.9"
"version" : "2"
}
2 changes: 1 addition & 1 deletion modules/TS6/Base.module/Base.pm
Expand Up @@ -131,7 +131,7 @@ sub _handle_command {
if (defined $params[0] && $params[0] eq $message::PARAM_BAD) {
notice(server_protocol_warning =>
$server->name, $server->id,
"provided invalid parameters for ts6 command ".$msg->command
"provided invalid parameters for TS6 command ".$msg->command
);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/TS6/Incoming.module/Incoming.json
Expand Up @@ -9,5 +9,5 @@
"description" : "basic set of TS6 command handlers",
"name" : "TS6::Incoming",
"package" : "M::TS6::Incoming",
"version" : "17.4"
"version" : "17.8"
}
134 changes: 96 additions & 38 deletions modules/TS6/Incoming.module/Incoming.pm
Expand Up @@ -186,6 +186,16 @@ our %ts6_incoming_commands = (
# :uid INVITE uid channel channelTS
params => '-source(user) user channel ts',
code => \&invite
},
ENCAP_LOGIN => {
# :uid ENCAP serv_mask LOGIN account_name
params => '-source(user) * * *',
code => \&login
},
ENCAP_SU => {
# :sid SU serv_mask SU uid account_name
params => '-source(server) * * user *(opt)',
code => \&su
}
);

Expand Down Expand Up @@ -789,50 +799,57 @@ sub _join {
# ts6-protocol.txt:253
#
sub encap {
my ($server, $msg, $source, $serv_mask, $cmd, @rest) = @_;

my (%done, $doing_me);
foreach my $serv ($pool->lookup_server_mask($serv_mask)) {
my $location = $serv->{location} || $serv; # for $me, location = nil
my ($server, $msg, $source, $serv_mask, $encap_cmd, @rest) = @_;

# already did or the server is connected via the source server
next if $done{$server};
next if $location == $server;
# ENCAP
#
# This master handler fires virtual commands which manually ->forward().
# If no handler exists, this one will forward the message to TS6 servers
# exactly as it was received. Unfortunately it is impossible to send
# unknown ENCAP commands to indirectly-connected TS6 servers with servers
# linked via other protocols in between them.
#
# SEE ISSUE #29 for details.
#

# if the server is me
if ($serv == $me) {
$doing_me = 1;
next;
}
# create a fake ENCAP_* command.
my $cmd = uc 'ENCAP_'.$encap_cmd;
$msg->{command} = $cmd;

# === Forward ===
#
# TODO: !!! this will have to actually break down
# what the commands are and fire the appropriate outgoing
# handlers, since other protocols do not have ENCAP
#
# fire the virtual command.
my $fire = $server->prepare_together(
[ "ts6_message" => $msg ],
[ "ts6_message_$cmd" => $msg ]
)->fire('safe');

$done{$location} = 1;
# an exception occurred in the virtual command handler.
if (my $e = $fire->exception) {
my $stopper = $fire->stopper;
notice(exception => "Error in $cmd from $stopper: $e");
return;
}

return 1 unless $doing_me;
# if a TS6 command handler manually forwarded this, we're done.
return 1 if $msg->{encap_forwarded};

# otherwise, forward as-is to TS6 servers.
L("ENCAP $encap_cmd is not known by this server; forwarding as-is");
$msg->{command} = 'ENCAP';
my %done;

# find servers matching the mask.
foreach my $serv ($pool->lookup_server_mask($serv_mask)) {
my $location = $serv->{location} || $serv; # for $me, location = nil

next if $done{$location}; # already did this location
$done{$location} = 1; # remember sent/checked

next if $location == $server; # this is the origin
next if $location->{link_type} ne 'ts6'; # not a TS6 server

# OK, send it as-is.
$location->send($msg->data);

# TODO: make a better way to handle ENCAP stuff
if ($cmd eq 'LOGIN') {
# source: user
# parameters: account name
return login($server, $msg, $source, @rest);
}
if ($cmd eq 'SU') {
# source: services server
# parameters: user, new login name
my $user = $pool->lookup_user(uid_from_ts6($rest[0])) or return;
if (!length $rest[1]) {
delete $user->{account};
L("TS6 logout $$user{nick}");
return 1;
}
return login($server, $msg, $user, $rest[1]);
}

return 1;
Expand All @@ -847,9 +864,50 @@ sub encap {
# ts6-protocol.txt:505
#
sub login {
my ($server, $msg, $user, $act_name) = @_;
my ($server, $msg, $user, $serv_mask, undef, $act_name) = @_;
$msg->{encap_forwarded} = 1;

# login.
L("TS6 login $$user{nick} as $act_name");
$user->{account} = { name => $act_name };

#=== Forward ===#
$msg->forward_to_mask($serv_mask, login => $user, $act_name);

return 1;
}

# SU
#
# encap only
# encap target: *
# source: services server
# parameters: target user, new login name (optional)
#
sub su {
my ($server, $msg, $source_serv, $serv_mask, undef, $user, $act_name) = @_;
$msg->{encap_forwarded} = 1;

# no account name = logout.
if (!length $act_name) {
delete $user->{account};
L("TS6 logout $$user{nick}");

#=== Forward ===#
$msg->forward_to_mask($serv_mask, su_logout => $source_serv, $user);

return 1;
}

# login.
L("TS6 login $$user{nick} as $act_name");
$user->{account} = { name => $act_name };

#=== Forward ===#
$msg->forward_to_mask($serv_mask, su_login =>
$source_serv, $user, $act_name
);

return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/TS6/Outgoing.module/Outgoing.json
Expand Up @@ -12,5 +12,5 @@
"description" : "basic set of TS6 outgoing commands",
"name" : "TS6::Outgoing",
"package" : "M::TS6::Outgoing",
"version" : "7"
"version" : "7.1"
}
32 changes: 31 additions & 1 deletion modules/TS6/Outgoing.module/Outgoing.pm
Expand Up @@ -61,7 +61,9 @@ our %ts6_outgoing_commands = (
motd => \&motd,
version => \&version,
lusers => \&lusers,
invite => \&invite
invite => \&invite,
su_login => \&su_login,
su_logout => \&su_logout
);

sub init {
Expand Down Expand Up @@ -570,6 +572,34 @@ sub login {
":$id ENCAP * LOGIN $acctname"
}

# SU
#
# encap only
# encap target: *
# source: services server
# parameters: target user, new login name (optional)
#
sub su_login {
my ($to_server, $source_serv, $user, $acctname) = @_;
my $sid = ts6_id($source_serv);
my $uid = ts6_id($user);
":$sid ENCAP * SU $uid $acctname"
}

# SU
#
# encap only
# encap target: *
# source: services server
# parameters: target user, new login name (optional)
#
sub su_logout {
my ($to_server, $source_serv, $user) = @_;
my $sid = ts6_id($source_serv);
my $uid = ts6_id($user);
":$sid ENCAP * SU $uid"
}

# PING
#
# source: any
Expand Down
2 changes: 1 addition & 1 deletion modules/ircd.module/message.module/message.json
Expand Up @@ -8,5 +8,5 @@
"no_bless" : 1,
"package" : "message",
"preserve_sym" : 1,
"version" : "10.2"
"version" : "11.04"
}

0 comments on commit 3b4df7f

Please sign in to comment.