@@ -113,16 +113,20 @@ function insert($event_name, $data) {
113113 $ homedir = $ data ['new ' ]['dir ' ].'/home/ ' .$ data ['new ' ]['username ' ];
114114 }
115115
116+ // Create home base directory if it does not exist
116117 if (!is_dir ($ data ['new ' ]['dir ' ].'/home ' )){
117- $ app ->file ->mkdirs (escapeshellcmd ($ data ['new ' ]['dir ' ].'/home ' ), '0750 ' );
118- $ app ->system ->chown (escapeshellcmd ($ data ['new ' ]['dir ' ].'/home ' ),escapeshellcmd ($ data ['new ' ]['puser ' ]));
119- $ app ->system ->chgrp (escapeshellcmd ($ data ['new ' ]['dir ' ].'/home ' ),escapeshellcmd ($ data ['new ' ]['pgroup ' ]));
118+ $ app ->file ->mkdirs (escapeshellcmd ($ data ['new ' ]['dir ' ].'/home ' ), '0755 ' );
120119 }
121120
121+ // Change ownership of home base dir to root user
122+ $ app ->system ->chown (escapeshellcmd ($ data ['new ' ]['dir ' ].'/home ' ),'root ' );
123+ $ app ->system ->chgrp (escapeshellcmd ($ data ['new ' ]['dir ' ].'/home ' ),'root ' );
124+ $ app ->system ->chmod (escapeshellcmd ($ data ['new ' ]['dir ' ].'/home ' ),0755 );
125+
122126 if (!is_dir ($ homedir )){
123127 $ app ->file ->mkdirs (escapeshellcmd ($ homedir ), '0750 ' );
124- $ app ->system ->chown (escapeshellcmd ($ homedir ),escapeshellcmd ($ data ['new ' ]['puser ' ]));
125- $ app ->system ->chgrp (escapeshellcmd ($ homedir ),escapeshellcmd ($ data ['new ' ]['pgroup ' ]));
128+ $ app ->system ->chown (escapeshellcmd ($ homedir ),escapeshellcmd ($ data ['new ' ]['puser ' ]), false );
129+ $ app ->system ->chgrp (escapeshellcmd ($ homedir ),escapeshellcmd ($ data ['new ' ]['pgroup ' ]), false );
126130 }
127131 $ command = 'useradd ' ;
128132 $ command .= ' -d ' .escapeshellcmd ($ homedir );
@@ -137,8 +141,8 @@ function insert($event_name, $data) {
137141 $ app ->log ("Executed command: " .$ command , LOGLEVEL_DEBUG );
138142 $ app ->log ("Added shelluser: " .$ data ['new ' ]['username ' ], LOGLEVEL_DEBUG );
139143
140- $ app ->system ->chown (escapeshellcmd ($ data ['new ' ]['dir ' ]),escapeshellcmd ($ data ['new ' ]['username ' ]));
141- $ app ->system ->chgrp (escapeshellcmd ($ data ['new ' ]['dir ' ]),escapeshellcmd ($ data ['new ' ]['pgroup ' ]));
144+ $ app ->system ->chown (escapeshellcmd ($ data ['new ' ]['dir ' ]),escapeshellcmd ($ data ['new ' ]['username ' ]), false );
145+ $ app ->system ->chgrp (escapeshellcmd ($ data ['new ' ]['dir ' ]),escapeshellcmd ($ data ['new ' ]['pgroup ' ]), false );
142146
143147
144148 // call the ssh-rsa update function
@@ -149,7 +153,7 @@ function insert($event_name, $data) {
149153
150154 //* Create .bash_history file
151155 $ app ->system ->touch (escapeshellcmd ($ homedir ).'/.bash_history ' );
152- $ app ->system ->chmod (escapeshellcmd ($ homedir ).'/.bash_history ' , 0755 );
156+ $ app ->system ->chmod (escapeshellcmd ($ homedir ).'/.bash_history ' , 0750 );
153157 $ app ->system ->chown (escapeshellcmd ($ homedir ).'/.bash_history ' , $ data ['new ' ]['username ' ]);
154158 $ app ->system ->chgrp (escapeshellcmd ($ homedir ).'/.bash_history ' , $ data ['new ' ]['pgroup ' ]);
155159
@@ -249,17 +253,17 @@ function update($event_name, $data) {
249253 $ app ->system ->chown (escapeshellcmd ($ data ['new ' ]['dir ' ].'/home ' ),escapeshellcmd ($ data ['new ' ]['puser ' ]));
250254 $ app ->system ->chgrp (escapeshellcmd ($ data ['new ' ]['dir ' ].'/home ' ),escapeshellcmd ($ data ['new ' ]['pgroup ' ]));
251255 }
252- $ app ->file ->mkdirs (escapeshellcmd ($ homedir ), '0750 ' );
253- $ app ->system ->chown (escapeshellcmd ($ homedir ),escapeshellcmd ( $ data [ ' new ' ][ ' puser ' ]) );
254- $ app ->system ->chgrp (escapeshellcmd ($ homedir ),escapeshellcmd ( $ data [ ' new ' ][ ' pgroup ' ]) );
256+ $ app ->file ->mkdirs (escapeshellcmd ($ homedir ), '0755 ' );
257+ $ app ->system ->chown (escapeshellcmd ($ homedir ),' root ' );
258+ $ app ->system ->chgrp (escapeshellcmd ($ homedir ),' root ' );
255259 $ app ->system ->web_folder_protection ($ web ['document_root ' ], true );
256260 } else {
257261 if (!is_dir ($ homedir )){
258262 $ app ->system ->web_folder_protection ($ web ['document_root ' ], false );
259263 if (!is_dir ($ data ['new ' ]['dir ' ].'/home ' )){
260- $ app ->file ->mkdirs (escapeshellcmd ($ data ['new ' ]['dir ' ].'/home ' ), '0750 ' );
261- $ app ->system ->chown (escapeshellcmd ($ data ['new ' ]['dir ' ].'/home ' ),escapeshellcmd ( $ data [ ' new ' ][ ' puser ' ]) );
262- $ app ->system ->chgrp (escapeshellcmd ($ data ['new ' ]['dir ' ].'/home ' ),escapeshellcmd ( $ data [ ' new ' ][ ' pgroup ' ]) );
264+ $ app ->file ->mkdirs (escapeshellcmd ($ data ['new ' ]['dir ' ].'/home ' ), '0755 ' );
265+ $ app ->system ->chown (escapeshellcmd ($ data ['new ' ]['dir ' ].'/home ' ),' root ' );
266+ $ app ->system ->chgrp (escapeshellcmd ($ data ['new ' ]['dir ' ].'/home ' ),' root ' );
263267 }
264268 $ app ->file ->mkdirs (escapeshellcmd ($ homedir ), '0750 ' );
265269 $ app ->system ->chown (escapeshellcmd ($ homedir ),escapeshellcmd ($ data ['new ' ]['puser ' ]));
@@ -279,7 +283,7 @@ function update($event_name, $data) {
279283 //* Create .bash_history file
280284 if (!is_file ($ data ['new ' ]['dir ' ]).'/.bash_history ' ) {
281285 $ app ->system ->touch (escapeshellcmd ($ homedir ).'/.bash_history ' );
282- $ app ->system ->chmod (escapeshellcmd ($ homedir ).'/.bash_history ' , 0755 );
286+ $ app ->system ->chmod (escapeshellcmd ($ homedir ).'/.bash_history ' , 0750 );
283287 $ app ->system ->chown (escapeshellcmd ($ homedir ).'/.bash_history ' , escapeshellcmd ($ data ['new ' ]['username ' ]));
284288 $ app ->system ->chgrp (escapeshellcmd ($ homedir ).'/.bash_history ' , escapeshellcmd ($ data ['new ' ]['pgroup ' ]));
285289 }
0 commit comments