static char *sccsid
= "@(#)chsh.c 4.1 (Berkeley) 10/1/80";
char passwd
[] = "/etc/passwd";
char temp
[] = "/etc/ptmp";
struct passwd
*getpwent();
if(argc
< 2 || argc
> 3) {
printf("Usage: chsh user [ /bin/oldcsh ] [ /bin/csh ]\n");
else if (strcmp(argv
[2], "/bin/oldcsh") && strcmp(argv
[2], "/bin/csh") && getuid()) {
printf("Only /bin/oldcsh or /bin/csh may be specified\n");
while((pwd
=getpwent()) != NULL
){
if(strcmp(pwd
->pw_name
,argv
[1]) == 0){
if(u
!=0 && u
!= pwd
->pw_uid
){
printf("Permission denied.\n");
if(access(temp
, 0) >= 0) {
printf("Temporary file busy -- try again\n");
if((tf
=fopen(temp
,"w")) == NULL
) {
printf("Cannot create temporary file\n");
* copy passwd to temp, replacing matching lines
while((pwd
=getpwent()) != NULL
) {
if(strcmp(pwd
->pw_name
,argv
[1]) == 0) {
if(u
!= 0 && u
!= pwd
->pw_uid
) {
printf("Permission denied.\n");
fprintf(tf
,"%s:%s:%d:%d:%s:%s:%s\n",
* copy temp back to passwd file
if((fi
=open(temp
,0)) < 0) {
printf("Temp file disappeared!\n");
if((fo
=creat(passwd
, 0644)) < 0) {
printf("Cannot recreat passwd file.\n");
while((u
=read(fi
,buf
,sizeof(buf
))) > 0) write(fo
,buf
,u
);