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

Function SetUnixOwner

Libraries/unrar/uowners.cpp:93–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91
92
93void SetUnixOwner(Archive &Arc,const wchar *FileName)
94{
95 char NameA[NM];
96 WideToChar(FileName,NameA,ASIZE(NameA));
97
98 // First, we try to resolve symbolic names. If they are missing or cannot
99 // be resolved, we try to use numeric values if any. If numeric values
100 // are missing too, function fails.
101 FileHeader &hd=Arc.FileHead;
102 if (*hd.UnixOwnerName!=0)
103 {
104 struct passwd *pw;
105 if ((pw=getpwnam(hd.UnixOwnerName))==NULL)
106 {
107 if (!hd.UnixOwnerNumeric)
108 {
109 uiMsg(UIERROR_UOWNERGETOWNERID,Arc.FileName,GetWide(hd.UnixOwnerName));
110 ErrHandler.SetErrorCode(RARX_WARNING);
111 return;
112 }
113 }
114 else
115 hd.UnixOwnerID=pw->pw_uid;
116 }
117 if (*hd.UnixGroupName!=0)
118 {
119 struct group *gr;
120 if ((gr=getgrnam(hd.UnixGroupName))==NULL)
121 {
122 if (!hd.UnixGroupNumeric)
123 {
124 uiMsg(UIERROR_UOWNERGETGROUPID,Arc.FileName,GetWide(hd.UnixGroupName));
125 ErrHandler.SetErrorCode(RARX_WARNING);
126 return;
127 }
128 }
129 else
130 hd.UnixGroupID=gr->gr_gid;
131 }
132#if defined(SAVE_LINKS) && !defined(_APPLE)
133 if (lchown(NameA,hd.UnixOwnerID,hd.UnixGroupID)!=0)
134#else
135 if (chown(NameA,hd.UnixOwnerID,hd.UnixGroupID)!=0)
136#endif
137 {
138 uiMsg(UIERROR_UOWNERSET,Arc.FileName,FileName);
139 ErrHandler.SetErrorCode(RARX_CREATE);
140 }
141}

Callers 1

SetFileHeaderExtraFunction · 0.85

Calls 4

WideToCharFunction · 0.85
uiMsgFunction · 0.85
GetWideFunction · 0.85
SetErrorCodeMethod · 0.80

Tested by

no test coverage detected