rpcdname.c revision 90271
126219Swpaul/*
226219Swpaul * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
326219Swpaul * unrestricted use provided that this legend is included on all tape
426219Swpaul * media and as a part of the software program in whole or part.  Users
526219Swpaul * may copy or modify Sun RPC without charge, but are not authorized
626219Swpaul * to license or distribute it to anyone else except as part of a product or
726219Swpaul * program developed by the user or with the express written consent of
826219Swpaul * Sun Microsystems, Inc.
926219Swpaul *
1026219Swpaul * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
1126219Swpaul * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
1226219Swpaul * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
1326219Swpaul *
1426219Swpaul * Sun RPC is provided with no support and without any obligation on the
1526219Swpaul * part of Sun Microsystems, Inc. to assist in its use, correction,
1626219Swpaul * modification or enhancement.
1726219Swpaul *
1826219Swpaul * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
1926219Swpaul * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
2026219Swpaul * OR ANY PART THEREOF.
2126219Swpaul *
2226219Swpaul * In no event will Sun Microsystems, Inc. be liable for any lost revenue
2326219Swpaul * or profits or other special, indirect and consequential damages, even if
2426219Swpaul * Sun has been advised of the possibility of such damages.
2526219Swpaul *
2626219Swpaul * Sun Microsystems, Inc.
2726219Swpaul * 2550 Garcia Avenue
2826219Swpaul * Mountain View, California  94043
2926219Swpaul */
3026219Swpaul#if !defined(lint) && defined(SCCSIDS)
3126219Swpaulstatic char sccsid[] = "@(#)rpcdname.c 1.7 91/03/11 Copyr 1989 Sun Micro";
3226219Swpaul#endif
3374462Salfred/*	$FreeBSD: head/lib/libc/rpc/rpcdname.c 90271 2002-02-05 23:43:43Z alfred $ */
3426219Swpaul
3526219Swpaul/*
3626219Swpaul * rpcdname.c
3726219Swpaul * Gets the default domain name
3826219Swpaul */
3926219Swpaul
4074462Salfred#include "namespace.h"
4126219Swpaul#include <stdlib.h>
4226219Swpaul#include <unistd.h>
4326219Swpaul#include <string.h>
4474462Salfred#include "un-namespace.h"
4526219Swpaul
4626219Swpaulstatic char *default_domain = 0;
4726219Swpaul
4826219Swpaulstatic char *
4926219Swpaulget_default_domain()
5026219Swpaul{
5126219Swpaul	char temp[256];
5226219Swpaul
5326219Swpaul	if (default_domain)
5426219Swpaul		return (default_domain);
5526219Swpaul	if (getdomainname(temp, sizeof(temp)) < 0)
5626219Swpaul		return (0);
5726219Swpaul	if ((int) strlen(temp) > 0) {
5826219Swpaul		default_domain = (char *)malloc((strlen(temp)+(unsigned)1));
5926219Swpaul		if (default_domain == 0)
6026219Swpaul			return (0);
6126219Swpaul		(void) strcpy(default_domain, temp);
6226219Swpaul		return (default_domain);
6326219Swpaul	}
6426219Swpaul	return (0);
6526219Swpaul}
6626219Swpaul
6726219Swpaul/*
6826219Swpaul * This is a wrapper for the system call getdomainname which returns a
6926219Swpaul * ypclnt.h error code in the failure case.  It also checks to see that
7026219Swpaul * the domain name is non-null, knowing that the null string is going to
7126219Swpaul * get rejected elsewhere in the NIS client package.
7226219Swpaul */
7326219Swpaulint
7490271Salfred__rpc_get_default_domain(domain)
7526219Swpaul	char **domain;
7626219Swpaul{
7726219Swpaul	if ((*domain = get_default_domain()) != 0)
7826219Swpaul		return (0);
7926219Swpaul	return (-1);
8026219Swpaul}
81