internal static IntPtr SCardEstablishContext( [In] IntPtr dwScope, [In] IntPtr pvReserved1, [In] IntPtr pvReserved2, [In, Out] ref IntPtr phContext) { if (_osUnixPlatform == OSUnixPlatform.Linux) { return(LinuxNativeMethods.SCardEstablishContext( dwScope, pvReserved1, pvReserved2, ref phContext)); } else if (_osUnixPlatform == OSUnixPlatform.OSX) { return(OSXNativeMethods.SCardEstablishContext( dwScope, pvReserved1, pvReserved2, ref phContext)); } else { throw new NotImplementedException(); } }
private static IntPtr GetLibsecretSchema() => LinuxNativeMethods.secret_schema_new("org.freedesktop.Secret.Generic", LinuxNativeMethods.SecretSchemaFlags.SECRET_SCHEMA_DONT_MATCH_NAME, "service", LinuxNativeMethods.SecretSchemaAttributeType.SECRET_SCHEMA_ATTRIBUTE_STRING, "account", LinuxNativeMethods.SecretSchemaAttributeType.SECRET_SCHEMA_ATTRIBUTE_STRING);
public void Dispose() { IntPtr schemaPtr = GetLibsecretSchema(); try { LinuxNativeMethods.secret_password_clear_sync(schemaPtr, IntPtr.Zero, "service", ExpectedServiceName, "account", _cloudName); } finally { LinuxNativeMethods.secret_schema_unref(schemaPtr); } }
private static string GetUserHomeDirOnUnix() { if (SharedUtilities.IsWindowsPlatform()) { throw new NotSupportedException(); } if (!string.IsNullOrEmpty(SharedUtilities.s_homeEnvVar)) { return(SharedUtilities.s_homeEnvVar); } string username = null; if (!string.IsNullOrEmpty(SharedUtilities.s_lognameEnvVar)) { username = s_lognameEnvVar; } else if (!string.IsNullOrEmpty(SharedUtilities.s_userEnvVar)) { username = s_userEnvVar; } else if (!string.IsNullOrEmpty(SharedUtilities.s_lNameEnvVar)) { username = s_lNameEnvVar; } else if (!string.IsNullOrEmpty(SharedUtilities.s_usernameEnvVar)) { username = s_usernameEnvVar; } if (SharedUtilities.IsMacPlatform()) { return(!string.IsNullOrEmpty(username) ? Path.Combine("/Users", username) : null); } else if (SharedUtilities.IsLinuxPlatform()) { if (LinuxNativeMethods.getuid() == LinuxNativeMethods.RootUserId) { return("/root"); } else { return(!string.IsNullOrEmpty(username) ? Path.Combine("/home", username) : null); } } else { throw new NotSupportedException(); } }
public static IDisposable Create(string cloudName, string refreshToken) { IntPtr schemaPtr = GetLibsecretSchema(); try { LinuxNativeMethods.secret_password_store_sync(schemaPtr, LinuxNativeMethods.SECRET_COLLECTION_SESSION, $"{ExpectedServiceName}/{cloudName}", refreshToken, IntPtr.Zero, "service", ExpectedServiceName, "account", cloudName); } finally { LinuxNativeMethods.secret_schema_unref(schemaPtr); } return(new LinuxRefreshTokenFixture(cloudName)); }
internal static int dlclose( [In] IntPtr handle) { if (_osUnixPlatform == OSUnixPlatform.Linux) { return(LinuxNativeMethods.dlclose(handle)); } else if (_osUnixPlatform == OSUnixPlatform.OSX) { return(OSXNativeMethods.dlclose(handle)); } else { throw new NotImplementedException(); } }
internal static IntPtr SCardIsValidContext( [In] IntPtr hContext) { if (_osUnixPlatform == OSUnixPlatform.Linux) { return(LinuxNativeMethods.SCardIsValidContext(hContext)); } else if (_osUnixPlatform == OSUnixPlatform.OSX) { return(OSXNativeMethods.SCardIsValidContext(hContext)); } else { throw new NotImplementedException(); } }
public static void CreateHardLink(string oldFileName, string newFileName) { if (OperatingSystem.IsWindows()) { WindowsNativeMethods.CreateHardLink(oldFileName, newFileName); } else if (OperatingSystem.IsLinux()) { LinuxNativeMethods.CreateHardLink(oldFileName, newFileName); } else { throw new PlatformNotSupportedException(); } }
internal static IntPtr SCardBeginTransaction( [In] IntPtr hCard) { if (_osUnixPlatform == OSUnixPlatform.Linux) { return(LinuxNativeMethods.SCardBeginTransaction(hCard)); } else if (_osUnixPlatform == OSUnixPlatform.OSX) { return(OSXNativeMethods.SCardBeginTransaction(hCard)); } else { throw new NotImplementedException(); } }
internal static IntPtr SCardFreeMemory( [In] IntPtr hContext, [In] IntPtr pvMem) { if (_osUnixPlatform == OSUnixPlatform.Linux) { return(LinuxNativeMethods.SCardFreeMemory(hContext, pvMem)); } else if (_osUnixPlatform == OSUnixPlatform.OSX) { return(OSXNativeMethods.SCardFreeMemory(hContext, pvMem)); } else { throw new NotImplementedException(); } }
internal static IntPtr SCardDisconnect( [In] IntPtr hCard, [In] IntPtr dwDisposition) { if (_osUnixPlatform == OSUnixPlatform.Linux) { return(LinuxNativeMethods.SCardDisconnect(hCard, dwDisposition)); } else if (_osUnixPlatform == OSUnixPlatform.OSX) { return(OSXNativeMethods.SCardDisconnect(hCard, dwDisposition)); } else { throw new NotImplementedException(); } }
internal static IntPtr dlsym( [In] IntPtr handle, [In] string szSymbol) { if (_osUnixPlatform == OSUnixPlatform.Linux) { return(LinuxNativeMethods.dlsym(handle, szSymbol)); } else if (_osUnixPlatform == OSUnixPlatform.OSX) { return(OSXNativeMethods.dlsym(handle, szSymbol)); } else { throw new NotImplementedException(); } }
internal static IntPtr dlopen( [In] string szFilename, [In] int flag) { if (_osUnixPlatform == OSUnixPlatform.Linux) { return(LinuxNativeMethods.dlopen(szFilename, flag)); } else if (_osUnixPlatform == OSUnixPlatform.OSX) { return(OSXNativeMethods.dlopen(szFilename, flag)); } else { throw new NotImplementedException(); } }
internal static IntPtr SCardListReaderGroups( [In] IntPtr hContext, [Out] byte[] mszGroups, [In, Out] ref IntPtr pcchGroups) { if (_osUnixPlatform == OSUnixPlatform.Linux) { return(LinuxNativeMethods.SCardListReaderGroups(hContext, mszGroups, ref pcchGroups)); } else if (_osUnixPlatform == OSUnixPlatform.OSX) { return(OSXNativeMethods.SCardListReaderGroups(hContext, mszGroups, ref pcchGroups));; } else { throw new NotImplementedException(); } }
internal static IntPtr SCardGetStatusChange( [In] IntPtr hContext, [In] IntPtr dwTimeout, [In, Out] SCARD_READERSTATE[] rgReaderStates, [In] IntPtr cReaders) { if (_osUnixPlatform == OSUnixPlatform.Linux) { return(LinuxNativeMethods.SCardGetStatusChange(hContext, dwTimeout, rgReaderStates, cReaders)); } else if (_osUnixPlatform == OSUnixPlatform.OSX) { return(OSXNativeMethods.SCardGetStatusChange(hContext, dwTimeout, rgReaderStates, cReaders)); } else { throw new NotImplementedException(); } }
internal static IntPtr SCardReconnect( [In] IntPtr hCard, [In] IntPtr dwShareMode, [In] IntPtr dwPreferredProtocols, [In] IntPtr dwInitialization, [Out] out IntPtr pdwActiveProtocol) { if (_osUnixPlatform == OSUnixPlatform.Linux) { return(LinuxNativeMethods.SCardReconnect(hCard, dwShareMode, dwPreferredProtocols, dwInitialization, out pdwActiveProtocol)); } else if (_osUnixPlatform == OSUnixPlatform.OSX) { return(OSXNativeMethods.SCardReconnect(hCard, dwShareMode, dwPreferredProtocols, dwInitialization, out pdwActiveProtocol)); } else { throw new NotImplementedException(); } }
internal static IntPtr SCardSetAttrib( [In] IntPtr hCard, [In] IntPtr dwAttrId, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] byte[] pbAttr, [In] IntPtr cbAttrLen) { if (_osUnixPlatform == OSUnixPlatform.Linux) { return(LinuxNativeMethods.SCardSetAttrib(hCard, dwAttrId, pbAttr, cbAttrLen)); } else if (_osUnixPlatform == OSUnixPlatform.OSX) { return(OSXNativeMethods.SCardSetAttrib(hCard, dwAttrId, pbAttr, cbAttrLen)); } else { throw new NotImplementedException(); } }
internal static IntPtr SCardConnect( [In] IntPtr hContext, [In] byte[] szReader, [In] IntPtr dwShareMode, [In] IntPtr dwPreferredProtocols, [Out] out IntPtr phCard, [Out] out IntPtr pdwActiveProtocol) { if (_osUnixPlatform == OSUnixPlatform.Linux) { return(LinuxNativeMethods.SCardConnect(hContext, szReader, dwShareMode, dwPreferredProtocols, out phCard, out pdwActiveProtocol)); } else if (_osUnixPlatform == OSUnixPlatform.OSX) { return(OSXNativeMethods.SCardConnect(hContext, szReader, dwShareMode, dwPreferredProtocols, out phCard, out pdwActiveProtocol)); } else { throw new NotImplementedException(); } }
public static Int32 Main(String[] args) { if (args.Length == 0) { Console.WriteLine("Usage: ClrLibRunner.exe <NativeSharedLibrary> <Args>..."); return(1); } String sharedLibrary = args[0]; // TODO: detect which platform we are on to know how to load a shared library correctly bool onLinux = true; EntryDelegate entry; if (onLinux) { const uint RTLD_NOW = 2; IntPtr moduleHandle = LinuxNativeMethods.dlopen(sharedLibrary, RTLD_NOW); if (moduleHandle == IntPtr.Zero) { Console.WriteLine("Error: dlopen '{0}' failed: {1}", sharedLibrary, LinuxNativeMethods.dlerror()); return(1); } IntPtr funcPtr = LinuxNativeMethods.dlsym(moduleHandle, EntryName); if (funcPtr == IntPtr.Zero) { Console.WriteLine("Error: dlsym '{0}' failed: {1}", EntryName, LinuxNativeMethods.dlerror()); return(1); } entry = (EntryDelegate)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(EntryDelegate)); } else { Console.WriteLine("Error: unsupported platform"); return(1); } IntPtr createDelegateFuncPtr = Marshal.GetFunctionPointerForDelegate(new CreateDelegateDelegate(CreateDelegate)); return(entry(createDelegateFuncPtr, args.Length, args)); }
internal static IntPtr SCardTransmit( [In] IntPtr hCard, [In] IntPtr pioSendPci, [In] byte[] pbSendBuffer, [In] IntPtr cbSendLength, [In, Out] IntPtr pioRecvPci, [Out] byte[] pbRecvBuffer, [In, Out] ref IntPtr pcbRecvLength) { if (_osUnixPlatform == OSUnixPlatform.Linux) { return(LinuxNativeMethods.SCardTransmit(hCard, pioSendPci, pbSendBuffer, cbSendLength, pioRecvPci, pbRecvBuffer, ref pcbRecvLength)); } else if (_osUnixPlatform == OSUnixPlatform.OSX) { return(OSXNativeMethods.SCardTransmit(hCard, pioSendPci, pbSendBuffer, cbSendLength, pioRecvPci, pbRecvBuffer, ref pcbRecvLength));; } else { throw new NotImplementedException(); } }
internal static IntPtr SCardControl( [In] IntPtr hCard, [In] IntPtr dwControlCode, [In] byte[] pbSendBuffer, [In] IntPtr cbSendLength, [Out] byte[] pbRecvBuffer, [In] IntPtr pcbRecvLength, [Out] out IntPtr lpBytesReturned) { if (_osUnixPlatform == OSUnixPlatform.Linux) { return(LinuxNativeMethods.SCardControl(hCard, dwControlCode, pbSendBuffer, cbSendLength, pbRecvBuffer, pcbRecvLength, out lpBytesReturned)); } else if (_osUnixPlatform == OSUnixPlatform.OSX) { return(OSXNativeMethods.SCardControl(hCard, dwControlCode, pbSendBuffer, cbSendLength, pbRecvBuffer, pcbRecvLength, out lpBytesReturned)); } else { throw new NotImplementedException(); } }
internal static IntPtr SCardStatus( [In] IntPtr hCard, [Out] byte[] szReaderName, [In, Out] ref IntPtr pcchReaderLen, [Out] out IntPtr pdwState, [Out] out IntPtr pdwProtocol, [Out] byte[] pbAtr, [In, Out] ref IntPtr pcbAtrLen) { if (_osUnixPlatform == OSUnixPlatform.Linux) { return(LinuxNativeMethods.SCardStatus(hCard, szReaderName, ref pcchReaderLen, out pdwState, out pdwProtocol, pbAtr, ref pcbAtrLen)); } else if (_osUnixPlatform == OSUnixPlatform.OSX) { return(OSXNativeMethods.SCardStatus(hCard, szReaderName, ref pcchReaderLen, out pdwState, out pdwProtocol, pbAtr, ref pcbAtrLen)); } else { throw new NotImplementedException(); } }
public static Int32 Main(String[] args) { if (args.Length == 0) { Console.WriteLine("Usage: ClrLibRunner.exe <NativeSharedLibrary> <Args>..."); return(1); } String sharedLibrary = args[0]; // TODO: might want to make this a command-line option (--dlopen or --loadlibrary)? // TODO: need a way to detect whether or not this mechanism is supported // maybe I should use runtime reflection? //bool onWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); bool onWindows = Directory.Exists("C:\\Windows\\System32"); EntryDelegate entry; if (onWindows) { IntPtr moduleHandle = WindowsNativeMethods.LoadLibrary(sharedLibrary); if (moduleHandle == IntPtr.Zero) { Console.WriteLine("Error: LoadLibrary '{0}' failed: {1}", sharedLibrary, Marshal.GetLastWin32Error()); return(1); } IntPtr funcPtr = WindowsNativeMethods.GetProcAddress(moduleHandle, EntryName); if (funcPtr == IntPtr.Zero) { Int32 errorCode = Marshal.GetLastWin32Error(); if (errorCode == WindowsNativeMethods.ERROR_PROC_NOT_FOUND) { Console.WriteLine("Error: library '{0}' is missing function '{1}'", sharedLibrary, EntryName); } else { Console.WriteLine("Error: GetProcAddress '{0}' failed: {1}", EntryName, errorCode); } return(1); } entry = (EntryDelegate)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(EntryDelegate)); } else { const uint RTLD_NOW = 2; IntPtr moduleHandle = LinuxNativeMethods.dlopen(sharedLibrary, RTLD_NOW); if (moduleHandle == IntPtr.Zero) { Console.WriteLine("Error: dlopen '{0}' failed: {1}", sharedLibrary, LinuxNativeMethods.dlerror()); return(1); } IntPtr funcPtr = LinuxNativeMethods.dlsym(moduleHandle, EntryName); if (funcPtr == IntPtr.Zero) { Console.WriteLine("Error: dlsym '{0}' failed: {1}", EntryName, LinuxNativeMethods.dlerror()); return(1); } entry = (EntryDelegate)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(EntryDelegate)); } IntPtr createDelegateFuncPtr = Marshal.GetFunctionPointerForDelegate(new CreateDelegateDelegate(CreateDelegate)); return(entry(createDelegateFuncPtr, args.Length, args)); }