I have to write a program to maintain users. That is, create new
accounts, change or delete existing accounts, etc. The program must
maintain entries in /etc/passwd and /etc/group as well as our own
database files, which contain additional information about each user.
There are system & library routines (and plenty of good documention)
enabling me to read /etc/passwd and /etc/group. And putpwent is OK
for adding new users to the end of the file. But how do I delete an
entry, or modify an entry? I cannot find any system or library
routines to do this (Linux 2.0.25).
As I struggle to figure this out, I realize I have no idea how to do
this with ANY simple ASCII text file! That is: given a file
containing variable-length records, how does one modify or delete a
record in the middle of the file?
Of course there is the brute force approach: Copy it to another file,
modifying it along the way, then replace the original file with the
new one. But I am scared codeless of manhandling the /etc/passwd file
in this manner.
I must be missing something.
-Lee Allen