diff options
author | Vladislav Vaintroub <wlad@montyprogram.com> | 2012-04-17 01:03:10 +0200 |
---|---|---|
committer | Vladislav Vaintroub <wlad@montyprogram.com> | 2012-04-17 01:03:10 +0200 |
commit | e13e93cb0b4ba2f0edf74fa7ed4d602bd5731ed1 (patch) | |
tree | 83dc68eb343ef6fe0ecacef9fc5488058df76bca | |
parent | 296167d6d222a84ef5c019f7572378075b0d7c7c (diff) | |
parent | 2004bd1736d0a984c12b1d56156f5552816c80f4 (diff) | |
download | mariadb-git-e13e93cb0b4ba2f0edf74fa7ed4d602bd5731ed1.tar.gz |
merge
-rw-r--r-- | sql/mysql_install_db.cc | 18 | ||||
-rw-r--r-- | sql/sql_select.cc | 1 | ||||
-rw-r--r-- | win/packaging/ca/CustomAction.cpp | 87 | ||||
-rw-r--r-- | win/packaging/extra.wxs.in | 5 |
4 files changed, 102 insertions, 9 deletions
diff --git a/sql/mysql_install_db.cc b/sql/mysql_install_db.cc index 086dc292dec..364dca9120a 100644 --- a/sql/mysql_install_db.cc +++ b/sql/mysql_install_db.cc @@ -316,9 +316,9 @@ static int create_myini() static const char update_root_passwd_part1[]= - "UPDATE mysql.user SET Password = PASSWORD('"; + "UPDATE mysql.user SET Password = PASSWORD("; static const char update_root_passwd_part2[]= - "') where User='root';\n"; + ") where User='root';\n"; static const char remove_default_user_cmd[]= "DELETE FROM mysql.user where User='';\n"; static const char allow_remote_root_access_cmd[]= @@ -589,11 +589,19 @@ static int create_db_instance() } /* Change root password if requested. */ - if (opt_password) + if (opt_password && opt_password[0]) { - verbose("Changing root password",remove_default_user_cmd); + verbose("Setting root password",remove_default_user_cmd); fputs(update_root_passwd_part1, in); - fputs(opt_password, in); + + /* Use hex encoding for password, to avoid escaping problems.*/ + fputc('0', in); + fputc('x', in); + for(int i= 0; opt_password[i]; i++) + { + fprintf(in,"%02x",opt_password[i]); + } + fputs(update_root_passwd_part2, in); fflush(in); } diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 338b0475626..8f8ecd1725d 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -15422,7 +15422,6 @@ free_tmp_table(THD *thd, TABLE *entry) else entry->file->ha_delete_table(entry->s->table_name.str); delete entry->file; - entry->file= 0; } /* free blobs */ diff --git a/win/packaging/ca/CustomAction.cpp b/win/packaging/ca/CustomAction.cpp index ed26dd45a94..50b39adc0b1 100644 --- a/win/packaging/ca/CustomAction.cpp +++ b/win/packaging/ca/CustomAction.cpp @@ -73,6 +73,82 @@ LExit: return WcaFinalize(er); } +/* + Escape command line parameter fpr pass to CreateProcess(). + + We assume out has enough space to include encoded string + 2*wcslen(in) is enough. + + It is assumed that called will add double quotation marks before and after + the string. +*/ +static void EscapeCommandLine(const wchar_t *in, wchar_t *out, size_t buflen) +{ + const wchar_t special_chars[]=L" \t\n\v\""; + bool needs_escaping= false; + size_t pos; + + for(int i=0; i< sizeof(special_chars) -1; i++) + { + if (wcschr(in, special_chars[i])) + { + needs_escaping = true; + break; + } + } + + if(!needs_escaping) + { + wcscpy_s(out, buflen, in); + return; + } + + pos= 0; + for(int i = 0 ; ; i++)
+ {
+ size_t n_backslashes = 0;
+ wchar_t c;
+ while (in[i] == L'\\')
+ {
+ i++;
+ n_backslashes++;
+ }
+
+ c= in[i];
+ if (c == 0)
+ {
+ /*
+ Escape all backslashes, but let the terminating double quotation mark
+ that caller adds be interpreted as a metacharacter.
+ */
+ for(size_t j= 0; j < 2*n_backslashes;j++)
+ {
+ out[pos++]=L'\\';
+ }
+ break;
+ }
+ else if (c == L'"')
+ {
+ /*
+ Escape all backslashes and the following double quotation mark.
+ */
+ for(size_t j= 0; j < 2*n_backslashes + 1; j++)
+ {
+ out[pos++]=L'\\';
+ }
+ out[pos++]= L'"';
+ }
+ else
+ {
+ /* Backslashes aren't special here. */
+ for (size_t j=0; j < n_backslashes; j++)
+ out[pos++] = L'\\';
+
+ out[pos++]= c;
+ }
+ } + out[pos++]= 0; +} /* Check for if directory is empty during install, sets "<PROPERTY>_NOT_EMPTY" otherise @@ -462,6 +538,8 @@ unsigned long long GetMaxBufferSize(unsigned long long totalPhys) return totalPhys; #endif } + + /* Checks SERVICENAME, PORT and BUFFERSIZE parameters */ @@ -470,6 +548,8 @@ extern "C" UINT __stdcall CheckDatabaseProperties (MSIHANDLE hInstall) wchar_t ServiceName[MAX_PATH]={0}; wchar_t SkipNetworking[MAX_PATH]={0}; wchar_t QuickConfig[MAX_PATH]={0}; + wchar_t Password[MAX_PATH]={0}; + wchar_t EscapedPassword[2*MAX_PATH+2]; wchar_t Port[6]; wchar_t BufferPoolSize[16]; DWORD PortLen=6; @@ -512,8 +592,13 @@ extern "C" UINT __stdcall CheckDatabaseProperties (MSIHANDLE hInstall) } } - DWORD SkipNetworkingLen= MAX_PATH; + DWORD PasswordLen= MAX_PATH; + MsiGetPropertyW (hInstall, L"PASSWORD", Password, &PasswordLen); + EscapeCommandLine(Password, EscapedPassword, + sizeof(EscapedPassword)/sizeof(EscapedPassword[0])); + MsiSetPropertyW(hInstall,L"ESCAPEDPASSWORD",EscapedPassword); + DWORD SkipNetworkingLen= MAX_PATH; MsiGetPropertyW(hInstall, L"SKIPNETWORKING", SkipNetworking, &SkipNetworkingLen); MsiGetPropertyW(hInstall, L"PORT", Port, &PortLen); diff --git a/win/packaging/extra.wxs.in b/win/packaging/extra.wxs.in index e4f459d3dfe..d4adc959333 100644 --- a/win/packaging/extra.wxs.in +++ b/win/packaging/extra.wxs.in @@ -34,6 +34,7 @@ <!-- Root password -->
<Property Id="PASSWORD" Hidden="yes" Secure="yes" />
+ <Property Id="ESCAPEDPASSWORD" Hidden="yes" Secure="yes" />
<!-- Database port -->
<Property Id="PORT" Value="3306" Secure="yes"/>
<!-- Whether to allow remote access for root user -->
@@ -668,7 +669,7 @@ <CustomAction Id='PresetDatabaseProperties' BinaryKey='wixca.dll' DllEntry='PresetDatabaseProperties' />
<CustomAction Id="CreateDatabaseCommand" Property="CreateDatabase"
Value=
- ""[#F.bin.mysql_install_db.exe]" "--service=[SERVICENAME]" --port=[PORT] "--password=[PASSWORD]" "--datadir=[DATADIR]\" [SKIPNETWORKING] [ALLOWREMOTEROOTACCESS] [DEFAULTUSER]"
+ ""[#F.bin.mysql_install_db.exe]" "--service=[SERVICENAME]" --port=[PORT] "--password=[ESCAPEDPASSWORD]" "--datadir=[DATADIR]\" [SKIPNETWORKING] [ALLOWREMOTEROOTACCESS] [DEFAULTUSER]"
Execute="immediate"
HideTarget="yes"
/>
@@ -703,7 +704,7 @@ <![CDATA[&DBInstance=3 AND NOT !DBInstance=3 AND OLDERVERSIONBEINGUPGRADED=""]]>
</Custom>
<Custom Action="ErrorDataDirNotEmpty" After="CheckDataDirectoryEmpty" >DATADIRNOTEMPTY</Custom>
-
+ <Custom Action="CheckDatabaseProperties" Before="CreateDatabaseCommand">SERVICENAME</Custom>
<Custom Action="CreateDatabaseCommand" After="CostFinalize" >
<![CDATA[&DBInstance=3 AND NOT !DBInstance=3 AND OLDERVERSIONBEINGUPGRADED=""]]>
</Custom>
|