The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Run command post account create

Discussion in 'cPanel Developers' started by JamieD, Oct 2, 2013.

  1. JamieD

    JamieD Well-Known Member

    Joined:
    Sep 3, 2003
    Messages:
    58
    Likes Received:
    0
    Trophy Points:
    6
    Hi,

    I want to run a command after an account is created, the command must be run as the newly created user. I also need to chown and chmod a particular file as root. Would the best way to do this be to use a hook event or would another way be better?

    Thanks
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    648
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
  3. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    I'd recommend using the Standardized Hooks system instead of /scripts/postwwwacct. There can only be one /scripts/postwwwacct script so you can run into trouble if any third-party add-ons are coded to use it as well. With Standardized hooks, you don't have any chance that your hook will be overwritten. Also, since you want to perform one action as the user and one as root, Standardized Hooks will allow you to have 2 different hooks in place, running as each uid. If you need those actions to be performed in sequence, you may need to built a timer into the root hook to wait for the first action.

    WHM Functions | Standardized Hooks (post
     
  4. JamieD

    JamieD Well-Known Member

    Joined:
    Sep 3, 2003
    Messages:
    58
    Likes Received:
    0
    Trophy Points:
    6
    Thanks for the info Dave, very useful. I take it then there is no order to the Standardized Hooks system, or is it that the scripts are run in parallel?

    The first command generates a file in the users home so I can set the other script to wait for the file to exist before running it's operations.

    The Whostmgr::Accounts::Create (post) hook documentation shows it runs as root, is there a way to get the script to run as the user or would this be the job of the script to do this?

    Thanks
     
  5. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    The hooks are entered in a specific order in /var/cpanel/hooks.yaml so I'd imagine that they are just loaded up into an array and executed in that order but I'd do some testing as if they are loaded into a hash, they may not have a constant order of execution.

    Yea, you'll have to use setuid() or your preferred method of changing to the uid that you need. I'm not aware of anything built-in to de-escalate, only the other way around.
     
Loading...

Share This Page