Tiger: how do I prompt for a "root" password?

Hi,
I’m fairly new at applescripting. Using panther, my script would run a shell script as such that it would prompt for an administrator password (in a dialog box) and then execute. Now that apple has changed the “do shell script” to run as setuid-root instead of root itself, I’m stuck.

Paste this into script editor:
do shell script “route add -net 10.174.0.0/16 10.170.78.1 2>&1” with administrator privileges

Note: this is only part of a larger script that involves other functions which still work well since they don’t need “root” privileges.

I now error out stating I need to run this as “root”. I have tried various combinations such as eliminating “with adminstrator privileges” and adding “sudo” before the “route add”, etc. What I need is a way to execute this with a prompt from the system to enter my root password.

I have to execute this script when I go into the office and connect to my company’s network.

Has anyone found a work around for the change to setuid-root when running “do shell script”. I’d really appreciate some help with this.

:frowning:

Model: Powerbook G4 AL 1.67ghz
AppleScript: 2.1
Browser: Safari 312
Operating System: Mac OS X (10.4)

I don’t understand your problem.

The ‘with administrator privileges’ should handle the authentication and provided you’re in the admin group you should be able to execute this command by entering your own user password.

Under Tiger, ‘do shell script’ accepts an additional parameter ‘username’ which lets you authenticate as a different user but, again, if you’re in the admin group the code as you have it should work.

When I execute my script as is and enter my admin password, I get the following AppleScript error:

Quote (from :

"AppleScript Error

route: must be root to alter routing table (77)"

This is my problem.

Prior to Tiger, “do shell script … with administrator privileges” executed the shell script as “root”. With Tiger, this has changed:

  1. You no longer need the term “with administator privileges” as this is now implied and will put up a dialog box to authenticate.
  2. “do shell script …” excutes now as “suid-root”, not “root”.

The above items are from the release notes.

Since “add route” needs to execute as root (not suid-root), I’m stuck unless someone has found a work around.

Can anyone else help with this problem?

Thanks.

Does this work?

set boomerang to "perl -Ue '$< = $>; system(@ARGV)' "
set the_script to "route add -net 10.174.0.0/16 10.170.78.1 2>&1"
do shell script boomerang & the_script with administrator privileges

Jon

Jon,

I’ll give it a try this weekend. I have too much on my plate this week.

Thanks for your help and I’ll let you know the results.

I also may have found another work around to try as a result of a shell scripting class I’m taking this week.

I’ll post the results (for both your’s and mine) this weekend.

Thanks again.

Thanks a lot for this trick, works great and very clever! :smiley:

Jon,

Sorry it took me so long to get back to you. I’ve been pretty busy with work (including weekends).

I just finished upgrading my primary system to Tiger.

YOUR SOLUTION WORKED LIKE A CHARM! :smiley:

Thank you very much.

HMG

You can also enable root user and change the UserName to root and enter your root password and it’ll work.