Hi all,

First of all, apologies in advance for what seems to be the beating of a
dead horse.  I've poured over the docs and the discussions, but I can't find
an example that quite meets my scenario.

-----> SCENARIO:
ASP.NET webserver on Intranet using Windows authentication.
Webserver needs to create directories based on user input on a Linux server
running Samba.
Samba configuration grants these users (with domain accounts) write access
to the Linux server.

-----> HISTORY:
I've tried LogonUser passing (UserName, Domain, Password, 3, 0, out token1)
and WindowsIdentity.Impersonate() with no luck.  Some combinations have
earned a successful login, others haven't, but in all cases, I receive a
"DirectoryNotFoundException", insinuating improper access rights.

-----> INTERESTING POINT:
This code (and a combination of WindowsIdentity.Impersonate()) successfully
creates directories on machines that I have access to using my domain
userid/pwd.  I don't have access to the Linux machine, so I'm relying on
others to attempt login.  While these users are able to be authenticated
using WindowsIdentity.Impersonate(), they cannot create directories on the
Linux machine or their own workstations.  Using the code below, which
apparently is what is required when accessing remote servers, these same
users are not being authenticated.

-----> CODE BIT 1 (relevant pieces left in):
(upon form submit providing username, pwd, domain, and directory to create)
   ImpersonatedUser u = new ImpersonatedUser();
   u.Password = sPassword;
   u.UserName = sUser;
   u.Domain = sDomain;
   if (u.Login())
    (create the directory)

-----> CODE BIT 2 (relevant pieces left in):
public class ImpersonatedUser
{
  [DllImport("C:\\WINDOWS\\System32\\advapi32.dll")]
  public static extern bool LogonUser(String lpszUsername,
                                      String lpszDomain,
                                      String lpszPassword,
                                      int dwLogonType,
                                      int dwLogonProvider,
                                      out int phToken);

  [DllImport("C:\\WINDOWS\\System32\\advapi32.dll")]
  public static extern bool ImpersonateLoggedOnUser(long token);

  public string UserName, Password, Domain;

  public bool Login()
  {
    int token1;
    if (LogonUser( UserName, Domain, Password, 4, 0, out token1 ))
      return (ImpersonateLoggedOnUser(token1));
    return false;
  }
}

Can someone point out to me what I may be doing incorrectly??

THANKS IN ADVANCE!

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to