[Security] Fix not being able to change the authorization prompt (#3612)

When asking for user credentials it was not possible to change the
default authorization prompt message so the application name is used
by default. When running an application with Mono this will be
mono-sgen64 or mono-sgen32.

The prompt is now added to the environment authorization item set
passed to AuthorizationCreate. It was being passed as part of the
rights item set. This allows a custom message to be set in the
authorization dialog.
This commit is contained in:
Matt Ward 2018-03-01 15:33:30 +00:00 коммит произвёл Chris Hamons
Родитель de15337f61
Коммит 78e966d7ee
1 изменённых файлов: 15 добавлений и 11 удалений

Просмотреть файл

@ -172,17 +172,16 @@ namespace Security {
unsafe { unsafe {
if (parameters != null){ if (parameters != null){
ppars = &pars; ppars = &pars;
pars.ptrToAuthorization = (AuthorizationItem *) Marshal.AllocHGlobal (sizeof (AuthorizationItem) * 3); pars.ptrToAuthorization = (AuthorizationItem *) Marshal.AllocHGlobal (sizeof (AuthorizationItem) * 2);
if (parameters.PathToSystemPrivilegeTool != null) if (parameters.PathToSystemPrivilegeTool != null)
EncodeString (ref pars.ptrToAuthorization [pars.count++], "system.privilege.admin", parameters.PathToSystemPrivilegeTool); 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) if (parameters.IconPath != null)
EncodeString (ref pars.ptrToAuthorization [pars.count++], "prompt", parameters.IconPath); EncodeString (ref pars.ptrToAuthorization [pars.count++], "prompt", parameters.IconPath);
} }
if (environment != null){ if (environment != null || (parameters != null && parameters.Prompt != null)){
penv = &env; penv = &env;
env.ptrToAuthorization = (AuthorizationItem *) Marshal.AllocHGlobal (sizeof (AuthorizationItem) * 3); env.ptrToAuthorization = (AuthorizationItem *) Marshal.AllocHGlobal (sizeof (AuthorizationItem) * 4);
if (environment != null){
if (environment.Username != null) if (environment.Username != null)
EncodeString (ref env.ptrToAuthorization [env.count++], "username", environment.Username); EncodeString (ref env.ptrToAuthorization [env.count++], "username", environment.Username);
if (environment.Password != null) if (environment.Password != null)
@ -190,6 +189,11 @@ namespace Security {
if (environment.AddToSharedCredentialPool) if (environment.AddToSharedCredentialPool)
EncodeString (ref env.ptrToAuthorization [env.count++], "shared", null); EncodeString (ref env.ptrToAuthorization [env.count++], "shared", null);
} }
if (parameters != null){
if (parameters.Prompt != null)
EncodeString (ref env.ptrToAuthorization [env.count++], "prompt", parameters.Prompt);
}
}
code = AuthorizationCreate (ppars, penv, flags, out auth); code = AuthorizationCreate (ppars, penv, flags, out auth);
if (code != 0) if (code != 0)
return null; return null;