* enter a password in the password file
* this program should be suid with owner
* with an owner with write permission on /etc/passwd
char *tfile
{ "/tmp/ptmp" };
char *pfile
{ "/etc/passwd" };
write(2, "Usage: passwd user password\n", 28);
if(stat(tfile
, tbuf
+20) >= 0) {
write(2, "Temporary file busy -- try again\n", 33);
tbuf
[0] = creat(tfile
, 0600);
write(2, "Cannot create temporary file\n", 29);
pbuf
[0] = open(pfile
, 0);
write(2, "Cannot open /etc/passwd\n", 24);
* skip to beginning of next line
write(2, "User name not found in password file\n", 37);
write(2, "Permission denied\n", 18);
tbuf
[0] = open(tfile
, 0);
pbuf
[0] = creat(pfile
, 0644);
write(2, "Cannot create /etc/passwd\n", 26);
while((c
= read(tbuf
[0], tbuf
+1, 512)) > 0)
write(pbuf
[0], tbuf
+1, c
);
write(2, "Password file illformed\n", 24);