Revision: 68
http://svn.sourceforge.net/nmailserver/?rev=68&view=rev
Author: tmyroadctfig
Date: 2006-10-31 01:24:33 -0800 (Tue, 31 Oct 2006)
Log Message:
-----------
Added a project for an Outlook plugin. Other project file changes.
Modified Paths:
--------------
NMail/branches/luke-dev/NMail.LocalStoreData.MySql/NMail.LocalStoreData.MySql.csproj
NMail/branches/luke-dev/NMail.Server.Console/NMail.config
NMail/branches/luke-dev/NMail.SpoolData.MySql/NMail.SpoolData.MySql.csproj
Added Paths:
-----------
NMail/branches/luke-dev/NMail/Authentication/ILockOutPolicy.cs
NMail/branches/luke-dev/NMail.LocalStoreData.MySql/MySqlAuthProvider.cs
NMail/branches/luke-dev/NMail.LocalStoreData.MySql/MySqlHelper.cs
NMail/branches/luke-dev/NMail.LocalStoreData.MySql/MySqlUserMap.cs
NMail/branches/luke-dev/NMail.OutlookPlugin/
NMail/branches/luke-dev/NMail.OutlookPlugin/NMail.OutlookPlugin.csproj
NMail/branches/luke-dev/NMail.OutlookPlugin/Properties/
NMail/branches/luke-dev/NMail.OutlookPlugin/Properties/AssemblyInfo.cs
Added: NMail/branches/luke-dev/NMail/Authentication/ILockOutPolicy.cs
===================================================================
--- NMail/branches/luke-dev/NMail/Authentication/ILockOutPolicy.cs (rev 0)
+++ NMail/branches/luke-dev/NMail/Authentication/ILockOutPolicy.cs 2006-10-31 09:24:33 UTC (rev 68)
@@ -0,0 +1,8 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace NMail.Authentication {
+ public interface ILockOutPolicy {
+ }
+}
Added: NMail/branches/luke-dev/NMail.LocalStoreData.MySql/MySqlAuthProvider.cs
===================================================================
--- NMail/branches/luke-dev/NMail.LocalStoreData.MySql/MySqlAuthProvider.cs (rev 0)
+++ NMail/branches/luke-dev/NMail.LocalStoreData.MySql/MySqlAuthProvider.cs 2006-10-31 09:24:33 UTC (rev 68)
@@ -0,0 +1,233 @@
+/*
+ * Copyright 2004-2006 Luke Quinane
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Security.Cryptography;
+using System.Text;
+
+using Mono.Security.Protocol.Ntlm;
+using MySql.Data.MySqlClient;
+
+using NMail.Authentication;
+using NMail.Configuration;
+using NMail.LocalStoreData.MySql.Configuration;
+
+// TODO: account lockout if too many bad attempts
+
+namespace NMail.LocalStoreData.MySql {
+ public class MySqlAuthProvider : MarshalByRefObject, IHashAuthProvider {
+
+ /// <summary>
+ /// A map of username to tokens.
+ /// </summary>
+ Dictionary<string, Dictionary<Guid, BasicAuthToken>> currentTokens = new Dictionary<string, Dictionary<Guid, BasicAuthToken>>();
+
+ private void purgeExpiredTokens() {
+ // TODO: implement!!!
+ }
+
+ private void addToCurrentTokens(BasicAuthToken authToken) {
+ // Ensure the user has a token dictionary
+ if (!this.currentTokens.ContainsKey(authToken.Username)) {
+ this.currentTokens.Add(authToken.Username, new Dictionary<Guid, BasicAuthToken>());
+ }
+
+ this.currentTokens[authToken.Username].Add(authToken.TokenId, authToken);
+
+ purgeExpiredTokens();
+ }
+
+ private IAuthenticationToken createValidatedToken(string username, bool disabled, DateTime passwordExpiry) {
+ // TODO: lockout check
+
+ // Check if the password is correct and the account is not disabled, etc
+ if (!disabled) {
+ DateTime expiry = (DateTime.Now + DefaultTokenExpiry > passwordExpiry)
+ ? DateTime.Now + DefaultTokenExpiry
+ : passwordExpiry;
+
+ BasicAuthToken token = new BasicAuthToken(username, passwordExpiry, expiry);
+ addToCurrentTokens(token);
+ return token;
+ }
+
+ return null;
+ }
+
+ #region IAuthenticationProvider
+
+ public DateTime GetTokenExpiry(IAuthenticationToken user) {
+ // Only basic tokens are valid
+ BasicAuthToken authToken = user as BasicAuthToken;
+
+ if (authToken != null && this.currentTokens.ContainsKey(authToken.Username)) {
+ Dictionary<Guid, BasicAuthToken> userTokens = this.currentTokens[authToken.Username];
+
+ if (userTokens.ContainsKey(authToken.TokenId)) {
+ // Don't trust the passed in expiry - we don't know where it has been!
+ return userTokens[authToken.TokenId].CredentialsExpiry;
+ }
+ }
+
+ // Invalid token
+ return DateTime.MinValue;
+ }
+
+ public bool TokenExpired(IAuthenticationToken user) {
+ return (GetTokenExpiry(user) > DateTime.Now);
+ }
+
+ public bool ValidToken(IAuthenticationToken user) {
+ // This also checks if the token is valid as well as not expired
+ return !TokenExpired(user);
+ }
+
+ public bool IsLockedOut(IAuthenticationToken user) {
+ // TODO: fix this!
+ return false;
+ }
+
+ public bool IsEnabled(IAuthenticationToken user) {
+ using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ using (MySqlCommand cmd = cnn.CreateCommand()) {
+ cmd.CommandText = "SELECT Disabled FROM `User` WHERE Username = ?Username";
+ cmd.Parameters.Add("Username", user.Username);
+ object o = cmd.ExecuteNonQuery();
+
+ bool disabled = true;
+
+ if (o is bool) {
+ disabled = (bool) o;
+ }
+
+ return (!disabled);
+ }
+ }
+ }
+
+ public bool ChangePassword(IAuthenticationToken user, string newPassword) {
+ using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ using (MySqlCommand cmd = cnn.CreateCommand()) {
+ cmd.CommandText = "UPDATE `User` SET Password = ?Password WHERE Username = ?Username";
+ cmd.Parameters.Add("Username", user.Username);
+ cmd.Parameters.Add("Password", newPassword);
+ int count = cmd.ExecuteNonQuery();
+
+ return (count == 1);
+ }
+ }
+ }
+
+ public void ResetLockOut(string username) {
+ throw new Exception("The method or operation is not implemented.");
+ }
+
+ public void SetEnabled(string username, bool enabled) {
+ using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ using (MySqlCommand cmd = cnn.CreateCommand()) {
+ cmd.CommandText = "UPDATE `User` SET Disabled = ?Disabled WHERE Username = ?Username";
+ cmd.Parameters.Add("Username", username);
+ cmd.Parameters.Add("Disabled", !enabled);
+ int count = cmd.ExecuteNonQuery();
+ }
+ }
+ }
+
+ public IAuthenticationToken Authenticate(string username, string password) {
+ // Get the hash stored in the database.
+ using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ using (MySqlCommand cmd = cnn.CreateCommand()) {
+ cmd.CommandText = "SELECT Disabled, LockedOutData, PasswordExpiry, Password FROM User WHERE Username = ?Username";
+ cmd.Parameters.Add("Username", username);
+ MySqlDataReader reader = cmd.ExecuteReader();
+
+ if (reader.Read()) {
+ string dbHash = reader["Password"] as string;
+ bool disabled = (bool) reader["Disabled"];
+ DateTime passwordExpiry = (DateTime) reader["PasswordExpiry"];
+
+ return createValidatedToken(username, disabled, passwordExpiry);
+ }
+ }
+ }
+
+ // Hashes do not match or no such user
+ return null;
+ }
+
+ public IAuthenticationToken CreateAuthToken(string username) {
+ // Get the hash stored in the database.
+ using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ using (MySqlCommand cmd = cnn.CreateCommand()) {
+ cmd.CommandText = "SELECT COUNT(*) FROM User WHERE Username = ?Username";
+ cmd.Parameters.Add("Username", username);
+ long count = (long) cmd.ExecuteScalar();
+
+ if (count == 1) {
+ return createValidatedToken(username, false, DateTime.MaxValue);
+ }
+ }
+ }
+
+ // No such user
+ return null;
+ }
+ #endregion
+
+ #region IHashAuthProvider Members
+
+ public IAuthenticationToken Authenticate(string username, string hash, HashAuthType authType) {
+ if ((authType & HashAuthType.Ntlm) == HashAuthType.Ntlm) {
+ // Get the hash stored in the database.
+ using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ using (MySqlCommand cmd = cnn.CreateCommand()) {
+ cmd.CommandText = "SELECT Disabled, LockedOutData, PasswordExpiry, Password FROM User WHERE Username = ?Username";
+ cmd.Parameters.Add("Username", username);
+ MySqlDataReader reader = cmd.ExecuteReader();
+
+ if (reader.Read()) {
+ string dbPassword = reader["Password"] as string;
+ bool disabled = (bool) reader["Disabled"];
+ DateTime passwordExpiry = (DateTime) reader["PasswordExpiry"];
+
+ // Generate a NTLM hash
+ Type3Message type3Msg = new Type3Message();
+ type3Msg.Password = dbPassword;
+ string dbHash = Convert.ToBase64String(type3Msg.NT);
+
+ if (dbHash == hash) {
+ // Hashes match, return a valid token
+ return createValidatedToken(username, disabled, passwordExpiry);
+ }
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ public HashAuthType HashAuthType {
+ get { return HashAuthType.Ntlm; }
+ }
+
+ #endregion
+
+ public static readonly TimeSpan DefaultTokenExpiry = TimeSpan.FromMinutes(30);
+ }
+}
Added: NMail/branches/luke-dev/NMail.LocalStoreData.MySql/MySqlHelper.cs
===================================================================
--- NMail/branches/luke-dev/NMail.LocalStoreData.MySql/MySqlHelper.cs (rev 0)
+++ NMail/branches/luke-dev/NMail.LocalStoreData.MySql/MySqlHelper.cs 2006-10-31 09:24:33 UTC (rev 68)
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using MySql.Data.MySqlClient;
+
+using NMail.LocalStoreData.MySql.Configuration;
+
+namespace NMail.LocalStoreData.MySql {
+ internal static class MySqlHelper {
+ internal static MySqlConnection GetConnection() {
+ MySqlConnection cnn = new MySqlConnection(MySqlLocalStoreDataConfiguration.Current.ConnectionString);
+ cnn.Open();
+ return cnn;
+ }
+ }
+}
Added: NMail/branches/luke-dev/NMail.LocalStoreData.MySql/MySqlUserMap.cs
===================================================================
--- NMail/branches/luke-dev/NMail.LocalStoreData.MySql/MySqlUserMap.cs (rev 0)
+++ NMail/branches/luke-dev/NMail.LocalStoreData.MySql/MySqlUserMap.cs 2006-10-31 09:24:33 UTC (rev 68)
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2004-2006 Luke Quinane
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using MySql.Data.MySqlClient;
+
+using NMail.Configuration;
+using NMail.DataTypes;
+using NMail.DataTypes.LocalStore;
+
+namespace NMail.LocalStoreData.MySql {
+ [Serializable]
+ public class MySqlUserMap : ILocalStoreUserMap {
+
+ protected ILocalStoreData LocalStoreData {
+ get {
+ return NMailConfiguration.Current.LocalStoreData;
+ }
+ }
+
+ #region ILocalStoreUserMap Members
+ /// <summary>
+ /// Maps the given mailbox to a user.
+ /// </summary>
+ /// <param name="mailbox">The mailbox to map.</param>
+ /// <returns>The user or null.</returns>
+ public LocalStoreUser MapMailboxToUser(string mailbox) {
+ using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ using (MySqlCommand cmd = cnn.CreateCommand()) {
+ // First check if the username matches the mailbox
+ cmd.CommandText = "SELECT u.UserId FROM User u WHERE u.Username LIKE ?Mailbox";
+ cmd.Parameters.Add("Mailbox", mailbox);
+ object o = cmd.ExecuteScalar();
+
+ if (o is int) {
+ return this.LocalStoreData.GetUser((int) o);
+ }
+
+ // Next check if the mailbox maps to a user
+ cmd.CommandText = "SELECT u.UserId FROM User u, MailboxMapping m WHERE u.UserId = m.UserId AND m.Mailbox LIKE ?Mailbox";
+ cmd.Parameters.Add("Mailbox", mailbox);
+ o = cmd.ExecuteScalar();
+
+ if (o is int) {
+ return this.LocalStoreData.GetUser((int) o);
+ }
+
+ // No such mailbox
+ return null;
+ }
+ }
+ }
+
+ public Mailbox[] GetUserMailboxes(string username) {
+ using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
+ using (MySqlCommand cmd = cnn.CreateCommand()) {
+ cmd.CommandText = "SELECT m.Mailbox FROM User u, MailboxMapping m WHERE u.UserId = m.UserId AND u.Username LIKE ?Username";
+ cmd.Parameters.Add("Username", username);
+
+ using (MySqlDataReader reader = cmd.ExecuteReader()) {
+ List<Mailbox> mailboxes = new List<Mailbox>();
+
+ while (reader.Read()) {
+ string mailboxName = (string) reader["Mailbox"];
+ mailboxes.Add(new Mailbox(mailboxName));
+ }
+
+ return mailboxes.ToArray();
+ }
+ }
+ }
+ }
+
+ public void AddUserMailbox(string username, Mailbox mailbox) {
+ throw new NotImplementedException();
+ }
+
+ public void RemoveUserMailbox(string username, Mailbox mailbox) {
+ throw new NotImplementedException();
+ }
+ #endregion
+ }
+}
Modified: NMail/branches/luke-dev/NMail.LocalStoreData.MySql/NMail.LocalStoreData.MySql.csproj
===================================================================
--- NMail/branches/luke-dev/NMail.LocalStoreData.MySql/NMail.LocalStoreData.MySql.csproj 2006-10-31 09:22:41 UTC (rev 67)
+++ NMail/branches/luke-dev/NMail.LocalStoreData.MySql/NMail.LocalStoreData.MySql.csproj 2006-10-31 09:24:33 UTC (rev 68)
@@ -111,7 +111,9 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="MySqlUserMap.cs" />
- <Content Include="MySqlLocalStore.sql" />
+ <Content Include="MySqlLocalStore.sql">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </Content>
<Content Include="NMail.LocalStoreData.Mysql.build" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
Added: NMail/branches/luke-dev/NMail.OutlookPlugin/NMail.OutlookPlugin.csproj
===================================================================
--- NMail/branches/luke-dev/NMail.OutlookPlugin/NMail.OutlookPlugin.csproj (rev 0)
+++ NMail/branches/luke-dev/NMail.OutlookPlugin/NMail.OutlookPlugin.csproj 2006-10-31 09:24:33 UTC (rev 68)
@@ -0,0 +1,65 @@
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.50727</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{9080FAD0-0BD8-4CA2-A645-9F2198C38CFE}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>NMail.OutlookPlugin</RootNamespace>
+ <AssemblyName>NMail.OutlookPlugin</AssemblyName>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>..\References\NMail\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>..\References\NMail\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Class1.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <COMReference Include="Microsoft.Office.Core">
+ <Guid>{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}</Guid>
+ <VersionMajor>2</VersionMajor>
+ <VersionMinor>3</VersionMinor>
+ <Lcid>0</Lcid>
+ <WrapperTool>primary</WrapperTool>
+ <Isolated>False</Isolated>
+ </COMReference>
+ <COMReference Include="Outlook">
+ <Guid>{00062FFF-0000-0000-C000-000000000046}</Guid>
+ <VersionMajor>9</VersionMajor>
+ <VersionMinor>2</VersionMinor>
+ <Lcid>0</Lcid>
+ <WrapperTool>primary</WrapperTool>
+ <Isolated>False</Isolated>
+ </COMReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
\ No newline at end of file
Added: NMail/branches/luke-dev/NMail.OutlookPlugin/Properties/AssemblyInfo.cs
===================================================================
--- NMail/branches/luke-dev/NMail.OutlookPlugin/Properties/AssemblyInfo.cs (rev 0)
+++ NMail/branches/luke-dev/NMail.OutlookPlugin/Properties/AssemblyInfo.cs 2006-10-31 09:24:33 UTC (rev 68)
@@ -0,0 +1,35 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("NMail.OutlookPlugin")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("NMail.OutlookPlugin")]
+[assembly: AssemblyCopyright("Copyright © 2006")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("6ec6c56a-8925-4e4e-9f93-e07309b0e646")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers
+// by using the '*' as shown below:
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
Modified: NMail/branches/luke-dev/NMail.Server.Console/NMail.config
===================================================================
--- NMail/branches/luke-dev/NMail.Server.Console/NMail.config 2006-10-31 09:22:41 UTC (rev 67)
+++ NMail/branches/luke-dev/NMail.Server.Console/NMail.config 2006-10-31 09:24:33 UTC (rev 68)
@@ -10,7 +10,6 @@
<section name="NMail.SpoolFilterService" type="NMail.SpoolFilter.Configuration.SpoolFilterServiceConfiguration, NMail.SpoolFilter" />
<section name="NMail.SpoolData.MySql" type="NMail.SpoolData.MySql.Configuration.MySqlSpoolDataConfiguration, NMail.SpoolData.MySql" />
<section name="NMail.MessageRouter" type="NMail.MessageRouter.Configuration.MessageRouterConfiguration, NMail.MessageRouter" />
- <section name="NMail.LocalStore" type="NMail.LocalStore.Configuration.LocalStoreConfiguration, NMail.LocalStore" />
<section name="NMail.LocalStoreData.MySql" type="NMail.LocalStoreData.MySql.Configuration.MySqlLocalStoreDataConfiguration, NMail.LocalStoreData.MySql" />
</configSections>
Modified: NMail/branches/luke-dev/NMail.SpoolData.MySql/NMail.SpoolData.MySql.csproj
===================================================================
--- NMail/branches/luke-dev/NMail.SpoolData.MySql/NMail.SpoolData.MySql.csproj 2006-10-31 09:22:41 UTC (rev 67)
+++ NMail/branches/luke-dev/NMail.SpoolData.MySql/NMail.SpoolData.MySql.csproj 2006-10-31 09:24:33 UTC (rev 68)
@@ -108,7 +108,9 @@
<Compile Include="MySqlSpoolData.cs">
<SubType>Code</SubType>
</Compile>
- <Content Include="MySqlSpoolData.sql" />
+ <Content Include="MySqlSpoolData.sql">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </Content>
<Content Include="NMail.SpoolData.MySql.build" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|