Beispiel #1
0
        private static int OpenAuthCallbackFromUnmanaged(IntPtr creds, uint ncreds, IntPtr cbdata)
        {
            // Give back the structure that hold cbdata and the callback target
            OpenAuthManagedCB cbAndUserData = (OpenAuthManagedCB)Marshal.PtrToStructure(cbdata, typeof(OpenAuthManagedCB));
            int offset    = 0;
            int credIndex = 0;

            ConnectCredential[] cc = new ConnectCredential[ncreds];
            // Loop thru credentials and initialize the ConnectCredential array
            while (credIndex < ncreds)
            {
                IntPtr            currentCred = MarshalHelper.IntPtrOffset(creds, offset);
                ConnectCredential cred        = (ConnectCredential)Marshal.PtrToStructure(currentCred, typeof(ConnectCredential));
                offset       += Marshal.SizeOf(cred);
                cc[credIndex] = cred;
                credIndex++;
            }
            // Call the delegate with the ConnectCredential array, this allow the user to answer the result
            cbAndUserData.cbManaged(ref cc, cbAndUserData.cbdata);

            offset    = 0;
            credIndex = 0;
            // Loop thru ConnectCredential array and copy back to unmanaged memory
            while (credIndex < ncreds)
            {
                IntPtr currentCred = MarshalHelper.IntPtrOffset(creds, offset);
                Marshal.StructureToPtr(cc[credIndex], currentCred, true);
                offset += Marshal.SizeOf(cc[credIndex]);
                credIndex++;
            }

            return(0);
        }
Beispiel #2
0
 private static int AuthCallback(ref ConnectCredential[] creds, IntPtr cbdata)
 {
     AuthData authData = (AuthData)Marshal.PtrToStructure(cbdata, typeof(AuthData));
     for (int i = 0; i < creds.Length; i++)
     {
         ConnectCredential cred = creds[i];
         switch (cred.type)
         {
             case ConnectCredentialType.VIR_CRED_AUTHNAME:
                 // Fill the user name
                 cred.Result = authData.user_name;
                 break;
             case ConnectCredentialType.VIR_CRED_PASSPHRASE:
                 // Fill the password
                 cred.Result = authData.password;
                 break;
             default:
                 return -1;
         }
     }
     return 0;
 }
        private static int OpenAuthCallbackFromUnmanaged(IntPtr creds, uint ncreds, IntPtr cbdata)
        {
            // Give back the structure that hold cbdata and the callback target
            OpenAuthManagedCB cbAndUserData = (OpenAuthManagedCB)Marshal.PtrToStructure(cbdata, typeof(OpenAuthManagedCB));
            int offset = 0;
            int credIndex = 0;

            ConnectCredential[] cc = new ConnectCredential[ncreds];
            // Loop thru credentials and initialize the ConnectCredential array
            while (credIndex < ncreds)
            {
                IntPtr currentCred = MarshalHelper.IntPtrOffset(creds, offset);
                ConnectCredential cred = (ConnectCredential)Marshal.PtrToStructure(currentCred, typeof(ConnectCredential));
                offset += Marshal.SizeOf(cred);
                cc[credIndex] = cred;
                credIndex++;
            }
            // Call the delegate with the ConnectCredential array, this allow the user to answer the result
            cbAndUserData.cbManaged(ref cc, cbAndUserData.cbdata);

            offset = 0;
            credIndex = 0;
            // Loop thru ConnectCredential array and copy back to unmanaged memory
            while (credIndex < ncreds)
            {
                IntPtr currentCred = MarshalHelper.IntPtrOffset(creds, offset);
                Marshal.StructureToPtr(cc[credIndex], currentCred, true);
                offset += Marshal.SizeOf(cc[credIndex]);
                credIndex++;
            }

            return 0;
        }