File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -42,7 +42,8 @@ function read_password($prompt = "Enter password: ")
4242 echo $ prompt ;
4343
4444 // Check if we're on Windows or Unix
45- if (strtoupper (substr (PHP_OS , 0 , 3 )) === 'WIN ' ) {
45+ if (strtoupper (substr (PHP_OS , 0 , 3 )) === 'WIN ' )
46+ {
4647 // Windows approach using COM object if available
4748 if (class_exists ('COM ' ))
4849 {
@@ -111,14 +112,25 @@ function print_help()
111112 "\n" );
112113}
113114
114- function get_passwd ()
115+ function get_passwd ($ create = false )
115116{
116117 global $ g_auth_file_db ;
117118
118119 if (!file_exists ($ g_auth_file_db ))
119120 {
120- fatal_log ("User database file does not exist: " . $ g_auth_file_db );
121- exit (1 );
121+ if ($ create )
122+ {
123+ // Attempt to create an empty file
124+ if (false === @touch ($ g_auth_file_db ))
125+ {
126+ fatal_log ("Failed to create user database file: " . $ g_auth_file_db );
127+ exit (1 );
128+ }
129+ } else
130+ {
131+ fatal_log ("User database file does not exist: " . $ g_auth_file_db );
132+ exit (1 );
133+ }
122134 }
123135
124136 $ passwd_file = new PasswdFile ($ g_auth_file_db );
@@ -185,7 +197,7 @@ function get_passwd()
185197 exit (1 );
186198 }
187199
188- $ passwd_file = get_passwd ();
200+ $ passwd_file = get_passwd (true );
189201
190202 if ($ passwd_file ->UserExists ($ username ))
191203 {
You can’t perform that action at this time.
0 commit comments