-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwarsync-server
130 lines (96 loc) · 3.86 KB
/
warsync-server
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/perl -T
##############################################################################
## warsync-server - Warsync Server ##
## ##
## Copyright (C) 2001-2004 Paul J. Baker ##
## ##
## This program is free software; you can redistribute it and/or modify ##
## it under the terms of the GNU General Public License version 2 as ##
## published by the Free Software Foundation. ##
## ##
## 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. ##
## ##
## You should have received a copy of the GNU General Public License ##
## along with this program; if not, write to the Free Software ##
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, ##
## MA 02111-1307, USA. ##
## ##
## You may contact the author via electronic mail at warsync@paulbaker.net ##
##############################################################################
## $Id: warsync-server 162 2005-11-05 01:43:07Z pbaker-guest $
=head1 NAME
B<warsync-server> - Warsync Server
=head1 SYNOPSIS
B<warsync-server>
=head1 DESCRIPTION
B<warsync-server> is a program that speaks the server side of Warsync
communication to stdout and expects client requests from stdin. B<warsync-server>
is not intended to be called directly, but from sshd(8) using ssh key
forced-commands.
=head1 SEE ALSO
warsync(8)
=head1 AUTHOR
Paul Baker, pbaker@where2getit.com
=cut
use warnings;
use strict;
use Warsync::Util;
use Warsync::Server;
$ENV{PATH} = '/usr/bin:/bin:/usr/sbin:/sbin';
$| = 1;
umask 022;
## client should be specified on real command line.
my $client = shift @ARGV;
## read incoming warsync command.
my $rpc = $ENV{SSH_ORIGINAL_COMMAND};
my $host = $ENV{SSH_CLIENT};
exit(2) unless $client && $rpc && $host;
## check for log directory.
unless (-d '/var/log/warsync') {
system('mkdir', '-p', '-m', '750', '/var/log/warsync');
}
## log command and ip.
open (my $log, '>> /var/log/warsync/server.log')
or die "could not append to server log: $!";
(my $log_rpc = $rpc) =~ s/\s+/ /g;
print $log join("\t", scalar(localtime), "$client=$host", $log_rpc), "\n";
close($log);
my $server = Warsync::Server->new()
or fault "this is not a warsync server";
## this had better be a warsync command.
$rpc =~ s/^warsync-//;
## check for compression.
$rpc =~ s/^compress-//;
## set tty.
tty($rpc =~ s/^tty-//);
my %options = ();
## check for other options
$options{'n'} = $rpc =~ s/^dry-run-//;
$options{'q'} = $rpc =~ s/^quiet-//;
## special check for verbose
if (my ($v) = $rpc =~ /^verbose(\d+)-/) {
$options{'v'} = $v;
$rpc =~ s/^verbose$v-//;
}
$server->options(\%options);
if ($server->verbose >= 5) {
$server->display(5, 's-debug: ', `ssh -V`);
foreach my $key (sort keys %ENV) {
$server->display(5, "s-debug: ENV $key = $ENV{$key}\n");
}
}
$server->display(4, 's-rpc: ', $ENV{SSH_ORIGINAL_COMMAND}, "\n");
my ($cmd, @args) = split(/ /, $rpc);
my $method = "rpc_$cmd";
$method =~ s/[^a-z]/_/g;
$server->display(3, 's-method: ', $method, "\n");
if ($server->can($method)) {
$server->$method(@args);
}
else {
fault "unexpected server command: $cmd";
}
exit($server->exit_code);