Skip to content

Commit

Permalink
Don't use portmapper in RPC tests
Browse files Browse the repository at this point in the history
On many Linux systems, due to what is arguably a bug in rpcbind, the
portmapper doesn't allow service registration from non-root processes.
This causes the RPC tests to be frequently skipped.  Modify the tests
so that they don't need the portmapper, by grabbing the port number
from the server process and passing it to the client.
  • Loading branch information
greghudson committed May 1, 2013
1 parent 11bd102 commit 5454da3
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 35 deletions.
3 changes: 0 additions & 3 deletions doc/build/doing_build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ However, there are several prerequisites that must be satisfied first:
**-**\ **-disable-rpath**, which renders the build tree less suitable for
installation, but allows testing without interference from
previously installed libraries.
* In order to test the RPC layer, the local system has to be running
the portmap daemon and it has to be listening to the regular network
interface (not just localhost).

There are additional regression tests available, which are not run
by ``make check``. These tests require manual setup and teardown of
Expand Down
50 changes: 38 additions & 12 deletions src/lib/rpc/unit-test/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@

#include <stdio.h>
#include <string.h>
#include <netdb.h>
#include <sys/socket.h>
#include "autoconf.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <gssrpc/rpc.h>
#include <gssapi/gssapi.h>
#include <gssapi/gssapi_krb5.h>
#include <gssrpc/rpc.h>
#include <gssrpc/auth_gssapi.h>
#include "rpc_test.h"
Expand Down Expand Up @@ -51,25 +54,27 @@ main(argc, argv)
int argc;
char **argv;
{
char *host, *target, *echo_arg, **echo_resp, buf[BIG_BUF];
char *prot;
char *host, *port, *target, *echo_arg, **echo_resp, buf[BIG_BUF];
CLIENT *clnt;
AUTH *tmp_auth;
struct rpc_err e;
int i, auth_once;
int i, auth_once, sock, use_tcp;
unsigned int count;
extern int optind;
extern char *optarg;
extern int svc_debug_gssapi, misc_debug_gssapi, auth_debug_gssapi;
int c;
struct sockaddr_in sin;
struct hostent *h;
struct timeval tv;

extern int krb5_gss_dbg_client_expcreds;
krb5_gss_dbg_client_expcreds = 1;

whoami = argv[0];
count = 1026;
auth_once = 0;
prot = NULL;
use_tcp = -1;

while ((c = getopt(argc, argv, "a:m:os:tu")) != -1) {
switch (c) {
Expand All @@ -86,39 +91,60 @@ main(argc, argv)
svc_debug_gssapi = atoi(optarg);
break;
case 't':
prot = "tcp";
use_tcp = 1;
break;
case 'u':
prot = "udp";
use_tcp = 0;
break;
case '?':
usage();
break;
}
}
if (prot == NULL)
if (use_tcp == -1)
usage();

argv += optind;
argc -= optind;

switch (argc) {
case 3:
count = atoi(argv[2]);
case 4:
count = atoi(argv[3]);
if (count > BIG_BUF-1) {
fprintf(stderr, "Test count cannot exceed %d.\n", BIG_BUF-1);
usage();
}
case 2:
case 3:
host = argv[0];
target = argv[1];
port = argv[1];
target = argv[2];
break;
default:
usage();
}

/* get server address */
h = gethostbyname(host);
if (h == NULL) {
fprintf(stderr, "Can't resolve hostname %s\n", host);
exit(1);
}
memset(&sin, 0, sizeof(sin));
sin.sin_family = h->h_addrtype;
sin.sin_port = ntohs(atoi(port));
memmove(&sin.sin_addr, h->h_addr, sizeof(sin.sin_addr));

/* client handle to rstat */
clnt = clnt_create(host, RPC_TEST_PROG, RPC_TEST_VERS_1, prot);
sock = RPC_ANYSOCK;
if (use_tcp) {
clnt = clnttcp_create(&sin, RPC_TEST_PROG, RPC_TEST_VERS_1, &sock, 0,
0);
} else {
tv.tv_sec = 5;
tv.tv_usec = 0;
clnt = clntudp_create(&sin, RPC_TEST_PROG, RPC_TEST_VERS_1, tv,
&sock);
}
if (clnt == NULL) {
clnt_pcreateerror(whoami);
exit(1);
Expand Down
21 changes: 5 additions & 16 deletions src/lib/rpc/unit-test/config/unix.exp
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ proc rpc_test_exit {} {
global server_started
global kill

if { [info exists server_started] && $server_started == 0 } {
return
}

if {[catch {
expect {
-i $server_id
Expand All @@ -138,6 +134,7 @@ proc rpc_test_start { } {
global server_id
global server_pid
global server_started
global server_port
global env

if [info exists server_pid] { rpc_test_exit }
Expand All @@ -148,25 +145,17 @@ proc rpc_test_start { } {
set server_pid [spawn $SERVER $PROT]
set server_id $spawn_id
set server_started 1
set server_port -1

unset env(KRB5_KTNAME)

set timeout 30

expect {
-re "port: (\[0-9\]*)\r\n" {
set server_port $expect_out(1,string)
}
"running" { }
"Cannot register service" {
send_error "Server cannot register with portmap/rpcbind!!\n"
note "+++"
note "+++ These tests require the ability to register with portmap/rpcbind"
note "+++ Either the server is not running or it does not"
note "+++ allow registration using a loopback connection"
note "+++"
verbose $expect_out(buffer) 1
set server_started 0
unsupported "Server registration"
return
}
eof {
send_error "server exited!"
verbose $expect_out(buffer) 1
Expand Down
6 changes: 3 additions & 3 deletions src/lib/rpc/unit-test/lib/helpers.exp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ proc flush_server {} {

proc start_client {testname ccname user password lifetime count
{target ""}} {
global env CLIENT PROT hostname spawn_id verbose
global env CLIENT PROT hostname server_port spawn_id verbose

if {$target == ""} {
set target "server@$hostname"
Expand All @@ -180,9 +180,9 @@ proc start_client {testname ccname user password lifetime count
kinit $user $password $lifetime

if {$verbose > 0} {
spawn $CLIENT -a 1 -s 1 -m 1 $PROT $hostname $target $count
spawn $CLIENT -a 1 -s 1 -m 1 $PROT $hostname $server_port $target $count
} else {
spawn $CLIENT $PROT $hostname $target $count
spawn $CLIENT $PROT $hostname $server_port $target $count
}

verbose "$testname: client $ccname started"
Expand Down
3 changes: 2 additions & 1 deletion src/lib/rpc/unit-test/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,13 @@ main(int argc, char **argv)
exit(1);
}
if (!svc_register(transp, RPC_TEST_PROG, RPC_TEST_VERS_1,
rpc_test_prog_1_svc, prot)) {
rpc_test_prog_1_svc, 0)) {
fprintf(stderr,
"unable to register (RPC_TEST_PROG, RPC_TEST_VERS_1, %s).",
prot == IPPROTO_TCP ? "tcp" : "udp");
exit(1);
}
printf("port: %d\n", (int)transp->xp_port);

if (svcauth_gssapi_set_names(names, 0) == FALSE) {
fprintf(stderr, "unable to set gssapi names\n");
Expand Down

0 comments on commit 5454da3

Please sign in to comment.