Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: bash - scope of exported functions

  1. #1
    Join Date
    Jun 2008
    Location
    South-West France
    Posts
    1,031

    Default bash - scope of exported functions

    Hello.

    In /etc/profile.local, I source 2 bash files. One for exporting common env variables, one for exporting common bash function.
    I am testing a program as super user ( declared in the wheel )
    The program must be run as root and start with
    Code:
    (( EUID != 0 )) && exec sudo -- "$0" "$@"
    Starting the program this way
    Code:
    sudo -E my_prog
    give me access to environment variables which was exported, but not to exported functions.
    Sudo seems to blocks it (As I saw by goggling) .

    So I see some solutions :
    1°) Run the program as root
    Code:
    su - root -c "my_prog"
    give me access to environment variables which was exported, and to exported functions.

    2°) Add code to source again the bash function file when program starts.
    But the code is source twice.

    3°) Source again the bash function file in my ~.profile.
    But the code is source twice

    Any help is welcome.
    Thanks for helping. JCD
    __________

    server leap 15-- ASUS g75vw KDE leap 42.3 -- ASUS g750JZ KDE leap 42.3 -- acer aspire s13 win 10 home -- HP Omen win 10 home - scan EPSON V500 - Brother HL2250DN - Samsung CLP-325W

  2. #2
    Join Date
    Jun 2008
    Location
    South-West France
    Posts
    1,031

    Default Re: bash - scope of exported functions

    Quote Originally Posted by jcdole View Post
    Hello.

    3°) Source again the bash function file in my ~.profile.
    But the code is source twice
    Does not work ?
    Thanks for helping. JCD
    __________

    server leap 15-- ASUS g75vw KDE leap 42.3 -- ASUS g750JZ KDE leap 42.3 -- acer aspire s13 win 10 home -- HP Omen win 10 home - scan EPSON V500 - Brother HL2250DN - Samsung CLP-325W

  3. #3
    Join Date
    Aug 2010
    Location
    Chicago suburbs
    Posts
    12,507
    Blog Entries
    3

    Default Re: bash - scope of exported functions

    Quote Originally Posted by jcdole View Post
    Sudo seems to blocks it (As I saw by goggling) .
    I assume that "sudo" sanitizes the environment. Otherwise there can be security risks using an untrusted environment as root.
    openSUSE Leap 15.1; KDE Plasma 5;
    testing Leap 15.2Alpha

  4. #4
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,010

    Default Re: bash - scope of exported functions

    Quote Originally Posted by nrickert View Post
    I assume that "sudo" sanitizes the environment. Otherwise there can be security risks using an untrusted environment as root.
    Like
    Code:
    su -
    It is of course a security risk to run a process as user a in the environment of user b. Specially as user a is root.

    To the OP. You at one point tell using sudo (to run processes ass owned by root) and later you give an alternative "Run the program as root" by using su -. I hope you understand that using sudo and su are just different ways of running processes as another user (often root).
    Henk van Velden

  5. #5
    Join Date
    Jun 2008
    Location
    South-West France
    Posts
    1,031

    Default Re: bash - scope of exported functions

    I'll rephrase the question :

    I have two bash files , one for exporting common env variables, one for exporting common bash function.
    I want that every logged user ( root, super user in the wheel, normal user ) has access to the exported variables and to the exported function when running their script.
    So where to put these files to achieve this goal.
    If possible without creating my own bash or my own operating system.

    Any help is welcome.
    Thanks for helping. JCD
    __________

    server leap 15-- ASUS g75vw KDE leap 42.3 -- ASUS g750JZ KDE leap 42.3 -- acer aspire s13 win 10 home -- HP Omen win 10 home - scan EPSON V500 - Brother HL2250DN - Samsung CLP-325W

  6. #6
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,010

    Default Re: bash - scope of exported functions

    What about /etc/profile.local?
    Code:
    henk@boven:/etc> head /etc/profile
    # /etc/profile for SuSE Linux
    #
    # PLEASE DO NOT CHANGE /etc/profile. There are chances that your changes
    # will be lost during system upgrades. Instead use /etc/profile.local for
    # your local settings, favourite global aliases, VISUAL and EDITOR
    # variables, etc ...
    
    henk@boven:/etc>
    Henk van Velden

  7. #7
    Join Date
    Jun 2008
    Location
    South-West France
    Posts
    1,031

    Default Re: bash - scope of exported functions

    Quote Originally Posted by hcvv View Post
    What about /etc/profile.local?
    Code:
    henk@boven:/etc> head /etc/profile
    # /etc/profile for SuSE Linux
    #
    # PLEASE DO NOT CHANGE /etc/profile. There are chances that your changes
    # will be lost during system upgrades. Instead use /etc/profile.local for
    # your local settings, favourite global aliases, VISUAL and EDITOR
    # variables, etc ...
    
    henk@boven:/etc>
    That was the start of my question

    Hello.

    In /etc/profile.local, I source 2 bash files. One for exporting common env variables, one for exporting common bash function.
    I am testing a program as super user ( declared in the wheel )
    The program must be run as root and start with
    Code:
    (( EUID != 0 )) && exec sudo -- "$0" "$@"
    Starting the program this way
    Code:
    sudo -E my_prog
    give me access to environment variables which was exported, but not to exported functions.
    Sudo seems to blocks it (As I saw by goggling) .
    Thanks for helping. JCD
    __________

    server leap 15-- ASUS g75vw KDE leap 42.3 -- ASUS g750JZ KDE leap 42.3 -- acer aspire s13 win 10 home -- HP Omen win 10 home - scan EPSON V500 - Brother HL2250DN - Samsung CLP-325W

  8. #8
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,010

    Default Re: bash - scope of exported functions

    What do you mean by:
    I am testing a program as super user ( declared in the wheel )
    What "wheel"? Where? I have the impression that you have a special environment created on your system. Which is of course your bussiness, but when you ask questions, you better explain extensive what you changed with respect to a fresh installed environment. Else you talk to deaf ears.

    And I never use sudo (I only use su -l) thus I have no comment on that. But showing something instead of only talking theoretical might help others in understanding you. You seem to think (and I refer also to another thread of you) that everybody lives in the same pupa as you and that everybody thus understands immediately all of your environment and your goals when you just tell a minimal bit of where you got stuck in your quest.
    Henk van Velden

  9. #9
    Join Date
    Jun 2008
    Location
    South-West France
    Posts
    1,031

    Default Re: bash - scope of exported functions

    >
    >What do you mean by:
    >
    >What "wheel"? Where?
    Please read :https://en.opensuse.org/SDB:Administer_with_sudo

    >I have the impression that you have a special environment created on your system.
    Very common install. Nothing more

    >And I never use sudo (I only use su -l) thus I have no comment on that.
    So if like me you don't know what sudo is for, you can't help me.

    >But showing something instead of only talking theoretical might help others in understanding you.
    All is in the post #1 : bash - scope of exported functions
    In /etc/profile.local, I source 2 bash files. One for exporting common env variables, one for exporting common bash function.
    I am testing a program as super user ( declared in the wheel )
    The program must be run as root and start with
    Code:
    (( EUID != 0 )) && exec sudo -- "$0" "$@"
    Starting the program this way
    Code:
    sudo -E my_prog
    give me access to environment variables which was exported, but not to exported functions.
    Sudo seems to blocks it (As I saw by goggling) .
    The goal : In /etc/profile.local, I source 2 bash files. One for exporting common env variables, one for exporting common bash function.

    The result : The running program cannot access exported function

    What I am doing : I am testing a program as super user ( declared in the wheel ) ......

    What could be specific : The program must be run as root and start with .........


    > Originally Posted by hcvv
    >What about /etc/profile.local?
    >Code:
    >henk@boven:/etc> head /etc/profile
    ># /etc/profile for SuSE Linux
    >#
    ># PLEASE DO NOT CHANGE /etc/profile. There are chances that your changes
    ># will be lost during system upgrades. Instead use /etc/profile.local for
    ># your local settings, favourite global aliases, VISUAL and EDITOR
    ># variables, etc ...
    >henk@boven:/etc

    In my question (see #1) I said that I have try this first.
    Thanks for helping. JCD
    __________

    server leap 15-- ASUS g75vw KDE leap 42.3 -- ASUS g750JZ KDE leap 42.3 -- acer aspire s13 win 10 home -- HP Omen win 10 home - scan EPSON V500 - Brother HL2250DN - Samsung CLP-325W

  10. #10
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,010

    Default Re: bash - scope of exported functions

    You talk a lot, but show not much.

    E.g. when you say "I source 2 bash files. One for exporting common env variables, one for exporting common bash function.", that is what you think you do. But how can we check if you did it correct there when we do not see anything?

    Showing computer facts makes your thread more trustworthy. Only telling stories makes your thread more suspicious. As another member once formulated it: We do not believe you, we believe computer facts.

    BTW, as you say that the exported process environment variables are found, but that the exported functions are not. Could it be that you missed from
    Code:
    man bash
    under INVOCATION:
    If the shell is started with the effective user (group) id not equal to the real user (group) id, and the -p option is not supplied, no startup files are read, shell functions are not inherited from the environment, the SHELLOPTS, BASHOPTS, CDPATH, and GLOBIGNORE variables, if they appear in the environment, are ignored, and the effective user id is set to the real user id. If the -p option is supplied at invocation, the startup behavior is the same, but the effective user id is not reset.
    (The bold is mine)
    Last edited by hcvv; 28-Jan-2017 at 11:34.
    Henk van Velden

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •