1168754Sbushman/*-
2168754Sbushman * Copyright (c) 2006 Michael Bushkov <bushman@freebsd.org>
3168754Sbushman * All rights repeed.
4168754Sbushman *
5168754Sbushman * Redistribution and use in source and binary forms, with or without
6168754Sbushman * modification, are permitted provided that the following conditions
7168754Sbushman * are met:
8168754Sbushman * 1. Redistributions of source code must retain the above copyright
9168754Sbushman *    notice, this list of conditions and the following disclaimer.
10168754Sbushman * 2. Redistributions in binary form must reproduce the above copyright
11168754Sbushman *    notice, this list of conditions and the following disclaimer in the
12168754Sbushman *    documentation and/or other materials provided with the distribution.
13168754Sbushman *
14168754Sbushman * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15168754Sbushman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16168754Sbushman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17168754Sbushman * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18168754Sbushman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19168754Sbushman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20168754Sbushman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21168754Sbushman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22168754Sbushman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23168754Sbushman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24168754Sbushman * SUCH DAMAGE.
25168754Sbushman *
26168754Sbushman */
27168754Sbushman
28168754Sbushman#include <sys/cdefs.h>
29168754Sbushman__FBSDID("$FreeBSD$");
30168754Sbushman
31168754Sbushman#include <arpa/inet.h>
32168754Sbushman#include <rpc/rpc.h>
33168754Sbushman#include <assert.h>
34168754Sbushman#include <errno.h>
35168754Sbushman#include <stdio.h>
36168754Sbushman#include <stdlib.h>
37168754Sbushman#include <string.h>
38168754Sbushman#include <stringlist.h>
39168754Sbushman#include <unistd.h>
40168754Sbushman#include "testutil.h"
41168754Sbushman
42168754Sbushmanenum test_methods {
43168754Sbushman	TEST_GETRPCENT,
44168754Sbushman	TEST_GETRPCBYNAME,
45168754Sbushman	TEST_GETRPCBYNUMBER,
46168754Sbushman	TEST_GETRPCENT_2PASS,
47168754Sbushman	TEST_BUILD_SNAPSHOT
48168754Sbushman};
49168754Sbushman
50168754Sbushmanstatic int debug = 0;
51168754Sbushmanstatic enum test_methods method = TEST_BUILD_SNAPSHOT;
52168754Sbushman
53168754SbushmanDECLARE_TEST_DATA(rpcent)
54168754SbushmanDECLARE_TEST_FILE_SNAPSHOT(rpcent)
55168754SbushmanDECLARE_1PASS_TEST(rpcent)
56168754SbushmanDECLARE_2PASS_TEST(rpcent)
57168754Sbushman
58168754Sbushmanstatic void clone_rpcent(struct rpcent *, struct rpcent const *);
59168754Sbushmanstatic int compare_rpcent(struct rpcent *, struct rpcent *, void *);
60168754Sbushmanstatic void dump_rpcent(struct rpcent *);
61168754Sbushmanstatic void free_rpcent(struct rpcent *);
62168754Sbushman
63168754Sbushmanstatic void sdump_rpcent(struct rpcent *, char *, size_t);
64168754Sbushmanstatic int rpcent_read_snapshot_func(struct rpcent *, char *);
65168754Sbushman
66168754Sbushmanstatic int rpcent_check_ambiguity(struct rpcent_test_data *,
67168754Sbushman	struct rpcent *);
68168754Sbushmanstatic int rpcent_fill_test_data(struct rpcent_test_data *);
69168754Sbushmanstatic int rpcent_test_correctness(struct rpcent *, void *);
70168754Sbushmanstatic int rpcent_test_getrpcbyname(struct rpcent *, void *);
71168754Sbushmanstatic int rpcent_test_getrpcbynumber(struct rpcent *, void *);
72168754Sbushmanstatic int rpcent_test_getrpcent(struct rpcent *, void *);
73168754Sbushman
74168754Sbushmanstatic void usage(void)  __attribute__((__noreturn__));
75168754Sbushman
76168754SbushmanIMPLEMENT_TEST_DATA(rpcent)
77168754SbushmanIMPLEMENT_TEST_FILE_SNAPSHOT(rpcent)
78168754SbushmanIMPLEMENT_1PASS_TEST(rpcent)
79168754SbushmanIMPLEMENT_2PASS_TEST(rpcent)
80168754Sbushman
81168754Sbushmanstatic void
82168754Sbushmanclone_rpcent(struct rpcent *dest, struct rpcent const *src)
83168754Sbushman{
84168754Sbushman	assert(dest != NULL);
85168754Sbushman	assert(src != NULL);
86168754Sbushman
87168754Sbushman	char **cp;
88168754Sbushman	int aliases_num;
89168754Sbushman
90168754Sbushman	memset(dest, 0, sizeof(struct rpcent));
91168754Sbushman
92168754Sbushman	if (src->r_name != NULL) {
93168754Sbushman		dest->r_name = strdup(src->r_name);
94168754Sbushman		assert(dest->r_name != NULL);
95168754Sbushman	}
96168754Sbushman
97168754Sbushman	dest->r_number = src->r_number;
98168754Sbushman
99168754Sbushman	if (src->r_aliases != NULL) {
100168754Sbushman		aliases_num = 0;
101168754Sbushman		for (cp = src->r_aliases; *cp; ++cp)
102168754Sbushman			++aliases_num;
103168754Sbushman
104168754Sbushman		dest->r_aliases = (char **)malloc((aliases_num+1) * (sizeof(char *)));
105168754Sbushman		assert(dest->r_aliases != NULL);
106168754Sbushman		memset(dest->r_aliases, 0, (aliases_num+1) * (sizeof(char *)));
107168754Sbushman
108168754Sbushman		for (cp = src->r_aliases; *cp; ++cp) {
109168754Sbushman			dest->r_aliases[cp - src->r_aliases] = strdup(*cp);
110168754Sbushman			assert(dest->r_aliases[cp - src->r_aliases] != NULL);
111168754Sbushman		}
112168754Sbushman	}
113168754Sbushman}
114168754Sbushman
115168754Sbushmanstatic void
116168754Sbushmanfree_rpcent(struct rpcent *rpc)
117168754Sbushman{
118168754Sbushman	char **cp;
119168754Sbushman
120168754Sbushman	assert(rpc != NULL);
121168754Sbushman
122168754Sbushman	free(rpc->r_name);
123168754Sbushman
124168754Sbushman	for (cp = rpc->r_aliases; *cp; ++cp)
125168754Sbushman		free(*cp);
126168754Sbushman	free(rpc->r_aliases);
127168754Sbushman}
128168754Sbushman
129168754Sbushmanstatic  int
130168754Sbushmancompare_rpcent(struct rpcent *rpc1, struct rpcent *rpc2, void *mdata)
131168754Sbushman{
132168754Sbushman	char **c1, **c2;
133168754Sbushman
134168754Sbushman	if (rpc1 == rpc2)
135168754Sbushman		return 0;
136168754Sbushman
137168754Sbushman	if ((rpc1 == NULL) || (rpc2 == NULL))
138168754Sbushman		goto errfin;
139168754Sbushman
140168754Sbushman	if ((strcmp(rpc1->r_name, rpc2->r_name) != 0) ||
141168754Sbushman		(rpc1->r_number != rpc2->r_number))
142168754Sbushman			goto errfin;
143168754Sbushman
144168754Sbushman	c1 = rpc1->r_aliases;
145168754Sbushman	c2 = rpc2->r_aliases;
146168754Sbushman
147168754Sbushman	if ((rpc1->r_aliases == NULL) || (rpc2->r_aliases == NULL))
148168754Sbushman		goto errfin;
149168754Sbushman
150168754Sbushman	for (;*c1 && *c2; ++c1, ++c2)
151168754Sbushman		if (strcmp(*c1, *c2) != 0)
152168754Sbushman			goto errfin;
153168754Sbushman
154168754Sbushman	if ((*c1 != '\0') || (*c2 != '\0'))
155168754Sbushman		goto errfin;
156168754Sbushman
157168754Sbushman	return 0;
158168754Sbushman
159168754Sbushmanerrfin:
160168754Sbushman	if ((debug) && (mdata == NULL)) {
161168754Sbushman		printf("following structures are not equal:\n");
162168754Sbushman		dump_rpcent(rpc1);
163168754Sbushman		dump_rpcent(rpc2);
164168754Sbushman	}
165168754Sbushman
166168754Sbushman	return (-1);
167168754Sbushman}
168168754Sbushman
169168754Sbushmanstatic void
170168754Sbushmansdump_rpcent(struct rpcent *rpc, char *buffer, size_t buflen)
171168754Sbushman{
172168754Sbushman	char **cp;
173168754Sbushman	int written;
174168754Sbushman
175168754Sbushman	written = snprintf(buffer, buflen, "%s %d",
176168754Sbushman		rpc->r_name, rpc->r_number);
177168754Sbushman	buffer += written;
178168754Sbushman	if (written > buflen)
179168754Sbushman		return;
180168754Sbushman	buflen -= written;
181168754Sbushman
182168754Sbushman	if (rpc->r_aliases != NULL) {
183168754Sbushman		if (*(rpc->r_aliases) != '\0') {
184168754Sbushman			for (cp = rpc->r_aliases; *cp; ++cp) {
185168754Sbushman				written = snprintf(buffer, buflen, " %s",*cp);
186168754Sbushman				buffer += written;
187168754Sbushman				if (written > buflen)
188168754Sbushman					return;
189168754Sbushman				buflen -= written;
190168754Sbushman
191168754Sbushman				if (buflen == 0)
192168754Sbushman					return;
193168754Sbushman			}
194168754Sbushman		} else
195168754Sbushman			snprintf(buffer, buflen, " noaliases");
196168754Sbushman	} else
197168754Sbushman		snprintf(buffer, buflen, " (null)");
198168754Sbushman}
199168754Sbushman
200168754Sbushmanstatic int
201168754Sbushmanrpcent_read_snapshot_func(struct rpcent *rpc, char *line)
202168754Sbushman{
203168754Sbushman	StringList *sl;
204168754Sbushman	char *s, *ps, *ts;
205168754Sbushman	int i;
206168754Sbushman
207168754Sbushman	if (debug)
208168754Sbushman		printf("1 line read from snapshot:\n%s\n", line);
209168754Sbushman
210168754Sbushman	i = 0;
211168754Sbushman	sl = NULL;
212168754Sbushman	ps = line;
213168754Sbushman	memset(rpc, 0, sizeof(struct rpcent));
214168754Sbushman	while ( (s = strsep(&ps, " ")) != NULL) {
215168754Sbushman		switch (i) {
216168754Sbushman			case 0:
217168754Sbushman				rpc->r_name = strdup(s);
218168754Sbushman				assert(rpc->r_name != NULL);
219168754Sbushman			break;
220168754Sbushman
221168754Sbushman			case 1:
222168754Sbushman				rpc->r_number = (int)strtol(s, &ts, 10);
223168754Sbushman				if (*ts != '\0') {
224168754Sbushman					free(rpc->r_name);
225168754Sbushman					return (-1);
226168754Sbushman				}
227168754Sbushman			break;
228168754Sbushman
229168754Sbushman			default:
230168754Sbushman				if (sl == NULL) {
231168754Sbushman					if (strcmp(s, "(null)") == 0)
232168754Sbushman						return (0);
233168754Sbushman
234168754Sbushman					sl = sl_init();
235168754Sbushman					assert(sl != NULL);
236168754Sbushman
237168754Sbushman					if (strcmp(s, "noaliases") != 0) {
238168754Sbushman						ts = strdup(s);
239168754Sbushman						assert(ts != NULL);
240168754Sbushman						sl_add(sl, ts);
241168754Sbushman					}
242168754Sbushman				} else {
243168754Sbushman					ts = strdup(s);
244168754Sbushman					assert(ts != NULL);
245168754Sbushman					sl_add(sl, ts);
246168754Sbushman				}
247168754Sbushman			break;
248168754Sbushman		};
249168754Sbushman		++i;
250168754Sbushman	}
251168754Sbushman
252168754Sbushman	if (i < 3) {
253168754Sbushman		free(rpc->r_name);
254168754Sbushman		memset(rpc, 0, sizeof(struct rpcent));
255168754Sbushman		return (-1);
256168754Sbushman	}
257168754Sbushman
258168754Sbushman	sl_add(sl, NULL);
259168754Sbushman	rpc->r_aliases = sl->sl_str;
260168754Sbushman
261168754Sbushman	/* NOTE: is it a dirty hack or not? */
262168754Sbushman	free(sl);
263168754Sbushman	return (0);
264168754Sbushman}
265168754Sbushman
266168754Sbushmanstatic void
267168754Sbushmandump_rpcent(struct rpcent *result)
268168754Sbushman{
269168754Sbushman	if (result != NULL) {
270168754Sbushman		char buffer[1024];
271168754Sbushman		sdump_rpcent(result, buffer, sizeof(buffer));
272168754Sbushman		printf("%s\n", buffer);
273168754Sbushman	} else
274168754Sbushman		printf("(null)\n");
275168754Sbushman}
276168754Sbushman
277168754Sbushmanstatic int
278168754Sbushmanrpcent_fill_test_data(struct rpcent_test_data *td)
279168754Sbushman{
280168754Sbushman	struct rpcent *rpc;
281168754Sbushman
282168754Sbushman	setrpcent(1);
283168754Sbushman	while ((rpc = getrpcent()) != NULL) {
284168754Sbushman		if (rpcent_test_correctness(rpc, NULL) == 0)
285168754Sbushman			TEST_DATA_APPEND(rpcent, td, rpc);
286168754Sbushman		else
287168754Sbushman			return (-1);
288168754Sbushman	}
289168754Sbushman	endrpcent();
290168754Sbushman
291168754Sbushman	return (0);
292168754Sbushman}
293168754Sbushman
294168754Sbushmanstatic int
295168754Sbushmanrpcent_test_correctness(struct rpcent *rpc, void *mdata)
296168754Sbushman{
297168754Sbushman	if (debug) {
298168754Sbushman		printf("testing correctness with the following data:\n");
299168754Sbushman		dump_rpcent(rpc);
300168754Sbushman	}
301168754Sbushman
302168754Sbushman	if (rpc == NULL)
303168754Sbushman		goto errfin;
304168754Sbushman
305168754Sbushman	if (rpc->r_name == NULL)
306168754Sbushman		goto errfin;
307168754Sbushman
308168754Sbushman	if (rpc->r_number < 0)
309168754Sbushman		goto errfin;
310168754Sbushman
311168754Sbushman	if (rpc->r_aliases == NULL)
312168754Sbushman		goto errfin;
313168754Sbushman
314168754Sbushman	if (debug)
315168754Sbushman		printf("correct\n");
316168754Sbushman
317168754Sbushman	return (0);
318168754Sbushmanerrfin:
319168754Sbushman	if (debug)
320168754Sbushman		printf("incorrect\n");
321168754Sbushman
322168754Sbushman	return (-1);
323168754Sbushman}
324168754Sbushman
325168754Sbushman/* rpcent_check_ambiguity() is needed when one port+rpc is associated with
326168754Sbushman * more than one peice (these cases are usually marked as PROBLEM in
327168754Sbushman * /etc/peices. This functions is needed also when one peice+rpc is
328168754Sbushman * associated with several ports. We have to check all the rpcent structures
329168754Sbushman * to make sure that rpc really exists and correct */
330168754Sbushmanstatic int
331168754Sbushmanrpcent_check_ambiguity(struct rpcent_test_data *td, struct rpcent *rpc)
332168754Sbushman{
333168754Sbushman
334168754Sbushman	return (TEST_DATA_FIND(rpcent, td, rpc, compare_rpcent,
335168754Sbushman		NULL) != NULL ? 0 : -1);
336168754Sbushman}
337168754Sbushman
338168754Sbushmanstatic int
339168754Sbushmanrpcent_test_getrpcbyname(struct rpcent *rpc_model, void *mdata)
340168754Sbushman{
341168754Sbushman	char **alias;
342168754Sbushman	struct rpcent *rpc;
343168754Sbushman
344168754Sbushman	if (debug) {
345168754Sbushman		printf("testing getrpcbyname() with the following data:\n");
346168754Sbushman		dump_rpcent(rpc_model);
347168754Sbushman	}
348168754Sbushman
349168754Sbushman	rpc = getrpcbyname(rpc_model->r_name);
350168754Sbushman	if (rpcent_test_correctness(rpc, NULL) != 0)
351168754Sbushman		goto errfin;
352168754Sbushman
353168754Sbushman	if ((compare_rpcent(rpc, rpc_model, NULL) != 0) &&
354168754Sbushman	    (rpcent_check_ambiguity((struct rpcent_test_data *)mdata, rpc)
355168754Sbushman	    !=0))
356168754Sbushman	    goto errfin;
357168754Sbushman
358168754Sbushman	for (alias = rpc_model->r_aliases; *alias; ++alias) {
359168754Sbushman		rpc = getrpcbyname(*alias);
360168754Sbushman
361168754Sbushman		if (rpcent_test_correctness(rpc, NULL) != 0)
362168754Sbushman			goto errfin;
363168754Sbushman
364168754Sbushman		if ((compare_rpcent(rpc, rpc_model, NULL) != 0) &&
365168754Sbushman		    (rpcent_check_ambiguity(
366168754Sbushman		    (struct rpcent_test_data *)mdata, rpc) != 0))
367168754Sbushman		    goto errfin;
368168754Sbushman	}
369168754Sbushman
370168754Sbushman	if (debug)
371168754Sbushman		printf("ok\n");
372168754Sbushman	return (0);
373168754Sbushman
374168754Sbushmanerrfin:
375168754Sbushman	if (debug)
376168754Sbushman		printf("not ok\n");
377168754Sbushman
378168754Sbushman	return (-1);
379168754Sbushman}
380168754Sbushman
381168754Sbushmanstatic int
382168754Sbushmanrpcent_test_getrpcbynumber(struct rpcent *rpc_model, void *mdata)
383168754Sbushman{
384168754Sbushman	struct rpcent *rpc;
385168754Sbushman
386168754Sbushman	if (debug) {
387168754Sbushman		printf("testing getrpcbyport() with the following data...\n");
388168754Sbushman		dump_rpcent(rpc_model);
389168754Sbushman	}
390168754Sbushman
391168754Sbushman	rpc = getrpcbynumber(rpc_model->r_number);
392168754Sbushman	if ((rpcent_test_correctness(rpc, NULL) != 0) ||
393168754Sbushman	    ((compare_rpcent(rpc, rpc_model, NULL) != 0) &&
394168754Sbushman	    (rpcent_check_ambiguity((struct rpcent_test_data *)mdata, rpc)
395168754Sbushman	    != 0))) {
396168754Sbushman	    if (debug)
397168754Sbushman		printf("not ok\n");
398168754Sbushman	    return (-1);
399168754Sbushman	} else {
400168754Sbushman	    if (debug)
401168754Sbushman		printf("ok\n");
402168754Sbushman	    return (0);
403168754Sbushman	}
404168754Sbushman}
405168754Sbushman
406168754Sbushmanstatic int
407168754Sbushmanrpcent_test_getrpcent(struct rpcent *rpc, void *mdata)
408168754Sbushman{
409168754Sbushman	/* Only correctness can be checked when doing 1-pass test for
410168754Sbushman	 * getrpcent(). */
411168754Sbushman	return (rpcent_test_correctness(rpc, NULL));
412168754Sbushman}
413168754Sbushman
414168754Sbushmanstatic void
415168754Sbushmanusage(void)
416168754Sbushman{
417168754Sbushman	(void)fprintf(stderr,
418168754Sbushman	    "Usage: %s -nve2 [-d] [-s <file>]\n",
419168754Sbushman	    getprogname());
420168754Sbushman	exit(1);
421168754Sbushman}
422168754Sbushman
423168754Sbushmanint
424168754Sbushmanmain(int argc, char **argv)
425168754Sbushman{
426168754Sbushman	struct rpcent_test_data td, td_snap, td_2pass;
427168754Sbushman	char *snapshot_file;
428168754Sbushman	int rv;
429168754Sbushman	int c;
430168754Sbushman
431168754Sbushman	if (argc < 2)
432168754Sbushman		usage();
433168754Sbushman
434168754Sbushman	snapshot_file = NULL;
435168754Sbushman	while ((c = getopt(argc, argv, "nve2ds:")) != -1)
436168754Sbushman		switch (c) {
437168754Sbushman		case 'd':
438168754Sbushman			debug++;
439168754Sbushman			break;
440168754Sbushman		case 'n':
441168754Sbushman			method = TEST_GETRPCBYNAME;
442168754Sbushman			break;
443168754Sbushman		case 'v':
444168754Sbushman			method = TEST_GETRPCBYNUMBER;
445168754Sbushman			break;
446168754Sbushman		case 'e':
447168754Sbushman			method = TEST_GETRPCENT;
448168754Sbushman			break;
449168754Sbushman		case '2':
450168754Sbushman			method = TEST_GETRPCENT_2PASS;
451168754Sbushman			break;
452168754Sbushman		case 's':
453168754Sbushman			snapshot_file = strdup(optarg);
454168754Sbushman			break;
455168754Sbushman		default:
456168754Sbushman			usage();
457168754Sbushman		}
458168754Sbushman
459168754Sbushman	TEST_DATA_INIT(rpcent, &td, clone_rpcent, free_rpcent);
460168754Sbushman	TEST_DATA_INIT(rpcent, &td_snap, clone_rpcent, free_rpcent);
461168754Sbushman	if (snapshot_file != NULL) {
462168754Sbushman		if (access(snapshot_file, W_OK | R_OK) != 0) {
463168754Sbushman			if (errno == ENOENT)
464168754Sbushman				method = TEST_BUILD_SNAPSHOT;
465168754Sbushman			else {
466168754Sbushman				if (debug)
467168754Sbushman					printf("can't access the file %s\n",
468168754Sbushman				snapshot_file);
469168754Sbushman
470168754Sbushman				rv = -1;
471168754Sbushman				goto fin;
472168754Sbushman			}
473168754Sbushman		} else {
474168754Sbushman			if (method == TEST_BUILD_SNAPSHOT) {
475168754Sbushman				rv = 0;
476168754Sbushman				goto fin;
477168754Sbushman			}
478168754Sbushman
479168754Sbushman			TEST_SNAPSHOT_FILE_READ(rpcent, snapshot_file,
480168754Sbushman				&td_snap, rpcent_read_snapshot_func);
481168754Sbushman		}
482168754Sbushman	}
483168754Sbushman
484168754Sbushman	rv = rpcent_fill_test_data(&td);
485168754Sbushman	if (rv == -1)
486168754Sbushman		return (-1);
487168754Sbushman	switch (method) {
488168754Sbushman	case TEST_GETRPCBYNAME:
489168754Sbushman		if (snapshot_file == NULL)
490168754Sbushman			rv = DO_1PASS_TEST(rpcent, &td,
491168754Sbushman				rpcent_test_getrpcbyname, (void *)&td);
492168754Sbushman		else
493168754Sbushman			rv = DO_1PASS_TEST(rpcent, &td_snap,
494168754Sbushman				rpcent_test_getrpcbyname, (void *)&td_snap);
495168754Sbushman		break;
496168754Sbushman	case TEST_GETRPCBYNUMBER:
497168754Sbushman		if (snapshot_file == NULL)
498168754Sbushman			rv = DO_1PASS_TEST(rpcent, &td,
499168754Sbushman				rpcent_test_getrpcbynumber, (void *)&td);
500168754Sbushman		else
501168754Sbushman			rv = DO_1PASS_TEST(rpcent, &td_snap,
502168754Sbushman				rpcent_test_getrpcbynumber, (void *)&td_snap);
503168754Sbushman		break;
504168754Sbushman	case TEST_GETRPCENT:
505168754Sbushman		if (snapshot_file == NULL)
506168754Sbushman			rv = DO_1PASS_TEST(rpcent, &td, rpcent_test_getrpcent,
507168754Sbushman				(void *)&td);
508168754Sbushman		else
509168754Sbushman			rv = DO_2PASS_TEST(rpcent, &td, &td_snap,
510168754Sbushman				compare_rpcent, NULL);
511168754Sbushman		break;
512168754Sbushman	case TEST_GETRPCENT_2PASS:
513168754Sbushman			TEST_DATA_INIT(rpcent, &td_2pass, clone_rpcent, free_rpcent);
514168754Sbushman			rv = rpcent_fill_test_data(&td_2pass);
515168754Sbushman			if (rv != -1)
516168754Sbushman				rv = DO_2PASS_TEST(rpcent, &td, &td_2pass,
517168754Sbushman					compare_rpcent, NULL);
518168754Sbushman			TEST_DATA_DESTROY(rpcent, &td_2pass);
519168754Sbushman		break;
520168754Sbushman	case TEST_BUILD_SNAPSHOT:
521168754Sbushman		if (snapshot_file != NULL)
522168754Sbushman		    rv = TEST_SNAPSHOT_FILE_WRITE(rpcent, snapshot_file, &td,
523168754Sbushman			sdump_rpcent);
524168754Sbushman		break;
525168754Sbushman	default:
526168754Sbushman		rv = 0;
527168754Sbushman		break;
528168754Sbushman	};
529168754Sbushman
530168754Sbushmanfin:
531168754Sbushman	TEST_DATA_DESTROY(rpcent, &td_snap);
532168754Sbushman	TEST_DATA_DESTROY(rpcent, &td);
533168754Sbushman	free(snapshot_file);
534168754Sbushman	return (rv);
535168754Sbushman}
536