Example #1
0
        public SSHv2(string url, Dictionary<string, string> options)
            : this()
        {
            m_options = options;
            var uri = new Utility.Uri(url);
            uri.RequireHost();
            
            if (options.ContainsKey("auth-username"))
                m_username = options["auth-username"];
            if (options.ContainsKey("auth-password"))
                m_password = options["auth-password"];
            if (!string.IsNullOrEmpty(uri .Username))
                m_username = uri.Username;
            if (!string.IsNullOrEmpty(uri .Password))
                m_password = uri.Password;

            m_path = uri.Path;

            if (!string.IsNullOrWhiteSpace(m_path) && !m_path.EndsWith("/"))
                m_path += "/";

            m_server = uri.Host;

            if (uri.Port > 0)
                m_port = uri.Port;
        }
Example #2
0
        public AzureBlobBackend(string url, Dictionary<string, string> options)
        {
            var uri = new Utility.Uri(url);
            uri.RequireHost();

            string storageAccountName = null;
            string accessKey = null;
            string containerName = uri.Host.ToLowerInvariant();

            if (options.ContainsKey("auth-username"))
                storageAccountName = options["auth-username"];
            if (options.ContainsKey("auth-password"))
                accessKey = options["auth-password"];
            if (options.ContainsKey("azure_account_name"))
                storageAccountName = options["azure_account_name"];
            if (options.ContainsKey("azure_access_key"))
                accessKey = options["azure_access_key"];
            if (!string.IsNullOrEmpty(uri.Username))
                storageAccountName = uri.Username;
            if (!string.IsNullOrEmpty(uri.Password))
                accessKey = uri.Password;

            if (string.IsNullOrWhiteSpace(storageAccountName))
            {
                throw new Exception(Strings.AzureBlobBackend.NoStorageAccountName);
            }
            if (string.IsNullOrWhiteSpace(accessKey))
            {
                throw new Exception(Strings.AzureBlobBackend.NoAccessKey);
            }

            _azureBlob = new AzureBlobWrapper(storageAccountName, accessKey, containerName);
        }
Example #3
0
        public FTP(string url, Dictionary<string, string> options)
        {
            //This can be made better by keeping a single ftp stream open,
            //unfortunately the .Net model does not allow this as the request is 
            //bound to a single url (path+file).
            //
            //To fix this, a thirdparty FTP library is required,
            //this would also allow a fix for the FTP servers
            //that only support SSL during authentication, not during transfers
            //
            //If you have experience with a stable open source .Net FTP library,
            //please let the Duplicati authors know

            var u = new Utility.Uri(url);
            u.RequireHost();

            if (!string.IsNullOrEmpty(u.Username))
            {
                m_userInfo = new System.Net.NetworkCredential();
                m_userInfo.UserName = u.Username;
                if (!string.IsNullOrEmpty(u.Password))
                    m_userInfo.Password = u.Password;
                else if (options.ContainsKey("auth-password"))
                    m_userInfo.Password = options["auth-password"];
            }
            else
            {
                if (options.ContainsKey("auth-username"))
                {
                    m_userInfo = new System.Net.NetworkCredential();
                    m_userInfo.UserName = options["auth-username"];
                    if (options.ContainsKey("auth-password"))
                        m_userInfo.Password = options["auth-password"];
                }
            }

            //Bugfix, see http://connect.microsoft.com/VisualStudio/feedback/details/695227/networkcredential-default-constructor-leaves-domain-null-leading-to-null-object-reference-exceptions-in-framework-code
            if (m_userInfo != null)
                m_userInfo.Domain = "";

            m_url = u.SetScheme("ftp").SetQuery(null).SetCredentials(null, null).ToString();
            if (!m_url.EndsWith("/"))
                m_url += "/";

            m_useSSL = Utility.Utility.ParseBoolOption(options, "use-ssl");

            m_listVerify = !Utility.Utility.ParseBoolOption(options, "disable-upload-verify");

            if (Utility.Utility.ParseBoolOption(options, "ftp-passive"))
            {
                m_defaultPassive = false;
                m_passive = true;
            }
            if (Utility.Utility.ParseBoolOption(options, "ftp-regular"))
            {
                m_defaultPassive = false;
                m_passive = false;
            }
        }
Example #4
0
        public WEBDAV(string url, Dictionary<string, string> options)
        {
            var u = new Utility.Uri(url);
            u.RequireHost();

            if (!string.IsNullOrEmpty(u.Username))
            {
                m_userInfo = new System.Net.NetworkCredential();
                m_userInfo.UserName = u.Username;
                if (!string.IsNullOrEmpty(u.Password))
                    m_userInfo.Password = u.Password;
                else if (options.ContainsKey("auth-password"))
                    m_userInfo.Password = options["auth-password"];
            }
            else
            {
                if (options.ContainsKey("auth-username"))
                {
                    m_userInfo = new System.Net.NetworkCredential();
                    m_userInfo.UserName = options["auth-username"];
                    if (options.ContainsKey("auth-password"))
                        m_userInfo.Password = options["auth-password"];
                }
            }
            
            //Bugfix, see http://connect.microsoft.com/VisualStudio/feedback/details/695227/networkcredential-default-constructor-leaves-domain-null-leading-to-null-object-reference-exceptions-in-framework-code
            if (m_userInfo != null)
                m_userInfo.Domain = "";

            m_useIntegratedAuthentication = Utility.Utility.ParseBoolOption(options, "integrated-authentication");
            m_forceDigestAuthentication = Utility.Utility.ParseBoolOption(options, "force-digest-authentication");
            m_useSSL = Utility.Utility.ParseBoolOption(options, "use-ssl");

            m_url = u.SetScheme(m_useSSL ? "https" : "http").SetCredentials(null, null).SetQuery(null).ToString();
            if (!m_url.EndsWith("/"))
                m_url += "/";

            m_path = u.Path;
            if (!m_path.StartsWith("/"))
            	m_path = "/" + m_path;
            if (!m_path.EndsWith("/"))
            	m_path += "/";

            m_path = System.Web.HttpUtility.UrlDecode(m_path);
            m_rawurl = new Utility.Uri(m_useSSL ? "https" : "http", u.Host, m_path).ToString();

            int port = u.Port;
            if (port <= 0)
                port = m_useSSL ? 443 : 80;

            m_rawurlPort = new Utility.Uri(m_useSSL ? "https" : "http", u.Host, m_path, null, null, null, port).ToString();
			m_sanitizedUrl = new Utility.Uri(m_useSSL ? "https" : "http", u.Host, m_path).ToString();
			m_reverseProtocolUrl = new Utility.Uri(m_useSSL ? "http" : "https", u.Host, m_path).ToString();
            options.TryGetValue("debug-propfind-file", out m_debugPropfindFile);
        }
Example #5
0
        public SSHv2(string url, Dictionary <string, string> options)
            : this()
        {
            m_options = options;
            var uri = new Utility.Uri(url);

            uri.RequireHost();

            if (options.ContainsKey("auth-username"))
            {
                m_username = options["auth-username"];
            }
            if (options.ContainsKey("auth-password"))
            {
                m_password = options["auth-password"];
            }
            if (options.ContainsKey(SSH_FINGERPRINT_OPTION))
            {
                m_fingerprint = options[SSH_FINGERPRINT_OPTION];
            }
            if (!string.IsNullOrEmpty(uri.Username))
            {
                m_username = uri.Username;
            }
            if (!string.IsNullOrEmpty(uri.Password))
            {
                m_password = uri.Password;
            }
            if (uri.QueryParameters != null && uri.QueryParameters[SSH_FINGERPRINT_OPTION] != null)
            {
                m_fingerprint = uri.QueryParameters[SSH_FINGERPRINT_OPTION];
            }

            m_fingerprintallowall = Utility.Utility.ParseBoolOption(options, SSH_FINGERPRINT_ACCEPT_ANY_OPTION);

            m_path = uri.Path;

            if (!string.IsNullOrWhiteSpace(m_path) && !m_path.EndsWith("/"))
            {
                m_path += "/";
            }

            if (!m_path.StartsWith("/"))
            {
                m_path = "/" + m_path;
            }

            m_server = uri.Host;

            if (uri.Port > 0)
            {
                m_port = uri.Port;
            }
        }
Example #6
0
        // ReSharper disable once UnusedMember.Global
        // This constructor is needed by the BackendLoader.
        public AzureBlobBackend(string url, Dictionary <string, string> options)
        {
            var uri = new Utility.Uri(url);

            uri.RequireHost();

            string storageAccountName = null;
            string accessKey          = null;
            string containerName      = uri.Host.ToLowerInvariant();

            if (options.ContainsKey("auth-username"))
            {
                storageAccountName = options["auth-username"];
            }
            if (options.ContainsKey("auth-password"))
            {
                accessKey = options["auth-password"];
            }
            if (options.ContainsKey("azure_account_name"))
            {
                storageAccountName = options["azure_account_name"];
            }
            if (options.ContainsKey("azure_access_key"))
            {
                accessKey = options["azure_access_key"];
            }
            if (!string.IsNullOrEmpty(uri.Username))
            {
                storageAccountName = uri.Username;
            }
            if (!string.IsNullOrEmpty(uri.Password))
            {
                accessKey = uri.Password;
            }

            if (storageAccountName == null && accessKey == null)
            {
                _azureBlob = new AzureBlobWrapper(url);
                return;
            }

            if (string.IsNullOrWhiteSpace(storageAccountName))
            {
                throw new UserInformationException(Strings.AzureBlobBackend.NoStorageAccountName, "AzureNoAccountName");
            }

            if (string.IsNullOrWhiteSpace(accessKey))
            {
                throw new UserInformationException(Strings.AzureBlobBackend.NoAccessKey, "AzureNoAccessKey");
            }

            _azureBlob = new AzureBlobWrapper(storageAccountName, accessKey, containerName);
        }
Example #7
0
        public TahoeBackend(string url, Dictionary<string, string> options)
        {
            //Validate URL
            var u = new Utility.Uri(url);
            u.RequireHost();

            if (!u.Path.StartsWith("uri/URI:DIR2:") && !u.Path.StartsWith("uri/URI%3ADIR2%3A"))
                throw new Exception(Strings.TahoeBackend.UnrecognizedUriError);

            m_useSSL = Utility.Utility.ParseBoolOption(options, "use-ssl");

            m_url = u.SetScheme(m_useSSL ? "https" : "http").SetQuery(null).SetCredentials(null, null).ToString();
            if (!m_url.EndsWith("/"))
                m_url += "/";
        }
Example #8
0
        public TahoeBackend(string url, Dictionary <string, string> options)
        {
            //Validate URL
            var u = new Utility.Uri(url);

            u.RequireHost();

            if (!u.Path.StartsWith("uri/URI:DIR2:", StringComparison.Ordinal) && !u.Path.StartsWith("uri/URI%3ADIR2%3A", StringComparison.Ordinal))
            {
                throw new UserInformationException(Strings.TahoeBackend.UnrecognizedUriError, "TahoeInvalidUri");
            }

            m_useSSL = Utility.Utility.ParseBoolOption(options, "use-ssl");

            m_url = u.SetScheme(m_useSSL ? "https" : "http").SetQuery(null).SetCredentials(null, null).ToString();
            m_url = Util.AppendDirSeparator(m_url, "/");
        }
Example #9
0
        public SSHv2(string url, Dictionary <string, string> options)
            : this()
        {
            m_options = options;
            var uri = new Utility.Uri(url);

            uri.RequireHost();

            if (options.ContainsKey("auth-username"))
            {
                m_username = options["auth-username"];
            }
            if (options.ContainsKey("auth-password"))
            {
                m_password = options["auth-password"];
            }
            if (!string.IsNullOrEmpty(uri.Username))
            {
                m_username = uri.Username;
            }
            if (!string.IsNullOrEmpty(uri.Password))
            {
                m_password = uri.Password;
            }

            m_path = uri.Path;

            if (!string.IsNullOrWhiteSpace(m_path) && !m_path.EndsWith("/"))
            {
                m_path += "/";
            }

            if (!m_path.StartsWith("/"))
            {
                m_path = "/" + m_path;
            }

            m_server = uri.Host;

            if (uri.Port > 0)
            {
                m_port = uri.Port;
            }
        }
Example #10
0
        public TahoeBackend(string url, Dictionary <string, string> options)
        {
            //Validate URL
            var u = new Utility.Uri(url);

            u.RequireHost();

            if (!u.Path.StartsWith("uri/URI:DIR2:") && !u.Path.StartsWith("uri/URI%3ADIR2%3A"))
            {
                throw new UserInformationException(Strings.TahoeBackend.UnrecognizedUriError);
            }

            m_useSSL = Utility.Utility.ParseBoolOption(options, "use-ssl");

            m_url = u.SetScheme(m_useSSL ? "https" : "http").SetQuery(null).SetCredentials(null, null).ToString();
            if (!m_url.EndsWith("/"))
            {
                m_url += "/";
            }
        }
Example #11
0
        public WEBDAV(string url, Dictionary <string, string> options)
        {
            var u = new Utility.Uri(url);

            u.RequireHost();
            m_dnsName = u.Host;

            if (!string.IsNullOrEmpty(u.Username))
            {
                m_userInfo          = new System.Net.NetworkCredential();
                m_userInfo.UserName = u.Username;
                if (!string.IsNullOrEmpty(u.Password))
                {
                    m_userInfo.Password = u.Password;
                }
                else if (options.ContainsKey("auth-password"))
                {
                    m_userInfo.Password = options["auth-password"];
                }
            }
            else
            {
                if (options.ContainsKey("auth-username"))
                {
                    m_userInfo          = new System.Net.NetworkCredential();
                    m_userInfo.UserName = options["auth-username"];
                    if (options.ContainsKey("auth-password"))
                    {
                        m_userInfo.Password = options["auth-password"];
                    }
                }
            }

            //Bugfix, see http://connect.microsoft.com/VisualStudio/feedback/details/695227/networkcredential-default-constructor-leaves-domain-null-leading-to-null-object-reference-exceptions-in-framework-code
            if (m_userInfo != null)
            {
                m_userInfo.Domain = "";
            }

            m_useIntegratedAuthentication = Utility.Utility.ParseBoolOption(options, "integrated-authentication");
            m_forceDigestAuthentication   = Utility.Utility.ParseBoolOption(options, "force-digest-authentication");
            m_useSSL = Utility.Utility.ParseBoolOption(options, "use-ssl");

            m_url = u.SetScheme(m_useSSL ? "https" : "http").SetCredentials(null, null).SetQuery(null).ToString();
            if (!m_url.EndsWith("/", StringComparison.Ordinal))
            {
                m_url += "/";
            }

            m_path = u.Path;
            if (!m_path.StartsWith("/", StringComparison.Ordinal))
            {
                m_path = "/" + m_path;
            }
            if (!m_path.EndsWith("/", StringComparison.Ordinal))
            {
                m_path += "/";
            }

            m_path   = Library.Utility.Uri.UrlDecode(m_path);
            m_rawurl = new Utility.Uri(m_useSSL ? "https" : "http", u.Host, m_path).ToString();

            int port = u.Port;

            if (port <= 0)
            {
                port = m_useSSL ? 443 : 80;
            }

            m_rawurlPort         = new Utility.Uri(m_useSSL ? "https" : "http", u.Host, m_path, null, null, null, port).ToString();
            m_sanitizedUrl       = new Utility.Uri(m_useSSL ? "https" : "http", u.Host, m_path).ToString();
            m_reverseProtocolUrl = new Utility.Uri(m_useSSL ? "http" : "https", u.Host, m_path).ToString();
            options.TryGetValue("debug-propfind-file", out m_debugPropfindFile);
        }
Example #12
0
        public SharePointBackend(string url, Dictionary <string, string> options)
        {
            m_deleteToRecycler    = Utility.Utility.ParseBoolOption(options, "delete-to-recycler");
            m_useBinaryDirectMode = Utility.Utility.ParseBoolOption(options, "binary-direct-mode");

            try
            {
                string strSpan;
                if (options.TryGetValue("web-timeout", out strSpan))
                {
                    TimeSpan ts = Timeparser.ParseTimeSpan(strSpan);
                    if (ts.TotalMilliseconds > 30000 && ts.TotalMilliseconds < int.MaxValue)
                    {
                        this.m_useContextTimeoutMs = (int)ts.TotalMilliseconds;
                    }
                }
            }
            catch { }

            try
            {
                string strChunkSize;
                if (options.TryGetValue("chunk-size", out strChunkSize))
                {
                    long pSize = Utility.Sizeparser.ParseSize(strChunkSize, "MB");
                    if (pSize >= (1 << 14) && pSize <= (1 << 30)) // [16kb .. 1GB]
                    {
                        this.m_fileChunkSize = (int)pSize;
                    }
                }
            }
            catch { }


            var u = new Utility.Uri(url);

            u.RequireHost();

            // Create sanitized plain https-URI (note: still has double slashes for processing web)
            m_orgUrl = new Utility.Uri("https", u.Host, u.Path, null, null, null, u.Port);

            // Actual path to Web will be searched for on first use. Ctor should not throw.
            m_spWebUrl = null;

            m_serverRelPath = u.Path;
            if (!m_serverRelPath.StartsWith("/", StringComparison.Ordinal))
            {
                m_serverRelPath = "/" + m_serverRelPath;
            }
            if (!m_serverRelPath.EndsWith("/", StringComparison.Ordinal))
            {
                m_serverRelPath += "/";
            }
            // remove marker for SP-Web
            m_serverRelPath = m_serverRelPath.Replace("//", "/");

            // Authentication settings processing:
            // Default: try integrated auth (will normally not work for Office365, but maybe with on-prem SharePoint...).
            // Otherwise: Use settings from URL(precedence) or from command line options.
            bool useIntegratedAuthentication = Utility.Utility.ParseBoolOption(options, "integrated-authentication");

            string useUsername = null;
            string usePassword = null;

            if (!useIntegratedAuthentication)
            {
                if (!string.IsNullOrEmpty(u.Username))
                {
                    useUsername = u.Username;
                    if (!string.IsNullOrEmpty(u.Password))
                    {
                        usePassword = u.Password;
                    }
                    else if (options.ContainsKey("auth-password"))
                    {
                        usePassword = options["auth-password"];
                    }
                }
                else
                {
                    if (options.ContainsKey("auth-username"))
                    {
                        useUsername = options["auth-username"];
                        if (options.ContainsKey("auth-password"))
                        {
                            usePassword = options["auth-password"];
                        }
                    }
                }
            }

            if (useIntegratedAuthentication || (useUsername == null || usePassword == null))
            {
                // This might or might not work for on-premises SP. Maybe support if someone complains...
                m_userInfo = System.Net.CredentialCache.DefaultNetworkCredentials;
            }
            else
            {
                System.Security.SecureString securePwd = new System.Security.SecureString();
                usePassword.ToList().ForEach(c => securePwd.AppendChar(c));
                m_userInfo = new Microsoft.SharePoint.Client.SharePointOnlineCredentials(useUsername, securePwd);
                // Other options (also ADAL, see class remarks) might be supported on request.
                // Maybe go in deep then and also look at:
                // - Microsoft.SharePoint.Client.AppPrincipalCredential.CreateFromKeyGroup()
                // - ctx.AuthenticationMode = SP.ClientAuthenticationMode.FormsAuthentication;
                // - ctx.FormsAuthenticationLoginInfo = new SP.FormsAuthenticationLoginInfo(user, pwd);
            }
        }
Example #13
0
        public SSHv2(string url, Dictionary <string, string> options)
            : this()
        {
            m_options = options;
            var uri = new Utility.Uri(url);

            uri.RequireHost();

            if (options.ContainsKey("auth-username"))
            {
                m_username = options["auth-username"];
            }
            if (options.ContainsKey("auth-password"))
            {
                m_password = options["auth-password"];
            }
            if (options.ContainsKey(SSH_FINGERPRINT_OPTION))
            {
                m_fingerprint = options[SSH_FINGERPRINT_OPTION];
            }
            if (!string.IsNullOrEmpty(uri.Username))
            {
                m_username = uri.Username;
            }
            if (!string.IsNullOrEmpty(uri.Password))
            {
                m_password = uri.Password;
            }

            m_fingerprintallowall = Utility.Utility.ParseBoolOption(options, SSH_FINGERPRINT_ACCEPT_ANY_OPTION);

            m_path = uri.Path;

            if (!string.IsNullOrWhiteSpace(m_path) && !m_path.EndsWith("/"))
            {
                m_path += "/";
            }

            if (!m_path.StartsWith("/"))
            {
                m_path = "/" + m_path;
            }

            m_server = uri.Host;

            if (uri.Port > 0)
            {
                m_port = uri.Port;
            }

            string timeoutstr;

            options.TryGetValue(SSH_TIMEOUT_OPTION, out timeoutstr);

            if (!string.IsNullOrWhiteSpace(timeoutstr))
            {
                m_operationtimeout = Library.Utility.Timeparser.ParseTimeSpan(timeoutstr);
            }

            options.TryGetValue(SSH_KEEPALIVE_OPTION, out timeoutstr);

            if (!string.IsNullOrWhiteSpace(timeoutstr))
            {
                m_keepaliveinterval = Library.Utility.Timeparser.ParseTimeSpan(timeoutstr);
            }
        }
Example #14
0
        public S3(string url, Dictionary <string, string> options)
        {
            var uri = new Utility.Uri(url);

            uri.RequireHost();

            string host = uri.Host;

            m_prefix = uri.Path;

            string awsID  = null;
            string awsKey = null;

            if (options.ContainsKey("auth-username"))
            {
                awsID = options["auth-username"];
            }
            if (options.ContainsKey("auth-password"))
            {
                awsKey = options["auth-password"];
            }

            if (options.ContainsKey("aws_access_key_id"))
            {
                awsID = options["aws_access_key_id"];
            }
            if (options.ContainsKey("aws_secret_access_key"))
            {
                awsKey = options["aws_secret_access_key"];
            }
            if (!string.IsNullOrEmpty(uri.Username))
            {
                awsID = uri.Username;
            }
            if (!string.IsNullOrEmpty(uri.Password))
            {
                awsKey = uri.Password;
            }

            if (string.IsNullOrEmpty(awsID))
            {
                throw new UserInformationException(Strings.S3Backend.NoAMZUserIDError);
            }
            if (string.IsNullOrEmpty(awsKey))
            {
                throw new UserInformationException(Strings.S3Backend.NoAMZKeyError);
            }

            bool euBuckets = Utility.Utility.ParseBoolOption(options, EU_BUCKETS_OPTION);
            bool useRRS    = Utility.Utility.ParseBoolOption(options, RRS_OPTION);
            bool useSSL    = Utility.Utility.ParseBoolOption(options, SSL_OPTION);

            string locationConstraint;

            options.TryGetValue(LOCATION_OPTION, out locationConstraint);

            if (!string.IsNullOrEmpty(locationConstraint) && euBuckets)
            {
                throw new UserInformationException(Strings.S3Backend.OptionsAreMutuallyExclusiveError(LOCATION_OPTION, EU_BUCKETS_OPTION));
            }

            if (euBuckets)
            {
                locationConstraint = S3_EU_REGION_NAME;
            }

            string storageClass;

            options.TryGetValue(STORAGECLASS_OPTION, out storageClass);
            if (string.IsNullOrWhiteSpace(storageClass) && useRRS)
            {
                storageClass = S3_RRS_CLASS_NAME;
            }

            string s3host;

            options.TryGetValue(SERVER_NAME, out s3host);
            if (string.IsNullOrEmpty(s3host))
            {
                s3host = DEFAULT_S3_HOST;

                //Change in S3, now requires that you use location specific endpoint
                if (!string.IsNullOrEmpty(locationConstraint))
                {
                    foreach (KeyValuePair <string, string> kvp in DEFAULT_S3_LOCATION_BASED_HOSTS)
                    {
                        if (kvp.Key.Equals(locationConstraint, StringComparison.InvariantCultureIgnoreCase))
                        {
                            s3host = kvp.Value;
                            break;
                        }
                    }
                }
            }

            //Fallback to previous formats
            if (host.Contains(DEFAULT_S3_HOST))
            {
                Uri u = new Uri(url);
                host     = u.Host;
                m_prefix = "";

                if (host.ToLower() == s3host)
                {
                    m_bucket = Library.Utility.Uri.UrlDecode(u.PathAndQuery);

                    if (m_bucket.StartsWith("/"))
                    {
                        m_bucket = m_bucket.Substring(1);
                    }

                    if (m_bucket.Contains("/"))
                    {
                        m_prefix = m_bucket.Substring(m_bucket.IndexOf("/") + 1);
                        m_bucket = m_bucket.Substring(0, m_bucket.IndexOf("/"));
                    }
                }
                else
                {
                    //Subdomain type lookup
                    if (host.ToLower().EndsWith("." + s3host))
                    {
                        m_bucket = host.Substring(0, host.Length - ("." + s3host).Length);
                        host     = s3host;
                        m_prefix = Library.Utility.Uri.UrlDecode(u.PathAndQuery);

                        if (m_prefix.StartsWith("/"))
                        {
                            m_prefix = m_prefix.Substring(1);
                        }
                    }
                    else
                    {
                        throw new UserInformationException(Strings.S3Backend.UnableToDecodeBucketnameError(url));
                    }
                }

                try { Console.Error.WriteLine(Strings.S3Backend.DeprecatedUrlFormat("s3://" + m_bucket + "/" + m_prefix)); }
                catch { }
            }
            else
            {
                //The new simplified url style s3://bucket/prefix
                m_bucket = host;
                host     = s3host;
            }

            m_options = options;
            m_prefix  = m_prefix.Trim();
            if (m_prefix.Length != 0 && !m_prefix.EndsWith("/"))
            {
                m_prefix += "/";
            }

            m_wrapper = new S3Wrapper(awsID, awsKey, locationConstraint, host, storageClass, useSSL, options);
        }
Example #15
0
        public FTP(string url, Dictionary <string, string> options)
        {
            //This can be made better by keeping a single ftp stream open,
            //unfortunately the .Net model does not allow this as the request is
            //bound to a single url (path+file).
            //
            //To fix this, a thirdparty FTP library is required,
            //this would also allow a fix for the FTP servers
            //that only support SSL during authentication, not during transfers
            //
            //If you have experience with a stable open source .Net FTP library,
            //please let the Duplicati authors know

            var u = new Utility.Uri(url);

            u.RequireHost();

            if (!string.IsNullOrEmpty(u.Username))
            {
                m_userInfo          = new System.Net.NetworkCredential();
                m_userInfo.UserName = u.Username;
                if (!string.IsNullOrEmpty(u.Password))
                {
                    m_userInfo.Password = u.Password;
                }
                else if (options.ContainsKey("auth-password"))
                {
                    m_userInfo.Password = options["auth-password"];
                }
            }
            else
            {
                if (options.ContainsKey("auth-username"))
                {
                    m_userInfo          = new System.Net.NetworkCredential();
                    m_userInfo.UserName = options["auth-username"];
                    if (options.ContainsKey("auth-password"))
                    {
                        m_userInfo.Password = options["auth-password"];
                    }
                }
            }

            //Bugfix, see http://connect.microsoft.com/VisualStudio/feedback/details/695227/networkcredential-default-constructor-leaves-domain-null-leading-to-null-object-reference-exceptions-in-framework-code
            if (m_userInfo != null)
            {
                m_userInfo.Domain = "";
            }

            m_url = u.SetScheme("ftp").SetQuery(null).SetCredentials(null, null).ToString();
            if (!m_url.EndsWith("/"))
            {
                m_url += "/";
            }

            m_useSSL = Utility.Utility.ParseBoolOption(options, "use-ssl");

            m_listVerify = !Utility.Utility.ParseBoolOption(options, "disable-upload-verify");

            if (Utility.Utility.ParseBoolOption(options, "ftp-passive"))
            {
                m_defaultPassive = false;
                m_passive        = true;
            }
            if (Utility.Utility.ParseBoolOption(options, "ftp-regular"))
            {
                m_defaultPassive = false;
                m_passive        = false;
            }
        }
Example #16
0
        public SharePointBackend(string url, Dictionary<string, string> options)
        {
            m_deleteToRecycler = Utility.Utility.ParseBoolOption(options, "delete-to-recycler");
            m_useBinaryDirectMode = Utility.Utility.ParseBoolOption(options, "binary-direct-mode");

            try
            {
                string strSpan;
                if (options.TryGetValue("web-timeout", out strSpan))
                {
                    TimeSpan ts = Timeparser.ParseTimeSpan(strSpan);
                    if (ts.TotalMilliseconds > 30000 && ts.TotalMilliseconds < int.MaxValue)
                        this.m_useContextTimeoutMs = (int)ts.TotalMilliseconds;
                }
            }
            catch { }

            try
            {
                string strChunkSize;
                if (options.TryGetValue("chunk-size", out strChunkSize))
                {
                    long pSize = Utility.Sizeparser.ParseSize(strChunkSize, "MB");
                    if (pSize >= (1 << 14) && pSize <= (1 << 30)) // [16kb .. 1GB]
                        this.m_fileChunkSize = (int)pSize;
                }
            }
            catch { }

            var u = new Utility.Uri(url);
            u.RequireHost();

            // Create sanitized plain https-URI (note: still has double slashes for processing web)
            m_orgUrl = new Utility.Uri("https", u.Host, u.Path, null, null, null, u.Port);

            // Actual path to Web will be searched for on first use. Ctor should not throw.
            m_spWebUrl = null;

            m_serverRelPath = u.Path;
            if (!m_serverRelPath.StartsWith("/"))
                m_serverRelPath = "/" + m_serverRelPath;
            if (!m_serverRelPath.EndsWith("/"))
                m_serverRelPath += "/";
            // remove marker for SP-Web
            m_serverRelPath = m_serverRelPath.Replace("//", "/");

            // Authentication settings processing:
            // Default: try integrated auth (will normally not work for Office365, but maybe with on-prem SharePoint...).
            // Otherwise: Use settings from URL(precedence) or from command line options.
            bool useIntegratedAuthentication = Utility.Utility.ParseBoolOption(options, "integrated-authentication");

            string useUsername = null;
            string usePassword = null;

            if (!useIntegratedAuthentication)
            {
                if (!string.IsNullOrEmpty(u.Username))
                {
                    useUsername = u.Username;
                    if (!string.IsNullOrEmpty(u.Password))
                        usePassword = u.Password;
                    else if (options.ContainsKey("auth-password"))
                        usePassword = options["auth-password"];
                }
                else
                {
                    if (options.ContainsKey("auth-username"))
                    {
                        useUsername = options["auth-username"];
                        if (options.ContainsKey("auth-password"))
                            usePassword = options["auth-password"];
                    }
                }
            }

            if (useIntegratedAuthentication || (useUsername == null || usePassword == null))
            {
                // This might or might not work for on-premises SP. Maybe support if someone complains...
                m_userInfo = System.Net.CredentialCache.DefaultNetworkCredentials;
            }
            else
            {
                System.Security.SecureString securePwd = new System.Security.SecureString();
                usePassword.ToList().ForEach(c => securePwd.AppendChar(c));
                m_userInfo = new Microsoft.SharePoint.Client.SharePointOnlineCredentials(useUsername, securePwd);
                // Other options (also ADAL, see class remarks) might be supported on request.
                // Maybe go in deep then and also look at:
                // - Microsoft.SharePoint.Client.AppPrincipalCredential.CreateFromKeyGroup()
                // - ctx.AuthenticationMode = SP.ClientAuthenticationMode.FormsAuthentication;
                // - ctx.FormsAuthenticationLoginInfo = new SP.FormsAuthenticationLoginInfo(user, pwd);
            }
        }
Example #17
0
        public S3(string url, Dictionary <string, string> options)
        {
            var uri = new Utility.Uri(url);

            uri.RequireHost();

            string host = uri.Host;

            m_prefix = uri.Path;

            string awsID  = null;
            string awsKey = null;

            if (options.ContainsKey("auth-username"))
            {
                awsID = options["auth-username"];
            }
            if (options.ContainsKey("auth-password"))
            {
                awsKey = options["auth-password"];
            }

            if (options.ContainsKey("aws_access_key_id"))
            {
                awsID = options["aws_access_key_id"];
            }
            if (options.ContainsKey("aws_secret_access_key"))
            {
                awsKey = options["aws_secret_access_key"];
            }
            if (!string.IsNullOrEmpty(uri.Username))
            {
                awsID = uri.Username;
            }
            if (!string.IsNullOrEmpty(uri.Password))
            {
                awsKey = uri.Password;
            }

            if (string.IsNullOrEmpty(awsID))
            {
                throw new UserInformationException(Strings.S3Backend.NoAMZUserIDError, "S3NoAmzUserID");
            }
            if (string.IsNullOrEmpty(awsKey))
            {
                throw new UserInformationException(Strings.S3Backend.NoAMZKeyError, "S3NoAmzKey");
            }

            bool euBuckets = Utility.Utility.ParseBoolOption(options, EU_BUCKETS_OPTION);
            bool useRRS    = Utility.Utility.ParseBoolOption(options, RRS_OPTION);
            bool useSSL    = Utility.Utility.ParseBoolOption(options, SSL_OPTION);

            string locationConstraint;

            options.TryGetValue(LOCATION_OPTION, out locationConstraint);

            if (!string.IsNullOrEmpty(locationConstraint) && euBuckets)
            {
                throw new UserInformationException(Strings.S3Backend.OptionsAreMutuallyExclusiveError(LOCATION_OPTION, EU_BUCKETS_OPTION), "S3CannotMixLocationAndEuOptions");
            }

            if (euBuckets)
            {
                locationConstraint = S3_EU_REGION_NAME;
            }

            string storageClass;

            options.TryGetValue(STORAGECLASS_OPTION, out storageClass);
            if (string.IsNullOrWhiteSpace(storageClass) && useRRS)
            {
                storageClass = S3_RRS_CLASS_NAME;
            }

            string s3host;

            options.TryGetValue(SERVER_NAME, out s3host);
            if (string.IsNullOrEmpty(s3host))
            {
                s3host = DEFAULT_S3_HOST;

                //Change in S3, now requires that you use location specific endpoint
                if (!string.IsNullOrEmpty(locationConstraint))
                {
                    if (DEFAULT_S3_LOCATION_BASED_HOSTS.TryGetValue(locationConstraint, out var s3hostmatch))
                    {
                        s3host = s3hostmatch;
                    }
                }
            }

            //Fallback to previous formats
            if (host.Contains(DEFAULT_S3_HOST))
            {
                Uri u = new Uri(url);
                host     = u.Host;
                m_prefix = "";

                if (String.Equals(host, s3host, StringComparison.OrdinalIgnoreCase))
                {
                    m_bucket = Utility.Uri.UrlDecode(u.PathAndQuery);

                    if (m_bucket.StartsWith("/", StringComparison.Ordinal))
                    {
                        m_bucket = m_bucket.Substring(1);
                    }

                    if (m_bucket.Contains("/"))
                    {
                        m_prefix = m_bucket.Substring(m_bucket.IndexOf("/", StringComparison.Ordinal) + 1);
                        m_bucket = m_bucket.Substring(0, m_bucket.IndexOf("/", StringComparison.Ordinal));
                    }
                }
                else
                {
                    //Subdomain type lookup
                    if (host.EndsWith("." + s3host, StringComparison.OrdinalIgnoreCase))
                    {
                        m_bucket = host.Substring(0, host.Length - ("." + s3host).Length);
                        host     = s3host;
                        m_prefix = Utility.Uri.UrlDecode(u.PathAndQuery);

                        if (m_prefix.StartsWith("/", StringComparison.Ordinal))
                        {
                            m_prefix = m_prefix.Substring(1);
                        }
                    }
                    else
                    {
                        throw new UserInformationException(Strings.S3Backend.UnableToDecodeBucketnameError(url), "S3CannotDecodeBucketName");
                    }
                }

                Logging.Log.WriteWarningMessage(LOGTAG, "DeprecatedS3Format", null, Strings.S3Backend.DeprecatedUrlFormat("s3://" + m_bucket + "/" + m_prefix));
            }
            else
            {
                //The new simplified url style s3://bucket/prefix
                m_bucket = host;
                host     = s3host;
            }

            m_prefix = m_prefix.Trim();
            if (m_prefix.Length != 0)
            {
                m_prefix = Util.AppendDirSeparator(m_prefix, "/");
            }

            // Auto-disable dns lookup for non AWS configurations
            var hasForcePathStyle = options.ContainsKey("s3-ext-forcepathstyle");

            if (!hasForcePathStyle && !DEFAULT_S3_LOCATION_BASED_HOSTS.Any(x => string.Equals(x.Value, host, StringComparison.OrdinalIgnoreCase)) && !string.Equals(host, "s3.amazonaws.com", StringComparison.OrdinalIgnoreCase))
            {
                options["s3-ext-forcepathstyle"] = "true";
            }


            options.TryGetValue(S3_CLIENT_OPTION, out var s3ClientOptionValue);

            if (s3ClientOptionValue == "aws" || s3ClientOptionValue == null)
            {
                s3Client = new S3AwsClient(awsID, awsKey, locationConstraint, host, storageClass, useSSL, options);
            }
            else
            {
                s3Client = new S3MinioClient(awsID, awsKey, locationConstraint, host, storageClass, useSSL, options);
            }
        }
Example #18
0
        public SharePointBackend(string url, Dictionary <string, string> options)
        {
            m_deleteToRecycler = Utility.Utility.ParseBoolOption(options, "delete-to-recycler");

            var u = new Utility.Uri(url);

            u.RequireHost();

            // Create sanitized plain https-URI (note: still has double slashes for processing web)
            m_orgUrl = new Utility.Uri("https", u.Host, u.Path, null, null, null, u.Port);

            // Actual path to Web will be searched for on first use. Ctor should not throw.
            m_spWebUrl = null;

            m_serverRelPath = u.Path;
            if (!m_serverRelPath.StartsWith("/"))
            {
                m_serverRelPath = "/" + m_serverRelPath;
            }
            if (!m_serverRelPath.EndsWith("/"))
            {
                m_serverRelPath += "/";
            }
            // remove marker for SP-Web
            m_serverRelPath = m_serverRelPath.Replace("//", "/");

            // Authentication settings processing:
            // Default: try integrated auth (will normally not work for Office365, but maybe with on-prem SharePoint...).
            // Otherwise: Use settings from URL(precedence) or from command line options.
            bool useIntegratedAuthentication = Utility.Utility.ParseBoolOption(options, "integrated-authentication");

            string useUsername = null;
            string usePassword = null;

            if (!useIntegratedAuthentication)
            {
                if (!string.IsNullOrEmpty(u.Username))
                {
                    useUsername = u.Username;
                    if (!string.IsNullOrEmpty(u.Password))
                    {
                        usePassword = u.Password;
                    }
                    else if (options.ContainsKey("auth-password"))
                    {
                        usePassword = options["auth-password"];
                    }
                }
                else
                {
                    if (options.ContainsKey("auth-username"))
                    {
                        useUsername = options["auth-username"];
                        if (options.ContainsKey("auth-password"))
                        {
                            usePassword = options["auth-password"];
                        }
                    }
                }
            }

            if (useIntegratedAuthentication || (useUsername == null || usePassword == null))
            {
                // This might or might not work for on-premises SP. Maybe support if someone complains...
                m_userInfo = System.Net.CredentialCache.DefaultNetworkCredentials;
            }
            else
            {
                System.Security.SecureString securePwd = new System.Security.SecureString();
                usePassword.ToList().ForEach(c => securePwd.AppendChar(c));
                m_userInfo = new Microsoft.SharePoint.Client.SharePointOnlineCredentials(useUsername, securePwd);
                // Other options (also ADAL, see class remarks) might be supported on request.
                // Maybe go in deep then and also look at:
                // - Microsoft.SharePoint.Client.AppPrincipalCredential.CreateFromKeyGroup()
                // - ctx.AuthenticationMode = SP.ClientAuthenticationMode.FormsAuthentication;
                // - ctx.FormsAuthenticationLoginInfo = new SP.FormsAuthenticationLoginInfo(user, pwd);
            }
        }
Example #19
0
        public S3(string url, Dictionary<string, string> options)
        {
            var uri = new Utility.Uri(url);
            uri.RequireHost();

            string host = uri.Host;
            m_prefix = uri.Path;

            string awsID = null;
            string awsKey = null;

            if (options.ContainsKey("auth-username"))
                awsID = options["auth-username"];
            if (options.ContainsKey("auth-password"))
                awsKey = options["auth-password"];

            if (options.ContainsKey("aws_access_key_id"))
                awsID = options["aws_access_key_id"];
            if (options.ContainsKey("aws_secret_access_key"))
                awsKey = options["aws_secret_access_key"];
            if (!string.IsNullOrEmpty(uri.Username))
                awsID = uri.Username;
            if (!string.IsNullOrEmpty(uri.Password))
                awsKey = uri.Password;

            if (string.IsNullOrEmpty(awsID))
                throw new Exception(Strings.S3Backend.NoAMZUserIDError);
            if (string.IsNullOrEmpty(awsKey))
                throw new Exception(Strings.S3Backend.NoAMZKeyError);

            bool euBuckets = Utility.Utility.ParseBoolOption(options, EU_BUCKETS_OPTION);
            bool useRRS = Utility.Utility.ParseBoolOption(options, RRS_OPTION);
            bool useSSL = Utility.Utility.ParseBoolOption(options, SSL_OPTION);

            string locationConstraint;
            options.TryGetValue(LOCATION_OPTION, out locationConstraint);

            if (!string.IsNullOrEmpty(locationConstraint) && euBuckets)
                throw new Exception(string.Format(Strings.S3Backend.OptionsAreMutuallyExclusiveError, LOCATION_OPTION, EU_BUCKETS_OPTION));

            if (euBuckets)
                locationConstraint = S3_EU_REGION_NAME;

            string s3host;
            options.TryGetValue(SERVER_NAME, out s3host);
            if (string.IsNullOrEmpty(s3host))
            {
                s3host = DEFAULT_S3_HOST;

                //Change in S3, now requires that you use location specific endpoint
                if (!string.IsNullOrEmpty(locationConstraint))
                    foreach(KeyValuePair<string, string> kvp in DEFAULT_S3_LOCATION_BASED_HOSTS)
                        if (kvp.Key.Equals(locationConstraint, StringComparison.InvariantCultureIgnoreCase))
                        {
                            s3host = kvp.Value;
                            break;
                        }
            }

            //Fallback to previous formats
            if (host.Contains(DEFAULT_S3_HOST))
            {
                Uri u = new Uri(url);
                host = u.Host;
                m_prefix = "";

                if (host.ToLower() == s3host)
                {
                    m_bucket = System.Web.HttpUtility.UrlDecode(u.PathAndQuery);

                    if (m_bucket.StartsWith("/"))
                        m_bucket = m_bucket.Substring(1);

                    if (m_bucket.Contains("/"))
                    {
                        m_prefix = m_bucket.Substring(m_bucket.IndexOf("/") + 1);
                        m_bucket = m_bucket.Substring(0, m_bucket.IndexOf("/"));
                    }
                }
                else
                {
                    //Subdomain type lookup
                    if (host.ToLower().EndsWith("." + s3host))
                    {
                        m_bucket = host.Substring(0, host.Length - ("." + s3host).Length);
                        host = s3host;
                        m_prefix = System.Web.HttpUtility.UrlDecode(u.PathAndQuery);

                        if (m_prefix.StartsWith("/"))
                            m_prefix = m_prefix.Substring(1);
                    }
                    else
                        throw new Exception(string.Format(Strings.S3Backend.UnableToDecodeBucketnameError, url));
                }

                try { Console.Error.WriteLine(string.Format(Strings.S3Backend.DeprecatedUrlFormat, "s3://" + m_bucket + "/" + m_prefix)); }
                catch { }
            }
            else
            {
                //The new simplified url style s3://bucket/prefix
                m_bucket = host;
                host = s3host;
            }

            m_options = options;
            m_prefix = m_prefix.Trim();
            if (m_prefix.Length != 0 && !m_prefix.EndsWith("/"))
                m_prefix += "/";

            m_wrapper = new S3Wrapper(awsID, awsKey, locationConstraint, host, useRRS, useSSL);
        }