Esempio n. 1
0
        /// <summary>
        /// Retrieves transated attribute value as a string
        /// Assumes attributes are single valued
        /// </summary>
        /// <param name="attributeValue">Attribute value as byte array</param>
        /// <param name="attributeName">Attribute name as JetColumn</param>
        /// <returns></returns>
        private string TranslateAttributeAsString(byte[] attributeValue, JetColumn attributeName)
        {
            switch (attributeName)
            {
            case JetColumn.objectSid:
            {
                return(new SecurityIdentifier(attributeValue, 0).Value);
            };

            case JetColumn.lastLogon:
            {
                Int64 lVal = BitConverter.ToInt64(attributeValue, 0);

                if (lVal > 0)
                {
                    return(String.Format("{0:yyyy-MM-dd hh:mm:ss}", DateTime.FromFileTime(lVal)));
                }
                return(null);
            };
            }
            return(Encoding.Unicode.GetString(attributeValue));
        }
Esempio n. 2
0
        public Queue <SortedList <string, string> > RetrieveTranslatedAttributes(string eseDbTableName, JetColumn attributes)
        {
            Queue <SortedList <string, string> > result = new Queue <SortedList <string, string> >();

            try
            {
                if (Api.TryOpenTable(this.jetSesId, this.jetDbId, eseDbTableName, OpenTableGrbit.ReadOnly, out this.jetTableId))
                {
                    this.tableName = eseDbTableName;

                    int recordsTotal = -1;
                    Api.JetIndexRecordCount(this.jetSesId, this.jetTableId, out recordsTotal, 0);

                    while (recordsTotal > 1)
                    {
                        Api.JetMove(this.jetSesId, this.jetTableId, JET_Move.Next, MoveGrbit.None);

                        SortedList <string, string> row = new SortedList <string, string>(StringComparer.OrdinalIgnoreCase);
                        result.Enqueue(this.ReadRowAttributes(attributes));

                        recordsTotal--;
                    }
                }
            }
            catch (Exception eX)
            {
                throw new Exception(string.Format("{0}::{1}", new StackFrame(0, true).GetMethod().Name, eX.Message));
            }

            return(result);
        }
Esempio n. 3
0
 private string GetAttributeInternalName(JetColumn jetColumn)
 {
     return(GetAttributeInternalNames(jetColumn)[0]);
 }
Esempio n. 4
0
        private string[] GetAttributeInternalNames(JetColumn jetColumns)
        {
            List <string> result = new List <string>();

            if ((jetColumns & JetColumn.objectSid) > 0)
            {
                result.Add("ATTr589970");
            }
            if ((jetColumns & JetColumn.sAMAccountName) > 0)
            {
                result.Add("ATTm590045");
            }
            if ((jetColumns & JetColumn.sAMAccountType) > 0)
            {
                result.Add("ATTj590126");
            }
            if ((jetColumns & JetColumn.userPrincipalName) > 0)
            {
                result.Add("ATTm590480");
            }
            if ((jetColumns & JetColumn.userAccountControl) > 0)
            {
                result.Add("ATTj589832");
            }
            if ((jetColumns & JetColumn.lastLogon) > 0)
            {
                result.Add("ATTq589876");
            }
            if ((jetColumns & JetColumn.lastLogonTimestamp) > 0)
            {
                result.Add("ATTq591520");
            }
            if ((jetColumns & JetColumn.accountExpires) > 0)
            {
                result.Add("ATTq589983");
            }
            if ((jetColumns & JetColumn.pwdLastSet) > 0)
            {
                result.Add("ATTq589920");
            }
            if ((jetColumns & JetColumn.badPasswordTime) > 0)
            {
                result.Add("ATTq589873");
            }
            if ((jetColumns & JetColumn.logonCount) > 0)
            {
                result.Add("ATTj589993");
            }
            if ((jetColumns & JetColumn.badPwdCount) > 0)
            {
                result.Add("ATTj589836");
            }
            if ((jetColumns & JetColumn.primaryGroupID) > 0)
            {
                result.Add("ATTj589922");
            }
            if ((jetColumns & JetColumn.EncryptedNTHash) > 0)
            {
                result.Add("ATTk589914");
            }
            if ((jetColumns & JetColumn.EncryptedLMHash) > 0)
            {
                result.Add("ATTk589879");
            }
            if ((jetColumns & JetColumn.EncryptedNTHashHistory) > 0)
            {
                result.Add("ATTk589918");
            }
            if ((jetColumns & JetColumn.EncryptedLMHashHistory) > 0)
            {
                result.Add("ATTk589984");
            }
            if ((jetColumns & JetColumn.unixPassword) > 0)
            {
                result.Add("ATTk591734");
            }
            if ((jetColumns & JetColumn.ADUserObjects) > 0)
            {
                result.Add("ATTk36");
            }
            if ((jetColumns & JetColumn.supplementCredentials) > 0)
            {
                result.Add("ATTk589949");
            }

            return(result.ToArray());
        }
Esempio n. 5
0
        /// <summary>
        /// Method translates attributes to string,string collection
        /// </summary>
        /// <param name="attributes">JetColumn attributes to translate</param>
        /// <returns></returns>
        private SortedList <string, string> ReadRowAttributes(JetColumn attributes)
        {
            SortedList <string, string> result = new SortedList <string, string>(StringComparer.OrdinalIgnoreCase);

            if ((attributes & JetColumn.objectSid) > 0)
            {
                string internalName = this.GetAttributeInternalName(JetColumn.objectSid);
                byte[] value        = Api.RetrieveColumn(this.jetSesId, this.jetTableId, this.databaseTables[this.tableName][internalName].Columnid);
                if (value != null)
                {
                    result.Add(JetColumn.objectSid.ToString(), new SecurityIdentifier(value, 0).Value);
                }
                else
                {
                    result.Add(JetColumn.objectSid.ToString(), null);
                }
            }

            if ((attributes & JetColumn.sAMAccountName) > 0)
            {
                string internalName = this.GetAttributeInternalName(JetColumn.sAMAccountName);
                byte[] value        = Api.RetrieveColumn(this.jetSesId, this.jetTableId, this.databaseTables[this.tableName][internalName].Columnid);
                if (value != null)
                {
                    result.Add(JetColumn.sAMAccountName.ToString(), Encoding.Unicode.GetString(value));
                }
                else
                {
                    result.Add(JetColumn.sAMAccountName.ToString(), null);
                }
            }

            if ((attributes & JetColumn.userAccountControl) > 0)
            {
                string internalName = this.GetAttributeInternalName(JetColumn.userAccountControl);
                byte[] value        = Api.RetrieveColumn(this.jetSesId, this.jetTableId, this.databaseTables[this.tableName][internalName].Columnid);

                if (value != null)
                {
                    result.Add(JetColumn.userAccountControl.ToString(), BitConverter.ToUInt32(value, 0).ToString());
                }
                else
                {
                    result.Add(JetColumn.userAccountControl.ToString(), null);
                }
            }

            if ((attributes & JetColumn.EncryptedNTHash) > 0)
            {
                string internalName = this.GetAttributeInternalName(JetColumn.EncryptedNTHash);
                byte[] value        = Api.RetrieveColumn(this.jetSesId, this.jetTableId, this.databaseTables[this.tableName][internalName].Columnid);

                if (value != null)
                {
                    result.Add(JetColumn.EncryptedNTHash.ToString(), BitConverter.ToUInt32(value, 0).ToString());
                }
                else
                {
                    result.Add(JetColumn.EncryptedNTHash.ToString(), null);
                }
            }

            return(result);
        }