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();
        }
Exemple #2
0
 public static int DaemonMain(Options options)
 {
     ServerOptions = options;
     config = new Configuration(ServerOptions.configFile);
     if (config.LoadParm(options))
     {
         StartAcceptLoop(options.rsyncPort);
     }
     return -1;
 }
        /// <summary>
        /// Generate hash for passwords
        /// </summary>
        /// <param name="indata"></param>
        /// <param name="challenge"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static string GenerateHash(string indata, string challenge, Options options)
        {
            Sum sum = new Sum(options);

            sum.Init(0);
            sum.Update(Encoding.ASCII.GetBytes(indata), 0, indata.Length);
            sum.Update(Encoding.ASCII.GetBytes(challenge), 0, challenge.Length);
            byte[] buf = sum.End();
            string hash = Convert.ToBase64String(buf);
            return hash.Substring(0, (buf.Length * 8 + 5) / 6);
        }
		public static string auth_client( string user, string pass, string challenge, Options options)
		{			
			if(String.Compare(user, "") == 0)
				user = "******";
			if(pass == null || String.Compare(pass, "") == 0)
				pass = getpassf(password_file);
			if(String.Compare(pass, "") == 0)
				pass = System.Environment.GetEnvironmentVariable("RSYNC_PASSWORD");			
			if(pass == null || String.Compare(pass, "") == 0)
				pass = getpass();
			string pass2 = generate_hash(pass, challenge, options);
			Log.WriteLine(user + " " + pass2);

			return pass2;
		}
		public static string gen_challenge(string addr, Options opt)
		{			
			string challenge = "";
			byte[] input = new byte[32];			
			DateTime tv = DateTime.Now;			
			
			for(int i=0; i < addr.Length; i++)
				input[i] = Convert.ToByte(addr[i]);
						
			CheckSum.SIVAL(ref input, 16, (UInt32)tv.Second);
			CheckSum.SIVAL(ref input, 20, (UInt32)tv.Hour);
			CheckSum.SIVAL(ref input, 24, (UInt32)tv.Day);

			Sum sum = new Sum(opt);
			sum.Init(0);
			sum.Update(input,0,input.Length);
			challenge = Encoding.ASCII.GetString(sum.End());
			return challenge;
		}
Exemple #6
0
		public CheckSum(Options opt)
		{
			options = opt;
		}
Exemple #7
0
		public MDFour(Options opt)
		{
			options = opt;
		}
Exemple #8
0
		public FileList(Options opt)
		{
			options = opt;
			checkSum = new CheckSum(options);
		}
Exemple #9
0
		public Match(Options opt)
		{
			options = opt;			
		}
Exemple #10
0
 public SysCall(Options opt)
 {
     options = opt;
 }
 public Generator(Options opt)
 {
     options = opt;
     checkSum = new CheckSum(options);
 }
Exemple #12
0
		/*
		public void checkTimeOut()
		{
			if(Options.ioTimeout == 0)
				return;
			if(Options.lastIO == DateTime.MinValue)
			{
				Options.lastIO = DateTime.Now;
				return;
			}

			if(DateTime.Now.Ticks - Options.lastIO.Ticks >= Options.ioTimeout * 10000000)
			{
				if(!Options.amServer && !Options.amDaemon)
					Log.WriteLine("io timeout after "+(DateTime.Now.Ticks - Options.lastIO.Ticks)/10000000+" seconds - exiting");
				Environment.Exit(0);
			}
		}
		 */
		public string readFilesFromLine(Stream fd, Options options)
		{
			string fileName = "";
			bool readingRemotely = options.remoteFilesFromFile != null;
			bool nulls = options.eolNulls || readingRemotely;
			while(true)
			{
				while(true)
				{
					int readByte = fd.ReadByte();
					if(readByte==-1)
						break;
					// ...select
					if(nulls ? readByte == '\0' : (readByte == '\r' || readByte == '\n'))
					{
						if(!readingRemotely && fileName == "")
							continue;
						break;
					}
					fileName += readByte;
				}
				if(fileName == "" || !(fileName[0] == '#' || fileName[0] == ';') )
					break;
				continue;
			}
			return fileName;
		}
Exemple #13
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="stream"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public string readFilesFromLine(Stream stream, Options options)
 {
     string fileName = String.Empty;
     bool readingRemotely = options.remoteFilesFromFile != null;
     bool nulls = options.eolNulls || readingRemotely;
     while (true)
     {
         while (true)
         {
             int readByte = stream.ReadByte();
             if (readByte == -1)
             {
                 break;
             }
             // ...select
             if (nulls ? readByte == '\0' : (readByte == '\r' || readByte == '\n'))
             {
                 if (!readingRemotely && fileName == String.Empty)
                 {
                     continue;
                 }
                 break;
             }
             fileName += readByte;
         }
         if (fileName == String.Empty || !(fileName[0] == '#' || fileName[0] == ';'))
         {
             break;
         }
         continue;
     }
     return fileName;
 }
        /// <summary>
        /// Client-side authorization request maker
        /// </summary>
        /// <param name="user"></param>
        /// <param name="pass"></param>
        /// <param name="challenge"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static string AuthorizeClient(string user, string pass, string challenge, Options options)
        {
            if (String.Empty.Equals(user))
            {
                user = "******";
            }
            if (string.IsNullOrEmpty(pass))
            {
                pass = GetEmptyPassword(password_file);
            }
            if (pass.Equals(String.Empty))
            {
                pass = System.Environment.GetEnvironmentVariable("RSYNC_PASSWORD");
            }
            if (string.IsNullOrEmpty(pass))
            {
                pass = GetPassword();
            }
            string pass2 = GenerateHash(pass, challenge, options);
            Log.WriteLine(user + " " + pass2);

            return pass2;
        }
Exemple #15
0
 /// <summary>
 /// Compares time of modification for given files
 /// </summary>
 /// <param name="file1ModificationTime"></param>
 /// <param name="file2ModificationTime"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public static int CompareModificationTime(long file1ModificationTime, long file2ModificationTime, Options options)
 {
     if (file2ModificationTime > file1ModificationTime)
     {
         if (file2ModificationTime - file1ModificationTime <= options.modifyWindow)
         {
             return(0);
         }
         return(-1);
     }
     if (file1ModificationTime - file2ModificationTime <= options.modifyWindow)
     {
         return(0);
     }
     return(1);
 }
Exemple #16
0
		public Sum(Options opt)
		{
			options = opt;
			md = new MDFour(opt);
		}
Exemple #17
0
 /// <summary>
 /// Compares time of modification for given files
 /// </summary>
 /// <param name="file1ModificationTime"></param>
 /// <param name="file2ModificationTime"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public static int CompareModificationTime(long file1ModificationTime, long file2ModificationTime, Options options)
 {
     if (file2ModificationTime > file1ModificationTime)
     {
         if (file2ModificationTime - file1ModificationTime <= options.modifyWindow)
         {
             return 0;
         }
         return -1;
     }
     if (file1ModificationTime - file2ModificationTime <= options.modifyWindow)
     {
         return 0;
     }
     return 1;
 }
Exemple #18
0
		public Token(Options opt)
		{
			options = opt;			
		}
Exemple #19
0
 public Receiver(Options opt)
 {
     options = opt;
     checkSum = new CheckSum(options);
 }
Exemple #20
0
 public static int ParseArguments(string[] args, Options options)
 {
     int argsNotUsed = 0;
     int i = 0;
     Exclude excl = new Exclude(options);
     while (i < args.Length)
     {
         try
         {
             switch (args[i])
             {
                 case "--version":
                     MainClass.PrintRsyncVersion();
                     MainClass.Exit(String.Empty, null);
                     break;
                 case "--suffix":
                     options.backupSuffix = args[++i];
                     break;
                 case "--rsync-path":
                     options.rsyncPath = args[++i];
                     break;
                 case "--password-file":
                     options.passwordFile = args[++i];
                     break;
                 case "--ignore-times":
                 case "-I":
                     options.ignoreTimes = true;
                     break;
                 case "--size-only":
                     options.sizeOnly = true;
                     break;
                 case "--modify-window":
                     options.usingModifyWindow = true;
                     options.modifyWindow = Convert.ToInt32(args[++i]);
                     break;
                 case "--one-file-system":
                 case "-x":
                     options.oneFileSystem = true;
                     break;
                 case "--delete":
                     options.deleteMode = true;
                     break;
                 case "--existing":
                     options.onlyExisting = true;
                     break;
                 case "--ignore-existing":
                     options.optIgnoreExisting = true;
                     break;
                 case "--delete-after":
                     options.deleteMode = true;
                     options.deleteAfter = true;
                     break;
                 case "--delete-excluded":
                     options.deleteMode = true;
                     options.deleteExcluded = true;
                     break;
                 case "--force":
                     options.forceDelete = true;
                     break;
                 case "--numeric-ids":
                     options.numericIds = true;
                     break;
                 case "--exclude":
                     excl.AddExclude(ref options.excludeList, args[++i], 0);
                     break;
                 case "--include":
                     excl.AddExclude(ref options.excludeList, args[++i], (int)Options.XFLG_DEF_INCLUDE);
                     options.forceDelete = true;
                     break;
                 case "--exclude-from":
                 case "--include-from":
                     string arg = args[i];
                     excl.AddExcludeFile(ref options.excludeList, args[++i],
                             (arg.CompareTo("--exclude-from") == 0) ? 0 : (int)Options.XFLG_DEF_INCLUDE);
                     break;
                 case "--safe-links":
                     options.safeSymlinks = true;
                     break;
                 case "--help":
                 case "-h":
                     MainClass.Usage();
                     MainClass.Exit(String.Empty, null);
                     break;
                 case "--backup":
                 case "-b":
                     options.makeBackups = true;
                     break;
                 case "--dry-run":
                 case "-n":
                     options.dryRun = true;
                     break;
                 case "--sparse":
                 case "-S":
                     options.sparseFiles = true;
                     break;
                 case "--cvs-exclude":
                 case "-C":
                     options.cvsExclude = true;
                     break;
                 case "--update":
                 case "-u":
                     options.updateOnly = true;
                     break;
                 case "--inplace":
                     options.inplace = true;
                     break;
                 case "--keep-dirlinks":
                 case "-K":
                     options.keepDirLinks = true;
                     break;
                 case "--links":
                 case "-l":
                     options.preserveLinks = true;
                     break;
                 case "--copy-links":
                 case "-L":
                     options.copyLinks = true;
                     break;
                 case "--whole-file":
                 case "-W":
                     options.wholeFile = 1;
                     break;
                 case "--no-whole-file":
                     options.wholeFile = 0;
                     break;
                 case "--copy-unsafe-links":
                     options.copyUnsafeLinks = true;
                     break;
                 case "--perms":
                 case "-p":
                     options.preservePerms = true;
                     break;
                 case "--owner":
                 case "-o":
                     options.preserveUID = true;
                     break;
                 case "--group":
                 case "-g":
                     options.preserveGID = true;
                     break;
                 case "--devices":
                 case "-D":
                     options.preserveDevices = true;
                     break;
                 case "--times":
                 case "-t":
                     options.preserveTimes = true;
                     break;
                 case "--checksum":
                 case "-c":
                     options.alwaysChecksum = true;
                     break;
                 case "--verbose":
                 case "-v":
                     options.verbose++;
                     break;
                 case "--quiet":
                 case "-q":
                     options.quiet++;
                     break;
                 case "--archive":
                 case "-a":
                     options.archiveMode = true;
                     break;
                 case "--server":
                     options.amServer = true;
                     break;
                 case "--sender":
                     options.amSender = true;
                     break;
                 case "--recursive":
                 case "-r":
                     options.recurse = true;
                     break;
                 case "--relative":
                 case "-R":
                     options.relativePaths = true;
                     break;
                 case "--no-relative":
                     options.relativePaths = false;
                     break;
                 case "--rsh":
                 case "-e":
                     options.shellCmd = args[++i];
                     break;
                 case "--block-size":
                 case "-B":
                     options.blockSize = Convert.ToInt32(args[++i]);
                     break;
                 case "--max-delete":
                     options.maxDelete = Convert.ToInt32(args[++i]);
                     break;
                 case "--timeout":
                     options.ioTimeout = Convert.ToInt32(args[++i]);
                     break;
                 case "--temp-dir":
                 case "-T":
                     options.tmpDir = args[++i];
                     break;
                 case "--compare-dest":
                     options.compareDest = args[++i];
                     break;
                 case "--link-dest":
                     options.compareDest = args[++i];
                     break;
                 case "--compress":
                 case "-z":
                     options.doCompression = true;
                     break;
                 case "--stats":
                     options.doStats = true;
                     break;
                 case "--progress":
                     options.doProgress = true;
                     break;
                 case "--partial":
                     options.keepPartial = true;
                     break;
                 case "--partial-dir":
                     options.partialDir = args[++i];
                     break;
                 case "--ignore-errors":
                     options.ignoreErrors = true;
                     break;
                 case "--blocking-io":
                     options.blockingIO = 1;
                     break;
                 case "--no-blocking-io":
                     options.blockingIO = 0;
                     break;
                 case "-P":
                     options.doProgress = true;
                     options.keepPartial = true;
                     break;
                 case "--log-format":
                     options.logFormat = args[++i];
                     break;
                 case "--bwlimit":
                     options.bwLimit = Convert.ToInt32(args[++i]);
                     break;
                 case "--backup-dir":
                     options.backupDir = args[++i];
                     break;
                 case "--hard-links":
                 case "-H":
                     options.preserveHardLinks = true;
                     break;
                 case "--read-batch":
                     options.batchName = args[++i];
                     options.readBatch = true;
                     break;
                 case "--write-batch":
                     options.batchName = args[++i];
                     options.writeBatch = true;
                     break;
                 case "--files-from":
                     options.filesFrom = args[++i];
                     break;
                 case "--from0":
                     options.eolNulls = true;
                     break;
                 case "--no-implied-dirs":
                     options.impliedDirs = true;
                     break;
                 case "--protocol":
                     options.protocolVersion = Convert.ToInt32(args[++i]);
                     break;
                 case "--checksum-seed":
                     options.checksumSeed = Convert.ToInt32(args[++i]);
                     break;
                 case "--daemon":
                     options.amDaemon = true;
                     break;
                 case "--address":
                     options.bindAddress = args[++i];
                     break;
                 case "--port":
                     options.rsyncPort = Convert.ToInt32(args[++i]);
                     break;
                 case "--config":
                     options.configFile = args[++i].Trim();
                     break;
                 default:
                     {
                         argsNotUsed += ParseMergeArgs(args[i], options);
                         break;
                     }
             }
             i++;
         }
         catch { return -1; }
     }
     if (options.amSender && !options.amServer)
     {
         MainClass.Usage();
         MainClass.Exit(String.Empty, null);
     }
     if (options.ioTimeout > 0 && options.ioTimeout < options.selectTimeout)
     {
         options.selectTimeout = options.ioTimeout;
     }
     return argsNotUsed;
 }
		public bool LoadParm(Options options)
		{
			lock(this)
			{
				TextReader cf;
				// TODO: path length
				if(confFile == null || confFile.CompareTo("") == 0 || !FileSystem.File.Exists(confFile))
				{
					MainClass.Exit("Can't find .conf file: " + confFile, null);
					return false;			
				}
				try
				{
					cf = new System.IO.StreamReader(confFile);
				}
				catch
				{				
					MainClass.Exit("failed to open: " + confFile, null);
					return false;
				}

				Module mod = null;
			
				if(Modules == null)
					Modules = new ArrayList();
				lock(cf)
				{
					while(true)
					{
						string line = cf.ReadLine();
						if(line == null)
							break;
						line = line.Trim();
						if(line.CompareTo("") != 0 && line[0] != ';' && line[0] != '#')
						{
							if(line[0] == '[' && line[line.Length - 1] == ']')
							{
								line = line.TrimStart('[').TrimEnd(']');
								int numberModule = -1;
								if((numberModule = GetNumberModule(line)) >= 0)
								{ 
									mod = GetModule(numberModule);
								}
								else 
								{
									mod = new Module(line);
									Modules.Add(mod);
								}
							} 
							else 
							{
								if(mod != null)
								{
									string[] parm = line.Split('=');
									if(parm.Length > 2)
										continue;
									parm[0] = parm[0].Trim().ToLower();
									parm[1] = parm[1].Trim();
									switch(parm[0])
									{
										case "path":
											mod.Path = parm[1].Replace(@"\","/");
											break;
										case "comment":
											mod.Comment = parm[1];
											break;
										case "read only":
											mod.ReadOnly = (parm[1].CompareTo("false") == 0) ? false : true;
											break;
										case "write only":
											mod.WriteOnly = (parm[1].CompareTo("true") == 0) ? true : false;
											break;
										case "hosts allow":
											mod.HostsAllow = parm[1];
											break;
										case "hosts deny":
											mod.HostsDeny = parm[1];
											break;
										case "auth users":
											mod.AuthUsers = parm[1];
											break;
										case "secrets file":
											mod.SecretsFile = Path.GetFileName(parm[1]);
											break;
										default:
											continue;
									}
								} 
								else
								{
									string[] parm = line.Split('=');
									if(parm.Length > 2)
										continue;
									parm[0] = parm[0].Trim();
									parm[1] = parm[1].Trim();
									switch(parm[0])
									{
										case "log file":
											string logFile = parm[1];
											try
											{
												options.logFile = new FileStream(logFile, FileMode.OpenOrCreate | FileMode.Append, FileAccess.Write);
											}										
											catch(Exception e)
											{
												Log.Write(e.Message);
											}																				
											break;
										case "port":
											port = parm[1];									
											options.rsyncPort = Convert.ToInt32(port);
											break;
										case "address":
											options.bindAddress = address = parm[1];
											break;
										default:
											continue;
									}
								}
							}
						}
					}
					cf.Close();
				}
			}
			return true;	
		}
Exemple #22
0
        private static int ParseMergeArgs(string MergeArgs, Options options)
        {
            if (MergeArgs != null && MergeArgs.StartsWith("-") && MergeArgs.Substring(1).IndexOf('-') == -1)
            {
                MergeArgs = MergeArgs.Substring(1);
                string[] args = new string[MergeArgs.Length];
                for (int i = 0; i < MergeArgs.Length; i++)
                {
                    args[i] = "-" + MergeArgs[i];
                }
                return ParseArguments(args, options);

            }
            return 1;
        }
Exemple #23
0
		public Exclude(Options opt)
		{
			options = opt;
		}
Exemple #24
0
 public Sender(Options opt)
 {
     options = opt;
     checkSum = new CheckSum(options);
 }