0

我有一个正在升级的小型部署工具。该工具从构建框中获取一个版本的代码,更新 SVN,然后将其放在 X 服务器上(部署将部署安装的特定部分移动到堆栈中的不同服务器)。

现在发生的情况是,当它在我们的构建盒之外的任何东西上运行时,由于安全性,它不会工作。

我们的构建框是内部的并且在我们自己的域中。我们要复制到的服务器位于高安全域上。我使用了这里解释的技术:Accessing Password Protected Network Drives in Windows in C#? 用于访问那些域驱动器上的文件/数据,所以我不需要映射它。

但这就是问题所在。

构建框 - 域 A

部署服务器 - 域 B 部署服务器 2 - 域 B

我的盒子可以完全控制我们的 Build Box,因为开发人员以管理员身份运行,并且它在我们的域中。但是,一旦我冒充我的登录名进入域 B,我就无法访问我的域 A 构建框。

这是一个内部实用程序,任何帮助将不胜感激。

*如果在这方面有大量工作而不是复制,我可以打开新线程并运行命令行以从每台服务器上的 SVN获取这些文件,因为这是一种可能而不是复制。我们将所有部署安装文件保存在 SVN 中。

IntPtr token;
if (!Security.Access.LogonUser("ChuckNorris", "a_small_bunny[0]", "OfficeSpace", Security.Enums.LogonType.NewCredentials, Security.Enums.LogonProvider.Default, out token))
{
    throw new Win32Exception();
}

try
{
    IntPtr dToken;
    if (!Security.Access.DuplicateToken(token, Security.Enums.SecurityImpersonationLevel.Impersonation, out dToken))
        throw new Win32Exception();

    try
    {
        using (WindowsImpersonationContext iContext = new WindowsIdentity(dToken).Impersonate())
        {
            Directory.CreateDirectory(destDir); //Works Here as I have impersonation

            // copy each file to destination
     //This will bomb as my user is now linked to the prod domain.
            foreach (string file in Directory.GetFiles(srcDir))
            {
                // update property bag
                UpdatePropertyBag(
                    propertyBag,
                    PropertyBag.Step,
                    "Copying [" + file + "] to [" + destDir + "]");

                // copy each file
                File.Copy(file, CombinePath(destDir, Path.GetFileName(file)));
            }

            // deal with each file/folder
            foreach (string dir in Directory.GetDirectories(srcDir))
            {
                // copy each subdirectory
                CopyDirectory(propertyBag, srcDir, destDir, Path.GetFileName(dir));
            }

            iContext.Undo();
        }
    }
    catch (Exception ex)
    {
    }
    finally
    {
        if (dToken != IntPtr.Zero)
        {
            if (!Security.Access.CloseHandle(dToken))
            {
                // Uncomment if you need to know this case.
                ////throw new Win32Exception();
            }
        }
    }
}
catch (Exception ex)
{
}
finally
{
    if (token != IntPtr.Zero)
    {
        if (!Security.Access.CloseHandle(token))
        {
            // Uncomment if you need to know this case.
            ////throw new Win32Exception();
        }
    }
}
4

1 回答 1

0

我可能在上面的流程中遗漏了一些东西,但你能:

  1. 模拟域 A
  2. 复制到具有两个域权限的共享位置。
  3. 模拟域 b,移动到最终位置。其他选项是读取文件详细信息、加载到内存中、写入目的地并在必要时保留时间戳。
于 2011-10-26T16:45:48.733 回答