Support for DLU by allowing luid's to be passed by the system process.

This commit is contained in:
Jim Norman 2006-10-17 20:39:48 +00:00
parent 3f093e092d
commit 39fdc355c7
4 changed files with 103 additions and 9 deletions

View File

@ -36,15 +36,39 @@ namespace Novell.Casa.Client.Auth
private const string AUTH_LIBRARY = "C:\\Program Files\\Novell\\CASA\\lib\\authtoken";
private const int BUFFER_OVERFLOW = 6;
[DllImport(AUTH_LIBRARY, CharSet=CharSet.None) ]
public static extern int ObtainAuthToken
(
[In] byte[] baService,
[In] byte[] baHost,
[In, Out] byte[] baToken,
[In, Out] ref int iTokenLength
);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct LUID
{
public int luidLow;
public int luidHigh;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class SSCS_EXT_T
{
public int extID = 0; // defined to identify the extension
public int version = 0; // defined as the version of the specified extension
public IntPtr ext; // points to the actual extension
} ;
[DllImport(AUTH_LIBRARY, CharSet=CharSet.None) ]
private static extern int ObtainAuthToken
(
[In] byte[] baService,
[In] byte[] baHost,
[In, Out] byte[] baToken,
[In, Out] ref int iTokenLength
);
[DllImport(AUTH_LIBRARY, CharSet=CharSet.None) ]
private static extern int ObtainAuthTokenEx
(
[In] byte[] baService,
[In] byte[] baHost,
[In, Out] byte[] baToken,
[In, Out] ref int iTokenLength,
[In] SSCS_EXT_T ext
);
public Authtoken()
@ -53,11 +77,17 @@ namespace Novell.Casa.Client.Auth
public static byte[] ObtainAuthToken(string sService, string sHost)
{
return ObtainAuthToken(sService, sHost, null);
}
public static byte[] ObtainAuthToken(string sService, string sHost, WinLuid luid)
{
int rcode = 0;
byte[] baService = null;
byte[] baHost = null;
int bufferSize = 0;
bool bLuidPassedIn = false;
byte[] baToken = new byte[bufferSize];
@ -81,11 +111,35 @@ namespace Novell.Casa.Client.Auth
throw new Exception("Invalid parameter");
}
SSCS_EXT_T ext = new SSCS_EXT_T();
if ((luid.GetHighPart() != 0) || (luid.GetLowPart() != 0))
{
// allocate a structure to marshal
LUID sluid = new LUID();
sluid.luidHigh = luid.GetHighPart();
sluid.luidLow = luid.GetLowPart();
ext.extID = 1;
ext.version = 1;
ext.ext = Marshal.AllocHGlobal(Marshal.SizeOf(sluid));
Marshal.StructureToPtr(sluid, ext.ext, false);
bLuidPassedIn = true;
}
// call with buffersize of 0. This way we determine the exact size.
try
{
rcode = ObtainAuthToken(baService, baHost, baToken, ref bufferSize);
if (bLuidPassedIn)
{
rcode = ObtainAuthTokenEx(baService, baHost, baToken, ref bufferSize, ext);
}
else
{
rcode = ObtainAuthToken(baService, baHost, baToken, ref bufferSize);
}
int test = (rcode & BUFFER_OVERFLOW);
if (test == BUFFER_OVERFLOW)
@ -101,6 +155,8 @@ namespace Novell.Casa.Client.Auth
return null;
}
if (ext.ext != IntPtr.Zero)
Marshal.FreeHGlobal(ext.ext);
if (rcode != 0)
{

View File

@ -93,6 +93,11 @@
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "WinLuid.cs"
SubType = "Code"
BuildAction = "Compile"
/>
</Include>
</Files>
</CSHARP>

View File

@ -0,0 +1,29 @@
using System;
namespace Novell.Casa.Client.Auth
{
/// <summary>
/// Summary description for WinLuid.
/// </summary>
public class WinLuid
{
private int m_low = 0;
private int m_high = 0;
public WinLuid(int lowPart, int highPart )
{
m_low = lowPart;
m_high = highPart;
}
public int GetLowPart()
{
return m_low;
}
public int GetHighPart()
{
return m_high;
}
}
}

View File

@ -48,6 +48,10 @@ namespace TestClientAuth
try
{
WinLuid luid = new WinLuid(1234, 5678);
Authtoken.ObtainAuthToken("testService", args[0], luid);
byte[] baToken = Authtoken.ObtainAuthToken("testService", args[0]);
Console.WriteLine("Token returned: ("+ baToken.Length + ")");
for (int i=0; i<baToken.Length; i++)