ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libptytty/ptytty.m4
Revision: 1.24
Committed: Thu May 12 14:17:56 2011 UTC (13 years ago) by sf-exg
Branch: MAIN
Changes since 1.23: +47 -148 lines
Log Message:
Factor common code to find utmp/wtmp/lastlog files into an autoconf macro.

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