c# wrapper updates, etc.

This commit is contained in:
Jim Norman
2006-08-18 17:41:08 +00:00
parent 169e3a389d
commit 2ec99203a2
7 changed files with 98 additions and 93 deletions

View File

@@ -6,15 +6,14 @@ using System.Runtime.CompilerServices;
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyTitle("AuthToken Wrapper")]
[assembly: AssemblyDescription("C# Wrapper for Authentication Tokens")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCompany("Novell, Inc")]
[assembly: AssemblyProduct("CASA")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// Version information for an assembly consists of the following four values:
//
@@ -26,7 +25,7 @@ using System.Runtime.CompilerServices;
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.7.*")]
//
// In order to sign your assembly you must specify a key to use. Refer to the
@@ -54,5 +53,5 @@ using System.Runtime.CompilerServices;
// documentation for more information on this.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyFile("../../AuthToken.snk")]
[assembly: AssemblyKeyName("")]

View File

@@ -10,23 +10,21 @@ namespace Novell.Casa.Client.Auth
public class Authtoken
{
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,
IntPtr pToken,
[In, Out] ref int iTokenLength
[In, Out] byte[] baToken,
[In, Out] ref int iTokenLength
);
public Authtoken()
{
//
// TODO: Add constructor logic here
//
}
@@ -34,10 +32,8 @@ namespace Novell.Casa.Client.Auth
{
int rcode = 0;
byte[] baService = null;
byte[] baHost = null;
int bufferSize = 4096;
IntPtr pBuffer = Marshal.AllocHGlobal(bufferSize);
byte[] baHost = null;
int bufferSize = 0;
byte[] baToken = new byte[bufferSize];
@@ -56,45 +52,45 @@ namespace Novell.Casa.Client.Auth
{
baHost = Encoding.ASCII.GetBytes(sHost);
}
LogMessage("Calling Native API->ObtainAuthToken");
LogMessage("Buffer size is "+ bufferSize);
else
{
throw new Exception("Invalid parameter");
}
// call with buffersize of 0. This way we determine the exact size.
try
{
rcode = ObtainAuthToken(baService, baHost, pBuffer, ref bufferSize);
rcode = ObtainAuthToken(baService, baHost, baToken, ref bufferSize);
int test = (rcode & BUFFER_OVERFLOW);
if (test == BUFFER_OVERFLOW)
{
// now allocate the proper size
baToken = new byte[bufferSize];
rcode = ObtainAuthToken(baService, baHost, baToken, ref bufferSize);
}
}
catch (Exception e)
{
LogMessage(e.ToString());
return null;
}
LogMessage("ObtainAuthToken returned " + rcode);
if (rcode != 0)
{
Marshal.FreeHGlobal(pBuffer);
{
throw new Exception(rcode.ToString());
}
else
{
// marshal the IntPtr into a byte array
String sTemp = Marshal.PtrToStringAnsi(pBuffer, bufferSize);
Marshal.FreeHGlobal(pBuffer);
return (Encoding.ASCII.GetBytes(sTemp));
}
return null;
return baToken;
}
}
private static void LogMessage(string sMessage)
{
System.Diagnostics.Trace.WriteLine("(C#)AuthToken: " + sMessage);
}
}
}

View File

@@ -76,7 +76,7 @@
/>
<Reference
Name = "System.XML"
AssemblyName = "System.XML"
AssemblyName = "System.Xml"
HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll"
/>
</References>