/***************************************************************************** Application ASH: chgrp.c (c) Pierre Adriaans 1994 ------------------------------------------------------------------------------ Module de gestion des chgrp. *****************************************************************************/ #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]; /***************************************************************************** ChangeGrp() ------------------------------------------------------------------------------ Changement de groupe pour un ou plusieurs fichiers. *****************************************************************************/ void ChangeGrp(void) { int Nb,i; char Group[50]; struct group *grp; GetNbTagged(List[AL],&Nb,&i); if(Nb == 0 && strcmp(Current[AL]->Info.Name,"..") == 0) { InitAnswerBoxItem(&InfoMsg); AddAnswerBoxItem(&InfoMsg,"Changing group for '..' is too dangerous."); InfoBox(ErrorNorm,ErrorInv," Change Group ",InfoMsg,0,0,DOUBLE_FRAMED); return; } if(Nb == 0) { grp = getgrgid(Current[AL]->Info.s.st_gid); if(grp == NULL) strcpy(Group,"???"); else strcpy(Group,grp->gr_name); } else strcpy(Group,""); if(InputBox(Group,64,FileOpNorm,FileOpInv," Change Group ", "Enter new group name:",0,0,DOUBLE_FRAMED) == 1) return; grp = getgrnam(Group); if(grp == NULL) { InitAnswerBoxItem(&InfoMsg); AddAnswerBoxItem(&InfoMsg," ERROR: unknown group "); AddAnswerBoxItem(&InfoMsg,Group); InfoBox(ErrorNorm,ErrorInv," Change Group ",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,Current[AL]->Info.s.st_uid,grp->gr_gid) == -1) { InitAnswerBoxItem(&InfoMsg); if(IS_DIR(Current[AL]->Info.s.st_mode)) AddAnswerBoxItem(&InfoMsg, "Impossible to change the group of the directory"); else AddAnswerBoxItem(&InfoMsg, "Impossible to change the group 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 Group ",InfoMsg,0,0,DOUBLE_FRAMED); } else Current[AL]->Info.s.st_gid = grp->gr_gid; } 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,Current[AL]->Info.s.st_uid,grp->gr_gid) == -1) { InitAnswerBoxItem(&InfoMsg); if(IS_DIR(Dummy->Info.s.st_mode)) AddAnswerBoxItem(&InfoMsg, "Impossible to change the group of the directory"); else AddAnswerBoxItem(&InfoMsg, "Impossible to change the group 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 Group ",InfoMsg,0,0,DOUBLE_FRAMED); } else { Dummy->Info.Tagged = 0; Dummy->Info.s.st_gid = grp->gr_gid; } } 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); } }