Managing Systems and Workgroups: A Guide for HP-UX System Administrators
Setting Up and Administering an HP-UX NFS Diskless Cluster
NFS Diskless Questions and Answers
Chapter 10 945
• If you need to unlink the file, perform the operation on
/etc/share/passwd, not /etc/passwd (and /etc/share/group
rather than /etc/group).
For example:
cp /etc/share/passwd /etc/share/passwd.new
vi /etc/share/passwd.new
mv /etc/share/passwd.new /etc/share/passwd
• Use code such as the fragment that follows to modify the password
file programmatically.
Modifying the Password File Programmatically The code
fragment below looks for a user in the password file with the user name
found in the variable
login_name
, and replaces the home directory for
that user with the value found in the variable
new_directory
. The
algorithm makes a copy of the password file before modifying it, then
replaces the existing password file with the modified file in an atomic
operation.
strcpy(passwd_file, "/etc/passwd");
/* follow possible symbolic links to get actual password file */
while(1) {
if (lstat(passwd_file, &file_info) != 0)
ERROR
if ((file_info.st_mode &S_IFMT) == S_IFREG)
break;
if ((file_info.st_mode &S_IFMT) != S_IFLNK)
ERROR
if (readlink(passwd_file, follow_link, 100) < 0)
ERROR
strncpy(passwd_file, follow_link, rc);
passwd_file[rc] = `\\0';
}
/* block simultaneous access attempts at password file */
lckpwdf();
/* open temporary password file */
strcpy(temp_pwd, passwd_file); strcat(temp_pwd, ".tmp");
tf = fopen(temp_pwd, "w");
if (tf == NULL)
ERROR
/* copy existing passwd file to temporary file, modifying desired entry */