public void StartDaemon() { var remoteEndPoint = _client.RemoteEndPoint as IPEndPoint; _clientInfo.Options.RemoteAddr = remoteEndPoint.Address.ToString(); _clientInfo.Options.RemoteHost = Dns.GetHostEntry(remoteEndPoint.Address).HostName; Daemon.StartDaemon(_clientInfo); _client.Close(); _clientSockets.Remove(this); }
public int ClientRun(ClientInfo clientInfo, int pid, string[] args) { var options = clientInfo.Options; var ioStream = clientInfo.IoStream; FileList fList; List <FileStruct> fileList; WinRsync.SetupProtocol(clientInfo); if (options.ProtocolVersion >= 23 && !options.ReadBatch) { ioStream.IoStartMultiplexIn(); } if (options.AmSender) { ioStream.IoStartBufferingOut(); if (options.DeleteMode && !options.DeleteExcluded) { var excl = new Exclude(options); excl.SendExcludeList(ioStream); } if (options.Verbose > 3) { Log.Write("File list sent\n"); } ioStream.Flush(); fList = new FileList(options); fileList = fList.SendFileList(clientInfo, args); if (options.Verbose > 3) { Log.WriteLine("file list sent"); } ioStream.Flush(); var sender = new Sender(options); sender.SendFiles(fileList, clientInfo); ioStream.Flush(); ioStream.WriteInt(-1); return(-1); } options.Dir = args[0]; options.Dir = Path.GetFullPath(options.Dir ?? string.Empty); if (!options.ReadBatch) { var excl = new Exclude(options); excl.SendExcludeList(ioStream); } fList = new FileList(options); fileList = fList.ReceiveFileList(clientInfo); return(Daemon.DoReceive(clientInfo, fileList, null)); }
public void StartDaemon() { string remoteAddr = Client.RemoteEndPoint.ToString(); remoteAddr = remoteAddr.Substring(0, remoteAddr.IndexOf(':')); //string remoteHost = Dns.GetHostByAddress(IPAddress.Parse(remoteAddr)).HostName; string remoteHost = Dns.GetHostEntry(IPAddress.Parse(remoteAddr)).HostName; ClientInfo.Options.remoteAddr = remoteAddr; ClientInfo.Options.remoteHost = remoteHost; Daemon.StartDaemon(ClientInfo); Client.Close(); ClientSockets.Remove(this); }
public void Run(string[] args) { Opt = new Options(); if (args.Length == 0) { Exit(String.Empty, null); } int argsNotUsed = CommandLineParser.ParseArguments(args, Opt); if (argsNotUsed == -1) { Exit("Error parsing options", null); } string[] args2 = new string[argsNotUsed]; for (int i = 0; i < argsNotUsed; i++) { args2[i] = args[args.Length - argsNotUsed + i]; } if (Opt.AmDaemon && !Opt.AmSender) { Daemon.DaemonMain(Opt); return; } var cInfo = new ClientInfo { Options = Opt }; StartClient(args2, cInfo); Opt.DoStats = true; cInfo.IoStream = null; Report(cInfo); Console.Write("Press 'Enter' to exit."); Console.Read(); }
public void Run(string[] args) { opt = new Options(); opt.Init(); if (args.Length == 0) { Usage(); MainClass.Exit(String.Empty, null); } int argsNotUsed = CommandLineParser.ParseArguments(args, opt); if (argsNotUsed == -1) { MainClass.Exit("Error parsing options", null); } string[] args2 = new string[argsNotUsed]; for (int i = 0; i < argsNotUsed; i++) { args2[i] = args[args.Length - argsNotUsed + i]; } if (opt.amDaemon && !opt.amSender) { Daemon.DaemonMain(opt); return; } ClientInfo cInfo = new ClientInfo(); cInfo.Options = opt; StartClient(args2, cInfo); opt.doStats = true; cInfo.IoStream = null; Report(cInfo); Console.Write("Press 'Enter' to exit."); Console.Read(); }
public static int RsyncModule(ClientInfo cInfo, int moduleNumber) { string path = Daemon.config.GetModule(moduleNumber).Path; string name = Daemon.config.GetModuleName(moduleNumber); IOStream f = cInfo.IoStream; Options options = cInfo.Options; string[] args = new string[Options.MAX_ARGS]; int argc = 0, maxargs = Options.MAX_ARGS; string line = ""; if (path[0] == '/') { path = path.Remove(0, 1); } path = path.Replace("\n", ""); 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 + ")"); f.IOPrintf("@ERROR: access denied to " + name + " from " + options.remoteHost + " (" + options.remoteAddr + ")\n"); return(-1); } if (!Authentication.AuthServer(cInfo, moduleNumber, options.remoteAddr, "@RSYNCD: AUTHREQD ")) { Log.Write("auth failed on module " + name + " from " + options.remoteHost + " (" + options.remoteAddr + ")\n"); f.IOPrintf("@ERROR: auth failed on module " + name + "\n"); return(-1); } // TODO: path length if (FileSystem.Directory.Exists(path)) { f.IOPrintf("@RSYNCD: OK\n"); } else { try { // TODO: path length FileSystem.Directory.CreateDirectory(path); f.IOPrintf("@RSYNCD: OK\n"); } catch (Exception) { f.IOPrintf("@ERROR: Path not found\n"); MainClass.Exit("@ERROR: Path not found: " + path, cInfo); } } options.amServer = true; //to fix error in SetupProtocol options.dir = path; while (true) { line = f.ReadLine(); line = line.Substring(0, line.Length - 1); if (line.CompareTo("") == 0) { break; } if (argc == maxargs) { maxargs += Options.MAX_ARGS; MapFile.ReallocArrayString(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", cInfo); } string[] args2 = new string[argsNotUsed]; for (int i = 0; i < argsNotUsed; i++) { args2[i] = args[args.Length - argsNotUsed + i]; } MainClass.SetupProtocol(cInfo); f.IOStartMultiplexOut(); Daemon.StartServer(cInfo, args2); return(-1); }
public int ClientRun(ClientInfo clientInfo, int pid, string[] args) { Options options = clientInfo.Options; IOStream ioStream = clientInfo.IoStream; FileList fList; List <FileStruct> fileList; MainClass.SetupProtocol(clientInfo); if (options.protocolVersion >= 23 && !options.readBatch) { ioStream.IOStartMultiplexIn(); } if (options.amSender) { ioStream.IOStartBufferingOut(); if (options.deleteMode && !options.deleteExcluded) { Exclude excl = new Exclude(options); excl.SendExcludeList(ioStream); } if (options.verbose > 3) { Log.Write("File list sent\n"); } ioStream.Flush(); fList = new FileList(options); fileList = fList.sendFileList(clientInfo, args); if (options.verbose > 3) { Log.WriteLine("file list sent"); } ioStream.Flush(); Sender sender = new Sender(options); sender.SendFiles(fileList, clientInfo); ioStream.Flush(); ioStream.writeInt(-1); return(-1); } options.dir = args[0]; if (options.dir.CompareTo(String.Empty) != 0 && options.dir.IndexOf(':') == -1) { if (options.dir[0] == '/') { options.dir = "c:" + options.dir; } else if (options.dir.IndexOf('/') != -1) { options.dir = options.dir.Insert(options.dir.IndexOf('/') - 1, ":"); } } if (!options.readBatch) { Exclude excl = new Exclude(options); excl.SendExcludeList(ioStream); } fList = new FileList(options); fileList = fList.receiveFileList(clientInfo); return(Daemon.DoReceive(clientInfo, fileList, null)); }
/// <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? { var path = Daemon.Config.GetModule(moduleNumber).Path; var name = Daemon.Config.GetModuleName(moduleNumber); var ioStream = clientInfo.IoStream; var options = clientInfo.Options; var args = new string[Options.MaxArgs]; int argc = 0, maxArgs = Options.MaxArgs; var line = String.Empty; if (path[0] == '/') { path = path.Remove(0, 1); } path = path.Replace("\n", String.Empty); var 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"); WinRsync.Exit("@ERROR: Path not found: " + path, clientInfo); } } options.AmServer = true; //to fix error in SetupProtocol options.Dir = path; do { line = ioStream.ReadLine(); line = line.Substring(0, line.Length - 1); if (argc == maxArgs) { maxArgs += Options.MaxArgs; MapFile.ExtendArray(ref args, maxArgs); } args[argc++] = line; } while (!string.IsNullOrEmpty(line)); args[argc++] = path; options.Verbose = 0; var argsNotUsed = CommandLineParser.ParseArguments(args, options); if (argsNotUsed == -1) { WinRsync.Exit("Error parsing options", clientInfo); } var args2 = new string[argsNotUsed]; for (var i = 0; i < argsNotUsed; i++) { args2[i] = args[args.Length - argsNotUsed + i]; } WinRsync.SetupProtocol(clientInfo); ioStream.IoStartMultiplexOut(); Daemon.StartServer(clientInfo, args2); }