Friday, February 17, 2012

Access Remote Server Resources in asp.net

I am writing an asp.net page for work that needs to access files on servers in remote offices, and serve those files to the user who requested it.
The asp.net app knows the path to the file, and in testing a simple command like this works:

Dim FileExists As Boolean = My.Computer.FileSystem.FileExists(filePath)

The problem is that in testing, the user account being used to execute the above code under is my own. But on the production web server, the iis worker process is running under "NETWORK SERVICE" and that account is not on the domain and does not have access to resources...well anywhere.

The solution to this problem was to impersonate a user with domain privileges, and use NTFS permissions to allow that user account access to the resources I need to access.

Using code I found here: http://support.microsoft.com/default.aspx?scid=KB;EN-US;306158#4

I used the code under the "Impersonate a Specific User in Code" section and it worked perfectly!

I basically just copier the code in to my user control with the exception of the code in the form_load sub, and used this where I needed it:

If impersonateValidUser("Username", "Domain", "Password") Then
'Insert your code that runs under the security context of a specific user here.
FileExists = My.Computer.FileSystem.FileExists(filePath) = True
undoImpersonation()
Else
'Your impersonation failed. Therefore, include a fail-safe mechanism here.
Throw New Exception("Unable to access KD files. Security failure.")
End If


Be sure to undo the impersonation after the code you need elevated has executed.

Note: I tried to use the Domain Administrator account for testing, and it seemed to impersonate it, but the code did not execute with elevated privileges. I used a normal domain user account and that did the trick. There must be some failsafe to disallow the use of the Administrator account in this way.

Monday, February 6, 2012

I am cursed

Woke up this morning to find that somebody had broken in to our unit, rummaged through my Wife's handbag and found her wallet. Took all her cash and then left.

This is getting a bit out of hand.

Thursday, February 2, 2012

Am I cursed?

I genuinely think I might be cursed. Any ideas?


Evidence:

Late November 2011:
I crash my car, my pride and joy. I write it off, and two other cars with it. Other parties lie to cover their butts, so I get found to be at fault and lose a bunch of points off my license.

Early December 2011:
Get a speeding fine in a state I've never driven in before, on a road I've never driven on before, in a car I've never driven before, which I later find out has a faulty speedo. While interstate on a work trip!

Early January 2012:
First day back at work, and it turns out the night before our NSW Head Sales office was struck by lightning. Twice.
Strike fried almost every VoIP phone, almost every Switch, the only server, and all of the VMs that were running on it, the Cable Modem, 8+ motherboards in workstations, 5+ PSUs in workstations.
Residual damage from the strike destroys several further switches in varying degrees of sparks and electrical smoke.

Two weeks ago, I get cut off by some jerk in a white van who pretends to let me merge (I have right of way) and then speeds up at the last second to try and make me run out of road and crash in to a gutter.

Last Week, nearly get killed by a courier truck almost crushing me while driving through North Ryde.

Last night, after cooking dinner I seriously burn my finger and now there's a massive blister on it that is annoying the hell out of me.

For the last 3 weeks one of my customers has had a problem that I simply cannot figure out how to fix. It's stressing the hell out of me.

Work keeps piling up faster than I can complete it, and people keep hassling me for things that I just don't have time to do.

I keep getting woken up at 5:30am by the guy across the road doing a burnout on his way to work.

Two nights ago, my SSD in my PC dies completely!

Last night, I get woken up at 1:30am by the MD's assistant because the MD is overseas and needs a file deleted on the network.

Tonight, the night before I go quad biking with by Brother-In-Law, the power at our Head Office goes out and all the servers go down. Now I have to wait for the power to come back on and go in to work to turn everything back on that doesn't turn on by itself. My off-sider is at a medical appointment in the morning and won't be around tomorrow. What's the bet I miss quad biking altogether?

I think I missed a couple things.

FML

Friday, October 28, 2011

How to hide Battlefield 3 Beta in Origin

As discussed here:
http://forums.steampowered.com/forums/showthread.php?t=2172567

Head over to: "C:\ProgramData\Origin\InstalledGames.xml"

Search for Game GameID="71171" and change "hidden="0"" to "hidden="1""

No more BF3 beta in origin (you need to restart origin)

Wednesday, September 28, 2011

LanSafe and Windows Server 2008 Firewall Issues

Recently I upgraded our UPS Software to LanSafe 6.0.6 and I found that all of our Windows Server 2008 R2 machines were not appearing in the Management Settings.

When I opened Management Settings it sat at "Loading management settings data" for a long time and then I received a warning:
One or more member is offline. Saving these settings will overwrite existing management settings.
Are you sure you want to change the Management Settings?


I pressed Yes, and only the Windows Server 2003 machines in our environment were visible, plus the Controller.

I discovered that the LanSafe controller makes an active attempt to connect to each of it's members, instead of each of the members regularly polling the controller. This kind of makes sense, but I had previously thought that there would be a constant TCP connection between each Member and it's Controller.

In fact, it's all UDP traffic on UDP ports 3068, 3069, and 7015 as explained here:
http://www.powerware.com/Software/lansafe_help/LSHelp404.htm
Additionally, I found the controller was listening on UDP Port 4500, but it's unclear why, or whether it's necessary to allow that UDP Port on the controller.
Be sure to allow the PowerMonitor.exe and UDP Ports 3068, 3069, and 7015 to receive incoming traffic on the LanSafe Controller.

In order to fix the 2008 clients not appearing issue, we needed to add a new INCOMING rule in to the "Windows Firewall with Advanced Security" on each of the Members. The rule was for:
C:\Program Files (x86)\Powerware\LanSafe\Bin\PowerMonitor.exe

You must allow the PowerMonitor.exe executable to receive incoming traffic through the firewall.

I feel sorry for anybody who is managing hundreds of 2008 boxes, you might want to consider using Group Policy to push out this firewall rule since manually adding it to each machine seems impractical.

Hope this helps.

Thursday, August 25, 2011

SKYPE HOME I FART IN YOUR GENERAL DIRECTION

Dear Skype, or Microsoft, or whoever you are now,

Skype Home needs to be OPTIONAL. You CANNOT FORCE YOUR SOCIAL NETWORK BULL***T DOWN OUR THROATS!

If I ever meet the assh*le who decided to turn Skype Home on, and make it compulsory, I will fart on your head.

Sincerely,

A very P*SSED OFF CUSTOMER!!

Saturday, June 4, 2011

Domestic Disturbance

I woke up abruptly this morning by the sound of a male yelling and a female's hysterical screaming coming from a neighboring unit.

As I lay in bed, I could tell they were not speaking English. It sounded like the male was the aggressor and the female was the victim.

I got out of bed, still in my underwear, and went to the hallway to listen. I wanted to see if it was just a silly argument over who was going to the corner shop to buy milk, or something more serious. It sounded pretty serious, but as it had only just started I went back inside to see if it would calm down.

As I went to the bathroom, I heard continued yelling and a big bang come from the other unit. It's at that point I was concerned someone might be being hurt. So I went to the hallway and banged pretty hard on their door. The screaming continued.

I banged again and it sounded like the screaming and whimpering of the woman moved from the living room/kitchen to a bedroom. Still no answer at the door, and the screaming continued.

I banged at least two more times, before I decided this was probably out of my hands. I picked up the phone and dialed 112. Quick side note: 112 DOES NOT work from a landline! Only mobiles. Lesson learned. I dialed 000 from my house phone (instead of my mobile) because when you use a fixed line the call center already knows your address, return number, etc. You get through to the police much quicker this way.

I explained that I was reporting a domestic disturbance, that I'd heard at least 1 male and 1 female in distress in the unit, and that it sounded pretty serious. They took my details, and now begins the anxious wait. You can never tell if the cops will actually come out. We had a party that got gate-crashed a few years ago, and it took 4 or 5 calls to the police before we got any help, and by that stage we'd already dispersed the majority of the riffraff anyway! The cops simply drove past the house, and continued on their way by the time they turned up. So you never know if they'll come to help.

This time they explained that the next available car would be sent, and it certainly was. Within minutes (seemed like ages), an unmarked Holden Commodore Omega came hauling arse down Parramatta Road, lights and sirens screaming. The two detectives managed to get in to the building as someone was driving out of the basement. Another car turned up which I didn't see, and as I came to the front door of my unit to tell the cops which unit it was, 2 plain clothed detectives and 2 fully uniformed police were in the hallway.

I explained that I had been woken up fairly abruptly by the argument and that it must have been pretty loud, as our walls are quite thick (double brick, cement rendered).

The cops knocked on the door of the other unit, and announced themselves as Auburn police, as I wished them luck and closed my door.

I had various communications with one particular Constable, who took my details. He didn't seem to think anybody was hurt, and seemed frustrated that they were unable to get a solid understanding of what the argument was about. But seemed confident the woman was ok.

They all left about 30 minutes after it began.

My main concern was for the woman in the fight, she sounded like she was screaming for help. An unmistakable scream in any language. But, my secondary concern was, Did I do the right thing by calling? Did I just waste the time of 3 cars of police? I hear sirens screaming up and down Parramatta Road all day and all night, the cops must be flat out all the time. Should I have waited longer to see if the argument settled down? What happens if the woman was seriously hurt, and couldn't call for help and I did nothing?

Is it always safer just to call the cops and let them determine the seriousness of the situation? Or should I have tried for longer to talk to the occupants myself to see if everyone was OK?

Who knows what would have happened if I didn't call. Maybe nothing.