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