Lazarus

Programming => Operating Systems => Linux => Topic started by: AlexTP on June 17, 2021, 09:12:07 pm

Title: Get/set Unix file 'owner'?
Post by: AlexTP on June 17, 2021, 09:12:07 pm
CudaText runs 'pkexec /bin/cp old_filename new_filename'.
It works OK but the owner of that file changes from 'root' to my name.
Can I change the owner of a file?
Can I read the owner of a file?
Title: Re: Get/set Unix file 'owner'?
Post by: winni on June 17, 2021, 09:37:41 pm
Hi!

The unit BaseUnix has a wapper for the Unix command chown:

Code: Pascal  [Select][+][-]
  1. Function  FpChown   (const path : RawByteString; owner : TUid; group : TGid): cInt;

Winni
Title: Re: Get/set Unix file 'owner'?
Post by: AlexTP on June 17, 2021, 10:00:02 pm
To run the 'pkexec --user username' I need the string-user-name of file owner. How to get it?
Title: Re: Get/set Unix file 'owner'?
Post by: skalogryz on June 17, 2021, 10:08:13 pm
don't you need elevated rights (sudo) to assign "root" as the owner?
Title: Re: Get/set Unix file 'owner'?
Post by: winni on June 17, 2021, 10:08:42 pm
Hi


Use the Unix command id:

To get the UserID:
Code: Bash  [Select][+][-]
  1.  
  2. id -u winni


To get the GroupId:


Code: Bash  [Select][+][-]
  1. id -g winni


Winni

Title: Re: Get/set Unix file 'owner'?
Post by: winni on June 17, 2021, 10:10:14 pm
don't you need elevated rights (sudo) to assign "root" as the owner?

Yes

Winni
Title: Re: Get/set Unix file 'owner'?
Post by: winni on June 17, 2021, 10:36:43 pm
Hi!

Oops - you need it vice versa.

For UserId 1000  you use:

Code: Bash  [Select][+][-]
  1. grep - w 1000 /etc/passwd

It returns in my case:

Code: Text  [Select][+][-]
  1. winni:x:1000:100::/home/winni:/bin/bash


which is:

Code: Text  [Select][+][-]
  1. UserName:pwd:UserID:GroupID:comment:HomeDirectory:shell

Winni
Title: Re: Get/set Unix file 'owner'?
Post by: AlexTP on June 17, 2021, 11:21:28 pm
Thanks.
I found that 'pkexec /bin/mv' does NOT set root owner. But 'pkexec /bin/cp filename /etc/filename' does it! Solved.
TinyPortal © 2005-2018