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, 48 insertions, 47 deletions
diff --git a/openbsd-compat/bsd-cygwin_util.c b/openbsd-compat/bsd-cygwin_util.c
index 0fa5964bc..a87cf3c97 100644
--- a/openbsd-compat/bsd-cygwin_util.c
+++ b/openbsd-compat/bsd-cygwin_util.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * cygwin_util.c
3 *
4 * Copyright (c) 2000, 2001, Corinna Vinschen <vinschen@cygnus.com> 2 * Copyright (c) 2000, 2001, Corinna Vinschen <vinschen@cygnus.com>
5 * 3 *
6 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
@@ -31,7 +29,7 @@
31 29
32#include "includes.h" 30#include "includes.h"
33 31
34RCSID("$Id: bsd-cygwin_util.c,v 1.9 2002/11/09 15:59:29 mouring Exp $"); 32RCSID("$Id: bsd-cygwin_util.c,v 1.11 2003/08/07 06:23:43 dtucker Exp $");
35 33
36#ifdef HAVE_CYGWIN 34#ifdef HAVE_CYGWIN
37 35
@@ -53,7 +51,8 @@ RCSID("$Id: bsd-cygwin_util.c,v 1.9 2002/11/09 15:59:29 mouring Exp $");
53# undef pipe 51# undef pipe
54#endif 52#endif
55 53
56int binary_open(const char *filename, int flags, ...) 54int
55binary_open(const char *filename, int flags, ...)
57{ 56{
58 va_list ap; 57 va_list ap;
59 mode_t mode; 58 mode_t mode;
@@ -61,55 +60,56 @@ int binary_open(const char *filename, int flags, ...)
61 va_start(ap, flags); 60 va_start(ap, flags);
62 mode = va_arg(ap, mode_t); 61 mode = va_arg(ap, mode_t);
63 va_end(ap); 62 va_end(ap);
64 return open(filename, flags | O_BINARY, mode); 63 return (open(filename, flags | O_BINARY, mode));
65} 64}
66 65
67int binary_pipe(int fd[2]) 66int
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 has_capability(int what) 81static int
82has_capability(int what)
82{ 83{
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. */
88 static int inited; 84 static int inited;
89 static int has_create_token; 85 static int has_create_token;
90 static int has_ntsec_by_default; 86 static int has_ntsec_by_default;
91 87
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 */
92 if (!inited) { 95 if (!inited) {
93 struct utsname uts; 96 struct utsname uts;
94 char *c; 97 char *c;
95 98
96 if (!uname(&uts)) { 99 if (!uname(&uts)) {
97 int major_high = 0; 100 int major_high = 0, major_low = 0, minor = 0;
98 int major_low = 0; 101 int api_major_version = 0, api_minor_version = 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 c = strchr(uts.release, '('); 106 if ((c = strchr(uts.release, '(')) != NULL) {
107 if (c)
108 sscanf(c + 1, "%d.%d", &api_major_version, 107 sscanf(c + 1, "%d.%d", &api_major_version,
109 &api_minor_version); 108 &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,14 +118,15 @@ static int 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 check_nt_auth(int pwd_authenticated, struct passwd *pw) 128int
129check_nt_auth(int pwd_authenticated, struct passwd *pw)
129{ 130{
130 /* 131 /*
131 * The only authentication which is able to change the user 132 * The only authentication which is able to change the user
@@ -149,34 +150,33 @@ int check_nt_auth(int pwd_authenticated, struct passwd *pw)
149 has_create_token = 0; 150 has_create_token = 0;
150 if (has_capability(HAS_CREATE_TOKEN) && 151 if (has_capability(HAS_CREATE_TOKEN) &&
151 (ntsec_on(cygwin) || 152 (ntsec_on(cygwin) ||
152 (has_capability(HAS_NTSEC_BY_DEFAULT) && 153 (has_capability(HAS_NTSEC_BY_DEFAULT) &&
153 !ntsec_off(cygwin)))) 154 !ntsec_off(cygwin))))
154 has_create_token = 1; 155 has_create_token = 1;
155 } 156 }
156 if (has_create_token < 1 && 157 if (has_create_token < 1 &&
157 !pwd_authenticated && geteuid() != pw->pw_uid) 158 !pwd_authenticated && geteuid() != pw->pw_uid)
158 return 0; 159 return (0);
159 } 160 }
160 return 1; 161 return (1);
161} 162}
162 163
163int check_ntsec(const char *filename) 164int
165check_ntsec(const char *filename)
164{ 166{
165 char *cygwin; 167 char *cygwin;
166 int allow_ntea = 0; 168 int allow_ntea = 0, allow_ntsec = 0;
167 int allow_ntsec = 0;
168 struct statfs fsstat; 169 struct statfs fsstat;
169 170
170 /* Windows 95/98/ME don't support file system security at all. */ 171 /* Windows 95/98/ME don't support file system security at all. */
171 if (!is_winnt) 172 if (!is_winnt)
172 return 0; 173 return (0);
173 174
174 /* Evaluate current CYGWIN settings. */ 175 /* Evaluate current CYGWIN settings. */
175 cygwin = getenv("CYGWIN"); 176 cygwin = getenv("CYGWIN");
176 allow_ntea = ntea_on(cygwin); 177 allow_ntea = ntea_on(cygwin);
177 allow_ntsec = ntsec_on(cygwin) || 178 allow_ntsec = ntsec_on(cygwin) ||
178 (has_capability(HAS_NTSEC_BY_DEFAULT) && 179 (has_capability(HAS_NTSEC_BY_DEFAULT) && !ntsec_off(cygwin));
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 @@ int 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,12 +200,13 @@ int 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 register_9x_service(void) 208void
209register_9x_service(void)
209{ 210{
210 HINSTANCE kerneldll; 211 HINSTANCE kerneldll;
211 DWORD (*RegisterServiceProcess)(DWORD, DWORD); 212 DWORD (*RegisterServiceProcess)(DWORD, DWORD);
@@ -219,10 +220,10 @@ void register_9x_service(void)
219 */ 220 */
220 if (is_winnt) 221 if (is_winnt)
221 return; 222 return;
222 if (! (kerneldll = LoadLibrary("KERNEL32.DLL"))) 223 if (!(kerneldll = LoadLibrary("KERNEL32.DLL")))
223 return; 224 return;
224 if (! (RegisterServiceProcess = (DWORD (*)(DWORD, DWORD)) 225 if (!(RegisterServiceProcess = (DWORD (*)(DWORD, DWORD))
225 GetProcAddress(kerneldll, "RegisterServiceProcess"))) 226 GetProcAddress(kerneldll, "RegisterServiceProcess")))
226 return; 227 return;
227 RegisterServiceProcess(0, 1); 228 RegisterServiceProcess(0, 1);
228} 229}