CSharp/C# >> Multiple Domain Authentication in Class Library

by jimmyraystamper » Mon, 22 Dec 2003 00:44:04 GMT

HI there

First time poster, long time lurker

I am building a windows class library that will be used on an active
server page. The purpose of the library is to copy files from one
server to another. The number of files to be copied will range
anywhere from 1 to 1000. Seems simple enough, but here's the catch:
the code will be running in domain A and the source files will need to
be copied from Domain B to Domain C. My issue is authentication. I
have tinkered with using the Diagnostics.Process class to run "net
use" commands to connect to the shares on Domains B and C (See
OpenShare method below). The OpenShare function runs just fine and
the "net use" returns with an ExitCode of 0. So, everyhting should be
OK. However, when I attempt to copy files between the shares using
File.Copy, I get "Access Denied" errors. It is as if the shares were
not created. I know that the permissions of the domain users I am
using are sufficient to perform the required operations. Also, the
IUSR that is running the code will be priviledged enough to run
cmd.exe (I know, that may give some heart palpatations, but there are
several other layers of security in place). Any thoughts, ideas, and
criticisms are welcome.


string retval1 = OpenShare(@"\\domainB\shareB", "userBpassword",
"domainB\userB");
string retval2 = OpenShare(@"\\domainC\shareC", "userCpassword",
"domainC\userC");

// retval1 and retval2 should each be "0";

try
{
File.Copy(@"\\domainB\shareB\myfile.txt",
@"\\domainC\shareC\myfile.txt", true);
}
catch(System.Exception err)
{
// Do stuff to handle errors...
// err.Message will contain "Access Denied"
}



private string OpenShare(string username, string password, string
uncpath)
{
try
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "cmd.exe";
psi.Arguments = String.Format("/c net use {0} {1} /user:{2}",
uncpath, password, username);
Process proc = Process.Start(psi);
proc.WaitForExit();
return "(OpenShare) " + Convert.ToString(proc.ExitCode);
}
catch(System.Exception err)
{
return err.Message;
}
}

Similar Threads

1. Integrated Windows Authentication for Multiple Domains - Asp.Net

2. C# Class Library: multiple classes

I have a class library which contains 3 classes; one exposes all its 
behaviours and the other two are used internally by the public class. My 
problem is that although I can create an instance of the subservient classes, 
I cannot see the methods in them from the public class.

Could someone guide me on this or give me a template?
Thanks.

3. Connection string/Sql Server 2005/Windows authentication/ but not on domain - CSharp/C#

4. c# and domain authentication

Is it possible thru c# to create a login screen which authenticates with a
windows servers using normal windows login instead of having to create a
different set of tables and passwords for my users.



5. Connection string/Sql Server 2005/Windows authentication/ but not on domain - CSharp/C#

6. NTLM authentication against an NT 4.0 Domain

I'm trying to authenticate username/passwords against an NT 4.0 Domain.  My 
client is still using NT 4.0 even with Windows XP clients running Framework 
1.1 SP1

I've looked through the 1.1 Framework System.Security namespaces, and 
there's nothing I can find that will do this.

How can I authenticate against against NT 4.0 Domains? 


7. User Authentication on Domain Controller - CSharp/C#

8. User domain authentication

Jeff wrote:

> Does anyone know how to obtain the currently logged in user's domain authentication information
> (username and password)?  I have a program which sends email using anonymous SMTP but our
> exchange server will not allow us to send email outside the domain without authentication.

Any decent non-relay mail servr will require the same or it will be used for SPAM.
The user name is easy, I would save the password somewhere. 

unsigned long maxlen = 50;
char buf[51];
::GetUserName(buf,&maxlen);

-- 
-Michael Gillen