1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
void ExtractUnixOwner(Archive &Arc,char *FileName)
{
if (Arc.HeaderCRC!=Arc.UOHead.HeadCRC)
{
Log(Arc.FileName,St(MOwnersBroken),FileName);
ErrHandler.SetErrorCode(CRC_ERROR);
return;
}
struct passwd *pw;
errno=0; // Required by getpwnam specification if we need to check errno.
if ((pw=getpwnam(Arc.UOHead.OwnerName))==NULL)
{
Log(Arc.FileName,St(MErrGetOwnerID),Arc.UOHead.OwnerName);
ErrHandler.SysErrMsg();
ErrHandler.SetErrorCode(WARNING);
return;
}
uid_t OwnerID=pw->pw_uid;
struct group *gr;
errno=0; // Required by getgrnam specification if we need to check errno.
if ((gr=getgrnam(Arc.UOHead.GroupName))==NULL)
{
Log(Arc.FileName,St(MErrGetGroupID),Arc.UOHead.GroupName);
ErrHandler.SysErrMsg();
ErrHandler.SetErrorCode(CRC_ERROR);
return;
}
uint Attr=GetFileAttr(FileName,NULL);
gid_t GroupID=gr->gr_gid;
#if defined(SAVE_LINKS) && !defined(_APPLE)
if (lchown(FileName,OwnerID,GroupID)!=0)
#else
if (chown(FileName,OwnerID,GroupID)!=0)
#endif
{
Log(Arc.FileName,St(MSetOwnersError),FileName);
ErrHandler.SetErrorCode(CREATE_ERROR);
}
SetFileAttr(FileName,NULL,Attr);
}
void ExtractUnixOwnerNew(Archive &Arc,char *FileName)
{
char *OwnerName=(char *)&Arc.SubHead.SubData[0];
int OwnerSize=strlen(OwnerName)+1;
int GroupSize=Arc.SubHead.SubData.Size()-OwnerSize;
char GroupName[NM];
strncpy(GroupName,(char *)&Arc.SubHead.SubData[OwnerSize],GroupSize);
GroupName[GroupSize]=0;
struct passwd *pw;
if ((pw=getpwnam(OwnerName))==NULL)
{
Log(Arc.FileName,St(MErrGetOwnerID),OwnerName);
ErrHandler.SetErrorCode(WARNING);
return;
}
uid_t OwnerID=pw->pw_uid;
struct group *gr;
if ((gr=getgrnam(GroupName))==NULL)
{
Log(Arc.FileName,St(MErrGetGroupID),GroupName);
ErrHandler.SetErrorCode(CRC_ERROR);
return;
}
uint Attr=GetFileAttr(FileName,NULL);
gid_t GroupID=gr->gr_gid;
#if defined(SAVE_LINKS) && !defined(_APPLE)
if (lchown(FileName,OwnerID,GroupID)!=0)
#else
if (chown(FileName,OwnerID,GroupID)!=0)
#endif
{
Log(Arc.FileName,St(MSetOwnersError),FileName);
ErrHandler.SetErrorCode(CREATE_ERROR);
}
SetFileAttr(FileName,NULL,Attr);
}
|