I want to add or delete or edit usernames of /etc/passwd
in a C program. Are there any standard Linux functions that do a such functions?
Asked
Active
Viewed 457 times
3
-
I don't think that there is a standard function for it (someone correct me if I'm wrong), but you can append the information to the file. See [here](http://www.cyberciti.biz/faq/understanding-etcpasswd-file-format/) for the format. Note that you need root access to read/write to this file, and be careful when playing with it, make a backup in case something goes wrong. – Jacob H Oct 18 '16 at 14:58
1 Answers
2
There is adduser
and deluser
. Use man deluser
for details.
EDIT: i missed the C part in the question.
man
is also your friend in this case. With man 3 deluser
you can ask if there is anything in stdlib called like that. Read https://unix.stackexchange.com/questions/3586/what-do-the-numbers-in-a-man-page-mean for more informations on that.
This is not the case. You might want to call the unix tool from within C: How do you write a C program to execute another program?
-
Also, `useradd`, `userdel`, `usermod`. Some distros have both these and your mentioned `adduser` and `deluser`, some have one or the other. Almost all have at least one of the sets... – twalberg Oct 18 '16 at 19:36