image
image

Go Back   macosx.com > Mac Help Forums > HOWTO & FAQs

Reply
 
Thread Tools
  #1  
Old November 21st, 2002, 11:04 PM
~departed~
 
Join Date: Jul 2002
Location: Kansas City, MO
Posts: 457
Thanks: 0
Thanked 0 Times in 0 Posts
gatorparrots is on a distinguished road
How to change a user's home directory

First, it is always a good idea to read the existing information about the user:
niutil -read . /users/userx

The output will be generally similar to this:
Code:
authentication_authority: ;basic; ;LocalWindowsHash;
picture: /Library/User Pictures/Animals/Butterfly.tif
_shadow_passwd: 
hint: 
uid: 502
_writers_passwd: userx
realname: userx
_writers_hint: userx
gid: 20
shell: /bin/tcsh
name: userx
_writers_tim_password: userx
passwd: 3wbpLri9iMo
_writers_picture: userx
home: /Users/userx
sharedDir: Public
Here is the general syntax for the command line method for changing a user's home directory:
sudo niutil -createprop . /users/userx home "/Volumes/drivename/directory"
You're creating a property on top of one that already exists, overwriting the previous home directory (i.e. /Users/userx/) with the new one on another volume and directory altogether (on/Volumes/drivename/directory).

To confirm the changes, I recommend running the initial command again:
niutil -read . /users/userx

Code:
authentication_authority: ;basic; ;LocalWindowsHash;
picture: /Library/User Pictures/Animals/Butterfly.tif
_shadow_passwd: 
hint: 
uid: 502
_writers_passwd: userx
realname: userx
_writers_hint: userx
gid: 20
shell: /bin/tcsh
name: userx
_writers_tim_password: userx
passwd: 3wbpLri9iMo
_writers_picture: userx
home: /Volumes/drivename/directory
sharedDir: Public
And of course, you would want to
chmod -R 765 /Volumes/drivename/directory
and
chown -R userx /Volumes/drivename/directory
(or whatever is appropriate for your particular scenario).

Last edited by gatorparrots; November 21st, 2002 at 11:29 PM.
Reply With Quote
  #2  
Old November 22nd, 2002, 12:07 AM
~departed~
 
Join Date: Jul 2002
Location: Kansas City, MO
Posts: 457
Thanks: 0
Thanked 0 Times in 0 Posts
gatorparrots is on a distinguished road
How to change the lookup order of lookupd

First, create the path structure:
sudo niutil -create / /locations/lookupd/hosts
Then create the needed values:
sudo niutil -createprop / /locations/lookupd/hosts LookupOrder CacheAgent NIAgent DNSAgent

You want to modify the hosts lookup order, since this is responsible for resolving domain names.

Finally, restart lookupd to affect the changes:
sudo kill -HUP `cat /var/run/looupd.pid`

Last edited by gatorparrots; November 22nd, 2002 at 12:24 AM.
Reply With Quote
  #3  
Old November 22nd, 2002, 12:23 AM
~departed~
 
Join Date: Jul 2002
Location: Kansas City, MO
Posts: 457
Thanks: 0
Thanked 0 Times in 0 Posts
gatorparrots is on a distinguished road
How to add hostnames

On a local area network, it makes sense to have hostnames for various machines and to be able to access them via their hostname.

For example, you have "BigMac" and "Sidecar". The NetInfo databases on both machines needs to be updated to include the new hosname aliases.

Find out the IP address of each computer (if they are not known already). On each machine, issue this command:
ifconfig en0 inet

Next, add the new hostnames. Mac OS X relies on NetInfo instead of the traditional /etc/hosts file. (All of the commands below need root access, so rather than sudo each, it is more effecient to sudo -s and exit when done.)
sudo -s
niutil -create . /machines/BigMac
niutil -createprop . /machines/BigMac ip_address "192.168.1.2"
niutil -create . /machines/Sidecar
niutil -createprop . /machines/Sidecar ip_address "192.168.1.3"

Restart lookupd to register these changes:
kill -HUP `cat /var/run/lookupd.pid`
exit

Last edited by gatorparrots; December 8th, 2002 at 02:02 AM.
Reply With Quote
  #4  
Old November 22nd, 2002, 10:59 AM
NSCoder
 
Join Date: Oct 2002
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
anarchie is on a distinguished road
Note that if BigMac and Sidecar both run OS 10.2, they will be able to find each other's addresses using Rendezvous name resolution. If "local" is specified in Network Preferences' "Additional Search Domains", the names "BigMac" and "Sidecar" will resolve. If not, they can be looked up with "BigMac.local" and "Sidecar.local".
Reply With Quote
  #5  
Old December 6th, 2002, 02:49 AM
~departed~
 
Join Date: Jul 2002
Location: Kansas City, MO
Posts: 457
Thanks: 0
Thanked 0 Times in 0 Posts
gatorparrots is on a distinguished road
A caveat about changing the lookup order

Okay; now that we have the basics down, I have a real-world application. Our network is behind firewall/router that does not allow loopbacks. Therefore, changing the lookup order and adding machines entries to NetInfo to get local domain name resolution is the preferred method for adding entries to access our domain named e-mail server. This works fine for desktop machines within the confines of a LAN.

However, I have a laptop user to contend with who is not always on the network. He often travels and dials-up on the road. NetInfo 'machines' entries will trump his DNS resolution, making our domain-named e-mail and web server inaccessible to him when not behind our router/firewall.

The ideal solution(?) is to have the user switch lookup orders for when they are on the road and back when they are behind the network. I elected to create an AppleScript to do the job and install the Script Menu in the user's menubar to make the script easily accessible.

Overall, it seemed like the most effecient way to accomplish the goal. For those interested, here is the script in its enirety. (Save as an AppleScript application from Script Editor.)
Code:
(*
This script will set optimize your lookup order for a LAN internet connection  or dial-up
*)

set runresult to ""

tell me to activate
display dialog "Please choose your connection method to optimize your internet connection" buttons {"LAN", "Dial-up"} default button 2
set userchoice to button returned of result
if userchoice = "LAN" then
	repeat
		set theResponse to display dialog "Please enter your administrator password:" default answer "" with icon caution
		set thePassword to the text returned of theResponse
		try
			do shell script "sudo ls" password thePassword with administrator privileges
			exit repeat
		on error
			display dialog "Sorry, that password is invalid." buttons {"Cancel", "Try Again"} default button "Try Again" with icon stop
		end try
	end repeat
	try
		--LAN optimized
		tell application "Microsoft Entourage" to quit
		do shell script "sudo /usr/bin/niutil -create / /locations/lookupd/hosts" password thePassword with administrator privileges
		do shell script "sudo /usr/bin/niutil -createprop / /locations/lookupd/hosts LookupOrder CacheAgent NIAgent DNSAgent" password thePassword with administrator privileges
		do shell script "sudo /bin/kill -USR1 `/bin/cat /var/run/lookupd.pid`" password thePassword with administrator privileges
		do shell script "sleep 1"
		do shell script "/usr/bin/open '/Applications/Microsoft Office X/Microsoft Entourage'"
		do shell script "sleep 5"
		tell me to activate
		set runresult to "Network settings optimized for LAN connection" & return
	on error errormsj
		display dialog errormsj as string
		set runresult to runresult & "Settings change failed: " & errormsj & return
		--return adds ASCII13 to the output
	end try
	--end if
	
	tell me to activate
	display dialog (runresult as string) buttons {"Ok"}
	
else if userchoice = "Dial-up" then
	repeat
		set theResponse to display dialog "Please enter your administrator password:" default answer "" with icon caution
		set thePassword to the text returned of theResponse
		try
			do shell script "sudo ls" password thePassword with administrator privileges
			exit repeat
		on error
			display dialog "That's not a valid password!" buttons {"Cancel", "Try Again"} default button "Try Again" with icon stop
		end try
	end repeat
	try
		--Dial-up optimized
		tell application "Microsoft Entourage" to quit
		do shell script "/usr/bin/niutil -create / /locations/lookupd/hosts" password myPassword with administrator privileges
		do shell script "/usr/bin/niutil -createprop / /locations/lookupd/hosts LookupOrder CacheAgent DNSAgent NIAgent" password myPassword with administrator privileges
		do shell script "/bin/kill -USR1 `/bin/cat /var/run/lookupd.pid`" password myPassword with administrator privileges
		do shell script "sleep 1"
		do shell script "/usr/bin/open '/Applications/Microsoft Office X/Microsoft Entourage'"
		do shell script "sleep 5"
		tell me to activate
		--display progress
		set runresult to "Settings optimized for dial-up connection"
	on error errormsj
		display dialog errormsj as string
		set runresult to errormsj
	end try
	--end if
	tell me to activate
	display dialog ("Network Configuration:" & return & runresult) as string buttons {"Ok"}
end if

Last edited by gatorparrots; December 10th, 2002 at 04:10 PM.
Reply With Quote
  #6  
Old December 6th, 2002, 04:47 PM
wiz wiz is offline
Registered User
 
Join Date: Jul 2002
Location: Sol
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
wiz is on a distinguished road
this should be renamed and moved to the HowTos
Reply With Quote
  #7  
Old December 10th, 2002, 04:24 PM
~departed~
 
Join Date: Jul 2002
Location: Kansas City, MO
Posts: 457
Thanks: 0
Thanked 0 Times in 0 Posts
gatorparrots is on a distinguished road
I had to revise the script above to include a routine to quit/restart Microsoft Entourage (the MUA used) in order to get it to notice the lookup order change. Also, I revised the authentication scheme to be more robust (handling null or incorrectly entered passwords). Please update your copy if you have download the previous version I had posted/
Reply With Quote
Reply

Thread Tools

Posting 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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[HOWTO] - Find files of same type or creator as another file jverd Mac OS X System & Mac Software 3 March 19th, 2003 07:05 PM
[HOWTO] - Speed up DNS lookups in OSX Darkshadow HOWTO & FAQs 44 January 4th, 2003 05:15 AM
Correct procedure for adding users with niutil? Gwailo Unix & X11 2 July 7th, 2002 04:16 PM
niutil question crash Mac OS X System & Mac Software 1 June 6th, 2002 12:40 PM
the -niutil passwd jollewhoever Mac OS X System & Mac Software 0 April 25th, 2002 02:31 PM


All times are GMT -5. The time now is 11:43 AM.


Mac Support® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2000-2008 DigitalCrowd, Inc.