osx - STPrivilegedTask ask for password for each task -


i start lot of nstasks require root privilege, found should use apple's authorization kit , found stprivilegedtask, designed that.

the thing is, when start stprivilegedtask, ask me root password each time. there way enter root password first privileged task, , other tasks, application remember root password, user won't have enter password again , again , again?

depending on use case, might happy replacing initialization of authorizationref in stprivilegedtask -launch like...

// create authorization reference static authorizationref authorizationref = null; @synchronized(self) {     if (!authorizationref) {         err = authorizationcreate(null, kauthorizationemptyenvironment, kauthorizationflagdefaults, &authorizationref);         if (err != errauthorizationsuccess) { return err; }     } } 

... , removing authorizationfree:

// free auth ref authorizationfree(authorizationref, kauthorizationflagdefaults); 

that allow launch tasks without password prompt five minutes.

if need more control, create command line tool in xcode executes desired commands using normal nstask calls.

when launch tool using stprivilegedtask or authorizationexecutewithprivileges, nstask commands run administrator privileges (euid = 0).

smjobbless way launch tool going forward — if need perform privileged operations on regular basis, without prompting password.

it's much harder correctly using authorizationexecutewithprivileges.

notes on smjobbless

smjobbless prompts password & installs helper.

when talk helper, there no password prompt.

apple's own example on convoluted, there other examples out there.

some pages suggest application allowed talk helper. apple doesn't anywhere. after helper installed, i'm pretty sure anyone can talk it.

you enforce code signing requirements (property lists section of this document) yourself, couldn't find examples that.

i used authorizationexecutewithprivileges couple years ago install launchd daemon, have yet tangle smjobbless myself.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -