I'm trying to write a C program to change a user password using Linux system calls. I have tryed to use the /etc/passwd
and /etc/shadow
files but I'm having problems because the password is encrypted, can you help me to solve this?
void main (int argc, char **argv) {
uid_t uid;
struct passwd *pw;
uid = getuid();
if (argc > 1)
pw = getpwnam(argv[1]);
else
pw = getpwuid(uid);
//system("passwd");
//printf("%i",execl("/usr/bin/passwd","passwd",pw->pw_name)); //here I tried to use execl but it returns error
}
I used system("passwd") but I don't think my teacher will accept that. On the rest of it I was just trying to understand the getpw... stuff, it's not important.