• Converting Object Sid byte[] to Object Sid String

    I am working on an asset/inventory software for our IT deparment to replace a somewhat dated access database that uses a lot of free text fields. During this process i wanted to make sure that I collected Active directory users into my own tables to persist an audit trail for each asset. Since active directory users get deleted eventually and there may be users with a Sam Account name that is the same as a previous employee I decided to story users by their Object Sid as the primary key. Unfortunately,  System.DirectoryServices.DirectorySearcher returns DirectoryEntry objects which contain the objectSid as an array of bytes (byte[]) which isn't very useful for a primary key nor for the human eye. People are more use to seeing something like S-21-5-29389828-1283920-1283901-12345 or something like that. So i did some research on it and came up with this unmanaged solution.



     
           [DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
            internal static extern bool ConvertSidToStringSid(
                IntPtr sid,

                [In, Out, MarshalAs(UnmanagedType.LPTStr)] ref StringBuilder pStringSid);

    StringBuilder sidString2 = new StringBuilder();
     
                   
                    byte[] bytes = user.ObjectSid;
                    unsafe
                    {
                        IntPtr ptr = Marshal.AllocHGlobal(bytes.Length);
     
                        for (int x = 0; x < bytes.Length; x++)
                        {
                            Marshal.WriteByte(ptr, x,bytes[x]);
                        }
                        ConvertSidToStringSid(ptr, ref sidString2);
                        Marshal.Release(ptr);
                    }
     
    Unfortunately, just after i got that written i found this Managed Solution!
    http://www.netomatix.com/GetUserSid.aspx

    Full story

    Comments (0)

  • MCTS: Windows Communication Foundation, sign me up.

    So, it's not officially announced anywhere that i could find, but i read on Howard's blog that there is in fact MCTS: Windows Communication Foundation, MCTS: Workflow Foundation, and MCTS: Windows Presentation Foundation coming eventually. Somewhere on his blog i read they were due late 2007.

    Thankfully, my 70-536 will count towards all of them... which is making me almost think I should just stop reading the 70-529 prep book i bought last week, but it just reads so well! ( hah hah! ).

    Due to the extreme cost of creating tests it seems microsoft are doing a proof of concept on community test development, see more here

    It also seems like the shelf life of the MCPD is going to be 3 years, which by the time i get all the mcts's for MCPD: Enterprise developer i'll have to learn new mcts's again... let me at those beta tests, time is wasting!

    As far as things at work... i'm getting pretty frustrated with the enterprise library validation rules... i guess a Nullable<DateTime> can't be validated by a date range validator. If you composite And with [IgnoreNulls] then the range works but it allows nulls so if you are requiring a date it's not possible to get the error template to show up... conversly if you change your type to a DateTime then it automatically will be 1/1/0001... which since i'm binding the day, month, and year to seperate text boxes it makes my month and day both valid, which isn't my intended result.

    Another interesting, nay, annoying, thing about wpf and validation with the enterprise library is value converters... if for example i want to format numbers (so that 0's are string.empty in a text box for example) then i get some really annoying exceptions with ValidationHelper... i'd say more but i haven't proven that it's enterprise library or Paul Stovell's implementation of it (which i'm using at work, thanks paul!) or lastly, that it may be my own ignorance of how to use them or both or with wpf!

    For my birthday, yesterday, i caught a cold, gave up a horrible habit unintentionally, and found that Bear Grylls will eat just or drink just about anything, and will follow it up by brushing his teeth with just about any piece of branch, root, or leaf he can find.

    Full story

    Comments (0)