Imported Upstream version 1.7.4p6
[debian/sudo] / check.c
1 /*
2  * Copyright (c) 1993-1996,1998-2005, 2007-2010
3  *      Todd C. Miller <Todd.Miller@courtesan.com>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  *
17  * Sponsored in part by the Defense Advanced Research Projects
18  * Agency (DARPA) and Air Force Research Laboratory, Air Force
19  * Materiel Command, USAF, under agreement number F39502-99-1-0512.
20  */
21
22 #include <config.h>
23
24 #include <sys/types.h>
25 #include <sys/param.h>
26 #include <sys/time.h>
27 #include <sys/stat.h>
28 #ifdef __linux__
29 # include <sys/vfs.h>
30 #endif
31 #if defined(__sun) && defined(__SVR4)
32 # include <sys/statvfs.h>
33 #endif
34 #ifndef __TANDEM
35 # include <sys/file.h>
36 #endif
37 #include <stdio.h>
38 #ifdef STDC_HEADERS
39 # include <stdlib.h>
40 # include <stddef.h>
41 #else
42 # ifdef HAVE_STDLIB_H
43 #  include <stdlib.h>
44 # endif
45 #endif /* STDC_HEADERS */
46 #ifdef HAVE_STRING_H
47 # include <string.h>
48 #endif /* HAVE_STRING_H */
49 #ifdef HAVE_STRINGS_H
50 # include <strings.h>
51 #endif /* HAVE_STRINGS_H */
52 #ifdef HAVE_UNISTD_H
53 # include <unistd.h>
54 #endif /* HAVE_UNISTD_H */
55 #if TIME_WITH_SYS_TIME
56 # include <time.h>
57 #endif
58 #include <errno.h>
59 #include <fcntl.h>
60 #include <signal.h>
61 #include <pwd.h>
62 #include <grp.h>
63
64 #include "sudo.h"
65
66 /* Status codes for timestamp_status() */
67 #define TS_CURRENT              0
68 #define TS_OLD                  1
69 #define TS_MISSING              2
70 #define TS_NOFILE               3
71 #define TS_ERROR                4
72
73 /* Flags for timestamp_status() */
74 #define TS_MAKE_DIRS            1
75 #define TS_REMOVE               2
76
77 /*
78  * Info stored in tty ticket from stat(2) to help with tty matching.
79  */
80 static struct tty_info {
81     dev_t dev;                  /* ID of device tty resides on */
82     dev_t rdev;                 /* tty device ID */
83     ino_t ino;                  /* tty inode number */
84     struct timeval ctime;       /* tty inode change time */
85 } tty_info;
86
87 static void  build_timestamp    __P((char **, char **));
88 static int   timestamp_status   __P((char *, char *, char *, int));
89 static char *expand_prompt      __P((char *, char *, char *));
90 static void  lecture            __P((int));
91 static void  update_timestamp   __P((char *, char *));
92 static int   tty_is_devpts      __P((const char *));
93
94 /*
95  * This function only returns if the user can successfully
96  * verify who he/she is.
97  */
98 void
99 check_user(validated, mode)
100     int validated;
101     int mode;
102 {
103     char *timestampdir = NULL;
104     char *timestampfile = NULL;
105     char *prompt;
106     struct stat sb;
107     int status;
108
109     /* Stash the tty's ctime for tty ticket comparison. */
110     if (def_tty_tickets && user_ttypath && stat(user_ttypath, &sb) == 0) {
111         tty_info.dev = sb.st_dev;
112         tty_info.ino = sb.st_ino;
113         tty_info.rdev = sb.st_rdev;
114         if (tty_is_devpts(user_ttypath))
115             ctim_get(&sb, &tty_info.ctime);
116     }
117
118     /* Always prompt for a password when -k was specified with the command. */
119     if (ISSET(mode, MODE_INVALIDATE)) {
120         SET(validated, FLAG_CHECK_USER);
121     } else {
122         /*
123          * Don't prompt for the root passwd or if the user is exempt.
124          * If the user is not changing uid/gid, no need for a password.
125          */
126         if (user_uid == 0 || (user_uid == runas_pw->pw_uid &&
127             (!runas_gr || user_in_group(sudo_user.pw, runas_gr->gr_name))) ||
128             user_is_exempt())
129             return;
130     }
131
132     build_timestamp(&timestampdir, &timestampfile);
133     status = timestamp_status(timestampdir, timestampfile, user_name,
134         TS_MAKE_DIRS);
135
136     if (status != TS_CURRENT || ISSET(validated, FLAG_CHECK_USER)) {
137         /* Bail out if we are non-interactive and a password is required */
138         if (ISSET(mode, MODE_NONINTERACTIVE))
139             errorx(1, "sorry, a password is required to run %s", getprogname());
140
141         /* If user specified -A, make sure we have an askpass helper. */
142         if (ISSET(tgetpass_flags, TGP_ASKPASS)) {
143             if (user_askpass == NULL)
144                 log_error(NO_MAIL,
145                     "no askpass program specified, try setting SUDO_ASKPASS");
146         } else if (!ISSET(tgetpass_flags, TGP_STDIN)) {
147             /* If no tty but DISPLAY is set, use askpass if we have it. */
148             if (!user_ttypath && !tty_present()) {
149                 if (user_askpass && user_display && *user_display != '\0') {
150                     SET(tgetpass_flags, TGP_ASKPASS);
151                 } else if (!def_visiblepw) {
152                     log_error(NO_MAIL,
153                         "no tty present and no askpass program specified");
154                 }
155             }
156         }
157
158         if (!ISSET(tgetpass_flags, TGP_ASKPASS))
159             lecture(status);
160
161         /* Expand any escapes in the prompt. */
162         prompt = expand_prompt(user_prompt ? user_prompt : def_passprompt,
163             user_name, user_shost);
164
165         verify_user(auth_pw, prompt);
166     }
167     /* Only update timestamp if user was validated. */
168     if (ISSET(validated, VALIDATE_OK) && !ISSET(mode, MODE_INVALIDATE) && status != TS_ERROR)
169         update_timestamp(timestampdir, timestampfile);
170     efree(timestampdir);
171     efree(timestampfile);
172 }
173
174 /*
175  * Standard sudo lecture.
176  */
177 static void
178 lecture(status)
179     int status;
180 {
181     FILE *fp;
182     char buf[BUFSIZ];
183     ssize_t nread;
184
185     if (def_lecture == never ||
186         (def_lecture == once && status != TS_MISSING && status != TS_ERROR))
187         return;
188
189     if (def_lecture_file && (fp = fopen(def_lecture_file, "r")) != NULL) {
190         while ((nread = fread(buf, sizeof(char), sizeof(buf), fp)) != 0)
191             fwrite(buf, nread, 1, stderr);
192         fclose(fp);
193     } else {
194         (void) fputs("\n\
195 We trust you have received the usual lecture from the local System\n\
196 Administrator. It usually boils down to these three things:\n\
197 \n\
198     #1) Respect the privacy of others.\n\
199     #2) Think before you type.\n\
200     #3) With great power comes great responsibility.\n\n",
201     stderr);
202     }
203 }
204
205 /*
206  * Update the time on the timestamp file/dir or create it if necessary.
207  */
208 static void
209 update_timestamp(timestampdir, timestampfile)
210     char *timestampdir;
211     char *timestampfile;
212 {
213     /* If using tty timestamps but we have no tty there is nothing to do. */
214     if (def_tty_tickets && !user_ttypath)
215         return;
216
217     if (timestamp_uid != 0)
218         set_perms(PERM_TIMESTAMP);
219     if (timestampfile) {
220         /*
221          * Store tty info in timestamp file
222          */
223         int fd = open(timestampfile, O_WRONLY|O_CREAT, 0600);
224         if (fd == -1)
225             log_error(NO_EXIT|USE_ERRNO, "Can't open %s", timestampfile);
226         else {
227             lock_file(fd, SUDO_LOCK);
228             write(fd, &tty_info, sizeof(tty_info));
229             close(fd);
230         }
231     } else {
232         if (touch(-1, timestampdir, NULL) == -1) {
233             if (mkdir(timestampdir, 0700) == -1)
234                 log_error(NO_EXIT|USE_ERRNO, "Can't mkdir %s", timestampdir);
235         }
236     }
237     if (timestamp_uid != 0)
238         set_perms(PERM_ROOT);
239 }
240
241 /*
242  * Expand %h and %u escapes in the prompt and pass back the dynamically
243  * allocated result.  Returns the same string if there are no escapes.
244  */
245 static char *
246 expand_prompt(old_prompt, user, host)
247     char *old_prompt;
248     char *user;
249     char *host;
250 {
251     size_t len, n;
252     int subst;
253     char *p, *np, *new_prompt, *endp;
254
255     /* How much space do we need to malloc for the prompt? */
256     subst = 0;
257     for (p = old_prompt, len = strlen(old_prompt); *p; p++) {
258         if (p[0] =='%') {
259             switch (p[1]) {
260                 case 'h':
261                     p++;
262                     len += strlen(user_shost) - 2;
263                     subst = 1;
264                     break;
265                 case 'H':
266                     p++;
267                     len += strlen(user_host) - 2;
268                     subst = 1;
269                     break;
270                 case 'p':
271                     p++;
272                     if (def_rootpw)
273                             len += 2;
274                     else if (def_targetpw || def_runaspw)
275                             len += strlen(runas_pw->pw_name) - 2;
276                     else
277                             len += strlen(user_name) - 2;
278                     subst = 1;
279                     break;
280                 case 'u':
281                     p++;
282                     len += strlen(user_name) - 2;
283                     subst = 1;
284                     break;
285                 case 'U':
286                     p++;
287                     len += strlen(runas_pw->pw_name) - 2;
288                     subst = 1;
289                     break;
290                 case '%':
291                     p++;
292                     len--;
293                     subst = 1;
294                     break;
295                 default:
296                     break;
297             }
298         }
299     }
300
301     if (subst) {
302         new_prompt = (char *) emalloc(++len);
303         endp = new_prompt + len;
304         for (p = old_prompt, np = new_prompt; *p; p++) {
305             if (p[0] =='%') {
306                 switch (p[1]) {
307                     case 'h':
308                         p++;
309                         n = strlcpy(np, user_shost, np - endp);
310                         if (n >= np - endp)
311                             goto oflow;
312                         np += n;
313                         continue;
314                     case 'H':
315                         p++;
316                         n = strlcpy(np, user_host, np - endp);
317                         if (n >= np - endp)
318                             goto oflow;
319                         np += n;
320                         continue;
321                     case 'p':
322                         p++;
323                         if (def_rootpw)
324                                 n = strlcpy(np, "root", np - endp);
325                         else if (def_targetpw || def_runaspw)
326                                 n = strlcpy(np, runas_pw->pw_name, np - endp);
327                         else
328                                 n = strlcpy(np, user_name, np - endp);
329                         if (n >= np - endp)
330                                 goto oflow;
331                         np += n;
332                         continue;
333                     case 'u':
334                         p++;
335                         n = strlcpy(np, user_name, np - endp);
336                         if (n >= np - endp)
337                             goto oflow;
338                         np += n;
339                         continue;
340                     case 'U':
341                         p++;
342                         n = strlcpy(np,  runas_pw->pw_name, np - endp);
343                         if (n >= np - endp)
344                             goto oflow;
345                         np += n;
346                         continue;
347                     case '%':
348                         /* convert %% -> % */
349                         p++;
350                         break;
351                     default:
352                         /* no conversion */
353                         break;
354                 }
355             }
356             *np++ = *p;
357             if (np >= endp)
358                 goto oflow;
359         }
360         *np = '\0';
361     } else
362         new_prompt = old_prompt;
363
364     return(new_prompt);
365
366 oflow:
367     /* We pre-allocate enough space, so this should never happen. */
368     errorx(1, "internal error, expand_prompt() overflow");
369 }
370
371 /*
372  * Checks if the user is exempt from supplying a password.
373  */
374 int
375 user_is_exempt()
376 {
377     if (!def_exempt_group)
378         return(FALSE);
379     return(user_in_group(sudo_user.pw, def_exempt_group));
380 }
381
382 /*
383  * Fills in timestampdir as well as timestampfile if using tty tickets.
384  */
385 static void
386 build_timestamp(timestampdir, timestampfile)
387     char **timestampdir;
388     char **timestampfile;
389 {
390     char *dirparent;
391     int len;
392
393     dirparent = def_timestampdir;
394     len = easprintf(timestampdir, "%s/%s", dirparent, user_name);
395     if (len >= PATH_MAX)
396         log_error(0, "timestamp path too long: %s", *timestampdir);
397
398     /*
399      * Timestamp file may be a file in the directory or NUL to use
400      * the directory as the timestamp.
401      */
402     if (def_tty_tickets) {
403         char *p;
404
405         if ((p = strrchr(user_tty, '/')))
406             p++;
407         else
408             p = user_tty;
409         if (def_targetpw)
410             len = easprintf(timestampfile, "%s/%s/%s:%s", dirparent, user_name,
411                 p, runas_pw->pw_name);
412         else
413             len = easprintf(timestampfile, "%s/%s/%s", dirparent, user_name, p);
414         if (len >= PATH_MAX)
415             log_error(0, "timestamp path too long: %s", *timestampfile);
416     } else if (def_targetpw) {
417         len = easprintf(timestampfile, "%s/%s/%s", dirparent, user_name,
418             runas_pw->pw_name);
419         if (len >= PATH_MAX)
420             log_error(0, "timestamp path too long: %s", *timestampfile);
421     } else
422         *timestampfile = NULL;
423 }
424
425 /*
426  * Check the timestamp file and directory and return their status.
427  */
428 static int
429 timestamp_status(timestampdir, timestampfile, user, flags)
430     char *timestampdir;
431     char *timestampfile;
432     char *user;
433     int flags;
434 {
435     struct stat sb;
436     struct timeval boottime, mtime;
437     time_t now;
438     char *dirparent = def_timestampdir;
439     int status = TS_ERROR;              /* assume the worst */
440
441     if (timestamp_uid != 0)
442         set_perms(PERM_TIMESTAMP);
443
444     /*
445      * Sanity check dirparent and make it if it doesn't already exist.
446      * We start out assuming the worst (that the dir is not sane) and
447      * if it is ok upgrade the status to ``no timestamp file''.
448      * Note that we don't check the parent(s) of dirparent for
449      * sanity since the sudo dir is often just located in /tmp.
450      */
451     if (lstat(dirparent, &sb) == 0) {
452         if (!S_ISDIR(sb.st_mode))
453             log_error(NO_EXIT, "%s exists but is not a directory (0%o)",
454                 dirparent, (unsigned int) sb.st_mode);
455         else if (sb.st_uid != timestamp_uid)
456             log_error(NO_EXIT, "%s owned by uid %lu, should be uid %lu",
457                 dirparent, (unsigned long) sb.st_uid,
458                 (unsigned long) timestamp_uid);
459         else if ((sb.st_mode & 0000022))
460             log_error(NO_EXIT,
461                 "%s writable by non-owner (0%o), should be mode 0700",
462                 dirparent, (unsigned int) sb.st_mode);
463         else {
464             if ((sb.st_mode & 0000777) != 0700)
465                 (void) chmod(dirparent, 0700);
466             status = TS_MISSING;
467         }
468     } else if (errno != ENOENT) {
469         log_error(NO_EXIT|USE_ERRNO, "can't stat %s", dirparent);
470     } else {
471         /* No dirparent, try to make one. */
472         if (ISSET(flags, TS_MAKE_DIRS)) {
473             if (mkdir(dirparent, S_IRWXU))
474                 log_error(NO_EXIT|USE_ERRNO, "can't mkdir %s",
475                     dirparent);
476             else
477                 status = TS_MISSING;
478         }
479     }
480     if (status == TS_ERROR) {
481         if (timestamp_uid != 0)
482             set_perms(PERM_ROOT);
483         return(status);
484     }
485
486     /*
487      * Sanity check the user's ticket dir.  We start by downgrading
488      * the status to TS_ERROR.  If the ticket dir exists and is sane
489      * this will be upgraded to TS_OLD.  If the dir does not exist,
490      * it will be upgraded to TS_MISSING.
491      */
492     status = TS_ERROR;                  /* downgrade status again */
493     if (lstat(timestampdir, &sb) == 0) {
494         if (!S_ISDIR(sb.st_mode)) {
495             if (S_ISREG(sb.st_mode)) {
496                 /* convert from old style */
497                 if (unlink(timestampdir) == 0)
498                     status = TS_MISSING;
499             } else
500                 log_error(NO_EXIT, "%s exists but is not a directory (0%o)",
501                     timestampdir, (unsigned int) sb.st_mode);
502         } else if (sb.st_uid != timestamp_uid)
503             log_error(NO_EXIT, "%s owned by uid %lu, should be uid %lu",
504                 timestampdir, (unsigned long) sb.st_uid,
505                 (unsigned long) timestamp_uid);
506         else if ((sb.st_mode & 0000022))
507             log_error(NO_EXIT,
508                 "%s writable by non-owner (0%o), should be mode 0700",
509                 timestampdir, (unsigned int) sb.st_mode);
510         else {
511             if ((sb.st_mode & 0000777) != 0700)
512                 (void) chmod(timestampdir, 0700);
513             status = TS_OLD;            /* do date check later */
514         }
515     } else if (errno != ENOENT) {
516         log_error(NO_EXIT|USE_ERRNO, "can't stat %s", timestampdir);
517     } else
518         status = TS_MISSING;
519
520     /*
521      * If there is no user ticket dir, AND we are in tty ticket mode,
522      * AND the TS_MAKE_DIRS flag is set, create the user ticket dir.
523      */
524     if (status == TS_MISSING && timestampfile && ISSET(flags, TS_MAKE_DIRS)) {
525         if (mkdir(timestampdir, S_IRWXU) == -1) {
526             status = TS_ERROR;
527             log_error(NO_EXIT|USE_ERRNO, "can't mkdir %s", timestampdir);
528         }
529     }
530
531     /*
532      * Sanity check the tty ticket file if it exists.
533      */
534     if (timestampfile && status != TS_ERROR) {
535         if (status != TS_MISSING)
536             status = TS_NOFILE;                 /* dir there, file missing */
537         if (def_tty_tickets && !user_ttypath)
538             goto done;                          /* no tty, always prompt */
539         if (lstat(timestampfile, &sb) == 0) {
540             if (!S_ISREG(sb.st_mode)) {
541                 status = TS_ERROR;
542                 log_error(NO_EXIT, "%s exists but is not a regular file (0%o)",
543                     timestampfile, (unsigned int) sb.st_mode);
544             } else {
545                 /* If bad uid or file mode, complain and kill the bogus file. */
546                 if (sb.st_uid != timestamp_uid) {
547                     log_error(NO_EXIT,
548                         "%s owned by uid %lu, should be uid %lu",
549                         timestampfile, (unsigned long) sb.st_uid,
550                         (unsigned long) timestamp_uid);
551                     (void) unlink(timestampfile);
552                 } else if ((sb.st_mode & 0000022)) {
553                     log_error(NO_EXIT,
554                         "%s writable by non-owner (0%o), should be mode 0600",
555                         timestampfile, (unsigned int) sb.st_mode);
556                     (void) unlink(timestampfile);
557                 } else {
558                     /* If not mode 0600, fix it. */
559                     if ((sb.st_mode & 0000777) != 0600)
560                         (void) chmod(timestampfile, 0600);
561
562                     /*
563                      * Check for stored tty info.  If the file is zero-sized
564                      * it is an old-style timestamp with no tty info in it.
565                      * If removing, we don't care about the contents.
566                      * The actual mtime check is done later.
567                      */
568                     if (ISSET(flags, TS_REMOVE)) {
569                         status = TS_OLD;
570                     } else if (sb.st_size != 0) {
571                         struct tty_info info;
572                         int fd = open(timestampfile, O_RDONLY, 0644);
573                         if (fd != -1) {
574                             if (read(fd, &info, sizeof(info)) == sizeof(info) &&
575                                 memcmp(&info, &tty_info, sizeof(info)) == 0) {
576                                 status = TS_OLD;
577                             }
578                             close(fd);
579                         }
580                     }
581                 }
582             }
583         } else if (errno != ENOENT) {
584             log_error(NO_EXIT|USE_ERRNO, "can't stat %s", timestampfile);
585             status = TS_ERROR;
586         }
587     }
588
589     /*
590      * If the file/dir exists and we are not removing it, check its mtime.
591      */
592     if (status == TS_OLD && !ISSET(flags, TS_REMOVE)) {
593         mtim_get(&sb, &mtime);
594         /* Negative timeouts only expire manually (sudo -k). */
595         if (def_timestamp_timeout < 0 && mtime.tv_sec != 0)
596             status = TS_CURRENT;
597         else {
598             now = time(NULL);
599             if (def_timestamp_timeout &&
600                 now - mtime.tv_sec < 60 * def_timestamp_timeout) {
601                 /*
602                  * Check for bogus time on the stampfile.  The clock may
603                  * have been set back or someone could be trying to spoof us.
604                  */
605                 if (mtime.tv_sec > now + 60 * def_timestamp_timeout * 2) {
606                     time_t tv_sec = (time_t)mtime.tv_sec;
607                     log_error(NO_EXIT,
608                         "timestamp too far in the future: %20.20s",
609                         4 + ctime(&tv_sec));
610                     if (timestampfile)
611                         (void) unlink(timestampfile);
612                     else
613                         (void) rmdir(timestampdir);
614                     status = TS_MISSING;
615                 } else if (get_boottime(&boottime) && timevalcmp(&mtime, &boottime, <)) {
616                     status = TS_OLD;
617                 } else {
618                     status = TS_CURRENT;
619                 }
620             }
621         }
622     }
623
624 done:
625     if (timestamp_uid != 0)
626         set_perms(PERM_ROOT);
627     return(status);
628 }
629
630 /*
631  * Remove the timestamp ticket file/dir.
632  */
633 void
634 remove_timestamp(remove)
635     int remove;
636 {
637     struct timeval tv;
638     char *timestampdir, *timestampfile, *path;
639     int status;
640
641     build_timestamp(&timestampdir, &timestampfile);
642     status = timestamp_status(timestampdir, timestampfile, user_name,
643         TS_REMOVE);
644     if (status == TS_OLD || status == TS_CURRENT) {
645         path = timestampfile ? timestampfile : timestampdir;
646         if (remove) {
647             if (timestampfile)
648                 status = unlink(timestampfile);
649             else
650                 status = rmdir(timestampdir);
651             if (status == -1 && errno != ENOENT) {
652                 log_error(NO_EXIT, "can't remove %s (%s), will reset to Epoch",
653                     path, strerror(errno));
654                 remove = FALSE;
655             }
656         } else {
657             timevalclear(&tv);
658             if (touch(-1, path, &tv) == -1 && errno != ENOENT)
659                 error(1, "can't reset %s to Epoch", path);
660         }
661     }
662
663     efree(timestampdir);
664     efree(timestampfile);
665 }
666
667 /*
668  * Returns TRUE if tty lives on a devpts or /devices filesystem, else FALSE.
669  * Unlike most filesystems, the ctime of devpts nodes is not updated when
670  * the device node is written to, only when the inode's status changes,
671  * typically via the chmod, chown, link, rename, or utimes system calls.
672  * Since the ctime is "stable" in this case, we can stash it the tty ticket
673  * file and use it to determine whether the tty ticket file is stale.
674  */
675 static int
676 tty_is_devpts(tty)
677     const char *tty;
678 {
679     int retval = FALSE;
680 #ifdef __linux__
681     struct statfs sfs;
682
683 #ifndef DEVPTS_SUPER_MAGIC
684 # define DEVPTS_SUPER_MAGIC 0x1cd1
685 #endif
686
687     if (statfs(tty, &sfs) == 0) {
688         if (sfs.f_type == DEVPTS_SUPER_MAGIC)
689             retval = TRUE;
690     }
691 #elif defined(__sun) && defined(__SVR4)
692     struct statvfs sfs;
693
694     if (statvfs(tty, &sfs) == 0) {
695         if (strcmp(sfs.f_fstr, "devices") == 0)
696             retval = TRUE;
697     }
698 #endif /* __linux__ */
699     return retval;
700 }