MCPcopy Create free account
hub / github.com/abbeycode/UnrarKit / ExtractUnixOwner30

Function ExtractUnixOwner30

Libraries/unrar/uowners.cpp:50–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48
49
50void ExtractUnixOwner30(Archive &Arc,const wchar *FileName)
51{
52 char NameA[NM];
53 WideToChar(FileName,NameA,ASIZE(NameA));
54
55 char *OwnerName=(char *)&Arc.SubHead.SubData[0];
56 int OwnerSize=strlen(OwnerName)+1;
57 int GroupSize=Arc.SubHead.SubData.Size()-OwnerSize;
58 char GroupName[NM];
59 strncpy(GroupName,(char *)&Arc.SubHead.SubData[OwnerSize],GroupSize);
60 GroupName[GroupSize]=0;
61
62 struct passwd *pw;
63 if ((pw=getpwnam(OwnerName))==NULL)
64 {
65 uiMsg(UIERROR_UOWNERGETOWNERID,Arc.FileName,GetWide(OwnerName));
66 ErrHandler.SetErrorCode(RARX_WARNING);
67 return;
68 }
69 uid_t OwnerID=pw->pw_uid;
70
71 struct group *gr;
72 if ((gr=getgrnam(GroupName))==NULL)
73 {
74 uiMsg(UIERROR_UOWNERGETGROUPID,Arc.FileName,GetWide(GroupName));
75 ErrHandler.SetErrorCode(RARX_WARNING);
76 return;
77 }
78 uint Attr=GetFileAttr(FileName);
79 gid_t GroupID=gr->gr_gid;
80#if defined(SAVE_LINKS) && !defined(_APPLE)
81 if (lchown(NameA,OwnerID,GroupID)!=0)
82#else
83 if (chown(NameA,OwnerID,GroupID)!=0)
84#endif
85 {
86 uiMsg(UIERROR_UOWNERSET,Arc.FileName,FileName);
87 ErrHandler.SetErrorCode(RARX_CREATE);
88 }
89 SetFileAttr(FileName,Attr);
90}
91
92
93void SetUnixOwner(Archive &Arc,const wchar *FileName)

Callers 1

SetExtraInfoFunction · 0.85

Calls 7

WideToCharFunction · 0.85
uiMsgFunction · 0.85
GetWideFunction · 0.85
GetFileAttrFunction · 0.85
SetFileAttrFunction · 0.85
SetErrorCodeMethod · 0.80
SizeMethod · 0.45

Tested by

no test coverage detected