Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
Operating Systems
»
Linux
»
Get/set Unix file 'owner'?
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
IRC channel
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
android
by
BlueIcaro
[
Today
at 11:41:53 am]
Combined pointer style
by
wp
[
Today
at 11:40:45 am]
Initiaiizing records by c...
by
Molochnik
[
Today
at 11:38:56 am]
Lazarus character map
by
Thaddy
[
Today
at 11:24:42 am]
Square Fractal: A bit dif...
by
Boleeman
[
Today
at 10:47:20 am]
Tpagecontrol descendant
by
dseligo
[
Today
at 10:29:02 am]
Here's some Pong game. Su...
by
Seenkao
[
Today
at 10:16:13 am]
Using WebAssemblies
by
marcov
[
Today
at 10:02:12 am]
lamw
by
dseligo
[
Today
at 09:35:00 am]
"fpc.cfg is missing" (not...
by
Thaddy
[
Today
at 08:55:31 am]
Fairtris 2: The Ultimate ...
by
TRon
[
Today
at 08:48:08 am]
A question on Modula2 vs ...
by
MarkMLl
[
Today
at 08:39:26 am]
Offical launch of the 1 B...
by
Thaddy
[
Today
at 08:37:40 am]
Indeed TCustomApplication...
by
Gustavo 'Gus' Carreno
[
Today
at 08:22:53 am]
[Solved] Help with sql
by
TRon
[
Today
at 08:21:18 am]
Hypocycloid Program (incl...
by
speter
[
Today
at 05:33:19 am]
Designer
by
SandyG
[
Today
at 03:20:24 am]
Best way to exchange data...
by
cdbc
[
Today
at 03:00:24 am]
scanline example
by
speter
[
Today
at 12:12:12 am]
Pack
by
domasz
[March 18, 2024, 10:24:35 pm]
IsManagedType problem, do...
by
PascalDragon
[March 18, 2024, 10:05:44 pm]
Conflict when static link...
by
tetrastes
[March 18, 2024, 10:05:28 pm]
Interesting discovery wit...
by
wp
[March 18, 2024, 09:11:23 pm]
Use Lazarus 3.2 with FPC ...
by
AxBen
[March 18, 2024, 08:56:42 pm]
More Normal Mode for Laza...
by
RayoGlauco
[March 18, 2024, 08:55:53 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Get/set Unix file 'owner'? (Read 4349 times)
AlexTP
Hero Member
Posts: 2365
Get/set Unix file 'owner'?
«
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?
«
Last Edit: June 17, 2021, 09:22:23 pm by Alextp
»
Logged
CudaText editor
-
ATSynEdit
-
More from me
winni
Hero Member
Posts: 3197
Re: Get/set Unix file 'owner'?
«
Reply #1 on:
June 17, 2021, 09:37:41 pm »
Hi!
The unit
BaseUnix
has a wapper for the Unix command
chown
:
Code: Pascal
[Select]
[+]
[-]
Function
FpChown
(
const
path
:
RawByteString
;
owner
:
TUid
;
group
:
TGid
)
:
cInt
;
Winni
Logged
AlexTP
Hero Member
Posts: 2365
Re: Get/set Unix file 'owner'?
«
Reply #2 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?
Logged
CudaText editor
-
ATSynEdit
-
More from me
skalogryz
Global Moderator
Hero Member
Posts: 2770
Re: Get/set Unix file 'owner'?
«
Reply #3 on:
June 17, 2021, 10:08:13 pm »
don't you need elevated rights (sudo) to assign "root" as the owner?
Logged
winni
Hero Member
Posts: 3197
Re: Get/set Unix file 'owner'?
«
Reply #4 on:
June 17, 2021, 10:08:42 pm »
Hi
Use the Unix command
id
:
To get the UserID:
Code: Bash
[Select]
[+]
[-]
id
-u
winni
To get the GroupId:
Code: Bash
[Select]
[+]
[-]
id
-g
winni
Winni
Logged
winni
Hero Member
Posts: 3197
Re: Get/set Unix file 'owner'?
«
Reply #5 on:
June 17, 2021, 10:10:14 pm »
Quote from: skalogryz on June 17, 2021, 10:08:13 pm
don't you need elevated rights (sudo) to assign "root" as the owner?
Yes
Winni
Logged
winni
Hero Member
Posts: 3197
Re: Get/set Unix file 'owner'?
«
Reply #6 on:
June 17, 2021, 10:36:43 pm »
Hi!
Oops - you need it vice versa.
For UserId 1000 you use:
Code: Bash
[Select]
[+]
[-]
grep
-
w
1000
/
etc
/
passwd
It returns in my case:
Code: Text
[Select]
[+]
[-]
winni:x:1000:100::/home/winni:/bin/bash
which is:
Code: Text
[Select]
[+]
[-]
UserName:pwd:UserID:GroupID:comment:HomeDirectory:shell
Winni
«
Last Edit: June 17, 2021, 10:41:29 pm by winni
»
Logged
AlexTP
Hero Member
Posts: 2365
Re: Get/set Unix file 'owner'?
«
Reply #7 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.
Logged
CudaText editor
-
ATSynEdit
-
More from me
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
Operating Systems
»
Linux
»
Get/set Unix file 'owner'?
TinyPortal
© 2005-2018