Exemplo n.º 1
0
        public static string ComputerNameRender(this Device device, DiscoDataContext Database, ADDomain Domain)
        {
            if (Domain == null)
                throw new ArgumentNullException("Domain");

            var deviceProfile = device.DeviceProfile;
            Expression computerNameTemplateExpression = null;
            computerNameTemplateExpression = ExpressionCache.GetValue(DeviceProfileExtensions.ComputerNameExpressionCacheModule, deviceProfile.Id.ToString(), () =>
            {
                // Removed 2012-06-14 G# - Properties moved to DeviceProfile model & DB Migrated in DBv3.
                //return Expressions.Expression.TokenizeSingleDynamic(null, deviceProfile.Configuration(context).ComputerNameTemplate, 0);
                return Expression.TokenizeSingleDynamic(null, deviceProfile.ComputerNameTemplate, 0);
            });
            var evaluatorVariables = Expression.StandardVariables(null, Database, UserService.CurrentUser, DateTime.Now, null);
            string rendered;
            try
            {
                rendered = computerNameTemplateExpression.EvaluateFirst<string>(device, evaluatorVariables);
            }
            catch (Exception ex)
            {
                ex.ToExceptionless().AddObject(deviceProfile.ComputerNameTemplate, "ComputerNameTemplate").Submit();
                throw new InvalidOperationException(string.Format("An error occurred rendering the computer name: [{0}] {1}", ex.GetType().Name, ex.Message), ex.InnerException);
            }
            if (rendered == null || rendered.Length > 24)
            {
                throw new InvalidOperationException("The rendered computer name would be invalid or longer than 24 characters");
            }

            return string.Format(@"{0}\{1}", Domain.NetBiosName, rendered);
        }
Exemplo n.º 2
0
 private ADOrganisationalUnit(ADDomain Domain, string DistinguishedName, string Name, List<ADOrganisationalUnit> Children)
 {
     this.Domain = Domain;
     this.DistinguishedName = DistinguishedName;
     this.Name = Name;
     this.Children = Children;
 }
Exemplo n.º 3
0
        internal ADDirectoryEntry(ADDomain Domain, ADDomainController DomainController, DirectoryEntry Entry)
        {
            if (Domain == null)
                throw new ArgumentNullException("Domain");
            if (DomainController == null)
                throw new ArgumentNullException("DomainController");
            if (Entry == null)
                throw new ArgumentNullException("Entry");

            this.Domain = Domain;
            this.DomainController = DomainController;
            this.Entry = Entry;
        }
Exemplo n.º 4
0
        public ADDomainController(ActiveDirectoryContext Context, DomainController DomainController, ADDomain Domain, bool IsSiteServer, bool IsWritable)
        {
            this.context = Context;

            this.Domain = Domain;
            this.DomainController = DomainController;

            this.Name = DomainController.Name;
            this.SiteName = DomainController.SiteName;

            this.IsSiteServer = IsSiteServer;
            this.IsWritable = IsWritable;

            this.AvailableWhen = null;
        }
Exemplo n.º 5
0
        private static string RelevantSearchTerm(string Term, out ADDomain Domain)
        {
            Domain = null;

            if (string.IsNullOrWhiteSpace(Term))
                return null;

            var term = Term.Trim();

            var domainSeperatorIndex = term.IndexOf('\\');

            if (domainSeperatorIndex >= 0)
            {
                // Domain Search Restriction

                if (term.Length > domainSeperatorIndex + 1)
                {
                    var netbiosName = term.Substring(0, domainSeperatorIndex);
                    if (Context.TryGetDomainByNetBiosName(netbiosName, out Domain))
                    {
                        return term.Substring(domainSeperatorIndex + 1);
                    }
                    else
                    {
                        return null; // Unknown Domain
                    }
                }
                else
                {
                    return null; // No term to search, only Domain
                }
            }

            return term;
        }
Exemplo n.º 6
0
        public static bool IsValidDomainAccountId(string AccountId, out string AccountUsername, out ADDomain Domain)
        {
            if (string.IsNullOrEmpty(AccountId))
            {
                AccountUsername = null;
                Domain = null;
                return false;
            }

            var slashIndex = AccountId.IndexOf('\\');
            if (slashIndex < 0)
            {
                AccountUsername = AccountId;
                Domain = null;
                return false;
            }
            else
            {
                AccountUsername = AccountId.Substring(slashIndex + 1);
                return ActiveDirectory.Context.TryGetDomainByNetBiosName(AccountId.Substring(0, slashIndex), out Domain);
            }
        }
Exemplo n.º 7
0
        public static bool IsValidDomainAccountId(string AccountId, out ADDomain Domain)
        {
            string accountUsername;

            return IsValidDomainAccountId(AccountId, out accountUsername, out Domain);
        }
Exemplo n.º 8
0
        public static string ParseDomainAccountId(string AccountId, string AccountDomain, out string AccountUsername, out ADDomain Domain)
        {
            if (string.IsNullOrWhiteSpace(AccountId))
                throw new ArgumentNullException("AccountId");

            var slashIndex = AccountId.IndexOf('\\');

            if (slashIndex < 0 && !string.IsNullOrWhiteSpace(AccountDomain))
            {
                AccountId = AccountDomain + @"\" + AccountId;
                slashIndex = AccountDomain.Length;
            }

            if (slashIndex < 0)
            {
                AccountUsername = AccountId;
                Domain = Context.PrimaryDomain;
            }
            else
            {
                AccountUsername = AccountId.Substring(slashIndex + 1);
                Domain = Context.GetDomainByNetBiosName(AccountId.Substring(0, slashIndex));
            }

            return string.Concat(Domain.NetBiosName, @"\", AccountUsername);
        }
Exemplo n.º 9
0
 public static string ParseDomainAccountId(string AccountId, out string AccountUsername, out ADDomain Domain)
 {
     return ParseDomainAccountId(AccountId, null, out AccountUsername, out Domain);
 }
Exemplo n.º 10
0
        public static string ParseDomainAccountId(string AccountId, string AccountDomain, out ADDomain Domain)
        {
            string accountUsername;

            return ParseDomainAccountId(AccountId, AccountDomain, out accountUsername, out Domain);
        }
Exemplo n.º 11
0
        public bool TryGetDomainFromDistinguishedName(string DistinguishedName, out ADDomain Domain)
        {
            // Find closest match
            Domain = this.Domains.Where(d => DistinguishedName.EndsWith(d.DistinguishedName, StringComparison.OrdinalIgnoreCase))
                .OrderByDescending(d => d.DistinguishedName.Length).FirstOrDefault();

            return (Domain != null);
        }
Exemplo n.º 12
0
        public bool TryGetDomainFromId(string Id, out ADDomain Domain)
        {
            if (string.IsNullOrWhiteSpace(Id))
                throw new ArgumentNullException("Id");

            var slashIndex = Id.IndexOf('\\');

            if (slashIndex < 0)
                throw new ArgumentException(string.Format("The Id must include the Domain [{0}]", Id), "Id");

            return TryGetDomainByNetBiosName(Id.Substring(0, slashIndex), out Domain);
        }
Exemplo n.º 13
0
 public bool TryGetDomainFromSecurityIdentifier(SecurityIdentifier SecurityIdentifier, out ADDomain Domain)
 {
     Domain = this.Domains.FirstOrDefault(d => d.SecurityIdentifier.IsEqualDomainSid(SecurityIdentifier));
     return (Domain != null);
 }
Exemplo n.º 14
0
 public bool TryGetDomainByName(string Name, out ADDomain Domain)
 {
     Domain = this.Domains.FirstOrDefault(d => d.Name.Equals(Name, StringComparison.OrdinalIgnoreCase));
     return (Domain != null);
 }