From 11f501db439d9e47546604d6b54544bf04af9eae Mon Sep 17 00:00:00 2001 From: Juan Carlos Luciani Date: Mon, 4 Dec 2006 05:03:49 +0000 Subject: [PATCH] Fixed fix path issue in CasaAuthToken c-sharp library. --- .../Novell.Casa.Authtoken/Authtoken.cs | 255 +++++++++--------- .../client/lib/test/windows/test.vcproj | 9 +- .../client/lib/windows/client.vcproj | 4 +- .../authtokenclient_msm.vdproj | 40 ++- 4 files changed, 172 insertions(+), 136 deletions(-) diff --git a/CASA-auth-token/client/csharp-api/Novell.Casa.Authtoken/Authtoken.cs b/CASA-auth-token/client/csharp-api/Novell.Casa.Authtoken/Authtoken.cs index b71ea0d5..a4fe70f5 100644 --- a/CASA-auth-token/client/csharp-api/Novell.Casa.Authtoken/Authtoken.cs +++ b/CASA-auth-token/client/csharp-api/Novell.Casa.Authtoken/Authtoken.cs @@ -28,52 +28,52 @@ using System.Runtime.InteropServices; namespace Novell.Casa.Client.Auth { - /// - /// Summary description for Class1. - /// - public class Authtoken - { - private const string AUTH_LIBRARY = "C:\\Program Files\\Novell\\CASA\\lib\\authtoken"; - private const int BUFFER_OVERFLOW = 6; + /// + /// Summary description for Class1. + /// + public class Authtoken + { + private const string AUTH_LIBRARY = "casa_authtoken"; + private const int BUFFER_OVERFLOW = 6; - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - private struct LUID - { - public int luidLow; - public int luidHigh; - } + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + private 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 - } ; + [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 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 - ); + [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() - { - } + public Authtoken() + { + } public static string ObtainAuthTokenAsString(string sService, string sHost) { @@ -89,76 +89,77 @@ 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) + { + return ObtainAuthToken(sService, sHost, null); + } - private static byte[] ObtainAuthToken(string sService, string sHost, WinLuid luid) - { - int rcode = 0; - byte[] baService = null; - byte[] baHost = null; - int bufferSize = 0; - bool bLuidPassedIn = false; + private 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]; + byte[] baToken = new byte[bufferSize]; - // convert service to ascii byte array - if (sService != null) - { - baService = Encoding.ASCII.GetBytes(sService); - } - else - { - throw new Exception("Invalid parameter"); - } + // convert service to ascii byte array + if (sService != null) + { + baService = Encoding.ASCII.GetBytes(sService); + } + else + { + throw new Exception("Invalid parameter"); + } - // convert host to ascii byte array - if (sHost != null) - { - baHost = Encoding.ASCII.GetBytes(sHost); - } - else - { - throw new Exception("Invalid parameter"); - } - + // convert host to ascii byte array + if (sHost != null) + { + baHost = Encoding.ASCII.GetBytes(sHost); + } + else + { + throw new Exception("Invalid parameter"); + } + - SSCS_EXT_T ext = new SSCS_EXT_T(); - if ((luid != null) && (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)); + SSCS_EXT_T ext = new SSCS_EXT_T(); + LUID sluid; + if ((luid != null) && (luid.GetHighPart() != 0) || (luid.GetLowPart() != 0)) + { + // allocate a structure to marshal + 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; - } + Marshal.StructureToPtr(sluid, ext.ext, false); + bLuidPassedIn = true; + } - - // call with buffersize of 0. This way we determine the exact size. - try - { - 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) - { - // now allocate the proper size - baToken = new byte[bufferSize]; + + // call with buffersize of 0. This way we determine the exact size. + try + { + 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) + { + // now allocate the proper size + baToken = new byte[bufferSize]; if (bLuidPassedIn) { rcode = ObtainAuthTokenEx(baService, baHost, baToken, ref bufferSize, ext); @@ -167,30 +168,30 @@ namespace Novell.Casa.Client.Auth { rcode = ObtainAuthToken(baService, baHost, baToken, ref bufferSize); } - } - } - catch (Exception e) - { - LogMessage(e.ToString()); - return null; - } - - if (ext.ext != IntPtr.Zero) - Marshal.FreeHGlobal(ext.ext); + } + } + catch (Exception e) + { + LogMessage(e.ToString()); + return null; + } + + if (ext.ext != IntPtr.Zero) + Marshal.FreeHGlobal(ext.ext); - if (rcode != 0) - { - throw new Exception(rcode.ToString()); - } - else - { - return baToken; - } - } + if (rcode != 0) + { + throw new Exception(rcode.ToString()); + } + else + { + return baToken; + } + } - private static void LogMessage(string sMessage) - { - System.Diagnostics.Trace.WriteLine("(C#)AuthToken: " + sMessage); - } - } + private static void LogMessage(string sMessage) + { + System.Diagnostics.Trace.WriteLine("(C#)AuthToken: " + sMessage); + } + } } diff --git a/CASA-auth-token/client/lib/test/windows/test.vcproj b/CASA-auth-token/client/lib/test/windows/test.vcproj index b5edf9fd..61c810b9 100644 --- a/CASA-auth-token/client/lib/test/windows/test.vcproj +++ b/CASA-auth-token/client/lib/test/windows/test.vcproj @@ -4,6 +4,7 @@ Version="8.00" Name="test" ProjectGUID="{6034EBF1-0838-45C4-A538-A41A31EC8F46}" + RootNamespace="test" Keyword="Win32Proj" > @@ -62,10 +63,10 @@ />