November 2010 (1)
August 2010 (1)
July 2010 (1)
June 2010 (3)
July 2009 (3)
June 2009 (1)
May 2009 (1)
February 2009 (1)
January 2009 (1)
November 2008 (3)
October 2008 (4)
September 2008 (9)
August 2008 (6)
July 2008 (3)
June 2008 (3)
January 2008 (1)
November 2007 (2)
October 2007 (6)
September 2007 (5)
August 2007 (22)
July 2007 (6)
June 2007 (1)
May 2007 (3)
April 2007 (27)
March 2007 (8)
February 2007 (6)
September 2006 (2)
August 2006 (4)
July 2006 (9)
June 2006 (17)
May 2006 (20)
April 2006 (12)
March 2006 (9)
February 2006 (4)
January 2006 (3)
December 2005 (2)
November 2005 (4)
October 2005 (5)
September 2005 (37)
August 2005 (83)
July 2005 (6)

Active Directory / LDAP (0)
ASP.Net (19)
Blackberry Development (4)
c# (34)
c++ (3)
Code Camp (1)
Excel (1)
Exchange (3)
Front Page 2003 (6)
FTP User Editor (4)
HTML / CSS / DHTML (8)
IIS (146)
IIS - Log Parser (7)
IIS / FTP (12)
IIS / Tools / Administration (42)
IIS / Tools / Authentication (6)
IIS / Tools / Compression (8)
IIS / Tools / Crash & Hang (12)
IIS / Tools / ISAPI Filters (17)
IIS / Tools / Log Files (17)
IIS / Tools / Scripts (28)
IIS / Tools / Security (9)
IIS / Tools / SSL (6)
IIS 7 (3)
Internet Information Server (1)
Me (Chris Crowe) (6)
MIME Types (1)
Misc (72)
Oulook Express (2)
Silverlight (1)
SQL Server (27)
SQL Server CTE (1)
Vista (15)
Vista Gadgets (8)
Visual Studio (11)
Voice over BroadBand (1)
Windows (33)
Windows Powershell (3)
Windows Sharepoint Services (0)
Windows Sharepoint Services (15)
Windows Vista (14)
Wine Cellar (1)
WMI (8)

Archive

February 2006 (4)

Interesting Active Directory Attribute : drink

I tried to edit this attribute for my AD Account at work but it didn't want to play! Pity I was going to populate it with Gin, Wine, Single Malt....


C# application to show the WWW and FTP Sites and their log file directories....

I often look at the log files on my web server and with IIS 6 the folders are created with random numbers.

Correction from Tom regarding the “random numbers“:

In fact the log file names are generated from the site name so that in cases where a site is run on multiple servers the site id will be the same on each server. This helps with scripting and stuff. You can configure it in the registry to use the IIS5 type naming format if you want.

More details can be found below:

This simple application will display the WWW and FTP sites along with the log file directory. Just compile
it up or download the executable and drop the executable into your c:\windows\system32\logfiles folder and
just dblclick on it when you need to view the sites to folders relationships.



using System;
using System.DirectoryServices;
using System.IO;
using System.Collections;
using System.Windows.Forms;
namespace IISHelpDir
{
    /// 
    /// Summary description for Class1.
    /// 
    class Class1
    {
        /// 
        /// The main entry point for the application.
        /// 
        [STAThread]
        static void Main(string[] args)
        {
            SortedList www = new SortedList();
            SortedList ftp = new SortedList();
            try
            {
                const string FtpServerSchema = "IIsFtpServer"; // Case Sensitive
                const string WebServerSchema = "IIsWebServer"; // Case Sensitive
                string ServerName = "LocalHost";
                DirectoryEntry W3SVC = new DirectoryEntry("IIS://" + ServerName + "/w3svc");
                foreach (DirectoryEntry Site in W3SVC.Children) 
                {
                    if (Site.SchemaClassName == WebServerSchema) 
                    {
                        string LogFilePath = System.IO.Path.Combine(
                            Site.Properties["LogFileDirectory"].Value.ToString(),
                            "W3CSVC"+Site.Name);
                        www.Add(Site.Properties["ServerComment"].Value.ToString(), LogFilePath);
                    }
                }
    
                DirectoryEntry MSFTPSVC = new DirectoryEntry("IIS://" + ServerName + "/msftpsvc");
                foreach (DirectoryEntry Site in MSFTPSVC.Children) 
                {
                    if (Site.SchemaClassName == FtpServerSchema) 
                    {
                        string LogFilePath = System.IO.Path.Combine(
                            Site.Properties["LogFileDirectory"].Value.ToString(), 
                            "MSFTPSVC"+Site.Name);
                        ftp.Add(Site.Properties["ServerComment"].Value.ToString(), LogFilePath);
                    }
                }
                int MaxWidth = 0;
                foreach(string Site in www.Keys)
                {
                    if (Site.Length > MaxWidth)
                        MaxWidth = Site.Length;
                }
                foreach(string Site in ftp.Keys)
                {
                    if (Site.Length > MaxWidth)
                        MaxWidth = Site.Length;
                }
                Console.WriteLine("Site Description".PadRight(MaxWidth)+"  Log File Directory");
                Console.WriteLine("".PadRight(79,'='));
                Console.WriteLine();
                Console.WriteLine("WWW Sites");
                Console.WriteLine("=========");
                foreach(string Site in www.Keys)
                {
                    Console.WriteLine(Site.PadRight(MaxWidth) + "  " + www[Site]);
                }                
                if (ftp.Keys.Count > 0)
                {
                    Console.WriteLine();
                    Console.WriteLine("FTP Sites");
                    Console.WriteLine("=========");
                    foreach(string Site in ftp.Keys)
                    {
                        Console.WriteLine(Site.PadRight(MaxWidth) + "  " + ftp[Site]);
                    }                
                }
            }
                // Catch any errors
            catch (Exception e) 
            {
                Console.WriteLine("Error: " + e.ToString());
            }
            finally
            {
                Console.WriteLine();
                Console.WriteLine("Press enter to close/exit....");
                Console.Read();
            }
        }
    }
}

To download a ZIP file containing the c# source and executable (.Net 1.1) please click here.


SQL Script to return user accounts and the roles they are assigned to...

This script will return a list of all logins that are in use on the current database and also the creation date and modified date of the user. Also the roles that they are assigned to are also returned.

This can be useful to companies who must audit their SQL server databases for SOX compliance.

Example Output:

Name Creation Date Last Modified Account Type Roles
domain\is 4-Aug-04 16:04:57 4-Aug-04 16:04:57 Windows Account db_datareader
dbo 6-Aug-00 1:27:55 6-Aug-00 1:27:55 SQL Server User db_owner
guest 6-Aug-00 1:27:55 9-Jul-01 11:39:31 SQL Server User db_datareader
LandSurveyRead 19-Jul-04 9:59:56 19-Jul-04 9:59:56 SQL Server User db_datareader
Phonebook 2-Aug-05 12:44:59 2-Aug-05 12:44:59 SQL Server User  
scobb 6-Oct-04 10:20:45 6-Oct-04 10:20:45 SQL Server User db_datareader
Requests 18-Feb-04 8:52:33 18-Feb-04 8:54:30 SQL Server User db_datareader, db_datawriter, db_owner
UserInformationRead 13-Feb-04 9:04:17 13-Feb-04 9:04:17 SQL Server User db_owner
UserInformationWrite 10-Aug-04 8:55:55 10-Aug-04 8:55:55 SQL Server User db_owner


-- Process
--     Create Temp Table for Users
--    Create Temp Table for Roles
--    Populate Users
--    Populate Roles
--    Iterate though each user and update their roles into a single column
--    Return the users and their roles
Create Table #Temp_Users
(
    Name             varchar(128),
    CreateDate        datetime,
    LastModifiedDate    datetime,
    LoginType        varchar(50),
    Roles            varchar(1024)
)
Create Table #Temp_Roles ( Name varchar(128), Role varchar(128) )
insert into #Temp_Users select Name, [Create Date] = CreateDate, [Last Modified Date] = UpdateDate, LoginType = case when IsNTName = 1 then 'Windows Account' when IsNTGroup = 1 then 'Windows Group' when isSqlUser = 1 then 'SQL Server User' when isAliased =1 then 'Aliased' when isSQLRole = 1 then 'SQL Role' when isAppRole = 1 then 'Application Role' else 'Unknown' end, Roles = '' from sysusers where SID is not null order by Name
insert into #Temp_Roles select MemberName = u.name, DbRole = g.name from sysusers u, sysusers g, sysmembers m where g.uid = m.groupuid and g.issqlrole = 1 and u.uid = m.memberuid order by 1, 2


Declare
@Name varchar(128) Declare @Roles varchar(1024) Declare @Role varchar(128)
DECLARE UserCursor CURSOR for SELECT name from #Temp_Users OPEN UserCursor FETCH NEXT FROM UserCursor into @Name WHILE @@FETCH_STATUS = 0 BEGIN set @Roles = '' print @Name DECLARE RoleCursor CURSOR for SELECT Role from #Temp_Roles where Name = @Name OPEN RoleCursor FETCH NEXT FROM RoleCursor into @Role WHILE @@FETCH_STATUS = 0 BEGIN if (@Roles > '') set @Roles = @Roles + ', '+@Role else set @Roles = @Role FETCH NEXT FROM RoleCursor into @Role end Close RoleCursor DEALLOCATE RoleCursor Update #Temp_Users set Roles = @Roles where Name = @Name FETCH NEXT FROM UserCursor into @Name END CLOSE UserCursor DEALLOCATE UserCursor
select * from #Temp_Users
drop table #Temp_Users drop table #Temp_Roles

FTP User Account Editor for Active Directory

FTP User Editor for Microsoft Active Directory.....

What is this?

When you run the FTP server with Microsoft IIS 6.0 on the Windows 2003 Server Family of products you can have the FTP server isolate users to their own folders. This means that the user can not browse into another users folder.

There are three isolation modes:

  1. Do not isolate users
  2. Isolate Users
  3. Isolate Users with Active Directory

This application is designed for option 3 and allows you to edit two attributes for a users account:

  • msIIS-FTPRoot
  • msIIS-FTPDir

For more details on these attributes see the following page.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adschema/adschema/a_msiis_ftproot.asp

There is no Windows UI to perform this step but there is a way to edit these attributes using the IISFTP.vbs script that is installed when you install IIS with the FTP Service in IIS 6.

The IISFTP.vbs script works fine but sometimes it is nicer and simpler to have a UI to help perform these steps. You also can see potential problems easier with a Windows UI.

The Application

This application has been written to in c# and requires the .NET Framework 2.0 (the new framework) to function. Windows 2003 Server Family by default installs the .NET Framework 1.1.

The .NET Framework 2.0 redistributable can be downloaded from this page and is approx 22MB

http://www.microsoft.com/downloads/details.aspx?FamilyID=0856EACB-4362-4B0D-8EDD-AAB15C5E04F5&displaylang=en

You can then download and install this application from the URL below.

http://blog.crowe.co.nz/Attachments/FTPUserEditor/setup.msi

After you install the program a new item will be added to your Start - Programs folder called IIS Tools.

When you run the application it will prompt you for a Windows Active Directory domain to log onto. You can log on with the currently logged on user account or you can specify another account to log on with.

Once you log on you are then shown a tree of Folders and Organizational Units (OUs). Click on a node will display all user accounts in that folder or OU.

You can select one or more users and right click and select Edit which will bring up the User Editor dialog.

This dialog allows you to set or clear the attributes that are required for users to log on to the FTP server.

If you have any comments on this application ( or bug reports ) please let me know at iismvp2005@iisfaq.homeip.net

Cheers

Chris Crowe [ IIS MVP 1997 -> 2006 ]
http://www.microsoft.com/windows2000/community/mvp/bios/crowe.mspx

Additional references

Hosting Multiple FTP Sites with FTP User Isolation (IIS 6.0)
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/b63de8ef-e3c5-456d-a8ca-7af4198819d4.mspx