4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
33 #include <sys/types.h>
36 #include <sys/utsname.h>
37 #include <sys/systeminfo.h>
48 static char *look4domain(char *, char *, int);
49 static char *readdomain(char *, int);
53 * maildomain() - retrieve the domain name
59 * Retrieve the domain name from xgetenv("DOMAIN").
60 * If that is not set, look in /etc/resolv.conf, /etc/inet/named.boot
61 * and /etc/named.boot for "^domain[ ]+<domain>".
62 * If that is not set, use sysinfo(SI_SRPC_DOMAIN) from
63 * -lnsl. Otherwise, return an empty string.
66 /* read a file for the domain */
67 static char *look4domain(char *file
, char *buf
, int size
)
70 FILE *fp
= fopen(file
, "r");
75 while (fgets(buf
, size
, fp
))
76 if (strncmp(buf
, "domain", 6) == 0)
77 if (isspace(buf
[6])) {
78 char *x
= skipspace(buf
+ 6);
91 /* read the domain from the xenvironment or one of the files */
92 static char *readdomain(char *buf
, int size
)
96 if ((ret
= xgetenv("DOMAIN")) != 0) {
97 (void) strncpy(buf
, ret
, size
);
101 if (((ret
= look4domain("/etc/resolv.conf", buf
, size
)) != 0) ||
102 ((ret
= look4domain("/etc/inet/named.boot", buf
, size
)) != 0) ||
103 ((ret
= look4domain("/etc/named.boot", buf
, size
)) != 0))
107 if (sysinfo(SI_SRPC_DOMAIN
, buf
, size
) >= 0)
117 static char *domain
= 0;
118 static char dombuf
[NMLN
+1] = ".";
120 /* if we've already been here, return the info */
124 domain
= readdomain(dombuf
+1, NMLN
);
126 /* Make certain that the domain begins with a single dot */
127 /* and does not have one at the end. */
131 while (*domain
&& *domain
== '.')
134 len
= strlen(domain
);
135 while ((len
> 0) && (domain
[len
-1] == '.'))
136 domain
[--len
] = '\0';
138 /* no domain information */