Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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));
        }