Execute system calls directly

system-calls

Provided a user is authorized to access something, how can he execute a system call directly, like geteuid() – get effective user ID (it's just an example) from bash, how could I do it?

Best Answer

User-space kernel-space communication via system calls is done in terms of memory locations and machine registers. That's way below the abstraction level of shells, which operate mainly with text strings.

That said, in bash, you can use the https://github.com/taviso/ctypes.sh plugin to get through the text-string abstraction down to C-level granularity:

$ . ctypes.sh
$ dlcall -r long geteuid
long:1001

For this particular operation though, it would be much simpler, more idiomatic, and more efficient to simply use bash's magic $UID variable.

$ echo "$EUID" #effectively a cached geteuid call
1001
Related Question