Mac OS X Unleashed

Mac OS X Unleashed

By John Ray and William C. Ray

Getting to Know the NetInfo Database

In this section, we will get to know the NetInfo database. We will use the NetInfo Manager to examine parts of the NetInfo database. Then we will actually make a change to the NetInfo database by adding a printer to the system. We will demonstrate how to add a printer using the NetInfo Manager entirely. Then we will add a printer by using the Print Center in conjunction with the NetInfo Manager. In the final portion of this section, we will integrate command-line usage while examining some of the NetInfo database and adding a printer.

Using the NetInfo Manager to Examine the NetInfo Database

The NetInfo Manager (path: /Applications/Utilities/NetInfo Manager) is the graphical interface to the NetInfo database. Using the NetInfo Manager to examine some of the contents of your NetInfo database is the easiest way to see the hierarchical arrangement of the database.

When you first start the NetInfo Manager, under the Domain menu, you open the NetInfo database on your machine by choosing Open. This opens a window from which you can select a domain. The only choice is to select the / domain, as shown in Figure 23.1.

23fig01.jpg

Figure 23.1 Opening your machine's NetInfo database from the top level.

Your machine's local NetInfo database also has the name, or tag, local. When you looked at the Domain menu, you might have noticed the option to Open by Tag. If you try to Open by Tag rather than Open, the dialog box shown in Figure 23.2 asks for the host name or IP address and the NetInfo database tag. Possible entries you can use for your own host include its IP address, localhost, or 127.0.0.1. For the tag, enter local.

23fig02.jpg

Figure 23.2 Opening your machine's NetInfo database by tag.

No matter which way you choose to open your NetInfo database, the result is the same, except that how the name of the local database is displayed might vary. Figure 23.3 shows what you get if you choose to open your NetInfo database using Open and selecting the default domain. Here the name is displayed as local@localhost.biosci.ohio-state.edu - /. In our case, the Open By Tag window displays the database as local@localhost.

23fig03.jpg

Figure 23.3 The top level of your NetInfo database, as seen in the NetInfo Manager.

As you can see in Figure 23.3, the hierarchical nature of the NetInfo database is immediately apparent. In the left window, it's in the top level, /. In the second window, there is a list of directories. If you scroll through the list, you will see some of the types of information that the NetInfo database stores. In the lower window are the properties for a given directory. In Figure 23.3, we see the properties for the / directory. We see that our machine is the master of its local database, and we see that we could add a list of trusted networks.

Let's examine the NetInfo database a bit using the NetInfo Manager. If we click the aliases directory in the second window, more data appears in the third window. In the bottom window, we see the property values for the aliases directory. It only has a property called name with a value of aliases. Yes, the name property is indeed the name of the directory. The third window displays the actual contents of the aliases directory. The folder to the right, just above the right window, shows where we are currently in the hierarchy. Figure 23.4 shows where we are at this point.

23fig04.jpg

Figure 23.4 The third window shows the contents of the aliases directory. The bottom window shows any properties associated with the aliases directory.

If we click a directory, postmaster, in the third window, we see that we have reached the end of the hierarchy. What was the third window is now the second window. The third window has no data. The folder above the right window shows where we are in the hierarchy, /aliases/postmaster. The bottom window shows the properties of the postmaster directory. In addition to the name property, we see that the postmaster directory also has a members property with a value of root. What we learn from Figure 23.5 is that postmaster is aliased to root. The portion of the NetInfo database that we just looked at is what, in Unix machines, is usually stored in the file /etc/aliases or /etc/mail/aliases, depending on the system.

23fig05.jpg

Figure 23.5 The bottom window shows the contents of the postmaster directory. The lack of data in the third window shows that we have reached the end of the hierarchy.

Let's look at something else in the NetInfo database. If we scroll back one window and click services, we see the same behavior we saw with the aliases directory. It only has a name property. Similar to the aliases directory, it has additional directories under it as displayed in the third window. The third window has enough directories to have to scroll through the listing. If you scroll to the ssh service and click it, you see what is shown in Figure 23.6.

23fig06.jpg

Figure 23.6 The contents of the /services/ssh directory of the NetInfo database.

In Figure 23.6, we see that the /services/ssh directory of the NetInfo database contains a name property with value ssh, a port property with value 22 and a protocol property with value tcp. As you might have guessed, this is NetInfo's way of displaying information that would normally be stored in a file, /etc/services, on a typical Unix machine. The ssh service itself, will be discussed in greater detail in Chapter 26, "Remote Administration."

As we have seen in our brief tour of the NetInfo database, the hierarchical nature of the database indeed becomes apparent when viewed in the NetInfo Manager.

Single-User Mode

Now that you have had the opportunity to briefly tour the NetInfo database, you might be starting to see that the NetInfo database is an important part of OS X. Consequently, it is good practice to regularly back up the NetInfo database before you make any changes to it. We will learn how to do that shortly.

You might be making your backups of the database in single-user mode. Even if you don't end up making the backups in single-user mode, there is bound to be a time when you make a change to the NetInfo database that does not work at all. Or, you might accidentally delete all of it, if you selected the wrong directory. In any case, at some point in time, you might have to restore your NetInfo database from single-user mode.

Whether it is for backing up or restoring, it is best to familiarize yourself with single-user mode ahead of time. The appearance of single-user mode on a Macintosh can be quite disturbing. It is best to have some idea of what to expect before you really need to be in single-user mode.

So, what is single-user mode? It is a quiet state of the machine. In single-user mode, root is the only user who can access the machine. Only a minimum number of processes are running. Only a minimum number of partitions are mounted.

To get into single-user mode, press Command + S, while the machine is booting or rebooting. When the Macintosh boots into single-user mode, it looks much like a PC. You will see a black background and text in various colors scroll by. The final portion of what appears on the screen is this:

Singleuser boot - fsck not done
Root device is mounted read-only
If you want to make modifications to files,
run '/sbin/fsck -y' first and then '/sbin/mount -uw /'
localhost#

Not all OS X machines appear to boot into single-user mode with the root device mounted read-only. Be sure to look carefully at the lines of output before the localhost prompt. If you need to modify any files, such as making a backup or restoring the NetInfo database, be sure to follow the indicated instructions. Otherwise, you will not be able to make any changes. It is helpful to know what behavior to expect from your system ahead of time, so that you don't panic. Because root is the only user in single-user mode, it is important to be calm and pay close attention to what you're doing.

While you are in single-user mode, you might be interested in running ps, just to see what processes run in single-user mode. When you return to multi-user mode, try running ps again to see the difference.

To return to multi-user mode, issue the command

sync;sync;sync;reboot

The first three commands, sync, force the system to complete any disk writes before rebooting. It is tradition to issue the command three times. Then reboot is executed.

After seeing your machine once in single-user mode, you are better prepared for any emergencies you might encounter by the end of the chapter.

Using the NetInfo Manager to Add a Printer

After a brief tour of the NetInfo database, you should feel a bit more comfortable navigating through the database in the NetInfo Manager. This is a useful skill for what we are about to do—add a printer to the NetInfo database. Because it is common in a Unix environment for one host to serve a printer that can be used by other hosts, the printer we will add to our system is a PostScript printer that is served by another Unix machine. After we are done adding the printer, we will be able to print directly from the command line, rather than having to resort to selecting Print in the Terminal application.

Creating a Backup of the Local NetInfo Database

Given the importance of the NetInfo database to your machine's functioning, it is best to back up the NetInfo database before making any major changes to it. You can back up the NetInfo database at either the command line or in the NetInfo Manager. In the command line, you could use cp or tar to create your backup. The NetInfo database is the directory /var/db/netinfo/local.nidb. When backing up the NetInfo database from the command line, Apple recommends making the back up in single-user mode.

localhost# cp -R local.nidb local.nidb-backup
lccalhost# tar -cf local.nidb-backup.tar local.nidb

If you prefer, you can back up the database in the NetInfo Manager. Click the lock in the bottom left side of the window to make changes, enter the administrator username and password, and click OK. Under the Domain menu, select Save Backup. Then pick a name and location. As shown in Figure 23.7, the default name is local.nibak and the default location is in /var/db/netinfo/. Please note that backing up the NetInfo database through the NetInfo Manager can take a long time. We recommend that you back up the NetInfo database using the command line, especially as you customize the database more and more.

23fig07.jpg

Figure 23.7 In addition to using the command line, the NetInfo database can be backed up directly in the NetInfo Manager.

No matter which method you use to make your backup, remember to double-check /var/db/netinfo to verify that it has been made:

localhost# ls -l local.nidb-backup

     total 136
     -rw-------  1 root  wheel      4 May  3 10:09 Clean
     -rw-r--r--  1 root  wheel      4 May  3 10:09 Config
     -rw-------  1 root  wheel   2656 May  3 10:09 Index
     -rw-r--r--  1 root  wheel   9216 May  3 10:09 Store.128
     -rw-------  1 root  wheel   1472 May  3 10:09 Store.1472
     -rw-r--r--  1 root  wheel  10720 May  3 10:09 Store.160
     -rw-r--r--  1 root  wheel   1344 May  3 10:09 Store.192
     -rw-------  1 root  wheel    224 May  3 10:09 Store.224
     -rw-r--r--  1 root  wheel   2464 May  3 10:09 Store.352
     -rw-------  1 root  wheel    416 May  3 10:09 Store.416
     -rw-------  1 root  wheel   2560 May  3 10:09 Store.640
     -rw-------  1 root  wheel    672 May  3 10:09 Store.672
     -rw-r--r--  1 root  wheel   1344 May  3 10:09 Store.96

localhost# ls -l local.nidb-backup.tar

     -rw-r--r--  1 root  wheel  51200 May  3 10:10 local.nidb-backup.tar

[localhost:/var/db/netinfo] root# ls -l local.nibak

     total 136
     -rw-------  1 root  wheel      4 May  3 09:58 Clean
     -rw-r--r--  1 root  wheel      4 Apr  4 12:20 Config
     -rw-------  1 root  wheel   2656 May  3 09:58 Index
     -rw-r--r--  1 root  wheel   9216 Apr 27 17:15 Store.128
     -rw-------  1 root  wheel   1472 Apr  4 12:47 Store.1472
     -rw-r--r--  1 root  wheel  10720 Apr 27 17:15 Store.160
     -rw-r--r--  1 root  wheel   1344 Apr 27 17:15 Store.192
     -rw-------  1 root  wheel    224 May  1 10:29 Store.224
     -rw-r--r--  1 root  wheel   2464 Apr  4 14:55 Store.352
     -rw-------  1 root  wheel    416 Apr 27 13:08 Store.416
     -rw-------  1 root  wheel   2560 Apr 27 17:15 Store.640
     -rw-------  1 root  wheel    672 Apr 16 12:37 Store.672
     -rw-r--r--  1 root  wheel   1344 May  1 10:29 Store.96

Modifying the NetInfo Database

After you are satisfied that your backup does indeed exist, you are ready to change your NetInfo database. To add a printer through the NetInfo Manager, we have widened the view a bit and increased the amount of space available for the values section. If you have a remote LaserWriter printer, we recommend that you do the same.

As we observed in the previous section, the NetInfo database is the information warehouse used by your OS X machine, instead of where files would ordinarily be used on other Unix systems. For printers, the equivalent file on some Unix systems is /etc/printcap. You might want to take a look at the man page for printcap to familiarize yourself with some of the values we will enter. Other Unix systems do not use /etc/printcap at all. Although printing on those systems seems a bit more magical, when the magic is working, it works well and seamlessly from the user's perspective.

To add a PostScript printer served by another Unix machine, do the following:

  1. If you are not already in NetInfo Manager, start it up; then open your local database.
  2. As you probably noticed in the previous section, the values shown in the bottom window of the NetInfo Manager were grayed out, and therefore could not be edited. To make changes to the NetInfo database, click the lock in the bottom-left side of the window. Enter the administrator username and password, and click OK. If you backed up your NetInfo database using the NetInfo Manager, this step is unnecessary.
  3. Click the printers directory. In the bottom window, you will see that the printers directory only has a name property with a value of printers. In the right window, you will see nothing. At this time, we are at the end of the hierarchy.
  4. Under the Directory menu, select New Directory. Notice that a directory, called new_directory, appears in the window to the right of where printers is located. Notice also that, in the bottom window, the new_directory only has a name property with value new_directory, as shown in Figure 23.8.
    23fig08.jpg

    Figure 23.8 To add a printer definition to the printers directory, select New Subdirectory under the Directory menu. A new directory called new_directory is created.

  5. Change the name of new_directory to the name that we want to call our printer—lp. Double-click new_directory in the bottom window, and change the name to lp. You might have to wait a couple seconds before you can edit the value.
  6. Now new_directory has one property called name with a value of lp. We need more values than that to define our printer, though. Under the Directory menu, select Insert Property, New Property, or Append Property. Insert Property and New Property add a new property above the name line. Append Property adds a new line following the name line. For this example, it shouldn't matter which you pick. Now a new line with a new_property with a grayed-out value of <no_value> is added, as shown in Figure 23.9. It doesn't matter where in the list the new_property lands. The NetInfo database will sort everything.
    23fig09.jpg

    Figure 23.9 Under the Directory menu, select either Insert Property or Append Property to add a new property. A new property called new_property with a grayed-out value of <no_value> is added.

  7. As you did before for the lp value, double-click new_property. Change it to lo. To change the value, select New Value or Insert Value under the Directory menu. Now <no_value> becomes an editable new value. Change it to lock. You should have two lines that look like the ones shown in Figure 23.10.
    23fig10.jpg

    Figure 23.10 After adding a new property and editing its values, we now have two lines in our printer definition.

  8. Using the techniques described in the previous steps, add the following lines to further define lp:
    Property Value(s)
    rp <name of the remote printer as it is known to the remote host>
    rm <IP address or name of the remote machine>
    lp /dev/null
    sd /var/spool/lpd/lp
    LPR_PRINTER 1
  9. In a terminal window, look at this directory: /System/Library/Printers/PPDs/Contents/Resources. You should see a listing of directories of the form <language>.lproj. Here is what the English.lproj directory looks like:
    [localhost:PPDs/Contents/Resources] joray% ls English.lproj
    
    LaserWriter                             LaserWriter IIf v2010.130
    LaserWriter 12_640 PS                   LaserWriter IIg v2010.113
    LaserWriter 16_600 PS                   LaserWriter IIg v2010.130
    LaserWriter 16_600 PS Fax               LaserWriter Personal 320
    LaserWriter 16_600 PS-J                 LaserWriter Personal NT
    LaserWriter 4_600 PS                    LaserWriter Personal NTR
    LaserWriter 8500 PPD v1.2               LaserWriter Pro 400 v2011.110
    LaserWriter Color 12_600 PS             LaserWriter Pro 405 v2011.110
    LaserWriter Color 12_600 PS-J           LaserWriter Pro 600 v2010.130
    LaserWriter Color 12_660 PS             LaserWriter Pro 630 v2010.130
    LaserWriter II NT                       LaserWriter Pro 810
    LaserWriter II NTX                      LaserWriter Pro 810f
    LaserWriter II NTX v50.5                LaserWriter Select 360
    LaserWriter II NTX v51.8                LaserWriter Select 360f
    LaserWriter II NTX-J v50.5              LaserWriter Select 610
    LaserWriter IIf v2010.113
    
    That directory contains the default English PPDs that come with OS X. If you see a PPD for your remote printer, add a line to the lp definition that follows the form shown here for a LaserWriter Select 360:
    Ppdurl        file://localhost/System/Library/Printers/PPDs/Contents/Resources/English
    
                ccc.gif
             .lproj/LaserWriter%20Select%20360
    
    If your printer could be described as a generic PostScript printer, this line should be fine:
    ppdurl      <no_value>
    
    If you have another PPD file for your printer on the system, specify its location.
  10. Now you have entered all the values to define a PostScript printer attached to a remote host. Figure 23.11 shows what values for a remote LaserWriter 360 attached to another Unix system would look like.
    23fig11.jpg

    Figure 23.11 Completed values for a remote PostScript printer. In this case, we know that the remote PostScript printer is a LaserWriter Select 360.

  11. To save our changes to the NetInfo database, select Save, under the Domain menu.
  12. A request to Confirm Modification appears. Click Update this copy. Now the new_directory has been changed to lp, as shown in Figure 23.12.
    23fig12.jpg

    Figure 23.12 After saving our changes to the NetInfo database, we see that the directory called new_directory has become lp. We have successfully added a new hierarchy level to the NetInfo database.

  13. Under the Options menu, select Restart All NetInfo Domains on Local Host. An alert asking if you really want to restart the machine's NetInfo servers appears. Click Yes.
  14. Click the lock at the bottom-left side of the window to end your ability to make changes at this time; then close the NetInfo Manager. You may find it sufficient to just click on the lock to save your changes.

Adding the Printer to the Print Center

We have updated the NetInfo database. To be able to use this printer in regular applications, including the capability to print from the menu in the Terminal application, we need to add the printer to the Printer List in the Print Center.

  1. Start the Print Center (path: /Applications/Utilities/Print Center). Either under Printers, select Add Printer, or click Add Printer in the Printer List.
  2. Select the Directory Services connection type. You should lp listed as NetInfo host, as shown in Figure 23.13. Click Add.
    23fig13.jpg

    Figure 23.13 When we add our printer lp to the list of printers in the Print Center, lp appears as a choice under Directory Services and is described as a NetInfo host.

  3. You are almost ready to try printing. If you try to print via the command line using lpr, you should get an error at this point. The spool directory (the sd property) does not yet exist. In a terminal window, make the spool directory, /var/spool/lpd/lp. The directory /var/spool/lpd should already exist.
    [localhost:/var/spool/lpd] root# mkdir lp
    [localhost:/var/spool/lpd] root# chmod 770 lp
    [localhost:/var/spool/lpd] root# chown daemon.daemon lp
    
  4. Test your printer from the command line by running lpr.
    [localhost:~] joray% lpr file2
    
    To see your print job in the queue, check the queue.
    [localhost:~] joray% lpq
    lw360 is ready and printing
    
    Rank    Owner   Job     File(s)                         Total Size
    active  joray   0       file2                           34 bytes
    
  5. Test lp from an OS X application, such as Internet Explorer.

Add lpd to Your Startup Scripts

After you are satisfied that the printer works, it is probably a good idea to make a backup copy of the NetInfo database. It is also necessary to set up lpd, the daemon that handles sending print jobs to the printer, to start up at boot time. Until lpd is set to start at boot time, your ability to print will last only through your current session. To add lpd to your startup scripts, do the following:

  1. Make a backup copy of /etc/hostconfig:
    [localhost:~joray] root# cp /etc/hostconfig /etc/hostconfig.backup
    
  2. Create a directory called /System/Library/StartupItems/LPD:
    [localhost:/Users/joray] root# cd /System/Library/StartupItems
    [localhost:/System/Library/StartupItems] root# mkdir LPD
    
  3. In /System/Library/StartupItems/LPD, using your favorite text editor, make a file called LPD with the following contents:
    #!/bin/sh
    
    ##
    # start lpd
    ##
    
    . /etc/rc.common
    if [ "${ LPD:=-NO-} " = "-YES-" ]; then
        ConsoleMessage "Starting lpd"
    
        /usr/libexec/lpd
    
    fi
    
    You can start to create the file by copying /System/Library/StartupItems/Apache/Apache to the LPD directory as LPD and editing the appropriate lines. If you choose to start by copying a file from another StartupItems directory, recall that cp -p retains the permissions of the original file.
  4. In /System/Library/StartupItems/LPD, using your favorite text editor, make a file called StartupParameters.plist. Again, you can start it by copying a simple StartupParameters.plist in another directory, such as the one in the Apache directory, to the LPD directory and editing it so that it looks like this:
    {
      Description   = "let's you print";
      Provides      = ("lpd");
      Requires      = ("Resolver");
      Uses          = ("Network Time");
      Preference    = "None";
      Messages =
      {
        start = "Starting lpd";
        stop  = "Stopping lpd";
      } ;
    }
    
  5. The Provides, Requires, and Uses entries are suggestions to the startup system regarding when and whether it is appropriate to run the script. It is not clear at this point that the startup system actually uses these specifications, but many parts of OS X are still evolving. Although it doesn't seem necessary to provide correct information in these fields at this time, we suggest trying to make your entries as intelligent as possible. What we've chosen here are certainly not the only possible choices—feel free to tweak it as you see fit. So far, this Startu p Parameters.plist appears to work for us. Make sure that your files have the permissions as listed here.
    [localhost:Library/StartupItems/LPD] root# ls -l
    total 16
    -r-xr-xr-x  1 root  wheel  147 Apr 24 12:18 LPD
    -r—r—r—  1 root  wheel  241 Apr 25 19:48 StartupParameters.plist
    
    If your files do not have the permissions listed previously, use the commands below to change them.
    [localhost:Library/StartupItems/LPD] root# chmod 555 LPD
    [localhost:Library/StartupItems/LPD] root# chmod 444 StartupParameters.plist
    

After you are satisfied that you have completed the previous steps, reboot the machine. When you log back in you should be able to print from the command line using the lpr command, as shown in Chapter 12, "Introducing the BSD Subsystem."

Using the Print Center and NetInfo Manager to Add a Printer

Although you can often work completely in the NetInfo Manager to update the NetInfo database, there are some instances when another tool in the system can enter part of the NetInfo properties for you. Determining what properties you need to add to the NetInfo database for a given item can sometimes seem like guesswork. Carefully reading the man pages will give you some clues. Sometimes, using another system tool can do some of the work for you. In this example, we will add a printer to the system by using the Print Center and NetInfo Manager in combination with each other. What we will do is add a printer in the Print Center, use the NetInfo Manager to modify the settings the Print Center adds to the NetInfo database, and modify the printer in the Print Center using the updated information from the NetInfo database.

To add a PostScript printer served by another Unix host to the NetInfo database using the Print Center and the NetInfo Manager, do the following:

  1. Make a backup of the NetInfo database.
  2. Start the Print Center. Under Printers, select Add Printer; or click Add Printer in the Printer List.
  3. In the window that comes up, select LPR Printers using IP. Enter the IP address or name of the remote Unix host. Select a printer description, if one is available. The choices are various types of LaserWriter printers (the same ones we saw listed in the /System/Library/Printers/PPDs/Contents/Resources/<language>. lproj directory), generic, and other. Selecting other enables you to specify a PPD that you might have elsewhere on your machine. Figure 23.14 shows our printer defined in the Print Center.
    23fig14.jpg

    Figure 23.14 Defining our printer in the Print Center. We have listed the remote host's IP address and selected a PPD file.

  4. When you are returned to the Printer List, note that the new printer is described as an lpr host, as shown in Figure 23.15.
    23fig15.jpg

    Figure 23.15 Our printer has been added to the Printer List as an lpr host.

  5. Now you are ready to interact with the NetInfo database using the NetInfo Manager. Open the NetInfo Manager and select your local domain, if it is not already open. Click printers, and then click the IP address/name in the window to the right. Click in the lock to make changes, and then enter your administrator username and password. Figure 23.16 shows the default NetInfo entry that the Print Center added to the database.
    23fig16.jpg

    Figure 23.16 Print Center has already added our printer to the NetInfo database in a directory labeled with the IP address/name of the remote Unix host and created a number of properties for us.

    It should be getting clearer how some tools integrate and interoperate with the NetInfo database. The Print Center added not only a directory for our printer, but also a number of properties for the printer.
  6. Rather than adding properties manually in the NetInfo database, following this path, a few precreated properties need to be edited instead. Before editing the properties, take a look at your /var/spool/lpd directory. You'll note that the Print Center not only added information about the printer to NetInfo, but also created the spool directory. At this time, the spool directory has the same name as the directory entry that was created in the NetInfo database, which came from the IP address or name of the remote host. Edit the properties accordingly:
    Property Value(s)
    rp <name of the remote printer as it is known to the remote host>
    rm <IP adddress or name of the remote machine>
    lp /dev/null
    sd /var/spool/lpd/lp
    LPR_PRINTER 1
    ppdurl <as appropriate>
  7. Double-check your edits and then save them. Select Save under the Domain menu. A request to Confirm Modification appears. Click Update this copy. Note that the directory named with the IP address/remote hostname is now called lp.
  8. Under the Options menu, select Restart All NetInfo Domains on Local Host. An alert asking if you really want to restart the machine's NetInfo servers appears. Click Yes. Click the lock at the bottom left of the window to end your ability to make changes at this time. Then close the NetInfo Manager.
  9. Start the Print Center. Either under Printers, select Add Printer, or click Add Printer in the Printer List.
  10. Select the Directory Services connection type. You should see lp listed as a NetInfo host. Click Add.
  11. Now there is a listing for lp as a NetInfo host and a listing for the printer as an lpr host, as shown in Figure 23.17. Select the printer as an lpr host definition and delete it.
    23fig17.jpg

    Figure 23.17 Now the printer has been added as lp, a NetInfo host. The original description of the printer as an lpr host is still in the Printer List, but can be deleted now.

You can now test the printer by running lpr in the command line and printing from an OS X application. After you are satisfied that it prints, add lpd to your startup scripts as described in the previous section. You might also want to make a backup copy of your NetInfo database.

Using the Command Line to Examine the NetInfo Database

As you have seen throughout this book, command-line tools are frequently available to do what can be done in the graphical tools in OS X. This is also the case with the NetInfo database. You can manage the database graphically in the NetInfo Manager, and you can manage the database through command-line tools. As you become more familiar with the NetInfo database, you will learn that sometimes the graphical tools are more suitable for accomplishing your task, whereas at other times the command-line tools are more suitable.

In this section we will take some of the same tour of the NetInfo database that we did using the NetInfo Manager, only this time we will use the command line. Having already used the NetInfo Manager will make the introduction to the command line easier.

Before we even begin our tour, we can verify that our machine is indeed a NetInfo server, serving its own local domain by running ps:

[localhost:~] joray% ps -aux | grep netinfo

     root   196  0.0 0.1  1632  496  ?? S  0:00.49 netinfod local (master)
     joray  558  0.0 0.0  5708  0 std   RV 0:00.00 grep netinfo

As we can see from the ps listing, our machine is indeed running a NetInfo server for its local domain, and it is the master of its local domain.

Now let's look directly at the NetInfo database. We will be examining the NetInfo database using the niutil command, the NetInfo utility. You can do more than just examine the database with niutil, but we will get to that later.

The primary form of niutil is

niutil <action> [opts] <domain> 
   <path>

One of the most confusing parts about using the command-line tools is remembering what term to use to refer to the local domain. As you might guess from the NetInfo Manager, / would probably refer to the local domain. However, you will also see in man pages and online documentation the use of . to refer to the local domain. Which is it?

[localhost:~] joray% niutil -domainname .

     /
[localhost:~] joray% niutil -domainname /

     /

As we see from the niutil command, we can use either . or / to refer to the local domain, as long as the local domain is the only domain we have. As you research things on the Internet, you might see both terms being used to refer to the local domain. As we continue with this chapter, we will use the notation described in the man pages.

Let's look at the root directory of our local domain:

[localhost:~] joray% niutil -list . /

     1        users
     7        groups
     27       machines
     31       networks
     33       protocols
     48       rpcs
     77       services
     141      aliases
     150      mounts
     151      printers
     152      localconfig
     156      config
     164      afpuser_aliases

This looks familiar! The result we get on the command line looks much like what we saw in NetInfo Manager in the right window, except that the NetInfo Manager listed the directories in alphabetical order rather than by numeric ID.

We can look at the properties of the root directory of the local domain:

[localhost:~] joray% niutil -read . /

     master: localhost/local
     trusted_networks:

This looks like the same view we had in the bottom window of the NetInfo Manager.

Let's do the command-line equivalent of clicking on the aliases directory in the NetInfo Manager:

[localhost:~] joray% niutil -list . /aliases

     142      administrator
     143      postmaster
     144      MAILER-DAEMON
     145      MAILER-AGENT
     146      nobody
     147      dumper
     148      manager
     149      operator

If we were in the NetInfo Manager, the window to the right would show more data now. If we click the postmaster directory, we also see in the command line that we have reached the end of the hierarchy:

[localhost:~] joray% niutil -list . /aliases/postmaster

Again, we can look at the properties of postmaster:

[localhost:~] joray% niutil -read . /aliases/postmaster

     name: postmaster
     members: root

As we saw in the NetInfo Manager, postmaster appears to be aliased to root.

We can also view a specific property using the command line. Here we ask for the value of the port property of the ssh directory of the services directory in our local domain:

[localhost:~] joray% niutil -readprop . /services/ssh port
     22

Now we have taken a brief tour of our local NetInfo database using niutil. So far, we have seen that using -list or some form of -read is much like clicking on values in the NetInfo Manager. Specifically, -list lists directories in the specified name and path, and -read lists associated values of a directory. In NetInfo Manager terms, the -list action is like navigating the upper windows, but using -read is like viewing the contents of a directory being displayed in the upper window in the bottom window. The command documentation table for niutil is shown in Table 23.1.

Table 23.1. The NetInfo Utility niutil Is Used to Edit the NetInfo Database.

Niutil NetInfo utility
niutil -create [opts] <domain> <path>
niutil -destroy [opts] <domain> <path>
niutil -createprop [opts] <domain> <path> <key> [<val>…]
niutil -appendprop [opts] <domain> <path> <key> <val>…
niutil -mergeprop [opts] <domain> <path> <key> <val>…
niutil -insertval [opts] <domain> <path> <key> <val> <index>
niutil -destroyprop [opts] <domain> <path> <key>
niutil -destroyval [opts] <domain> <path> <key> <val>
niutil -renameprop [opts] <domain> <path> <oldkey> <newkey>
niutil -read [opts] <domain> <path>
niutil -list [opts] <domain> <path>
niutil -rparent [opts] <domain>
niutil -resync [opts] <domain>
niutil -statistics [opts] <domain>
niutil enables you to perform arbitrary reads and writes on the specified NetInfo < domain >. To perform writes, niutil must be run as root on the NetInfo master for the database, unless -p, -P, or -u is specified. The directory specified by < path > is separated by / characters. A numeric ID may be used for a path in place of a string. Property names might be given in a path with an =. The default property name is name. The following examples refer to a user with user ID 3:
/name=users/uid=3
/users/uid=3/
Options
-t < host >/< tag > Interprets the domain as a tagged domain. For example, pa r rish/network is the domain tagged network on machine parrish.
-p Prompts for the root password or the password of < user > if combined with -u.
-u < user > Authenticates as < user >. Implies -p.
-P < password > Provides the root password or the password of < user > if combined with -u. Overrides -p.
-T < seconds > Sets the read and write timeout to < seconds >. Default is 30 seconds.
Operations
-create < domain > <path> Creates a new directory with the specified path.
-destroy <domain> <path> Destroys the directory with the specified path.
-createprop < domain > < path > < key > [< val >...] Creates a new property in the directory < path >. < key > is the name of the property. Zero or more property values may be specified. If the named property already exists, it is overwritten.
-appendprop < domain > < path > < key > < val >... Appends new values to an existing property in directory < path >. < key > is the name of the property. Zero or more property values may be specified. If the named property does not exist, it is created.
-mergeprop < domain > < path > < key > < val >... Merges new values into an existing property in the directory < path >. <key> is the name of the property. Zero or more property values might be specified. The values are appended to the property only if they do not already exist. If the named property does not exist, it is created.
-insertval < domain > < path > < key > < val > < propindex > Inserts a new value into an existing property in the directory < path > at position < propindex >. < key > is the name of the property. If the named property does not exist, it is created.
-destroyprop < domain > < path > < key > Destroys the property with name < key > in the specified < path >.
-destroyval < domain > < path > < key > < val > Destroys the specified value in the property named < key > in the specified <path> .
-renameprop < domain > < path > < oldkey > < newkey > Renames the property with name < oldkey > in the specified < path >.
-read < domain > < path > Reads the properties associated with the directory < path > in the specified < domain >.
-list < domain > < path > Lists the directories in the specified < domain > and < path >. Directory IDs are listed along with directory names.
-readprop < domain > < path > < key > Reads the value of the property named < key > in the directory < path > of the specified < domain >.
-readval < domain > < path > < key > < index > Reads the value at the given index of the named property in the specified directory.
-rparent < domain > Prints the current NetInfo parent of a server. The server should be explicitly given using the -t < host >/< tag > option.
-resync < domain > Resynchronizes NetInfo. If a domain name is given, the master resynchronizes all clones. If the -t <clone>/<tag> option is used instead, only that clone is resynchronized. Using -t < master >/< tag > resynchronizes the whole domain.
-statistics < domain > Prints server statistics on the specified < domain >.
-domainname < domain > Prints the domain name of the given domain.
< domain > A value of . for < domain > refers to the local NetInfo database.

Using the Command Line to Add a Printer

With all the values we saw in the previous sections, you might feel that adding a printer through the command-line tools would be especially painful. However, this method can be as easy as the method described in the section on using the Print Center with the NetInfo Manager.

As you might recall, OS X uses the NetInfo database to store information on printers, whereas some versions of Unix store this information in a file called /etc/printcap.

OS X has a nice command-line tool available that understands certain typical Unix flat files and can convert them to NetInfo data. One of the flat-file formats that the tool, niload, understands is the printcap.

To add a PostScript printer served by a remote Unix host using primarily command-line tools, do the following:

  1. Make a backup of the NetInfo database.
  2. Look at the man page and sample /etc/printcap that comes with the system to familiarize yourself with the basic format of the /etc/printcap file.
  3. Using your favorite text editor, create a printcap file in some location. Do not overwrite or even edit the sample that comes with the system, so that you have your original sample intact.
  4. Add a line of this form to your printcap file:
    lp::lp=/dev/null:rm=192.168.1.5:rp=lw360::sd=/var/spool/lpd/lp:
    
    These values should already look familiar. The lp on the first line is the name of our printer. The lp on the second line will become the lp property with value /dev/null. The rm on the second line will become the rm property with the value of the IP address or name of the remote machine. The rp on the second line will become the rp property with the value of the name of the printer as it is known on the remote host. The sd on the third line will become the sd property with a value of the spool directory, /var/spool/lpd/lp. Please note that this file is virtually only one line long, even though it is entered on three lines. The \ indicates that the current line continues to the next line in the file.
  5. As root, use the niload command to load the flat file you made into the NetInfo Database. The basic form of the command we will use is niload < format > < domain > < < filename >.
    [localhost:~] root# niload printcap . < printcap-test
    
    The command documentation table for niload is shown in Table 23.2. Look at the results of what you just did using the command niutil and/or the NetInfo Manager. In our command-line result, lp2 appears, rather than lp, because we created a second definition of the same printer for demonstration purposes.
    [localhost:~] joray% niutil -read . /printers/lp2
    lp: /dev/null
    rp: lw360
    sd: /var/spool/lpd/lp
    name: lp2
    rm: 192.168.1.5
    

Figure 23.18 shows a sample of what the niload version of the printcap data looks like in the NetInfo Manager.

23fig18.jpg

Figure 23.18 niload has been successfully used to load printcap information into the NetInfo database.

Notice that the printcap does not necessarily use all the values that the Print Center generates. The minimum values that can be defined in a typical printcap file are acceptable to the NetInfo database.

  1. Create the spool directory. In a terminal window, make the spool directory, /var/spool/lpd/lp. The directory /var/spool/lpd should already exist.
    [localhost:/var/spool/lpd] root# mkdir lp
    [localhost:/var/spool/lpd] root# chmod 770 lp
    [localhost:/var/spool/lpd] root# chown daemon.daemon lp
    
  2. Start the Print Center. Either under Printers, select Add Printer, or click Add Printer in the Printer List. A window set to Directory Services should drop down, and you should see lp listed as a NetInfo. Click Add.
  3. Test printing via lpr in the command line, as well as through the normal print menu of an OS X application.

After you are satisfied that it prints, add lpd to your startup scripts as described in the section on adding a printer directly through the NetInfo Manager. You might also want to make a backup copy of your NetInfo database.

Table 23.2. Use niload to Load Data into NetInfo Domains

niload [-v] [-d | m] [-p] [-t] {-r <directory> | <format>} <domain>
niload loads information from standard output into the specified NetInfo <domain> . If <format> is specified, the input is interpreted according to the flat-file format <format> . Acceptable values for <fo r mat> are aliases, bootparams, bootptab, fstab, group, hosts, networks, passwd, printcap, protocols, rpc, and services.
If -r < directory > is specified instead of <format> , the input is interpreted as raw NetInfo data, as generated by nidump -r, and is loaded into <directory> .
niload overwrites entries in the existing directory with those contained in the input. Entries that are in the directory, but not in the input, are not deleted unless -d is specified. niload must be run as the sup e ruser on the master NetInfo server for <domain> , unless -p is specified.
-v Verbose mode. Prints + for each entry loaded, and - for each entry deleted (flat-file formats only).
-d Deletes entries that are in the directory, but not in the input.
-m Merges new values into the directory when the input contains a duplicate name.
Note: Only one of -d or -m might be specified. If neither option is specified, existing entries in the NetInfo database will remain unchanged when the input contains a duplicate name.
-p Prompts for the root password of the given domain so that the command might be run from locations other than the master.
-u < user > Authenticates as <user> . Implies -p.
-P <password> Provides <password> on the command line. Overrides -p.
-t <host> / <tag> Interprets the domain as a tagged domain. For example, trotter/network refers to the domain network on the machine trotter. Machine name can be specified as an actual name or an IP address.
-T < seconds > Sets the read and write timeout to <seconds> . Default is 30 seconds.
-r < directory > Loads entries in raw format, as generated by nidump -r. The first argument should be the path of a NetInfo directory into which the information is loaded. The specified directory might be renamed as a result of contents of the input, particularly if the input includes a top-level name property. If the specified directory does not exist, it is created.
<domain> NetInfo <domain> that is receiving input. If . is the value for <domain> , it is referring to the local NetInfo database.

NetInfo Manager Interface

Now that you have had a chance to use the NetInfo Manager, let's take a brief look at the NetInfo Manager interface itself. The NetInfo Manager and NetInfo database can seem so overwhelming at first, that now is a good time to take a step back and look at the interface itself.

As you have seen throughout this chapter, there are many options available under the menu items of the NetInfo Manager. Because there are so many options, it can be easy to overlook the buttons that are included in the upper left of the NetInfo Manager window.

The buttons, provide some useful shortcuts for some actions. Descriptions are provided for the buttons, from left to right:

In addition to the buttons, you might also have noticed the folder at the right. Your present location in the NetInfo database is displayed underneath this folder. The upper window is where you navigate through the NetInfo database. The lower window is where you view the contents of a specific directory in the NetInfo database.

Share ThisShare This

Informit Network