summaryrefslogtreecommitdiff
path: root/openbsd-compat/bsd-cygwin_util.c
diff options
context:
space:
mode:
Diffstat (limited to 'openbsd-compat/bsd-cygwin_util.c')
-rw-r--r--openbsd-compat/bsd-cygwin_util.c95
1 files changed, 47 insertions, 48 deletions
diff --git a/openbsd-compat/bsd-cygwin_util.c b/openbsd-compat/bsd-cygwin_util.c
index a87cf3c97..0fa5964bc 100644
--- a/openbsd-compat/bsd-cygwin_util.c
+++ b/openbsd-compat/bsd-cygwin_util.c
@@ -1,4 +1,6 @@
1/* 1/*
2 * cygwin_util.c
3 *
2 * Copyright (c) 2000, 2001, Corinna Vinschen <vinschen@cygnus.com> 4 * Copyright (c) 2000, 2001, Corinna Vinschen <vinschen@cygnus.com>
3 * 5 *
4 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
@@ -29,7 +31,7 @@
29 31
30#include "includes.h" 32#include "includes.h"
31 33
32RCSID("$Id: bsd-cygwin_util.c,v 1.11 2003/08/07 06:23:43 dtucker Exp $"); 34RCSID("$Id: bsd-cygwin_util.c,v 1.9 2002/11/09 15:59:29 mouring Exp $");
33 35
34#ifdef HAVE_CYGWIN 36#ifdef HAVE_CYGWIN
35 37
@@ -51,8 +53,7 @@ RCSID("$Id: bsd-cygwin_util.c,v 1.11 2003/08/07 06:23:43 dtucker Exp $");
51# undef pipe 53# undef pipe
52#endif 54#endif
53 55
54int 56int binary_open(const char *filename, int flags, ...)
55binary_open(const char *filename, int flags, ...)
56{ 57{
57 va_list ap; 58 va_list ap;
58 mode_t mode; 59 mode_t mode;
@@ -60,56 +61,55 @@ binary_open(const char *filename, int flags, ...)
60 va_start(ap, flags); 61 va_start(ap, flags);
61 mode = va_arg(ap, mode_t); 62 mode = va_arg(ap, mode_t);
62 va_end(ap); 63 va_end(ap);
63 return (open(filename, flags | O_BINARY, mode)); 64 return open(filename, flags | O_BINARY, mode);
64} 65}
65 66
66int 67int binary_pipe(int fd[2])
67binary_pipe(int fd[2])
68{ 68{
69 int ret = pipe(fd); 69 int ret = pipe(fd);
70 70
71 if (!ret) { 71 if (!ret) {
72 setmode(fd[0], O_BINARY); 72 setmode (fd[0], O_BINARY);
73 setmode(fd[1], O_BINARY); 73 setmode (fd[1], O_BINARY);
74 } 74 }
75 return (ret); 75 return ret;
76} 76}
77 77
78#define HAS_CREATE_TOKEN 1 78#define HAS_CREATE_TOKEN 1
79#define HAS_NTSEC_BY_DEFAULT 2 79#define HAS_NTSEC_BY_DEFAULT 2
80 80
81static int 81static int has_capability(int what)
82has_capability(int what)
83{ 82{
83 /* has_capability() basically calls uname() and checks if
84 specific capabilities of Cygwin can be evaluated from that.
85 This simplifies the calling functions which only have to ask
86 for a capability using has_capability() instead of having
87 to figure that out by themselves. */
84 static int inited; 88 static int inited;
85 static int has_create_token; 89 static int has_create_token;
86 static int has_ntsec_by_default; 90 static int has_ntsec_by_default;
87 91
88 /*
89 * has_capability() basically calls uname() and checks if
90 * specific capabilities of Cygwin can be evaluated from that.
91 * This simplifies the calling functions which only have to ask
92 * for a capability using has_capability() instead of having
93 * to figure that out by themselves.
94 */
95 if (!inited) { 92 if (!inited) {
96 struct utsname uts; 93 struct utsname uts;
97 char *c; 94 char *c;
98 95
99 if (!uname(&uts)) { 96 if (!uname(&uts)) {
100 int major_high = 0, major_low = 0, minor = 0; 97 int major_high = 0;
101 int api_major_version = 0, api_minor_version = 0; 98 int major_low = 0;
99 int minor = 0;
100 int api_major_version = 0;
101 int api_minor_version = 0;
102 char *c; 102 char *c;
103 103
104 sscanf(uts.release, "%d.%d.%d", &major_high, 104 sscanf(uts.release, "%d.%d.%d", &major_high,
105 &major_low, &minor); 105 &major_low, &minor);
106 if ((c = strchr(uts.release, '(')) != NULL) { 106 c = strchr(uts.release, '(');
107 if (c)
107 sscanf(c + 1, "%d.%d", &api_major_version, 108 sscanf(c + 1, "%d.%d", &api_major_version,
108 &api_minor_version); 109 &api_minor_version);
109 }
110 if (major_high > 1 || 110 if (major_high > 1 ||
111 (major_high == 1 && (major_low > 3 || 111 (major_high == 1 && (major_low > 3 ||
112 (major_low == 3 && minor >= 2)))) 112 (major_low == 3 && minor >= 2))))
113 has_create_token = 1; 113 has_create_token = 1;
114 if (api_major_version > 0 || api_minor_version >= 56) 114 if (api_major_version > 0 || api_minor_version >= 56)
115 has_ntsec_by_default = 1; 115 has_ntsec_by_default = 1;
@@ -118,15 +118,14 @@ has_capability(int what)
118 } 118 }
119 switch (what) { 119 switch (what) {
120 case HAS_CREATE_TOKEN: 120 case HAS_CREATE_TOKEN:
121 return (has_create_token); 121 return has_create_token;
122 case HAS_NTSEC_BY_DEFAULT: 122 case HAS_NTSEC_BY_DEFAULT:
123 return (has_ntsec_by_default); 123 return has_ntsec_by_default;
124 } 124 }
125 return (0); 125 return 0;
126} 126}
127 127
128int 128int check_nt_auth(int pwd_authenticated, struct passwd *pw)
129check_nt_auth(int pwd_authenticated, struct passwd *pw)
130{ 129{
131 /* 130 /*
132 * The only authentication which is able to change the user 131 * The only authentication which is able to change the user
@@ -150,33 +149,34 @@ check_nt_auth(int pwd_authenticated, struct passwd *pw)
150 has_create_token = 0; 149 has_create_token = 0;
151 if (has_capability(HAS_CREATE_TOKEN) && 150 if (has_capability(HAS_CREATE_TOKEN) &&
152 (ntsec_on(cygwin) || 151 (ntsec_on(cygwin) ||
153 (has_capability(HAS_NTSEC_BY_DEFAULT) && 152 (has_capability(HAS_NTSEC_BY_DEFAULT) &&
154 !ntsec_off(cygwin)))) 153 !ntsec_off(cygwin))))
155 has_create_token = 1; 154 has_create_token = 1;
156 } 155 }
157 if (has_create_token < 1 && 156 if (has_create_token < 1 &&
158 !pwd_authenticated && geteuid() != pw->pw_uid) 157 !pwd_authenticated && geteuid() != pw->pw_uid)
159 return (0); 158 return 0;
160 } 159 }
161 return (1); 160 return 1;
162} 161}
163 162
164int 163int check_ntsec(const char *filename)
165check_ntsec(const char *filename)
166{ 164{
167 char *cygwin; 165 char *cygwin;
168 int allow_ntea = 0, allow_ntsec = 0; 166 int allow_ntea = 0;
167 int allow_ntsec = 0;
169 struct statfs fsstat; 168 struct statfs fsstat;
170 169
171 /* Windows 95/98/ME don't support file system security at all. */ 170 /* Windows 95/98/ME don't support file system security at all. */
172 if (!is_winnt) 171 if (!is_winnt)
173 return (0); 172 return 0;
174 173
175 /* Evaluate current CYGWIN settings. */ 174 /* Evaluate current CYGWIN settings. */
176 cygwin = getenv("CYGWIN"); 175 cygwin = getenv("CYGWIN");
177 allow_ntea = ntea_on(cygwin); 176 allow_ntea = ntea_on(cygwin);
178 allow_ntsec = ntsec_on(cygwin) || 177 allow_ntsec = ntsec_on(cygwin) ||
179 (has_capability(HAS_NTSEC_BY_DEFAULT) && !ntsec_off(cygwin)); 178 (has_capability(HAS_NTSEC_BY_DEFAULT) &&
179 !ntsec_off(cygwin));
180 180
181 /* 181 /*
182 * `ntea' is an emulation of POSIX attributes. It doesn't support 182 * `ntea' is an emulation of POSIX attributes. It doesn't support
@@ -185,14 +185,14 @@ check_ntsec(const char *filename)
185 * for security checks. 185 * for security checks.
186 */ 186 */
187 if (allow_ntea) 187 if (allow_ntea)
188 return (1); 188 return 1;
189 189
190 /* 190 /*
191 * Retrieve file system flags. In Cygwin, file system flags are 191 * Retrieve file system flags. In Cygwin, file system flags are
192 * copied to f_type which has no meaning in Win32 itself. 192 * copied to f_type which has no meaning in Win32 itself.
193 */ 193 */
194 if (statfs(filename, &fsstat)) 194 if (statfs(filename, &fsstat))
195 return (1); 195 return 1;
196 196
197 /* 197 /*
198 * Only file systems supporting ACLs are able to set permissions. 198 * Only file systems supporting ACLs are able to set permissions.
@@ -200,13 +200,12 @@ check_ntsec(const char *filename)
200 * ACLs to support POSIX permissions on files. 200 * ACLs to support POSIX permissions on files.
201 */ 201 */
202 if (fsstat.f_type & FS_PERSISTENT_ACLS) 202 if (fsstat.f_type & FS_PERSISTENT_ACLS)
203 return (allow_ntsec); 203 return allow_ntsec;
204 204
205 return (0); 205 return 0;
206} 206}
207 207
208void 208void register_9x_service(void)
209register_9x_service(void)
210{ 209{
211 HINSTANCE kerneldll; 210 HINSTANCE kerneldll;
212 DWORD (*RegisterServiceProcess)(DWORD, DWORD); 211 DWORD (*RegisterServiceProcess)(DWORD, DWORD);
@@ -220,10 +219,10 @@ register_9x_service(void)
220 */ 219 */
221 if (is_winnt) 220 if (is_winnt)
222 return; 221 return;
223 if (!(kerneldll = LoadLibrary("KERNEL32.DLL"))) 222 if (! (kerneldll = LoadLibrary("KERNEL32.DLL")))
224 return; 223 return;
225 if (!(RegisterServiceProcess = (DWORD (*)(DWORD, DWORD)) 224 if (! (RegisterServiceProcess = (DWORD (*)(DWORD, DWORD))
226 GetProcAddress(kerneldll, "RegisterServiceProcess"))) 225 GetProcAddress(kerneldll, "RegisterServiceProcess")))
227 return; 226 return;
228 RegisterServiceProcess(0, 1); 227 RegisterServiceProcess(0, 1);
229} 228}