all groups > dotnet security > july 2005 >
You're in the

dotnet security

group:

C# windows service blues



C# windows service blues Panayotis
7/5/2005 11:17:02 PM
dotnet security: Hi,

I have created a web service using C# that needs to check whether some XML
files are updated, if they are, it downloads them (saves them to disk) and
processes them by updating data in a back-end MS SQL database.

The client has a proxy server installed on their network and they request
that the windows service be run under a low privileged account that will only
be able to download the XML files through the proxy as well as
insert/update/delete data in the MS SQL database.

In addition, they do not want to store the proxy info (server name,
username, password and domain) to a file, even in encrypted form, but they
request that the windows service should "automagically" download the files
via the proxy server by retrieving the SID token of the user account under
which the windows service will be run from time to time.

I am no expert in this, so I do not know if it is doable. How can I retrieve
the SID of the currently "service user account" in order to present the
appropriate network credentials to the proxy server and download the files ?

Can anyone give any pointers, code examples, anything really ?

Clueless,
Re: C# windows service blues Dominick Baier [DevelopMentor]
7/5/2005 11:56:20 PM
Hello Panayotis,

so - i guess this proxy does windows integrated authentication.

Are you using HttpWebRequest for downloading??

This class has a .Proxy property where you can set the proxy.

The WebProxy class in turn has a .Credentials property.

To authenticate against the proxy using windows auth you set

proxy.Credentials = CredentialCache.DefaultCredentials;

and assign the proxy to the webrequest

that should do the trick.


---------------------------------------
Dominick Baier - DevelopMentor
http://www.leastprivilege.com

[quoted text, click to view]


Re: C# windows service blues Panayotis
7/6/2005 12:32:01 AM
Hi Dominick,

Thank you for your prompt feedback.

So, I just supply the USER ACCOUNT i will be given by the network admin of
the client and enter it to the windows service. Do I need to mess with the
rights of the user account ???

For the file download, I use the WebClient class to download the XML file,
only after I attempt to load it into an XMLDocument, using the
XMLDocument.Load (fileURL) method.

I load it into an XMLDocument so as to parse an XML node containing the
"LastUpdate" file date. If the "LastUpdate" date is newer than a date I keep
on the db, then I download the XML file and save it to disk, using
WebClient.DownloadFile (fileURL, filename) .

How can I download the file and write it to disk using the HttpWebRequest
class?

Thank you again for your help.

[quoted text, click to view]
AddThis Social Bookmark Button