Mike,

The two subroutines, EncodePassword and DecodePassword are Visual Basic
Scripting that encode and decode IMail passwords. Please feel free to
rewrite them in some other language or use them as is.

Of course you need to be able to set and retrieve the IMail passwords from
the NT registry. More specifically, you need to be able to read and write
all of the pertinent registry entries. Use the IISSample.RegistryAccess
component  from Microsoft's Active Directory Services SDK. The Registry
Access component provides access to the registry keys on a local or remote
machine. Using this component you can retrieve, set, add, delete and copy
registry keys and named values.  You can download it at
http://www.microsoft.com/ntserver/nts/downloads/archive/IISRegistryAccess/de
fault.asp . Ensure that you read the documentation carefully. Test on a test
machine. If you screw up on a live machine, it can ruin your entire day.
Possibly two or three days. I am not joking about that. Upon command,
RegistryAccess will happily delete any portion of your regisrtry. It will
even do it remotely from another machine. Once you have the component, you
need a working example. See the Visual Basic Scripting function
CreateEmailAccount. Oh yeah, that code also creates the 4 default mailboxes
for the account.

And of course, you need to temporarily provide your unprivileged user with
admin privs. You could use ASPUSER, an NT User and Security Management
Component, which for $120.00 you can get at  http://www.aspuser.com/ . Or if
you know C and scripting components, you can use the following C code to
handle your ImpersonateLoggedOnUser and RevertToSelf calls. It provides only
the basic requirements, but the rest can be done in scripting...

Other than some knowledge of how IMail uses the registry and how it cross
links Virtual IP or real IP addresses with the host entry, those are the
tools you need.

Having Fun - Dancing on the dark side of the moon,
Mike

----------------------------------------------------------------------------
-----------
// Admin.cpp : Implementation of CAdmin
#include "stdafx.h"
#include "LogonUser.h"
#include "Admin.h"

////////////////////////////////////////////////////////////////////////////
/
// CAdmin

STDMETHODIMP CAdmin::InterfaceSupportsErrorInfo(REFIID riid)
{
 static const IID* arr[] =
 {
  &IID_IAdmin,
 };
 for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
 {
  if (InlineIsEqualGUID(*arr[i],riid))
   return S_OK;
 }
 return S_FALSE;
}

STDMETHODIMP CAdmin::OnStartPage (IUnknown* pUnk)
{
 if(!pUnk)
  return E_POINTER;

 CComPtr<IScriptingContext> spContext;
 HRESULT hr;

 // Get the IScriptingContext Interface
 hr = pUnk->QueryInterface(IID_IScriptingContext, (void **)&spContext);
 if(FAILED(hr))
  return hr;

 // Get Request Object Pointer
 hr = spContext->get_Request(&m_piRequest);
 if(FAILED(hr))
 {
  spContext.Release();
  return hr;
 }

 // Get Response Object Pointer
 hr = spContext->get_Response(&m_piResponse);
 if(FAILED(hr))
 {
  m_piRequest.Release();
  return hr;
 }

 // Get Server Object Pointer
 hr = spContext->get_Server(&m_piServer);
 if(FAILED(hr))
 {
  m_piRequest.Release();
  m_piResponse.Release();
  return hr;
 }

 // Get Session Object Pointer
 hr = spContext->get_Session(&m_piSession);
 if(FAILED(hr))
 {
  m_piRequest.Release();
  m_piResponse.Release();
  m_piServer.Release();
  return hr;
 }

 // Get Application Object Pointer
 hr = spContext->get_Application(&m_piApplication);
 if(FAILED(hr))
 {
  m_piRequest.Release();
  m_piResponse.Release();
  m_piServer.Release();
  m_piSession.Release();
  return hr;
 }
 m_bOnStartPageCalled = TRUE;
 return S_OK;
}

STDMETHODIMP CAdmin::OnEndPage ()
{
 m_bOnStartPageCalled = FALSE;
 // Release all interfaces
 m_piRequest.Release();
 m_piResponse.Release();
 m_piServer.Release();
 m_piSession.Release();
 m_piApplication.Release();

 return S_OK;
}


void AfxBSTR2CString(char * pStr, BSTR bstr)
{
 int nLen = SysStringLen(bstr);
 int nBytes = WideCharToMultiByte(CP_ACP, 0, bstr, nLen, NULL, NULL, NULL,
NULL);
 WideCharToMultiByte(CP_ACP, 0, bstr, nLen, pStr, nBytes, NULL, NULL);
}


char Username[512] = "";
char Password[512] = "";
char Domain[512]   = ".";

HANDLE hToken;

STDMETHODIMP CAdmin::LogonUser()
{
  ::LogonUser( Username, Domain, Password, LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT, &hToken );
 return S_OK;
}

STDMETHODIMP CAdmin::ImpersonateLoggedOnUser()
{
  ::ImpersonateLoggedOnUser( hToken );
 return S_OK;
}

STDMETHODIMP CAdmin::RevertToSelf()
{
  ::RevertToSelf( );

 return S_OK;
}

STDMETHODIMP CAdmin::get_Username(BSTR *pVal)
{

  *pVal = T2BSTR(Username);

 return S_OK;
}

STDMETHODIMP CAdmin::put_Username(BSTR newVal)
{

  AfxBSTR2CString(Username, newVal);

 return S_OK;
}

STDMETHODIMP CAdmin::get_Password(BSTR *pVal)
{

  *pVal = T2BSTR(Password);

 return S_OK;
}

STDMETHODIMP CAdmin::put_Password(BSTR newVal)
{

  AfxBSTR2CString(Password, newVal);

 return S_OK;
}

STDMETHODIMP CAdmin::get_Domain(BSTR *pVal)
{

  *pVal = T2BSTR(Domain);

 return S_OK;
}

STDMETHODIMP CAdmin::put_Domain(BSTR newVal)
{

  AfxBSTR2CString(Domain, newVal);

 return S_OK;
}
----------------------------------------------------------------------------
------------

Function EncodePassword( Password, UserName )

Dim Encode
Dim EncodedStr
Dim EncodeVal
Dim PassLen
Dim i

  Encode = ""
  EncodedStr = ""
  EncodeVal = 0
  PassLen = Len(Password)

  If UserName <> "" Then
    If Len(UserName) = PassLen Then
      Encode = UserName
    ElseIf Len(UserName) > PassLen Then
      Encode = Left(UserName, PassLen)
    Else
      Do While Len(Encode) < PassLen
        Encode = Encode & UserName
      Loop
      If Len(Encode) > PassLen Then
        Encode = Left(Encode, PassLen)
      End If
    End If
    For i = 1 TO PassLen
      EncodeVal = Asc( Mid( Password, i, 1) )
      EncodeVal = EncodeVal + Asc( Mid( Encode, i, 1) )

      Select Case Int( EncodeVal / 16 )
        Case 0
          EncodedStr = EncodedStr & "0"
        Case 1
          EncodedStr = EncodedStr & "1"
        Case 2
          EncodedStr = EncodedStr & "2"
        Case 3
          EncodedStr = EncodedStr & "3"
        Case 4
          EncodedStr = EncodedStr & "4"
        Case 5
          EncodedStr = EncodedStr & "5"
        Case 6
          EncodedStr = EncodedStr & "6"
        Case 7
          EncodedStr = EncodedStr & "7"
        Case 8
          EncodedStr = EncodedStr & "8"
        Case 9
          EncodedStr = EncodedStr & "9"
        Case 10
          EncodedStr = EncodedStr & "A"
        Case 11
          EncodedStr = EncodedStr & "B"
        Case 12
          EncodedStr = EncodedStr & "C"
        Case 13
          EncodedStr = EncodedStr & "D"
        Case 14
          EncodedStr = EncodedStr & "E"
        Case 15
          EncodedStr = EncodedStr & "F"
      End Select

      Select Case Int( EncodeVal MOD 16 )
        Case 0
          EncodedStr = EncodedStr & "0"
        Case 1
          EncodedStr = EncodedStr & "1"
        Case 2
          EncodedStr = EncodedStr & "2"
        Case 3
          EncodedStr = EncodedStr & "3"
        Case 4
          EncodedStr = EncodedStr & "4"
        Case 5
          EncodedStr = EncodedStr & "5"
        Case 6
          EncodedStr = EncodedStr & "6"
        Case 7
          EncodedStr = EncodedStr & "7"
        Case 8
          EncodedStr = EncodedStr & "8"
        Case 9
          EncodedStr = EncodedStr & "9"
        Case 10
          EncodedStr = EncodedStr & "A"
        Case 11
          EncodedStr = EncodedStr & "B"
        Case 12
          EncodedStr = EncodedStr & "C"
        Case 13
          EncodedStr = EncodedStr & "D"
        Case 14
          EncodedStr = EncodedStr & "E"
        Case 15
          EncodedStr = EncodedStr & "F"
      End Select

    Next
    EncodePassword = EncodedStr
  Else
    EncodePassword = " "
  End If
End Function


Function DecodePassword( Password, UserName )

Dim Encode
Dim EncodedStr
Dim EncodeVal
Dim PassLen
Dim i
Dim Ix

  Encode = ""
  EncodedStr = ""
  EncodeVal = 0
  PassLen = Len(Password) / 2

  If UserName <> "" Then
    If Len(UserName) = PassLen Then
      Encode = UserName
    ElseIf Len(UserName) > PassLen Then
      Encode = Left(UserName, PassLen)
    Else
      Do While Len(Encode) < PassLen
        Encode = Encode & UserName
      Loop
      If Len(Encode) > PassLen Then
        Encode = Left(Encode, PassLen)
      End If
    End If

    Ix = 1
    For i = 1 TO PassLen
      Select Case Mid( Password, Ix, 1)
        Case "0"
          EncodeVal = 0
        Case "1"
          EncodeVal = 16
        Case "2"
          EncodeVal = 32
        Case "3"
          EncodeVal = 48
        Case "4"
          EncodeVal = 64
        Case "5"
          EncodeVal = 80
        Case "6"
          EncodeVal = 96
        Case "7"
          EncodeVal = 112
        Case "8"
          EncodeVal = 128
        Case "9"
          EncodeVal = 144
        Case "A"
          EncodeVal = 160
        Case "B"
          EncodeVal = 176
        Case "C"
          EncodeVal = 192
        Case "D"
          EncodeVal = 208
        Case "E"
          EncodeVal = 224
        Case "F"
          EncodeVal = 240
      End Select
      Ix = Ix + 1

      Select Case Mid( Password, Ix, 1)
        Case "0"
          EncodeVal = EncodeVal + 0
        Case "1"
          EncodeVal = EncodeVal + 1
        Case "2"
          EncodeVal = EncodeVal + 2
        Case "3"
          EncodeVal = EncodeVal + 3
        Case "4"
          EncodeVal = EncodeVal + 4
        Case "5"
          EncodeVal = EncodeVal + 5
        Case "6"
          EncodeVal = EncodeVal + 6
        Case "7"
          EncodeVal = EncodeVal + 7
        Case "8"
          EncodeVal = EncodeVal + 8
        Case "9"
          EncodeVal = EncodeVal + 9
        Case "A"
          EncodeVal = EncodeVal + 10
        Case "B"
          EncodeVal = EncodeVal + 11
        Case "C"
          EncodeVal = EncodeVal + 12
        Case "D"
          EncodeVal = EncodeVal + 13
        Case "E"
          EncodeVal = EncodeVal + 14
        Case "F"
          EncodeVal = EncodeVal + 15
      End Select
      Ix = Ix + 1

      EncodeVal = EncodeVal - Asc(Mid(Encode, i, 1))
      EncodedStr = EncodedStr & Chr(CLng(EncodeVal))
    Next
    DecodePassword = EncodedStr
  Else
    DecodePassword = ""
  End If
End Function

Function CreateEmailAccount( UserName, DomainName, Password, LastName,
FirstName )
Dim KeyRoot
Dim KeyName
Dim Registry
Dim MachineName
Dim Path
Dim fso
Dim MyFile

  Set Registry = Server.CreateObject("IISSample.RegistryAccess")
    MachineName = GetEmailServerMachineName( DomainName )
    KeyRoot = "\\" & MachineName &
"\HKEY_LOCAL_MACHINE\Software\Ipswitch\IMail\Domains\" & DomainName
    KeyName = KeyRoot & "\Users\" & UserName
    Path  = "\\" & MachineName & "\CDrive\Imail\" & DomainName & "\users\"
& UserName

  Application.Lock
      Registry.Set KeyName & "\Type", 0
      Registry.Set KeyName & "\Flags", 132
      Registry.Set KeyName & "\MaxMsgs", 100
      Registry.Set KeyName & "\MaxSize", 10000000
      Registry.Set KeyName & "\Fullname", FirstName & " " & LastName
      Registry.Set KeyName & "\MailAddr", UserName & "@" & DomainName
      Registry.Set KeyName & "\Password", EncodePassword( Password,
UserName )
      Registry.Set KeyName & "\info\GivenName", FirstName
      Registry.Set KeyName & "\info\SurName", LastName
    If Registry.KeyExists(KeyRoot) Then
      Set fso   = CreateObject("Scripting.FileSystemObject")
      If fso.FolderExists( Path ) = False Then
        fso.CreateFolder( Path )
      End If

      Path  = Path & "\"

      If fso.FileExists( Path & "Main.mbx" ) = False Then
        Set MyFile = fso.CreateTextFile( Path & "Main.mbx", True)
        MyFile.Close
      End If

      If fso.FileExists( Path & "Draft.mbx" ) = False Then
        Set MyFile = fso.CreateTextFile( Path & "Draft.mbx", True)
        MyFile.Close
      End If

      If fso.FileExists( Path & "Sent.mbx" ) = False Then
        Set MyFile = fso.CreateTextFile( Path & "Sent.mbx", True)
        MyFile.Close
      End If

      If fso.FileExists( Path & "Deleted.mbx" ) = False Then
        Set MyFile = fso.CreateTextFile( Path & "Deleted.mbx", True)
        MyFile.Close
      End If

    End If
  Application.Unlock
  CreateEmailAccount = True
End Function

----- Original Message -----
From: Mike Collins <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, February 27, 2001 12:51 PM
Subject: [IMail Forum] ASP interface for creating user mailboxes


Hello all,
I was asked to automate our e-mail system by creating asp pages that would
allow a user to add themselves through a secure web area.  Has anyone faced
this challenge yet?  Any books or references to get started? I was hoping to
use the imail database but I am wondering if an external database is the way
to go.
Thank you in advance for your time-
Mike Collins, MCSE, MCP+I, MCT, CCNA


Please visit http://www.ipswitch.com/support/mailing-lists.html
to be removed from this list.

An Archive of this list is available at:
http://www.mail-archive.com/imail_forum%40list.ipswitch.com/



Please visit http://www.ipswitch.com/support/mailing-lists.html 
to be removed from this list.

An Archive of this list is available at:
http://www.mail-archive.com/imail_forum%40list.ipswitch.com/

Reply via email to