/// <summary>
        /// Coes the set proxy blanket.
        /// </summary>
        /// <param name="proxy">The proxy.</param>
        /// <param name="dwAuthnSvc">The dw authn SVC.</param>
        /// <param name="dwAuthzSvc">The dw authz SVC.</param>
        /// <param name="pServerPrincName">Name of the p server princ.</param>
        /// <param name="dwAuthnLevel">The dw authn level.</param>
        /// <param name="dwImpLevel">The dw imp level.</param>
        /// <param name="pAuthInfo">The p authentication information.</param>
        /// <param name="dwCapababilities">The dw capababilities.</param>
        /// <param name="throwOnError">if set to <c>true</c> [throw on error].</param>
        /// <returns>System.Int32.</returns>
        /// <exception cref="COMException">CoSetProxyBlanket failed with HRESULT {hr:X}</exception>
        private static int CoSetProxyBlanket(IntPtr proxy,
                                             uint dwAuthnSvc,
                                             uint dwAuthzSvc,
                                             string pServerPrincName,
                                             RpcAuthnLevel dwAuthnLevel,
                                             RpcImpLevel dwImpLevel,
                                             IntPtr pAuthInfo,
                                             OleAuthCapabilities dwCapababilities,
                                             bool throwOnError)
        {
            //should be called once for process to be able to call into ecs com api's
            int hr = Win32Helper.CoSetProxyBlanket(
                proxy,
                dwAuthnSvc,
                dwAuthzSvc,
                pServerPrincName,
                dwAuthnLevel,
                dwImpLevel,
                pAuthInfo,
                dwCapababilities);

            //expected is 0
            if (HResult.Failed(hr) && throwOnError)
            {
                throw new COMException($"{StorageSyncResources.ComError1} {hr:X}");
            }

            return(hr);
        }
Esempio n. 2
0
 public static extern int CoInitializeSecurity(IntPtr pVoid,
                                               int cAuthSvc,
                                               IntPtr asAuthSvc,
                                               IntPtr pReserved1,
                                               RpcAuthnLevel level,
                                               RpcImpLevel impers,
                                               IntPtr pAuthList,
                                               EoAuthnCap dwCapabilities,
                                               IntPtr pReserved3);
Esempio n. 3
0
 public static extern int CoSetProxyBlanket(
     IntPtr pProxy,
     uint dwAuthnSvc,
     uint dwAuthzSvc,
     string pServerPrincName,
     RpcAuthnLevel dwAuthnLevel,
     RpcImpLevel dwImpLevel,
     IntPtr pAuthInfo,
     OleAuthCapabilities dwCapababilities);
Esempio n. 4
0
 public COAUTHINFO(RpcAuthnSrv authent, RpcAuthzSrv author, string serverprinc,
                   RpcAuthnLevel level, RpcImpersLevel impers, IntPtr ciptr)
 {
     authnsvc           = authent;
     authzsvc           = author;
     serverprincname    = serverprinc;
     authnlevel         = level;
     impersonationlevel = impers;
     authidentitydata   = ciptr;
 }
Esempio n. 5
0
 public static extern int CoInitializeSecurity(
     IntPtr pSecDesc,
     int cAuthSvc,
     IntPtr asAuthSvc,
     IntPtr pReserved1,
     [MarshalAs(UnmanagedType.U4)] RpcAuthnLevel dwAuthnLevel,
     [MarshalAs(UnmanagedType.U4)] RpcImpLevel dwImpLevel,
     IntPtr pAuthList,
     [MarshalAs(UnmanagedType.U4)] EoAuthnCap dwCapabilities,
     IntPtr pReserved3);
 /// <summary>
 /// Coes the set proxy blanket.
 /// </summary>
 /// <param name="proxy">The proxy.</param>
 /// <param name="dwAuthnSvc">The dw authn SVC.</param>
 /// <param name="dwAuthzSvc">The dw authz SVC.</param>
 /// <param name="pServerPrincName">Name of the p server princ.</param>
 /// <param name="dwAuthnLevel">The dw authn level.</param>
 /// <param name="dwImpLevel">The dw imp level.</param>
 /// <param name="dwCapababilities">The dw capababilities.</param>
 /// <param name="exception">if set to <c>true</c> [exception].</param>
 /// <returns>System.Int32.</returns>
 private static int CoSetProxyBlanket(IntPtr proxy,
                                      uint dwAuthnSvc                      = ManagementInteropConstants.RPC_C_AUTHN_DEFAULT,
                                      uint dwAuthzSvc                      = ManagementInteropConstants.RPC_C_AUTHZ_NONE,
                                      string pServerPrincName              = null,
                                      RpcAuthnLevel dwAuthnLevel           = RpcAuthnLevel.Default,
                                      RpcImpLevel dwImpLevel               = RpcImpLevel.Impersonate,
                                      OleAuthCapabilities dwCapababilities = OleAuthCapabilities.EOACNONE,
                                      bool exception = true)
 {
     return(CoSetProxyBlanket(
                proxy,
                dwAuthnSvc,
                dwAuthzSvc,
                pServerPrincName,
                dwAuthnLevel,
                dwImpLevel,
                IntPtr.Zero,
                dwCapababilities,
                exception));
 }
Esempio n. 7
0
        public static object[] CoCreateInstanceEx(Guid clsid, ClsCtx ctx, string servername, Guid[] iids,
                                                  RpcAuthnSrv authent, RpcAuthzSrv author, string serverprinc,
                                                  RpcAuthnLevel level, RpcImpersLevel impers,
                                                  string domain, string user, string password)
        {
            int num = iids.Length;

            MULTI_QI[] amqi = new MULTI_QI[num];

            IntPtr guidbuf = Marshal.AllocCoTaskMem(num * 16);        // allocate memory for IIDs

            for (int i = 0; i < num; i++)
            {
                IntPtr piid = (IntPtr)((int)guidbuf + (i * 16));
                Marshal.StructureToPtr(iids[i], piid, false);
                amqi[i] = new MULTI_QI(piid);
            }

            COAUTHIDENTITY ci    = new COAUTHIDENTITY(user, domain, password);
            IntPtr         ciptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(ci));

            Marshal.StructureToPtr(ci, ciptr, false);

            COAUTHINFO ca;

            if (string.IsNullOrEmpty(user))
            {
                ca = new COAUTHINFO(authent, author, serverprinc, level, impers, IntPtr.Zero /* ptr to coauth*/);
            }
            else
            {
                ca = new COAUTHINFO(authent, author, serverprinc, level, impers, ciptr);
            }
            IntPtr captr = Marshal.AllocCoTaskMem(Marshal.SizeOf(ca));

            Marshal.StructureToPtr(ca, captr, false);

            COSERVERINFO cs = new COSERVERINFO(servername, captr);

            int hr = CoCreateInstanceEx(ref clsid, IntPtr.Zero, (int)ctx, cs, num, amqi);

            Marshal.DestroyStructure(captr, typeof(COAUTHINFO));
            Marshal.FreeCoTaskMem(captr);
            Marshal.FreeCoTaskMem(guidbuf);

            if (hr < 0)                        // FAILED()
            {
                Marshal.DestroyStructure(ciptr, typeof(COAUTHIDENTITY));
                Marshal.FreeCoTaskMem(ciptr);
                return(null);
            }

            int refcount;

            object[] ifret = new object[num];
            for (int i = 0; i < num; i++)
            {
                if (amqi[i].hr != 0)
                {
                    ifret[i] = (int)amqi[i].hr;
                    continue;
                }

                IntPtr ip = amqi[i].pItf;
                amqi[i].pItf = IntPtr.Zero;
                ifret[i]     = Marshal.GetObjectForIUnknown(ip);
                refcount     = Marshal.Release(ip);
                continue;
#if COMPROXY
                hr = CoSetProxyBlanket(ip, authent, author, serverprinc, level, impers, ciptr, 0);
                if (hr < 0)                        // FAILED()
                {
                    ifret[i] = (int)hr;
                }
                else
                {
                    ifret[i] = Marshal.GetObjectForIUnknown(ip);
                }

                refcount = Marshal.Release(ip);
 #endif
            }

            Marshal.DestroyStructure(ciptr, typeof(COAUTHIDENTITY));
            Marshal.FreeCoTaskMem(ciptr);

            return(ifret);
        }
Esempio n. 8
0
 private static extern int CoSetProxyBlanket(IntPtr pProxy, RpcAuthnSrv authent, RpcAuthzSrv author,
                                             string serverprinc, RpcAuthnLevel level, RpcImpersLevel impers,
                                             IntPtr ciptr, int dwCapabilities);
Esempio n. 9
0
 public static extern int CoInitializeSecurity(IntPtr pVoid, int cAuthSvc, IntPtr asAuthSvc, IntPtr pReserved1, RpcAuthnLevel level,
     RpcImpLevel impers, IntPtr pAuthList, EoAuthnCap dwCapabilities, IntPtr pReserved3);
Esempio n. 10
0
 public static extern void CoInitializeSecurity([MarshalAs(UnmanagedType.LPStruct)] Guid pSecDesc, int cAuthSvc, IntPtr asAuthSvc, IntPtr pReserved1, RpcAuthnLevel level, RpcImpLevel impers, IntPtr pAuthList, EoAuthnCap dwCapabilities, IntPtr pReserved3);
Esempio n. 11
0
        private int capabilities = 0; // EOAC_NONE

        #region Constructors

        public COAUTHINFO(RpcAuthnSrv authent, RpcAuthzSrv author, string serverprinc,
                                RpcAuthnLevel level, RpcImpersLevel impers, IntPtr ciptr)
        {
            authnsvc = authent;
                authzsvc = author;
                serverprincname = serverprinc;
                authnlevel = level;
                impersonationlevel = impers;
                authidentitydata = ciptr;
        }
Esempio n. 12
0
 private static extern int CoSetProxyBlanket(IntPtr pProxy, RpcAuthnSrv authent, RpcAuthzSrv author,
                                                     string serverprinc, RpcAuthnLevel level, RpcImpersLevel impers,
                                                     IntPtr ciptr, int dwCapabilities);
Esempio n. 13
0
        public static object[] CoCreateInstanceEx(Guid clsid, ClsCtx ctx, string servername, Guid[] iids,
                                                        RpcAuthnSrv authent, RpcAuthzSrv author, string serverprinc,
                                                        RpcAuthnLevel level, RpcImpersLevel impers,
                                                        string domain,  string user, string password)
        {
            int num = iids.Length;
                MULTI_QI[] amqi = new MULTI_QI[num];

                IntPtr guidbuf = Marshal.AllocCoTaskMem(num * 16);    // allocate memory for IIDs
                for (int i = 0; i < num; i++)
                {
                    IntPtr piid = (IntPtr)((int)guidbuf + (i * 16));
                    Marshal.StructureToPtr(iids[i], piid, false);
                    amqi[i] = new MULTI_QI(piid);
                }

                COAUTHIDENTITY ci = new COAUTHIDENTITY(user, domain, password);
                IntPtr ciptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(ci));
                Marshal.StructureToPtr(ci, ciptr, false);

                COAUTHINFO ca;
                if (string.IsNullOrEmpty(user))
                {
                    ca = new COAUTHINFO(authent, author, serverprinc, level, impers, IntPtr.Zero /* ptr to coauth*/);
                }
                else
                {
                    ca = new COAUTHINFO(authent, author, serverprinc, level, impers, ciptr);

                }
                IntPtr captr = Marshal.AllocCoTaskMem(Marshal.SizeOf(ca));
                Marshal.StructureToPtr(ca, captr, false);

                COSERVERINFO cs = new COSERVERINFO(servername, captr);

                int hr = CoCreateInstanceEx(ref clsid, IntPtr.Zero, (int)ctx, cs, num, amqi);

                Marshal.DestroyStructure(captr, typeof(COAUTHINFO));
                Marshal.FreeCoTaskMem(captr);
                Marshal.FreeCoTaskMem(guidbuf);

                if (hr < 0)                    // FAILED()
                {
                    Marshal.DestroyStructure(ciptr, typeof(COAUTHIDENTITY));
                    Marshal.FreeCoTaskMem(ciptr);
                    return null;
                }

                int refcount;
                object[] ifret = new object[num];
                for (int i = 0; i < num; i++)
                {
                    if (amqi[i].hr != 0)
                    {
                        ifret[i] = (int)amqi[i].hr;
                        continue;
                    }

                    IntPtr ip = amqi[i].pItf;
                    amqi[i].pItf = IntPtr.Zero;
                    ifret[i] = Marshal.GetObjectForIUnknown(ip);
                    refcount = Marshal.Release(ip);
                    continue;
            #if COMPROXY

                    hr = CoSetProxyBlanket(ip, authent, author, serverprinc, level, impers, ciptr, 0);
                    if (hr < 0)                    // FAILED()
                        ifret[i] = (int)hr;
                    else
                        ifret[i] = Marshal.GetObjectForIUnknown(ip);

                    refcount = Marshal.Release(ip);
             #endif
                }

                Marshal.DestroyStructure(ciptr, typeof(COAUTHIDENTITY));
                Marshal.FreeCoTaskMem(ciptr);

                return ifret;
        }