xref: /openbsd/lib/libc/yp/yp_get_default_domain.c (revision ba364bef)
1*ba364befSguenther /*	$OpenBSD: yp_get_default_domain.c,v 1.9 2015/09/13 20:57:28 guenther Exp $ */
218128546Sderaadt /*
318128546Sderaadt  * Copyright (c) 1992, 1993 Theo de Raadt <deraadt@theos.com>
418128546Sderaadt  * All rights reserved.
518128546Sderaadt  *
618128546Sderaadt  * Redistribution and use in source and binary forms, with or without
718128546Sderaadt  * modification, are permitted provided that the following conditions
818128546Sderaadt  * are met:
918128546Sderaadt  * 1. Redistributions of source code must retain the above copyright
1018128546Sderaadt  *    notice, this list of conditions and the following disclaimer.
1118128546Sderaadt  * 2. Redistributions in binary form must reproduce the above copyright
1218128546Sderaadt  *    notice, this list of conditions and the following disclaimer in the
1318128546Sderaadt  *    documentation and/or other materials provided with the distribution.
1418128546Sderaadt  *
1518128546Sderaadt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
1618128546Sderaadt  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1718128546Sderaadt  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1818128546Sderaadt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
1918128546Sderaadt  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2018128546Sderaadt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2118128546Sderaadt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2218128546Sderaadt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2318128546Sderaadt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2418128546Sderaadt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2518128546Sderaadt  * SUCH DAMAGE.
2618128546Sderaadt  */
2718128546Sderaadt 
2818128546Sderaadt #include <sys/types.h>
2918128546Sderaadt #include <unistd.h>
30aea60beeSderaadt #include <limits.h>
3118128546Sderaadt #include <rpc/rpc.h>
3218128546Sderaadt #include <rpc/xdr.h>
3318128546Sderaadt #include <rpcsvc/yp.h>
3418128546Sderaadt #include <rpcsvc/ypclnt.h>
3518128546Sderaadt #include "ypinternal.h"
3618128546Sderaadt 
3718128546Sderaadt int
3811e5d692Sderaadt yp_get_default_domain(char **domp)
3918128546Sderaadt {
4018128546Sderaadt 	*domp = NULL;
4118128546Sderaadt 	if (_yp_domain[0] == '\0')
4218128546Sderaadt 		if (getdomainname(_yp_domain, sizeof _yp_domain))
4318128546Sderaadt 			return YPERR_NODOM;
4418128546Sderaadt 	*domp = _yp_domain;
455915e514Sschwarze 	if (_yp_domain[0] == '\0')
465915e514Sschwarze 		return YPERR_NODOM;
4718128546Sderaadt 	return 0;
4818128546Sderaadt }
49*ba364befSguenther DEF_WEAK(yp_get_default_domain);
50