Пример #1
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;
 }
Пример #2
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);
        }
Пример #3
0
 public static extern int CoInitializeSecurity(IntPtr pVoid, int cAuthSvc, IntPtr asAuthSvc, IntPtr pReserved1,
                                               RpcAuthnLevel level, RpcImpersLevel impers, IntPtr pAuthList, int dwCapabilities, IntPtr pReserved3);
Пример #4
0
 private static extern int CoSetProxyBlanket(IntPtr pProxy, RpcAuthnSrv authent, RpcAuthzSrv author,
                                             string serverprinc, RpcAuthnLevel level, RpcImpersLevel impers,
                                             IntPtr ciptr, int dwCapabilities);
Пример #5
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;
        }
Пример #6
0
 private static extern int CoSetProxyBlanket(IntPtr pProxy, RpcAuthnSrv authent, RpcAuthzSrv author,
                                                     string serverprinc, RpcAuthnLevel level, RpcImpersLevel impers,
                                                     IntPtr ciptr, int dwCapabilities);
Пример #7
0
 public static extern int CoInitializeSecurity(IntPtr pVoid, int cAuthSvc, IntPtr asAuthSvc, IntPtr pReserved1,
         RpcAuthnLevel level, RpcImpersLevel impers, IntPtr pAuthList, int dwCapabilities, IntPtr pReserved3);
Пример #8
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;
        }