2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 /* $XConsortium: lutil.c /main/4 1996/11/21 20:00:35 drk $ */
26 * (c) Copyright 1993, 1994 Hewlett-Packard Company
27 * (c) Copyright 1993, 1994 International Business Machines Corp.
28 * (c) Copyright 1993, 1994 Novell, Inc.
29 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
32 #include <EUSCompat.h>
38 #if defined(sun) || defined(USL) || defined(__uxp__)
40 #include <sys/systeminfo.h>
42 #define X_INCLUDE_PWD_H
43 #define XOS_USE_XT_LOCKING
47 #include <X11/Xos_r.h>
53 extern char * strdup(const char *);
57 _DtCmGetPrefix(char *str, char sep)
66 while (*str && *str != sep)
79 static char *host = NULL;
82 host = (char *)malloc(MAXHOSTNAMELEN+1);
83 #if defined(sun) || defined(USL) || defined(__uxp__)
84 (void)sysinfo(SI_HOSTNAME, host, MAXHOSTNAMELEN);
86 (void)gethostname(host, MAXHOSTNAMELEN);
87 #endif /* sun || USL || __uxp__ */
94 _DtCmGetLocalDomain(char *hostname)
96 static char *domain = NULL;
97 char buf[BUFSIZ], *ptr;
100 if (domain == NULL) {
101 domain = (char *)malloc(BUFSIZ);
102 #if defined(sun) || defined(USL) || defined(__uxp__)
103 sysinfo(SI_SRPC_DOMAIN, domain, BUFSIZ - 1);
105 getdomainname(domain, BUFSIZ - 1);
106 #endif /* sun || USL || __uxp__ */
108 /* check domain name */
109 /* this is a hack to find out the domain name that
110 * is acceptable to the rpc interface, e.g.
111 * DGDO.Eng.Sun.COM is returned by sysinfo but
112 * this name is not acceptable to the rpc interface
113 * hence we need to stripe out the first component
116 if (hostname == NULL) hostname = _DtCmGetLocalHost();
118 sprintf(buf, "%s.%s", hostname, ptr);
119 if ((cl = clnt_create(buf, 100068, 5, "udp")) == NULL) {
120 ptr = strchr(ptr, '.');
130 if (ptr && ptr != domain)
138 _DtCmGetHostAtDomain()
140 static char *hostname = NULL;
143 if (hostname == NULL) {
144 hostname = malloc(BUFSIZ);
146 host = _DtCmGetLocalHost();
147 if (strchr(host, '.') == NULL)
148 sprintf(hostname, "%s.%s", host,
149 _DtCmGetLocalDomain(host));
151 strcpy(hostname, host);
160 static char *name = NULL;
161 _Xgetpwparams pwd_buf;
162 struct passwd * pwd_ret;
165 name = malloc(BUFSIZ);
167 if ((pwd_ret = _XGetpwuid(geteuid(), pwd_buf)) == NULL)
168 strcpy(name, "nobody");
170 strcpy(name, pwd_ret->pw_name);
177 * this routine checks whether the given name is a valid user name
180 _DtCmIsUserName(char *user)
182 _Xgetpwparams pwd_buf;
183 struct passwd * pwd_ret;
185 pwd_ret = _XGetpwnam(user, pwd_buf);