From: Vásáry Dániel Date: Tue, 17 Oct 2017 08:58:23 +0000 (+0000) Subject: git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube... X-Git-Url: http://git.useribm.hu/?a=commitdiff_plain;h=bcd4abc606516f7aa4908f5c0342304caaa970b3;p=mediacube.git git-tfs-id: [tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube;C30631 --- diff --git a/client/IntegrationTests/MaestroIT.cs b/client/IntegrationTests/MaestroIT.cs index 0017041e..e669ea94 100644 --- a/client/IntegrationTests/MaestroIT.cs +++ b/client/IntegrationTests/MaestroIT.cs @@ -7,8 +7,32 @@ using Maestro.Commons; using System.Diagnostics; using SharpCifs.Smb; using Commons; +using System.Runtime.InteropServices; +using Microsoft.Win32.SafeHandles; +using System.Runtime.ConstrainedExecution; +using System.Security; +using System.Security.Permissions; +using System.Security.Principal; namespace IntegrationTests { + public sealed class SafeTokenHandle : SafeHandleZeroOrMinusOneIsInvalid { + private SafeTokenHandle() + : base(true) { + } + + [DllImport("kernel32.dll")] + [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] + [SuppressUnmanagedCodeSecurity] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool CloseHandle(IntPtr handle); + + protected override bool ReleaseHandle() { + return CloseHandle(handle); + } + } + + + [TestClass] public class MaestroTests { @@ -72,5 +96,71 @@ namespace IntegrationTests { result = result.Substring(0, result.LastIndexOf(".")); Debug.WriteLine(result); } + + [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)] + public static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword, + int dwLogonType, int dwLogonProvider, out SafeTokenHandle phToken); + + [DllImport("kernel32.dll", CharSet = CharSet.Auto)] + public extern static bool CloseHandle(IntPtr handle); + + + + [PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")] + [TestMethod] + public void TestImpersonate() { + SafeTokenHandle safeTokenHandle; + try { + string userName, domainName, password; + // Get the user token for the specified user, domain, and password using the + // unmanaged LogonUser method. + // The local machine name can be used for the domain name to impersonate a user on this machine. + domainName = "."; + userName = "mediacube"; + password = "Broadca5T"; + const int LOGON32_PROVIDER_DEFAULT = 0; + //This parameter causes LogonUser to create a primary token. + const int LOGON32_LOGON_INTERACTIVE = 2; + + // Call LogonUser to obtain a handle to an access token. + bool returnValue = LogonUser(userName, domainName, password, + LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, + out safeTokenHandle); + + Console.WriteLine("LogonUser called."); + + if (false == returnValue) { + int ret = Marshal.GetLastWin32Error(); + Console.WriteLine("LogonUser failed with error code : {0}", ret); + throw new System.ComponentModel.Win32Exception(ret); + } + using (safeTokenHandle) { + Console.WriteLine("Did LogonUser Succeed? " + (returnValue ? "Yes" : "No")); + Console.WriteLine("Value of Windows NT token: " + safeTokenHandle); + + // Check the identity. + Console.WriteLine("Before impersonation: " + + WindowsIdentity.GetCurrent().Name); + // Use the token handle returned by LogonUser. + using (WindowsIdentity newId = new WindowsIdentity(safeTokenHandle.DangerousGetHandle())) { + using (WindowsImpersonationContext impersonatedUser = newId.Impersonate()) { + + // Check the identity. + Console.WriteLine("After impersonation: " + + WindowsIdentity.GetCurrent().Name); + } + } + // Releasing the context object stops the impersonation + // Check the identity. + Console.WriteLine("After closing the context: " + WindowsIdentity.GetCurrent().Name); + } + } + catch (Exception ex) { + Console.WriteLine("Exception occurred. " + ex.Message); + } + + } + + } } \ No newline at end of file diff --git a/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioClipEventDispatcher.java b/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioClipEventDispatcher.java index 95065b8f..c4ae372d 100644 --- a/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioClipEventDispatcher.java +++ b/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioClipEventDispatcher.java @@ -52,6 +52,17 @@ public class NexioClipEventDispatcher implements ClipEventListener { static private final byte[] GET_SPECIAL_ID_ATTRIBUTES_REQ = { (byte) 0xC8, (byte) 0x84 }; static private final char[] hexArray = "0123456789ABCDEF".toCharArray(); + public static String bytesToBin(byte[] bytes) { + StringBuilder result = new StringBuilder(); + for (byte b : bytes) { + String str = byteToStr(b); + result.append(str); + if (result.length() % 4 == 0) + result.append(" "); + } + return result.toString(); + } + public static String bytesToHex(byte[] bytes) { char[] hexChars = new char[bytes.length * 2]; for (int j = 0; j < bytes.length; j++) { @@ -62,6 +73,18 @@ public class NexioClipEventDispatcher implements ClipEventListener { return new String(hexChars); } + public static String byteToStr(byte b) { + String binaryString = Integer.toBinaryString(b & 0xFF); + String str = String.format("%8s", binaryString).replace(' ', '0'); + return str; + } + + public static String longToStr(long b) { + String binaryString = Long.toBinaryString(b & 0xFFFF); + String str = String.format("%16s", binaryString).replace(' ', '0'); + return str; + } + private EventListenerList progressListenerList; private ProgressEvent progressEvent = new ProgressEvent(this, 0); private INexioChangeListener nexioChangeListener; @@ -195,8 +218,7 @@ public class NexioClipEventDispatcher implements ClipEventListener { } try { - if ("2931346-3".equals(jsClip.getString(LONGNAMEID))) - jsClip.put(KILLDATE, clip.getKillDate()); + jsClip.put(KILLDATE, clip.getKillDate()); } catch (Exception e) { // System.out.println(e); } diff --git a/server/user.jobengine.osgi.commons/src/user/commons/nexio/api/ClipImpl.java b/server/user.jobengine.osgi.commons/src/user/commons/nexio/api/ClipImpl.java index a722d73e..ece5fd4b 100644 --- a/server/user.jobengine.osgi.commons/src/user/commons/nexio/api/ClipImpl.java +++ b/server/user.jobengine.osgi.commons/src/user/commons/nexio/api/ClipImpl.java @@ -3,13 +3,16 @@ package user.commons.nexio.api; import java.io.IOException; import java.util.Calendar; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + import user.commons.nexio.server.protocol.Id; import user.commons.nexio.server.protocol.NexioServerProtocol; import user.commons.nexio.server.protocol.ProtocolException; import user.commons.nexio.server.protocol.Xid; class ClipImpl implements Clip { - + private static final Logger logger = LogManager.getLogger(); private static final String PROTOCOL = "protocol"; private static final String ID = "id"; private static final String XID = "xid"; @@ -90,11 +93,27 @@ class ClipImpl implements Clip { metadata = protocol.executeGetIDMetadata(id); checkClipExists(metadata); } - byte[] filetime = { metadata[42], metadata[43] }; - Calendar result = Calendar.getInstance(); - - return null; + byte[] dtArray = { metadata[43], metadata[42] }; + + long data = dtArray[0] & 0xFF; + data <<= 8; + data |= (dtArray[1] & 0xFF); + + //logger.info("--- {} .. {}", NexioClipEventDispatcher.bytesToBin(dtArray), NexioClipEventDispatcher.longToStr(data)); + + int day = (int) (data >> 11); + int month = (int) ((data & 0x7FF) >> 7); + int year = 1900 + (int) (data & 0x7F); + //System.out.println(String.format("day %s month %s year %s", day, month, year)); + result.set(Calendar.YEAR, year); + result.set(Calendar.MONTH, month - 1); + result.set(Calendar.DAY_OF_MONTH, day); + result.set(Calendar.HOUR_OF_DAY, 0); + result.set(Calendar.MINUTE, 0); + result.set(Calendar.SECOND, 0); + result.set(Calendar.MILLISECOND, 0); + return result; } @Override diff --git a/server/user.jobengine.osgi.commons/test/user/common/nexio/test/NexioDataMinerTest.java b/server/user.jobengine.osgi.commons/test/user/common/nexio/test/NexioDataMinerTest.java index 16474a18..6052a2c7 100644 --- a/server/user.jobengine.osgi.commons/test/user/common/nexio/test/NexioDataMinerTest.java +++ b/server/user.jobengine.osgi.commons/test/user/common/nexio/test/NexioDataMinerTest.java @@ -12,6 +12,32 @@ import user.commons.nexio.NexioDataMiner; import user.commons.nexio.api.Controller; public class NexioDataMinerTest { + public static String bytesToBin(byte[] bytes) { + StringBuilder result = new StringBuilder(); + for (byte b : bytes) { + String str = byteToStr(b); + result.append(str); + if (result.length() % 4 == 0) + result.append(" "); + } + return result.toString(); + } + + public static long bytesToLong(byte[] b) { + long result = 0; + for (int i = 0; i < 2; i++) { + result <<= 8; + result |= (b[i] & 0xFF); + } + return result; + } + + public static String byteToStr(byte b) { + String binaryString = Integer.toBinaryString(b & 0xFF); + String str = String.format("%8s", binaryString).replace(' ', '0'); + return str; + } + @BeforeClass public static void initialize() throws Exception { //Naplozas @@ -30,6 +56,12 @@ public class NexioDataMinerTest { System.getProperties().putAll(properties); } + public static String longToStr(long b) { + String binaryString = Long.toBinaryString(b & 0xFFFF); + String str = String.format("%16s", binaryString).replace(' ', '0'); + return str; + } + private NexioDataMiner sut; @Test @@ -50,4 +82,17 @@ public class NexioDataMinerTest { c.connect(); c.getMediabase().getProtocol().setDescription("%0000205", "VALAMI"); } + + @Test + public void testKillDateConverter() throws Exception { + byte[] data = { 8, -58 }; + long num = bytesToLong(data); + System.out.println(String.format("%s .. %s", bytesToBin(data), longToStr(num))); + int day = (int) (num >> 11); + int month = (int) ((num & 0x7FF) >> 7); + int year = (int) (num & 0x7F); + System.out.println(String.format("day %s month %s year %s", day, month, year)); + + } + }