* 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
{ "/usr/adm/ptmp" };
char *pfile
{ "/etc/passwd" };
write(2, "Usage: passwd user [ password ]\n", 32);
write(2, "Password: ", 10);
write(2, "\nAgain: ", 8);
if (read(0, &x
, 1) != 1 || x
== '\n')
while (read(0, &x
, 1) == 1 && x
!= '\n')
write(2, "\nThose weren't the same\n", 24);
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", 25);
* skip to beginning of next line
write(2, "User name not found in password file\n", 37);
if((c
&0377) == 0 && ((c
>>8)&0377) == v
)
write(2, "Permission denied\n", 18);
tbuf
[0] = open(tfile
, 0);
pbuf
[0] = creat(pfile
, 0644);
write(2, "Cannot create /etc/passwd\n", 27);
while((c
= read(tbuf
[0], tbuf
+1, 512)) > 0)
write(pbuf
[0], tbuf
+1, c
);
write(2, "Password file illformed\n", 24);