From: Greg Hudson Date: Sat, 24 Apr 2010 22:20:58 +0000 (+0000) Subject: Merge trunk changes from r23929 to r23937 to iakerb branch X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9fd78ae007eed7d266abe595744e1c2cb22820ba;p=thirdparty%2Fkrb5.git Merge trunk changes from r23929 to r23937 to iakerb branch git-svn-id: svn://anonsvn.mit.edu/krb5/branches/iakerb@23938 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/Makefile.in b/src/Makefile.in index 2f64c497ba..35040a1eeb 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -106,7 +106,7 @@ install-headers-prerecurse: install-headers-mkdirs # install:: # $(MAKE) $(MFLAGS) install.man -fake-install: +fake-install: runenv.py $(RM) -r $(FAKEPREFIX) @for i in $(INSTALLMKDIRS); do \ $(srcdir)/config/mkinstalldirs util/fakedest$$i; \ @@ -627,13 +627,11 @@ check-unix:: krb5-config check-prerecurse: fake-install # Create a test realm and spawn a shell in an environment pointing to it. -testrealm: fake-install runenv.py +testrealm: fake-install PYTHONPATH=$(BUILDTOP):$(top_srcdir)/util $(PYTHON) $(srcdir)/util/testrealm.py # environment variable settings to propagate to Python-based tests -check-pytests-yes: runenv.py - pyrunenv.vals: Makefile $(KRB5_RUN_ENV) \ for i in $(KRB5_RUN_VARS); do \ diff --git a/src/appl/gss-sample/Makefile.in b/src/appl/gss-sample/Makefile.in index ab0495af9a..301f05cc9d 100644 --- a/src/appl/gss-sample/Makefile.in +++ b/src/appl/gss-sample/Makefile.in @@ -44,6 +44,9 @@ gss-client: gss-client.o gss-misc.o $(GSS_DEPLIBS) $(KRB5_BASE_DEPLIBS) clean-unix:: $(RM) gss-server gss-client +check-pytests:: + $(RUNPYTEST) $(srcdir)/t_gss_sample.py $(PYTESTFLAGS) + install-unix:: $(INSTALL_PROGRAM) gss-client $(DESTDIR)$(CLIENT_BINDIR)/gss-client $(INSTALL_PROGRAM) gss-server $(DESTDIR)$(SERVER_BINDIR)/gss-server diff --git a/src/appl/gss-sample/gss-server.c b/src/appl/gss-sample/gss-server.c index 0b8a0e1a5d..0ddfaeee87 100644 --- a/src/appl/gss-sample/gss-server.c +++ b/src/appl/gss-sample/gss-server.c @@ -742,6 +742,7 @@ main(int argc, char **argv) if ((stmp = create_socket(port)) >= 0) { if (listen(stmp, max_threads == 1 ? 0 : max_threads) < 0) perror("listening on socket"); + fprintf(stderr, "starting...\n"); do { struct _work_plan *work = malloc(sizeof(struct _work_plan)); diff --git a/src/appl/gss-sample/t_gss_sample.py b/src/appl/gss-sample/t_gss_sample.py new file mode 100644 index 0000000000..8a09b21239 --- /dev/null +++ b/src/appl/gss-sample/t_gss_sample.py @@ -0,0 +1,40 @@ +# Copyright (C) 2010 by the Massachusetts Institute of Technology. +# All rights reserved. +# +# Export of this software from the United States of America may +# require a specific license from the United States Government. +# It is the responsibility of any person or organization contemplating +# export to obtain such a license before exporting. +# +# WITHIN THAT CONSTRAINT, permission to use, copy, modify, and +# distribute this software and its documentation for any purpose and +# without fee is hereby granted, provided that the above copyright +# notice appear in all copies and that both that copyright notice and +# this permission notice appear in supporting documentation, and that +# the name of M.I.T. not be used in advertising or publicity pertaining +# to distribution of the software without specific, written prior +# permission. Furthermore if you modify this software you must label +# your software as modified software and not distribute it in such a +# fashion that it might be confused with the original M.I.T. software. +# M.I.T. makes no representations about the suitability of +# this software for any purpose. It is provided "as is" without express +# or implied warranty. + +#!/usr/bin/python +from k5test import * + +appdir = os.path.join(buildtop, 'appl', 'gss-sample') +gss_client = os.path.join(appdir, 'gss-client') +gss_server = os.path.join(appdir, 'gss-server') + +for realm in multipass_realms(): + portstr = str(realm.server_port()) + server = realm.start_server([gss_server, '-port', portstr, 'host'], + 'starting...') + output = realm.run_as_client([gss_client, '-port', portstr, + hostname, 'host', 'testmsg']) + if 'Signature verified.' not in output: + fail('Expected message not seen in gss-client output') + stop_daemon(server) + +success('GSS sample application') diff --git a/src/appl/simple/server/sim_server.c b/src/appl/simple/server/sim_server.c index d06c255393..07cb01d5f3 100644 --- a/src/appl/simple/server/sim_server.c +++ b/src/appl/simple/server/sim_server.c @@ -172,6 +172,8 @@ main(int argc, char *argv[]) exit(1); } + printf("starting...\n"); + #ifdef DEBUG printf("socket has port # %d\n", ntohs(s_sock.sin_port)); #endif diff --git a/src/config/post.in b/src/config/post.in index 861117c9e9..43c218bdff 100644 --- a/src/config/post.in +++ b/src/config/post.in @@ -129,26 +129,12 @@ undepend-postrecurse: undepend-recurse ############################## # Python tests -check-unix:: check-pytests +check-unix:: check-pytests-@HAVE_PYTHON@ -# Makefile.in should add dependencies to check-pytests for test -# programs that need to be built before scripts are run. - -check-pytests:: check-pytests-@HAVE_PYTHON@ - -check-pytests-yes: - @pytests="$(PYTESTS)"; \ - for t in $$pytests; do \ - echo PYTHONPATH=$(BUILDTOP):$(top_srcdir)/util VALGRIND="$(VALGRIND)" \ - $(PYTHON) $(srcdir)/$$t $(PYTESTFLAGS); \ - PYTHONPATH=`pwd`:$(top_srcdir)/util VALGRIND="$(VALGRIND)" \ - $(PYTHON) $(srcdir)/$$t $(PYTESTFLAGS) || exit 1; \ - done - -check-pytests-no: - @if test -n "$(PYTESTS)"; then \ - echo "+++ Skipping because Python not available: $(PYTESTS)"; \ - fi +# Makefile.in should add rules to check-pytests to execute Python tests. +check-pytests-yes:: check-pytests +check-pytests-no:: +check-pytests:: clean:: clean-$(WHAT) diff --git a/src/config/pre.in b/src/config/pre.in index a39c0faa5e..d2cad1cd02 100644 --- a/src/config/pre.in +++ b/src/config/pre.in @@ -244,6 +244,9 @@ host=@krb5_cv_host@ DEJAFLAGS = --debug --srcdir $(srcdir) --host $(host) RUNTEST = runtest $(DEJAFLAGS) +RUNPYTEST = PYTHONPATH=$(top_srcdir)/util VALGRIND="$(VALGRIND)" \ + $(PYTHON) + START_SERVERS = $(STESTDIR)/scripts/start_servers $(TEST_SERVER) $(TEST_PATH) START_SERVERS_LOCAL = $(STESTDIR)/scripts/start_servers_local @@ -572,8 +575,7 @@ VALGRIND1 = valgrind --tool=memcheck --log-file=$(VALGRIND_LOGDIR)/vg --trace-ch # something that looks like an FQDN, with an IPv4 address. OFFLINE=no -# Makefile.in should set PYTESTS to a list of Python test scripts to run. -PYTESTS= +# Used when running Python tests. PYTESTFLAGS= ## diff --git a/src/tests/Makefile.in b/src/tests/Makefile.in index 66a3db0768..df2c808cde 100644 --- a/src/tests/Makefile.in +++ b/src/tests/Makefile.in @@ -2,7 +2,6 @@ mydir=tests BUILDTOP=$(REL).. SUBDIRS = resolve asn.1 create hammer verify gssapi dejagnu shlib \ gss-threads misc mkeystash_compat -PYTESTS = t_general.py t_anonpkinit.py RUN_SETUP = @KRB5_RUN_ENV@ KRB5_KDC_PROFILE=kdc.conf KRB5_CONFIG=krb5.conf KRB5_RUN_ENV= @KRB5_RUN_ENV@ @@ -61,6 +60,10 @@ kdb_check: kdc.conf krb5.conf $(RUN_SETUP) $(VALGRIND) ../kadmin/dbutil/kdb5_util $(KADMIN_OPTS) destroy -f $(RM) $(TEST_DB)* stash_file +check-pytests:: + $(RUNPYTEST) $(srcdir)/t_general.py $(PYTESTFLAGS) + $(RUNPYTEST) $(srcdir)/t_anonpkinit.py $(PYTESTFLAGS) + clean:: $(RM) kdc.conf diff --git a/src/tests/dejagnu/config/default.exp b/src/tests/dejagnu/config/default.exp index 1638a5a0d4..f0276b59aa 100644 --- a/src/tests/dejagnu/config/default.exp +++ b/src/tests/dejagnu/config/default.exp @@ -1489,69 +1489,6 @@ proc start_kpropd {} { envstack_pop } -proc start_tail { fname spawnid_var pid_var which standalone } { - upvar $spawnid_var spawnid - upvar $pid_var pid - global timeout - - set f [open $fname a] - - spawn tail -f $fname - set spawnid $spawn_id - set pid [exp_pid] - - set markstr "===MARK $pid [clock format [clock seconds]] ===" - puts $f $markstr - flush $f - - set p 0 - set otimeout $timeout - set timeout 3 - set ok 0 - while { $ok == 0 && $p < 3 } { - expect { - -i $spawn_id - -ex "$markstr" { set ok 1 } - -re "\[^\r\n\]*\r\n" { exp_continue } - timeout { - # Some versions of GNU tail had a race condition where - # the first batch of data would be read from the end - # of the file, and then there was a brief window - # before calling stat and recording the size of the - # file. If the marker is written during that window, - # then yet another file modification is needed to get - # the first one noticed. - if { $p < 3 } { - verbose -log "no tail output yet, prodding with a blank line" - incr p - puts $f "" - flush $f - exp_continue - } else { - close $f - verbose -log "tail $fname output:" - verbose -log [exec tail $fname] - if {$standalone} { - verbose -log "tail -f timed out ($timeout sec) looking for mark in $which log" - fail "$which" - } else { - perror "$which tail -f timed out ($timeout sec) looking for mark in $which log" - } - stop_kerberos_daemons - exec kill $pid - expect -i $spawn_id eof - wait -i $spawn_id - set timeout $otimeout - return 0 - } - } - } - } - close $f - set timeout $otimeout - return 1 -} - # start_kerberos_daemons # A procedure to build a Kerberos database and start up the kerberos # and kadmind daemons. This sets the global variables kdc_pid, @@ -1595,10 +1532,6 @@ proc start_kerberos_daemons { standalone } { set kdc_pidfile $tmppwd/kdc.pid set kadmind_pidfile $tmppwd/kadmind.pid - if ![start_tail $kdc_lfile tailf_spawn_id tailf_pid krb5kdc $standalone] { - return 0 - } - envstack_push setup_kerberos_env kdc # Nuke pid file - to test if setup @@ -1609,42 +1542,18 @@ proc start_kerberos_daemons { standalone } { set kdc_spawn_id $spawn_id expect { - -i $tailf_spawn_id - -re "commencing operation\r\n" { } - -re "krb5kdc: \[a-zA-Z\]* - Cannot bind server socket to \[ 0-9a-fA-F:.\]*\r\n" { - verbose -log "warning: $expect_out(0,string)" - exp_continue - } - "no sockets set up?" { - if {$standalone} { - verbose -log "krb5kdc startup failed to bind listening sockets" - fail "krb5kdc" - } else { - perror "krb5kdc startup failed to bind listening sockets" - } - stop_kerberos_daemons - exec kill $tailf_pid - expect -i $tailf_spawn_id eof - wait -i $tailf_spawn_id - return 0 - } - timeout { + "starting" { } + eof { if {$standalone} { - verbose -log "krb5kdc startup timed out" + verbose -log "krb5kdc failed to start" fail "krb5kdc" } else { - perror "krb5kdc startup timed out" + perror "krb5kdc failed to start" } stop_kerberos_daemons - exec kill $tailf_pid - expect -i $tailf_spawn_id eof - wait -i $tailf_spawn_id return 0 } } - exec kill $tailf_pid - expect -i $tailf_spawn_id eof - wait -i $tailf_spawn_id if (![file exists $kdc_pidfile]) { fail "krb5kdc pidfile" @@ -1677,17 +1586,11 @@ proc start_kerberos_daemons { standalone } { } catch "unset env(KRB5_KTNAME)" - if ![start_tail $kadmind_lfile tailf_spawn_id tailf_pid kadmind $standalone] { - return 0 - } - # Start up the kadmind daemon - # XXXX kadmind uses stderr a lot. the sh -c and redirect can be - # removed when this is fixed envstack_push setup_kerberos_env kdc file delete $kadmind_pidfile - spawn $BINSH -c "exec $KADMIND -r $REALMNAME -W -nofork -P $kadmind_pidfile 2>>$kadmind_lfile" + spawn $BINSH -c "exec $KADMIND -r $REALMNAME -W -nofork -P $kadmind_pidfile" envstack_pop set kadmind_pid [exp_pid] set kadmind_spawn_id $spawn_id @@ -1699,58 +1602,23 @@ proc start_kerberos_daemons { standalone } { } expect { - -i $tailf_spawn_id "Seeding random number" exp_continue - "cannot initialize network" { - if {$standalone} { - verbose -log "kadmind failed network init" - fail "kadmind" - } else { - perror "kadmind failed network init" - } - stop_kerberos_daemons - exec kill $tailf_pid - expect -i $tailf_spawn_id eof - wait -i $tailf_spawn_id - return 0 - } - "cannot bind to network address" { - if {$standalone} { - verbose -log "kadmind failed to bind socket" - fail "kadmind" - } else { - perror "kadmind failed to bind socket" - } - stop_kerberos_daemons - exec kill $tailf_pid - expect -i $tailf_spawn_id eof - wait -i $tailf_spawn_id - return 0 - } "No principal in keytab matches desired name" { dump_db exp_continue } "starting" { } - timeout { + eof { + verbose -log "kadmind failed to start" if {$standalone} { - verbose -log "kadmind failed to start" fail "kadmind" } else { - verbose -log "kadmind failed to start" perror "kadmind failed to start" } -#sleep 10 stop_kerberos_daemons - exec kill $tailf_pid - expect -i $tailf_spawn_id eof - wait -i $tailf_spawn_id return 0 } } - exec kill $tailf_pid - expect -i $tailf_spawn_id eof - wait -i $tailf_spawn_id if (![file exists $kadmind_pidfile]) { fail "kadmind pidfile" diff --git a/src/tests/dejagnu/krb-standalone/gssapi.exp b/src/tests/dejagnu/krb-standalone/gssapi.exp index 1f6664abd2..582e087197 100644 --- a/src/tests/dejagnu/krb-standalone/gssapi.exp +++ b/src/tests/dejagnu/krb-standalone/gssapi.exp @@ -285,7 +285,11 @@ proc doit { } { spawn $GSSSERVER -export -logfile $tmppwd/gss-server.log -verbose -port [expr 8 + $portbase] gssservice@$hostname set gss_server_pid [exp_pid] set gss_server_spawn_id $spawn_id - sleep 2 + + expect { + "starting" { } + eof { perror "gss-server failed to start" } + } run_client gssclient0 $tmppwd/gss_tk_0 gssclient0 run_client gssclient1 $tmppwd/gss_tk_1 gssclient1 diff --git a/src/tests/dejagnu/krb-standalone/simple.exp b/src/tests/dejagnu/krb-standalone/simple.exp index 7f2763c783..fa749035fc 100644 --- a/src/tests/dejagnu/krb-standalone/simple.exp +++ b/src/tests/dejagnu/krb-standalone/simple.exp @@ -46,8 +46,10 @@ proc start_sim_server_daemon { } { verbose "sim_server_spawn is $sim_server_spawn_id" 1 - # Give sim_server some time to start - sleep 2 + expect { + "starting" { } + eof { perror "sim_server failed to start" } + } return 1 } diff --git a/src/tests/gssapi/Makefile.in b/src/tests/gssapi/Makefile.in index ecd066e7cb..2ba81de61f 100644 --- a/src/tests/gssapi/Makefile.in +++ b/src/tests/gssapi/Makefile.in @@ -8,11 +8,10 @@ SRCS= $(srcdir)/t_imp_name.c $(srcdir)/t_s4u.c $(srcdir)/t_namingexts.c $(srcdir OBJS= t_imp_name.o t_s4u.o t_namingexts.o t_gssexts.o t_spnego.o -PYTESTS= t_gssapi.py - all:: t_imp_name t_s4u t_namingexts t_gssexts t_spnego check-pytests:: t_spnego + $(RUNPYTEST) $(srcdir)/t_gssapi.py $(PYTESTFLAGS) t_imp_name: t_imp_name.o $(GSS_DEPLIBS) $(KRB5_BASE_DEPLIBS) $(CC_LINK) -o t_imp_name t_imp_name.o $(GSS_LIBS) $(KRB5_BASE_LIBS) diff --git a/src/util/k5test.py b/src/util/k5test.py index f90f8ac51c..9ac1fc8458 100644 --- a/src/util/k5test.py +++ b/src/util/k5test.py @@ -22,9 +22,13 @@ """A module for krb5 test scripts -Put test script names in the PYTESTS make variable to get them run -with the appropriate PYTHONPATH during "make check". Sample test -script usage: +To run test scripts during "make check" (if Python 2.4 or later is +available), add rules like the following to Makeflie.in: + + check-pytests:: + $(RUNPYTEST) $(srcdir)/t_testname.py $(PYTESTFLAGS) + +A sample test script: from k5test import * @@ -303,11 +307,7 @@ import socket import string import subprocess import sys - -# runenv.py is built in each directory where tests are run, providing -# the environment variable settings needed for running programs in the -# build tree. These can vary by platform. -import runenv +import imp # Used when most things go wrong (other than programming errors) so # that the user sees an error message rather than a Python traceback, @@ -467,15 +467,25 @@ def _match_cmdnum(cmdnum, ind): # Return an environment suitable for running programs in the build # tree. It is safe to modify the result. def _build_env(): - global buildtop + global buildtop, _runenv env = os.environ.copy() - for (k, v) in runenv.env.iteritems(): + for (k, v) in _runenv.iteritems(): if v.find('./') == 0: env[k] = os.path.join(buildtop, v) else: env[k] = v return env + +def _import_runenv(): + global buildtop + runenv_py = os.path.join(buildtop, 'runenv.py') + if not os.path.exists(runenv_py): + fail('You must run "make fake-install" in %s first.' % buildtop) + module = imp.load_source('runenv', runenv_py) + return module.env + + # Merge the nested dictionaries cfg1 and cfg2 into a new dictionary. # cfg1 or cfg2 may be None, in which case the other is returned. If # cfg2 contains keys mapped to None, the corresponding keys will be @@ -1019,6 +1029,7 @@ _cmd_index = 1 buildtop = _find_buildtop() srctop = _find_srctop() plugins = _find_plugins() +_runenv = _import_runenv() hostname = socket.getfqdn() null_input = open(os.devnull, 'r')