xref: /freebsd/lib/libypclnt/ypclnt_new.c (revision 5e53a4f90f82c4345f277dd87cc9292f26e04a29)
1c0f2281eSDag-Erling Smørgrav /*-
2*5e53a4f9SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
3*5e53a4f9SPedro F. Giffuni  *
4c0f2281eSDag-Erling Smørgrav  * Copyright (c) 2002 Networks Associates Technology, Inc.
5c0f2281eSDag-Erling Smørgrav  * All rights reserved.
6c0f2281eSDag-Erling Smørgrav  *
7c0f2281eSDag-Erling Smørgrav  * This software was developed for the FreeBSD Project by ThinkSec AS and
8c0f2281eSDag-Erling Smørgrav  * NAI Labs, the Security Research Division of Network Associates, Inc.
9c0f2281eSDag-Erling Smørgrav  * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
10c0f2281eSDag-Erling Smørgrav  * DARPA CHATS research program.
11c0f2281eSDag-Erling Smørgrav  *
12c0f2281eSDag-Erling Smørgrav  * Redistribution and use in source and binary forms, with or without
13c0f2281eSDag-Erling Smørgrav  * modification, are permitted provided that the following conditions
14c0f2281eSDag-Erling Smørgrav  * are met:
15c0f2281eSDag-Erling Smørgrav  * 1. Redistributions of source code must retain the above copyright
16c0f2281eSDag-Erling Smørgrav  *    notice, this list of conditions and the following disclaimer.
17c0f2281eSDag-Erling Smørgrav  * 2. Redistributions in binary form must reproduce the above copyright
18c0f2281eSDag-Erling Smørgrav  *    notice, this list of conditions and the following disclaimer in the
19c0f2281eSDag-Erling Smørgrav  *    documentation and/or other materials provided with the distribution.
20c0f2281eSDag-Erling Smørgrav  * 3. The name of the author may not be used to endorse or promote
21c0f2281eSDag-Erling Smørgrav  *    products derived from this software without specific prior written
22c0f2281eSDag-Erling Smørgrav  *    permission.
23c0f2281eSDag-Erling Smørgrav  *
24c0f2281eSDag-Erling Smørgrav  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
25c0f2281eSDag-Erling Smørgrav  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26c0f2281eSDag-Erling Smørgrav  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27c0f2281eSDag-Erling Smørgrav  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
28c0f2281eSDag-Erling Smørgrav  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29c0f2281eSDag-Erling Smørgrav  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30c0f2281eSDag-Erling Smørgrav  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31c0f2281eSDag-Erling Smørgrav  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32c0f2281eSDag-Erling Smørgrav  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33c0f2281eSDag-Erling Smørgrav  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34c0f2281eSDag-Erling Smørgrav  * SUCH DAMAGE.
35c0f2281eSDag-Erling Smørgrav  *
36c0f2281eSDag-Erling Smørgrav  * $FreeBSD$
37c0f2281eSDag-Erling Smørgrav  */
38c0f2281eSDag-Erling Smørgrav 
39c0f2281eSDag-Erling Smørgrav #include <stdlib.h>
40c0f2281eSDag-Erling Smørgrav #include <string.h>
41c0f2281eSDag-Erling Smørgrav 
42c0f2281eSDag-Erling Smørgrav #include "ypclnt.h"
43c0f2281eSDag-Erling Smørgrav 
44c0f2281eSDag-Erling Smørgrav ypclnt_t *
45c0f2281eSDag-Erling Smørgrav ypclnt_new(const char *domain, const char *map, const char *server)
46c0f2281eSDag-Erling Smørgrav {
47c0f2281eSDag-Erling Smørgrav 	ypclnt_t *ypclnt;
48c0f2281eSDag-Erling Smørgrav 
49c0f2281eSDag-Erling Smørgrav 	if ((ypclnt = calloc(1, sizeof *ypclnt)) == NULL)
50c0f2281eSDag-Erling Smørgrav 		return (NULL);
51c0f2281eSDag-Erling Smørgrav 	if (domain != NULL && (ypclnt->domain = strdup(domain)) == NULL)
52c0f2281eSDag-Erling Smørgrav 		goto fail;
53c0f2281eSDag-Erling Smørgrav 	if (map != NULL && (ypclnt->map = strdup(map)) == NULL)
54c0f2281eSDag-Erling Smørgrav 		goto fail;
55c0f2281eSDag-Erling Smørgrav 	if (server != NULL && (ypclnt->server = strdup(server)) == NULL)
56c0f2281eSDag-Erling Smørgrav 		goto fail;
57c0f2281eSDag-Erling Smørgrav 	return (ypclnt);
58c0f2281eSDag-Erling Smørgrav  fail:
59c0f2281eSDag-Erling Smørgrav 	free(ypclnt->domain);
60c0f2281eSDag-Erling Smørgrav 	free(ypclnt->map);
61c0f2281eSDag-Erling Smørgrav 	free(ypclnt->server);
62c0f2281eSDag-Erling Smørgrav 	free(ypclnt);
63c0f2281eSDag-Erling Smørgrav 	return (NULL);
64c0f2281eSDag-Erling Smørgrav }
65