Get user ID for name on Linux

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Get user ID for name on Linux

tobiasgiesen
Hello,

I would like to get the user ID for a Linux user name.

Unfortunately Libc and UnixUtils don't seem to be available in 64-bit, so I can't call the
functions getpwnam or GetUserId. Is there a replacement? Or could I define and
import the function myself?

Thanks for any help!

Cheers,
Tobias


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Get user ID for name on Linux

Marco van de Voort
In our previous episode, Tobias Giesen said:
> I would like to get the user ID for a Linux user name.
>
> Unfortunately Libc and UnixUtils don't seem to be available in 64-bit, so I can't call the
> functions getpwnam or GetUserId. Is there a replacement? Or could I define and
> import the function myself?

Try the units in package users (packages/users in the sources)
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Get user ID for name on Linux

Graeme Geldenhuys-6
In reply to this post by tobiasgiesen
On 2018-01-03 00:12, Tobias Giesen wrote:
> Unfortunately Libc and UnixUtils don't seem to be available in 64-bit, so I can't call the
> functions getpwnam or GetUserId.

As Marco said, you can use the "users" unit. Here is an example of how I
use in in fpGUI, and it supports 32-bit and 64-bit systems.

 
https://github.com/graemeg/fpGUI/blob/develop/src/corelib/x11/fpg_x11.pas#L4010-L4044

Note though that it only works for Linux. So other UNIX-type systems
like FreeBSD and Solaris are not supported.


Regards,
   Graeme

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Get user ID for name on Linux

Giuliano Colla
In reply to this post by tobiasgiesen

Il 03/01/2018 01:12, Tobias Giesen ha scritto:

I would like to get the user ID for a Linux user name.

You might execute from the application the "/usr/bin/id" command which should exist in any Linux flavour passing the required user name ( if it's the current user, UserName := GetEnvironmentVariableUTF8('USERNAME'); ) as a parameter and then parse the resulting output, sort of:

uid=500(colla) gid=500(colla) groups=500(colla),3(sys),5(tty),18(dialout)

Giuliano


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Get user ID for name on Linux

tobiasgiesen
In reply to this post by Graeme Geldenhuys-6
Many thanks! That's great. The completeness of FPC units and packages is really
astonishing.

Cheers,
Tobias

----

On Wed, 3 Jan 2018 06:36:32 +0000
Graeme Geldenhuys <[hidden email]> wrote:

> On 2018-01-03 00:12, Tobias Giesen wrote:
> > Unfortunately Libc and UnixUtils don't seem to be available in 64-bit, so I can't call the
> > functions getpwnam or GetUserId.
>
> As Marco said, you can use the "users" unit. Here is an example of how I
> use in in fpGUI, and it supports 32-bit and 64-bit systems.
>
>  
> https://github.com/graemeg/fpGUI/blob/develop/src/corelib/x11/fpg_x11.pas#L4010-L4044
>
> Note though that it only works for Linux. So other UNIX-type systems
> like FreeBSD and Solaris are not supported.
>
>
> Regards,
>    Graeme
>
> --
> fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
> http://fpgui.sourceforge.net/
>
> My public PGP key:  http://tinyurl.com/graeme-pgp
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Kind Regards,
Tobias Giesen

Super Flexible Software Ltd. & Co. KG
Buddenstr. 29-31
48143 Münster, Germany
www.superflexible.com
www.tgtools.com

-----------------------------------------------------------
Registered at register court Münster as HRA 9716
Liability / general partner: TGTools Ltd.
Company No. 05513299
Registered in England and Wales
Directors: Tobias Giesen and Claudia Giesen

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Get user ID for name on Linux

geneb
On Wed, 3 Jan 2018, Tobias Giesen wrote:

> Many thanks! That's great. The completeness of FPC units and packages is really
> astonishing.
>
Is there a complete list of packages available somewhere?

tnx.

g.

--
Proud owner of F-15C 80-0007
http://www.f15sim.com - The only one of its kind.
http://www.diy-cockpits.org/coll - Go Collimated or Go Home.
Some people collect things for a hobby.  Geeks collect hobbies.

ScarletDME - The red hot Data Management Environment
A Multi-Value database for the masses, not the classes.
http://scarlet.deltasoft.com - Get it _today_!
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Get user ID for name on Linux

Marco van de Voort
In our previous episode, geneb said:
>
> > Many thanks! That's great. The completeness of FPC units and packages is really
> > astonishing.
> >
> Is there a complete list of packages available somewhere?

There is some info(1) in the wiki, though many details are missing, and the
status of each package is not explicitely recorded.

There however is a page specific about the libc_unit (2) that named the
 "users" package as a replacement for certain calls.

(1) http://wiki.freepascal.org/Package_List
(2) http://wiki.freepascal.org/libc_unit
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Get user ID for name on Linux

geneb
On Wed, 3 Jan 2018, Marco van de Voort wrote:

> In our previous episode, geneb said:
>>
>> > Many thanks! That's great. The completeness of FPC units and packages is really
>> > astonishing.
>> >
>> Is there a complete list of packages available somewhere?
>
> There is some info(1) in the wiki, though many details are missing, and the
> status of each package is not explicitely recorded.
>
> There however is a page specific about the libc_unit (2) that named the
> "users" package as a replacement for certain calls.
>
Thanks for the info Marco.
g
.

--
Proud owner of F-15C 80-0007
http://www.f15sim.com - The only one of its kind.
http://www.diy-cockpits.org/coll - Go Collimated or Go Home.
Some people collect things for a hobby.  Geeks collect hobbies.

ScarletDME - The red hot Data Management Environment
A Multi-Value database for the masses, not the classes.
http://scarlet.deltasoft.com - Get it _today_!
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Get user ID for name on Linux

Free Pascal - General mailing list
In reply to this post by geneb
> Is there a complete list of packages available somewhere?

$ svn co https://svn.freepascal.org/svn/fpc/trunk fpc
$ cd fpc/packages
$ ls

tadaaa...




--
Sent from: http://free-pascal-general.1045716.n5.nabble.com/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Get user ID for name on Linux

Marco van de Voort
In reply to this post by Graeme Geldenhuys-6
In our previous episode, Graeme Geldenhuys said:
> As Marco said, you can use the "users" unit. Here is an example of how I
> use in in fpGUI, and it supports 32-bit and 64-bit systems.
>
>  
> https://github.com/graemeg/fpGUI/blob/develop/src/corelib/x11/fpg_x11.pas#L4010-L4044
>
> Note though that it only works for Linux. So other UNIX-type systems
> like FreeBSD and Solaris are not supported.

FreeBSD is mostly supported,  though two units (shadow and crypth) and some calls
relating to shadow passwords in users are not.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Get user ID for name on Linux

Graeme Geldenhuys-6
On 2018-01-04 15:17, Marco van de Voort wrote:
> FreeBSD is mostly supported,  though two units (shadow and crypth) and some calls
> relating to shadow passwords in users are not.

Thanks for the information Marco. I'll take a look.

Regards,
   Graeme

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal