]> andersk Git - openssh.git/blob - cygwin_util.c
88748c4fb3be077e6a32cb69705db86aa6783f5b
[openssh.git] / cygwin_util.c
1 /*
2  *
3  * cygwin_util.c
4  *
5  * Author: Corinna Vinschen <vinschen@cygnus.com>
6  *
7  * Copyright (c) 2000 Corinna Vinschen <vinschen@cygnus.com>, Duisburg, Germany
8  *                    All rights reserved
9  *
10  * Created: Sat Sep 02 12:17:00 2000 cv
11  *
12  * This file contains functions for forcing opened file descriptors to
13  * binary mode on Windows systems.
14  */
15
16 #include "config.h"
17
18 #ifdef HAVE_CYGWIN
19 #include <fcntl.h>
20 #include <io.h>
21 #include <stdlib.h>
22 #include <sys/vfs.h>
23 #include <windows.h>
24 #define is_winnt       (GetVersion() < 0x80000000)
25
26 int binary_open(const char *filename, int flags, mode_t mode)
27 {
28        return open(filename, flags | O_BINARY, mode);
29 }
30
31 int binary_pipe(int fd[2])
32 {
33        int ret = pipe(fd);
34        if (!ret) {
35                setmode (fd[0], O_BINARY);
36                setmode (fd[1], O_BINARY);
37        }
38        return ret;
39 }
40
41 int check_nt_auth (int pwd_authenticated, uid_t uid)
42 {
43         /*
44          * The only authentication which is able to change the user
45          * context on NT systems is the password authentication. So
46          * we deny all requsts for changing the user context if another
47          * authentication method is used.
48          * This may change in future when a special openssh
49          * subauthentication package is available.
50          */
51         if (is_winnt && !pwd_authenticated && geteuid() != uid)
52                 return 0;
53         return 1;
54 }
55
56 int check_ntsec (const char *filename)
57 {
58         char *cygwin;
59         int allow_ntea = 0;
60         int allow_ntsec = 0;
61         struct statfs fsstat;
62
63         /* Windows 95/98/ME don't support file system security at all. */
64         if (!is_winnt)
65                 return 0;
66
67         /* Evaluate current CYGWIN settings. */
68         if ((cygwin = getenv("CYGWIN")) != NULL) {
69                 if (strstr(cygwin, "ntea") && !strstr(cygwin, "nontea"))
70                         allow_ntea = 1;
71                 if (strstr(cygwin, "ntsec") && !strstr(cygwin, "nontsec"))
72                         allow_ntsec = 1;
73         }
74
75         /*
76          * `ntea' is an emulation of POSIX attributes. It doesn't support
77          * real file level security as ntsec on NTFS file systems does
78          * but it supports FAT filesystems. `ntea' is minimum requirement
79          * for security checks.
80          */
81         if (allow_ntea)
82                 return 1;
83
84         /*
85          * Retrieve file system flags. In Cygwin, file system flags are
86          * copied to f_type which has no meaning in Win32 itself.
87          */
88         if (statfs(filename, &fsstat))
89                 return 1;
90
91         /*
92          * Only file systems supporting ACLs are able to set permissions.
93          * `ntsec' is the setting in Cygwin which switches using of NTFS
94          * ACLs to support POSIX permissions on files.
95          */
96         if (fsstat.f_type & FS_PERSISTENT_ACLS)
97                 return allow_ntsec;
98
99         return 0;
100 }
101 #endif
This page took 0.535668 seconds and 3 git commands to generate.