Deleting application password stored in Keychain on OS X

0

0

I'm trying to delete an application password. I'm using the security delete-generic-password command. When I execute it via terminal, everything works fine – it does delete the password.

When I include the same command in a shell script, and then execute it via Xcode, it does not delete the password. I guess the problem is that the security command can't get the root password.


I'm deleting it in an uninstaller, so before I execute anything, I'm asking for the root password. After that, I'm calling this script through the Xcode project. Since I already have the root password, I execute command with sudo as follows:

sudo security delete-generic-password password_name "/Library/Keychains/System.keychain"

I hope sudo does get the root password internally, as I'm already authenticating before executing anything in my uninstaller.

chitnisprasanna

Posted 2012-02-08T04:22:08.867

Reputation: 33

What's the return code of this command? – Daniel Beck – 2012-02-08T06:35:35.923

1By the way, you can edit your posts at any time to provide additional information. There is no need to delete previously posted questions and post essentially the same thing again. – Daniel Beck – 2012-02-08T08:48:39.730

I have identified the problem . the thing is when we execute command via terminal it asks for password and after we enter and if its correct it deletes the keychain. But if we use it in some script and try to execute it via Xcode project their is no UI that essential asks for password so it does not get password thats why it was not able to delete it . now i all want to know is how can we put up UI asking for password and then passing that password to the security command ... – chitnisprasanna – 2012-02-16T06:26:21.027

and when i checked in the Console it was giving this error no tty present and no askpass program specified ; TTY=unknown ; PWD=/ ; USER=root ;.. – chitnisprasanna – 2012-02-16T06:34:27.960

Do you need sudo when you already have the uninstaller on elevated privileges? Would it be possible to wrap the command in AppleScript's do shell script?

– Daniel Beck – 2012-02-16T07:10:54.923

ya sudo not required and currently i am using AuthorizationExecuteWithPrivileges API to execute the script it does executes it with root privileges but the command security again expects password so its giving error message which i had mentioned above – chitnisprasanna – 2012-02-17T10:27:52.997

You need to add the -l argument to delete the entry with name password_name. Does the deletion work when you enter and execute the following in AppleScript Editor: do shell script "security delete-generic-password -l password_name /Library/Keychains/System.keychain" with administrator privileges? – Daniel Beck – 2012-02-17T10:36:54.670

I am very new to apple scriptting could you please tell how can i execute it in applescript with administrator privileges?? – chitnisprasanna – 2012-02-20T06:11:58.407

Just copy the highlighted code snippet and paste it into AppleScript editor, and press the Go/Run button. with administrator privileges is part of the code snippet, as you can see from the monospaced font and highlighting. – Daniel Beck – 2012-02-20T06:15:32.630

yes it does delete – chitnisprasanna – 2012-02-20T06:42:33.760

1Then something's wrong with the environment in which you execute this code, and which you haven't explained in detail. If you want help, explain in detail how other users can reproduce the problem from scratch and without having ever written an OS X installer or uninstaller. Edit your question and add relevant information. – Daniel Beck – 2012-02-20T06:44:21.977

the command u give deletes the keychain....and is their anyway through which we can pass root password to applescript? ..because in current scenario initially i am authorizing the user when he tries to unintsall and while deleting this system keychain also again i am authenticating so the password dialog box appears twice ...can we do this just by using one dialog prompt only?? – chitnisprasanna – 2012-02-20T08:15:31.837

No answers