Example #1
0
        internal static unsafe void FreeNative(NativeAuthorizationItemSet *itemsPtr)
        {
            if (itemsPtr == null)
            {
                return;
            }

            var items = *itemsPtr;

            if (items.items == null)
            {
                return;
            }

            for (int i = 0; i < items.count; i++)
            {
                if (items.items [i].name != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(items.items [i].name);
                }

                if (items.items [i].value != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(items.items [i].value);
                }
            }

            Marshal.FreeHGlobal((IntPtr)items.items);
        }
Example #2
0
        public static Authorization Create(
            AuthorizationRights rights,
            AuthorizationEnvironment environment,
            AuthorizationFlags flags)
        {
            NativeAuthorizationItemSet  rightsNative = new NativeAuthorizationItemSet();
            NativeAuthorizationItemSet *rightsPtr    = null;

            NativeAuthorizationItemSet  envNative = new NativeAuthorizationItemSet();
            NativeAuthorizationItemSet *envPtr    = null;

            int    code;
            IntPtr auth;

            try {
                if (rights != null && rights.Count > 0)
                {
                    rights.ToNative(ref rightsNative);
                    rightsPtr = &rightsNative;
                }

                if (environment != null)
                {
                    environment.ToAuthorizationItemSet().ToNative(ref envNative);
                    if (envNative.count > 0)
                    {
                        envPtr = &envNative;
                    }
                }

                code = AuthorizationCreate(rightsPtr, envPtr, flags, out auth);
                if (code != 0)
                {
                    return(null);
                }

                return(new Authorization(auth));
            } finally {
                AuthorizationItemSet.FreeNative(rightsPtr);
                AuthorizationItemSet.FreeNative(envPtr);
            }
        }
Example #3
0
 extern static int /* OSStatus = int */ AuthorizationCreate(NativeAuthorizationItemSet *rights, NativeAuthorizationItemSet *environment, AuthorizationFlags flags, out IntPtr auth);