CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Peter's Gekko

public Blog MyNotepad : Imho { }

December 2006 - Posts

  • Worst goodies

    The year is almost over. So is the project of tidying up my office. The best things found, which also takes up space in a quite uneconomic way, are all the personal souvenirs. Like the beautiful cardboard creations by my kids. And there are goodies. Good goodies, redundant goodies and bad goodies.

    What is it ?

    It's a bottle opener with a folding beaker. Does it work ?

    No, the beaker leaks like hell. Which would have been appropriate had the goodie been labeled Windows 9x. So far the gadget has survived as a thumbscrew and jumper collector. But it won't make it till next year.

    See you in 2007.

  • Deployment of a VS2005 web application project

    With VS 2005 sp1 a web application project (which puts all webpages in a single assembly) is again a standard project type. What you have to watch yourself is the support in a deployment project. Having created a "web setup" project you see the folder tree on the target machine. This does include a bin folder.

    It's up to you to include the right files in the right folders.

    • Content files in the root.
    • Primary project output and all loose referenced assemblies in the bin folder.

    No big deal; but it's better to know this in advance instead of finding out behind your customers machine J

  • The end of the game port

    Sinterklaas, the original Santa Claus, still honors his country of origin. December 5th he visits the Netherlands to shower kids of all ages with presents. This year that included some in-house shuffling with the gaming PC and game controllers. As old Santa has difficulties in staying up to date with all this new technology I had to give him a hand.

    The better older motherboards included a game port connector to plug in your joystick, gamepad or even MIDI-cables. In case the motherboard didn't provide the connector there was often one on the soundcard; all Sound-Blasters had one.

    My old MS FF stick has been used like this for years with a lot of PC's.

    We also have a simple but efficient gamepad with such a connector. My kids want their gamepad, for instance to make their gameboy-emulator even more realistic. I already confessed being somewhat a FS addict; I did not want to lose (my) control(er) either in the shuffle. The kids got a new XP machine, I went to Vista.

    Newer motherboards do not have a game port. When running Vista inserting a SoundBlaster did not help either. Vista perfectly identified the "Unsupported Creative Gameport". So for me it would be end of the game or back to XP.

    Sitecom produces a gameport to USB cable. This is known not to work with a complex controller like the MS FF joystick. But we gave it a try for the gamepad. At first sight it worked, Windows recognizes the controller and you can calibrate it in the control panel. But it ended there. Most of the games either didn't see the controller or it ran haywire having lost all calibration. Droids running all over the screen without even touching it. So to prevent disillusioned kids my suggestion is to stay away from that. This weekend I will plug in an old Sound-Blaster again.

    For my personal games I needed a more drastic solution. There did not seem to be a chance of getting my joystick hooked up. Thank goodness Santa found a very good deal on a Saitek aviator (and even rudder pedals !). The joystick does not have an electronic force feedback, but does have a large mechanical spring which always returns the stick to the central position when you let go. Sounds simple but it works very well. American top stunt team the Blue Angels fly standard planes. The only modification made is such a spring fitted to the stick.

    Modern game controllers all use USB. An extra good thing with that is that it's no problem to hook up several controllers at the same time. Games know how to handle that. Vista instantly reported both Saitek devices after plugging in and in most flight sims you simply assign control surfaces to levers on the sticks attached. Most flight sims, the older pre-USB CFS1 can't handle it. It does see several controllers but refuses to hook up. That's the end of that game as well, but to the others it's a new game. The gameport may be dead but I'm soaring up to heaven.

     

  • AD GetDirectoryEntry on DirectorySearch result <> new DirectoryEntry (Security hits back)

    In my last post I described some of my troubles working with Active directory entries from code. Here's another one which increased my baldness.

    I described using a Directory search object, creating a DirectoryEntry out of that and setting the password to validate the entry. Like this:

    const string MemberOf = "memberof";

       

    DirectorySearcher ds = new DirectorySearcher();

    ds.Filter = "samaccountname=" + userName;

    ds.PropertiesToLoad.Add(MemberOf);

    SearchResult sr = ds.FindOne();

    DirectoryEntry adsEntry = sr.GetDirectoryEntry();

    adsEntry.Password = passWord;

    try

    {

       object o = adsEntry.NativeObject;

    }

       catch (DirectoryServicesCOMException ex)

    {

       // Not a valid account

    }

    Alas this does not always work in a real life domain. It does work when you are validating your own account under which you are logged in. But it does not work for any other account. What does work is creating a new directoryentry from scratch using exactly the same credentials.

    DirectoryEntry adsEntry = new DirectoryEntry("", userName, passWord);

    try

    {

        object o = adsEntry.NativeObject;

    }

    catch (DirectoryServicesCOMException ex)

    {

        // Not a valid account

    }

    Don't ask me why, without a doubt it's intended as security. Crossing the border from coding into the world of IT management just stays hard.

    Posted Dec 14 2006, 04:47 AM by pvanooijen with 2 comment(s)
    Filed under:
  • Getting information out of active directory: DirectorySearcher, Properties and DirectoryEntry

    One of my apps needed to get some information out of ActiveDirectory. The 2.0 framework does contain some very nice classes to help. Getting these to work as intended took some trouble; so I'll recapitulate in public.

    The scenario: the user can log in from anywhere, not necessarily from within the domain, and provides his username and password credentials (note the security risk of a password travelling over a potentially insecure wire). It's up to the webapp to check if the user is a valid member of the (Active Directory) domain and which group s/he is a member off. The web server on which the app is running is a member of the domain.

    The DirectorySearcher class provides all AD info. Use it's Filter property to select the AD entries. The FindOne method will return the first entry matching, the FindAll method returns all entries. After invoking the method the Properties of the search result contain all AD properties.

    DirectorySearcher ds = new DirectorySearcher();

    ds.Filter = "samaccountname=" + userName;

    SearchResult sr = ds.FindOne();

       

    System.Text.StringBuilder sb = new System.Text.StringBuilder();

    foreach (string var in sr.Properties.PropertyNames)

        sb.AppendLine(string.Format("{0} : {1}", var, sr.Properties[var][0].ToString()));

    this first shot returns most AD info. An example of the result in IE

    That are quite a lot of properties. You can restrict the number of properties returned by filling the PropertiesToLoad collection of the DirectorySearcher object. Another thing to watch is that some properties are a collection on itself. Take the memberof property. It's a list of the groups the user is a member off. Precisely the info I needed. A better shot would be:

    DirectorySearcher ds = new DirectorySearcher();

    ds.Filter = "samaccountname=" + userName;

    ds.PropertiesToLoad.Add("memberof");

    SearchResult sr = ds.FindOne();

       

    System.Text.StringBuilder sb = new System.Text.StringBuilder();

    foreach (string var in sr.Properties.PropertyNames)

    {

        for (int i=0; i < sr.Properties[var].Count; i++)

                        sb.AppendLine(string.Format("{0}-{1} : {2}", var, i, sr.Properties[var]Idea.ToString()));

    }

    Now the code provides me exactly the info I need.

    Note that you can read all this information without a valid password for the user. To validate the user password you need a DirectoryEntry object. This can be created straight from the search result. After setting the Password property you have to bind to the native underlying AD Com object to validate the password.

    DirectoryEntry adsEntry = sr.GetDirectoryEntry();

    adsEntry.Password = passWord;

    try

    {

    object o = adsEntry.NativeObject;

    }

    catch (DirectoryServicesCOMException ex)

    {

    adError = ex.Message;

    }

    In case the password is invalid this will result in a clear message "Logon failure: unknown user name or bad password".

    In the end this looks quite simple. What really got me on the wrong track is that the internal name of the AD properties does not always match the name as it is displayed in the AD management console. For instance there no Last Name property, only a sn property. I had to find out the property names by enumerating the PropertyNames collection; I could not find any resource which map the display names on the internal names. Another thing is that for a domain user who is not part of any internal domain group, but only of an external group, the member of collection is empty and as a result the memberOf property is not even returned.

    It took some patience…

  • Sign of the times giveaway

    Tidying up the office I found this goodie.

    For those who started with Windows and pen-drives: it is a 5.25" single sided floppy disk (with a capacity of 160 or 180 Kb) by the Massachusetts Mineral and Mining Minnesota Mining and Manufacturing company pimped as an analog clock. At the time floppies were so expensive they could offer you a complete clock when buying a 10-pack DS.

    I'm emotional fool enough wanting to keep it. But I found two copies, this one is a giveaway. You want it ? Here's how to apply:

    • Make an original comment why you should get it.
    • Visit the SDN meeting coming December 11 in Ede. The program on itself is more than good enough to visit. No worries, I'm not speaking J. In case you can't make it there due to distance or language problems, include an original way to get the clock to you.

    See you in Ede.

More Posts

Our Sponsors

Free Tech Publications

This Blog

Syndication

News