Loading commands/editor/sed.cpp +9 −1 Changes for commands/editor/sed.cpp: 9 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <sys/stat.h> #include "shell.h" #include "ids.h" namespace fresh { namespace cmd { Loading Loading @@ -994,8 +995,15 @@ namespace fresh { namespace cmd { if(rc==4){ unlink(tmp.c_str()); return 4; } if(rc) status=rc; } { // the file's owner, a UUID or GUID one too (classic // chown() would hand the file to the overflow id); // chown first, it clears setuid and setgid uid_r_t ou; gid_r_t og; fresh::ids::fileIds(f,true,st,ou,og); if(fresh::ids::chownPath(tmp,false,&ou,&og)!=0){} } chmod(tmp.c_str(),st.st_mode & 07777); if(chown(tmp.c_str(),st.st_uid,st.st_gid)!=0){} if(!r.inPlaceSuffix.empty()){ std::string backup; if(r.inPlaceSuffix.find('*')!=std::string::npos){ Loading commands/system/tar.cpp +23 −9 Changes for commands/system/tar.cpp: 23 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -59,6 +59,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <grp.h> #include "shell.h" #include "ids.h" namespace fresh { namespace cmd { Loading Loading @@ -367,6 +368,11 @@ namespace fresh { namespace cmd { unsigned long uid=(unsigned long)getNum(h.uid,sizeof h.uid),gid=(unsigned long)getNum(h.gid,sizeof h.gid); if(attrs.count("uid")) uid=strtoul(attrs["uid"].c_str(),nullptr,10); if(attrs.count("gid")) gid=strtoul(attrs["gid"].c_str(),nullptr,10); // UUID or GUID owners (see -c), otherwise the classic ids uid_r_t ruid=uid_r_legacy((unsigned)uid); gid_r_t rgid=uid_r_legacy((unsigned)gid); if(attrs.count("FENRIR.uid_r")) uid_r_from_str(attrs["FENRIR.uid_r"].c_str(),&ruid); if(attrs.count("FENRIR.gid_r")) uid_r_from_str(attrs["FENRIR.gid_r"].c_str(),&rgid); if(type=='5' && !name.empty() && name.back()!='/') name+='/'; if(type=='0' && !name.empty() && name.back()=='/') type='5'; Loading Loading @@ -414,8 +420,8 @@ namespace fresh { namespace cmd { localtime_r(&mtime,&tmv); strftime(tb,sizeof tb,"%Y-%m-%d %H:%M",&tmv); std::string owner=field(h.uname,sizeof h.uname),group=field(h.gname,sizeof h.gname); if(owner.empty() || o.numericOwner) owner=std::to_string(uid); if(group.empty() || o.numericOwner) group=std::to_string(gid); if(owner.empty() || o.numericOwner) owner=fresh::ids::str(ruid); if(group.empty() || o.numericOwner) group=fresh::ids::str(rgid); vo << modeStr(type,mode) << " " << owner << "/" << group << " " << size << " " << tb << " " << name; if(type=='2') vo << " -> " << link; if(type=='1') vo << " link to " << link; Loading Loading @@ -525,7 +531,7 @@ namespace fresh { namespace cmd { return 2; } if(fd>=0){ if(root && o.sameOwner && fchown(fd,(uid_t)uid,(gid_t)gid)!=0){} if(root && o.sameOwner && fresh::ids::chownFd(fd,&ruid,&rgid)!=0){} fchmod(fd,applied); if(!o.noMtime){ struct timespec ts[2]={{mtime,0},{mtime,0}}; Loading @@ -542,13 +548,13 @@ namespace fresh { namespace cmd { continue; } if(type=='2' || type=='3' || type=='4' || type=='6'){ if(root && o.sameOwner && lchown(target.c_str(),(uid_t)uid,(gid_t)gid)!=0){} if(root && o.sameOwner && fresh::ids::chownPath(target,false,&ruid,&rgid)!=0){} if(!o.noMtime){ struct timespec ts[2]={{mtime,0},{mtime,0}}; utimensat(AT_FDCWD,target.c_str(),ts,AT_SYMLINK_NOFOLLOW); } } if(type=='5' && root && o.sameOwner && chown(target.c_str(),(uid_t)uid,(gid_t)gid)!=0){} if(type=='5' && root && o.sameOwner && fresh::ids::chownPath(target,true,&ruid,&rgid)!=0){} } // directories last: their contents changed their mtime Loading Loading @@ -651,6 +657,12 @@ namespace fresh { namespace cmd { if(!split(name,pre,nm)){ recs["path"]=name; nm=name.substr(0,99); pre.clear(); } if(link.size()>100) recs["linkpath"]=link; if(!fitsOctal(size,12)) recs["size"]=std::to_string(size); // a UUID or GUID owner goes into a pax record (vendor // keyword; other tars ignore it and see the overflow id) uid_r_t ruid; gid_r_t rgid; fresh::ids::fileIds(path,false,st,ruid,rgid); if(!uid_r_is_legacy(&ruid)) recs["FENRIR.uid_r"]=fresh::ids::str(ruid); if(!uid_r_is_legacy(&rgid)) recs["FENRIR.gid_r"]=fresh::ids::str(rgid); if(!recs.empty()) pax(name,recs); strncpy(h.name,nm.c_str(),sizeof h.name); Loading @@ -664,10 +676,12 @@ namespace fresh { namespace cmd { h.typeflag=type; memcpy(h.magic,"ustar",6); memcpy(h.version,"00",2); struct passwd *pw=o.numericOwner ? nullptr : getpwuid(st.st_uid); struct group *gr=o.numericOwner ? nullptr : getgrgid(st.st_gid); if(pw) strncpy(h.uname,pw->pw_name,sizeof h.uname-1); if(gr) strncpy(h.gname,gr->gr_name,sizeof h.gname-1); if(!o.numericOwner){ std::string un=fresh::ids::hasUserName(ruid) ? fresh::ids::userName(ruid) : ""; std::string gn=fresh::ids::hasGroupName(rgid) ? fresh::ids::groupName(rgid) : ""; strncpy(h.uname,un.c_str(),sizeof h.uname-1); strncpy(h.gname,gn.c_str(),sizeof h.gname-1); } if(type=='3' || type=='4'){ setNum(h.devmajor,8,major(st.st_rdev)); setNum(h.devminor,8,minor(st.st_rdev)); Loading Loading
commands/editor/sed.cpp +9 −1 Changes for commands/editor/sed.cpp: 9 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <sys/stat.h> #include "shell.h" #include "ids.h" namespace fresh { namespace cmd { Loading Loading @@ -994,8 +995,15 @@ namespace fresh { namespace cmd { if(rc==4){ unlink(tmp.c_str()); return 4; } if(rc) status=rc; } { // the file's owner, a UUID or GUID one too (classic // chown() would hand the file to the overflow id); // chown first, it clears setuid and setgid uid_r_t ou; gid_r_t og; fresh::ids::fileIds(f,true,st,ou,og); if(fresh::ids::chownPath(tmp,false,&ou,&og)!=0){} } chmod(tmp.c_str(),st.st_mode & 07777); if(chown(tmp.c_str(),st.st_uid,st.st_gid)!=0){} if(!r.inPlaceSuffix.empty()){ std::string backup; if(r.inPlaceSuffix.find('*')!=std::string::npos){ Loading
commands/system/tar.cpp +23 −9 Changes for commands/system/tar.cpp: 23 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -59,6 +59,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <grp.h> #include "shell.h" #include "ids.h" namespace fresh { namespace cmd { Loading Loading @@ -367,6 +368,11 @@ namespace fresh { namespace cmd { unsigned long uid=(unsigned long)getNum(h.uid,sizeof h.uid),gid=(unsigned long)getNum(h.gid,sizeof h.gid); if(attrs.count("uid")) uid=strtoul(attrs["uid"].c_str(),nullptr,10); if(attrs.count("gid")) gid=strtoul(attrs["gid"].c_str(),nullptr,10); // UUID or GUID owners (see -c), otherwise the classic ids uid_r_t ruid=uid_r_legacy((unsigned)uid); gid_r_t rgid=uid_r_legacy((unsigned)gid); if(attrs.count("FENRIR.uid_r")) uid_r_from_str(attrs["FENRIR.uid_r"].c_str(),&ruid); if(attrs.count("FENRIR.gid_r")) uid_r_from_str(attrs["FENRIR.gid_r"].c_str(),&rgid); if(type=='5' && !name.empty() && name.back()!='/') name+='/'; if(type=='0' && !name.empty() && name.back()=='/') type='5'; Loading Loading @@ -414,8 +420,8 @@ namespace fresh { namespace cmd { localtime_r(&mtime,&tmv); strftime(tb,sizeof tb,"%Y-%m-%d %H:%M",&tmv); std::string owner=field(h.uname,sizeof h.uname),group=field(h.gname,sizeof h.gname); if(owner.empty() || o.numericOwner) owner=std::to_string(uid); if(group.empty() || o.numericOwner) group=std::to_string(gid); if(owner.empty() || o.numericOwner) owner=fresh::ids::str(ruid); if(group.empty() || o.numericOwner) group=fresh::ids::str(rgid); vo << modeStr(type,mode) << " " << owner << "/" << group << " " << size << " " << tb << " " << name; if(type=='2') vo << " -> " << link; if(type=='1') vo << " link to " << link; Loading Loading @@ -525,7 +531,7 @@ namespace fresh { namespace cmd { return 2; } if(fd>=0){ if(root && o.sameOwner && fchown(fd,(uid_t)uid,(gid_t)gid)!=0){} if(root && o.sameOwner && fresh::ids::chownFd(fd,&ruid,&rgid)!=0){} fchmod(fd,applied); if(!o.noMtime){ struct timespec ts[2]={{mtime,0},{mtime,0}}; Loading @@ -542,13 +548,13 @@ namespace fresh { namespace cmd { continue; } if(type=='2' || type=='3' || type=='4' || type=='6'){ if(root && o.sameOwner && lchown(target.c_str(),(uid_t)uid,(gid_t)gid)!=0){} if(root && o.sameOwner && fresh::ids::chownPath(target,false,&ruid,&rgid)!=0){} if(!o.noMtime){ struct timespec ts[2]={{mtime,0},{mtime,0}}; utimensat(AT_FDCWD,target.c_str(),ts,AT_SYMLINK_NOFOLLOW); } } if(type=='5' && root && o.sameOwner && chown(target.c_str(),(uid_t)uid,(gid_t)gid)!=0){} if(type=='5' && root && o.sameOwner && fresh::ids::chownPath(target,true,&ruid,&rgid)!=0){} } // directories last: their contents changed their mtime Loading Loading @@ -651,6 +657,12 @@ namespace fresh { namespace cmd { if(!split(name,pre,nm)){ recs["path"]=name; nm=name.substr(0,99); pre.clear(); } if(link.size()>100) recs["linkpath"]=link; if(!fitsOctal(size,12)) recs["size"]=std::to_string(size); // a UUID or GUID owner goes into a pax record (vendor // keyword; other tars ignore it and see the overflow id) uid_r_t ruid; gid_r_t rgid; fresh::ids::fileIds(path,false,st,ruid,rgid); if(!uid_r_is_legacy(&ruid)) recs["FENRIR.uid_r"]=fresh::ids::str(ruid); if(!uid_r_is_legacy(&rgid)) recs["FENRIR.gid_r"]=fresh::ids::str(rgid); if(!recs.empty()) pax(name,recs); strncpy(h.name,nm.c_str(),sizeof h.name); Loading @@ -664,10 +676,12 @@ namespace fresh { namespace cmd { h.typeflag=type; memcpy(h.magic,"ustar",6); memcpy(h.version,"00",2); struct passwd *pw=o.numericOwner ? nullptr : getpwuid(st.st_uid); struct group *gr=o.numericOwner ? nullptr : getgrgid(st.st_gid); if(pw) strncpy(h.uname,pw->pw_name,sizeof h.uname-1); if(gr) strncpy(h.gname,gr->gr_name,sizeof h.gname-1); if(!o.numericOwner){ std::string un=fresh::ids::hasUserName(ruid) ? fresh::ids::userName(ruid) : ""; std::string gn=fresh::ids::hasGroupName(rgid) ? fresh::ids::groupName(rgid) : ""; strncpy(h.uname,un.c_str(),sizeof h.uname-1); strncpy(h.gname,gn.c_str(),sizeof h.gname-1); } if(type=='3' || type=='4'){ setNum(h.devmajor,8,major(st.st_rdev)); setNum(h.devminor,8,minor(st.st_rdev)); Loading