Ejemplo n.º 1
0
 public virtual void Dispose(AuthorizationFlags flags, bool disposing)
 {
     if (Handle != IntPtr.Zero && Owns)
     {
         AuthorizationFree(Handle, flags);
     }
     base.Dispose(disposing);
 }
Ejemplo n.º 2
0
 public virtual void Dispose(AuthorizationFlags flags, bool disposing)
 {
     if (handle != IntPtr.Zero)
     {
         AuthorizationFree(handle, flags);
         handle = IntPtr.Zero;
     }
 }
Ejemplo n.º 3
0
        public static bool Upgrade(Authorization auth, AuthorizationFlags flags)
        {
            Logging.Info("Upgrading old helper with the new one...");

            // Hack to force "authentication required" window to pop-up;
            auth.ExecuteWithPrivileges("/bin/echo", flags, new string[] { });

            if (!Uninstall(auth))
            {
                Logging.Info("Uninstallation seems not complete successfuly.");
            }

            return(InstallHelper(auth));
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
        public int ExecuteWithPrivileges(string pathToTool, AuthorizationFlags flags, string []?args)
        {
            string?[]? arguments = args !;

            if (arguments is not null)
            {
                // The arguments array must be null-terminated, so make sure that's the case
                if (arguments.Length == 0)
                {
                    arguments = new string? [] { null };
                }
                else if (arguments [arguments.Length - 1] is not null)
                {
                    var array = new string? [arguments.Length + 1];
                    arguments.CopyTo(array, 0);
                    arguments = array;
                }
            }

            return(AuthorizationExecuteWithPrivileges(Handle, pathToTool, flags, arguments, IntPtr.Zero));
        }
Ejemplo n.º 6
0
		extern static int AuthorizationFree (IntPtr handle, AuthorizationFlags flags);
Ejemplo n.º 7
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);
				}
			}
		}
Ejemplo n.º 8
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);
                }
            }
        }
Ejemplo n.º 9
0
 public static Authorization Create(AuthorizationFlags flags)
 {
     return(Create(null, null, flags));
 }
Ejemplo n.º 10
0
		extern static int AuthorizationCreate (AuthorizationItemSet *rights, AuthorizationItemSet *environment, AuthorizationFlags flags, out IntPtr auth);
Ejemplo n.º 11
0
		public static Authorization Create (AuthorizationFlags flags)
		{
			return Create (null, null, flags);
		}
Ejemplo n.º 12
0
 extern static int /* OSStatus = int */ AuthorizationExecuteWithPrivileges(IntPtr handle, string pathToTool, AuthorizationFlags flags, string [] args, IntPtr FILEPtr);
Ejemplo n.º 13
0
 extern static int /* OSStatus = int */ AuthorizationCreate(AuthorizationItemSet *rights, AuthorizationItemSet *environment, AuthorizationFlags flags, out IntPtr auth);
 extern static int AuthorizationFree(IntPtr handle, AuthorizationFlags flags);
Ejemplo n.º 15
0
		public int ExecuteWithPrivileges (string pathToTool, AuthorizationFlags flags, string [] args)
		{
			return AuthorizationExecuteWithPrivileges (handle, pathToTool, flags, args, IntPtr.Zero);
		}
Ejemplo n.º 16
0
		public virtual void Dispose (AuthorizationFlags flags, bool disposing)
		{
			if (handle != IntPtr.Zero){
				AuthorizationFree (handle, flags);
				handle = IntPtr.Zero;
			}
		}
Ejemplo n.º 17
0
 extern static int /* OSStatus = int */ AuthorizationFree(IntPtr handle, AuthorizationFlags flags);
Ejemplo n.º 18
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);
				}
			}
		}
Ejemplo n.º 19
0
 public int ExecuteWithPrivileges(string pathToTool, AuthorizationFlags flags, string [] args)
 {
     return(AuthorizationExecuteWithPrivileges(handle, pathToTool, flags, args, IntPtr.Zero));
 }
Ejemplo n.º 20
0
		extern static int AuthorizationExecuteWithPrivileges (IntPtr handle, string pathToTool, AuthorizationFlags flags, string [] args, IntPtr FILEPtr);
Ejemplo n.º 21
0
 public static Authorization Create(
     AuthorizationParameters parameters,
     AuthorizationEnvironment environment,
     AuthorizationFlags flags)
 => Create(parameters?.ToAuthorizationRights(), environment, flags);