Chris Crowe's Blog
Ramblings of an IIS MVP ( MVP Since 1997 )

Powered By IIS 7

Search my blog

Some of my readers



My Microsoft Certifications


Dec 15, 1998

Dec 20, 2000

Jan 31, 2001

Jul 22, 2002

Nov 1, 2004

My Microsoft MVP Awards




1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
mvp.support.microsoft.com

February 2006 Entries

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....

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.

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 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