/***************************************************************************** Application ASH: chown.c (c) Pierre Adriaans 1994 ------------------------------------------------------------------------------ Module de gestion des chown. *****************************************************************************/ #include "ash.h" extern DirList_t *List[NB_MAX_WINS], *Current[NB_MAX_WINS], *Dummy; extern AnswerBoxItem_t *InfoMsg; extern int AL; extern char DummyStr[DUMMYSTR_SIZE],WorkingDir[NB_MAX_WINS][FILENAME_LENGTH]; extern InvZone_t InvZone[NB_MAX_WINS]; /***************************************************************************** ChangeOwner() ------------------------------------------------------------------------------ Changement de Owner pour un ou plusieurs fichiers. *****************************************************************************/ void ChangeOwner(void) { int Nb,i; char Owner[50]; struct passwd *pw; GetNbTagged(List[AL],&Nb,&i); if(Nb == 0 && strcmp(Current[AL]->Info.Name,"..") == 0) { InitAnswerBoxItem(&InfoMsg); AddAnswerBoxItem(&InfoMsg,"Changing owner for '..' is too dangerous."); InfoBox(ErrorNorm,ErrorInv," Change Owner ",InfoMsg,0,0,DOUBLE_FRAMED); return; } if(Nb == 0) { pw = getpwuid(Current[AL]->Info.s.st_uid); if(pw == NULL) strcpy(Owner,"???"); else strcpy(Owner,pw->pw_name); } else strcpy(Owner,""); if(InputBox(Owner,64,FileOpNorm,FileOpInv," Change Owner ", "Enter new owner name:",0,0,DOUBLE_FRAMED) == 1) return; pw = getpwnam(Owner); if(pw == NULL) { InitAnswerBoxItem(&InfoMsg); AddAnswerBoxItem(&InfoMsg," ERROR: unknown user "); AddAnswerBoxItem(&InfoMsg,Owner); InfoBox(ErrorNorm,ErrorInv," Change Owner ",InfoMsg,0,0,DOUBLE_FRAMED); return; } if(Nb == 0) { strcpy(DummyStr,WorkingDir[AL]); if(DummyStr[strlen(DummyStr) - 1] != PATH_SEPARATOR_CHAR) strcat(DummyStr,PATH_SEPARATOR_STR); if(IS_DIR(Current[AL]->Info.s.st_mode)) strcat(DummyStr,(Current[AL]->Info.Name) + 1); else strcat(DummyStr,Current[AL]->Info.Name); if(chown(DummyStr,pw->pw_uid,Current[AL]->Info.s.st_gid) == -1) { InitAnswerBoxItem(&InfoMsg); if(IS_DIR(Current[AL]->Info.s.st_mode)) AddAnswerBoxItem(&InfoMsg, "Impossible to change the owner of the directory"); else AddAnswerBoxItem(&InfoMsg, "Impossible to change the owner of the file"); AddAnswerBoxItem(&InfoMsg,DummyStr); switch(errno) { case ENOENT: AddAnswerBoxItem(&InfoMsg,"File or directory not found."); break; case EACCES: case EPERM: AddAnswerBoxItem(&InfoMsg,"Permission denied."); break; case EROFS: AddAnswerBoxItem(&InfoMsg,"File system is read-only."); break; case ENOLINK: AddAnswerBoxItem(&InfoMsg,"Remote link no longer active."); break; case EMULTIHOP: AddAnswerBoxItem(&InfoMsg,"Multiple remote machines link."); break; } InfoBox(ErrorNorm,ErrorInv," Change Owner ",InfoMsg,0,0,DOUBLE_FRAMED); } else Current[AL]->Info.s.st_uid = pw->pw_uid; } else { for(Dummy = List[AL]; Dummy != (DirList_t *)NULL; Dummy = Dummy->Suivant) if(Dummy->Info.Tagged) { strcpy(DummyStr,WorkingDir[AL]); if(DummyStr[strlen(DummyStr) - 1] != PATH_SEPARATOR_CHAR) strcat(DummyStr,PATH_SEPARATOR_STR); if(IS_DIR(Dummy->Info.s.st_mode)) strcat(DummyStr,(Dummy->Info.Name) + 1); else strcat(DummyStr,Dummy->Info.Name); if(chown(DummyStr,pw->pw_uid,Dummy->Info.s.st_gid) == -1) { InitAnswerBoxItem(&InfoMsg); if(IS_DIR(Dummy->Info.s.st_mode)) AddAnswerBoxItem(&InfoMsg, "Impossible to change the owner of the directory"); else AddAnswerBoxItem(&InfoMsg, "Impossible to change the owner of the file"); AddAnswerBoxItem(&InfoMsg,DummyStr); switch(errno) { case ENOENT: AddAnswerBoxItem(&InfoMsg,"File or directory not found."); break; case EACCES: case EPERM: AddAnswerBoxItem(&InfoMsg,"Permission denied."); break; case EROFS: AddAnswerBoxItem(&InfoMsg,"File system is read-only."); break; case ENOLINK: AddAnswerBoxItem(&InfoMsg,"Remote link no longer active."); break; case EMULTIHOP: AddAnswerBoxItem(&InfoMsg,"Multiple remote machines link."); break; } InfoBox(ErrorNorm,ErrorInv," Change Owner ",InfoMsg,0,0,DOUBLE_FRAMED); } else { Dummy->Info.Tagged = 0; Dummy->Info.s.st_uid = pw->pw_uid; } } RedisplayWin(AL); if(Current[AL]->Info.Tagged) PaintString(InvZone[AL].Lig,InvZone[AL].Col, InvZone[AL].Length,MainWinTagRev); else PaintString(InvZone[AL].Lig,InvZone[AL].Col, InvZone[AL].Length,MainWinInv); } }