Advanced Programming in the UNIX Environment: Second Edition [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Advanced Programming in the UNIX Environment: Second Edition [Electronic resources] - نسخه متنی

W. Richard Stevens; Stephen A. Rago

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید



6.7. Other Data Files


We've discussed only two of the system's data files so far: the password file and the group file. Numerous other files are used by UNIX systems in normal day-to-day operation. For example, the BSD networking software has one data file for the services provided by the various network servers (/etc/services), one for the protocols (/etc/protocols), and one for the networks (/etc/networks). Fortunately, the interfaces to these various files are like the ones we've already described for the password and group files.

The general principle is that every data file has at least three functions:

  • A get function that reads the next record, opening the file if necessary. These functions normally return a pointer to a structure. A null pointer is returned when the end of file is reached. Most of the get functions return a pointer to a static structure, so we always have to copy it if we want to save it.

  • A set function that opens the file, if not already open, and rewinds the file. This function is used when we know we want to start again at the beginning of the file.

  • An end enTRy that closes the data file. As we mentioned earlier, we always have to call this when we're done, to close all the files.

  • Additionally, if the data file supports some form of keyed lookup, routines are provided to search for a record with a specific key. For example, two keyed lookup routines are provided for the password file: getpwnam looks for a record with a specific user name, and getpwuid looks for a record with a specific user ID.

    Figure 6.6 shows some of these routines, which are common to UNIX systems. In this figure, we show the functions for the password files and group file, which we discussed earlier in this chapter, and some of the networking functions. There are get, set, and end functions for all the data files in this figure.

    Figure 6.6. Similar routines for accessing system data files

    Description

    Data file

    Header

    Structure

    Additional keyed lookup functions

    passwords

    /etc/passwd

    <pwd.h>

    passwd

    getpwnam, getpwuid

    groups

    /etc/group

    <grp.h>

    group

    getgrnam, getgrgid

    shadow

    /etc/shadow

    <shadow.h>

    spwd

    getspnam

    hosts

    /etc/hosts

    <netdb.h>

    hostent

    gethostbyname, gethostbyaddr

    networks

    /etc/networks

    <netdb.h>

    netent

    getnetbyname, getnetbyaddr

    protocols

    /etc/protocols

    <netdb.h>

    protoent

    getprotobyname, getprotobynumber

    services

    /etc/services

    <netdb.h>

    servent

    getservbyname, getservbyport

    Under Solaris, the last four data files in Figure 6.6 are symbolic links to files of the same name in the directory /etc/inet. Most UNIX System implementations have additional functions that are like these, but the additional functions tend to deal with system administration files and are specific to each implementation.


      / 369