Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Login Programmatically on OS X

Login Programmatically on OS X
Thread Tools
ajcaruana
Fresh-Faced Recruit
Join Date: Nov 2009
Location: Malta
Status: Offline
Reply With Quote
Nov 17, 2009, 05:40 AM
 
Hi,

I am new to this forum. I am trying to create a daemon which will send user credentials to the OS X login window. I know that this is possible by means of an AppleScript, but this is giving trouble when logging in for the first time after the MAC is booted. Is there any other way to do this?

Thanks
Alan J. Caruana
     
chabig
Addicted to MacNN
Join Date: Jun 1999
Location: Las Vegas, NV, USA
Status: Offline
Reply With Quote
Nov 17, 2009, 01:33 PM
 
I didn't know this was possible with a "Mac". Wouldn't it be a security problem on a "Mac" if you could script the "Mac's" login credentials. There is already an option to auto-login after booting your "Mac".

P.S. Your computer is not a MAC. It's a Mac, which is short for Macintosh.
     
andi*pandi
Moderator
Join Date: Jun 2000
Location: inside 128, north of 90
Status: Offline
Reply With Quote
Nov 17, 2009, 02:35 PM
 
you mean like remote access?
     
larkost
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status: Offline
Reply With Quote
Nov 17, 2009, 09:50 PM
 
AppleScript is pretty useless for working at the loginwindow starting in 10.5, so that method is probably out (could be that interface scripting still works there, but most things crash when they try to access the WindowServer, this is by design).

But I was thinking this over a while ago, and think I came up with a method of doing it, but have never tested it out:

1) Write the appropriate value to /Library/Preferences/com.apple.loginwindow.plist : autoLoginUser

2) Move the appropriately obfuscated password for the user to /private/etc/kcpassword with the correct permissions.

3) Kill the /var/run/com.apple.loginwindow.didRunThisBoot file.

4) Kill the loginwindow process (the one owned by root) and let launchd autostart a new one.

Like I said, I have never tested this, but my thinking is that this will run through the normal process that the loginwindow goes through, and should auto-login the user. Most of this is just good guesswork, but I did have my hands into the API that the loginwindow uses for a project or two, so it is a well educated guess.

If killing that file does not do it, then you might have to setup something to watch the loginwindow process better while it is doing an autologin (there are ways of setting this up with Instruments/dtrace, but I don't know them).
     
ajcaruana  (op)
Fresh-Faced Recruit
Join Date: Nov 2009
Location: Malta
Status: Offline
Reply With Quote
Nov 18, 2009, 04:50 AM
 
you mean like remote access?
Just like a Remote Desktop Session. Similar to VNC, but I need to use a different protocol.
I didn't know this was possible with a "Mac". Wouldn't it be a security problem on a "Mac" if you could script the "Mac's" login credentials. There is already an option to auto-login after booting your "Mac".
Arguably, yes it could be a security problem, but if there is no API, I need to find a way to do it, and I do not know which user wants to login until the user actually connects to the daemon and sends his/her credentials.
AppleScript is pretty useless for working at the loginwindow starting in 10.5....
That's strange, as the only time this method does not work for me is when the Mac has just booted and nobody has logged in, otherwise it works, however thanks for the suggestion. I will try it out and let you know the outcome.
     
ajcaruana  (op)
Fresh-Faced Recruit
Join Date: Nov 2009
Location: Malta
Status: Offline
Reply With Quote
Nov 18, 2009, 04:51 AM
 
...
( Last edited by ajcaruana; Nov 18, 2009 at 04:53 AM. Reason: Emptied double entry which occurred because of timeout)
     
ajcaruana  (op)
Fresh-Faced Recruit
Join Date: Nov 2009
Location: Malta
Status: Offline
Reply With Quote
Nov 18, 2009, 07:11 AM
 
larkost,

I tried out your suggestion, but it did not work. Here is what I did:

1. enable auto-login, and reboot. This way I was sure that auto-login was being performed, and the obfuscated password is correct, and in the correct place.
2. killed the file /var/run/com.apple.loginwindow.didRunThisBoot
3. killed the only loginwindown process that was running.

The Mac turned to the loginwindow and did not login again. I also tried logging out before step 2, connecting via SSH to the Mac, and performing steps 2 & 3 via SSH, but the results did not change.
     
Warhaven
Dedicated MacNNer
Join Date: Jul 2002
Status: Offline
Reply With Quote
Nov 18, 2009, 05:17 PM
 
Originally Posted by ajcaruana View Post
Hi,

I am new to this forum. I am trying to create a daemon which will send user credentials to the OS X login window. I know that this is possible by means of an AppleScript, but this is giving trouble when logging in for the first time after the MAC is booted. Is there any other way to do this?

Thanks
Alan J. Caruana
Can I see the AppleScript you were attempting to use that was giving you problem? I use AppleScript just fine to log in to an entire lab of computers from time to time. Haven't had any problems with it. Here's what I use via ARD's Send Unix Command (as user root):

Code:
osascript -e ' set login to "" set passwd to "" tell application "System Events" keystroke login delay 1 key down return delay 1 keystroke passwd delay 0.5 key down return end tell'
Change the first instance of "key down return" to "keystroke tab" if you're using the login/passsword prompt instead of the list of users. And of course, insert username and password into the script.
     
larkost
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status: Offline
Reply With Quote
Nov 18, 2009, 10:06 PM
 
Originally Posted by ajcaruana View Post
larkost, I tried out your suggestion, but it did not work. Here is what I did:
Like I said, I have never actually implemented this, so I am not too surprised. But that is probably a start of what you have to do to get this going.
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 05:02 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,