diff options
Diffstat (limited to 'extra')
26 files changed, 480 insertions, 312 deletions
diff --git a/extra/CMakeLists.txt b/extra/CMakeLists.txt index c1477e41a81..cec0db6a4ae 100755 --- a/extra/CMakeLists.txt +++ b/extra/CMakeLists.txt @@ -51,7 +51,5 @@ ADD_EXECUTABLE(replace replace.c) TARGET_LINK_LIBRARIES(replace strings mysys debug dbug wsock32) IF(EMBED_MANIFESTS) - MYSQL_EMBED_MANIFEST("my_print_defaults" "asInvoker") - MYSQL_EMBED_MANIFEST("perror" "asInvoker") - MYSQL_EMBED_MANIFEST("replace" "asInvoker") + MYSQL_EMBED_MANIFEST("myTest" "asInvoker") ENDIF(EMBED_MANIFESTS) diff --git a/extra/Makefile.am b/extra/Makefile.am index 16567f8d613..75422c4ee11 100644 --- a/extra/Makefile.am +++ b/extra/Makefile.am @@ -14,7 +14,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include \ - @ndbcluster_includes@ -I$(top_srcdir)/sql + -I$(top_srcdir)/sql LDADD = @CLIENT_EXTRA_LDFLAGS@ ../mysys/libmysys.a \ ../dbug/libdbug.a ../strings/libmystrings.a \ $(ZLIB_LIBS) @@ -23,10 +23,8 @@ BUILT_SOURCES= $(top_builddir)/include/mysqld_error.h \ $(top_builddir)/include/mysqld_ername.h pkginclude_HEADERS= $(BUILT_SOURCES) DISTCLEANFILES = $(BUILT_SOURCES) -# We never use SUBDIRS here, but needed for automake 1.6.3 -# to generate code to handle DIST_SUBDIRS -SUBDIRS= -DIST_SUBDIRS= yassl +SUBDIRS = @yassl_dir@ +DIST_SUBDIRS = yassl # This will build mysqld_error.h, mysqld_ername.h and sql_state.h # NOTE Built files should depend on their sources to avoid @@ -44,7 +42,7 @@ $(top_builddir)/include/mysqld_error.h: comp_err.c \ $(top_builddir)/include/mysqld_ername.h: $(top_builddir)/include/mysqld_error.h $(top_builddir)/include/sql_state.h: $(top_builddir)/include/mysqld_error.h -bin_PROGRAMS = replace comp_err perror resolveip my_print_defaults \ +bin_PROGRAMS = replace perror resolveip my_print_defaults \ resolve_stack_dump mysql_waitpid # "innochecksum" should be switched if BUILD_INNODB_TOOLS @@ -52,7 +50,11 @@ bin_PROGRAMS += innochecksum endif noinst_PROGRAMS = charset2html -EXTRA_DIST = CMakeLists.txt +EXTRA_PROGRAMS = comp_err +EXTRA_DIST = CMakeLists.txt + +perror.o: perror.c + $(COMPILE) @ndbcluster_includes@ $(LM_CFLAGS) -c $< # Don't update the files from bitkeeper %::SCCS/s.% diff --git a/extra/comp_err.c b/extra/comp_err.c index 342085b64d6..9326444ade9 100644 --- a/extra/comp_err.c +++ b/extra/comp_err.c @@ -99,31 +99,31 @@ static struct my_option my_long_options[]= {"debug", '#', "This is a non-debug version. Catch this and exit", 0, 0, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0}, #else - {"debug", '#', "Output debug log", (gptr *) & default_dbug_option, - (gptr *) & default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, + {"debug", '#', "Output debug log", (uchar**) & default_dbug_option, + (uchar**) & default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, #endif - {"debug-info", 'T', "Print some debug info at exit.", (gptr *) & info_flag, - (gptr *) & info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"debug-info", 'T', "Print some debug info at exit.", (uchar**) & info_flag, + (uchar**) & info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"help", '?', "Displays this help and exits.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, {"version", 'V', "Prints version", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"charset", 'C', "Charset dir", (gptr *) & charsets_dir, - (gptr *) & charsets_dir, + {"charset", 'C', "Charset dir", (uchar**) & charsets_dir, + (uchar**) & charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"in_file", 'F', "Input file", (gptr *) & TXTFILE, (gptr *) & TXTFILE, + {"in_file", 'F', "Input file", (uchar**) & TXTFILE, (uchar**) & TXTFILE, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"out_dir", 'D', "Output base directory", (gptr *) & DATADIRECTORY, - (gptr *) & DATADIRECTORY, + {"out_dir", 'D', "Output base directory", (uchar**) & DATADIRECTORY, + (uchar**) & DATADIRECTORY, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"out_file", 'O', "Output filename (errmsg.sys)", (gptr *) & OUTFILE, - (gptr *) & OUTFILE, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"header_file", 'H', "mysqld_error.h file ", (gptr *) & HEADERFILE, - (gptr *) & HEADERFILE, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"name_file", 'N', "mysqld_ername.h file ", (gptr *) & NAMEFILE, - (gptr *) & NAMEFILE, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"state_file", 'S', "sql_state.h file", (gptr *) & STATEFILE, - (gptr *) & STATEFILE, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"out_file", 'O', "Output filename (errmsg.sys)", (uchar**) & OUTFILE, + (uchar**) & OUTFILE, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"header_file", 'H', "mysqld_error.h file ", (uchar**) & HEADERFILE, + (uchar**) & HEADERFILE, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"name_file", 'N', "mysqld_ername.h file ", (uchar**) & NAMEFILE, + (uchar**) & NAMEFILE, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"state_file", 'S', "sql_state.h file", (uchar**) & STATEFILE, + (uchar**) & STATEFILE, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; @@ -192,9 +192,9 @@ int main(int argc, char *argv[]) DBUG_RETURN(1); } clean_up(lang_head, error_head); - DBUG_LEAVE; /* we can't call my_end after DBUG_RETURN */ + DBUG_LEAVE; /* Can't use dbug after my_end() */ my_end(info_flag ? MY_CHECK_ERROR | MY_GIVE_INFO : 0); - return(0); + return 0; } } @@ -242,7 +242,7 @@ static int create_header_files(struct errors *error_head) /* generating sql_state.h file */ if (tmp_error->sql_code1[0] || tmp_error->sql_code2[0]) fprintf(sql_statef, - "%-40s,\"%s\", \"%s\",\n", tmp_error->er_name, + "{ %-40s,\"%s\", \"%s\" },\n", tmp_error->er_name, tmp_error->sql_code1, tmp_error->sql_code2); /*generating er_name file */ fprintf(er_namef, "{ \"%s\", %d },\n", tmp_error->er_name, @@ -330,21 +330,21 @@ static int create_sys_files(struct languages *lang_head, /* continue with header of the errmsg.sys file */ length= ftell(to) - HEADER_LENGTH - row_count * 2; - bzero((gptr) head, HEADER_LENGTH); - bmove((byte *) head, (byte *) file_head, 4); + bzero((uchar*) head, HEADER_LENGTH); + bmove((uchar *) head, (uchar *) file_head, 4); head[4]= 1; int2store(head + 6, length); int2store(head + 8, row_count); head[30]= csnum; my_fseek(to, 0l, MY_SEEK_SET, MYF(0)); - if (my_fwrite(to, (byte*) head, HEADER_LENGTH, MYF(MY_WME | MY_FNABP))) + if (my_fwrite(to, (uchar*) head, HEADER_LENGTH, MYF(MY_WME | MY_FNABP))) goto err; for (i= 0; i < row_count; i++) { int2store(head, file_pos[i]); - if (my_fwrite(to, (byte*) head, 2, MYF(MY_WME | MY_FNABP))) + if (my_fwrite(to, (uchar*) head, 2, MYF(MY_WME | MY_FNABP))) goto err; } my_fclose(to, MYF(0)); @@ -363,7 +363,7 @@ static void clean_up(struct languages *lang_head, struct errors *error_head) struct errors *tmp_error, *next_error; uint count, i; - my_free((gptr) default_language, MYF(0)); + my_free((uchar*) default_language, MYF(0)); for (tmp_lang= lang_head; tmp_lang; tmp_lang= next_language) { @@ -371,7 +371,7 @@ static void clean_up(struct languages *lang_head, struct errors *error_head) my_free(tmp_lang->lang_short_name, MYF(0)); my_free(tmp_lang->lang_long_name, MYF(0)); my_free(tmp_lang->charset, MYF(0)); - my_free((gptr) tmp_lang, MYF(0)); + my_free((uchar*) tmp_lang, MYF(0)); } for (tmp_error= error_head; tmp_error; tmp_error= next_error) @@ -382,17 +382,17 @@ static void clean_up(struct languages *lang_head, struct errors *error_head) { struct message *tmp; tmp= dynamic_element(&tmp_error->msg, i, struct message*); - my_free((gptr) tmp->lang_short_name, MYF(0)); - my_free((gptr) tmp->text, MYF(0)); + my_free((uchar*) tmp->lang_short_name, MYF(0)); + my_free((uchar*) tmp->text, MYF(0)); } delete_dynamic(&tmp_error->msg); if (tmp_error->sql_code1[0]) - my_free((gptr) tmp_error->sql_code1, MYF(0)); + my_free((uchar*) tmp_error->sql_code1, MYF(0)); if (tmp_error->sql_code2[0]) - my_free((gptr) tmp_error->sql_code2, MYF(0)); - my_free((gptr) tmp_error->er_name, MYF(0)); - my_free((gptr) tmp_error, MYF(0)); + my_free((uchar*) tmp_error->sql_code2, MYF(0)); + my_free((uchar*) tmp_error->er_name, MYF(0)); + my_free((uchar*) tmp_error, MYF(0)); } } @@ -472,7 +472,7 @@ static int parse_input_file(const char *file_name, struct errors **top_error, current_error->er_name, current_message.lang_short_name); DBUG_RETURN(0); } - if (insert_dynamic(¤t_error->msg, (byte *) & current_message)) + if (insert_dynamic(¤t_error->msg, (uchar *) & current_message)) DBUG_RETURN(0); continue; } @@ -535,7 +535,7 @@ static uint parse_error_offset(char *str) end= 0; ioffset= (uint) my_strtoll10(soffset, &end, &error); - my_free((gptr) soffset, MYF(0)); + my_free((uchar*) soffset, MYF(0)); DBUG_RETURN(ioffset); } @@ -762,7 +762,7 @@ static char *get_word(char **str) DBUG_ENTER("get_word"); *str= find_end_of_word(start); - DBUG_RETURN(my_strdup_with_length(start, (uint) (*str - start), + DBUG_RETURN(my_strndup(start, (uint) (*str - start), MYF(MY_WME | MY_FAE))); } @@ -796,7 +796,7 @@ static struct message *parse_message_string(struct message *new_message, while (*str != ' ' && *str != '\t' && *str) str++; if (!(new_message->lang_short_name= - my_strdup_with_length(start, (uint) (str - start), + my_strndup(start, (uint) (str - start), MYF(MY_WME | MY_FAE)))) DBUG_RETURN(0); /* Fatal error */ DBUG_PRINT("info", ("msg_slang: %s", new_message->lang_short_name)); @@ -816,7 +816,7 @@ static struct message *parse_message_string(struct message *new_message, start= str + 1; str= parse_text_line(start); - if (!(new_message->text= my_strdup_with_length(start, (uint) (str - start), + if (!(new_message->text= my_strndup(start, (uint) (str - start), MYF(MY_WME | MY_FAE)))) DBUG_RETURN(0); /* Fatal error */ DBUG_PRINT("info", ("msg_text: %s", new_message->text)); diff --git a/extra/innochecksum.c b/extra/innochecksum.c index 33f925a4cad..9bd4bfcc0cd 100644 --- a/extra/innochecksum.c +++ b/extra/innochecksum.c @@ -51,10 +51,10 @@ /* another argument to specify page ranges... seek to right spot and go from there */ typedef unsigned long int ulint; -typedef unsigned char byte; +typedef unsigned char uchar; /* innodb function in name; modified slightly to not have the ASM version (lots of #ifs that didn't apply) */ -ulint mach_read_from_4(byte *b) +ulint mach_read_from_4(uchar *b) { return( ((ulint)(b[0]) << 24) + ((ulint)(b[1]) << 16) @@ -78,7 +78,7 @@ ulint ut_fold_binary( /*===========*/ /* out: folded value */ - byte* str, /* in: string of bytes */ + uchar* str, /* in: string of bytes */ ulint len) /* in: length */ { ulint i; @@ -98,7 +98,7 @@ ulint buf_calc_page_new_checksum( /*=======================*/ /* out: checksum */ - byte* page) /* in: buffer page */ + uchar* page) /* in: buffer page */ { ulint checksum; @@ -123,7 +123,7 @@ ulint buf_calc_page_old_checksum( /*=======================*/ /* out: checksum */ - byte* page) /* in: buffer page */ + uchar* page) /* in: buffer page */ { ulint checksum; @@ -138,7 +138,7 @@ buf_calc_page_old_checksum( int main(int argc, char **argv) { FILE *f; /* our input file */ - byte *p; /* storage of pages read */ + uchar *p; /* storage of pages read */ int bytes; /* bytes read count */ ulint ct; /* current page number (0 based) */ int now; /* current time */ @@ -224,7 +224,7 @@ int main(int argc, char **argv) } else if (verbose) { - printf("file %s= %llu bytes (%lu pages)...\n", argv[1], size, pages); + printf("file %s = %llu bytes (%lu pages)...\n", argv[optind], size, pages); printf("checking pages in range %lu to %lu\n", start_page, use_end_page ? end_page : (pages - 1)); } @@ -256,7 +256,7 @@ int main(int argc, char **argv) } /* allocate buffer for reading (so we don't realloc every time) */ - p= (byte *)malloc(UNIV_PAGE_SIZE); + p= (uchar *)malloc(UNIV_PAGE_SIZE); /* main checksumming loop */ ct= start_page; diff --git a/extra/my_print_defaults.c b/extra/my_print_defaults.c index f5f7e68c9e6..06f7e51c380 100644 --- a/extra/my_print_defaults.c +++ b/extra/my_print_defaults.c @@ -47,30 +47,30 @@ static struct my_option my_long_options[] = added if the file has no extension) */ {"config-file", 'c', "Deprecated, please use --defaults-file instead. Name of config file to read; if no extension is given, default extension (e.g., .ini or .cnf) will be added", - (gptr*) &config_file, (gptr*) &config_file, 0, GET_STR, REQUIRED_ARG, + (uchar**) &config_file, (uchar**) &config_file, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, #ifdef DBUG_OFF {"debug", '#', "This is a non-debug version. Catch this and exit", 0,0, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0}, #else - {"debug", '#', "Output debug log", (gptr*) &default_dbug_option, - (gptr*) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, + {"debug", '#', "Output debug log", (uchar**) &default_dbug_option, + (uchar**) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, #endif {"defaults-file", 'c', "Like --config-file, except: if first option, then read this file only, do not read global or per-user config files; should be the first option", - (gptr*) &config_file, (gptr*) &config_file, 0, GET_STR, REQUIRED_ARG, + (uchar**) &config_file, (uchar**) &config_file, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"defaults-extra-file", 'e', "Read this file after the global config file and before the config file in the users home directory; should be the first option", - (gptr*) &my_defaults_extra_file, (gptr*) &my_defaults_extra_file, 0, + (uchar**) &my_defaults_extra_file, (uchar**) &my_defaults_extra_file, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"defaults-group-suffix", 'g', "In addition to the given groups, read also groups with this suffix", - (gptr*) &my_defaults_group_suffix, (gptr*) &my_defaults_group_suffix, + (uchar**) &my_defaults_group_suffix, (uchar**) &my_defaults_group_suffix, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"extra-file", 'e', "Deprecated. Synonym for --defaults-extra-file.", - (gptr*) &my_defaults_extra_file, - (gptr*) &my_defaults_extra_file, 0, GET_STR, + (uchar**) &my_defaults_extra_file, + (uchar**) &my_defaults_extra_file, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"no-defaults", 'n', "Return an empty string (useful for scripts).", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, diff --git a/extra/mysql_waitpid.c b/extra/mysql_waitpid.c index a166e6b15af..42465998862 100644 --- a/extra/mysql_waitpid.c +++ b/extra/mysql_waitpid.c @@ -38,7 +38,7 @@ static struct my_option my_long_options[] = 0, 0, 0, 0, 0}, {"verbose", 'v', "Be more verbose. Give a warning, if kill can't handle signal 0.", - (gptr*) &verbose, (gptr*) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + (uchar**) &verbose, (uchar**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"version", 'V', "Print version information and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} diff --git a/extra/perror.c b/extra/perror.c index 1ee2ec08d83..a98a4fc3d1b 100644 --- a/extra/perror.c +++ b/extra/perror.c @@ -13,25 +13,44 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* Return error-text for system error messages and nisam messages */ +/* Return error-text for system error messages and handler messages */ -#define PERROR_VERSION "2.10" +#define PERROR_VERSION "2.11" #include <my_global.h> #include <my_sys.h> #include <m_string.h> #include <errno.h> #include <my_getopt.h> -#ifdef HAVE_NDBCLUSTER_DB -#include "../ndb/src/ndbapi/ndberror.c" -#include "../ndb/src/kernel/error/ndbd_exit_codes.c" +#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE +#include "../storage/ndb/src/ndbapi/ndberror.c" +#include "../storage/ndb/src/kernel/error/ndbd_exit_codes.c" +#include "../storage/ndb/include/mgmapi/mgmapi_error.h" #endif static my_bool verbose, print_all_codes; -#ifdef HAVE_NDBCLUSTER_DB +#include "../include/my_base.h" +#include "../mysys/my_handler_errors.h" +#include "../include/my_handler.h" + +#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE static my_bool ndb_code; static char ndb_string[1024]; +int mgmapi_error_string(int err_no, char *str, int size) +{ + int i; + for (i= 0; i < ndb_mgm_noOfErrorMsgs; i++) + { + if ((int)ndb_mgm_error_msgs[i].code == err_no) + { + my_snprintf(str, size-1, "%s", ndb_mgm_error_msgs[i].msg); + str[size-1]= '\0'; + return 0; + } + } + return -1; +} #endif static struct my_option my_long_options[] = @@ -40,19 +59,19 @@ static struct my_option my_long_options[] = NO_ARG, 0, 0, 0, 0, 0, 0}, {"info", 'I', "Synonym for --help.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, -#ifdef HAVE_NDBCLUSTER_DB - {"ndb", 257, "Ndbcluster storage engine specific error codes.", (gptr*) &ndb_code, - (gptr*) &ndb_code, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, +#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE + {"ndb", 257, "Ndbcluster storage engine specific error codes.", (uchar**) &ndb_code, + (uchar**) &ndb_code, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, #endif #ifdef HAVE_SYS_ERRLIST {"all", 'a', "Print all the error messages and the number.", - (gptr*) &print_all_codes, (gptr*) &print_all_codes, 0, GET_BOOL, NO_ARG, + (uchar**) &print_all_codes, (uchar**) &print_all_codes, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, #endif {"silent", 's', "Only print the error message.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"verbose", 'v', "Print error code and message (default).", (gptr*) &verbose, - (gptr*) &verbose, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0}, + {"verbose", 'v', "Print error code and message (default).", (uchar**) &verbose, + (uchar**) &verbose, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0}, {"version", 'V', "Displays version information and exits.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} @@ -67,48 +86,6 @@ typedef struct ha_errors { static HA_ERRORS ha_errlist[]= { - { 120,"Didn't find key on read or update" }, - { 121,"Duplicate key on write or update" }, - { 123,"Someone has changed the row since it was read (while the table was locked to prevent it)" }, - { 124,"Wrong index given to function" }, - { 126,"Index file is crashed" }, - { 127,"Record-file is crashed" }, - { 128,"Out of memory" }, - { 130,"Incorrect file format" }, - { 131,"Command not supported by database" }, - { 132,"Old database file" }, - { 133,"No record read before update" }, - { 134,"Record was already deleted (or record file crashed)" }, - { 135,"No more room in record file" }, - { 136,"No more room in index file" }, - { 137,"No more records (read after end of file)" }, - { 138,"Unsupported extension used for table" }, - { 139,"Too big row"}, - { 140,"Wrong create options"}, - { 141,"Duplicate unique key or constraint on write or update"}, - { 142,"Unknown character set used"}, - { 143,"Conflicting table definitions in sub-tables of MERGE table"}, - { 144,"Table is crashed and last repair failed"}, - { 145,"Table was marked as crashed and should be repaired"}, - { 146,"Lock timed out; Retry transaction"}, - { 147,"Lock table is full; Restart program with a larger locktable"}, - { 148,"Updates are not allowed under a read only transactions"}, - { 149,"Lock deadlock; Retry transaction"}, - { 150,"Foreign key constraint is incorrectly formed"}, - { 151,"Cannot add a child row"}, - { 152,"Cannot delete a parent row"}, - { 153,"No savepoint with that name"}, - { 154,"Non unique key block size"}, - { 155,"The table does not exist in engine"}, - { 156,"The table existed in storage engine"}, - { 157,"Could not connect to storage engine"}, - { 158,"NULLs are not supported in spatial index"}, - { 159,"The table changed in storage engine"}, - { 160,"The table changed in storage engine"}, - { 161,"The table is not writable"}, - { 162,"Failed to get the next autoinc value"}, - { 163,"Failed to set the row autoinc value"}, - { 164,"Too many active concurrent transactions"}, { -30999, "DB_INCOMPLETE: Sync didn't finish"}, { -30998, "DB_KEYEMPTY: Key/data deleted or never created"}, { -30997, "DB_KEYEXIST: The key/data pair already exists"}, @@ -138,7 +115,7 @@ static void usage(void) { print_version(); puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n"); - printf("Print a description for a system error code or an error code from\na MyISAM/ISAM/BDB table handler.\n"); + printf("Print a description for a system error code or a MySQL error code.\n"); printf("If you want to get the error for a negative error code, you should use\n-- before the first error code to tell perror that there was no more options.\n\n"); printf("Usage: %s [OPTIONS] [ERRORCODE [ERRORCODE...]]\n",my_progname); my_print_help(my_long_options); @@ -190,6 +167,17 @@ static const char *get_ha_error_msg(int code) { HA_ERRORS *ha_err_ptr; + /* + If you got compilation error here about compile_time_assert array, check + that every HA_ERR_xxx constant has a corresponding error message in + handler_error_messages[] list (check mysys/ma_handler_errors.h and + include/my_base.h). + */ + compile_time_assert(HA_ERR_FIRST + array_elements(handler_error_messages) == + HA_ERR_LAST + 1); + if (code >= HA_ERR_FIRST && code <= HA_ERR_LAST) + return handler_error_messages[code - HA_ERR_FIRST]; + for (ha_err_ptr=ha_errlist ; ha_err_ptr->errcode ;ha_err_ptr++) if (ha_err_ptr->errcode == code) return ha_err_ptr->msg; @@ -232,6 +220,8 @@ int main(int argc,char *argv[]) if (get_options(&argc,&argv)) exit(1); + my_handler_error_register(); + error=0; #ifdef HAVE_SYS_ERRLIST if (print_all_codes) @@ -272,11 +262,12 @@ int main(int argc,char *argv[]) found=0; code=atoi(*argv); -#ifdef HAVE_NDBCLUSTER_DB +#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE if (ndb_code) { - if ((ndb_error_string(code, ndb_string, sizeof(ndb_string)) < 0) && - (ndbd_exit_string(code, ndb_string, sizeof(ndb_string)) < 0)) + if ((ndb_error_string(code, ndb_string, sizeof(ndb_string)) < 0) && + (ndbd_exit_string(code, ndb_string, sizeof(ndb_string)) < 0) && + (mgmapi_error_string(code, ndb_string, sizeof(ndb_string)) < 0)) { msg= 0; } @@ -311,36 +302,31 @@ int main(int argc,char *argv[]) (const uchar*) "Unknown Error", 13) && (!unknown_error || strcmp(msg, unknown_error))) { - found=1; + found= 1; if (verbose) - printf("OS error code %3d: %s\n",code,msg); + printf("OS error code %3d: %s\n", code, msg); else puts(msg); } - + if ((msg= get_ha_error_msg(code))) + { + found= 1; + if (verbose) + printf("MySQL error code %3d: %s\n", code, msg); + else + puts(msg); + } if (!found) { - /* Error message still not found, look in handler error codes */ - if (!(msg=get_ha_error_msg(code))) - { #if defined(__WIN__) - if (!(skip_win_message= !print_win_error_msg((DWORD)code, verbose))) - { + if (!(skip_win_message= !print_win_error_msg((DWORD)code, verbose))) + { #endif - fprintf(stderr,"Illegal error code: %d\n",code); - error=1; + fprintf(stderr,"Illegal error code: %d\n",code); + error=1; #if defined(__WIN__) - } -#endif - } - else - { - found= 1; - if (verbose) - printf("MySQL error code %3d: %s\n",code,msg); - else - puts(msg); } +#endif } #if defined(__WIN__) if (!skip_win_message) diff --git a/extra/replace.c b/extra/replace.c index de0a4b05764..9b7695eddcb 100644 --- a/extra/replace.c +++ b/extra/replace.c @@ -51,7 +51,7 @@ typedef struct st_pointer_array { /* when using array-strings */ TYPELIB typelib; /* Pointer to strings */ - byte *str; /* Strings is here */ + uchar *str; /* Strings is here */ int7 *flag; /* Flag about each var. */ uint array_allocs,max_count,length,max_length; } POINTER_ARRAY; @@ -67,7 +67,7 @@ typedef struct st_replace { } REPLACE; typedef struct st_replace_found { - bool found; + my_bool found; char *replace_string; uint to_offset; int from_offset; @@ -83,14 +83,14 @@ static int static_get_options(int *argc,char * * *argv); static int get_replace_strings(int *argc,char * * *argv, POINTER_ARRAY *from_array, POINTER_ARRAY *to_array); -static int insert_pointer_name(POINTER_ARRAY *pa, my_string name); +static int insert_pointer_name(POINTER_ARRAY *pa, char * name); static void free_pointer_array(POINTER_ARRAY *pa); static int convert_pipe(REPLACE *,FILE *,FILE *); -static int convert_file(REPLACE *, my_string); -static REPLACE *init_replace(my_string *from, my_string *to,uint count, - my_string word_end_chars); -static uint replace_strings(REPLACE *rep, my_string *start,uint *max_length, - my_string from); +static int convert_file(REPLACE *, char *); +static REPLACE *init_replace(char * *from, char * *to,uint count, + char * word_end_chars); +static uint replace_strings(REPLACE *rep, char * *start,uint *max_length, + char * from); static int initialize_buffer(void); static void reset_buffer(void); static void free_buffer(void); @@ -245,10 +245,10 @@ POINTER_ARRAY *from_array,*to_array; return 0; } -static int insert_pointer_name(reg1 POINTER_ARRAY *pa,my_string name) +static int insert_pointer_name(reg1 POINTER_ARRAY *pa,char * name) { uint i,length,old_count; - byte *new_pos; + uchar *new_pos; const char **new_array; DBUG_ENTER("insert_pointer_name"); @@ -256,16 +256,16 @@ static int insert_pointer_name(reg1 POINTER_ARRAY *pa,my_string name) { if (!(pa->typelib.type_names=(const char **) my_malloc(((PC_MALLOC-MALLOC_OVERHEAD)/ - (sizeof(my_string)+sizeof(*pa->flag))* - (sizeof(my_string)+sizeof(*pa->flag))),MYF(MY_WME)))) + (sizeof(char *)+sizeof(*pa->flag))* + (sizeof(char *)+sizeof(*pa->flag))),MYF(MY_WME)))) DBUG_RETURN(-1); - if (!(pa->str= (byte*) my_malloc((uint) (PS_MALLOC-MALLOC_OVERHEAD), + if (!(pa->str= (uchar*) my_malloc((uint) (PS_MALLOC-MALLOC_OVERHEAD), MYF(MY_WME)))) { - my_free((gptr) pa->typelib.type_names,MYF(0)); + my_free((uchar*) pa->typelib.type_names,MYF(0)); DBUG_RETURN (-1); } - pa->max_count=(PC_MALLOC-MALLOC_OVERHEAD)/(sizeof(byte*)+ + pa->max_count=(PC_MALLOC-MALLOC_OVERHEAD)/(sizeof(uchar*)+ sizeof(*pa->flag)); pa->flag= (int7*) (pa->typelib.type_names+pa->max_count); pa->length=0; @@ -277,7 +277,7 @@ static int insert_pointer_name(reg1 POINTER_ARRAY *pa,my_string name) { pa->max_length=(pa->length+length+MALLOC_OVERHEAD+PS_MALLOC-1)/PS_MALLOC; pa->max_length=pa->max_length*PS_MALLOC-MALLOC_OVERHEAD; - if (!(new_pos= (byte*) my_realloc((gptr) pa->str, + if (!(new_pos= (uchar*) my_realloc((uchar*) pa->str, (uint) pa->max_length, MYF(MY_WME)))) DBUG_RETURN(1); @@ -295,23 +295,23 @@ static int insert_pointer_name(reg1 POINTER_ARRAY *pa,my_string name) int len; pa->array_allocs++; len=(PC_MALLOC*pa->array_allocs - MALLOC_OVERHEAD); - if (!(new_array=(const char **) my_realloc((gptr) pa->typelib.type_names, + if (!(new_array=(const char **) my_realloc((uchar*) pa->typelib.type_names, (uint) len/ - (sizeof(byte*)+sizeof(*pa->flag))* - (sizeof(byte*)+sizeof(*pa->flag)), + (sizeof(uchar*)+sizeof(*pa->flag))* + (sizeof(uchar*)+sizeof(*pa->flag)), MYF(MY_WME)))) DBUG_RETURN(1); pa->typelib.type_names=new_array; old_count=pa->max_count; - pa->max_count=len/(sizeof(byte*) + sizeof(*pa->flag)); + pa->max_count=len/(sizeof(uchar*) + sizeof(*pa->flag)); pa->flag= (int7*) (pa->typelib.type_names+pa->max_count); - memcpy((byte*) pa->flag,(my_string) (pa->typelib.type_names+old_count), + memcpy((uchar*) pa->flag,(char *) (pa->typelib.type_names+old_count), old_count*sizeof(*pa->flag)); } pa->flag[pa->typelib.count]=0; /* Reset flag */ - pa->typelib.type_names[pa->typelib.count++]= pa->str+pa->length; + pa->typelib.type_names[pa->typelib.count++]= (char*) (pa->str+pa->length); pa->typelib.type_names[pa->typelib.count]= NullS; /* Put end-mark */ - VOID(strmov(pa->str+pa->length,name)); + VOID(strmov((char*) pa->str + pa->length, name)); pa->length+=length; DBUG_RETURN(0); } /* insert_pointer_name */ @@ -324,9 +324,9 @@ static void free_pointer_array(reg1 POINTER_ARRAY *pa) if (pa->typelib.count) { pa->typelib.count=0; - my_free((gptr) pa->typelib.type_names,MYF(0)); + my_free((uchar*) pa->typelib.type_names,MYF(0)); pa->typelib.type_names=0; - my_free((gptr) pa->str,MYF(0)); + my_free((uchar*) pa->str,MYF(0)); } return; } /* free_pointer_array */ @@ -380,23 +380,23 @@ static int get_next_bit(REP_SET *set,uint lastpos); static short find_set(REP_SETS *sets,REP_SET *find); static short find_found(FOUND_SET *found_set,uint table_offset, int found_offset); -static uint start_at_word(my_string pos); -static uint end_of_word(my_string pos); -static uint replace_len(my_string pos); +static uint start_at_word(char * pos); +static uint end_of_word(char * pos); +static uint replace_len(char * pos); static uint found_sets=0; /* Init a replace structure for further calls */ -static REPLACE *init_replace(my_string *from, my_string *to,uint count, - my_string word_end_chars) +static REPLACE *init_replace(char * *from, char * *to,uint count, + char * word_end_chars) { uint i,j,states,set_nr,len,result_len,max_length,found_end,bits_set,bit_nr; int used_sets,chr; short default_state; char used_chars[LAST_CHAR_CODE],is_word_end[256]; - my_string pos,to_pos,*to_array; + char * pos, *to_pos, **to_array; REP_SETS sets; REP_SET *set,*start_states,*word_states,*new_set; FOLLOWS *follow,*follow_ptr; @@ -441,7 +441,7 @@ static REPLACE *init_replace(my_string *from, my_string *to,uint count, if (!(follow=(FOLLOWS*) my_malloc((states+2)*sizeof(FOLLOWS),MYF(MY_WME)))) { free_sets(&sets); - my_free((gptr) found_set,MYF(0)); + my_free((uchar*) found_set,MYF(0)); DBUG_RETURN(0); } @@ -632,12 +632,12 @@ static REPLACE *init_replace(my_string *from, my_string *to,uint count, if ((replace=(REPLACE*) my_malloc(sizeof(REPLACE)*(sets.count)+ sizeof(REPLACE_STRING)*(found_sets+1)+ - sizeof(my_string)*count+result_len, + sizeof(char *)*count+result_len, MYF(MY_WME | MY_ZEROFILL)))) { rep_str=(REPLACE_STRING*) (replace+sets.count); - to_array=(my_string*) (rep_str+found_sets+1); - to_pos=(my_string) (to_array+count); + to_array=(char **) (rep_str+found_sets+1); + to_pos=(char *) (to_array+count); for (i=0 ; i < count ; i++) { to_array[i]=to_pos; @@ -663,9 +663,9 @@ static REPLACE *init_replace(my_string *from, my_string *to,uint count, replace[i].next[j]=(REPLACE*) (rep_str+(-sets.set[i].next[j]-1)); } } - my_free((gptr) follow,MYF(0)); + my_free((uchar*) follow,MYF(0)); free_sets(&sets); - my_free((gptr) found_set,MYF(0)); + my_free((uchar*) found_set,MYF(0)); DBUG_PRINT("exit",("Replace table has %d states",sets.count)); DBUG_RETURN(replace); } @@ -681,7 +681,7 @@ static int init_sets(REP_SETS *sets,uint states) if (!(sets->bit_buffer=(uint*) my_malloc(sizeof(uint)*sets->size_of_bits* SET_MALLOC_HUNC,MYF(MY_WME)))) { - my_free((gptr) sets->set,MYF(0)); + my_free((uchar*) sets->set,MYF(0)); return 1; } return 0; @@ -713,13 +713,13 @@ static REP_SET *make_new_set(REP_SETS *sets) return set; } count=sets->count+sets->invisible+SET_MALLOC_HUNC; - if (!(set=(REP_SET*) my_realloc((gptr) sets->set_buffer, + if (!(set=(REP_SET*) my_realloc((uchar*) sets->set_buffer, sizeof(REP_SET)*count, MYF(MY_WME)))) return 0; sets->set_buffer=set; sets->set=set+sets->invisible; - if (!(bit_buffer=(uint*) my_realloc((gptr) sets->bit_buffer, + if (!(bit_buffer=(uint*) my_realloc((uchar*) sets->bit_buffer, (sizeof(uint)*sets->size_of_bits)*count, MYF(MY_WME)))) return 0; @@ -742,8 +742,8 @@ static void free_last_set(REP_SETS *sets) static void free_sets(REP_SETS *sets) { - my_free((gptr)sets->set_buffer,MYF(0)); - my_free((gptr)sets->bit_buffer,MYF(0)); + my_free((uchar*)sets->set_buffer,MYF(0)); + my_free((uchar*)sets->bit_buffer,MYF(0)); return; } @@ -770,13 +770,13 @@ static void or_bits(REP_SET *to,REP_SET *from) static void copy_bits(REP_SET *to,REP_SET *from) { - memcpy((byte*) to->bits,(byte*) from->bits, + memcpy((uchar*) to->bits,(uchar*) from->bits, (size_t) (sizeof(uint) * to->size_of_bits)); } static int cmp_bits(REP_SET *set1,REP_SET *set2) { - return bcmp((byte*) set1->bits,(byte*) set2->bits, + return bcmp((uchar*) set1->bits,(uchar*) set2->bits, sizeof(uint) * set1->size_of_bits); } @@ -847,21 +847,21 @@ static short find_found(FOUND_SET *found_set,uint table_offset, /* Return 1 if regexp starts with \b or ends with \b*/ -static uint start_at_word(my_string pos) +static uint start_at_word(char * pos) { return (((!bcmp(pos,"\\b",2) && pos[2]) || !bcmp(pos,"\\^",2)) ? 1 : 0); } -static uint end_of_word(my_string pos) +static uint end_of_word(char * pos) { - my_string end=strend(pos); + char * end=strend(pos); return ((end > pos+2 && !bcmp(end-2,"\\b",2)) || (end >= pos+2 && !bcmp(end-2,"\\$",2))) ? 1 : 0; } -static uint replace_len(my_string str) +static uint replace_len(char * str) { uint len=0; while (*str) @@ -877,12 +877,12 @@ static uint replace_len(my_string str) /* The actual loop */ -static uint replace_strings(REPLACE *rep, my_string *start,uint *max_length, - my_string from) +static uint replace_strings(REPLACE *rep, char **start, uint *max_length, + char *from) { reg1 REPLACE *rep_pos; reg2 REPLACE_STRING *rep_str; - my_string to,end,pos,new; + char *to, *end, *pos, *new; end=(to= *start) + *max_length-1; rep_pos=rep+1; @@ -903,7 +903,7 @@ static uint replace_strings(REPLACE *rep, my_string *start,uint *max_length, } if (!(rep_str = ((REPLACE_STRING*) rep_pos))->replace_string) return (uint) (to - *start)-1; - updated=1; /* Some my_string is replaced */ + updated=1; /* Some char * is replaced */ to-=rep_str->to_offset; for (pos=rep_str->replace_string; *pos ; pos++) { @@ -988,7 +988,8 @@ int n; return 0; /* Read in new stuff. */ - if ((i=(int) my_read(fd, buffer + bufbytes, (uint) bufread,MYF(MY_WME))) < 0) + if ((i=(int) my_read(fd, (uchar*) buffer + bufbytes, + (size_t) bufread, MYF(MY_WME))) < 0) return -1; /* Kludge to pretend every nonempty file ends with a newline. */ @@ -1039,7 +1040,7 @@ FILE *in,*out; return 1; if (!my_eof) out_buff[length++]=save_char; /* Don't write added newline */ - if (my_fwrite(out,out_buff,length,MYF(MY_WME | MY_NABP))) + if (my_fwrite(out, (uchar*) out_buff, length, MYF(MY_WME | MY_NABP))) DBUG_RETURN(1); } } @@ -1047,7 +1048,7 @@ FILE *in,*out; } -static int convert_file(REPLACE *rep, my_string name) +static int convert_file(REPLACE *rep, char * name) { int error; FILE *in,*out; @@ -1056,6 +1057,7 @@ static int convert_file(REPLACE *rep, my_string name) char link_name[FN_REFLEN]; #endif File temp_file; + size_t dir_buff_length; DBUG_ENTER("convert_file"); /* check if name is a symlink */ @@ -1065,7 +1067,7 @@ static int convert_file(REPLACE *rep, my_string name) #endif if (!(in= my_fopen(org_name,O_RDONLY,MYF(MY_WME)))) DBUG_RETURN(1); - dirname_part(dir_buff,org_name); + dirname_part(dir_buff, org_name, &dir_buff_length); if ((temp_file= create_temp_file(tempname, dir_buff, "PR", O_WRONLY, MYF(MY_WME))) < 0) { diff --git a/extra/resolve_stack_dump.c b/extra/resolve_stack_dump.c index 04ab8a30f0d..447d63890bd 100644 --- a/extra/resolve_stack_dump.c +++ b/extra/resolve_stack_dump.c @@ -53,10 +53,10 @@ static struct my_option my_long_options[] = 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, {"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"symbols-file", 's', "Use specified symbols file.", (gptr*) &sym_fname, - (gptr*) &sym_fname, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"symbols-file", 's', "Use specified symbols file.", (uchar**) &sym_fname, + (uchar**) &sym_fname, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"numeric-dump-file", 'n', "Read the dump from specified file.", - (gptr*) &dump_fname, (gptr*) &dump_fname, 0, GET_STR, REQUIRED_ARG, + (uchar**) &dump_fname, (uchar**) &dump_fname, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; @@ -235,7 +235,7 @@ static void init_sym_table() SYM_ENTRY se; if (init_sym_entry(&se, buf)) continue; - if (insert_dynamic(&sym_table, (gptr)&se)) + if (insert_dynamic(&sym_table, (uchar*)&se)) die("insert_dynamic() failed - looks like we are out of memory"); } @@ -255,7 +255,7 @@ static void verify_sort() for (i = 0; i < sym_table.elements; i++) { SYM_ENTRY se; - get_dynamic(&sym_table, (gptr)&se, i); + get_dynamic(&sym_table, (uchar*)&se, i); if (se.addr < last) die("sym table does not appear to be sorted, did you forget \ --numeric-sort arg to nm? trouble addr = %p, last = %p", se.addr, last); @@ -267,16 +267,16 @@ static void verify_sort() static SYM_ENTRY* resolve_addr(uchar* addr, SYM_ENTRY* se) { uint i; - get_dynamic(&sym_table, (gptr)se, 0); + get_dynamic(&sym_table, (uchar*)se, 0); if (addr < se->addr) return 0; for (i = 1; i < sym_table.elements; i++) { - get_dynamic(&sym_table, (gptr)se, i); + get_dynamic(&sym_table, (uchar*)se, i); if (addr < se->addr) { - get_dynamic(&sym_table, (gptr)se, i - 1); + get_dynamic(&sym_table, (uchar*)se, i - 1); return se; } } @@ -290,7 +290,8 @@ static void do_resolve() char buf[1024], *p; while (fgets(buf, sizeof(buf), fp_dump)) { - p = buf; + /* skip bracket */ + p= (p= strchr(buf, '[')) ? p+1 : buf; /* skip space */ while (my_isspace(&my_charset_latin1,*p)) ++p; diff --git a/extra/resolveip.c b/extra/resolveip.c index aedc2cc3418..5f2a9269f62 100644 --- a/extra/resolveip.c +++ b/extra/resolveip.c @@ -33,7 +33,7 @@ #include <my_net.h> #include <my_getopt.h> -#if !defined(_AIX) && !defined(HAVE_UNIXWARE7_THREADS) && !defined(HAVE_UNIXWARE7_POSIX) && !defined(h_errno) +#if !defined(_AIX) && !defined(h_errno) extern int h_errno; #endif @@ -45,7 +45,7 @@ static struct my_option my_long_options[] = 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, {"info", 'I', "Synonym for --help.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"silent", 's', "Be more silent.", (gptr*) &silent, (gptr*) &silent, + {"silent", 's', "Be more silent.", (uchar**) &silent, (uchar**) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"version", 'V', "Displays version information and exits.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, @@ -85,7 +85,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), return 0; } -/*static my_string load_default_groups[]= { "resolveip","client",0 }; */ +/*static char * load_default_groups[]= { "resolveip","client",0 }; */ static int get_options(int *argc,char ***argv) { diff --git a/extra/yassl/CMakeLists.txt b/extra/yassl/CMakeLists.txt index 981f679f785..3407aa7d0dc 100755 --- a/extra/yassl/CMakeLists.txt +++ b/extra/yassl/CMakeLists.txt @@ -24,4 +24,5 @@ SET(YASSL_SOURCES src/buffer.cpp src/cert_wrapper.cpp src/crypto_wrapper.cpp sr src/yassl_imp.cpp src/yassl_int.cpp) IF(NOT SOURCE_SUBLIBS) ADD_LIBRARY(yassl ${YASSL_SOURCES}) + ADD_DEPENDENCIES(yassl GenError) ENDIF(NOT SOURCE_SUBLIBS) diff --git a/extra/yassl/Makefile.am b/extra/yassl/Makefile.am index 35946e002c4..ddd57d60a99 100644 --- a/extra/yassl/Makefile.am +++ b/extra/yassl/Makefile.am @@ -1,5 +1,5 @@ SUBDIRS = taocrypt src testsuite -EXTRA_DIST = yassl.dsp yassl.dsw CMakeLists.txt +EXTRA_DIST = CMakeLists.txt # Don't update the files from bitkeeper %::SCCS/s.% diff --git a/extra/yassl/include/cert_wrapper.hpp b/extra/yassl/include/cert_wrapper.hpp index ce8003aa4cf..572b9f87293 100644 --- a/extra/yassl/include/cert_wrapper.hpp +++ b/extra/yassl/include/cert_wrapper.hpp @@ -34,6 +34,7 @@ #include "yassl_types.hpp" // SignatureAlgorithm #include "buffer.hpp" // input_buffer #include "asn.hpp" // SignerList +#include "openssl/ssl.h" // internal and external use #include STL_LIST_FILE #include STL_ALGORITHM_FILE @@ -87,6 +88,7 @@ class CertManager { bool verifyNone_; // no error if verify fails bool failNoCert_; bool sendVerify_; + VerifyCallback verifyCallback_; // user verify callback public: CertManager(); ~CertManager(); @@ -118,6 +120,7 @@ public: void setFailNoCert(); void setSendVerify(); void setPeerX509(X509*); + void setVerifyCallback(VerifyCallback); private: CertManager(const CertManager&); // hide copy CertManager& operator=(const CertManager&); // and assign diff --git a/extra/yassl/include/openssl/prefix_ssl.h b/extra/yassl/include/openssl/prefix_ssl.h index 3a3a8c26c9c..138d9fb8821 100644 --- a/extra/yassl/include/openssl/prefix_ssl.h +++ b/extra/yassl/include/openssl/prefix_ssl.h @@ -52,6 +52,7 @@ #define SSL_load_error_strings yaSSL_load_error_strings #define SSL_set_session yaSSL_set_session #define SSL_get_session yaSSL_get_session +#define SSL_flush_sessions yaSSL_flush_sessions #define SSL_SESSION_set_timeout yaSSL_SESSION_set_timeout #define SSL_CTX_set_session_cache_mode yaSSL_CTX_set_session_cache_mode #define SSL_get_peer_certificate yaSSL_get_peer_certificate diff --git a/extra/yassl/include/openssl/ssl.h b/extra/yassl/include/openssl/ssl.h index c0b87f804ad..05b34a0dc45 100644 --- a/extra/yassl/include/openssl/ssl.h +++ b/extra/yassl/include/openssl/ssl.h @@ -170,8 +170,9 @@ enum { /* X509 Constants */ X509_V_ERR_CRL_SIGNATURE_FAILURE = 10, X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD = 11, X509_V_ERR_CRL_HAS_EXPIRED = 12, - X509_V_ERR_CERT_REVOKED = 13 - + X509_V_ERR_CERT_REVOKED = 13, + X509_V_FLAG_CRL_CHECK = 14, + X509_V_FLAG_CRL_CHECK_ALL = 15 }; @@ -202,7 +203,8 @@ SSL_CTX* SSL_CTX_new(SSL_METHOD*); SSL* SSL_new(SSL_CTX*); int SSL_set_fd (SSL*, YASSL_SOCKET_T); YASSL_SOCKET_T SSL_get_fd(const SSL*); -int SSL_connect(SSL*); +int SSL_connect(SSL*); /* if you get an error from connect + see note at top of REAMDE */ int SSL_write(SSL*, const void*, int); int SSL_read(SSL*, void*, int); int SSL_accept(SSL*); @@ -227,6 +229,7 @@ void SSL_load_error_strings(void); int SSL_set_session(SSL *ssl, SSL_SESSION *session); SSL_SESSION* SSL_get_session(SSL* ssl); +void SSL_flush_sessions(SSL_CTX *ctx, long tm); long SSL_SESSION_set_timeout(SSL_SESSION*, long); long SSL_CTX_set_session_cache_mode(SSL_CTX* ctx, long mode); X509* SSL_get_peer_certificate(SSL*); diff --git a/extra/yassl/include/yassl_error.hpp b/extra/yassl/include/yassl_error.hpp index 63fa9a761ba..d2473fb3e2b 100644 --- a/extra/yassl/include/yassl_error.hpp +++ b/extra/yassl/include/yassl_error.hpp @@ -64,7 +64,7 @@ enum YasslError { enum Library { yaSSL_Lib = 0, CryptoLib, SocketLib }; enum { MAX_ERROR_SZ = 80 }; -void SetErrorString(YasslError, char*); +void SetErrorString(unsigned long, char*); /* remove for now, if go back to exceptions use this wrapper // Base class for all yaSSL exceptions diff --git a/extra/yassl/include/yassl_imp.hpp b/extra/yassl/include/yassl_imp.hpp index f6434443cb0..8893ba8a8ba 100644 --- a/extra/yassl/include/yassl_imp.hpp +++ b/extra/yassl/include/yassl_imp.hpp @@ -667,10 +667,12 @@ struct Parameters { Cipher suites_[MAX_SUITE_SZ]; char cipher_name_[MAX_SUITE_NAME]; char cipher_list_[MAX_CIPHERS][MAX_SUITE_NAME]; + bool removeDH_; // for server's later use Parameters(ConnectionEnd, const Ciphers&, ProtocolVersion, bool haveDH); - void SetSuites(ProtocolVersion pv, bool removeDH = false); + void SetSuites(ProtocolVersion pv, bool removeDH = false, + bool removeRSA = false, bool removeDSA = false); void SetCipherNames(); private: Parameters(const Parameters&); // hide copy diff --git a/extra/yassl/include/yassl_int.hpp b/extra/yassl/include/yassl_int.hpp index b207f0bffbd..1e761f559e2 100644 --- a/extra/yassl/include/yassl_int.hpp +++ b/extra/yassl/include/yassl_int.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -268,12 +268,14 @@ class Sessions { STL::list<SSL_SESSION*> list_; RandomPool random_; // for session cleaning Mutex mutex_; // no-op for single threaded + int count_; // flush counter - Sessions() {} // only GetSessions can create + Sessions() : count_(0) {} // only GetSessions can create public: SSL_SESSION* lookup(const opaque*, SSL_SESSION* copy = 0); void add(const SSL&); void remove(const opaque*); + void Flush(); ~Sessions(); @@ -425,8 +427,10 @@ private: pem_password_cb passwordCb_; void* userData_; bool sessionCacheOff_; + bool sessionCacheFlushOff_; Stats stats_; Mutex mutex_; // for Stats + VerifyCallback verifyCallback_; public: explicit SSL_CTX(SSL_METHOD* meth); ~SSL_CTX(); @@ -437,18 +441,22 @@ public: const Ciphers& GetCiphers() const; const DH_Parms& GetDH_Parms() const; const Stats& GetStats() const; + VerifyCallback getVerifyCallback() const; pem_password_cb GetPasswordCb() const; void* GetUserData() const; bool GetSessionCacheOff() const; + bool GetSessionCacheFlushOff() const; void setVerifyPeer(); void setVerifyNone(); void setFailNoCert(); + void setVerifyCallback(VerifyCallback); bool SetCipherList(const char*); bool SetDH(const DH&); void SetPasswordCb(pem_password_cb cb); void SetUserData(void*); void SetSessionCacheOff(); + void SetSessionCacheFlushOff(); void IncrementStats(StatsField); void AddCA(x509* ca); diff --git a/extra/yassl/include/yassl_types.hpp b/extra/yassl/include/yassl_types.hpp index e4b81f98fff..28535792828 100644 --- a/extra/yassl/include/yassl_types.hpp +++ b/extra/yassl/include/yassl_types.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -29,6 +29,13 @@ #include "type_traits.hpp" +#ifdef _MSC_VER + // disable conversion warning + // 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy + #pragma warning(disable:4244 4996) +#endif + + namespace yaSSL { #define YASSL_LIB @@ -163,7 +170,7 @@ const int RMD_LEN = 20; // RIPEMD-160 digest length const int PREFIX = 3; // up to 3 prefix letters for secret rounds const int KEY_PREFIX = 7; // up to 7 prefix letters for key rounds const int FORTEZZA_MAX = 128; // Maximum Fortezza Key length -const int MAX_SUITE_SZ = 64; // 32 max suites * sizeof(suite) +const int MAX_SUITE_SZ = 128; // 64 max suites * sizeof(suite) const int MAX_SUITE_NAME = 48; // max length of suite name const int MAX_CIPHERS = 32; // max supported ciphers for cipher list const int SIZEOF_ENUM = 1; // SSL considers an enum 1 byte, not 4 @@ -205,6 +212,7 @@ const int SEED_LEN = RAN_LEN * 2; // TLS seed, client + server random const int DEFAULT_TIMEOUT = 500; // Default Session timeout in seconds const int MAX_RECORD_SIZE = 16384; // 2^14, max size by standard const int COMPRESS_EXTRA = 1024; // extra compression possible addition +const int SESSION_FLUSH_COUNT = 256; // when to flush session cache typedef uint8 Cipher; // first byte is always 0x00 for SSLv3 & TLS diff --git a/extra/yassl/src/cert_wrapper.cpp b/extra/yassl/src/cert_wrapper.cpp index 8caca8f9649..ebec0882265 100644 --- a/extra/yassl/src/cert_wrapper.cpp +++ b/extra/yassl/src/cert_wrapper.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,6 +24,7 @@ #include "runtime.hpp" #include "cert_wrapper.hpp" #include "yassl_int.hpp" +#include "error.hpp" #if defined(USE_CML_LIB) #include "cmapi_cpp.h" @@ -90,7 +91,7 @@ opaque* x509::use_buffer() //CertManager CertManager::CertManager() : peerX509_(0), verifyPeer_(false), verifyNone_(false), failNoCert_(false), - sendVerify_(false) + sendVerify_(false), verifyCallback_(0) {} @@ -154,6 +155,12 @@ void CertManager::setSendVerify() } +void CertManager::setVerifyCallback(VerifyCallback vc) +{ + verifyCallback_ = vc; +} + + void CertManager::AddPeerCert(x509* x) { peerList_.push_back(x); // take ownership @@ -236,7 +243,7 @@ uint CertManager::get_privateKeyLength() const int CertManager::Validate() { CertList::reverse_iterator last = peerList_.rbegin(); - size_t count= peerList_.size(); + size_t count = peerList_.size(); while ( count > 1 ) { TaoCrypt::Source source((*last)->get_buffer(), (*last)->get_length()); @@ -257,7 +264,8 @@ int CertManager::Validate() TaoCrypt::Source source((*last)->get_buffer(), (*last)->get_length()); TaoCrypt::CertDecoder cert(source, true, &signers_, verifyNone_); - if (int err = cert.GetError().What()) + int err = cert.GetError().What(); + if ( err ) return err; uint sz = cert.GetPublicKey().size(); @@ -269,13 +277,25 @@ int CertManager::Validate() else peerKeyType_ = dsa_sa_algo; - size_t iSz= strlen(cert.GetIssuer()) + 1; - size_t sSz= strlen(cert.GetCommonName()) + 1; - size_t bSz= strlen(cert.GetBeforeDate()) + 1; - size_t aSz= strlen(cert.GetAfterDate()) + 1; + size_t iSz = strlen(cert.GetIssuer()) + 1; + size_t sSz = strlen(cert.GetCommonName()) + 1; + int bSz = (int)strlen(cert.GetBeforeDate()) + 1; + int aSz = (int)strlen(cert.GetAfterDate()) + 1; peerX509_ = NEW_YS X509(cert.GetIssuer(), iSz, cert.GetCommonName(), - sSz, cert.GetBeforeDate(), (int) bSz, - cert.GetAfterDate(), (int) aSz); + sSz, cert.GetBeforeDate(), bSz, + cert.GetAfterDate(), aSz); + + if (err == TaoCrypt::SIG_OTHER_E && verifyCallback_) { + X509_STORE_CTX store; + store.error = err; + store.error_depth = static_cast<int>(count) - 1; + store.current_cert = peerX509_; + + int ok = verifyCallback_(0, &store); + if (ok) return 0; + } + + if (err == TaoCrypt::SIG_OTHER_E) return err; } return 0; } diff --git a/extra/yassl/src/ssl.cpp b/extra/yassl/src/ssl.cpp index 781cfa36a70..4d8b6ac69b8 100644 --- a/extra/yassl/src/ssl.cpp +++ b/extra/yassl/src/ssl.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -245,6 +245,7 @@ YASSL_SOCKET_T SSL_get_fd(const SSL* ssl) } +// if you get an error from connect see note at top of README int SSL_connect(SSL* ssl) { if (ssl->GetError() == YasslError(SSL_ERROR_WANT_READ)) @@ -447,6 +448,9 @@ long SSL_CTX_set_session_cache_mode(SSL_CTX* ctx, long mode) if (mode == SSL_SESS_CACHE_OFF) ctx->SetSessionCacheOff(); + if (mode == SSL_SESS_CACHE_NO_AUTO_CLEAR) + ctx->SetSessionCacheFlushOff(); + return SSL_SUCCESS; } @@ -493,6 +497,15 @@ long SSL_get_default_timeout(SSL* /*ssl*/) } +void SSL_flush_sessions(SSL_CTX *ctx, long /* tm */) +{ + if (ctx->GetSessionCacheOff()) + return; + + GetSessions().Flush(); +} + + const char* SSL_get_cipher_name(SSL* ssl) { return SSL_get_cipher(ssl); @@ -560,7 +573,7 @@ int SSL_get_error(SSL* ssl, int /*previous*/) only need to turn on for client, becuase server on by default if built in but calling for server will tell you whether it's available or not */ -int SSL_set_compression(SSL* ssl) +int SSL_set_compression(SSL* ssl) /* Chad didn't rename to ya~ because it is prob. bug. */ { return ssl->SetCompression(); } @@ -604,13 +617,13 @@ char* X509_NAME_oneline(X509_NAME* name, char* buffer, int sz) { if (!name->GetName()) return buffer; - size_t len= strlen(name->GetName()) + 1; - int copySz = min((int) len, sz); + int len = (int)strlen(name->GetName()) + 1; + int copySz = min(len, sz); if (!buffer) { buffer = (char*)malloc(len); if (!buffer) return buffer; - copySz = (int) len; + copySz = len; } if (copySz == 0) @@ -693,7 +706,7 @@ int SSL_CTX_use_PrivateKey_file(SSL_CTX* ctx, const char* file, int format) } -void SSL_CTX_set_verify(SSL_CTX* ctx, int mode, VerifyCallback /*vc*/) +void SSL_CTX_set_verify(SSL_CTX* ctx, int mode, VerifyCallback vc) { if (mode & SSL_VERIFY_PEER) ctx->setVerifyPeer(); @@ -703,6 +716,8 @@ void SSL_CTX_set_verify(SSL_CTX* ctx, int mode, VerifyCallback /*vc*/) if (mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT) ctx->setFailNoCert(); + + ctx->setVerifyCallback(vc); } @@ -976,7 +991,7 @@ char* ERR_error_string(unsigned long errNumber, char* buffer) static char* msg = (char*)"Please supply a buffer for error string"; if (buffer) { - SetErrorString(YasslError(errNumber), buffer); + SetErrorString(errNumber, buffer); return buffer; } @@ -1450,6 +1465,8 @@ unsigned long err_helper(bool peek = false) default : return 0; } + + return 0; // shut up compiler } diff --git a/extra/yassl/src/yassl_error.cpp b/extra/yassl/src/yassl_error.cpp index dc120028e13..dd30348cd93 100644 --- a/extra/yassl/src/yassl_error.cpp +++ b/extra/yassl/src/yassl_error.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -26,6 +26,11 @@ #include "openssl/ssl.h" // SSL_ERROR_WANT_READ #include <string.h> // strncpy +#ifdef _MSC_VER + // 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy + #pragma warning(disable: 4996) +#endif + namespace yaSSL { @@ -50,7 +55,7 @@ Library Error::get_lib() const */ -void SetErrorString(YasslError error, char* buffer) +void SetErrorString(unsigned long error, char* buffer) { using namespace TaoCrypt; const int max = MAX_ERROR_SZ; // shorthand diff --git a/extra/yassl/src/yassl_imp.cpp b/extra/yassl/src/yassl_imp.cpp index 2b2efbbe04f..f079df8c7ce 100644 --- a/extra/yassl/src/yassl_imp.cpp +++ b/extra/yassl/src/yassl_imp.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -136,9 +136,19 @@ void DH_Server::build(SSL& ssl) const CertManager& cert = ssl.getCrypto().get_certManager(); if (ssl.getSecurity().get_parms().sig_algo_ == rsa_sa_algo) + { + if (cert.get_keyType() != rsa_sa_algo) { + ssl.SetError(privateKey_error); + return; + } auth.reset(NEW_YS RSA(cert.get_privateKey(), cert.get_privateKeyLength(), false)); + } else { + if (cert.get_keyType() != dsa_sa_algo) { + ssl.SetError(privateKey_error); + return; + } auth.reset(NEW_YS DSS(cert.get_privateKey(), cert.get_privateKeyLength(), false)); sigSz += DSS_ENCODED_EXTRA; @@ -436,18 +446,21 @@ Parameters::Parameters(ConnectionEnd ce, const Ciphers& ciphers, pending_ = true; // suite not set yet strncpy(cipher_name_, "NONE", 5); + removeDH_ = !haveDH; // only use on server side for set suites + if (ciphers.setSuites_) { // use user set list suites_size_ = ciphers.suiteSz_; memcpy(suites_, ciphers.suites_, ciphers.suiteSz_); SetCipherNames(); } else - SetSuites(pv, ce == server_end && !haveDH); // defaults + SetSuites(pv, ce == server_end && removeDH_); // defaults } -void Parameters::SetSuites(ProtocolVersion pv, bool removeDH) +void Parameters::SetSuites(ProtocolVersion pv, bool removeDH, bool removeRSA, + bool removeDSA) { int i = 0; // available suites, best first @@ -456,67 +469,87 @@ void Parameters::SetSuites(ProtocolVersion pv, bool removeDH) if (isTLS(pv)) { if (!removeDH) { - suites_[i++] = 0x00; - suites_[i++] = TLS_DHE_RSA_WITH_AES_256_CBC_SHA; - suites_[i++] = 0x00; - suites_[i++] = TLS_DHE_DSS_WITH_AES_256_CBC_SHA; + if (!removeRSA) { + suites_[i++] = 0x00; + suites_[i++] = TLS_DHE_RSA_WITH_AES_256_CBC_SHA; + } + if (!removeDSA) { + suites_[i++] = 0x00; + suites_[i++] = TLS_DHE_DSS_WITH_AES_256_CBC_SHA; + } + } + if (!removeRSA) { + suites_[i++] = 0x00; + suites_[i++] = TLS_RSA_WITH_AES_256_CBC_SHA; } - suites_[i++] = 0x00; - suites_[i++] = TLS_RSA_WITH_AES_256_CBC_SHA; - if (!removeDH) { - suites_[i++] = 0x00; - suites_[i++] = TLS_DHE_RSA_WITH_AES_128_CBC_SHA; - suites_[i++] = 0x00; - suites_[i++] = TLS_DHE_DSS_WITH_AES_128_CBC_SHA; + if (!removeRSA) { + suites_[i++] = 0x00; + suites_[i++] = TLS_DHE_RSA_WITH_AES_128_CBC_SHA; + } + if (!removeDSA) { + suites_[i++] = 0x00; + suites_[i++] = TLS_DHE_DSS_WITH_AES_128_CBC_SHA; + } + } + if (!removeRSA) { + suites_[i++] = 0x00; + suites_[i++] = TLS_RSA_WITH_AES_128_CBC_SHA; + suites_[i++] = 0x00; + suites_[i++] = TLS_RSA_WITH_AES_256_CBC_RMD160; + suites_[i++] = 0x00; + suites_[i++] = TLS_RSA_WITH_AES_128_CBC_RMD160; + suites_[i++] = 0x00; + suites_[i++] = TLS_RSA_WITH_3DES_EDE_CBC_RMD160; } - suites_[i++] = 0x00; - suites_[i++] = TLS_RSA_WITH_AES_128_CBC_SHA; - - suites_[i++] = 0x00; - suites_[i++] = TLS_RSA_WITH_AES_256_CBC_RMD160; - suites_[i++] = 0x00; - suites_[i++] = TLS_RSA_WITH_AES_128_CBC_RMD160; - suites_[i++] = 0x00; - suites_[i++] = TLS_RSA_WITH_3DES_EDE_CBC_RMD160; - if (!removeDH) { + if (!removeRSA) { + suites_[i++] = 0x00; + suites_[i++] = TLS_DHE_RSA_WITH_AES_256_CBC_RMD160; + suites_[i++] = 0x00; + suites_[i++] = TLS_DHE_RSA_WITH_AES_128_CBC_RMD160; + suites_[i++] = 0x00; + suites_[i++] = TLS_DHE_RSA_WITH_3DES_EDE_CBC_RMD160; + } + if (!removeDSA) { + suites_[i++] = 0x00; + suites_[i++] = TLS_DHE_DSS_WITH_AES_256_CBC_RMD160; + suites_[i++] = 0x00; + suites_[i++] = TLS_DHE_DSS_WITH_AES_128_CBC_RMD160; + suites_[i++] = 0x00; + suites_[i++] = TLS_DHE_DSS_WITH_3DES_EDE_CBC_RMD160; + } + } + } + + if (!removeRSA) { suites_[i++] = 0x00; - suites_[i++] = TLS_DHE_RSA_WITH_AES_256_CBC_RMD160; - suites_[i++] = 0x00; - suites_[i++] = TLS_DHE_RSA_WITH_AES_128_CBC_RMD160; + suites_[i++] = SSL_RSA_WITH_RC4_128_SHA; suites_[i++] = 0x00; - suites_[i++] = TLS_DHE_RSA_WITH_3DES_EDE_CBC_RMD160; + suites_[i++] = SSL_RSA_WITH_RC4_128_MD5; suites_[i++] = 0x00; - suites_[i++] = TLS_DHE_DSS_WITH_AES_256_CBC_RMD160; - suites_[i++] = 0x00; - suites_[i++] = TLS_DHE_DSS_WITH_AES_128_CBC_RMD160; + suites_[i++] = SSL_RSA_WITH_3DES_EDE_CBC_SHA; suites_[i++] = 0x00; - suites_[i++] = TLS_DHE_DSS_WITH_3DES_EDE_CBC_RMD160; + suites_[i++] = SSL_RSA_WITH_DES_CBC_SHA; } - } - - suites_[i++] = 0x00; - suites_[i++] = SSL_RSA_WITH_RC4_128_SHA; - suites_[i++] = 0x00; - suites_[i++] = SSL_RSA_WITH_RC4_128_MD5; - - suites_[i++] = 0x00; - suites_[i++] = SSL_RSA_WITH_3DES_EDE_CBC_SHA; - suites_[i++] = 0x00; - suites_[i++] = SSL_RSA_WITH_DES_CBC_SHA; - if (!removeDH) { - suites_[i++] = 0x00; - suites_[i++] = SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA; - suites_[i++] = 0x00; - suites_[i++] = SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA; - - suites_[i++] = 0x00; - suites_[i++] = SSL_DHE_RSA_WITH_DES_CBC_SHA; - suites_[i++] = 0x00; - suites_[i++] = SSL_DHE_DSS_WITH_DES_CBC_SHA; + if (!removeRSA) { + suites_[i++] = 0x00; + suites_[i++] = SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA; + } + if (!removeDSA) { + suites_[i++] = 0x00; + suites_[i++] = SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA; + } + if (!removeRSA) { + suites_[i++] = 0x00; + suites_[i++] = SSL_DHE_RSA_WITH_DES_CBC_SHA; + } + if (!removeDSA) { + suites_[i++] = 0x00; + suites_[i++] = SSL_DHE_DSS_WITH_DES_CBC_SHA; + } } suites_size_ = i; @@ -1471,7 +1504,19 @@ void ClientHello::Process(input_buffer&, SSL& ssl) // downgrade to SSLv3 ssl.useSecurity().use_connection().TurnOffTLS(); ProtocolVersion pv = ssl.getSecurity().get_connection().version_; - ssl.useSecurity().use_parms().SetSuites(pv); // reset w/ SSL suites + bool removeDH = ssl.getSecurity().get_parms().removeDH_; + bool removeRSA = false; + bool removeDSA = false; + + const CertManager& cm = ssl.getCrypto().get_certManager(); + if (cm.get_keyType() == rsa_sa_algo) + removeDSA = true; + else + removeRSA = true; + + // reset w/ SSL suites + ssl.useSecurity().use_parms().SetSuites(pv, removeDH, removeRSA, + removeDSA); } else if (ssl.isTLSv1_1() && client_version_.minor_ == 1) // downgrade to TLSv1, but use same suites @@ -1517,6 +1562,7 @@ void ClientHello::Process(input_buffer&, SSL& ssl) return; } ssl.matchSuite(cipher_suites_, suite_len_); + if (ssl.GetError()) return; ssl.set_pending(ssl.getSecurity().get_parms().suite_[1]); if (compression_methods_ == zlib) diff --git a/extra/yassl/src/yassl_int.cpp b/extra/yassl/src/yassl_int.cpp index ba8ee8f66ab..8e4a9aa95ec 100644 --- a/extra/yassl/src/yassl_int.cpp +++ b/extra/yassl/src/yassl_int.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -40,28 +40,28 @@ void* operator new(size_t sz, yaSSL::new_t) { - void* ptr = malloc(sz ? sz : 1); - if (!ptr) abort(); + void* ptr = malloc(sz ? sz : 1); + if (!ptr) abort(); - return ptr; + return ptr; } void operator delete(void* ptr, yaSSL::new_t) { - if (ptr) free(ptr); + if (ptr) free(ptr); } void* operator new[](size_t sz, yaSSL::new_t nt) { - return ::operator new(sz, nt); + return ::operator new(sz, nt); } void operator delete[](void* ptr, yaSSL::new_t nt) { - ::operator delete(ptr, nt); + ::operator delete(ptr, nt); } namespace yaSSL { @@ -308,6 +308,20 @@ SSL::SSL(SSL_CTX* ctx) SetError(YasslError(err)); return; } + else if (serverSide) { + // remove RSA or DSA suites depending on cert key type + ProtocolVersion pv = secure_.get_connection().version_; + + bool removeDH = secure_.use_parms().removeDH_; + bool removeRSA = false; + bool removeDSA = false; + + if (cm.get_keyType() == rsa_sa_algo) + removeDSA = true; + else + removeRSA = true; + secure_.use_parms().SetSuites(pv, removeDH, removeRSA, removeDSA); + } } else if (serverSide) { SetError(no_key_file); @@ -320,6 +334,7 @@ SSL::SSL(SSL_CTX* ctx) cm.setVerifyNone(); if (ctx->getMethod()->failNoCert()) cm.setFailNoCert(); + cm.setVerifyCallback(ctx->getVerifyCallback()); if (serverSide) crypto_.SetDH(ctx->GetDH_Parms()); @@ -1039,7 +1054,7 @@ void SSL::fillData(Data& data) data.set_length(0); // output, actual data filled dataSz = min(dataSz, bufferedData()); - for (uint i = 0; i < elements; i++) { + for (size_t i = 0; i < elements; i++) { input_buffer* front = buffers_.getData().front(); uint frontSz = front->get_remaining(); uint readSz = min(dataSz - data.get_length(), frontSz); @@ -1063,7 +1078,7 @@ void SSL::fillData(Data& data) void SSL::PeekData(Data& data) { if (GetError()) return; - uint dataSz = data.get_length(); // input, data size to fill + uint dataSz = data.get_length(); // input, data size to fill size_t elements = buffers_.getData().size(); data.set_length(0); // output, actual data filled @@ -1100,7 +1115,7 @@ void SSL::flushBuffer() output_buffer out(sz); size_t elements = buffers_.getHandShake().size(); - for (uint i = 0; i < elements; i++) { + for (size_t i = 0; i < elements; i++) { output_buffer* front = buffers_.getHandShake().front(); out.write(front->get_buffer(), front->get_size()); @@ -1276,6 +1291,7 @@ void SSL::matchSuite(const opaque* peer, uint length) if (secure_.use_parms().suites_[i] == peer[j]) { secure_.use_parms().suite_[0] = 0x00; secure_.use_parms().suite_[1] = peer[j]; + return; } @@ -1284,7 +1300,7 @@ void SSL::matchSuite(const opaque* peer, uint length) void SSL::set_session(SSL_SESSION* s) -{ +{ if (getSecurity().GetContext()->GetSessionCacheOff()) return; @@ -1565,13 +1581,19 @@ Errors& GetErrors() typedef Mutex::Lock Lock; + void Sessions::add(const SSL& ssl) { if (ssl.getSecurity().get_connection().sessionID_Set_) { - Lock guard(mutex_); - list_.push_back(NEW_YS SSL_SESSION(ssl, random_)); + Lock guard(mutex_); + list_.push_back(NEW_YS SSL_SESSION(ssl, random_)); + count_++; } + + if (count_ > SESSION_FLUSH_COUNT) + if (!ssl.getSecurity().GetContext()->GetSessionCacheFlushOff()) + Flush(); } @@ -1660,6 +1682,25 @@ void Sessions::remove(const opaque* id) } +// flush expired sessions from cache +void Sessions::Flush() +{ + Lock guard(mutex_); + sess_iterator next = list_.begin(); + uint current = lowResTimer(); + + while (next != list_.end()) { + sess_iterator si = next; + ++next; + if ( ((*si)->GetBornOn() + (*si)->GetTimeOut()) < current) { + del_ptr_zero()(*si); + list_.erase(si); + } + } + count_ = 0; // reset flush counter +} + + // remove a self thread error void Errors::Remove() { @@ -1764,7 +1805,8 @@ bool SSL_METHOD::multipleProtocol() const SSL_CTX::SSL_CTX(SSL_METHOD* meth) : method_(meth), certificate_(0), privateKey_(0), passwordCb_(0), - userData_(0), sessionCacheOff_(false) + userData_(0), sessionCacheOff_(false), sessionCacheFlushOff_(false), + verifyCallback_(0) {} @@ -1791,6 +1833,12 @@ SSL_CTX::GetCA_List() const } +VerifyCallback SSL_CTX::getVerifyCallback() const +{ + return verifyCallback_; +} + + const x509* SSL_CTX::getCert() const { return certificate_; @@ -1851,6 +1899,12 @@ bool SSL_CTX::GetSessionCacheOff() const } +bool SSL_CTX::GetSessionCacheFlushOff() const +{ + return sessionCacheFlushOff_; +} + + void SSL_CTX::SetUserData(void* data) { userData_ = data; @@ -1863,6 +1917,12 @@ void SSL_CTX::SetSessionCacheOff() } +void SSL_CTX::SetSessionCacheFlushOff() +{ + sessionCacheFlushOff_ = true; +} + + void SSL_CTX::setVerifyPeer() { method_->setVerifyPeer(); @@ -1881,6 +1941,12 @@ void SSL_CTX::setFailNoCert() } +void SSL_CTX::setVerifyCallback(VerifyCallback vc) +{ + verifyCallback_ = vc; +} + + bool SSL_CTX::SetDH(const DH& dh) { dhParms_.p_ = dh.p->int_; @@ -2316,7 +2382,7 @@ X509::X509(const char* i, size_t iSz, const char* s, size_t sSz, : issuer_(i, iSz), subject_(s, sSz), beforeDate_(b, bSz), afterDate_(a, aSz) {} - + X509_NAME* X509::GetIssuer() { @@ -2354,10 +2420,10 @@ ASN1_STRING* X509_NAME::GetEntry(int i) memcpy(entry_.data, &name_[i], sz_ - i); if (entry_.data[sz_ -i - 1]) { entry_.data[sz_ - i] = 0; - entry_.length = (int) (sz_ - i); + entry_.length = int(sz_) - i; } else - entry_.length = (int) (sz_ - i - 1); + entry_.length = int(sz_) - i - 1; entry_.type = 0; return &entry_; diff --git a/extra/yassl/taocrypt/Makefile.am b/extra/yassl/taocrypt/Makefile.am index c03c1a2713b..11fea2064f0 100644 --- a/extra/yassl/taocrypt/Makefile.am +++ b/extra/yassl/taocrypt/Makefile.am @@ -1,5 +1,5 @@ SUBDIRS = src test benchmark -EXTRA_DIST = taocrypt.dsw taocrypt.dsp CMakeLists.txt $(wildcard mySTL/*.hpp) +EXTRA_DIST = CMakeLists.txt $(wildcard mySTL/*.hpp) # Don't update the files from bitkeeper %::SCCS/s.% diff --git a/extra/yassl/taocrypt/src/random.cpp b/extra/yassl/taocrypt/src/random.cpp index 89fd5f7c7bc..2bbc0a85e8b 100644 --- a/extra/yassl/taocrypt/src/random.cpp +++ b/extra/yassl/taocrypt/src/random.cpp @@ -27,7 +27,6 @@ #include <time.h> #if defined(_WIN32) - #define _WIN32_WINNT 0x0400 #include <windows.h> #include <wincrypt.h> #else |