internal bool SyncAllCallbackRoutine(IntPtr data, IntPtr update)
        {
            if (this.SyncFromAllServersCallback == null)
            {
                return(true);
            }
            DS_REPSYNCALL_UPDATE structure = new DS_REPSYNCALL_UPDATE();

            Marshal.PtrToStructure(update, structure);
            SyncFromAllServersEvent eventType = structure.eventType;
            IntPtr pErrInfo = structure.pErrInfo;
            SyncFromAllServersOperationException exception = null;

            if (pErrInfo != IntPtr.Zero)
            {
                exception = ExceptionHelper.CreateSyncAllException(pErrInfo, true);
                if (exception == null)
                {
                    return(true);
                }
            }
            string targetServer = null;
            string sourceServer = null;

            pErrInfo = structure.pSync;
            if (pErrInfo != IntPtr.Zero)
            {
                DS_REPSYNCALL_SYNC ds_repsyncall_sync = new DS_REPSYNCALL_SYNC();
                Marshal.PtrToStructure(pErrInfo, ds_repsyncall_sync);
                targetServer = Marshal.PtrToStringUni(ds_repsyncall_sync.pszDstId);
                sourceServer = Marshal.PtrToStringUni(ds_repsyncall_sync.pszSrcId);
            }
            return(this.SyncFromAllServersCallback(eventType, targetServer, sourceServer, exception));
        }
Example #2
0
 internal bool SyncAllCallbackRoutine(IntPtr data, IntPtr update)
 {
     if (this.SyncFromAllServersCallback != null)
     {
         DS_REPSYNCALL_UPDATE dSREPSYNCALLUPDATE = new DS_REPSYNCALL_UPDATE();
         Marshal.PtrToStructure(update, dSREPSYNCALLUPDATE);
         SyncFromAllServersEvent syncFromAllServersEvent = dSREPSYNCALLUPDATE.eventType;
         IntPtr intPtr = dSREPSYNCALLUPDATE.pErrInfo;
         SyncFromAllServersOperationException syncFromAllServersOperationException = null;
         if (intPtr != (IntPtr)0)
         {
             syncFromAllServersOperationException = ExceptionHelper.CreateSyncAllException(intPtr, true);
             if (syncFromAllServersOperationException == null)
             {
                 return(true);
             }
         }
         string stringUni = null;
         string str       = null;
         intPtr = dSREPSYNCALLUPDATE.pSync;
         if (intPtr != (IntPtr)0)
         {
             DS_REPSYNCALL_SYNC dSREPSYNCALLSYNC = new DS_REPSYNCALL_SYNC();
             Marshal.PtrToStructure(intPtr, dSREPSYNCALLSYNC);
             stringUni = Marshal.PtrToStringUni(dSREPSYNCALLSYNC.pszDstId);
             str       = Marshal.PtrToStringUni(dSREPSYNCALLSYNC.pszSrcId);
         }
         SyncUpdateCallback syncFromAllServersCallback = this.SyncFromAllServersCallback;
         return(syncFromAllServersCallback(syncFromAllServersEvent, stringUni, str, syncFromAllServersOperationException));
     }
     else
     {
         return(true);
     }
 }
Example #3
0
        internal void SyncReplicaAllHelper(IntPtr handle, SyncReplicaFromAllServersCallback syncAllFunctionPointer, string partition, SyncFromAllServersOptions option, SyncUpdateCallback callback, LoadLibrarySafeHandle libHandle)
        {
            IntPtr errorInfo = (IntPtr)0;

            if (!Partitions.Contains(partition))
            {
                throw new ArgumentException(SR.ServerNotAReplica, "partition");
            }

            // we want to return the dn instead of DNS guid
            // call DsReplicaSyncAllW
            IntPtr functionPtr = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaSyncAllW");

            if (functionPtr == (IntPtr)0)
            {
                throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error());
            }
            UnsafeNativeMethods.DsReplicaSyncAllW dsReplicaSyncAllW = (UnsafeNativeMethods.DsReplicaSyncAllW)Marshal.GetDelegateForFunctionPointer(functionPtr, typeof(UnsafeNativeMethods.DsReplicaSyncAllW));

            int result = dsReplicaSyncAllW(handle, partition, (int)option | DS_REPSYNCALL_ID_SERVERS_BY_DN, syncAllFunctionPointer, (IntPtr)0, ref errorInfo);

            try
            {
                // error happens during the synchronization
                if (errorInfo != (IntPtr)0)
                {
                    SyncFromAllServersOperationException e = ExceptionHelper.CreateSyncAllException(errorInfo, false);
                    if (e == null)
                    {
                        return;
                    }
                    else
                    {
                        throw e;
                    }
                }
                else
                {
                    // API does not return error infor occurred during synchronization, but result is not success.
                    if (result != 0)
                    {
                        throw new SyncFromAllServersOperationException(ExceptionHelper.GetErrorMessage(result, false));
                    }
                }
            }
            finally
            {
                // release the memory
                if (errorInfo != (IntPtr)0)
                {
                    UnsafeNativeMethods.LocalFree(errorInfo);
                }
            }
        }
Example #4
0
        internal bool SyncAllCallbackRoutine(IntPtr data, IntPtr update)
        {
            if (SyncFromAllServersCallback == null)
            {
                // user does not specify callback, resume the DsReplicaSyncAll execution
                return(true);
            }
            else
            {
                // user specifies callback
                // our callback is invoked, update should not be NULL, do assertion here
                Debug.Assert(update != (IntPtr)0);

                DS_REPSYNCALL_UPDATE syncAllUpdate = new DS_REPSYNCALL_UPDATE();
                Marshal.PtrToStructure(update, syncAllUpdate);

                // get the event type
                SyncFromAllServersEvent eventType = syncAllUpdate.eventType;

                // get the error information
                IntPtr temp = syncAllUpdate.pErrInfo;
                SyncFromAllServersOperationException exception = null;

                if (temp != (IntPtr)0)
                {
                    // error information is available
                    exception = ExceptionHelper.CreateSyncAllException(temp, true);
                    if (exception == null)
                    {
                        // this is the special case that we ingore the failure when SyncAllOptions.CheckServerAlivenessOnly is specified
                        return(true);
                    }
                }

                string targetName = null;
                string sourceName = null;

                temp = syncAllUpdate.pSync;
                if (temp != (IntPtr)0)
                {
                    DS_REPSYNCALL_SYNC sync = new DS_REPSYNCALL_SYNC();
                    Marshal.PtrToStructure(temp, sync);

                    targetName = Marshal.PtrToStringUni(sync.pszDstId);
                    sourceName = Marshal.PtrToStringUni(sync.pszSrcId);
                }

                // invoke the client callback
                SyncUpdateCallback clientCallback = SyncFromAllServersCallback;

                return(clientCallback(eventType, targetName, sourceName, exception));
            }
        }
        internal void SyncReplicaAllHelper(IntPtr handle, SyncReplicaFromAllServersCallback syncAllFunctionPointer, string partition, SyncFromAllServersOptions option, SyncUpdateCallback callback, LoadLibrarySafeHandle libHandle)
        {
            IntPtr zero = IntPtr.Zero;

            if (!this.Partitions.Contains(partition))
            {
                throw new ArgumentException(Res.GetString("ServerNotAReplica"), "partition");
            }
            IntPtr procAddress = System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaSyncAllW");

            if (procAddress == IntPtr.Zero)
            {
                throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error());
            }
            System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaSyncAllW delegateForFunctionPointer = (System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaSyncAllW)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaSyncAllW));
            int errorCode = delegateForFunctionPointer(handle, partition, ((int)option) | 4, syncAllFunctionPointer, IntPtr.Zero, ref zero);

            try
            {
                if (zero != IntPtr.Zero)
                {
                    SyncFromAllServersOperationException exception = ExceptionHelper.CreateSyncAllException(zero, false);
                    if (exception != null)
                    {
                        throw exception;
                    }
                }
                else if (errorCode != 0)
                {
                    throw new SyncFromAllServersOperationException(ExceptionHelper.GetErrorMessage(errorCode, false));
                }
            }
            finally
            {
                if (zero != IntPtr.Zero)
                {
                    System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.LocalFree(zero);
                }
            }
        }
Example #6
0
        internal void SyncReplicaAllHelper(IntPtr handle, SyncReplicaFromAllServersCallback syncAllFunctionPointer, string partition, SyncFromAllServersOptions option, SyncUpdateCallback callback, LoadLibrarySafeHandle libHandle)
        {
            IntPtr intPtr = (IntPtr)0;

            if (this.Partitions.Contains(partition))
            {
                IntPtr procAddress = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaSyncAllW");
                if (procAddress != (IntPtr)0)
                {
                    UnsafeNativeMethods.DsReplicaSyncAllW delegateForFunctionPointer = (UnsafeNativeMethods.DsReplicaSyncAllW)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(UnsafeNativeMethods.DsReplicaSyncAllW));
                    int num = delegateForFunctionPointer(handle, partition, (int)option | 4, syncAllFunctionPointer, (IntPtr)0, ref intPtr);
                    try
                    {
                        if (intPtr == (IntPtr)0)
                        {
                            if (num != 0)
                            {
                                throw new SyncFromAllServersOperationException(ExceptionHelper.GetErrorMessage(num, false));
                            }
                        }
                        else
                        {
                            SyncFromAllServersOperationException syncFromAllServersOperationException = ExceptionHelper.CreateSyncAllException(intPtr, false);
                            if (syncFromAllServersOperationException != null)
                            {
                                throw syncFromAllServersOperationException;
                            }
                        }
                    }
                    finally
                    {
                        if (intPtr != (IntPtr)0)
                        {
                            UnsafeNativeMethods.LocalFree(intPtr);
                        }
                    }
                    return;
                }
                else
                {
                    throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error());
                }
            }
            else
            {
                throw new ArgumentException(Res.GetString("ServerNotAReplica"), "partition");
            }
        }
Example #7
0
        internal unsafe void SyncReplicaAllHelper(IntPtr handle, SyncReplicaFromAllServersCallback syncAllCallback, string partition, SyncFromAllServersOptions option, SyncUpdateCallback?callback, SafeLibraryHandle libHandle)
        {
            IntPtr errorInfo = (IntPtr)0;

            if (!Partitions.Contains(partition))
            {
                throw new ArgumentException(SR.ServerNotAReplica, nameof(partition));
            }

            // we want to return the dn instead of DNS guid
            // call DsReplicaSyncAllW
            var dsReplicaSyncAllW = (delegate * unmanaged <IntPtr, char *, int, IntPtr, IntPtr, IntPtr *, int>)global::Interop.Kernel32.GetProcAddress(libHandle, "DsReplicaSyncAllW");

            if (dsReplicaSyncAllW == null)
            {
                throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error());
            }

            int result;

            fixed(char *partitionPtr = partition)
            {
                IntPtr syncAllFunctionPointer = Marshal.GetFunctionPointerForDelegate(syncAllCallback);

                result = dsReplicaSyncAllW(handle, partitionPtr, (int)option | DS_REPSYNCALL_ID_SERVERS_BY_DN, syncAllFunctionPointer, (IntPtr)0, &errorInfo);
                GC.KeepAlive(syncAllCallback);
            }

            try
            {
                // error happens during the synchronization
                if (errorInfo != (IntPtr)0)
                {
                    SyncFromAllServersOperationException?e = ExceptionHelper.CreateSyncAllException(errorInfo, false);
                    if (e == null)
                    {
                        return;
                    }
                    else
                    {
                        throw e;
                    }
                }
                else
                {
                    // API does not return error infor occurred during synchronization, but result is not success.
                    if (result != 0)
                    {
                        throw new SyncFromAllServersOperationException(ExceptionHelper.GetErrorMessage(result, false));
                    }
                }
            }
            finally
            {
                // release the memory
                if (errorInfo != (IntPtr)0)
                {
                    global::Interop.Kernel32.LocalFree(errorInfo);
                }
            }
        }