@@ -74,6 +74,29 @@ class APIUserCreate extends APIModel {
7474 }
7575 }
7676
77+ private function __validate_priv () {
78+ global $ priv_list ;
79+ $ this ->validated_data ["priv " ] = [];
80+
81+ # Check for our optional `priv` payload value
82+ if ($ this ->initial_data ["priv " ]) {
83+ # Ensure value is an array
84+ if (!is_array ($ this ->initial_data ["priv " ])) {
85+ $ this ->initial_data ["priv " ] = array ($ this ->initial_data ["priv " ]);
86+ }
87+
88+ # Loop through each requested privilege and ensure it exists
89+ foreach ($ this ->initial_data ["priv " ] as $ priv ) {
90+ if (array_key_exists ($ priv , $ priv_list )) {
91+ $ this ->validated_data ["priv " ][] = $ priv ;
92+ } else {
93+ $ this ->errors [] = APIResponse \get (5006 );
94+ break ;
95+ }
96+ }
97+ }
98+ }
99+
77100 private function __validate_disabled () {
78101 # Check for our optional `disabled` payload value
79102 if ($ this ->initial_data ["disabled " ] === true ) {
@@ -123,11 +146,11 @@ class APIUserCreate extends APIModel {
123146 # Set static object values
124147 $ this ->validated_data ["uid " ] = $ this ->config ["system " ]["nextuid " ];
125148 $ this ->validated_data ["scope " ] = "user " ;
126- $ this ->validated_data ["priv " ] = [];
127149
128150 # Run each validation method
129151 $ this ->__validate_username ();
130152 $ this ->__validate_password ();
153+ $ this ->__validate_priv ();
131154 $ this ->__validate_descr ();
132155 $ this ->__validate_disabled ();
133156 $ this ->__validate_expires ();
@@ -137,16 +160,15 @@ class APIUserCreate extends APIModel {
137160
138161 public function is_username_reserved ($ user ) {
139162 # Open the /etc/passwd file to read all system users
140- $ etc_passwd = explode (PHP_EOL , file_get_contents ("/etc/passwd " ));
163+ $ sys_users = explode (PHP_EOL , file_get_contents ("/etc/passwd " ));
141164
142165 # Loop through each system user and check if the username is reserved
143- foreach ($ etc_passwd as $ sys_user_ent ) {
166+ foreach ($ sys_users as $ sys_user_ent ) {
144167 $ sys_username = explode (": " , $ sys_user_ent )[0 ];
145168 if ($ sys_username == $ user ) {
146169 return true ;
147170 }
148171 }
149172 return false ;
150173 }
151-
152174}
0 commit comments