split out the error printing function and try to return better errors
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@20075 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
		| @@ -265,6 +265,9 @@ check_PROGRAMS = test_acquire_cred $(TESTS) | ||||
| bin_PROGRAMS = gss | ||||
| noinst_PROGRAMS = test_cred test_kcred test_context test_ntlm | ||||
|  | ||||
| test_context_SOURCES = test_context.c test_common.c | ||||
| test_ntlm_SOURCES = test_ntlm.c test_common.c | ||||
|  | ||||
| test_ntlm_LDADD = \ | ||||
| 	$(top_builddir)/lib/ntlm/libheimntlm.la \ | ||||
| 	$(LDADD) | ||||
|   | ||||
							
								
								
									
										74
									
								
								lib/gssapi/test_common.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								lib/gssapi/test_common.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,74 @@ | ||||
| /* | ||||
|  * Copyright (c) 2006 Kungliga Tekniska H<>gskolan | ||||
|  * (Royal Institute of Technology, Stockholm, Sweden).  | ||||
|  * All rights reserved.  | ||||
|  * | ||||
|  * Redistribution and use in source and binary forms, with or without  | ||||
|  * modification, are permitted provided that the following conditions  | ||||
|  * are met:  | ||||
|  * | ||||
|  * 1. Redistributions of source code must retain the above copyright  | ||||
|  *    notice, this list of conditions and the following disclaimer.  | ||||
|  * | ||||
|  * 2. Redistributions in binary form must reproduce the above copyright  | ||||
|  *    notice, this list of conditions and the following disclaimer in the  | ||||
|  *    documentation and/or other materials provided with the distribution.  | ||||
|  * | ||||
|  * 3. Neither the name of KTH nor the names of its contributors may be | ||||
|  *    used to endorse or promote products derived from this software without | ||||
|  *    specific prior written permission. | ||||
|  * | ||||
|  * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY | ||||
|  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||||
|  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||||
|  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE | ||||
|  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||||
|  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||||
|  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | ||||
|  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||||
|  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||||
|  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||||
|  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
|  */ | ||||
|  | ||||
| #include "krb5/gsskrb5_locl.h" | ||||
| #include <err.h> | ||||
| #include "test_common.h" | ||||
|  | ||||
| RCSID("$Id$"); | ||||
|  | ||||
| char * | ||||
| gssapi_err(OM_uint32 maj_stat, OM_uint32 min_stat, gss_OID mech) | ||||
| { | ||||
| 	OM_uint32 disp_min_stat, disp_maj_stat; | ||||
| 	gss_buffer_desc maj_error_message; | ||||
| 	gss_buffer_desc min_error_message; | ||||
| 	OM_uint32 msg_ctx = 0; | ||||
|  | ||||
| 	char *ret = NULL; | ||||
|  | ||||
| 	maj_error_message.length = 0; | ||||
| 	maj_error_message.value = NULL; | ||||
| 	min_error_message.length = 0; | ||||
| 	min_error_message.value = NULL; | ||||
| 	 | ||||
| 	disp_maj_stat = gss_display_status(&disp_min_stat, maj_stat,  | ||||
| 					   GSS_C_GSS_CODE, | ||||
| 					   mech, &msg_ctx, &maj_error_message); | ||||
| 	disp_maj_stat = gss_display_status(&disp_min_stat, min_stat, | ||||
| 					   GSS_C_MECH_CODE, | ||||
| 					   mech, &msg_ctx, &min_error_message); | ||||
| 	asprintf(&ret, "gss-code: %lu %.*s\nmech-code: %lu %.*s",  | ||||
| 		 (unsigned long)maj_stat, | ||||
| 		 (int)maj_error_message.length,  | ||||
| 		 (char *)maj_error_message.value,  | ||||
| 		 (unsigned long)min_stat, | ||||
| 		 (int)min_error_message.length,  | ||||
| 		 (char *)min_error_message.value); | ||||
|  | ||||
| 	gss_release_buffer(&disp_min_stat, &maj_error_message); | ||||
| 	gss_release_buffer(&disp_min_stat, &min_error_message); | ||||
|  | ||||
| 	return ret; | ||||
| } | ||||
|  | ||||
							
								
								
									
										36
									
								
								lib/gssapi/test_common.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								lib/gssapi/test_common.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,36 @@ | ||||
| /* | ||||
|  * Copyright (c) 2006 - 2007 Kungliga Tekniska H<>gskolan | ||||
|  * (Royal Institute of Technology, Stockholm, Sweden).  | ||||
|  * All rights reserved.  | ||||
|  * | ||||
|  * Redistribution and use in source and binary forms, with or without  | ||||
|  * modification, are permitted provided that the following conditions  | ||||
|  * are met:  | ||||
|  * | ||||
|  * 1. Redistributions of source code must retain the above copyright  | ||||
|  *    notice, this list of conditions and the following disclaimer.  | ||||
|  * | ||||
|  * 2. Redistributions in binary form must reproduce the above copyright  | ||||
|  *    notice, this list of conditions and the following disclaimer in the  | ||||
|  *    documentation and/or other materials provided with the distribution.  | ||||
|  * | ||||
|  * 3. Neither the name of KTH nor the names of its contributors may be | ||||
|  *    used to endorse or promote products derived from this software without | ||||
|  *    specific prior written permission. | ||||
|  * | ||||
|  * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY | ||||
|  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||||
|  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||||
|  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE | ||||
|  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||||
|  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||||
|  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | ||||
|  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||||
|  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||||
|  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||||
|  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
|  */ | ||||
|  | ||||
| /* $Id$ */ | ||||
|  | ||||
| char * gssapi_err(OM_uint32, OM_uint32, gss_OID); | ||||
| @@ -34,6 +34,7 @@ | ||||
| #include "krb5/gsskrb5_locl.h" | ||||
| #include <err.h> | ||||
| #include <getarg.h> | ||||
| #include "test_common.h" | ||||
|  | ||||
| RCSID("$Id$"); | ||||
|  | ||||
| @@ -50,35 +51,6 @@ static int version_flag = 0; | ||||
| static int verbose_flag = 0; | ||||
| static int help_flag	= 0; | ||||
|  | ||||
| static char *gssapi_err(OM_uint32 maj_stat, OM_uint32 min_stat,  | ||||
| 			gss_OID mech) | ||||
| { | ||||
| 	OM_uint32 disp_min_stat, disp_maj_stat; | ||||
| 	gss_buffer_desc maj_error_message; | ||||
| 	gss_buffer_desc min_error_message; | ||||
| 	OM_uint32 msg_ctx = 0; | ||||
|  | ||||
| 	char *ret = NULL; | ||||
|  | ||||
| 	maj_error_message.value = NULL; | ||||
| 	min_error_message.value = NULL; | ||||
| 	 | ||||
| 	disp_maj_stat = gss_display_status(&disp_min_stat, maj_stat, GSS_C_GSS_CODE, | ||||
| 			   mech, &msg_ctx, &maj_error_message); | ||||
| 	disp_maj_stat = gss_display_status(&disp_min_stat, min_stat, GSS_C_MECH_CODE, | ||||
| 			   mech, &msg_ctx, &min_error_message); | ||||
| 	asprintf(&ret, "gss-code: %.*s\nmech-code: %.*s",  | ||||
| 		 (int)maj_error_message.length,  | ||||
| 		 (char *)maj_error_message.value,  | ||||
| 		 (int)min_error_message.length,  | ||||
| 		 (char *)min_error_message.value); | ||||
|  | ||||
| 	gss_release_buffer(&disp_min_stat, &maj_error_message); | ||||
| 	gss_release_buffer(&disp_min_stat, &min_error_message); | ||||
|  | ||||
| 	return ret; | ||||
| } | ||||
|  | ||||
| static struct { | ||||
|     const char *name; | ||||
|     gss_OID *oid; | ||||
|   | ||||
| @@ -38,6 +38,7 @@ | ||||
| #include <err.h> | ||||
| #include <roken.h> | ||||
| #include <getarg.h> | ||||
| #include "test_common.h" | ||||
|  | ||||
| RCSID("$Id$"); | ||||
|  | ||||
| @@ -92,7 +93,8 @@ test_libntlm_v1(void) | ||||
| 				      NULL); | ||||
|     free(data.data); | ||||
|     if (GSS_ERROR(maj_stat)) | ||||
| 	errx(1, "accept_sec_context"); | ||||
| 	errx(1, "accept_sec_context v1: %s", | ||||
| 	     gssapi_err(maj_stat, min_stat, GSS_C_NO_OID)); | ||||
|  | ||||
|     if (output.length == 0) | ||||
| 	errx(1, "output.length == 0"); | ||||
| @@ -139,7 +141,8 @@ test_libntlm_v1(void) | ||||
| 				      NULL); | ||||
|     free(input.value); | ||||
|     if (maj_stat != GSS_S_COMPLETE) | ||||
| 	errx(1, "accept_sec_context 2"); | ||||
| 	errx(1, "accept_sec_context v1 2 %s", | ||||
| 	     gssapi_err(maj_stat, min_stat, GSS_C_NO_OID)); | ||||
|  | ||||
|  | ||||
|     return 0; | ||||
| @@ -193,7 +196,8 @@ test_libntlm_v2(void) | ||||
| 				      NULL); | ||||
|     free(data.data); | ||||
|     if (GSS_ERROR(maj_stat)) | ||||
| 	errx(1, "accept_sec_context"); | ||||
| 	errx(1, "accept_sec_context v2 %s", | ||||
| 	     gssapi_err(maj_stat, min_stat, GSS_C_NO_OID)); | ||||
|  | ||||
|     if (output.length == 0) | ||||
| 	errx(1, "output.length == 0"); | ||||
| @@ -246,7 +250,8 @@ test_libntlm_v2(void) | ||||
| 				      NULL); | ||||
|     free(input.value); | ||||
|     if (maj_stat != GSS_S_COMPLETE) | ||||
| 	errx(1, "accept_sec_context 2"); | ||||
| 	errx(1, "accept_sec_context v2 2 %s", | ||||
| 	     gssapi_err(maj_stat, min_stat, GSS_C_NO_OID)); | ||||
|  | ||||
|  | ||||
|     return 0; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Love Hörnquist Åstrand
					Love Hörnquist Åstrand