unrarsrc  6.1.7
About: unrar extracts, views and tests the contents of archives created with the RAR archiver.
  Fossies Dox: unrarsrc-6.1.7.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

uowners.cpp
Go to the documentation of this file.
1
2
3void ExtractUnixOwner20(Archive &Arc,const wchar *FileName)
4{
5 char NameA[NM];
6 WideToChar(FileName,NameA,ASIZE(NameA));
7
8 if (Arc.BrokenHeader)
9 {
12 return;
13 }
14
15 struct passwd *pw;
16 errno=0; // Required by getpwnam specification if we need to check errno.
17 if ((pw=getpwnam(Arc.UOHead.OwnerName))==NULL)
18 {
22 return;
23 }
24 uid_t OwnerID=pw->pw_uid;
25
26 struct group *gr;
27 errno=0; // Required by getgrnam specification if we need to check errno.
28 if ((gr=getgrnam(Arc.UOHead.GroupName))==NULL)
29 {
33 return;
34 }
35 uint Attr=GetFileAttr(FileName);
36 gid_t GroupID=gr->gr_gid;
37#if defined(SAVE_LINKS) && !defined(_APPLE)
38 if (lchown(NameA,OwnerID,GroupID)!=0)
39#else
40 if (chown(NameA,OwnerID,GroupID)!=0)
41#endif
42 {
43 uiMsg(UIERROR_UOWNERSET,Arc.FileName,FileName);
45 }
46 SetFileAttr(FileName,Attr);
47}
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 {
67 return;
68 }
69 uid_t OwnerID=pw->pw_uid;
70
71 struct group *gr;
72 if ((gr=getgrnam(GroupName))==NULL)
73 {
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);
88 }
89 SetFileAttr(FileName,Attr);
90}
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 {
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 {
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);
140 }
141}
ErrorHandler ErrHandler
bool BrokenHeader
Definition: archive.hpp:128
FileHeader FileHead
Definition: archive.hpp:104
FileHeader SubHead
Definition: archive.hpp:107
UnixOwnersHeader UOHead
Definition: archive.hpp:110
size_t Size()
Definition: array.hpp:94
void SetErrorCode(RAR_EXIT Code)
Definition: errhnd.cpp:243
void SysErrMsg()
Definition: errhnd.cpp:368
wchar FileName[NM]
Definition: file.hpp:88
@ RARX_CRC
Definition: errhnd.hpp:9
@ RARX_CREATE
Definition: errhnd.hpp:15
@ RARX_WARNING
Definition: errhnd.hpp:7
uint GetFileAttr(const wchar *Name)
Definition: filefn.cpp:280
bool SetFileAttr(const wchar *Name, uint Attr)
Definition: filefn.cpp:302
#define ASIZE(x)
Definition: rardefs.hpp:10
wchar_t wchar
Definition: rartypes.hpp:13
unsigned int uint
Definition: rartypes.hpp:8
const wchar * GetWide(const char *Src)
Definition: strfn.cpp:360
char UnixOwnerName[256]
Definition: headers.hpp:243
char UnixGroupName[256]
Definition: headers.hpp:243
uint UnixOwnerID
Definition: headers.hpp:248
bool UnixGroupNumeric
Definition: headers.hpp:242
uint UnixGroupID
Definition: headers.hpp:249
bool UnixOwnerNumeric
Definition: headers.hpp:242
Array< byte > SubData
Definition: headers.hpp:186
char GroupName[256]
Definition: headers.hpp:330
char OwnerName[256]
Definition: headers.hpp:329
void uiMsg(UIMESSAGE_CODE Code)
Definition: ui.hpp:148
@ UIERROR_UOWNERGETOWNERID
Definition: ui.hpp:39
@ UIERROR_UOWNERGETGROUPID
Definition: ui.hpp:39
@ UIERROR_UOWNERBROKEN
Definition: ui.hpp:39
@ UIERROR_UOWNERSET
Definition: ui.hpp:40
bool WideToChar(const wchar *Src, char *Dest, size_t DestSize)
Definition: unicode.cpp:20
void SetUnixOwner(Archive &Arc, const wchar *FileName)
Definition: uowners.cpp:93
void ExtractUnixOwner20(Archive &Arc, const wchar *FileName)
Definition: uowners.cpp:3
void ExtractUnixOwner30(Archive &Arc, const wchar *FileName)
Definition: uowners.cpp:50