/// <summary>
 /// Initializes a new instance of the <see cref="IndexDirectory"/> class.
 /// </summary>
 /// <param name="type">The DirectoryType of this <c>IndexDirectory</c>.</param>
 /// <param name="directoryPath">The directory path.</param>
 public IndexDirectory(DirectoryType type, string directoryPath)
 {
     if (type == DirectoryType.FileSystemDirectory && (string.IsNullOrEmpty(directoryPath) || !Directory.Exists(directoryPath)))
         throw new ArgumentException("DirectoryPath cannot be null and must exist for file system operations");
     this.directoryType = type;
     this.directoryPath = directoryPath;
 }
 public IEnumerable<Model.Node> Select(DirectoryType directoryType)
 {
     using (var conn = Database.Open())
     {
         return conn.Query<Model.Node, Model.DirectoryInfo, Model.Node>(NodeSql.SelectByDirectoryType(directoryType.GetHashCode()), SelectConvert, splitOn: "split");
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="IndexDirectory"/> class.
 /// </summary>
 /// <param name="type">The DirectoryType of this <c>IndexDirectory</c>.</param>
 /// <param name="directoryInfo">The directory info.</param>
 public IndexDirectory(DirectoryType type, DirectoryInfo directoryInfo)
 {
     if (directoryInfo == null)
         throw new ArgumentNullException("directoryInfo", "directoryInfo cannot be null");
     if (type == IndexLibrary.DirectoryType.FileSystemDirectory && !directoryInfo.Exists)
         throw new DirectoryNotFoundException("directoryInfo does not exist, and needs to for FileSystemDirectory types");
     this.directoryPath = directoryInfo.FullName;
     this.directoryType = type;
 }
        private static string GetSpecialDirectoryName(DirectoryType type)
        {
            switch (type)
            {
                case DirectoryType.AvatarDirectory:
                    return "Avatar";

                case DirectoryType.PhotoDirectory:
                default:
                    return "Photo";
            }
        }
Esempio n. 5
0
        private DirectoryType InitCiscoDirectory()
        {
            DirectoryType dir = new DirectoryType();

            dir.name = tbDirectoryName.Text;
            CiscoDatasourceType cdt = new CiscoDatasourceType();

            cdt.server     = tbCiscoServer.Text;
            cdt.axluser    = tbAXLUser.Text;
            cdt.axluserpwd = tbAXLUserPassword.Text;
            dir.Item       = cdt;
            return(dir);
        }
 private void AddFolders(string path, DirectoryType type, string header = null, string description = null)
 {
     Dispatcher.Invoke(() =>
     {
         ((HierarchicalItem)MainTreeView.Items[0]).Items.Add(new HierarchicalItem
         {
             Category    = type,
             Header      = header,
             FullPath    = path,
             Description = description
         });
     });
 }
 private void AddRoot(DirectoryType type, string header = null, string path = null)
 {
     Dispatcher.Invoke(() =>
     {
         MainTreeView.Items.Add(new HierarchicalItem
         {
             Category   = type,
             IsExpanded = true,
             Header     = header,
             FullPath   = path
         });
     });
 }
Esempio n. 8
0
 public Directory this[DirectoryType i]
 {
     get
     {
         if (!_dico.ContainsKey(i))
         {
             _dico[i] = new Directory(this);
         }
         return(_dico[i]);
     }
     set
     {
         _dico[i] = value;
     }
 }
 public FileDirectoryInfo(string fileSize, DirectoryType type, string name, string date, string adress, string displayName)
 {
     FileSize    = fileSize;
     Type        = type;
     Name        = name;
     Date        = date;
     DisplayName = displayName;
     //MessageBox.Show(getFileType(name));
     //if (type == DirectoryType.File)
     //{
     //    FileType = getFileType(name);
     //    MessageBox.Show(getFileType(name));
     //}
     this.Adress = adress;
 }
Esempio n. 10
0
        public void UpdateDirectory(DirectoryType dir)
        {
            var initialFile = "";

            switch (dir)
            {
            case DirectoryType.Source:
                initialFile = Source;
                break;

            case DirectoryType.Destination:
                initialFile = Destination;
                break;

            case DirectoryType.SecondDestination:
                initialFile = SecondDestination;
                break;

            default:
                break;
            }
            ;
            var result = _fileDialogService.GetFile(Title[dir], initialFile);

            if (!result.Success)
            {
                return;
            }

            switch (dir)
            {
            case DirectoryType.Source:
                Source = result.File;
                break;

            case DirectoryType.Destination:
                Destination = result.File;
                break;

            case DirectoryType.SecondDestination:
                SecondDestination = result.File;
                break;

            default:
                break;
            }
        }
Esempio n. 11
0
        private static bool FindDirectoryFromName(DirectoryType dir)
        {
            bool found = false;

            if (currentDirectoryName != "")
            {
                if (dir.name == currentDirectoryName)
                {
                    found = true;
                }
            }
            else
            {
                log.Debug("Looking for a directory with an empty name field is not allowed");
            }
            return(found);
        }
            public LdapSyncConfiguration(DirectoryType type)
            {
                switch (type)
                {
                case DirectoryType.ActiveDirectory:
                    CreationDateAttribute    = "whenCreated";
                    RevisionDateAttribute    = "whenChanged";
                    UserEmailPrefixAttribute = "sAMAccountName";
                    UserPath  = "CN=Users";
                    GroupPath = "CN=Users";
                    break;

                case DirectoryType.Other:
                    break;

                default:
                    break;
                }
            }
Esempio n. 13
0
 private static void OnCacheSuppress(string key, object value, System.Web.Caching.CacheItemRemovedReason reason)
 {
     log.Debug("Cache deleted: " + key + " reason: " + reason.ToString());
     try
     {
         DirectoryType dt = GetDirectory(key);
         if (dt != null)
         {
             log.Debug("Reinit directory cache...");
             if (HttpRuntime.Cache.Get(dt.name) == null)
             {
                 InitDirectoryCache();
             }
         }
     }
     catch (Exception e)
     {
         log.Debug("Unable to reinsert " + key + " object " + e.Message);
     }
 }
Esempio n. 14
0
 /// <summary>
 /// Grant Read Rights to the LDAP User on the the LDAP Container
 /// </summary>
 /// <param name="userDN">The LDAP User DN</param>
 /// <param name="containerDN">The LDAP Container DN</param>
 public void GrantReadRights(string userDN, string containerDN)
 {
     if (DirectoryType.Equals(LdapDirectoryType.ActiveDirectory))
     {
         // TODO: Modify this to support Active Directory
     }
     else if (DirectoryType.Equals(LdapDirectoryType.OpenLDAP))
     {
         // TODO: Modify this to support OpenLDAP.
     }
     else if (DirectoryType.Equals(LdapDirectoryType.eDirectory))
     {
         LdapAttribute attribute = new LdapAttribute("acl", new String[]
         {
             String.Format("1#subtree#{0}#[Entry Rights]", userDN),
             String.Format("3#subtree#{0}#[All Attributes Rights]", userDN)
         });
         LdapModification modification = new LdapModification(LdapModification.ADD, attribute);
         connection.Modify(containerDN, modification);
     }
 }
        public static ServerPath GetFilePath(this HttpContextBase httpContext, DirectoryType type, string userName, string extention)
        {
            string rootPath = httpContext.Server.MapPath("~/UserData/");
            string userDirectoryPath = Path.Combine(rootPath, userName);
            string specialDirectoryName = GetSpecialDirectoryName(type);
            string specialDirectoryPath = Path.Combine(userDirectoryPath, specialDirectoryName);

            if (!Directory.Exists(userDirectoryPath) || !Directory.Exists(specialDirectoryPath))
            {
                throw new DirectoryNotFoundException("User directory don't exist.");
            }

            string name = Path.GetRandomFileName();
            string newFileName = Path.ChangeExtension(name, extention);

            return new ServerPath()
            {
                AbsolutePath = Path.Combine(specialDirectoryPath, newFileName),
                LocalPath = Path.Combine("/UserData", userName, specialDirectoryName, newFileName)
            };
        }
Esempio n. 16
0
        public static DataSet Search(DirectoryType dir)
        {
            DataSet results = new DataSet();
            DataTable dt = results.Tables.Add();
            CiscoDatasourceType ldt = (CiscoDatasourceType)dir.Item;
            try
            {
                Init(ldt.server, ldt.axluser, ldt.axluserpwd);
                ExecuteSQLQueryReq query = new ExecuteSQLQueryReq();
                query.sql = "select firstname, lastname, telephonenumber, department from enduser";
                ExecuteSQLQueryRes response = _axl.executeSQLQuery(query);
                dt.Columns.Add("firstname");
                dt.Columns.Add("lastname");
                dt.Columns.Add("telephonenumber");
                dt.Columns.Add("department");
                if (response != null && response.@return != null && [email protected] > 0)
                {

                    foreach (object o in response.@return)
                    {
                        List<object> values = new List<object>();
                        values.Add(((XmlNode[])o)[0].InnerText);
                        values.Add(((XmlNode[])o)[1].InnerText);
                        values.Add(((XmlNode[])o)[2].InnerText);
                        values.Add(((XmlNode[])o)[3].InnerText);
                        dt.Rows.Add(values.ToArray());
                    }
                }
                else
                {
                    log.Error("No result retreive from AXL Server");
                }
                return results;
            }
            catch (Exception e)
            {
                log.Error(e.Message);
                return results;
            }
        }
        public SyncConfiguration(DirectoryType type)
        {
            Ldap = new LdapSyncConfiguration(type);

            switch (type)
            {
            case DirectoryType.ActiveDirectory:
                break;

            case DirectoryType.AzureActiveDirectory:
                break;

            case DirectoryType.Other:
                break;

            case DirectoryType.GSuite:
                break;

            default:
                break;
            }
        }
        public static string GetPicture(DirectoryType type)
        {
            switch (type)
            {
            case DirectoryType.File:
                return("pack://application:,,,/Icons/File.png");

            case DirectoryType.Folder:
                return("pack://application:,,,/Icons/Folder.png");

            case DirectoryType.Drive:
                return("pack://application:,,,/Icons/Drive.png");

            case DirectoryType.MyDocuments:
                return("pack://application:,,,/Icons/MyDocuments.png");

            case DirectoryType.MyDownloads:
                return("pack://application:,,,/Icons/MyDownloads.png");

            case DirectoryType.MyPhotos:
                return("pack://application:,,,/Icons/MyPhotos.png");

            case DirectoryType.MyVideos:
                return("pack://application:,,,/Icons/MyVideos.png");

            case DirectoryType.MyMusic:
                return("pack://application:,,,/Icons/MyMusic.png");

            case DirectoryType.Desktop:
                return("pack://application:,,,/Icons/Desktop.png");

            case DirectoryType.NUll:
                return("pack://application:,,,/Icons/Error.png");

            default:
                return("pack://application:,,,/Icons/Error.png");
            }
        }
Esempio n. 19
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Request.QueryString["dir"] == null)
     {
         log.Error("Unexpected url...transfer to home page.");
         Server.Transfer("DMDMgt.aspx");
     }
     else
     {
         if (!Page.IsPostBack)
         {
             DirectoryType dir = Global.GetDirectory(Request.QueryString["dir"]);
             if (dir != null)
             {
                 InitDirectory(dir);
             }
             else
             {
                 log.Error("The specified directory doesn't exist.");
             }
         }
     }
 }
Esempio n. 20
0
        public static DirectoryType GetDirectory(string directoryName)
        {
            DirectoryType dir = null;

            try
            {
                if (directoryConfiguration != null)
                {
                    currentDirectoryName = directoryName;
                    dir = directoryConfiguration.Find(FindDirectoryFromName);
                }
                else
                {
                    log.Debug("DMD config file empty or inexistant");
                }
                return(dir);
            }
            catch (Exception e)
            {
                log.Error("GetDirectory failed: " + e.Message);
                return(dir);
            }
        }
        protected StandaloneAzureTestsBase(DirectoryType directoryType)
        {
            _appDataDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            var lightBlueDirectory = Path.Combine(_appDataDirectory, "LightBlue");
            var accountDirectory = Path.Combine(lightBlueDirectory, "dev");
            var blobDirectory = Path.Combine(accountDirectory, "blob");
            var queuesDirectory = Path.Combine(accountDirectory, "queuse");

            StandaloneEnvironment.LightBlueDataDirectory = lightBlueDirectory;

            Directory.CreateDirectory(blobDirectory);
            Directory.CreateDirectory(queuesDirectory);

            switch (directoryType)
            {
                case DirectoryType.Account:
                    BasePath = accountDirectory;
                    break;
                case DirectoryType.BlobStorage:
                    BasePath = blobDirectory;
                    break;
                case DirectoryType.Container:
                    var containerDirectory = Path.Combine(blobDirectory, "container");
                    Directory.CreateDirectory(Path.Combine(containerDirectory, MetadataDirectory));
                    BasePath = containerDirectory;
                    break;
                case DirectoryType.QueueStorage:
                    BasePath = queuesDirectory;
                    break;
                case DirectoryType.Queue:
                    var queueDirectory = Path.Combine(queuesDirectory, "queue");
                    Directory.CreateDirectory(Path.Combine(queueDirectory, MetadataDirectory));
                    BasePath = queueDirectory;
                    break;
            }
        }
Esempio n. 22
0
        public string GetPluginsDirectory(DirectoryType dType)
        {
            switch (dType)
            {
                case DirectoryType.Local:
                    return AppConfig.Instance.LocalDirectory;
                    //break;

                case DirectoryType.Download:
                    return AppConfig.Instance.DownloadDirectory;
                    //break;

                case DirectoryType.Tmp:
                    return AppConfig.Instance.TmpDirectory;
                    //break;

                default:
                    return ".";
            }
        }
        //
        // This method determines whether the server we are talking to
        // is an AD domain controller or an ADAM instance
        //
        private DirectoryType GetDirectoryType()
        {
            DirectoryType directoryType = DirectoryType.Unknown;

            foreach (string supportedCapability in rootdse.Properties["supportedCapabilities"])
            {
                if (StringUtil.EqualsIgnoreCase(supportedCapability, LDAP_CAP_ACTIVE_DIRECTORY_ADAM_OID))
                {
                    directoryType = DirectoryType.ADAM;
                    break;
                }
                else if (StringUtil.EqualsIgnoreCase(supportedCapability, LDAP_CAP_ACTIVE_DIRECTORY_OID))
                {
                    directoryType = DirectoryType.AD;
                    break;
                }
            }

            if (directoryType == DirectoryType.Unknown)
                throw new ProviderException(SR.GetString(SR.ADMembership_Valid_Targets));

            return directoryType;
        }
Esempio n. 24
0
        /// <summary>
        /// Search method
        /// </summary>
        /// <param name="dir">Search settings<seealso cref="DirectoryType"/></param>
        /// <returns>A dataset conform to the specified FieldFormatters<seealso cref="FieldFormatter"/></returns>
        public static DataSet Search(DirectoryType dir)
        {
            DataSet results = new DataSet();
            DataTable dt = results.Tables.Add();
            LdapDatasourceType ldt = (LdapDatasourceType)dir.Item;
            try
            {
                Init(ldt.server, ldt.authenticationType, ldt.user, ldt.userPassword, ldt.targetOU, ldt.ldapFilter, ldt.pageSize, ldt.nbPages);
                log.Debug("Search " + ldapFilter + " from " + targetOU + " on " + ldapServer);
                PageResultRequestControl prc = new PageResultRequestControl(pageSize);
                prc.IsCritical = false;
                PageResultResponseControl cookie;
                SearchResponse sr;

                SearchRequest request = new SearchRequest(targetOU, ldapFilter, SearchScope.Subtree,ldt.ldapAttributes);
                request.Controls.Add(prc);

                foreach (string attribut in ldt.ldapAttributes)
                {
                    dt.Columns.Add(attribut, typeof(string));
                }
                

                int pageCount = 0;
                int count;
                while (true)
                {
                    pageCount++;

                    sr = (SearchResponse)ldapConnection.SendRequest(request);
                    log.Debug("Page " + pageCount.ToString() + ": " + sr.Entries.Count + " entries");

                    count = 0;
                    foreach (SearchResultEntry entry in sr.Entries)
                    {
                        count++;
                        log.Debug("Entry " + count.ToString() + ": " + entry.DistinguishedName);
                        List<object> values = new List<object>();
                        
                        foreach (string attribut in ldt.ldapAttributes)
                        {
                            DirectoryAttribute da = entry.Attributes[attribut];
                            if (da != null && da.GetValues(typeof(string)).Length > 0)
                            {
                                values.Add((string)da.GetValues(typeof(string))[0]);
                            }
                            else
                            {
                                values.Add("");
                            }
                        }
                        dt.Rows.Add(values.ToArray());
                    }

                    if (sr.Controls.Length != 1 || !(sr.Controls[0] is PageResultResponseControl))
                    {
                        log.Debug("Weird response...");
                        ldapConnection.Dispose();
                        return results;
                    }

                    cookie = (PageResultResponseControl)sr.Controls[0];

                    if (cookie.Cookie.Length == 0) break;

                    prc.Cookie = cookie.Cookie;
                }

                ldapConnection.Dispose();
                log.Debug("Search ended");
                return results;
            }
            catch (Exception e)
            {
                log.Error(e.Message);
                return results;
            }
        }
Esempio n. 25
0
 private void InitDirectory(DirectoryType dir)
 {
     tbDirectoryName.Text = dir.name;
     if (dir.Item is SqlDatasourceType)
     {
         rblDirectoryType.Items.FindByValue("SQL").Selected = true;
         SqlDatasourceType sdt = (SqlDatasourceType)dir.Item;
         tbSqlDsn.Text = sdt.dsn;
         tbSqlUid.Text = sdt.uid;
         tbSqlPwd.Text = sdt.pwd;
         tbSqlCommand.Text = sdt.command;
         tbSqlFilter.Text = sdt.sqlFilter;
         foreach (FieldFormatter ffs in sdt.fieldFormatters)
         {
             lbSQLFieldFormatters.Items.Add(new ListItem(ffs.fieldName, ffs.value + "#" + ffs.fieldType.ToString()));
         }
         if (sdt.ipphonefilter != null)
         {
             tbSQLFirstNameFilterMap.Text = sdt.ipphonefilter.firstnamemap;
             tbSQLLastNameFilterMap.Text = sdt.ipphonefilter.lastnamemap;
             tbSQLTelephoneNumberFilterMap.Text = sdt.ipphonefilter.telephonenumbermap;
         }
         ShowSQL();
     }
     else if (dir.Item is LdapDatasourceType)
     {
         rblDirectoryType.Items.FindByValue("LDAP").Selected = true;
         LdapDatasourceType ldt = (LdapDatasourceType)dir.Item;
         tbLdapServer.Text = ldt.server;
         ddlLdapAuthentication.Items.FindByText(ldt.authenticationType).Selected = true;
         tbLdapUser.Text = ldt.user;
         tbLdapUserPassword.Text = ldt.userPassword;
         tbLdapTargetOu.Text = ldt.targetOU;
         tbLdapFilter.Text = ldt.ldapFilter;
         tbLdapPageSize.Text = ldt.pageSize.ToString();
         tbLdapNbPages.Text = ldt.nbPages.ToString();
         foreach (string attribut in ldt.ldapAttributes)
         {
             lbLdapAttribute.Items.Add(new ListItem(attribut, attribut));
         }
         foreach (FieldFormatter ffl in ldt.fieldFormatters)
         {
             lbLdapFieldFormatters.Items.Add(new ListItem(ffl.fieldName, ffl.value + "#" + ffl.fieldType.ToString()));
         }
         if (ldt.ipphonefilter != null)
         {
             tbLdapFirstNameFilterMap.Text = ldt.ipphonefilter.firstnamemap;
             tbLdapLastNameFilterMap.Text = ldt.ipphonefilter.lastnamemap;
             tbLdapTelephoneNumberFilterMap.Text = ldt.ipphonefilter.telephonenumbermap;
         }
         ShowLdap();
     }
     else if (dir.Item is CiscoDatasourceType)
     {
         rblDirectoryType.Items.FindByValue("CISCO").Selected = true;
         CiscoDatasourceType ldt = (CiscoDatasourceType)dir.Item;
         tbCiscoServer.Text = ldt.server;
         tbAXLUser.Text = ldt.axluser;
         tbAXLUserPassword.Text = ldt.axluserpwd;
         foreach (FieldFormatter ffc in ldt.fieldFormatters)
         {
             lbCiscoFieldFormatters.Items.Add(new ListItem(ffc.fieldName, ffc.value + "#" + ffc.fieldType.ToString()));
         }
         if (ldt.ipphonefilter != null)
         {
             tbFirstNameFilterMap.Text = ldt.ipphonefilter.firstnamemap;
             tbLastNameFilterMap.Text = ldt.ipphonefilter.lastnamemap;
             tbTelephoneNumberFilterMap.Text = ldt.ipphonefilter.telephonenumbermap;
         }
         ShowCisco();
     }
     else
     {
         log.Error("Datasource type unknown...cannot load " + dir.name);
     }
 }
        internal DirectoryInformation(string adspath,
                                                            NetworkCredential credentials,
                                                            string connProtection,
                                                            int clientSearchTimeout,
                                                            int serverSearchTimeout,
                                                            bool enablePasswordReset)
        {

           //
           // all parameters have already been validated at this point
           //

            this.adspath = adspath;
            this.credentials = credentials;
            this.clientSearchTimeout = clientSearchTimeout;
            this.serverSearchTimeout = serverSearchTimeout;

            Debug.Assert(adspath != null);
            Debug.Assert(adspath.Length > 0);

            //
            // Provider must be LDAP
            //
            if (!(adspath.StartsWith("LDAP", StringComparison.Ordinal)))
                throw new ProviderException(SR.GetString(SR.ADMembership_OnlyLdap_supported));

            //
            // Parse out the server/domain information
            //
            NativeComInterfaces.IAdsPathname pathCracker = (NativeComInterfaces.IAdsPathname) new NativeComInterfaces.Pathname();

            try {
                pathCracker.Set(adspath, NativeComInterfaces.ADS_SETTYPE_FULL);
            }
            catch (COMException e)
            {
                if (e.ErrorCode == unchecked((int) 0x80005000))
                    throw new ProviderException(SR.GetString(SR.ADMembership_invalid_path));
                else
                    throw;
            }

            // Get the server and container names
            try
            {
                serverName = pathCracker.Retrieve(NativeComInterfaces.ADS_FORMAT_SERVER);
            }
            catch (COMException e)
            {
                if (e.ErrorCode == unchecked((int) 0x80005000))
                    throw new ProviderException(SR.GetString(SR.ADMembership_ServerlessADsPath_not_supported));
                else
                    throw;
            }
            Debug.Assert(serverName != null);

            creationContainerDN = containerDN = pathCracker.Retrieve(NativeComInterfaces.ADS_FORMAT_X500_DN);

            //
            // Parse out the port number if specified
            //
            int index = serverName.IndexOf(':');
            if (index != -1)
            {
                string tempStr = serverName;

                serverName = tempStr.Substring(0, index);

                Debug.Assert(tempStr.Length > index);
                port = Int32.Parse(tempStr.Substring(index + 1), NumberFormatInfo.InvariantInfo);
                portSpecified = true;
            }

            if (String.Compare(connProtection, "Secure", StringComparison.Ordinal) == 0)
            {
                //
                // The logic is as follows:
                // 1. Try Ssl first and check if concurrent binds are possible for validating users
                // 2. If Ssl is not supported, try signing and sealing
                // 3. If both the above are not supported, then we will fail
                //

                bool trySignAndSeal = false;
                bool trySslWithSecureAuth = false;

                // first try with simple bind
                if (!IsDefaultCredential())
                {

                    authenticationType = GetAuthenticationTypes(ActiveDirectoryConnectionProtection.Ssl, CredentialsType.NonWindows);
                    ldapAuthType = GetLdapAuthenticationTypes(ActiveDirectoryConnectionProtection.Ssl, CredentialsType.NonWindows);

                    try
                    {
                        rootdse = new DirectoryEntry(GetADsPath("rootdse"), GetUsername(), GetPassword(), authenticationType);
                        // this will force a bind
                        rootdse.RefreshCache();
                        this.connectionProtection = ActiveDirectoryConnectionProtection.Ssl;
                        if (!portSpecified)
                        {
                            port = SSL_PORT;
                            portSpecified = true;
                        }
                    }
                    catch (COMException ce)
                    {

                        if (ce.ErrorCode == unchecked((int) 0x8007052e))
                        {
                            //
                            // this could be an ADAM target with windows user (in that case simple bind will not work)
                            //
                            trySslWithSecureAuth = true;
                        }
                        else if (ce.ErrorCode == unchecked((int) 0x8007203a))
                        {
                            // server is not operational error, do nothing, we need to fall back to SignAndSeal
                            trySignAndSeal = true;
                        }
                        else
                            throw;
                     }
                }
                else
                {
                    // default credentials, so we have to do secure bind
                    trySslWithSecureAuth = true;
                }

                if (trySslWithSecureAuth)
                {

                    authenticationType = GetAuthenticationTypes(ActiveDirectoryConnectionProtection.Ssl, CredentialsType.Windows);
                    ldapAuthType = GetLdapAuthenticationTypes(ActiveDirectoryConnectionProtection.Ssl, CredentialsType.Windows);

                    try
                    {
                        rootdse = new DirectoryEntry(GetADsPath("rootdse"), GetUsername(), GetPassword(), authenticationType);
                        // this will force a bind
                        rootdse.RefreshCache();
                        this.connectionProtection = ActiveDirectoryConnectionProtection.Ssl;
                        if (!portSpecified)
                        {
                            port = SSL_PORT;
                            portSpecified = true;
                        }

                    }
                    catch (COMException ce)
                    {
                        if (ce.ErrorCode == unchecked((int) 0x8007203a))
                        {
                            // server is not operational error, do nothing, we need to fall back to SignAndSeal
                            trySignAndSeal = true;
                        }
                        else
                            throw;
                     }

                }

                if (trySignAndSeal)
                {
                    authenticationType = GetAuthenticationTypes(ActiveDirectoryConnectionProtection.SignAndSeal, CredentialsType.Windows);
                    ldapAuthType = GetLdapAuthenticationTypes(ActiveDirectoryConnectionProtection.SignAndSeal, CredentialsType.Windows);

                    try
                    {
                        rootdse = new DirectoryEntry(GetADsPath("rootdse"), GetUsername(), GetPassword(), authenticationType);
                        rootdse.RefreshCache();
                        this.connectionProtection = ActiveDirectoryConnectionProtection.SignAndSeal;
                    }
                    catch (COMException e)
                    {
                        throw new ProviderException(SR.GetString(SR.ADMembership_Secure_connection_not_established, e.Message), e);
                    }
                }
            }
            else
            {
                //
                // No connection protection
                //

                //
                // we will do a simple bind but we must ensure that the credentials are explicitly specified
                // since in the case of default credentials we cannot honor it (default credentials become anonymous in the case of
                // simple bind)
                //
                if (IsDefaultCredential())
                    throw new NotSupportedException(SR.GetString(SR.ADMembership_Default_Creds_not_supported));

                // simple bind
                authenticationType = GetAuthenticationTypes(connectionProtection, CredentialsType.NonWindows);
                ldapAuthType = GetLdapAuthenticationTypes(connectionProtection, CredentialsType.NonWindows);

                rootdse = new DirectoryEntry(GetADsPath("rootdse"), GetUsername(), GetPassword(), authenticationType);

            }

            //
            // Determine whether this is AD or ADAM by binding to the rootdse and
            // checking the supported capabilities
            //
            if (rootdse == null)
                rootdse = new DirectoryEntry(GetADsPath("RootDSE"), GetUsername(), GetPassword(), authenticationType);
            directoryType = GetDirectoryType();

            //
            // if the directory type is ADAM and the conntectionProtection was selected
            // as sign and seal, then we should throw an ProviderException. This is becuase validate user will always fail for ADAM
            // because ADAM does not support secure authentication for ADAM users.
            //
            if ((directoryType == DirectoryType.ADAM) && (this.connectionProtection == ActiveDirectoryConnectionProtection.SignAndSeal))
                throw new ProviderException(SR.GetString(SR.ADMembership_Ssl_connection_not_established));

            //
            // for AD, we need to block the GC ports
            //
            if ((directoryType == DirectoryType.AD) && ((port == GC_PORT) || (port == GC_SSL_PORT)))
                throw new ProviderException(SR.GetString(SR.ADMembership_GCPortsNotSupported));

            //
            // if container dn is null, we need to get the default naming context
            // (containerDN cannot be null for ADAM)
            //
            if (String.IsNullOrEmpty(containerDN))
            {
                if (directoryType == DirectoryType.AD)
                {
                    containerDN = (string)rootdse.Properties["defaultNamingContext"].Value;
                    if (containerDN == null)
                        throw new ProviderException(SR.GetString(SR.ADMembership_DefContainer_not_specified));

                    //
                    // we will create users in the default users container, check that it exists
                    //
                    string wkUsersContainerPath = GetADsPath("<WKGUID=" + GUID_USERS_CONTAINER_W + "," + containerDN + ">");
                    DirectoryEntry containerEntry = new DirectoryEntry(wkUsersContainerPath, GetUsername(), GetPassword(), authenticationType);

                    try
                    {
                        creationContainerDN = (string) PropertyManager.GetPropertyValue(containerEntry, "distinguishedName");
                    }
                    catch (COMException ce)
                    {
                        if (ce.ErrorCode == unchecked((int) 0x80072030))
                            throw new ProviderException(SR.GetString(SR.ADMembership_DefContainer_does_not_exist));
                        else
                            throw;
                    }
                }
                else
                {
                    // container must be specified for ADAM
                    throw new ProviderException(SR.GetString(SR.ADMembership_Container_must_be_specified));
                }
            }
            else
            {
                //
                // Normalize the container name (incase it was specified as GUID or WKGUID)
                //
                DirectoryEntry containerEntry = new DirectoryEntry(GetADsPath(containerDN), GetUsername(), GetPassword(), authenticationType);

                try
                {
                    creationContainerDN = containerDN = (string) PropertyManager.GetPropertyValue(containerEntry, "distinguishedName");
                }
                catch (COMException ce)
                {
                    if (ce.ErrorCode == unchecked((int) 0x80072030))
                        throw new ProviderException(SR.GetString(SR.ADMembership_Container_does_not_exist));
                    else
                        throw;
                }
            }

            //
            // Check if the specified path(container) exists on the specified server/domain
            // (NOTE: We need to do this using S.DS.Protocols rather than S.DS because we need to
            //            bypass the referral chasing which is automatic in S.DS)
            //

            LdapConnection tempConnection = new LdapConnection(new LdapDirectoryIdentifier(serverName + ":" + port), GetCredentialsWithDomain(credentials), ldapAuthType);
            tempConnection.SessionOptions.ProtocolVersion = 3;

            try
            {
                tempConnection.SessionOptions.ReferralChasing = System.DirectoryServices.Protocols.ReferralChasingOptions.None;
                SetSessionOptionsForSecureConnection(tempConnection, false /*useConcurrentBind */);
                tempConnection.Bind();


                SearchRequest request = new SearchRequest();
                request.DistinguishedName = containerDN;
                request.Filter = "(objectClass=*)";
                request.Scope = System.DirectoryServices.Protocols.SearchScope.Base;
                request.Attributes.Add("distinguishedName");
                request.Attributes.Add("objectClass");

                if (ServerSearchTimeout != -1)
                    request.TimeLimit = new TimeSpan(0, ServerSearchTimeout, 0);

                SearchResponse response;
                try
                {
                    response = (SearchResponse) tempConnection.SendRequest(request);
                    if (response.ResultCode == ResultCode.Referral || response.ResultCode ==  ResultCode.NoSuchObject)
                        throw new ProviderException(SR.GetString(SR.ADMembership_Container_does_not_exist));
                    else if (response.ResultCode != ResultCode.Success)
                        throw new ProviderException(response.ErrorMessage);
                }
                catch (DirectoryOperationException oe)
                {
                    SearchResponse errorResponse = (SearchResponse) oe.Response;
                    if (errorResponse.ResultCode == ResultCode.NoSuchObject)
                        throw new ProviderException(SR.GetString(SR.ADMembership_Container_does_not_exist));
                    else throw;
                }

                //
                // check that the container is of an object type that can be a superior of a user object
                //
                DirectoryAttribute objectClass = response.Entries[0].Attributes["objectClass"];
                if (!ContainerIsSuperiorOfUser(objectClass))
                    throw new ProviderException(SR.GetString(SR.ADMembership_Container_not_superior));

                //
                // Determine whether concurrent bind is supported
                //
                if ((connectionProtection == ActiveDirectoryConnectionProtection.None) || (connectionProtection == ActiveDirectoryConnectionProtection.Ssl))
                {
                    this.concurrentBindSupported = IsConcurrentBindSupported(tempConnection);
                }

            }
            finally
            {
                tempConnection.Dispose();
            }

            //
            // if this is ADAM, get the partition DN
            //
            if (directoryType == DirectoryType.ADAM)
            {
                adamPartitionDN = GetADAMPartitionFromContainer();
            }
            else
            {
                if (enablePasswordReset)
                {
                    // for AD, get the lockout duration for user account auto unlock
                    DirectoryEntry de = new DirectoryEntry(GetADsPath((string) PropertyManager.GetPropertyValue(rootdse, "defaultNamingContext")), GetUsername(), GetPassword(), AuthenticationTypes);
                    NativeComInterfaces.IAdsLargeInteger largeIntValue = (NativeComInterfaces.IAdsLargeInteger) PropertyManager.GetPropertyValue(de, "lockoutDuration");
                    Int64 int64Value = largeIntValue.HighPart * 0x100000000 + (uint) largeIntValue.LowPart;

                    // int64Value is the negative of the number of 100 nanoseconds interval that makes up the lockout duration
                    adLockoutDuration = new TimeSpan(-int64Value);
                }
            }
        }
Esempio n. 27
0
 private DirectoryType InitLdapDirectory()
 {
     DirectoryType dir = new DirectoryType();
     dir.name = tbDirectoryName.Text;
     LdapDatasourceType ldt = new LdapDatasourceType();
     ldt.authenticationType = ddlLdapAuthentication.SelectedValue;
     ldt.server = tbLdapServer.Text;
     ldt.user = tbLdapUser.Text;
     ldt.userPassword = tbLdapUserPassword.Text;
     ldt.targetOU = tbLdapTargetOu.Text;
     ldt.nbPages = Convert.ToInt32(tbLdapNbPages.Text);
     ldt.pageSize = Convert.ToInt32(tbLdapPageSize.Text);
     ldt.ldapFilter = tbLdapFilter.Text;
     List<string> attributes = new List<string>();
     foreach (ListItem li in lbLdapAttribute.Items)
     {
         attributes.Add(li.Text);
     }
     ldt.ldapAttributes = attributes.ToArray();
     dir.Item = ldt;
     return dir;
 }
Esempio n. 28
0
 private DirectoryType InitCiscoDirectory()
 {
     DirectoryType dir = new DirectoryType();
     dir.name = tbDirectoryName.Text;
     CiscoDatasourceType cdt = new CiscoDatasourceType();
     cdt.server = tbCiscoServer.Text;
     cdt.axluser = tbAXLUser.Text;
     cdt.axluserpwd = tbAXLUserPassword.Text;
     dir.Item = cdt;
     return dir;
 }
 public IndexConfiguration() {
   this._CommitTimeSec = 60;
   this.__isset.CommitTimeSec = true;
   this._DirectoryType = DirectoryType.MemoryMapped;
   this.__isset.DirectoryType = true;
   this._DefaultWriteLockTimeout = 1000;
   this.__isset.DefaultWriteLockTimeout = true;
   this._RamBufferSizeMb = 100;
   this.__isset.RamBufferSizeMb = true;
   this._RefreshTimeMilliSec = 25;
   this.__isset.RefreshTimeMilliSec = true;
   this._IndexVersion = IndexVersion.Lucene47;
   this.__isset.IndexVersion = true;
 }
Esempio n. 30
0
 private DirectoryType InitSqlDirectory()
 {
     DirectoryType dir = new DirectoryType();
     dir.name = tbDirectoryName.Text;
     SqlDatasourceType sdt = new SqlDatasourceType();
     sdt.dsn = tbSqlDsn.Text;
     sdt.uid = tbSqlUid.Text;
     sdt.pwd = tbSqlPwd.Text;
     sdt.command = tbSqlCommand.Text;
     sdt.sqlFilter = tbSqlFilter.Text;
     dir.Item = sdt;
     return dir;
 }
Esempio n. 31
0
        /// <summary>
        /// Search method
        /// </summary>
        /// <param name="directory">Search settings<seealso cref="DirectoryType"/></param>
        /// <returns>A dataset conform to the FieldFormatters specified<seealso cref="FieldFormatter"/></returns>
        public static DataSet Search(DirectoryType directory)
        {
            DataSet results = new DataSet();
            DataTable dt = results.Tables.Add();
            OdbcConnection odbc = new OdbcConnection();
            OdbcDataReader reader = null;
            OdbcCommand command = null;
            try
            {
                string dsn = "DSN=";
                dsn += ((SqlDatasourceType)directory.Item).dsn;
                dsn += ";Uid=";
                dsn += ((SqlDatasourceType)directory.Item).uid;
                dsn += ";Pwd=";
                dsn += ((SqlDatasourceType)directory.Item).pwd;
                odbc.ConnectionString = dsn;
                log.Debug("Opening ODBC connection...");
                odbc.Open();

                string sql = ((SqlDatasourceType)directory.Item).command + " " + ((SqlDatasourceType)directory.Item).sqlFilter;
                log.Debug("Initializing ODBC command: " + sql);
                command = odbc.CreateCommand();
                command.CommandText = sql;

                log.Debug("Loading data in memory...");
                reader = command.ExecuteReader();

                DataTable schema = reader.GetSchemaTable();
                foreach (DataRow dr in schema.Rows)
                {
                    dt.Columns.Add((string)dr[0], System.Type.GetType( ((Type)dr[5]).FullName));
                }
                object[] values = new object[dt.Columns.Count];
                while (reader.Read())
                {
                    reader.GetValues(values);
                    dt.Rows.Add(values);
                }

                return results;
            }
            catch (Exception e)
            {
                throw new Exception("Request failed!", e);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                    reader.Dispose();
                }
                if (command != null)
                {
                    command.Dispose();
                }
                if (odbc != null)
                {
                    odbc.Close();
                    odbc.Dispose();
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="IndexDirectory"/> class.
 /// </summary>
 /// <remarks>
 /// Assigns an empty string to the DirectoryPath
 /// </remarks>
 /// <param name="type">The DirectoryType of this <c>IndexDirectory</c>.</param>
 public IndexDirectory(DirectoryType type)
     : this(type, string.Empty)
 {
 }
Esempio n. 33
0
 public static void UpdateDirectory(DirectoryType dir)
 {
     try
     {
         if (directoryConfiguration != null)
         {
             foreach (DirectoryType dt in directoryConfiguration)
             {
                 if (dt.name == dir.name)
                 {
                     directoryConfiguration.Remove(dt);
                     directoryConfiguration.Add(dir);
                     break;
                 }
             }
             
         }
         else
         {
             log.Error("Cannot update a directory in an empty configuration file...");
         }
         SaveConfigFile();
     }
     catch (Exception e)
     {
         log.Error("Cannot update directory...: " + e.Message);
     }
 }
Esempio n. 34
0
 public static void AddDirectory(DirectoryType dir)
 {
     try
     {
         if (directoryConfiguration != null)
         {
             bool canSave = true;
             foreach (DirectoryType dt in directoryConfiguration)
             {
                 if (dt.name == dir.name)
                 {
                     canSave = false;
                     break;
                 }
             }
             if (canSave)
             {
                 directoryConfiguration.Add(dir);
             }
         }
         else
         {
             directoryConfiguration = new List<DirectoryType>();
             directoryConfiguration.Add(dir);
         }
         SaveConfigFile();
     }
     catch (Exception e)
     {
         log.Error("Cannot add directory...: " + e.Message);
     }
 }
Esempio n. 35
0
 private static bool FindDirectoryFromName(DirectoryType dir)
 {
     bool found = false;
     if (currentDirectoryName != "")
     {
         if (dir.name == currentDirectoryName)
         {
             found = true;
         }
     }
     else
     {
         log.Debug("Looking for a directory with an empty name field is not allowed");
     }
     return found;
 }