ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libptytty/ptytty.m4
Revision: 1.30
Committed: Wed Nov 23 19:29:27 2011 UTC (12 years, 6 months ago) by sf-exg
Branch: MAIN
Changes since 1.29: +15 -30 lines
Log Message:
Simplify.

File Contents

# Content
1 dnl this file is part of libptytty, do not make local modifications
2 dnl http://software.schmorp.de/pkg/libptytty
3
4 AC_DEFUN([PT_FIND_FILE],
5 [AC_CACHE_CHECK(where $1 is located, pt_cv_path_$1,
6 [AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
7 #include <stdlib.h>
8 #include <sys/stat.h>
9 #include <sys/types.h>
10 #ifdef HAVE_UTMPX_H
11 #include <utmpx.h>
12 #endif
13 #ifdef HAVE_UTMP_H
14 #include <utmp.h>
15 #endif
16 #ifdef HAVE_LASTLOG_H
17 #include <lastlog.h>
18 #endif
19 int main()
20 {
21 const char **path, *list[] = { $4, NULL };
22 FILE *f = fopen("conftestval", "w");
23 if (!f) return 1;
24 #ifdef $2
25 fprintf(f, "%s\n", $2);
26 #elif defined($3)
27 fprintf(f, "%s\n", $3);
28 #else
29 for (path = list; *path; path++) {
30 struct stat st;
31 if (stat(*path, &st) == 0) {
32 fprintf(f, "%s\n", *path);
33 break;
34 }
35 }
36 #endif
37 return fclose(f) != 0;
38 }]])],[pt_cv_path_$1=`cat conftestval`],[pt_cv_path_$1=],
39 [AC_MSG_WARN(Define $2 in config.h manually)])])
40 if test x$pt_cv_path_$1 != x; then
41 AC_DEFINE_UNQUOTED($2, "$pt_cv_path_$1", Define location of $1)
42 fi])
43
44 AC_DEFUN([PTY_CHECK],
45 [
46 AC_CHECK_HEADERS( \
47 pty.h \
48 util.h \
49 libutil.h \
50 sys/ioctl.h \
51 sys/stropts.h \
52 stropts.h \
53 )
54
55 AC_CHECK_FUNCS( \
56 revoke \
57 _getpty \
58 getpt \
59 posix_openpt \
60 isastream \
61 setuid \
62 seteuid \
63 setreuid \
64 setresuid \
65 )
66
67 AC_MSG_CHECKING(for UNIX98 ptys)
68 AC_LINK_IFELSE(
69 [AC_LANG_PROGRAM(
70 [[#include <stdlib.h>]],
71 [[grantpt(0);unlockpt(0);ptsname(0);]])],
72 [unix98_pty=yes
73 AC_DEFINE(UNIX98_PTY, 1, "")
74 AC_MSG_RESULT(yes)],
75 [AC_MSG_RESULT(no)])
76
77 if test -z "$unix98_pty"; then
78 AC_SEARCH_LIBS(openpty, util, AC_DEFINE(HAVE_OPENPTY, 1, ""))
79 fi
80 ])
81
82 AC_DEFUN([UTMP_CHECK],
83 [
84 support_utmp=yes
85 support_wtmp=yes
86 support_lastlog=yes
87
88 AC_ARG_ENABLE(utmp,
89 [AS_HELP_STRING([--enable-utmp],[enable utmp (utmpx) support])],
90 [if test x$enableval = xyes -o x$enableval = xno; then
91 support_utmp=$enableval
92 fi])
93
94 AC_ARG_ENABLE(wtmp,
95 [AS_HELP_STRING([--enable-wtmp],[enable wtmp (wtmpx) support (requires --enable-utmp)])],
96 [if test x$enableval = xyes -o x$enableval = xno; then
97 support_wtmp=$enableval
98 fi])
99
100 AC_ARG_ENABLE(lastlog,
101 [AS_HELP_STRING([--enable-lastlog],[enable lastlog support (requires --enable-utmp)])],
102 [if test x$enableval = xyes -o x$enableval = xno; then
103 support_lastlog=$enableval
104 fi])
105
106 if test x$support_utmp = xyes; then
107 AC_DEFINE(UTMP_SUPPORT, 1, Define if you want to have utmp/utmpx support)
108 fi
109 if test x$support_wtmp = xyes; then
110 AC_DEFINE(WTMP_SUPPORT, 1, Define if you want to have wtmp support when utmp/utmpx is enabled)
111 fi
112 if test x$support_lastlog = xyes; then
113 AC_DEFINE(LASTLOG_SUPPORT, 1, Define if you want to have lastlog support when utmp/utmpx is enabled)
114 fi
115
116 AC_CHECK_FUNCS( \
117 updwtmp \
118 updwtmpx \
119 updlastlogx \
120 )
121
122 AC_CHECK_HEADERS(lastlog.h)
123
124 dnl# --------------------------------------------------------------------------
125 dnl# DO ALL UTMP AND WTMP CHECKING
126 dnl# --------------------------------------------------------------------------
127 dnl# check for host field in utmp structure
128
129 dnl# --------------------------------------------
130 AC_CHECK_HEADERS(utmp.h,
131 AC_CHECK_TYPES([struct utmp], [], [], [
132 #include <sys/types.h>
133 #include <utmp.h>
134 ])
135
136 AC_CHECK_MEMBER([struct utmp.ut_host],
137 [AC_DEFINE(HAVE_UTMP_HOST, 1, Define if struct utmp contains ut_host)], [], [
138 #include <sys/types.h>
139 #include <utmp.h>
140 ])
141
142 AC_CHECK_MEMBER([struct utmp.ut_pid],
143 [AC_DEFINE(HAVE_UTMP_PID, 1, Define if struct utmp contains ut_pid)], [], [
144 #include <sys/types.h>
145 #include <utmp.h>
146 ])
147 ) dnl# AC_CHECK_HEADERS(utmp.h
148
149 dnl# --------------------------------------------
150
151 AC_CHECK_HEADERS(utmpx.h,
152 AC_CHECK_TYPES([struct utmpx], [], [], [
153 #include <sys/types.h>
154 #include <utmpx.h>
155 ])
156
157 AC_CHECK_MEMBER([struct utmpx.ut_host],
158 [AC_DEFINE(HAVE_UTMPX_HOST, 1, Define if struct utmpx contains ut_host)], [], [
159 #include <sys/types.h>
160 #include <utmpx.h>
161 ])
162
163 AC_CHECK_MEMBER([struct utmpx.ut_session],
164 [AC_DEFINE(HAVE_UTMPX_SESSION, 1, Define if struct utmpx contains ut_session)], [], [
165 #include <sys/types.h>
166 #include <utmpx.h>
167 ])
168 ) dnl# AC_CHECK_HEADERS(utmpx.h
169
170 dnl# --------------------------------------------------------------------------
171 dnl# check for struct lastlog
172 AC_CHECK_TYPES([struct lastlog], [], [], [
173 #include <sys/types.h>
174 #include <utmp.h>
175 #ifdef HAVE_LASTLOG_H
176 #include <lastlog.h>
177 #endif
178 ])
179
180 dnl# check for struct lastlogx
181 AC_CHECK_TYPES([struct lastlogx], [], [], [
182 #include <sys/types.h>
183 #include <utmpx.h>
184 #ifdef HAVE_LASTLOG_H
185 #include <lastlog.h>
186 #endif
187 ])
188
189 dnl# --------------------------------------------------------------------------
190 dnl# FIND FILES
191 dnl# --------------------------------------------------------------------------
192
193 dnl# find utmp
194 PT_FIND_FILE([utmp], [UTMP_FILE], [_PATH_UTMP],
195 ["/var/run/utmp", "/var/adm/utmp", "/etc/utmp", "/usr/etc/utmp", "/usr/adm/utmp"])
196
197 dnl# --------------------------------------------------------------------------
198
199 dnl# find wtmp
200 PT_FIND_FILE([wtmp], [WTMP_FILE], [_PATH_WTMP],
201 ["/var/log/wtmp", "/var/adm/wtmp", "/etc/wtmp", "/usr/etc/wtmp", "/usr/adm/wtmp"])
202 dnl# --------------------------------------------------------------------------
203
204 dnl# find wtmpx
205 PT_FIND_FILE([wtmpx], [WTMPX_FILE], [_PATH_WTMPX],
206 ["/var/log/wtmpx", "/var/adm/wtmpx"])
207 dnl# --------------------------------------------------------------------------
208
209 dnl# find lastlog
210 PT_FIND_FILE([lastlog], [LASTLOG_FILE], [_PATH_LASTLOG],
211 ["/var/log/lastlog"])
212 dnl# --------------------------------------------------------------------------
213
214 dnl# find lastlogx
215 PT_FIND_FILE([lastlogx], [LASTLOGX_FILE], [_PATH_LASTLOGX],
216 ["/var/log/lastlogx", "/var/adm/lastlogx"])
217 ])
218
219 AC_DEFUN([SCM_RIGHTS_CHECK],
220 [
221 AC_CACHE_CHECK(for unix-compliant filehandle passing ability, pt_cv_can_pass_fds,
222 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
223 #include <cstddef> // broken bsds (is that redundant?) need this
224 #include <sys/types.h>
225 #include <sys/socket.h>
226 #include <sys/uio.h>
227 ]], [[
228 {
229 msghdr msg;
230 iovec iov;
231 char buf [100];
232 char data = 0;
233
234 iov.iov_base = &data;
235 iov.iov_len = 1;
236
237 msg.msg_iov = &iov;
238 msg.msg_iovlen = 1;
239 msg.msg_control = buf;
240 msg.msg_controllen = sizeof buf;
241
242 cmsghdr *cmsg = CMSG_FIRSTHDR (&msg);
243 cmsg->cmsg_level = SOL_SOCKET;
244 cmsg->cmsg_type = SCM_RIGHTS;
245 cmsg->cmsg_len = 100;
246
247 *(int *)CMSG_DATA (cmsg) = 5;
248
249 return sendmsg (3, &msg, 0);
250 }
251 ]])],[pt_cv_can_pass_fds=yes],[pt_cv_can_pass_fds=no])])
252 if test x$pt_cv_can_pass_fds = xyes; then
253 AC_DEFINE(HAVE_UNIX_FDPASS, 1, Define if sys/socket.h defines the necessary macros/functions for file handle passing)
254 else
255 AC_MSG_ERROR([libptytty requires unix-compliant filehandle passing ability])
256 fi
257 ])
258
259 AC_DEFUN([TTY_GROUP_CHECK],
260 [
261 AC_CACHE_CHECK([for tty group], pt_cv_tty_group,
262 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
263 #include <sys/types.h>
264 #include <sys/stat.h>
265 #include <unistd.h>
266 #include <grp.h>
267
268 int main()
269 {
270 struct stat st;
271 struct group *gr;
272 char *tty;
273 gr = getgrnam("tty");
274 tty = ttyname(0);
275 if (gr != 0
276 && tty != 0
277 && (stat(tty, &st)) == 0
278 && st.st_gid == gr->gr_gid)
279 return 0;
280 else
281 return 1;
282 }]])],[pt_cv_tty_group=yes],[pt_cv_tty_group=no],[pt_cv_tty_group=no])])
283 if test x$pt_cv_tty_group = xyes; then
284 AC_DEFINE(TTY_GID_SUPPORT, 1, "")
285 fi])
286