This repository has been archived by the owner on Mar 21, 2024. It is now read-only.
forked from MatthewSteeples/rsync.net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClientServer.cs
125 lines (117 loc) · 4.58 KB
/
ClientServer.cs
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
/**
* Copyright (C) 2006 Alex Pedenko
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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
*/
using System;
using System.IO;
namespace NetSync
{
public class ClientServer
{
/// <summary>
/// Do nothing
/// </summary>
/// <param name="f"></param>
public static void SendListing(IOStream f) //@todo_long empty method
{
}
/// <summary>
///
/// </summary>
/// <param name="clientInfo"></param>
/// <param name="moduleNumber"></param>
/// <returns></returns>
public static void RsyncModule(ClientInfo clientInfo, int moduleNumber) //@fixed Why return something if result not used?
{
string path = Daemon.config.GetModule(moduleNumber).Path;
string name = Daemon.config.GetModuleName(moduleNumber);
IOStream ioStream = clientInfo.IoStream;
Options options = clientInfo.Options;
string[] args = new string[Options.MAX_ARGS];
int argc = 0, maxArgs = Options.MAX_ARGS;
string line = String.Empty;
if (path[0] == '/')
{
path = path.Remove(0, 1);
}
path = path.Replace("\n", String.Empty);
Access ac = new Access();
if (!ac.AllowAccess(options.remoteAddr, options.remoteHost, Daemon.config.GetHostsAllow(moduleNumber), Daemon.config.GetHostsDeny(moduleNumber)))
{
Log.Write("rsync denied on module " + name + " from " + options.remoteHost + " (" + options.remoteAddr + ")");
ioStream.IOPrintf("@ERROR: access denied to " + name + " from " + options.remoteHost + " (" + options.remoteAddr + ")\n");
return;
}
if (!Authentication.AuthorizeServer(clientInfo, moduleNumber, options.remoteAddr, "@RSYNCD: AUTHREQD "))
{
Log.Write("auth failed on module " + name + " from " + options.remoteHost + " (" + options.remoteAddr + ")\n");
ioStream.IOPrintf("@ERROR: auth failed on module " + name + "\n");
return;
}
// TODO: path length
if (Directory.Exists(path))
{
ioStream.IOPrintf("@RSYNCD: OK\n");
}
else
{
try
{
// TODO: path length
Directory.CreateDirectory(path);
ioStream.IOPrintf("@RSYNCD: OK\n");
}
catch (Exception)
{
ioStream.IOPrintf("@ERROR: Path not found\n");
MainClass.Exit("@ERROR: Path not found: " + path, clientInfo);
}
}
options.amServer = true; //to fix error in SetupProtocol
options.dir = path;
while (true)
{
line = ioStream.ReadLine();
line = line.Substring(0, line.Length - 1);
if (line.CompareTo(String.Empty) == 0)
{
break;
}
if (argc == maxArgs)
{
maxArgs += Options.MAX_ARGS;
MapFile.ExtendArray(ref args, maxArgs);
}
args[argc++] = line;
}
args[argc++] = path;
options.verbose = 0;
int argsNotUsed = CommandLineParser.ParseArguments(args, options);
if (argsNotUsed == -1)
{
MainClass.Exit("Error parsing options", clientInfo);
}
string[] args2 = new string[argsNotUsed];
for (int i = 0; i < argsNotUsed; i++)
{
args2[i] = args[args.Length - argsNotUsed + i];
}
MainClass.SetupProtocol(clientInfo);
ioStream.IOStartMultiplexOut();
Daemon.StartServer(clientInfo, args2);
}
}
}