WSS 数据库表中的 UserInfo 表中的 tp_SystemId 字段的使用


在 WSS 的数据库中,UserInfo表的 tp_SystemId 记录的是用户登录验证时需要用到的数据,是此用户在 AD( Active Directory ) 中的 SID( Security ID )。此字段的数据很重要,不小心改动的话,此用户将不能登录 WSS。

这里介绍一下如何修复 tp_SystemID 字段。
假设不能登录的用户叫 nt_user( UserInfo表中的 tp_Login 字段的值应该为 <Domain>\nt_user )。

  1. 在 AD 中找到此用户
       string stPath = "LDAP://" + System.Environment.UserDomainName;
         string stFilter = "(&(sAMAccountname=nt_user)(objectclass=user))";
       DirectoryEntry userEntry 
    = null;

       DirectoryEntry dirEntry 
    = new DirectoryEntry( stPath );

       
    // Create a DirectorySearcher object
       DirectorySearcher searcher = new DirectorySearcher( dirEntry );
       searcher.SearchScope 
    = SearchScope.Subtree;
       searcher.Filter 
    = stFilter;
       searcher.PropertiesToLoad.Add( 
    "objectSID" );

       
    // Analyse the results
       SearchResultCollection results = searcher.FindAll();
       Console.WriteLine( 
    "Search result count: {0}", results.Count );
       if( results.Count>0 )
       
    {
          userEntry 
    = results[0].GetDirectoryEntry();
       }

       
    else
       
    {
          
    // Can not find the user.
       }
  2. 获取此用户的 SID 值
    用户的 SID 值可以用 objectSID 属性获取。
        byte [] sid = userEntry.Properties["objectSID"].Value as byte[];
        
    string stSID = BytesToHexString( sid );

        
    public static string BytesToHexString( byte [] bytes )
        
    {
            System.Text.StringBuilder hexString 
    = new System.Text.StringBuilder();
            
    forint counter=0; counter<bytes.Length; counter++ )
                hexString.AppendFormat( 
    "{0:x2}", bytes[counter] );
        }
  3. 更新 UserInfo 表
    打开查询分析器或自己写程序可以直接更新 WSS 数据库表 UserInfo 的 tp_SystemID 字段的值。
  4. 在浏览器中再次访问 WSS 网站,用户就可以成功登录了!

posted on 2004-09-16 16:44  Liner  阅读(1405)  评论(1编辑  收藏  举报

导航