Changeset 1037


Ignore:
Timestamp:
Mar 31, 2009, 5:31:30 AM (15 years ago)
Author:
mitchb
Message:
Make get-password more accomodating in my.cnf formats it understands.
Allow the login info to appear in either the [mysql] or [client]
section, and allow spaces around the equal signs.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • locker/sql/bin/get-password

    r382 r1037  
    1212        global $env_user;
    1313        $cnfFile = file_get_contents($path);
    14         preg_match('/\[mysql\][^\[]*host=([^\n]*)/',$cnfFile,$match);
    15         $host = $match[1];
    16         preg_match('/\[mysql\][^\[]*user=([^\n]*)/',$cnfFile,$match);
    17         $user = $match[1];
    18         preg_match('/\[mysql\][^\[]*password=([^\n]*)/',$cnfFile,$match);
    19         $password = $match[1];
    20         if (empty($host)) $host = 'sql.mit.edu';
    21         if (empty($user)) $user = $env_user;
    22         if (empty($password)) $password = 'password';
     14        if (preg_match('/\[mysql\][^\[]*host *= *([^\n]*)/',$cnfFile,$match)) {
     15                $host = $match[1];
     16        } elseif (preg_match('/\[client\][^\[]*host *= *([^\n]*)/',$cnfFile,$match)) {
     17                $host = $match[1];
     18        } else {
     19                $host = 'sql.mit.edu';
     20        }
     21        if (preg_match('/\[mysql\][^\[]*user *= *([^\n]*)/',$cnfFile,$match)) {
     22                $user = $match[1];
     23        } elseif (preg_match('/\[client\][^\[]*user *= *([^\n]*)/',$cnfFile,$match)) {
     24                $user = $match[1];
     25        } else {
     26                $user = $env_user;
     27        }
     28        if (preg_match('/\[mysql\][^\[]*password *= *([^\n]*)/',$cnfFile,$match)) {
     29                $password = $match[1];
     30        } elseif (preg_match('/\[client\][^\[]*password *= *([^\n]*)/',$cnfFile,$match)) {
     31                $password = $match[1];
     32        } else {
     33                $password = 'password';
     34        }
    2335        return array($host,$user,$password);
    2436}
Note: See TracChangeset for help on using the changeset viewer.