• Re: Check if a program in an executable, was: Ho do I check if a number

    From Ottavio Caruso@21:1/5 to Ottavio Caruso on Thu Mar 24 15:49:44 2022
    On 24/03/2022 15:45, Ottavio Caruso wrote:
    I genuinely don't have a stable Internet connection and I have to rely
    to the *couch* public library or what remains of it):

    And the typos are an evidence of this, plus lack of sleep.

    s/a program in/a program is
    s/ho/how
    s/couch/cough

    and possibly more.

    --
    Ottavio Caruso

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Grant Taylor@21:1/5 to Ottavio Caruso on Thu Mar 24 14:08:24 2022
    On 3/24/22 9:45 AM, Ottavio Caruso wrote:
    Thanks it makes sense, but I'd like to rephrase my question (and
    sorry that I didn't do my homework. I genuinely don't have a stable
    Internet connection and I have to rely to the *couch* public library
    or what remains of it):

    IMHO there's no need to apologize. I consider the nature of discussions
    to involve learning and / or corrections and / or clarifications.

    How can I check that a number of programs are installed _and_ point
    to a true executable rather than a shell script or similar?

    It sounds like you mean "binary" as opposed to "executable". I consider scripts to be executables.

    I'd suggest focusing on a (repeatable) process to check an individual
    file to determine if it meets your standards or not.

    Once you have that process you would loop across the list of files to
    see if each file.

    Now, I prevent one of the possible objections: Debian makes great
    use of alternatives[1], therefore most programs do point to a shell
    script or a link rather than an executable. I'll have to make an
    explicit exception for Debian/Ubuntu and similar.

    I know that some programs actually use sym-links to provide varies ways
    to invoke the compiled binary. BusyBox is an example of such a
    quintessential binary wherein many different command names link to one
    binary and the binary behaves differently based on the invoking name.

    Another example is contemporary Solaris systems making /bin itself a
    sym-link to /usr/bin. So, what would you consider /bin/ls which is (indirectly) a sym-link to /usr/bin/ls.

    Aside: What if hard links are used in lieu of sym-links?

    Without a clear definition of what a proper executable (binary?) is,
    it's near impossible to derive a test that takes into account many
    different things that Unix has done over the years. Especially if you
    want to account for more esoteric things like over-mounting, hard links, LD_PRELOAD interceptions, etc.



    --
    Grant. . . .
    unix || die

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Geoff Clare@21:1/5 to Ottavio Caruso on Fri Mar 25 13:40:46 2022
    Ottavio Caruso wrote:

    How can I check that a number of programs are installed _and_ point to a
    true executable rather than a shell script or similar?

    Shell scripts *are* true executables. For example:

    $ type google-chrome
    google-chrome is /bin/google-chrome
    $ file /bin/google-chrome
    /bin/google-chrome: Bourne-Again shell script, ASCII text executable

    This is the genuine google-chrome browser, as provided by Google in
    a .deb package. Of course, the script ends up executing a binary,
    but that binary is not intended to be executed directly by users.

    If you want to distinguish original shell scripts from ones a user
    has created, you could perhaps use command -p -v to do a PATH search
    of only the "system" PATH instead of the user's PATH. However, there
    can be legitimate reasons for users to create wrapper scripts. For
    example, I have:

    $ cat ~/bin/mutt
    #! /bin/sh

    # this prevents blinking
    case $TERM in
    xterm) TERM=xterm-256color ;;
    esac

    exec /bin/mutt "$@"

    You do your users a disservice if you prevent them doing such things.

    --
    Geoff Clare <[email protected]>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenny McCormack@21:1/5 to [email protected] on Fri Mar 25 17:37:25 2022
    In article <[email protected]>,
    Geoff Clare <[email protected]> wrote:
    Ottavio Caruso wrote:

    How can I check that a number of programs are installed _and_ point to a
    true executable rather than a shell script or similar?

    Shell scripts *are* true executables. For example:

    Indeed. It is really hard to figure out what OP's real problem is.

    It would be useful if he would give us a good example (i.e., description
    of) the problem/error case he is worried about. i.e., what is the failure?

    --
    The randomly chosen signature file that would have appeared here is more than 4 lines long. As such, it violates one or more Usenet RFCs. In order to remain in compliance with said RFCs, the actual sig can be found at the following URL:
    http://user.xmission.com/~gazelle/Sigs/Pedantic

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenny McCormack@21:1/5 to [email protected] on Fri Mar 25 18:50:20 2022
    In article <t1l2eh$kvr$[email protected]>,
    Grant Taylor <[email protected]> wrote:
    On 3/25/22 11:37 AM, Kenny McCormack wrote:
    It would be useful if he would give us a good example (i.e.,
    description of) the problem/error case he is worried about.

    +10

    Thank you.

    --
    Life's big questions are big in the sense that they are momentous. However, contrary to
    appearances, they are not big in the sense of being unanswerable. It is only that the answers
    are generally unpalatable. There is no great mystery, but there is plenty of horror.
    (https://en.wikiquote.org/wiki/David_Benatar)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Grant Taylor@21:1/5 to Kenny McCormack on Fri Mar 25 12:42:53 2022
    On 3/25/22 11:37 AM, Kenny McCormack wrote:
    It would be useful if he would give us a good example (i.e.,
    description of) the problem/error case he is worried about.

    +10



    --
    Grant. . . .
    unix || die

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ottavio Caruso@21:1/5 to Kenny McCormack on Tue Mar 29 11:38:40 2022
    On 25/03/2022 17:37, Kenny McCormack wrote:
    It would be useful if he would give us a good example (i.e., description
    of) the problem/error case he is worried about. i.e., what is the
    failure?

    See below.


    On 25/03/2022 13:40, Geoff Clare wrote:
    If you want to distinguish original shell scripts from ones a user
    has created, you could perhaps use command -p -v to do a PATH search
    of only the "system" PATH instead of the user's PATH.

    Thanks. `command -p` is exactly what I was looking for



    $ (command -v ffmpeg 2>/dev/null)&& echo success || echo failure /home/oc/opt/bin/ffmpeg
    success

    $ (command -p ffmpeg 2>/dev/null)&& echo success || echo failure
    failure


    Pedantic question: Is `command -p` implemented consistently across all
    /bin/sh clones? Can the user hack the " PATH that guarantees to find all
    the standard utilities"?

    --
    Ottavio Caruso

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Grant Taylor@21:1/5 to Ottavio Caruso on Tue Mar 29 14:50:04 2022
    On 3/29/22 4:38 AM, Ottavio Caruso wrote:
    See below.

    I don't see an answer to what the problem / error case is.

    The example is a couple of options related to ffmpeg. But nothing about
    why /home/oc/opt/bin/ffmpeg vs /usr/local/bin/ffmpeg is a problem.

    Thanks. `command -p` is exactly what I was looking for

    My read of Zsh's man page for `command -p` makes me believe that
    (symbolic) links will be followed. And I thought that you had indicated
    that you wanted to exclude (symbolic) links too.

    Pedantic question: Is `command -p` implemented consistently across all /bin/sh clones?

    I don't know.

    Can the user hack the PATH that guarantees to find all the standard utilities?

    I don't know if the /user/ can or not. I strongly suspect that an administrator can change the system / default path to be anything they want.

    Also, what is the "default path" and how does it differ from the
    (user's) "non-default path"? -- What if a system administrator puts a symbolic link in a directory that's earlier in the default path? E.g.

    PATH=/bin:/usr/bin:/usr/local/bin

    /bin/ffmpeg -> /home/oc/opt/bin/ffmpeg

    I strongly suspect that even `command -p ffmpeg` would produce unwanted results.

    If you don't like the sym-link, try a hard link on a common file system.
    Or how about a wrapper script. Or how about a compiled binary that
    shells out to /home/oc/opt/bin/ffmpeg.

    We still don't have any working understanding of what the problem /
    error case is that you are worried about.



    --
    Grant. . . .
    unix || die

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Geoff Clare@21:1/5 to Grant Taylor on Wed Mar 30 13:31:02 2022
    Grant Taylor wrote:

    On 3/29/22 4:38 AM, Ottavio Caruso wrote:

    Thanks. `command -p` is exactly what I was looking for

    My read of Zsh's man page for `command -p` makes me believe that
    (symbolic) links will be followed. And I thought that you had indicated
    that you wanted to exclude (symbolic) links too.

    I suggested command -v -p because I suspected that what Ottavio really
    wanted was to distinguish "original" (system-supplied) executables from user-supplied ones, rather than taking any notice of what type of
    executable they are. I gave an example of an original shell script (google-chrome), but the same would apply to symbolic links as well.


    Pedantic question: Is `command -p` implemented consistently across all
    /bin/sh clones?

    POSIX requires that it searches a default PATH "that is guaranteed to
    find all of the standard utilities", instead of the PATH value from
    the environment. The contents of the default PATH could be chosen by
    the shell author, or they could leave it to the C library by using
    confstr() with _CS_PATH to obtain a suitable PATH.

    Can the user hack the PATH that guarantees to find all the standard
    utilities?

    No, it's built into the shell. (The "command" utility is necessarily implemented as a shell built-in.)

    --
    Geoff Clare <[email protected]>

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