System data files and information of Reading Notes in UNIX advanced programming (1)

Source: Internet
Author: User

1. the UNIX system password file contains the fields shown in the passwd struct defined in <PWD. h>.


POSIX defines two functions for getting password file items. After the user login name or user ID is given. The two functions can be used to view related items.

# Include <PWD. h>

Struct passwd * getpwuid (uid_t UID );

Struct passwd * getpwnam (const char * Name );

To view the entire password file, use the following three functions:

# Include <PWD. h>

Struct passwd * getpwent (void); // return the next record in the password file

Void setpwent (void); // locate the password file to the opening

Void endpwent (void); // close the password file. After opening the password file, remember to close the password file.


2. For the sake of security, many systems store encryption passwords in a place called Shadow passwords. The fields stored in the file are as follows:


Similar to a group of functions that access the password file, another group of functions can access the shadow password file.

# Include <shadow. h>

Struct spwd * getspnam (const char * Name );

Struct spwd * getspent (void );

Void setspent (void );

Void endspent (void );


3. group files

UNIX files contain the fields shown in. These fields are also included in the group structure defined in <GRP. h>.


POSIX defines the following two functions to find information about the user group based on the user name or user ID.

# Include <GRP. h>

Struct Group * getgrgid (gid_t GID );

Struct Group * getgrnam (const char * Name );

Similar to accessing a password file. To access the entire group file, you need to use the following three functions:

# Include <GRP. h>

Struct Group * getgrent (void );

Void setgrent (void );

Void endgrent (void );


System data files and information of Reading Notes in UNIX advanced programming (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.