Exemplo n.º 1
0
		public static Authorization Create (AuthorizationParameters parameters, AuthorizationEnvironment environment, AuthorizationFlags flags)
		{
			AuthorizationItem *pars = null;
			AuthorizationItem *env = null;
			int npars = 0, nenv = 0;
			int code;
			IntPtr auth;

			try {
				unsafe {
					if (parameters != null){
						pars = (AuthorizationItem *) Marshal.AllocHGlobal (sizeof (AuthorizationItem) * 3);
						if (parameters.PathToSystemPrivilegeTool != null)
							EncodeString (ref pars [npars++], "system.privilege.admin", parameters.PathToSystemPrivilegeTool);
						if (parameters.Prompt != null)
							EncodeString (ref pars [npars++], "prompt", parameters.Prompt);
						if (parameters.IconPath != null)
							EncodeString (ref pars [npars++], "prompt", parameters.IconPath);
					}
					if (environment != null){
						env = (AuthorizationItem *) Marshal.AllocHGlobal (sizeof (AuthorizationItem) * 3);
						if (environment.Username != null)
							EncodeString (ref pars [nenv++], "username", environment.Username);
						if (environment.Password != null)
							EncodeString (ref pars [nenv++], "password", environment.Password);
						if (environment.AddToSharedCredentialPool != null)
							EncodeString (ref pars [nenv++], "shared", null);
					}
					code = AuthorizationCreate (pars, env, flags, out auth);
					if (code != 0)
						return null;
					return new Authorization (auth);
				}
			} finally {
				if (pars != null){
					for (int i = 0; i < npars; i++){
						Marshal.FreeHGlobal (pars [i].name);
						Marshal.FreeHGlobal (pars [i].value);
					}
					Marshal.FreeHGlobal ((IntPtr)pars);
				}
				if (env != null){
					for (int i = 0; i < npars; i++){
						Marshal.FreeHGlobal (pars [i].name);
						if (pars [i].value != IntPtr.Zero)
							Marshal.FreeHGlobal (pars [i].value);
					}
					Marshal.FreeHGlobal ((IntPtr)env);
				}
			}
		}
Exemplo n.º 2
0
		public static Authorization Create (AuthorizationParameters parameters, AuthorizationEnvironment environment, AuthorizationFlags flags)
		{
			AuthorizationItemSet pars = new AuthorizationItemSet ();
			AuthorizationItemSet *ppars = null;
			AuthorizationItem *pitems = null;
			AuthorizationItemSet env = new AuthorizationItemSet ();
			AuthorizationItemSet *penv = null;
			AuthorizationItem *eitems = null;
			int code;
			IntPtr auth;

			try {
				unsafe {
					if (parameters != null){
						ppars = &pars;
						pars.ptrToAuthorization = (AuthorizationItem *) Marshal.AllocHGlobal (sizeof (AuthorizationItem) * 3);
						if (parameters.PathToSystemPrivilegeTool != null)
							EncodeString (ref pars.ptrToAuthorization [pars.count++], "system.privilege.admin", parameters.PathToSystemPrivilegeTool);
						if (parameters.Prompt != null)
							EncodeString (ref pars.ptrToAuthorization [pars.count++], "prompt", parameters.Prompt);
						if (parameters.IconPath != null)
							EncodeString (ref pars.ptrToAuthorization [pars.count++], "prompt", parameters.IconPath);
					}
					if (environment != null){
						penv = &env;
						env.ptrToAuthorization = (AuthorizationItem *) Marshal.AllocHGlobal (sizeof (AuthorizationItem) * 3);
						if (environment.Username != null)
							EncodeString (ref env.ptrToAuthorization [env.count++], "username", environment.Username);
						if (environment.Password != null)
							EncodeString (ref env.ptrToAuthorization [env.count++], "password", environment.Password);
						if (environment.AddToSharedCredentialPool)
							EncodeString (ref env.ptrToAuthorization [env.count++], "shared", null);
					}
					code = AuthorizationCreate (ppars, penv, flags, out auth);
					if (code != 0)
						return null;
					return new Authorization (auth);
				}
			} finally {
				if (ppars != null){
					for (int i = 0; i < pars.count; i++){
						Marshal.FreeHGlobal (pars.ptrToAuthorization [i].name);
						Marshal.FreeHGlobal (pars.ptrToAuthorization [i].value);
					}
					Marshal.FreeHGlobal ((IntPtr)pars.ptrToAuthorization);
				}
				if (penv != null){
					for (int i = 0; i < env.count; i++){
						Marshal.FreeHGlobal (env.ptrToAuthorization [i].name);
						if (env.ptrToAuthorization [i].value != IntPtr.Zero)
							Marshal.FreeHGlobal (env.ptrToAuthorization [i].value);
					}
					Marshal.FreeHGlobal ((IntPtr)env.ptrToAuthorization);
				}
			}
		}
        public static Authorization Create(AuthorizationParameters parameters, AuthorizationEnvironment environment, AuthorizationFlags flags)
        {
            AuthorizationItemSet  pars   = new AuthorizationItemSet();
            AuthorizationItemSet *ppars  = null;
            AuthorizationItem *   pitems = null;
            AuthorizationItemSet  env    = new AuthorizationItemSet();
            AuthorizationItemSet *penv   = null;
            AuthorizationItem *   eitems = null;
            int    code;
            IntPtr auth;

            try
            {
                unsafe
                {
                    if (parameters != null)
                    {
                        ppars = &pars;
                        pars.ptrToAuthorization = (AuthorizationItem *)Marshal.AllocHGlobal(sizeof(AuthorizationItem) * 3);
                        if (parameters.PathToSystemPrivilegeTool != null)
                        {
                            EncodeString(ref pars.ptrToAuthorization [pars.count++], "system.privilege.admin", parameters.PathToSystemPrivilegeTool);
                        }
                        if (parameters.Prompt != null)
                        {
                            EncodeString(ref pars.ptrToAuthorization [pars.count++], "prompt", parameters.Prompt);
                        }
                        if (parameters.IconPath != null)
                        {
                            EncodeString(ref pars.ptrToAuthorization [pars.count++], "prompt", parameters.IconPath);
                        }
                    }
                    if (environment != null)
                    {
                        penv = &env;
                        env.ptrToAuthorization = (AuthorizationItem *)Marshal.AllocHGlobal(sizeof(AuthorizationItem) * 3);
                        if (environment.Username != null)
                        {
                            EncodeString(ref env.ptrToAuthorization [env.count++], "username", environment.Username);
                        }
                        if (environment.Password != null)
                        {
                            EncodeString(ref env.ptrToAuthorization [env.count++], "password", environment.Password);
                        }
                        if (environment.AddToSharedCredentialPool)
                        {
                            EncodeString(ref env.ptrToAuthorization [env.count++], "shared", null);
                        }
                    }
                    code = AuthorizationCreate(ppars, penv, flags, out auth);
                    if (code != 0)
                    {
                        return(null);
                    }
                    return(new Authorization(auth));
                }
            }
            finally
            {
                if (ppars != null)
                {
                    for (int i = 0; i < pars.count; i++)
                    {
                        Marshal.FreeHGlobal(pars.ptrToAuthorization [i].name);
                        Marshal.FreeHGlobal(pars.ptrToAuthorization [i].value);
                    }
                    Marshal.FreeHGlobal((IntPtr)pars.ptrToAuthorization);
                }
                if (penv != null)
                {
                    for (int i = 0; i < env.count; i++)
                    {
                        Marshal.FreeHGlobal(env.ptrToAuthorization [i].name);
                        if (env.ptrToAuthorization [i].value != IntPtr.Zero)
                        {
                            Marshal.FreeHGlobal(env.ptrToAuthorization [i].value);
                        }
                    }
                    Marshal.FreeHGlobal((IntPtr)env.ptrToAuthorization);
                }
            }
        }