cuserid(), getlogin(), et. al. fail on OSR6 - SCO

This is a discussion on cuserid(), getlogin(), et. al. fail on OSR6 - SCO ; OSR6 with MP1 When the following program is built in UDK mode, getlogin() and cuserid() both return success but produce no output. getlogin_r() returns success but produces bad output. When built in OSR mode all three functions behave as expected. ...

+ Reply to Thread
Results 1 to 9 of 9

Thread: cuserid(), getlogin(), et. al. fail on OSR6

  1. cuserid(), getlogin(), et. al. fail on OSR6

    OSR6 with MP1

    When the following program is built in UDK mode, getlogin() and
    cuserid() both return success but produce no output. getlogin_r()
    returns success but produces bad output.

    When built in OSR mode all three functions behave as expected.

    Is there a known problem with these functions on OSR6?

    #include
    #include

    main()
    {
    char buf[128], *t, *s = buf;

    if ((t = getlogin()) != NULL)
    printf("getlogin() =<%s>\n",t);

    #ifdef __OPENSERVER__
    if (getlogin_r(s, sizeof(buf)))
    #else
    if (getlogin_r(s, sizeof(buf)) == 0)
    #endif
    printf("getlogin_r()=<%s>\n", s);

    if ((t = cuserid(NULL)) != NULL)
    printf("cuserid() =<%s>\n", t);
    }


  2. Re: cuserid(), getlogin(), et. al. fail on OSR6

    Roger Cornelius wrote:

    > OSR6 with MP1
    >
    > When the following program is built in UDK mode, getlogin() and
    > cuserid() both return success but produce no output. getlogin_r()
    > returns success but produces bad output.
    >
    > When built in OSR mode all three functions behave as expected.
    >
    > Is there a known problem with these functions on OSR6?
    >
    > #include
    > #include
    >
    > main()
    > {
    > char buf[128], *t, *s = buf;
    >
    > if ((t = getlogin()) != NULL)
    > printf("getlogin() =<%s>\n",t);
    >
    > #ifdef __OPENSERVER__
    > if (getlogin_r(s, sizeof(buf)))
    > #else
    > if (getlogin_r(s, sizeof(buf)) == 0)
    > #endif
    > printf("getlogin_r()=<%s>\n", s);
    >
    > if ((t = cuserid(NULL)) != NULL)
    > printf("cuserid() =<%s>\n", t);
    > }


    Compile it both ways, run them under `truss` -- are they opening the
    same files? Do they issue read() system calls in the same sizes?

    For reference, the OSR5 library code opens /etc/utmp and reads in
    36-byte chunks...

    >Bela<


  3. Re: cuserid(), getlogin(), et. al. fail on OSR6

    Bela Lubkin wrote:
    > Roger Cornelius wrote:
    >
    > > OSR6 with MP1
    > >
    > > When the following program is built in UDK mode, getlogin() and
    > > cuserid() both return success but produce no output. getlogin_r()
    > > returns success but produces bad output.
    > >
    > > When built in OSR mode all three functions behave as expected.
    > >
    > > Is there a known problem with these functions on OSR6?
    > >
    > > #include
    > > #include
    > >
    > > main()
    > > {
    > > char buf[128], *t, *s = buf;
    > >
    > > if ((t = getlogin()) != NULL)
    > > printf("getlogin() =<%s>\n",t);
    > >
    > > #ifdef __OPENSERVER__
    > > if (getlogin_r(s, sizeof(buf)))
    > > #else
    > > if (getlogin_r(s, sizeof(buf)) == 0)
    > > #endif
    > > printf("getlogin_r()=<%s>\n", s);
    > >
    > > if ((t = cuserid(NULL)) != NULL)
    > > printf("cuserid() =<%s>\n", t);
    > > }

    >
    > Compile it both ways, run them under `truss` -- are they opening the
    > same files? Do they issue read() system calls in the same sizes?
    >
    > For reference, the OSR5 library code opens /etc/utmp and reads in
    > 36-byte chunks...


    In the osr mode binary, getlogin() and getlogin_r() read /etc/utmp 36
    bytes at a time. cuserid() just does getuid() and looks up the result
    in /etc/passwd.

    In the udk binary, all three functions read /var/adm/utmpx in 372 byte
    chunks, which is the sizeof(utmpx) in udk mode. The problem is that
    /var/tmp/utmpx is written in 368 byte chunks which is the sizeof(utmpx)
    in osr mode.

    Is this intentional? Won't any program that manipulates utmpx using
    the standard functions have to be compiled in osr mode,


  4. Re: cuserid(), getlogin(), et. al. fail on OSR6

    Roger Cornelius wrote:
    > Bela Lubkin wrote:
    > > Roger Cornelius wrote:
    > >
    > > > OSR6 with MP1
    > > >
    > > > When the following program is built in UDK mode, getlogin() and
    > > > cuserid() both return success but produce no output. getlogin_r()
    > > > returns success but produces bad output.
    > > >
    > > > When built in OSR mode all three functions behave as expected.
    > > >
    > > > Is there a known problem with these functions on OSR6?
    > > >
    > > > #include
    > > > #include
    > > >
    > > > main()
    > > > {
    > > > char buf[128], *t, *s = buf;
    > > >
    > > > if ((t = getlogin()) != NULL)
    > > > printf("getlogin() =<%s>\n",t);
    > > >
    > > > #ifdef __OPENSERVER__
    > > > if (getlogin_r(s, sizeof(buf)))
    > > > #else
    > > > if (getlogin_r(s, sizeof(buf)) == 0)
    > > > #endif
    > > > printf("getlogin_r()=<%s>\n", s);
    > > >
    > > > if ((t = cuserid(NULL)) != NULL)
    > > > printf("cuserid() =<%s>\n", t);
    > > > }

    > >
    > > Compile it both ways, run them under `truss` -- are they opening the
    > > same files? Do they issue read() system calls in the same sizes?
    > >
    > > For reference, the OSR5 library code opens /etc/utmp and reads in
    > > 36-byte chunks...

    >
    > In the osr mode binary, getlogin() and getlogin_r() read /etc/utmp 36
    > bytes at a time. cuserid() just does getuid() and looks up the result
    > in /etc/passwd.
    >
    > In the udk binary, all three functions read /var/adm/utmpx in 372 byte
    > chunks, which is the sizeof(utmpx) in udk mode. The problem is that
    > /var/tmp/utmpx is written in 368 byte chunks which is the sizeof(utmpx)
    > in osr mode.


    Of course that should have been sizeof(struct utmpx) and
    /var/adm/utmpx.

    > Is this intentional? Won't any program that manipulates utmpx using
    > the standard functions have to be compiled in osr mode,



  5. Re: cuserid(), getlogin(), et. al. fail on OSR6

    Roger Cornelius wrote:
    > Roger Cornelius wrote:
    > > Bela Lubkin wrote:
    > > > Roger Cornelius wrote:
    > > >
    > > > > OSR6 with MP1
    > > > >
    > > > > When the following program is built in UDK mode, getlogin() and
    > > > > cuserid() both return success but produce no output. getlogin_r()
    > > > > returns success but produces bad output.
    > > > >
    > > > > When built in OSR mode all three functions behave as expected.
    > > > >
    > > > > Is there a known problem with these functions on OSR6?
    > > > >
    > > > > #include
    > > > > #include
    > > > >
    > > > > main()
    > > > > {
    > > > > char buf[128], *t, *s = buf;
    > > > >
    > > > > if ((t = getlogin()) != NULL)
    > > > > printf("getlogin() =<%s>\n",t);
    > > > >
    > > > > #ifdef __OPENSERVER__
    > > > > if (getlogin_r(s, sizeof(buf)))
    > > > > #else
    > > > > if (getlogin_r(s, sizeof(buf)) == 0)
    > > > > #endif
    > > > > printf("getlogin_r()=<%s>\n", s);
    > > > >
    > > > > if ((t = cuserid(NULL)) != NULL)
    > > > > printf("cuserid() =<%s>\n", t);
    > > > > }
    > > >
    > > > Compile it both ways, run them under `truss` -- are they opening the
    > > > same files? Do they issue read() system calls in the same sizes?
    > > >
    > > > For reference, the OSR5 library code opens /etc/utmp and reads in
    > > > 36-byte chunks...

    > >
    > > In the osr mode binary, getlogin() and getlogin_r() read /etc/utmp 36
    > > bytes at a time. cuserid() just does getuid() and looks up the result
    > > in /etc/passwd.
    > >
    > > In the udk binary, all three functions read /var/adm/utmpx in 372 byte
    > > chunks, which is the sizeof(utmpx) in udk mode. The problem is that
    > > /var/tmp/utmpx is written in 368 byte chunks which is the sizeof(utmpx)
    > > in osr mode.

    >
    > Of course that should have been sizeof(struct utmpx) and
    > /var/adm/utmpx.
    >
    > > Is this intentional? Won't any program that manipulates utmpx using
    > > the standard functions have to be compiled in osr mode,


    A little more info.

    The udk utmpx struct has an additional member ut_pad[4] not present in
    the osr struct utmpx, so that explains the sizeof discrepancy.

    I've tested getutxent() in udk mode and it works as expected. It reads
    utmpx 368 bytes at a time though, implying it was built using the osr
    utmpx.h.

    It seems the functions in question were built against the udk utmpx.h,
    while other library functions were built against the osr utmpx.h.


  6. Re: cuserid(), getlogin(), et. al. fail on OSR6

    Roger Cornelius wrote:

    > > > > > OSR6 with MP1
    > > > > >
    > > > > > When the following program is built in UDK mode, getlogin() and
    > > > > > cuserid() both return success but produce no output. getlogin_r()
    > > > > > returns success but produces bad output.
    > > > > >
    > > > > > When built in OSR mode all three functions behave as expected.
    > > > > >
    > > > > > Is there a known problem with these functions on OSR6?


    > The udk utmpx struct has an additional member ut_pad[4] not present in
    > the osr struct utmpx, so that explains the sizeof discrepancy.
    >
    > I've tested getutxent() in udk mode and it works as expected. It reads
    > utmpx 368 bytes at a time though, implying it was built using the osr
    > utmpx.h.
    >
    > It seems the functions in question were built against the udk utmpx.h,
    > while other library functions were built against the osr utmpx.h.


    Looks that way. I'd say, in response to your original question "Is
    there a known problem with these functions on OSR6?": now there is...

    It won't really be Officially Known unless you submit a bug report.
    Does SCO still have a working submit-a-bug web page?

    >Bela<


  7. Re: cuserid(), getlogin(), et. al. fail on OSR6

    Bela Lubkin wrote:
    > Roger Cornelius wrote:
    >
    > > > > > > OSR6 with MP1
    > > > > > >
    > > > > > > When the following program is built in UDK mode, getlogin() and
    > > > > > > cuserid() both return success but produce no output. getlogin_r()
    > > > > > > returns success but produces bad output.
    > > > > > >
    > > > > > > When built in OSR mode all three functions behave as expected.
    > > > > > >
    > > > > > > Is there a known problem with these functions on OSR6?

    >
    > > The udk utmpx struct has an additional member ut_pad[4] not present in
    > > the osr struct utmpx, so that explains the sizeof discrepancy.
    > >
    > > I've tested getutxent() in udk mode and it works as expected. It reads
    > > utmpx 368 bytes at a time though, implying it was built using the osr
    > > utmpx.h.
    > >
    > > It seems the functions in question were built against the udk utmpx.h,
    > > while other library functions were built against the osr utmpx.h.

    >
    > Looks that way. I'd say, in response to your original question "Is
    > there a known problem with these functions on OSR6?": now there is...
    >
    > It won't really be Officially Known unless you submit a bug report.
    > Does SCO still have a working submit-a-bug web page?


    Yes. It's here: http://www.sco.com/support/programs/bugform.html

    Thanks for your feedback. I will report it.


  8. Re: cuserid(), getlogin(), et. al. fail on OSR6

    Roger Cornelius wrote:
    > OSR6 with MP1
    >
    > When the following program is built in UDK mode, getlogin() and
    > cuserid() both return success but produce no output. getlogin_r()
    > returns success but produces bad output.
    > [...]


    Thanks for this report and its follow-ups. It is indeed a bug
    and it has been bug-reported internally. Hopefully it will get
    into OSR 6.0.0 mp2.

    I'm told that there's no readily usable workaround, other than to
    loop on getutmpx() looking for an entry with ut_type that's
    INIT_PROCESS, LOGIN_PROCESS or USER_PROCESS, for which its
    ut_pid matches the return of getsid(). The string returned
    by getlogin() is the one found in the ut_user[] array.

    Jonathan Schilling


  9. Re: cuserid(), getlogin(), et. al. fail on OSR6

    jlselsewhere@my-deja.com wrote:
    > Roger Cornelius wrote:
    > > OSR6 with MP1
    > >
    > > When the following program is built in UDK mode, getlogin() and
    > > cuserid() both return success but produce no output. getlogin_r()
    > > returns success but produces bad output.
    > > [...]

    >
    > Thanks for this report and its follow-ups. It is indeed a bug
    > and it has been bug-reported internally. Hopefully it will get
    > into OSR 6.0.0 mp2.
    >
    > I'm told that there's no readily usable workaround, other than to
    > loop on getutmpx() looking for an entry with ut_type that's


    I assume you meant getutxent() here - according to 'man S getutx',
    getutmpx() copies fields from a utmp struct to a utmpx struct.

    > INIT_PROCESS, LOGIN_PROCESS or USER_PROCESS, for which its
    > ut_pid matches the return of getsid(). The string returned
    > by getlogin() is the one found in the ut_user[] array.


    I believe the getutx family of functions are also broken. Following is
    the followup I submitted via
    http://www.sco.com/support/programs/buginfo.html to the original bug
    report I filed. Comments/criticisms welcome.

    This is a followup to bug report 1721; "cuserid(), getlogin(), and
    getlogin_r() are broken in UDK mode on OSR6 w/MP1"

    First, my diagnosis that the difference in size between the osr and udk
    mode versions of utmpx.h was due to ut_pad[4] was of course wrong.
    Rather, the problem is due to the difference in sizes of the ut_pid
    field which is a short in osr mode and a long in udk mode. In
    addition, the compiler is adding two bytes of padding to the struct in
    udk mode, thus accounting for the 4 byte difference.

    The problem with cuserid(), getlogin(), getlogin_r() is an indicator of
    a bigger issue. 'man S getpid' says getpid() returns pid_t, and
    assuming the udk mode is correct that pid_t is a long,
    then the 372 byte udk mode struct utmpx is correct. This infers that
    cuserid(), getlogin(), and getlogin_r() are not broken, but rather the
    erroneous output they produce is the result of correctly reading 372
    byte chunks from the utmpx file which was incorrectly written in 368
    byte chunks.

    Another consequence of this problem is that, in udk mode, the getutx
    functions are broken if you use the struct utmpx definition in utmpx.h
    (i.e., you #include ) because the functions will (incorrectly)
    read/write 368 byte chunks into/from a struct 372 bytes in length.
    E.g., the following prints the ut_host field minus it's first four
    characters:

    #include
    main()
    {
    char host[258];
    struct utmpx *utp;
    while ((utp = getutxent()) != NULL) {
    strncpy(host, utp->ut_host, 257);
    printf("%s\n", host);
    }
    }

    The temporary fix for the latter issue is to edit /usr/include/utmpx.h
    and change the line:

    pid_t ut_pid; /* process id */

    to:
    short ut_pid; /* process id */

    --
    Roger Cornelius rac@tenzing.org


+ Reply to Thread