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 libraries 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 <sys/param.h>
33 #include <EUSCompat.h>
41 #include <sys/systeminfo.h>
43 #define X_INCLUDE_PWD_H
44 #define XOS_USE_XT_LOCKING
48 #include <X11/Xos_r.h>
54 extern char * strdup(const char *);
58 _DtCmGetPrefix(char *str, char sep)
67 while (*str && *str != sep)
80 static char *host = NULL;
83 host = (char *)malloc(MAXHOSTNAMELEN+1);
85 (void)sysinfo(SI_HOSTNAME, host, MAXHOSTNAMELEN);
87 (void)gethostname(host, MAXHOSTNAMELEN);
95 _DtCmGetLocalDomain(char *hostname)
97 static char *domain = NULL;
98 char buf[BUFSIZ], *ptr;
101 if (domain == NULL) {
102 domain = (char *)malloc(BUFSIZ);
104 sysinfo(SI_SRPC_DOMAIN, domain, BUFSIZ - 1);
106 getdomainname(domain, BUFSIZ - 1);
109 /* check domain name */
110 /* this is a hack to find out the domain name that
111 * is acceptable to the rpc interface, e.g.
112 * DGDO.Eng.Sun.COM is returned by sysinfo but
113 * this name is not acceptable to the rpc interface
114 * hence we need to stripe out the first component
117 if (hostname == NULL) hostname = _DtCmGetLocalHost();
119 snprintf(buf, sizeof buf, "%s.%s", hostname, ptr);
120 if ((cl = clnt_create(buf, 100068, 5, "udp")) == NULL) {
121 ptr = strchr(ptr, '.');
131 if (ptr && ptr != domain)
139 _DtCmGetHostAtDomain()
141 static char *hostname = NULL;
144 if (hostname == NULL) {
145 hostname = malloc(BUFSIZ);
147 host = _DtCmGetLocalHost();
148 if (strchr(host, '.') == NULL)
149 snprintf(hostname, BUFSIZ, "%s.%s", host,
150 _DtCmGetLocalDomain(host));
152 /* XXX strcpy unsafe here */
153 strcpy(hostname, host);
162 static char *name = NULL;
163 _Xgetpwparams pwd_buf;
164 struct passwd * pwd_ret;
167 name = malloc(BUFSIZ);
169 if ((pwd_ret = _XGetpwuid(geteuid(), pwd_buf)) == NULL)
170 strcpy(name, "nobody");
172 strcpy(name, pwd_ret->pw_name);
179 * this routine checks whether the given name is a valid user name
182 _DtCmIsUserName(char *user)
184 _Xgetpwparams pwd_buf;
185 struct passwd * pwd_ret;
187 pwd_ret = _XGetpwnam(user, pwd_buf);