コード例 #1
0
ファイル: ClientServer.cs プロジェクト: xcrash/rsync.net
        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);
        }
コード例 #2
0
        /// <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);
        }