• User id

    From [via djgpp@delorie.com]" @21:1/5 to All on Tue Jul 21 19:25:40 2020
    Hi all,

    How do I convince BASH that I'm root and that my UID is 0 and not 42?

    I've tried editing the "djgpp.env" file.

    I also tried installing an "etc/passwd" file under the djgpp
    directory, with "dosuser" listed as having uid 0.

    Regards,
    Albert.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From [via djgpp@delorie.com]" @21:1/5 to All on Thu Jul 23 21:07:34 2020
    Am 21.07.2020 21:25, schrieb A. Wik (awik32@gmail.com) [via djgpp@delorie.com]:
    Hi all,

    How do I convince BASH that I'm root and that my UID is 0 and not 42?

    I've tried editing the "djgpp.env" file.

    I also tried installing an "etc/passwd" file under the djgpp
    directory, with "dosuser" listed as having uid 0.

    Regards,
    Albert.

    There is no way to do what you want to do.
    MSDOS does not know anything about uid and similars thus neither the port nor the c library supports them in the way it is known from unix. All versions
    of this port have relayed on the getuid and setuid functions provided by the library. Because there is nothing like uid and alike on MSDOS these functions emulate them for porting purposes with hard coded values. In the case of uid/gid
    the value is 42 when read by getuid and expects an uid of 42 when set by setuid;
    any different value will make setuid fail with EPERM.
    Currently I have no intentions to update the bash port providing such an uid/gid
    emulation. I even would not really know how to implement it in a way that it becomes a serious emulation of the unix functionality completely missed on MSDOS.
    If you are completely despaired to have a root uid behaviour, you will have
    to modify the code of the [g|s]etui() functions of the library in such a way that they read a defined environment variable that defines the current uid/gid to be used. With this modified libc.a you can then recompile the bash port and see what happens. But it is clear that no other program than the recompiled bash port will know about this modified g|s]etui(). In the worst case you would have to recompile also the shell utilities and file utilities and some other ports more. And if they really behave as root user mode on plain DOS needs to be investigated.
    If all this is worth to be done must be decided by you. I am also not really convinced that this will work at all.

    Regards,
    Juan M. Guerrero

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From [via djgpp@delorie.com]" @21:1/5 to All on Fri Jul 24 13:28:36 2020
    Hi,

    and thanks for your elaborate reply.

    On Thu, 23 Jul 2020 at 19:15, Juan Manuel Guerrero
    (juan.guerrero@gmx.de) [via djgpp@delorie.com] <djgpp@delorie.com>
    wrote:

    Am 21.07.2020 21:25, schrieb A. Wik (awik32@gmail.com) [via djgpp@delorie.com]:
    Hi all,

    How do I convince BASH that I'm root and that my UID is 0 and not 42?

    I've tried editing the "djgpp.env" file.

    I also tried installing an "etc/passwd" file under the djgpp
    directory, with "dosuser" listed as having uid 0.

    Regards,
    Albert.

    There is no way to do what you want to do.
    MSDOS does not know anything about uid and similars

    Of course, I think we all know that.

    thus neither the port nor
    the c library supports them in the way it is known from unix. All versions of this port have relayed on the getuid and setuid functions provided by the library. Because there is nothing like uid and alike on MSDOS these functions
    emulate them for porting purposes with hard coded values. In the case of uid/gid
    the value is 42 when read by getuid and expects an uid of 42 when set by setuid;
    any different value will make setuid fail with EPERM.

    I understand.

    Currently I have no intentions to update the bash port providing such an uid/gid
    emulation. I even would not really know how to implement it in a way that it becomes a serious emulation of the unix functionality completely missed on MSDOS.

    It doesn't need to be "serious". It does, in my mind, have to be configurable.

    If you are completely despaired to have a root uid behaviour, you will have to modify the code of the [g|s]etui() functions of the library in such a way that they read a defined environment variable that defines the current uid/gid
    to be used.

    Right. Using the environment variables sounds like a reasonable solution.

    With this modified libc.a you can then recompile the bash port and
    see what happens. But it is clear that no other program than the recompiled bash port will know about this modified g|s]etui(). In the worst case you would have to recompile also the shell utilities and file utilities and some other ports more. And if they really behave as root user mode on plain DOS needs to be investigated.
    If all this is worth to be done must be decided by you. I am also not really convinced that this will work at all.

    I used a shortcut solution. I have a utility program called HIEW.EXE,
    which can display a file in hex, ASCII, and 16/32-bit assembly
    language, and also edit them.

    First, I did this:
    C:\djgpp\lib\x>ar -xov ../libc.a getuid.o
    x - getuid.o

    Examining getuid.o, I found out that the relevant machine code is 0xB8,2A,00,00,00 for "mov eax, 42". I patched BASH, the C-library
    (libc.a), and the "id.exe" utility, replacing 0x2A with 00. I also
    replaced "dosuser\0" with "root\0er\0". I left the group name as
    "dos" for obvious reasons.

    Result:
    C:\djgpp\lib\x>bash
    bash-2.04# id
    uid=0(root) gid=0(dos)
    bash-2.04#

    But in the longer term, this should be fixed in the C library. I
    guess it is easy enough that I could even do it myself. We'll see.

    Cheers,
    Albert.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)