1258578Shrs/*- 2258578Shrs * Copyright (c) 2009, Sun Microsystems, Inc. 3258578Shrs * All rights reserved. 426219Swpaul * 5258578Shrs * Redistribution and use in source and binary forms, with or without 6258578Shrs * modification, are permitted provided that the following conditions are met: 7258578Shrs * - Redistributions of source code must retain the above copyright notice, 8258578Shrs * this list of conditions and the following disclaimer. 9258578Shrs * - Redistributions in binary form must reproduce the above copyright notice, 10258578Shrs * this list of conditions and the following disclaimer in the documentation 11258578Shrs * and/or other materials provided with the distribution. 12258578Shrs * - Neither the name of Sun Microsystems, Inc. nor the names of its 13258578Shrs * contributors may be used to endorse or promote products derived 14258578Shrs * from this software without specific prior written permission. 15258578Shrs * 16258578Shrs * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17258578Shrs * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18258578Shrs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19258578Shrs * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20258578Shrs * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21258578Shrs * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22258578Shrs * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23258578Shrs * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24258578Shrs * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25258578Shrs * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26258578Shrs * 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 46297790Spfgstatic char *default_domain; 4726219Swpaul 4826219Swpaulstatic char * 49287350Srodrigcget_default_domain(void) 5026219Swpaul{ 5126219Swpaul char temp[256]; 5226219Swpaul 53297790Spfg if (default_domain != NULL) 5426219Swpaul return (default_domain); 5526219Swpaul if (getdomainname(temp, sizeof(temp)) < 0) 5626219Swpaul return (0); 5726219Swpaul if ((int) strlen(temp) > 0) { 58297790Spfg default_domain = malloc((strlen(temp) + (unsigned)1)); 59297790Spfg if (default_domain == NULL) 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 74287341Srodrigc__rpc_get_default_domain(char **domain) 7526219Swpaul{ 76297790Spfg if ((*domain = get_default_domain()) != NULL) 7726219Swpaul return (0); 7826219Swpaul return (-1); 7926219Swpaul} 80