1261046Smav/*- 2261046Smav * Copyright (c) 2009, Sun Microsystems, Inc. 3261046Smav * All rights reserved. 426219Swpaul * 5261046Smav * Redistribution and use in source and binary forms, with or without 6261046Smav * modification, are permitted provided that the following conditions are met: 7261046Smav * - Redistributions of source code must retain the above copyright notice, 8261046Smav * this list of conditions and the following disclaimer. 9261046Smav * - Redistributions in binary form must reproduce the above copyright notice, 10261046Smav * this list of conditions and the following disclaimer in the documentation 11261046Smav * and/or other materials provided with the distribution. 12261046Smav * - Neither the name of Sun Microsystems, Inc. nor the names of its 13261046Smav * contributors may be used to endorse or promote products derived 14261046Smav * from this software without specific prior written permission. 15261046Smav * 16261046Smav * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17261046Smav * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18261046Smav * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19261046Smav * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20261046Smav * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21261046Smav * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22261046Smav * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23261046Smav * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24261046Smav * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25261046Smav * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26261046Smav * POSSIBILITY OF SUCH DAMAGE. 2726219Swpaul */ 28136581Sobrien 29136581Sobrien#if defined(LIBC_SCCS) && !defined(lint) 3026219Swpaulstatic char sccsid[] = "@(#)rpcdname.c 1.7 91/03/11 Copyr 1989 Sun Micro"; 3126219Swpaul#endif 3292990Sobrien#include <sys/cdefs.h> 3392990Sobrien__FBSDID("$FreeBSD$"); 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