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 <assert.h>
33168754Sbushman#include <errno.h>
34168754Sbushman#include <netdb.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_GETPROTOENT,
44168754Sbushman	TEST_GETPROTOBYNAME,
45168754Sbushman	TEST_GETPROTOBYNUMBER,
46168754Sbushman	TEST_GETPROTOENT_2PASS,
47168754Sbushman	TEST_BUILD_SNAPSHOT
48168754Sbushman};
49168754Sbushman
50168754Sbushmanstatic int debug = 0;
51168754Sbushmanstatic enum test_methods method = TEST_BUILD_SNAPSHOT;
52168754Sbushman
53168754SbushmanDECLARE_TEST_DATA(protoent)
54168754SbushmanDECLARE_TEST_FILE_SNAPSHOT(protoent)
55168754SbushmanDECLARE_1PASS_TEST(protoent)
56168754SbushmanDECLARE_2PASS_TEST(protoent)
57168754Sbushman
58168754Sbushmanstatic void clone_protoent(struct protoent *, struct protoent const *);
59168754Sbushmanstatic int compare_protoent(struct protoent *, struct protoent *, void *);
60168754Sbushmanstatic void dump_protoent(struct protoent *);
61168754Sbushmanstatic void free_protoent(struct protoent *);
62168754Sbushman
63168754Sbushmanstatic void sdump_protoent(struct protoent *, char *, size_t);
64168754Sbushmanstatic int protoent_read_snapshot_func(struct protoent *, char *);
65168754Sbushman
66168754Sbushmanstatic int protoent_check_ambiguity(struct protoent_test_data *,
67168754Sbushman	struct protoent *);
68168754Sbushmanstatic int protoent_fill_test_data(struct protoent_test_data *);
69168754Sbushmanstatic int protoent_test_correctness(struct protoent *, void *);
70168754Sbushmanstatic int protoent_test_getprotobyname(struct protoent *, void *);
71168754Sbushmanstatic int protoent_test_getprotobynumber(struct protoent *, void *);
72168754Sbushmanstatic int protoent_test_getprotoent(struct protoent *, void *);
73168754Sbushman
74168754Sbushmanstatic void usage(void)  __attribute__((__noreturn__));
75168754Sbushman
76168754SbushmanIMPLEMENT_TEST_DATA(protoent)
77168754SbushmanIMPLEMENT_TEST_FILE_SNAPSHOT(protoent)
78168754SbushmanIMPLEMENT_1PASS_TEST(protoent)
79168754SbushmanIMPLEMENT_2PASS_TEST(protoent)
80168754Sbushman
81168754Sbushmanstatic void
82168754Sbushmanclone_protoent(struct protoent *dest, struct protoent 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 protoent));
91168754Sbushman
92168754Sbushman	if (src->p_name != NULL) {
93168754Sbushman		dest->p_name = strdup(src->p_name);
94168754Sbushman		assert(dest->p_name != NULL);
95168754Sbushman	}
96168754Sbushman
97168754Sbushman	dest->p_proto = src->p_proto;
98168754Sbushman
99168754Sbushman	if (src->p_aliases != NULL) {
100168754Sbushman		aliases_num = 0;
101168754Sbushman		for (cp = src->p_aliases; *cp; ++cp)
102168754Sbushman			++aliases_num;
103168754Sbushman
104168754Sbushman		dest->p_aliases = (char **)malloc((aliases_num+1) * (sizeof(char *)));
105168754Sbushman		assert(dest->p_aliases != NULL);
106168754Sbushman		memset(dest->p_aliases, 0, (aliases_num+1) * (sizeof(char *)));
107168754Sbushman
108168754Sbushman		for (cp = src->p_aliases; *cp; ++cp) {
109168754Sbushman			dest->p_aliases[cp - src->p_aliases] = strdup(*cp);
110168754Sbushman			assert(dest->p_aliases[cp - src->p_aliases] != NULL);
111168754Sbushman		}
112168754Sbushman	}
113168754Sbushman}
114168754Sbushman
115168754Sbushmanstatic void
116168754Sbushmanfree_protoent(struct protoent *pe)
117168754Sbushman{
118168754Sbushman	char **cp;
119168754Sbushman
120168754Sbushman	assert(pe != NULL);
121168754Sbushman
122168754Sbushman	free(pe->p_name);
123168754Sbushman
124168754Sbushman	for (cp = pe->p_aliases; *cp; ++cp)
125168754Sbushman		free(*cp);
126168754Sbushman	free(pe->p_aliases);
127168754Sbushman}
128168754Sbushman
129168754Sbushmanstatic  int
130168754Sbushmancompare_protoent(struct protoent *pe1, struct protoent *pe2, void *mdata)
131168754Sbushman{
132168754Sbushman	char **c1, **c2;
133168754Sbushman
134168754Sbushman	if (pe1 == pe2)
135168754Sbushman		return 0;
136168754Sbushman
137168754Sbushman	if ((pe1 == NULL) || (pe2 == NULL))
138168754Sbushman		goto errfin;
139168754Sbushman
140168754Sbushman	if ((strcmp(pe1->p_name, pe2->p_name) != 0) ||
141168754Sbushman		(pe1->p_proto != pe2->p_proto))
142168754Sbushman			goto errfin;
143168754Sbushman
144168754Sbushman	c1 = pe1->p_aliases;
145168754Sbushman	c2 = pe2->p_aliases;
146168754Sbushman
147168754Sbushman	if ((pe1->p_aliases == NULL) || (pe2->p_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_protoent(pe1);
163168754Sbushman		dump_protoent(pe2);
164168754Sbushman	}
165168754Sbushman
166168754Sbushman	return (-1);
167168754Sbushman}
168168754Sbushman
169168754Sbushmanstatic void
170168754Sbushmansdump_protoent(struct protoent *pe, char *buffer, size_t buflen)
171168754Sbushman{
172168754Sbushman	char **cp;
173168754Sbushman	int written;
174168754Sbushman
175168754Sbushman	written = snprintf(buffer, buflen, "%s %d",
176168754Sbushman		pe->p_name, pe->p_proto);
177168754Sbushman	buffer += written;
178168754Sbushman	if (written > buflen)
179168754Sbushman		return;
180168754Sbushman	buflen -= written;
181168754Sbushman
182168754Sbushman	if (pe->p_aliases != NULL) {
183168754Sbushman		if (*(pe->p_aliases) != '\0') {
184168754Sbushman			for (cp = pe->p_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
201168754Sbushmanprotoent_read_snapshot_func(struct protoent *pe, 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(pe, 0, sizeof(struct protoent));
214168754Sbushman	while ( (s = strsep(&ps, " ")) != NULL) {
215168754Sbushman		switch (i) {
216168754Sbushman			case 0:
217168754Sbushman				pe->p_name = strdup(s);
218168754Sbushman				assert(pe->p_name != NULL);
219168754Sbushman			break;
220168754Sbushman
221168754Sbushman			case 1:
222168754Sbushman				pe->p_proto = (int)strtol(s, &ts, 10);
223168754Sbushman				if (*ts != '\0') {
224168754Sbushman					free(pe->p_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(pe->p_name);
254168754Sbushman		memset(pe, 0, sizeof(struct protoent));
255168754Sbushman		return (-1);
256168754Sbushman	}
257168754Sbushman
258168754Sbushman	sl_add(sl, NULL);
259168754Sbushman	pe->p_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_protoent(struct protoent *result)
268168754Sbushman{
269168754Sbushman	if (result != NULL) {
270168754Sbushman		char buffer[1024];
271168754Sbushman		sdump_protoent(result, buffer, sizeof(buffer));
272168754Sbushman		printf("%s\n", buffer);
273168754Sbushman	} else
274168754Sbushman		printf("(null)\n");
275168754Sbushman}
276168754Sbushman
277168754Sbushmanstatic int
278168754Sbushmanprotoent_fill_test_data(struct protoent_test_data *td)
279168754Sbushman{
280168754Sbushman	struct protoent *pe;
281168754Sbushman
282168754Sbushman	setprotoent(1);
283168754Sbushman	while ((pe = getprotoent()) != NULL) {
284168754Sbushman		if (protoent_test_correctness(pe, NULL) == 0)
285168754Sbushman			TEST_DATA_APPEND(protoent, td, pe);
286168754Sbushman		else
287168754Sbushman			return (-1);
288168754Sbushman	}
289168754Sbushman	endprotoent();
290168754Sbushman
291168754Sbushman	return (0);
292168754Sbushman}
293168754Sbushman
294168754Sbushmanstatic int
295168754Sbushmanprotoent_test_correctness(struct protoent *pe, void *mdata)
296168754Sbushman{
297168754Sbushman	if (debug) {
298168754Sbushman		printf("testing correctness with the following data:\n");
299168754Sbushman		dump_protoent(pe);
300168754Sbushman	}
301168754Sbushman
302168754Sbushman	if (pe == NULL)
303168754Sbushman		goto errfin;
304168754Sbushman
305168754Sbushman	if (pe->p_name == NULL)
306168754Sbushman		goto errfin;
307168754Sbushman
308168754Sbushman	if (pe->p_proto < 0)
309168754Sbushman		goto errfin;
310168754Sbushman
311168754Sbushman	if (pe->p_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/* protoent_check_ambiguity() is needed when one port+proto 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+proto is
328168754Sbushman * associated with several ports. We have to check all the protoent structures
329168754Sbushman * to make sure that pe really exists and correct */
330168754Sbushmanstatic int
331168754Sbushmanprotoent_check_ambiguity(struct protoent_test_data *td, struct protoent *pe)
332168754Sbushman{
333168754Sbushman
334168754Sbushman	return (TEST_DATA_FIND(protoent, td, pe, compare_protoent,
335168754Sbushman		NULL) != NULL ? 0 : -1);
336168754Sbushman}
337168754Sbushman
338168754Sbushmanstatic int
339168754Sbushmanprotoent_test_getprotobyname(struct protoent *pe_model, void *mdata)
340168754Sbushman{
341168754Sbushman	char **alias;
342168754Sbushman	struct protoent *pe;
343168754Sbushman
344168754Sbushman	if (debug) {
345168754Sbushman		printf("testing getprotobyname() with the following data:\n");
346168754Sbushman		dump_protoent(pe_model);
347168754Sbushman	}
348168754Sbushman
349168754Sbushman	pe = getprotobyname(pe_model->p_name);
350168754Sbushman	if (protoent_test_correctness(pe, NULL) != 0)
351168754Sbushman		goto errfin;
352168754Sbushman
353168754Sbushman	if ((compare_protoent(pe, pe_model, NULL) != 0) &&
354168754Sbushman	    (protoent_check_ambiguity((struct protoent_test_data *)mdata, pe)
355168754Sbushman	    !=0))
356168754Sbushman	    goto errfin;
357168754Sbushman
358168754Sbushman	for (alias = pe_model->p_aliases; *alias; ++alias) {
359168754Sbushman		pe = getprotobyname(*alias);
360168754Sbushman
361168754Sbushman		if (protoent_test_correctness(pe, NULL) != 0)
362168754Sbushman			goto errfin;
363168754Sbushman
364168754Sbushman		if ((compare_protoent(pe, pe_model, NULL) != 0) &&
365168754Sbushman		    (protoent_check_ambiguity(
366168754Sbushman		    (struct protoent_test_data *)mdata, pe) != 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
382168754Sbushmanprotoent_test_getprotobynumber(struct protoent *pe_model, void *mdata)
383168754Sbushman{
384168754Sbushman	struct protoent *pe;
385168754Sbushman
386168754Sbushman	if (debug) {
387168754Sbushman		printf("testing getprotobyport() with the following data...\n");
388168754Sbushman		dump_protoent(pe_model);
389168754Sbushman	}
390168754Sbushman
391168754Sbushman	pe = getprotobynumber(pe_model->p_proto);
392168754Sbushman	if ((protoent_test_correctness(pe, NULL) != 0) ||
393168754Sbushman	    ((compare_protoent(pe, pe_model, NULL) != 0) &&
394168754Sbushman	    (protoent_check_ambiguity((struct protoent_test_data *)mdata, pe)
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
407168754Sbushmanprotoent_test_getprotoent(struct protoent *pe, void *mdata)
408168754Sbushman{
409168754Sbushman	/* Only correctness can be checked when doing 1-pass test for
410168754Sbushman	 * getprotoent(). */
411168754Sbushman	return (protoent_test_correctness(pe, 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 protoent_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_GETPROTOBYNAME;
442168754Sbushman			break;
443168754Sbushman		case 'v':
444168754Sbushman			method = TEST_GETPROTOBYNUMBER;
445168754Sbushman			break;
446168754Sbushman		case 'e':
447168754Sbushman			method = TEST_GETPROTOENT;
448168754Sbushman			break;
449168754Sbushman		case '2':
450168754Sbushman			method = TEST_GETPROTOENT_2PASS;
451168754Sbushman			break;
452168754Sbushman		case 's':
453168754Sbushman			snapshot_file = strdup(optarg);
454168754Sbushman			break;
455168754Sbushman		default:
456168754Sbushman			usage();
457168754Sbushman		}
458168754Sbushman
459168754Sbushman	TEST_DATA_INIT(protoent, &td, clone_protoent, free_protoent);
460168754Sbushman	TEST_DATA_INIT(protoent, &td_snap, clone_protoent, free_protoent);
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(protoent, snapshot_file,
480168754Sbushman				&td_snap, protoent_read_snapshot_func);
481168754Sbushman		}
482168754Sbushman	}
483168754Sbushman
484168754Sbushman	rv = protoent_fill_test_data(&td);
485168754Sbushman	if (rv == -1)
486168754Sbushman		return (-1);
487168754Sbushman	switch (method) {
488168754Sbushman	case TEST_GETPROTOBYNAME:
489168754Sbushman		if (snapshot_file == NULL)
490168754Sbushman			rv = DO_1PASS_TEST(protoent, &td,
491168754Sbushman				protoent_test_getprotobyname, (void *)&td);
492168754Sbushman		else
493168754Sbushman			rv = DO_1PASS_TEST(protoent, &td_snap,
494168754Sbushman				protoent_test_getprotobyname, (void *)&td_snap);
495168754Sbushman		break;
496168754Sbushman	case TEST_GETPROTOBYNUMBER:
497168754Sbushman		if (snapshot_file == NULL)
498168754Sbushman			rv = DO_1PASS_TEST(protoent, &td,
499168754Sbushman				protoent_test_getprotobynumber, (void *)&td);
500168754Sbushman		else
501168754Sbushman			rv = DO_1PASS_TEST(protoent, &td_snap,
502168754Sbushman				protoent_test_getprotobynumber, (void *)&td_snap);
503168754Sbushman		break;
504168754Sbushman	case TEST_GETPROTOENT:
505168754Sbushman		if (snapshot_file == NULL)
506168754Sbushman			rv = DO_1PASS_TEST(protoent, &td,
507168754Sbushman				protoent_test_getprotoent, (void *)&td);
508168754Sbushman		else
509168754Sbushman			rv = DO_2PASS_TEST(protoent, &td, &td_snap,
510168754Sbushman				compare_protoent, NULL);
511168754Sbushman		break;
512168754Sbushman	case TEST_GETPROTOENT_2PASS:
513168754Sbushman			TEST_DATA_INIT(protoent, &td_2pass, clone_protoent,
514168754Sbushman				free_protoent);
515168754Sbushman			rv = protoent_fill_test_data(&td_2pass);
516168754Sbushman			if (rv != -1)
517168754Sbushman				rv = DO_2PASS_TEST(protoent, &td, &td_2pass,
518168754Sbushman					compare_protoent, NULL);
519168754Sbushman			TEST_DATA_DESTROY(protoent, &td_2pass);
520168754Sbushman		break;
521168754Sbushman	case TEST_BUILD_SNAPSHOT:
522168754Sbushman		if (snapshot_file != NULL)
523168754Sbushman		    rv = TEST_SNAPSHOT_FILE_WRITE(protoent, snapshot_file, &td,
524168754Sbushman			sdump_protoent);
525168754Sbushman		break;
526168754Sbushman	default:
527168754Sbushman		rv = 0;
528168754Sbushman		break;
529168754Sbushman	};
530168754Sbushman
531168754Sbushmanfin:
532168754Sbushman	TEST_DATA_DESTROY(protoent, &td_snap);
533168754Sbushman	TEST_DATA_DESTROY(protoent, &td);
534168754Sbushman	free(snapshot_file);
535168754Sbushman	return (rv);
536168754Sbushman}
537