summaryrefslogtreecommitdiff
path: root/other/ssharp/openbsd-compat/bsd-cygwin_util.c
diff options
context:
space:
mode:
Diffstat (limited to 'other/ssharp/openbsd-compat/bsd-cygwin_util.c')
-rw-r--r--other/ssharp/openbsd-compat/bsd-cygwin_util.c119
1 files changed, 119 insertions, 0 deletions
diff --git a/other/ssharp/openbsd-compat/bsd-cygwin_util.c b/other/ssharp/openbsd-compat/bsd-cygwin_util.c
new file mode 100644
index 0000000..e610454
--- /dev/null
+++ b/other/ssharp/openbsd-compat/bsd-cygwin_util.c
@@ -0,0 +1,119 @@
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 "includes.h"
17
18RCSID("$Id: bsd-cygwin_util.c,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $");
19
20#ifdef HAVE_CYGWIN
21
22#include <fcntl.h>
23#include <stdlib.h>
24#include <sys/vfs.h>
25#include <windows.h>
26#define is_winnt (GetVersion() < 0x80000000)
27
28#if defined(open) && open == binary_open
29# undef open
30#endif
31#if defined(pipe) && open == binary_pipe
32# undef pipe
33#endif
34
35int binary_open(const char *filename, int flags, ...)
36{
37 va_list ap;
38 mode_t mode;
39
40 va_start(ap, flags);
41 mode = va_arg(ap, mode_t);
42 va_end(ap);
43 return open(filename, flags | O_BINARY, mode);
44}
45
46int binary_pipe(int fd[2])
47{
48 int ret = pipe(fd);
49
50 if (!ret) {
51 setmode (fd[0], O_BINARY);
52 setmode (fd[1], O_BINARY);
53 }
54 return ret;
55}
56
57int check_nt_auth(int pwd_authenticated, uid_t uid)
58{
59 /*
60 * The only authentication which is able to change the user
61 * context on NT systems is the password authentication. So
62 * we deny all requsts for changing the user context if another
63 * authentication method is used.
64 * This may change in future when a special openssh
65 * subauthentication package is available.
66 */
67 if (is_winnt && !pwd_authenticated && geteuid() != uid)
68 return 0;
69
70 return 1;
71}
72
73int check_ntsec(const char *filename)
74{
75 char *cygwin;
76 int allow_ntea = 0;
77 int allow_ntsec = 0;
78 struct statfs fsstat;
79
80 /* Windows 95/98/ME don't support file system security at all. */
81 if (!is_winnt)
82 return 0;
83
84 /* Evaluate current CYGWIN settings. */
85 if ((cygwin = getenv("CYGWIN")) != NULL) {
86 if (strstr(cygwin, "ntea") && !strstr(cygwin, "nontea"))
87 allow_ntea = 1;
88 if (strstr(cygwin, "ntsec") && !strstr(cygwin, "nontsec"))
89 allow_ntsec = 1;
90 }
91
92 /*
93 * `ntea' is an emulation of POSIX attributes. It doesn't support
94 * real file level security as ntsec on NTFS file systems does
95 * but it supports FAT filesystems. `ntea' is minimum requirement
96 * for security checks.
97 */
98 if (allow_ntea)
99 return 1;
100
101 /*
102 * Retrieve file system flags. In Cygwin, file system flags are
103 * copied to f_type which has no meaning in Win32 itself.
104 */
105 if (statfs(filename, &fsstat))
106 return 1;
107
108 /*
109 * Only file systems supporting ACLs are able to set permissions.
110 * `ntsec' is the setting in Cygwin which switches using of NTFS
111 * ACLs to support POSIX permissions on files.
112 */
113 if (fsstat.f_type & FS_PERSISTENT_ACLS)
114 return allow_ntsec;
115
116 return 0;
117}
118
119#endif /* HAVE_CYGWIN */