Run command post account create

JamieD

Well-Known Member
Sep 3, 2003
58
0
156
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
 

KostonConsulting

Well-Known Member
Verifed Vendor
Jun 17, 2010
255
1
68
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
 

JamieD

Well-Known Member
Sep 3, 2003
58
0
156
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
 

KostonConsulting

Well-Known Member
Verifed Vendor
Jun 17, 2010
255
1
68
San Francisco, CA
cPanel Access Level
Root Administrator
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 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.

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
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.