View | Details | Raw Unified | Return to bug 2104
Collapse All | Expand All

(-)aclocal.m4 (-2 / +8 lines)
Lines 88-94 Link Here
88
      AC_MSG_RESULT($curl_cv_socklen_t_equiv)
88
      AC_MSG_RESULT($curl_cv_socklen_t_equiv)
89
      AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
89
      AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
90
			[type to use in place of socklen_t if not defined])],
90
			[type to use in place of socklen_t if not defined])],
91
      [#include <sys/types.h>
91
      [
92
#include <sys/socket.h>])
92
#include <sys/types.h>
93
#ifdef WIN32
94
# include <ws2tcpip.h>
95
#else
96
# include <sys/socket.h>
97
#endif
98
      ])
93
])
99
])
94
100
(-)addrmatch.c (-4 / +12 lines)
Lines 19-29 Link Here
19
#include "includes.h"
19
#include "includes.h"
20
20
21
#include <sys/types.h>
21
#include <sys/types.h>
22
#include <sys/socket.h>
22
#ifdef HAVE_SYS_SOCKET_H
23
#include <netinet/in.h>
23
# include <sys/socket.h>
24
#include <arpa/inet.h>
24
#endif
25
#ifdef HAVE_NETINET_IN_H
26
# include <netinet/in.h>
27
#endif
28
#ifdef HAVE_ARPA_INET_H
29
# include <arpa/inet.h>
30
#endif
25
31
26
#include <netdb.h>
32
#ifdef HAVE_NETDB_H
33
# include <netdb.h>
34
#endif
27
#include <string.h>
35
#include <string.h>
28
#include <stdlib.h>
36
#include <stdlib.h>
29
#include <stdio.h>
37
#include <stdio.h>
(-)atomicio.c (-1 / +3 lines)
Lines 29-35 Link Here
29
#include "includes.h"
29
#include "includes.h"
30
30
31
#include <sys/param.h>
31
#include <sys/param.h>
32
#include <sys/uio.h>
32
#ifdef HAVE_SYS_UIO_H
33
# include <sys/uio.h>
34
#endif
33
35
34
#include <errno.h>
36
#include <errno.h>
35
#ifdef HAVE_POLL_H
37
#ifdef HAVE_POLL_H
(-)authfd.c (-2 / +6 lines)
Lines 38-45 Link Here
38
#include "includes.h"
38
#include "includes.h"
39
39
40
#include <sys/types.h>
40
#include <sys/types.h>
41
#include <sys/un.h>
41
#ifdef HAVE_SYS_UN_H
42
#include <sys/socket.h>
42
# include <sys/un.h>
43
#endif
44
#ifdef HAVE_SYS_SOCKET_H
45
# include <sys/socket.h>
46
#endif
43
47
44
#include <openssl/evp.h>
48
#include <openssl/evp.h>
45
49
(-)authfile.c (-1 / +3 lines)
Lines 41-47 Link Here
41
#include <sys/types.h>
41
#include <sys/types.h>
42
#include <sys/stat.h>
42
#include <sys/stat.h>
43
#include <sys/param.h>
43
#include <sys/param.h>
44
#include <sys/uio.h>
44
#ifdef HAVE_SYS_UIO_H
45
# include <sys/uio.h>
46
#endif
45
47
46
#include <openssl/err.h>
48
#include <openssl/err.h>
47
#include <openssl/evp.h>
49
#include <openssl/evp.h>
(-)canohost.c (-4 / +12 lines)
Lines 15-28 Link Here
15
#include "includes.h"
15
#include "includes.h"
16
16
17
#include <sys/types.h>
17
#include <sys/types.h>
18
#include <sys/socket.h>
18
#ifdef HAVE_SYS_SOCKET_H
19
# include <sys/socket.h>
20
#endif
19
21
20
#include <netinet/in.h>
22
#ifdef HAVE_NETINET_IN_H
21
#include <arpa/inet.h>
23
# include <netinet/in.h>
24
#endif
25
#ifdef HAVE_ARPA_INET_H
26
# include <arpa/inet.h>
27
#endif
22
28
23
#include <ctype.h>
29
#include <ctype.h>
24
#include <errno.h>
30
#include <errno.h>
25
#include <netdb.h>
31
#ifdef HAVE_NETDB_H
32
# include <netdb.h>
33
#endif
26
#include <stdio.h>
34
#include <stdio.h>
27
#include <stdlib.h>
35
#include <stdlib.h>
28
#include <string.h>
36
#include <string.h>
(-)channels.c (-7 / +32 lines)
Lines 42-64 Link Here
42
#include "includes.h"
42
#include "includes.h"
43
43
44
#include <sys/types.h>
44
#include <sys/types.h>
45
#include <sys/ioctl.h>
45
#ifdef HAVE_SYS_IOCTL_H
46
#include <sys/un.h>
46
# include <sys/ioctl.h>
47
#include <sys/socket.h>
47
#endif
48
#ifdef HAVE_SYS_UN_H
49
# include <sys/un.h>
50
#endif
51
#ifdef HAVE_SYS_SOCKET_H
52
# include <sys/socket.h>
53
#endif
48
#ifdef HAVE_SYS_TIME_H
54
#ifdef HAVE_SYS_TIME_H
49
# include <sys/time.h>
55
# include <sys/time.h>
50
#endif
56
#endif
51
57
52
#include <netinet/in.h>
58
#ifdef HAVE_NETINET_IN_H
53
#include <arpa/inet.h>
59
# include <netinet/in.h>
60
#endif
61
#ifdef HAVE_ARPA_INET_H
62
# include <arpa/inet.h>
63
#endif
54
64
55
#include <errno.h>
65
#include <errno.h>
56
#include <fcntl.h>
66
#include <fcntl.h>
57
#include <netdb.h>
67
#ifdef HAVE_NETDB_H
68
# include <netdb.h>
69
#endif
58
#include <stdio.h>
70
#include <stdio.h>
59
#include <stdlib.h>
71
#include <stdlib.h>
60
#include <string.h>
72
#include <string.h>
61
#include <termios.h>
73
#ifdef HAVE_TERMIOS_H
74
# include <termios.h>
75
#endif
62
#include <unistd.h>
76
#include <unistd.h>
63
#include <stdarg.h>
77
#include <stdarg.h>
64
78
Lines 2142-2147 Link Here
2142
channel_prepare_select(fd_set **readsetp, fd_set **writesetp, int *maxfdp,
2156
channel_prepare_select(fd_set **readsetp, fd_set **writesetp, int *maxfdp,
2143
    u_int *nallocp, time_t *minwait_secs, int rekeying)
2157
    u_int *nallocp, time_t *minwait_secs, int rekeying)
2144
{
2158
{
2159
#ifdef NFDBITS
2145
	u_int n, sz, nfdset;
2160
	u_int n, sz, nfdset;
2146
2161
2147
	n = MAX(*maxfdp, channel_max_fd);
2162
	n = MAX(*maxfdp, channel_max_fd);
Lines 2161-2166 Link Here
2161
	*maxfdp = n;
2176
	*maxfdp = n;
2162
	memset(*readsetp, 0, sz);
2177
	memset(*readsetp, 0, sz);
2163
	memset(*writesetp, 0, sz);
2178
	memset(*writesetp, 0, sz);
2179
#else
2180
	if (*readsetp == NULL)
2181
		*readsetp = xmalloc(sizeof(fd_set));
2182
	if (*writesetp == NULL)
2183
		*writesetp = xmalloc(sizeof(fd_set));
2184
	*maxfdp = MAX(*maxfdp, channel_max_fd);
2185
	*nallocp = sizeof(fd_set);
2186
	memset(*readsetp, 0, sizeof(fd_set));
2187
	memset(*writesetp, 0, sizeof(fd_set));
2188
#endif
2164
2189
2165
	if (!rekeying)
2190
	if (!rekeying)
2166
		channel_handler(channel_pre, *readsetp, *writesetp,
2191
		channel_handler(channel_pre, *readsetp, *writesetp,
(-)clientloop.c (-4 / +12 lines)
Lines 62-68 Link Here
62
#include "includes.h"
62
#include "includes.h"
63
63
64
#include <sys/types.h>
64
#include <sys/types.h>
65
#include <sys/ioctl.h>
65
#ifdef HAVE_SYS_IOCTL_H
66
# include <sys/ioctl.h>
67
#endif
66
#include <sys/param.h>
68
#include <sys/param.h>
67
#ifdef HAVE_SYS_STAT_H
69
#ifdef HAVE_SYS_STAT_H
68
# include <sys/stat.h>
70
# include <sys/stat.h>
Lines 70-76 Link Here
70
#ifdef HAVE_SYS_TIME_H
72
#ifdef HAVE_SYS_TIME_H
71
# include <sys/time.h>
73
# include <sys/time.h>
72
#endif
74
#endif
73
#include <sys/socket.h>
75
#ifdef HAVE_SYS_SOCKET_H
76
# include <sys/socket.h>
77
#endif
74
78
75
#include <ctype.h>
79
#include <ctype.h>
76
#include <errno.h>
80
#include <errno.h>
Lines 82-89 Link Here
82
#include <stdio.h>
86
#include <stdio.h>
83
#include <stdlib.h>
87
#include <stdlib.h>
84
#include <string.h>
88
#include <string.h>
85
#include <termios.h>
89
#ifdef HAVE_TERMIOS_H
86
#include <pwd.h>
90
# include <termios.h>
91
#endif
92
#ifdef HAVE_PWD_H
93
# include <pwd.h>
94
#endif
87
#include <unistd.h>
95
#include <unistd.h>
88
96
89
#include "openbsd-compat/sys-queue.h"
97
#include "openbsd-compat/sys-queue.h"
(-)clientloop.h (-1 / +3 lines)
Lines 35-41 Link Here
35
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
 */
36
 */
37
37
38
#include <termios.h>
38
#ifdef HAVE_TERMIOS_H
39
# include <termios.h>
40
#endif
39
41
40
/* Client side main loop for the interactive session. */
42
/* Client side main loop for the interactive session. */
41
int	 client_loop(int, int, int);
43
int	 client_loop(int, int, int);
(-)configure.ac (-7 / +72 lines)
Lines 296-301 Link Here
296
)
296
)
297
297
298
AC_CHECK_HEADERS([ \
298
AC_CHECK_HEADERS([ \
299
	arpa/inet.h \
300
	arpa/nameser.h \
299
	bstring.h \
301
	bstring.h \
300
	crypt.h \
302
	crypt.h \
301
	crypto/sha2.h \
303
	crypto/sha2.h \
Lines 307-312 Link Here
307
	floatingpoint.h \
309
	floatingpoint.h \
308
	getopt.h \
310
	getopt.h \
309
	glob.h \
311
	glob.h \
312
	grp.h \
310
	ia.h \
313
	ia.h \
311
	iaf.h \
314
	iaf.h \
312
	limits.h \
315
	limits.h \
Lines 314-325 Link Here
314
	maillock.h \
317
	maillock.h \
315
	ndir.h \
318
	ndir.h \
316
	net/if_tun.h \
319
	net/if_tun.h \
320
	netinet/in.h \
321
	netinet/in_systm.h \
322
	netinet/tcp.h \
317
	netdb.h \
323
	netdb.h \
318
	netgroup.h \
324
	netgroup.h \
319
	pam/pam_appl.h \
325
	pam/pam_appl.h \
320
	paths.h \
326
	paths.h \
321
	poll.h \
327
	poll.h \
322
	pty.h \
328
	pty.h \
329
	pwd.h \
323
	readpassphrase.h \
330
	readpassphrase.h \
324
	rpc/types.h \
331
	rpc/types.h \
325
	security/pam_appl.h \
332
	security/pam_appl.h \
Lines 334-345 Link Here
334
	sys/bsdtty.h \
341
	sys/bsdtty.h \
335
	sys/cdefs.h \
342
	sys/cdefs.h \
336
	sys/dir.h \
343
	sys/dir.h \
344
	sys/ioctl.h \
337
	sys/mman.h \
345
	sys/mman.h \
338
	sys/ndir.h \
346
	sys/ndir.h \
339
	sys/poll.h \
347
	sys/poll.h \
340
	sys/prctl.h \
348
	sys/prctl.h \
341
	sys/pstat.h \
349
	sys/pstat.h \
350
	sys/resource.h \
342
	sys/select.h \
351
	sys/select.h \
352
	sys/socket.h \
343
	sys/stat.h \
353
	sys/stat.h \
344
	sys/stream.h \
354
	sys/stream.h \
345
	sys/stropts.h \
355
	sys/stropts.h \
Lines 348-354 Link Here
348
	sys/sysmacros.h \
358
	sys/sysmacros.h \
349
	sys/time.h \
359
	sys/time.h \
350
	sys/timers.h \
360
	sys/timers.h \
361
	sys/uio.h \
351
	sys/un.h \
362
	sys/un.h \
363
	sys/wait.h \
364
	syslog.h \
365
	termios.h \
352
	time.h \
366
	time.h \
353
	tmpdir.h \
367
	tmpdir.h \
354
	ttyent.h \
368
	ttyent.h \
Lines 505-510 Link Here
505
	AC_DEFINE([SSH_IOBUFSZ], [65535], [Windows is sensitive to read buffer size])
519
	AC_DEFINE([SSH_IOBUFSZ], [65535], [Windows is sensitive to read buffer size])
506
	AC_DEFINE([FILESYSTEM_NO_BACKSLASH], [1], [File names may not contain backslash characters]) 
520
	AC_DEFINE([FILESYSTEM_NO_BACKSLASH], [1], [File names may not contain backslash characters]) 
507
	;;
521
	;;
522
*-*-mingw32*)
523
	LIBS="$LIBS -lws2_32 -lntdll -lsecur32"
524
	# These are stdcall, which makes AC_CHECK_FUNCS fail
525
	AC_DEFINE([HAVE_FREEADDRINFO])
526
	AC_DEFINE([HAVE_GAI_STRERROR])
527
	AC_DEFINE([HAVE_GETADDRINFO])
528
	AC_DEFINE([HAVE_GETNAMEINFO])
529
	AC_DEFINE([HAVE_INET_NTOA])
530
	# Not really broken, but disabled and prints an error
531
	AC_DEFINE([IP_TOS_IS_BROKEN])
532
	;;
508
*-*-dgux*)
533
*-*-dgux*)
509
	AC_DEFINE([IP_TOS_IS_BROKEN], [1],
534
	AC_DEFINE([IP_TOS_IS_BROKEN], [1],
510
		[Define if your system choked on IP TOS setting])
535
		[Define if your system choked on IP TOS setting])
Lines 1395-1400 Link Here
1395
#include <stdio.h>
1420
#include <stdio.h>
1396
#include <stdlib.h>
1421
#include <stdlib.h>
1397
#include <stdint.h>
1422
#include <stdint.h>
1423
#ifdef WIN32
1424
# include <ws2tcpip.h>
1425
#endif
1398
#include <ldns/ldns.h>
1426
#include <ldns/ldns.h>
1399
int main() { ldns_status status = ldns_verify_trusted(NULL, NULL, NULL, NULL); status=LDNS_STATUS_OK; exit(0); }
1427
int main() { ldns_status status = ldns_verify_trusted(NULL, NULL, NULL, NULL); status=LDNS_STATUS_OK; exit(0); }
1400
                                ]])
1428
                                ]])
Lines 3171-3177 Link Here
3171
AC_CACHE_CHECK([for struct sockaddr_storage], ac_cv_have_struct_sockaddr_storage, [
3199
AC_CACHE_CHECK([for struct sockaddr_storage], ac_cv_have_struct_sockaddr_storage, [
3172
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3200
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3173
#include <sys/types.h>
3201
#include <sys/types.h>
3174
#include <sys/socket.h>
3202
#ifdef HAVE_SYS_SOCKET_H
3203
# include <sys/socket.h>
3204
#endif
3205
#ifdef WIN32
3206
# include <winsock2.h>
3207
#endif
3175
		]], [[ struct sockaddr_storage s; ]])],
3208
		]], [[ struct sockaddr_storage s; ]])],
3176
	[ ac_cv_have_struct_sockaddr_storage="yes" ],
3209
	[ ac_cv_have_struct_sockaddr_storage="yes" ],
3177
	[ ac_cv_have_struct_sockaddr_storage="no" 
3210
	[ ac_cv_have_struct_sockaddr_storage="no" 
Lines 3185-3191 Link Here
3185
AC_CACHE_CHECK([for struct sockaddr_in6], ac_cv_have_struct_sockaddr_in6, [
3218
AC_CACHE_CHECK([for struct sockaddr_in6], ac_cv_have_struct_sockaddr_in6, [
3186
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3219
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3187
#include <sys/types.h>
3220
#include <sys/types.h>
3188
#include <netinet/in.h>
3221
#ifdef HAVE_NETINET_IN_H
3222
# include <netinet/in.h>
3223
#endif
3224
#ifdef WIN32
3225
# include <ws2tcpip.h>
3226
#endif
3189
		]], [[ struct sockaddr_in6 s; s.sin6_family = 0; ]])],
3227
		]], [[ struct sockaddr_in6 s; s.sin6_family = 0; ]])],
3190
	[ ac_cv_have_struct_sockaddr_in6="yes" ],
3228
	[ ac_cv_have_struct_sockaddr_in6="yes" ],
3191
	[ ac_cv_have_struct_sockaddr_in6="no" 
3229
	[ ac_cv_have_struct_sockaddr_in6="no" 
Lines 3199-3205 Link Here
3199
AC_CACHE_CHECK([for struct in6_addr], ac_cv_have_struct_in6_addr, [
3237
AC_CACHE_CHECK([for struct in6_addr], ac_cv_have_struct_in6_addr, [
3200
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3238
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3201
#include <sys/types.h>
3239
#include <sys/types.h>
3202
#include <netinet/in.h>
3240
#ifdef HAVE_NETINET_IN_H
3241
# include <netinet/in.h>
3242
#endif
3243
#ifdef WIN32
3244
# include <ws2tcpip.h>
3245
#endif
3203
		]], [[ struct in6_addr s; s.s6_addr[0] = 0; ]])],
3246
		]], [[ struct in6_addr s; s.s6_addr[0] = 0; ]])],
3204
	[ ac_cv_have_struct_in6_addr="yes" ],
3247
	[ ac_cv_have_struct_in6_addr="yes" ],
3205
	[ ac_cv_have_struct_in6_addr="no" 
3248
	[ ac_cv_have_struct_in6_addr="no" 
Lines 3215-3229 Link Here
3215
#ifdef HAVE_SYS_TYPES_H
3258
#ifdef HAVE_SYS_TYPES_H
3216
#include <sys/types.h>
3259
#include <sys/types.h>
3217
#endif
3260
#endif
3218
#include <netinet/in.h>
3261
#ifdef HAVE_NETINET_IN_H
3262
# include <netinet/in.h>
3263
#endif
3264
#ifdef WIN32
3265
# include <ws2tcpip.h>
3266
#endif
3219
		])
3267
		])
3220
fi
3268
fi
3221
3269
3222
AC_CACHE_CHECK([for struct addrinfo], ac_cv_have_struct_addrinfo, [
3270
AC_CACHE_CHECK([for struct addrinfo], ac_cv_have_struct_addrinfo, [
3223
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3271
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3224
#include <sys/types.h>
3272
#include <sys/types.h>
3225
#include <sys/socket.h>
3273
#ifdef HAVE_SYS_SOCKET_H
3226
#include <netdb.h>
3274
# include <sys/socket.h>
3275
#endif
3276
#ifdef HAVE_NETDB_H
3277
# include <netdb.h>
3278
#endif
3279
#ifdef WIN32
3280
# include <ws2tcpip.h>
3281
#endif
3227
		]], [[ struct addrinfo s; s.ai_flags = AI_PASSIVE; ]])],
3282
		]], [[ struct addrinfo s; s.ai_flags = AI_PASSIVE; ]])],
3228
	[ ac_cv_have_struct_addrinfo="yes" ],
3283
	[ ac_cv_have_struct_addrinfo="yes" ],
3229
	[ ac_cv_have_struct_addrinfo="no" 
3284
	[ ac_cv_have_struct_addrinfo="no" 
Lines 3638-3644 Link Here
3638
			KRB5ROOT=${withval}
3693
			KRB5ROOT=${withval}
3639
		fi
3694
		fi
3640
3695
3641
		AC_DEFINE([KRB5], [1], [Define if you want Kerberos 5 support])
3696
		case "$host" in
3697
		*-*-mingw32*)
3698
			# Windows has libraries for emulating GSSAPI,
3699
			# but not direct Kerberos 5.
3700
			AC_DEFINE([GSSAPI])
3701
			;;
3702
		*)
3703
			AC_DEFINE([KRB5], [1], [Define if you want Kerberos 5 support])
3704
			;;
3705
		esac
3706
3642
		KRB5_MSG="yes"
3707
		KRB5_MSG="yes"
3643
3708
3644
		AC_PATH_PROG([KRB5CONF], [krb5-config],
3709
		AC_PATH_PROG([KRB5CONF], [krb5-config],
(-)defines.h (-3 / +20 lines)
Lines 45-52 Link Here
45
/*
45
/*
46
 * Definitions for IP type of service (ip_tos)
46
 * Definitions for IP type of service (ip_tos)
47
 */
47
 */
48
#include <netinet/in_systm.h>
48
#ifdef HAVE_NETINET_IN_SYSTM_H
49
#include <netinet/ip.h>
49
# include <netinet/in_systm.h>
50
#endif
51
#ifdef HAVE_NETINET_IP_H
52
# include <netinet/ip.h>
53
#endif
50
#ifndef IPTOS_LOWDELAY
54
#ifndef IPTOS_LOWDELAY
51
# define IPTOS_LOWDELAY          0x10
55
# define IPTOS_LOWDELAY          0x10
52
# define IPTOS_THROUGHPUT        0x08
56
# define IPTOS_THROUGHPUT        0x08
Lines 143-149 Link Here
143
# define S_ISREG(mode)	(((mode) & (_S_IFMT)) == (_S_IFREG))
147
# define S_ISREG(mode)	(((mode) & (_S_IFMT)) == (_S_IFREG))
144
#endif /* S_ISREG */
148
#endif /* S_ISREG */
145
149
146
#ifndef S_ISLNK
150
#if !defined(S_ISLNK) && defined(S_IFLNK)
147
# define S_ISLNK(mode)	(((mode) & S_IFMT) == S_IFLNK)
151
# define S_ISLNK(mode)	(((mode) & S_IFMT) == S_IFLNK)
148
#endif /* S_ISLNK */
152
#endif /* S_ISLNK */
149
153
Lines 184-189 Link Here
184
#define INADDR_LOOPBACK ((u_long)0x7f000001)
188
#define INADDR_LOOPBACK ((u_long)0x7f000001)
185
#endif
189
#endif
186
190
191
#ifndef IN_LOOPBACKNET
192
#define IN_LOOPBACKNET 127
193
#endif
194
187
/* Types */
195
/* Types */
188
196
189
/* If sys/types.h does not supply intXX_t, supply them ourselves */
197
/* If sys/types.h does not supply intXX_t, supply them ourselves */
Lines 524-529 Link Here
524
532
525
#if defined(HAVE_DECL_OFFSETOF) && HAVE_DECL_OFFSETOF == 0
533
#if defined(HAVE_DECL_OFFSETOF) && HAVE_DECL_OFFSETOF == 0
526
# define offsetof(type, member) ((size_t) &((type *)0)->member)
534
# define offsetof(type, member) ((size_t) &((type *)0)->member)
535
#endif
536
537
#ifndef FD_SET_SIZE
538
# ifdef NFDBITS
539
#  define FD_SET_SIZE(maxfd) \
540
	(howmany(maxfd + 1 , NFDBITS) * sizeof(fd_mask))
541
# else
542
#  define FD_SET_SIZE(maxfd) sizeof(fd_set)
543
# endif
527
#endif
544
#endif
528
545
529
/* Set up BSD-style BYTE_ORDER definition if it isn't there already */
546
/* Set up BSD-style BYTE_ORDER definition if it isn't there already */
(-)dns.c (-2 / +6 lines)
Lines 28-36 Link Here
28
#include "includes.h"
28
#include "includes.h"
29
29
30
#include <sys/types.h>
30
#include <sys/types.h>
31
#include <sys/socket.h>
31
#ifdef HAVE_SYS_SOCKET_H
32
# include <sys/socket.h>
33
#endif
32
34
33
#include <netdb.h>
35
#ifdef HAVE_NETDB_H
36
# include <netdb.h>
37
#endif
34
#include <stdarg.h>
38
#include <stdarg.h>
35
#include <stdio.h>
39
#include <stdio.h>
36
#include <string.h>
40
#include <string.h>
(-)entropy.c (-3 / +9 lines)
Lines 25-37 Link Here
25
#include "includes.h"
25
#include "includes.h"
26
26
27
#include <sys/types.h>
27
#include <sys/types.h>
28
#include <sys/socket.h>
28
#ifdef HAVE_SYS_SOCKET_H
29
# include <sys/socket.h>
30
#endif
29
#ifdef HAVE_SYS_UN_H
31
#ifdef HAVE_SYS_UN_H
30
# include <sys/un.h>
32
# include <sys/un.h>
31
#endif
33
#endif
32
34
33
#include <netinet/in.h>
35
#ifdef HAVE_NETINET_IN_H
34
#include <arpa/inet.h>
36
# include <netinet/in.h>
37
#endif
38
#ifdef HAVE_ARPA_INET_H
39
# include <arpa/inet.h>
40
#endif
35
41
36
#include <errno.h>
42
#include <errno.h>
37
#include <signal.h>
43
#include <signal.h>
(-)gss-genr.c (+1 lines)
Lines 34-39 Link Here
34
#include <stdarg.h>
34
#include <stdarg.h>
35
#include <string.h>
35
#include <string.h>
36
#include <unistd.h>
36
#include <unistd.h>
37
#include <stdio.h>
37
38
38
#include "xmalloc.h"
39
#include "xmalloc.h"
39
#include "buffer.h"
40
#include "buffer.h"
(-)hostfile.c (-2 / +6 lines)
Lines 40-51 Link Here
40
40
41
#include <sys/types.h>
41
#include <sys/types.h>
42
42
43
#include <netinet/in.h>
43
#ifdef HAVE_NETINET_IN_H
44
# include <netinet/in.h>
45
#endif
44
46
45
#include <openssl/hmac.h>
47
#include <openssl/hmac.h>
46
#include <openssl/sha.h>
48
#include <openssl/sha.h>
47
49
48
#include <resolv.h>
50
#ifdef HAVE_RESOLV_H
51
# include <resolv.h>
52
#endif
49
#include <stdarg.h>
53
#include <stdarg.h>
50
#include <stdio.h>
54
#include <stdio.h>
51
#include <stdlib.h>
55
#include <stdlib.h>
(-)includes.h (-4 / +21 lines)
Lines 22-29 Link Here
22
#define _GNU_SOURCE /* activate extra prototypes for glibc */
22
#define _GNU_SOURCE /* activate extra prototypes for glibc */
23
#endif
23
#endif
24
24
25
#ifdef WIN32
26
# define WIN32_LEAN_AND_MEAN
27
# define _WIN32_WINNT 0x0501
28
# define _WIN32_IE 0x0600
29
# include <winsock2.h>
30
# include <ws2tcpip.h>
31
# include <windows.h>
32
#endif
33
25
#include <sys/types.h>
34
#include <sys/types.h>
26
#include <sys/socket.h> /* For CMSG_* */
35
#ifdef HAVE_SOCKET_H
36
# include <sys/socket.h> /* For CMSG_* */
37
#endif
27
38
28
#ifdef HAVE_LIMITS_H
39
#ifdef HAVE_LIMITS_H
29
# include <limits.h> /* For PATH_MAX */
40
# include <limits.h> /* For PATH_MAX */
Lines 85-91 Link Here
85
#ifdef HAVE_STDINT_H
96
#ifdef HAVE_STDINT_H
86
# include <stdint.h>
97
# include <stdint.h>
87
#endif
98
#endif
88
#include <termios.h>
99
#ifdef HAVE_TERMIOS_H
100
# include <termios.h>
101
#endif
89
#ifdef HAVE_SYS_BITYPES_H
102
#ifdef HAVE_SYS_BITYPES_H
90
# include <sys/bitypes.h> /* For u_intXX_t */
103
# include <sys/bitypes.h> /* For u_intXX_t */
91
#endif
104
#endif
Lines 111-118 Link Here
111
#include <sys/ptms.h>	/* for grantpt() and friends */
124
#include <sys/ptms.h>	/* for grantpt() and friends */
112
#endif
125
#endif
113
126
114
#include <netinet/in.h>
127
#ifdef HAVE_NETINET_IN_H
115
#include <netinet/in_systm.h> /* For typedefs */
128
# include <netinet/in.h>
129
#endif
130
#ifdef HAVE_NETINET_IN_SYSTM_H
131
# include <netinet/in_systm.h> /* For typedefs */
132
#endif
116
#ifdef HAVE_RPC_TYPES_H
133
#ifdef HAVE_RPC_TYPES_H
117
# include <rpc/types.h> /* For INADDR_LOOPBACK */
134
# include <rpc/types.h> /* For INADDR_LOOPBACK */
118
#endif
135
#endif
(-)log.c (-1 / +3 lines)
Lines 43-49 Link Here
43
#include <stdio.h>
43
#include <stdio.h>
44
#include <stdlib.h>
44
#include <stdlib.h>
45
#include <string.h>
45
#include <string.h>
46
#include <syslog.h>
46
#ifdef HAVE_SYSLOG_H
47
# include <syslog.h>
48
#endif
47
#include <unistd.h>
49
#include <unistd.h>
48
#include <errno.h>
50
#include <errno.h>
49
#if defined(HAVE_STRNVIS) && defined(HAVE_VIS_H) && !defined(BROKEN_STRNVIS)
51
#if defined(HAVE_STRNVIS) && defined(HAVE_VIS_H) && !defined(BROKEN_STRNVIS)
(-)misc.c (-7 / +21 lines)
Lines 27-34 Link Here
27
#include "includes.h"
27
#include "includes.h"
28
28
29
#include <sys/types.h>
29
#include <sys/types.h>
30
#include <sys/ioctl.h>
30
#ifdef HAVE_SYS_IOCTL_H
31
#include <sys/socket.h>
31
# include <sys/ioctl.h>
32
#endif
33
#ifdef HAVE_SYS_SOCKET_H
34
# include <sys/socket.h>
35
#endif
32
#include <sys/param.h>
36
#include <sys/param.h>
33
37
34
#include <stdarg.h>
38
#include <stdarg.h>
Lines 38-51 Link Here
38
#include <time.h>
42
#include <time.h>
39
#include <unistd.h>
43
#include <unistd.h>
40
44
41
#include <netinet/in.h>
45
#ifdef HAVE_NETINET_IN_H
42
#include <netinet/in_systm.h>
46
# include <netinet/in.h>
43
#include <netinet/ip.h>
47
#endif
44
#include <netinet/tcp.h>
48
#ifdef HAVE_NETINET_IN_SYSTM_H
49
# include <netinet/in_systm.h>
50
#endif
51
#ifdef HAVE_NETINET_IP_H
52
# include <netinet/ip.h>
53
#endif
54
#ifdef HAVE_NETINET_TCP_H
55
# include <netinet/tcp.h>
56
#endif
45
57
46
#include <errno.h>
58
#include <errno.h>
47
#include <fcntl.h>
59
#include <fcntl.h>
48
#include <netdb.h>
60
#ifdef HAVE_NETDB_H
61
# include <netdb.h>
62
#endif
49
#ifdef HAVE_PATHS_H
63
#ifdef HAVE_PATHS_H
50
# include <paths.h>
64
# include <paths.h>
51
#include <pwd.h>
65
#include <pwd.h>
(-)monitor_fdpass.c (-2 / +6 lines)
Lines 27-34 Link Here
27
#include "includes.h"
27
#include "includes.h"
28
28
29
#include <sys/types.h>
29
#include <sys/types.h>
30
#include <sys/socket.h>
30
#ifdef HAVE_SYS_SOCKET_H
31
#include <sys/uio.h>
31
# include <sys/socket.h>
32
#endif
33
#ifdef HAVE_SYS_UIO_H
34
# include <sys/uio.h>
35
#endif
32
#ifdef HAVE_SYS_UN_H
36
#ifdef HAVE_SYS_UN_H
33
#include <sys/un.h>
37
#include <sys/un.h>
34
#endif
38
#endif
(-)msg.c (-1 / +3 lines)
Lines 26-32 Link Here
26
#include "includes.h"
26
#include "includes.h"
27
27
28
#include <sys/types.h>
28
#include <sys/types.h>
29
#include <sys/uio.h>
29
#ifdef HAVE_SYS_UIO_H
30
# include <sys/uio.h>
31
#endif
30
32
31
#include <errno.h>
33
#include <errno.h>
32
#include <stdio.h>
34
#include <stdio.h>
(-)mux.c (-2 / +6 lines)
Lines 35-42 Link Here
35
#include <sys/types.h>
35
#include <sys/types.h>
36
#include <sys/param.h>
36
#include <sys/param.h>
37
#include <sys/stat.h>
37
#include <sys/stat.h>
38
#include <sys/socket.h>
38
#ifdef HAVE_SYS_SOCKET_H
39
#include <sys/un.h>
39
# include <sys/socket.h>
40
#endif
41
#ifdef HAVE_SYS_UN_H
42
# include <sys/un.h>
43
#endif
40
44
41
#include <errno.h>
45
#include <errno.h>
42
#include <fcntl.h>
46
#include <fcntl.h>
(-)nchan.c (-1 / +3 lines)
Lines 26-32 Link Here
26
#include "includes.h"
26
#include "includes.h"
27
27
28
#include <sys/types.h>
28
#include <sys/types.h>
29
#include <sys/socket.h>
29
#ifdef HAVE_SYS_SOCKET_H
30
# include <sys/socket.h>
31
#endif
30
32
31
#include <errno.h>
33
#include <errno.h>
32
#include <string.h>
34
#include <string.h>
(-)packet.c (-12 / +16 lines)
Lines 42-55 Link Here
42
#include <sys/types.h>
42
#include <sys/types.h>
43
#include "openbsd-compat/sys-queue.h"
43
#include "openbsd-compat/sys-queue.h"
44
#include <sys/param.h>
44
#include <sys/param.h>
45
#include <sys/socket.h>
45
#ifdef HAVE_SYS_SOCKET_H
46
# include <sys/socket.h>
47
#endif
46
#ifdef HAVE_SYS_TIME_H
48
#ifdef HAVE_SYS_TIME_H
47
# include <sys/time.h>
49
# include <sys/time.h>
48
#endif
50
#endif
49
51
50
#include <netinet/in.h>
52
#ifdef HAVE_NETINET_IN_H
51
#include <netinet/ip.h>
53
# include <netinet/in.h>
52
#include <arpa/inet.h>
54
#endif
55
#ifdef HAVE_NETINET_IP_H
56
# include <netinet/ip.h>
57
#endif
58
#ifdef HAVE_ARPA_INET_H
59
# include <arpa/inet.h>
60
#endif
53
61
54
#include <errno.h>
62
#include <errno.h>
55
#include <stdarg.h>
63
#include <stdarg.h>
Lines 1048-1055 Link Here
1048
1056
1049
	DBG(debug("packet_read()"));
1057
	DBG(debug("packet_read()"));
1050
1058
1051
	setp = (fd_set *)xcalloc(howmany(active_state->connection_in + 1,
1059
	setp = (fd_set *)xcalloc(1, FD_SET_SIZE(active_state->connection_in));
1052
	    NFDBITS), sizeof(fd_mask));
1053
1060
1054
	/* Since we are blocking, ensure that all written packets have been sent. */
1061
	/* Since we are blocking, ensure that all written packets have been sent. */
1055
	packet_write_wait();
1062
	packet_write_wait();
Lines 1073-1080 Link Here
1073
		 * Otherwise, wait for some data to arrive, add it to the
1080
		 * Otherwise, wait for some data to arrive, add it to the
1074
		 * buffer, and try again.
1081
		 * buffer, and try again.
1075
		 */
1082
		 */
1076
		memset(setp, 0, howmany(active_state->connection_in + 1,
1083
		memset(setp, 0, FD_SET_SIZE(active_state->connection_in));
1077
		    NFDBITS) * sizeof(fd_mask));
1078
		FD_SET(active_state->connection_in, setp);
1084
		FD_SET(active_state->connection_in, setp);
1079
1085
1080
		if (active_state->packet_timeout_ms > 0) {
1086
		if (active_state->packet_timeout_ms > 0) {
Lines 1735-1746 Link Here
1735
	int ret, ms_remain;
1741
	int ret, ms_remain;
1736
	struct timeval start, timeout, *timeoutp = NULL;
1742
	struct timeval start, timeout, *timeoutp = NULL;
1737
1743
1738
	setp = (fd_set *)xcalloc(howmany(active_state->connection_out + 1,
1744
	setp = (fd_set *)xcalloc(1, FD_SET_SIZE(active_state->connection_out));
1739
	    NFDBITS), sizeof(fd_mask));
1740
	packet_write_poll();
1745
	packet_write_poll();
1741
	while (packet_have_data_to_write()) {
1746
	while (packet_have_data_to_write()) {
1742
		memset(setp, 0, howmany(active_state->connection_out + 1,
1747
		memset(setp, 0, FD_SET_SIZE(active_state->connection_out));
1743
		    NFDBITS) * sizeof(fd_mask));
1744
		FD_SET(active_state->connection_out, setp);
1748
		FD_SET(active_state->connection_out, setp);
1745
1749
1746
		if (active_state->packet_timeout_ms > 0) {
1750
		if (active_state->packet_timeout_ms > 0) {
(-)packet.h (-1 / +3 lines)
Lines 16-22 Link Here
16
#ifndef PACKET_H
16
#ifndef PACKET_H
17
#define PACKET_H
17
#define PACKET_H
18
18
19
#include <termios.h>
19
#ifdef HAVE_TERMIOS_H
20
# include <termios.h>
21
#endif
20
22
21
#include <openssl/bn.h>
23
#include <openssl/bn.h>
22
#ifdef OPENSSL_HAS_ECC
24
#ifdef OPENSSL_HAS_ECC
(-)platform.h (-1 / +5 lines)
Lines 18-24 Link Here
18
18
19
#include <sys/types.h>
19
#include <sys/types.h>
20
20
21
#include <pwd.h>
21
#ifdef HAVE_PWD_H
22
# include <pwd.h>
23
#endif
24
25
struct passwd;
22
26
23
void platform_pre_listen(void);
27
void platform_pre_listen(void);
24
void platform_pre_fork(void);
28
void platform_pre_fork(void);
(-)progressmeter.c (-2 / +6 lines)
Lines 26-33 Link Here
26
#include "includes.h"
26
#include "includes.h"
27
27
28
#include <sys/types.h>
28
#include <sys/types.h>
29
#include <sys/ioctl.h>
29
#ifdef HAVE_SYS_IOCTL_H
30
#include <sys/uio.h>
30
# include <sys/ioctl.h>
31
#endif
32
#ifdef HAVE_SYS_UIO_H
33
# include <sys/uio.h>
34
#endif
31
35
32
#include <errno.h>
36
#include <errno.h>
33
#include <signal.h>
37
#include <signal.h>
(-)readconf.c (-5 / +15 lines)
Lines 16-30 Link Here
16
16
17
#include <sys/types.h>
17
#include <sys/types.h>
18
#include <sys/stat.h>
18
#include <sys/stat.h>
19
#include <sys/socket.h>
19
#ifdef HAVE_SYS_SOCKET_H
20
# include <sys/socket.h>
21
#endif
20
22
21
#include <netinet/in.h>
23
#ifdef HAVE_NETINET_IN_H
22
#include <netinet/in_systm.h>
24
# include <netinet/in.h>
23
#include <netinet/ip.h>
25
#endif
26
#ifdef HAVE_NETINET_IN_SYSTM_H
27
# include <netinet/in_systm.h>
28
#endif
29
#ifdef HAVE_NETINET_IP_H
30
# include <netinet/ip.h>
31
#endif
24
32
25
#include <ctype.h>
33
#include <ctype.h>
26
#include <errno.h>
34
#include <errno.h>
27
#include <netdb.h>
35
#ifdef HAVE_NETDB_H
36
# include <netdb.h>
37
#endif
28
#include <signal.h>
38
#include <signal.h>
29
#include <stdarg.h>
39
#include <stdarg.h>
30
#include <stdio.h>
40
#include <stdio.h>
(-)readpass.c (-1 / +3 lines)
Lines 26-32 Link Here
26
#include "includes.h"
26
#include "includes.h"
27
27
28
#include <sys/types.h>
28
#include <sys/types.h>
29
#include <sys/wait.h>
29
#ifdef HAVE_SYS_WAIT_H
30
# include <sys/wait.h>
31
#endif
30
32
31
#include <errno.h>
33
#include <errno.h>
32
#include <fcntl.h>
34
#include <fcntl.h>
(-)roaming_client.c (-1 / +3 lines)
Lines 19-25 Link Here
19
19
20
#include "openbsd-compat/sys-queue.h"
20
#include "openbsd-compat/sys-queue.h"
21
#include <sys/types.h>
21
#include <sys/types.h>
22
#include <sys/socket.h>
22
#ifdef HAVE_SYS_SOCKET_H
23
# include <sys/socket.h>
24
#endif
23
25
24
#ifdef HAVE_INTTYPES_H
26
#ifdef HAVE_INTTYPES_H
25
#include <inttypes.h>
27
#include <inttypes.h>
(-)roaming_common.c (-2 / +6 lines)
Lines 18-25 Link Here
18
#include "includes.h"
18
#include "includes.h"
19
19
20
#include <sys/types.h>
20
#include <sys/types.h>
21
#include <sys/socket.h>
21
#ifdef HAVE_SYS_SOCKET_H
22
#include <sys/uio.h>
22
# include <sys/socket.h>
23
#endif
24
#ifdef HAVE_SYS_UIO_H
25
# include <sys/uio.h>
26
#endif
23
27
24
#include <errno.h>
28
#include <errno.h>
25
#ifdef HAVE_INTTYPES_H
29
#ifdef HAVE_INTTYPES_H
(-)ssh.c (-8 / +42 lines)
Lines 46-65 Link Here
46
#ifdef HAVE_SYS_STAT_H
46
#ifdef HAVE_SYS_STAT_H
47
# include <sys/stat.h>
47
# include <sys/stat.h>
48
#endif
48
#endif
49
#include <sys/resource.h>
49
#ifdef HAVE_SYS_RESOURCE_H
50
#include <sys/ioctl.h>
50
# include <sys/resource.h>
51
#endif
52
#ifdef HAVE_SYS_IOCTL_H
53
# include <sys/ioctl.h>
54
#endif
51
#include <sys/param.h>
55
#include <sys/param.h>
52
#include <sys/socket.h>
56
#ifdef HAVE_SYS_SOCKET_H
53
#include <sys/wait.h>
57
# include <sys/socket.h>
58
#endif
59
#ifdef HAVE_SYS_WAIT_H
60
# include <sys/wait.h>
61
#endif
54
62
55
#include <ctype.h>
63
#include <ctype.h>
56
#include <errno.h>
64
#include <errno.h>
57
#include <fcntl.h>
65
#include <fcntl.h>
58
#include <netdb.h>
66
#ifdef HAVE_NETDB_H
67
# include <netdb.h>
68
#endif
59
#ifdef HAVE_PATHS_H
69
#ifdef HAVE_PATHS_H
60
#include <paths.h>
70
#include <paths.h>
61
#endif
71
#endif
62
#include <pwd.h>
72
#ifdef HAVE_PWD_H
73
# include <pwd.h>
74
#endif
63
#include <signal.h>
75
#include <signal.h>
64
#include <stdarg.h>
76
#include <stdarg.h>
65
#include <stddef.h>
77
#include <stddef.h>
Lines 68-75 Link Here
68
#include <string.h>
80
#include <string.h>
69
#include <unistd.h>
81
#include <unistd.h>
70
82
71
#include <netinet/in.h>
83
#ifdef HAVE_NETINET_IN_H
72
#include <arpa/inet.h>
84
# include <netinet/in.h>
85
#endif
86
#ifdef HAVE_ARPA_INET_H
87
# include <arpa/inet.h>
88
#endif
73
89
74
#include <openssl/evp.h>
90
#include <openssl/evp.h>
75
#include <openssl/err.h>
91
#include <openssl/err.h>
Lines 248-253 Link Here
248
264
249
	struct servent *sp;
265
	struct servent *sp;
250
	Forward fwd;
266
	Forward fwd;
267
268
#ifdef WIN32
269
	WSADATA wsa_data;
270
271
	WSAStartup(MAKEWORD(2, 2), &wsa_data);
272
273
	/* Unlike Unix, stderr is buffered on Windows */
274
	if (setvbuf(stderr, NULL, _IONBF, 0))
275
		perror("setvbuf");
276
277
	/* And make sure \r isn't filtered out */
278
	if (_setmode(STDIN_FILENO, _O_BINARY) == -1)
279
		perror("_setmode");
280
	if (_setmode(STDOUT_FILENO, _O_BINARY) == -1)
281
		perror("_setmode");
282
	if (_setmode(STDERR_FILENO, _O_BINARY) == -1)
283
		perror("_setmode");
284
#endif
251
285
252
	/* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
286
	/* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
253
	sanitise_stdfd();
287
	sanitise_stdfd();
(-)sshconnect.c (-10 / +21 lines)
Lines 16-39 Link Here
16
#include "includes.h"
16
#include "includes.h"
17
17
18
#include <sys/types.h>
18
#include <sys/types.h>
19
#include <sys/wait.h>
19
#ifdef HAVE_SYS_WAIT_H
20
# include <sys/wait.h>
21
#endif
20
#include <sys/stat.h>
22
#include <sys/stat.h>
21
#include <sys/socket.h>
23
#ifdef HAVE_SYS_SOCKET_H
24
# include <sys/socket.h>
25
#endif
22
#ifdef HAVE_SYS_TIME_H
26
#ifdef HAVE_SYS_TIME_H
23
# include <sys/time.h>
27
# include <sys/time.h>
24
#endif
28
#endif
25
29
26
#include <netinet/in.h>
30
#ifdef HAVE_NETINET_IN_H
27
#include <arpa/inet.h>
31
# include <netinet/in.h>
32
#endif
33
#ifdef HAVE_ARPA_INET_H
34
# include <arpa/inet.h>
35
#endif
28
36
29
#include <ctype.h>
37
#include <ctype.h>
30
#include <errno.h>
38
#include <errno.h>
31
#include <fcntl.h>
39
#include <fcntl.h>
32
#include <netdb.h>
40
#ifdef HAVE_NETDB_H
41
# include <netdb.h>
42
#endif
33
#ifdef HAVE_PATHS_H
43
#ifdef HAVE_PATHS_H
34
#include <paths.h>
44
#include <paths.h>
35
#endif
45
#endif
36
#include <pwd.h>
46
#ifdef HAVE_PWD_H
47
# include <pwd.h>
48
#endif
37
#include <signal.h>
49
#include <signal.h>
38
#include <stdarg.h>
50
#include <stdarg.h>
39
#include <stdio.h>
51
#include <stdio.h>
Lines 61-66 Link Here
61
#include "roaming.h"
73
#include "roaming.h"
62
#include "ssh2.h"
74
#include "ssh2.h"
63
#include "version.h"
75
#include "version.h"
76
#include "uuencode.h"
64
77
65
char *client_version_string = NULL;
78
char *client_version_string = NULL;
66
char *server_version_string = NULL;
79
char *server_version_string = NULL;
Lines 274-281 Link Here
274
		goto done;
287
		goto done;
275
	}
288
	}
276
289
277
	fdset = (fd_set *)xcalloc(howmany(sockfd + 1, NFDBITS),
290
	fdset = (fd_set *)xcalloc(1, FD_SET_SIZE(sockfd));
278
	    sizeof(fd_mask));
279
	FD_SET(sockfd, fdset);
291
	FD_SET(sockfd, fdset);
280
	ms_to_timeval(&tv, *timeoutp);
292
	ms_to_timeval(&tv, *timeoutp);
281
293
Lines 472-479 Link Here
472
	struct timeval t_start, t_remaining;
484
	struct timeval t_start, t_remaining;
473
	fd_set *fdset;
485
	fd_set *fdset;
474
486
475
	fdsetsz = howmany(connection_in + 1, NFDBITS) * sizeof(fd_mask);
487
	fdset = xcalloc(1, FD_SET_SIZE(connection_in));
476
	fdset = xcalloc(1, fdsetsz);
477
488
478
	/*
489
	/*
479
	 * If we are SSH2-only then we can send the banner immediately and
490
	 * If we are SSH2-only then we can send the banner immediately and
(-)sshconnect1.c (-2 / +6 lines)
Lines 16-22 Link Here
16
#include "includes.h"
16
#include "includes.h"
17
17
18
#include <sys/types.h>
18
#include <sys/types.h>
19
#include <sys/socket.h>
19
#ifdef HAVE_SYS_SOCKET_H
20
# include <sys/socket.h>
21
#endif
20
22
21
#include <openssl/bn.h>
23
#include <openssl/bn.h>
22
#include <openssl/md5.h>
24
#include <openssl/md5.h>
Lines 26-32 Link Here
26
#include <stdlib.h>
28
#include <stdlib.h>
27
#include <string.h>
29
#include <string.h>
28
#include <signal.h>
30
#include <signal.h>
29
#include <pwd.h>
31
#ifdef HAVE_PWD_H
32
# include <pwd.h>
33
#endif
30
34
31
#include "xmalloc.h"
35
#include "xmalloc.h"
32
#include "ssh.h"
36
#include "ssh.h"
(-)sshconnect2.c (-4 / +12 lines)
Lines 27-40 Link Here
27
#include "includes.h"
27
#include "includes.h"
28
28
29
#include <sys/types.h>
29
#include <sys/types.h>
30
#include <sys/socket.h>
30
#ifdef HAVE_SYS_SOCKET_H
31
#include <sys/wait.h>
31
# include <sys/socket.h>
32
#endif
33
#ifdef HAVE_SYS_WAIT_H
34
# include <sys/wait.h>
35
#endif
32
#include <sys/stat.h>
36
#include <sys/stat.h>
33
37
34
#include <errno.h>
38
#include <errno.h>
35
#include <fcntl.h>
39
#include <fcntl.h>
36
#include <netdb.h>
40
#ifdef HAVE_NETDB_H
37
#include <pwd.h>
41
# include <netdb.h>
42
#endif
43
#ifdef HAVE_PWD_H
44
# include <pwd.h>
45
#endif
38
#include <signal.h>
46
#include <signal.h>
39
#include <stdarg.h>
47
#include <stdarg.h>
40
#include <stdio.h>
48
#include <stdio.h>
(-)sshpty.h (-1 / +3 lines)
Lines 14-20 Link Here
14
 * called by a name other than "ssh" or "Secure Shell".
14
 * called by a name other than "ssh" or "Secure Shell".
15
 */
15
 */
16
16
17
#include <termios.h>
17
#ifdef HAVE_TERMIOS_H
18
# include <termios.h>
19
#endif
18
20
19
struct termios *get_saved_tio(void);
21
struct termios *get_saved_tio(void);
20
void	 leave_raw_mode(int);
22
void	 leave_raw_mode(int);
(-)sshtty.c (-2 / +6 lines)
Lines 39-46 Link Here
39
39
40
#include <sys/types.h>
40
#include <sys/types.h>
41
#include <stdio.h>
41
#include <stdio.h>
42
#include <termios.h>
42
#ifdef HAVE_TERMIOS_H
43
#include <pwd.h>
43
# include <termios.h>
44
#endif
45
#ifdef HAVE_PWD_H
46
# include <pwd.h>
47
#endif
44
48
45
#include "sshpty.h"
49
#include "sshpty.h"
46
50
(-)ttymodes.c (-1 / +3 lines)
Lines 49-55 Link Here
49
49
50
#include <errno.h>
50
#include <errno.h>
51
#include <string.h>
51
#include <string.h>
52
#include <termios.h>
52
#ifdef HAVE_TERMIOS_H
53
# include <termios.h>
54
#endif
53
#include <stdarg.h>
55
#include <stdarg.h>
54
56
55
#include "packet.h"
57
#include "packet.h"
(-)ttymodes.h (+12 lines)
Lines 67-87 Link Here
67
67
68
/* termios macro */
68
/* termios macro */
69
/* name, op */
69
/* name, op */
70
#if defined(VINTR)
70
TTYCHAR(VINTR, 1)
71
TTYCHAR(VINTR, 1)
72
#endif /* VINTR */
73
#if defined(VQUIT)
71
TTYCHAR(VQUIT, 2)
74
TTYCHAR(VQUIT, 2)
75
#endif /* VQUIT */
76
#if defined(VERASE)
72
TTYCHAR(VERASE, 3)
77
TTYCHAR(VERASE, 3)
78
#endif /* VERASE */
73
#if defined(VKILL)
79
#if defined(VKILL)
74
TTYCHAR(VKILL, 4)
80
TTYCHAR(VKILL, 4)
75
#endif /* VKILL */
81
#endif /* VKILL */
82
#if defined(VEOF)
76
TTYCHAR(VEOF, 5)
83
TTYCHAR(VEOF, 5)
84
#endif /* VEOF */
77
#if defined(VEOL)
85
#if defined(VEOL)
78
TTYCHAR(VEOL, 6)
86
TTYCHAR(VEOL, 6)
79
#endif /* VEOL */
87
#endif /* VEOL */
80
#ifdef VEOL2
88
#ifdef VEOL2
81
TTYCHAR(VEOL2, 7)
89
TTYCHAR(VEOL2, 7)
82
#endif /* VEOL2 */
90
#endif /* VEOL2 */
91
#if defined(VSTART)
83
TTYCHAR(VSTART, 8)
92
TTYCHAR(VSTART, 8)
93
#endif /* VSTART */
94
#if defined(VSTOP)
84
TTYCHAR(VSTOP, 9)
95
TTYCHAR(VSTOP, 9)
96
#endif /* VSTOP */
85
#if defined(VSUSP)
97
#if defined(VSUSP)
86
TTYCHAR(VSUSP, 10)
98
TTYCHAR(VSUSP, 10)
87
#endif /* VSUSP */
99
#endif /* VSUSP */
(-)uidswap.c (-2 / +6 lines)
Lines 16-27 Link Here
16
16
17
#include <sys/param.h>
17
#include <sys/param.h>
18
#include <errno.h>
18
#include <errno.h>
19
#include <pwd.h>
19
#ifdef HAVE_PWD_H
20
# include <pwd.h>
21
#endif
20
#include <string.h>
22
#include <string.h>
21
#include <unistd.h>
23
#include <unistd.h>
22
#include <stdarg.h>
24
#include <stdarg.h>
23
25
24
#include <grp.h>
26
#ifdef HAVE_GRP_H
27
# include <grp.h>
28
#endif
25
29
26
#include "log.h"
30
#include "log.h"
27
#include "uidswap.h"
31
#include "uidswap.h"
(-)uuencode.c (-2 / +6 lines)
Lines 26-33 Link Here
26
#include "includes.h"
26
#include "includes.h"
27
27
28
#include <sys/types.h>
28
#include <sys/types.h>
29
#include <netinet/in.h>
29
#ifdef HAVE_NETINET_IN_H
30
#include <resolv.h>
30
# include <netinet/in.h>
31
#endif
32
#ifdef HAVE_RESOLV_H
33
# include <resolv.h>
34
#endif
31
#include <stdio.h>
35
#include <stdio.h>
32
36
33
#include "xmalloc.h"
37
#include "xmalloc.h"
(-)openbsd-compat/Makefile.in (-2 / +5 lines)
Lines 22-27 Link Here
22
22
23
PORTS=port-aix.o port-irix.o port-linux.o port-solaris.o port-tun.o port-uw.o
23
PORTS=port-aix.o port-irix.o port-linux.o port-solaris.o port-tun.o port-uw.o
24
24
25
WIN32=win32-afunix.o win32-misc.o win32-pwd.o win32-socket.o win32-sspi.o win32-stubs.o win32-tty.o
26
25
.c.o:
27
.c.o:
26
	$(CC) $(CFLAGS) $(CPPFLAGS) -c $<
28
	$(CC) $(CFLAGS) $(CPPFLAGS) -c $<
27
29
Lines 30-38 Link Here
30
$(COMPAT): ../config.h
32
$(COMPAT): ../config.h
31
$(OPENBSD): ../config.h
33
$(OPENBSD): ../config.h
32
$(PORTS): ../config.h
34
$(PORTS): ../config.h
35
$(WIN32): ../config.h
33
36
34
libopenbsd-compat.a:  $(COMPAT) $(OPENBSD) $(PORTS)
37
libopenbsd-compat.a:  $(COMPAT) $(OPENBSD) $(PORTS) $(WIN32)
35
	$(AR) rv $@ $(COMPAT) $(OPENBSD) $(PORTS)
38
	$(AR) rv $@ $(COMPAT) $(OPENBSD) $(PORTS) $(WIN32)
36
	$(RANLIB) $@
39
	$(RANLIB) $@
37
40
38
clean:
41
clean:
(-)openbsd-compat/base64.c (-3 / +9 lines)
Lines 50-58 Link Here
50
50
51
#include <sys/types.h>
51
#include <sys/types.h>
52
#include <sys/param.h>
52
#include <sys/param.h>
53
#include <sys/socket.h>
53
#ifdef HAVE_SYS_SOCKET_H
54
#include <netinet/in.h>
54
# include <sys/socket.h>
55
#include <arpa/inet.h>
55
#endif
56
#ifdef HAVE_NETINET_IN_H
57
# include <netinet/in.h>
58
#endif
59
#ifdef HAVE_ARPA_INET_H
60
# include <arpa/inet.h>
61
#endif
56
62
57
#include <ctype.h>
63
#include <ctype.h>
58
#include <stdio.h>
64
#include <stdio.h>
(-)openbsd-compat/bindresvport.c (-3 / +9 lines)
Lines 34-43 Link Here
34
34
35
#ifndef HAVE_BINDRESVPORT_SA
35
#ifndef HAVE_BINDRESVPORT_SA
36
#include <sys/types.h>
36
#include <sys/types.h>
37
#include <sys/socket.h>
37
#ifdef HAVE_SYS_SOCKET_H
38
# include <sys/socket.h>
39
#endif
38
40
39
#include <netinet/in.h>
41
#ifdef HAVE_NETINET_IN_H
40
#include <arpa/inet.h>
42
# include <netinet/in.h>
43
#endif
44
#ifdef HAVE_ARPA_INET_H
45
# include <arpa/inet.h>
46
#endif
41
47
42
#include <errno.h>
48
#include <errno.h>
43
#include <string.h>
49
#include <string.h>
(-)openbsd-compat/bsd-getpeereid.c (-1 / +3 lines)
Lines 19-25 Link Here
19
#if !defined(HAVE_GETPEEREID)
19
#if !defined(HAVE_GETPEEREID)
20
20
21
#include <sys/types.h>
21
#include <sys/types.h>
22
#include <sys/socket.h>
22
#ifdef HAVE_SYS_SOCKET_H
23
# include <sys/socket.h>
24
#endif
23
25
24
#include <unistd.h>
26
#include <unistd.h>
25
27
(-)openbsd-compat/bsd-misc.c (+3 lines)
Lines 29-34 Link Here
29
#include <signal.h>
29
#include <signal.h>
30
#include <stdlib.h>
30
#include <stdlib.h>
31
#include <unistd.h>
31
#include <unistd.h>
32
#ifdef HAVE_FCNTL_H
33
# include <fcntl.h>
34
#endif
32
35
33
#include "xmalloc.h"
36
#include "xmalloc.h"
34
37
(-)openbsd-compat/bsd-poll.c (-5 / +3 lines)
Lines 42-48 Link Here
42
	nfds_t i;
42
	nfds_t i;
43
	int saved_errno, ret, fd, maxfd = 0;
43
	int saved_errno, ret, fd, maxfd = 0;
44
	fd_set *readfds = NULL, *writefds = NULL, *exceptfds = NULL;
44
	fd_set *readfds = NULL, *writefds = NULL, *exceptfds = NULL;
45
	size_t nmemb;
46
	struct timeval tv, *tvp = NULL;
45
	struct timeval tv, *tvp = NULL;
47
46
48
	for (i = 0; i < nfds; i++) {
47
	for (i = 0; i < nfds; i++) {
Lines 54-63 Link Here
54
		maxfd = MAX(maxfd, fd);
53
		maxfd = MAX(maxfd, fd);
55
	}
54
	}
56
55
57
	nmemb = howmany(maxfd + 1 , NFDBITS);
56
	if ((readfds = calloc(1, FD_SET_SIZE(maxfd))) == NULL ||
58
	if ((readfds = calloc(nmemb, sizeof(fd_mask))) == NULL ||
57
	    (writefds = calloc(1, FD_SET_SIZE(maxfd))) == NULL ||
59
	    (writefds = calloc(nmemb, sizeof(fd_mask))) == NULL ||
58
	    (exceptfds = calloc(1, FD_SET_SIZE(maxfd))) == NULL) {
60
	    (exceptfds = calloc(nmemb, sizeof(fd_mask))) == NULL) {
61
		saved_errno = ENOMEM;
59
		saved_errno = ENOMEM;
62
		ret = -1;
60
		ret = -1;
63
		goto out;
61
		goto out;
(-)openbsd-compat/bsd-waitpid.c (-1 / +3 lines)
Lines 26-32 Link Here
26
26
27
#ifndef HAVE_WAITPID 
27
#ifndef HAVE_WAITPID 
28
#include <errno.h>
28
#include <errno.h>
29
#include <sys/wait.h>
29
#ifdef HAVE_SYS_WAIT_H
30
# include <sys/wait.h>
31
#endif
30
#include "bsd-waitpid.h"
32
#include "bsd-waitpid.h"
31
33
32
pid_t
34
pid_t
(-)openbsd-compat/fake-rfc2553.c (-2 / +6 lines)
Lines 40-47 Link Here
40
#include <stdlib.h>
40
#include <stdlib.h>
41
#include <string.h>
41
#include <string.h>
42
42
43
#include <netinet/in.h>
43
#ifdef HAVE_NETINET_IN_H
44
#include <arpa/inet.h>
44
# include <netinet/in.h>
45
#endif
46
#ifdef HAVE_ARPA_INET_H
47
# include <arpa/inet.h>
48
#endif
45
49
46
#ifndef HAVE_GETNAMEINFO
50
#ifndef HAVE_GETNAMEINFO
47
int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, 
51
int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, 
(-)openbsd-compat/getgrouplist.c (-1 / +3 lines)
Lines 40-46 Link Here
40
#include <sys/types.h>
40
#include <sys/types.h>
41
#include <string.h>
41
#include <string.h>
42
#include <unistd.h>
42
#include <unistd.h>
43
#include <grp.h>
43
#ifdef HAVE_GRP_H
44
# include <grp.h>
45
#endif
44
46
45
int
47
int
46
getgrouplist(const char *uname, gid_t agroup, gid_t *groups, int *grpcnt)
48
getgrouplist(const char *uname, gid_t agroup, gid_t *groups, int *grpcnt)
(-)openbsd-compat/getopt.h (-1 / +8 lines)
Lines 33-39 Link Here
33
#ifndef _GETOPT_H_
33
#ifndef _GETOPT_H_
34
#define _GETOPT_H_
34
#define _GETOPT_H_
35
35
36
#include <sys/cdefs.h>
36
#ifdef HAVE_SYS_CDEFS_H
37
# include <sys/cdefs.h>
38
#endif
39
40
#ifndef __BEGIN_DECLS
41
#define __BEGIN_DECLS
42
#define __END_DECLS
43
#endif
37
44
38
/*
45
/*
39
 * GNU-like getopt_long() and 4.4BSD getsubopt()/optreset extensions
46
 * GNU-like getopt_long() and 4.4BSD getsubopt()/optreset extensions
(-)openbsd-compat/getrrsetbyname.h (-4 / +12 lines)
Lines 53-62 Link Here
53
#ifndef HAVE_GETRRSETBYNAME
53
#ifndef HAVE_GETRRSETBYNAME
54
54
55
#include <sys/types.h>
55
#include <sys/types.h>
56
#include <netinet/in.h>
56
#ifdef HAVE_NETINET_IN_H
57
#include <arpa/nameser.h>
57
# include <netinet/in.h>
58
#include <netdb.h>
58
#endif
59
#include <resolv.h>
59
#ifdef HAVE_ARPA_NAMESER_H
60
# include <arpa/nameser.h>
61
#endif
62
#ifdef HAVE_NETDB_H
63
# include <netdb.h>
64
#endif
65
#ifdef HAVE_RESOLV_H
66
# include <resolv.h>
67
#endif
60
68
61
#ifndef HFIXEDSZ
69
#ifndef HFIXEDSZ
62
#define HFIXEDSZ 12
70
#define HFIXEDSZ 12
(-)openbsd-compat/glob.c (-4 / +9 lines)
Lines 67-73 Link Here
67
#include <ctype.h>
67
#include <ctype.h>
68
#include <errno.h>
68
#include <errno.h>
69
#include <limits.h>
69
#include <limits.h>
70
#include <pwd.h>
70
#ifdef HAVE_PWD_H
71
# include <pwd.h>
72
#endif
71
#include <stdlib.h>
73
#include <stdlib.h>
72
#include <string.h>
74
#include <string.h>
73
#include <unistd.h>
75
#include <unistd.h>
Lines 650-659 Link Here
650
			}
652
			}
651
653
652
			if (((pglob->gl_flags & GLOB_MARK) &&
654
			if (((pglob->gl_flags & GLOB_MARK) &&
653
			    pathend[-1] != SEP) && (S_ISDIR(sb.st_mode) ||
655
			    pathend[-1] != SEP) && (S_ISDIR(sb.st_mode)
654
			    (S_ISLNK(sb.st_mode) &&
656
#ifdef S_ISLNK
657
			    || (S_ISLNK(sb.st_mode) &&
655
			    (g_stat(pathbuf, &sb, pglob) == 0) &&
658
			    (g_stat(pathbuf, &sb, pglob) == 0) &&
656
			    S_ISDIR(sb.st_mode)))) {
659
			    S_ISDIR(sb.st_mode))
660
#endif
661
			    )) {
657
				if (pathend+1 > pathend_last)
662
				if (pathend+1 > pathend_last)
658
					return (1);
663
					return (1);
659
				*pathend++ = SEP;
664
				*pathend++ = SEP;
(-)openbsd-compat/inet_aton.c (-2 / +6 lines)
Lines 57-64 Link Here
57
57
58
#include <sys/types.h>
58
#include <sys/types.h>
59
#include <sys/param.h>
59
#include <sys/param.h>
60
#include <netinet/in.h>
60
#ifdef HAVE_NETINET_IN_H
61
#include <arpa/inet.h>
61
# include <netinet/in.h>
62
#endif
63
#ifdef HAVE_ARPA_INET_H
64
# include <arpa/inet.h>
65
#endif
62
#include <ctype.h>
66
#include <ctype.h>
63
67
64
#if 0
68
#if 0
(-)openbsd-compat/inet_ntop.c (-4 / +12 lines)
Lines 24-33 Link Here
24
24
25
#include <sys/param.h>
25
#include <sys/param.h>
26
#include <sys/types.h>
26
#include <sys/types.h>
27
#include <sys/socket.h>
27
#ifdef HAVE_SYS_SOCKET_H
28
#include <netinet/in.h>
28
# include <sys/socket.h>
29
#include <arpa/inet.h>
29
#endif
30
#include <arpa/nameser.h>
30
#ifdef HAVE_NETINET_IN_H
31
# include <netinet/in.h>
32
#endif
33
#ifdef HAVE_ARPA_INET_H
34
# include <arpa/inet.h>
35
#endif
36
#ifdef HAVE_ARPA_NAMESER_H
37
# include <arpa/nameser.h>
38
#endif
31
#include <string.h>
39
#include <string.h>
32
#include <errno.h>
40
#include <errno.h>
33
#include <stdio.h>
41
#include <stdio.h>
(-)openbsd-compat/openbsd-compat.h (-4 / +21 lines)
Lines 32-40 Link Here
32
#include "includes.h"
32
#include "includes.h"
33
33
34
#include <sys/types.h>
34
#include <sys/types.h>
35
#include <pwd.h>
35
#ifdef HAVE_PWD_H
36
# include <pwd.h>
37
#endif
38
39
#ifdef HAVE_SYS_SOCKET_H
40
# include <sys/socket.h>
41
#endif
36
42
37
#include <sys/socket.h>
43
/* Windows specific compatibility routines */
44
#include "win32-afunix.h"
45
#include "win32-misc.h"
46
#include "win32-pwd.h"
47
#include "win32-socket.h"
48
#include "win32-sspi.h"
49
#include "win32-stubs.h"
50
#include "win32-tty.h"
38
51
39
/* OpenBSD function replacements */
52
/* OpenBSD function replacements */
40
#include "base64.h"
53
#include "base64.h"
Lines 144-150 Link Here
144
157
145
#if defined(HAVE_DECL_WRITEV) && HAVE_DECL_WRITEV == 0
158
#if defined(HAVE_DECL_WRITEV) && HAVE_DECL_WRITEV == 0
146
# include <sys/types.h>
159
# include <sys/types.h>
147
# include <sys/uio.h>
160
# ifdef HAVE_SYS_UIO_H
161
#  include <sys/uio.h>
162
# endif
148
int writev(int, struct iovec *, int);
163
int writev(int, struct iovec *, int);
149
#endif
164
#endif
150
165
Lines 177-183 Link Here
177
#endif 
192
#endif 
178
193
179
#ifndef HAVE_OPENPTY
194
#ifndef HAVE_OPENPTY
180
# include <sys/ioctl.h>	/* for struct winsize */
195
# ifdef HAVE_SYS_IOCTL_H
196
#  include <sys/ioctl.h>	/* for struct winsize */
197
# endif
181
int openpty(int *, int *, char *, struct termios *, struct winsize *);
198
int openpty(int *, int *, char *, struct termios *, struct winsize *);
182
#endif /* HAVE_OPENPTY */
199
#endif /* HAVE_OPENPTY */
183
200
(-)openbsd-compat/port-solaris.h (-1 / +3 lines)
Lines 20-26 Link Here
20
20
21
#include <sys/types.h>
21
#include <sys/types.h>
22
22
23
#include <pwd.h>
23
#ifdef HAVE_PWD_H
24
# include <pwd.h>
25
#endif
24
26
25
void solaris_contract_pre_fork(void);
27
void solaris_contract_pre_fork(void);
26
void solaris_contract_post_fork_child(void);
28
void solaris_contract_post_fork_child(void);
(-)openbsd-compat/port-tun.c (-4 / +12 lines)
Lines 17-27 Link Here
17
#include "includes.h"
17
#include "includes.h"
18
18
19
#include <sys/types.h>
19
#include <sys/types.h>
20
#include <sys/ioctl.h>
20
#ifdef HAVE_SYS_IOCTL_H
21
# include <sys/ioctl.h>
22
#endif
21
23
22
#include <netinet/in.h>
24
#ifdef HAVE_NETINET_IN_H
23
#include <arpa/inet.h>
25
# include <netinet/in.h>
24
#include <netinet/ip.h>
26
#endif
27
#ifdef HAVE_ARPA_INET_H
28
# include <arpa/inet.h>
29
#endif
30
#ifdef HAVE_NETINET_IP_H
31
# include <netinet/ip.h>
32
#endif
25
33
26
#include <errno.h>
34
#include <errno.h>
27
#include <fcntl.h>
35
#include <fcntl.h>
(-)openbsd-compat/pwcache.c (-2 / +6 lines)
Lines 34-41 Link Here
34
34
35
#include <sys/types.h>
35
#include <sys/types.h>
36
36
37
#include <grp.h>
37
#ifdef HAVE_GRP_H
38
#include <pwd.h>
38
# include <grp.h>
39
#endif
40
#ifdef HAVE_PWD_H
41
# include <pwd.h>
42
#endif
39
#include <stdio.h>
43
#include <stdio.h>
40
#include <stdlib.h>
44
#include <stdlib.h>
41
#include <string.h>
45
#include <string.h>
(-)openbsd-compat/readpassphrase.c (-1 / +3 lines)
Lines 26-32 Link Here
26
26
27
#ifndef HAVE_READPASSPHRASE
27
#ifndef HAVE_READPASSPHRASE
28
28
29
#include <termios.h>
29
#ifdef HAVE_TERMIOS_H
30
# include <termios.h>
31
#endif
30
#include <signal.h>
32
#include <signal.h>
31
#include <ctype.h>
33
#include <ctype.h>
32
#include <fcntl.h>
34
#include <fcntl.h>
(-)openbsd-compat/realpath.c (+2 lines)
Lines 142-147 Link Here
142
			}
142
			}
143
			return (NULL);
143
			return (NULL);
144
		}
144
		}
145
#ifdef S_ISLNK
145
		if (S_ISLNK(sb.st_mode)) {
146
		if (S_ISLNK(sb.st_mode)) {
146
			if (symlinks++ > MAXSYMLINKS) {
147
			if (symlinks++ > MAXSYMLINKS) {
147
				errno = ELOOP;
148
				errno = ELOOP;
Lines 184-189 Link Here
184
			}
185
			}
185
			left_len = strlcpy(left, symlink, sizeof(left));
186
			left_len = strlcpy(left, symlink, sizeof(left));
186
		}
187
		}
188
#endif
187
	}
189
	}
188
190
189
	/*
191
	/*
(-)openbsd-compat/rresvport.c (-3 / +9 lines)
Lines 36-45 Link Here
36
#ifndef HAVE_RRESVPORT_AF
36
#ifndef HAVE_RRESVPORT_AF
37
37
38
#include <sys/types.h>
38
#include <sys/types.h>
39
#include <sys/socket.h>
39
#ifdef HAVE_SYS_SOCKET_H
40
# include <sys/socket.h>
41
#endif
40
42
41
#include <netinet/in.h>
43
#ifdef HAVE_NETINET_IN_H
42
#include <arpa/inet.h>
44
# include <netinet/in.h>
45
#endif
46
#ifdef HAVE_ARPA_INET_H
47
# include <arpa/inet.h>
48
#endif
43
49
44
#include <errno.h>
50
#include <errno.h>
45
#include <stdlib.h>
51
#include <stdlib.h>
(-)openbsd-compat/strmode.c (+2 lines)
Lines 56-64 Link Here
56
	case S_IFREG:			/* regular */
56
	case S_IFREG:			/* regular */
57
		*p++ = '-';
57
		*p++ = '-';
58
		break;
58
		break;
59
#ifdef S_IFLNK
59
	case S_IFLNK:			/* symbolic link */
60
	case S_IFLNK:			/* symbolic link */
60
		*p++ = 'l';
61
		*p++ = 'l';
61
		break;
62
		break;
63
#endif
62
#ifdef S_IFSOCK
64
#ifdef S_IFSOCK
63
	case S_IFSOCK:			/* socket */
65
	case S_IFSOCK:			/* socket */
64
		*p++ = 's';
66
		*p++ = 's';
(-)openbsd-compat/win32-afunix.c (+171 lines)
Added Link Here
1
/*
2
 * Copyright 2013 Pierre Ossman for Cendio AB
3
 *
4
 * Permission to use, copy, modify, and distribute this software for any
5
 * purpose with or without fee is hereby granted, provided that the above
6
 * copyright notice and this permission notice appear in all copies.
7
 *
8
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
 */
16
17
#include "includes.h"
18
19
#include "log.h"
20
21
#ifdef WIN32
22
23
static FD_SET afunix_sockets;
24
static int skip_redirection;
25
26
int
27
win32_is_afunix(int fd)
28
{
29
	/* Temporary bypass */
30
	if (skip_redirection) {
31
		skip_redirection = 0;
32
		return 0;
33
	}
34
35
	return FD_ISSET(fd, &afunix_sockets);
36
}
37
38
int
39
win32_afunix_close(int fd)
40
{
41
	if (!win32_is_afunix(fd)) {
42
		errno = EINVAL;
43
		return -1;
44
	}
45
46
	FD_CLR(fd, &afunix_sockets);
47
48
	return 0;
49
}
50
51
int
52
win32_afunix_accept(int socket, struct sockaddr *address,
53
                    socklen_t *address_len)
54
{
55
	errno = EINVAL;
56
	return -1;
57
}
58
59
int
60
win32_afunix_bind(int socket, const struct sockaddr *address,
61
                  socklen_t address_len)
62
{
63
	errno = EINVAL;
64
	return -1;
65
}
66
67
int
68
win32_afunix_connect(int socket, const struct sockaddr *address,
69
                     socklen_t address_len)
70
{
71
	int ret;
72
	const struct sockaddr_un *addr;
73
74
	FILE *f;
75
	int port;
76
	char cookie[65];
77
78
	struct sockaddr_in sin;
79
80
	if (!win32_is_afunix(socket)) {
81
		errno = EINVAL;
82
		return -1;
83
	}
84
85
	if ((address == NULL) || (address_len != sizeof(struct sockaddr_un))) {
86
		errno = EINVAL;
87
		return -1;
88
	}
89
90
	addr = (const struct sockaddr_un*)address;
91
92
	f = fopen(addr->sun_path, "rt");
93
	if (f == NULL)
94
		return -1;
95
96
	port = 0;
97
	cookie[0] = '\0';
98
99
	fscanf(f, "%d ", &port);
100
	fgets(cookie, sizeof(cookie), f);
101
	
102
	fclose(f);
103
104
	if ((port == 0) || (strlen(cookie) != sizeof(cookie)-1)) {
105
		errno = EINVAL;
106
		return -1;
107
	}
108
109
	memset(&sin, 0, sizeof(struct sockaddr_in));
110
111
	sin.sin_family = AF_INET;
112
	sin.sin_port = htons(port);
113
	sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
114
115
	/* Temporarily allow us to call a real connect() */
116
	skip_redirection = 1;
117
118
	ret = connect(socket, (struct sockaddr*)&sin,
119
	              sizeof(struct sockaddr_in));
120
	if (ret == -1) {
121
		FD_SET fds;
122
123
		if (errno != EINPROGRESS)
124
			return -1;
125
126
		debug("waiting for emulated unix socket to connect...");
127
128
		FD_ZERO(&fds);
129
		FD_SET(socket, &fds);
130
131
		ret = select(socket, NULL, &fds, NULL, NULL);
132
		if (ret == -1)
133
			return -1;
134
135
		debug("done.");
136
	}
137
138
	ret = write(socket, cookie, strlen(cookie));
139
	if (ret == -1)
140
		return -1;
141
142
	return 0;
143
}
144
145
int
146
win32_afunix_listen(int sockfd, int backlog)
147
{
148
	errno = EINVAL;
149
	return -1;
150
}
151
152
int
153
win32_afunix_socket(int domain, int type, int protocol)
154
{
155
	int fd;
156
157
	if ((domain != AF_UNIX) || (type != SOCK_STREAM)) {
158
		errno = EINVAL;
159
		return -1;
160
	}
161
162
	fd = socket(AF_INET, SOCK_STREAM, 0);
163
	if (fd == -1)
164
		return -1;
165
166
	FD_SET(fd, &afunix_sockets);
167
168
	return fd;
169
}
170
171
#endif /* WIN32 */
(-)openbsd-compat/win32-afunix.h (+39 lines)
Added Link Here
1
/*
2
 * Copyright 2013 Pierre Ossman for Cendio AB
3
 *
4
 * Permission to use, copy, modify, and distribute this software for any
5
 * purpose with or without fee is hereby granted, provided that the above
6
 * copyright notice and this permission notice appear in all copies.
7
 *
8
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
 */
16
17
#ifndef _WIN32_AFUNIX_H
18
#define _WIN32_AFUNIX_H
19
20
#include "includes.h"
21
22
#ifdef WIN32
23
24
int win32_is_afunix(int fd);
25
26
int win32_afunix_close(int fd);
27
28
int win32_afunix_accept(int socket, struct sockaddr *address,
29
                        socklen_t *address_len);
30
int win32_afunix_bind(int socket, const struct sockaddr *address,
31
                      socklen_t address_len);
32
int win32_afunix_connect(int socket, const struct sockaddr *address,
33
                         socklen_t address_len);
34
int win32_afunix_listen(int sockfd, int backlog);
35
int win32_afunix_socket(int domain, int type, int protocol);
36
37
#endif /* WIN32 */
38
39
#endif /* _WIN32_AFUNIX_H */
(-)openbsd-compat/win32-misc.c (+233 lines)
Added Link Here
1
/*
2
 * Copyright 2013 Pierre Ossman for Cendio AB
3
 *
4
 * Permission to use, copy, modify, and distribute this software for any
5
 * purpose with or without fee is hereby granted, provided that the above
6
 * copyright notice and this permission notice appear in all copies.
7
 *
8
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
 */
16
17
#include "includes.h"
18
19
#undef strerror
20
21
#ifdef WIN32
22
23
#include <ddk/ntifs.h>
24
25
int
26
isafifo(int fd)
27
{
28
	int ret;
29
	struct stat st;
30
31
	ret = fstat(fd, &st);
32
	if (ret != 0)
33
		return 0;
34
35
	return S_ISFIFO(st.st_mode);
36
}
37
38
int
39
fcntl(int fd, int cmd, ... /* arg */ )
40
{
41
	unsigned long val;
42
43
	va_list ap;
44
45
	switch (cmd) {
46
	case F_SETFD:
47
		return 0;
48
	case F_GETFL:
49
		if (isatty(fd)) {
50
			/* The console cannot be made non-blocking */
51
			return 0;
52
		} else if (isafifo(fd)) {
53
			HANDLE handle;
54
			DWORD state;
55
56
			handle = (HANDLE)_get_osfhandle(fd);
57
			if (!GetNamedPipeHandleState(handle, &state, NULL,
58
			                             NULL, NULL, NULL, 0)) {
59
				errno = GetLastError() | WIN32_ERRNO;
60
				return -1;
61
			}
62
63
			if (state & PIPE_NOWAIT)
64
				return O_NONBLOCK;
65
66
			return 0;
67
		} else {
68
			/*
69
			 * Sockets are blocking by default, but we have no
70
			 * way of checking what it is now.
71
			 */
72
			return 0;
73
		}
74
	case F_SETFL:
75
		va_start(ap, cmd);
76
		val = va_arg(ap, int);
77
		va_end(ap);
78
79
		if (isatty(fd)) {
80
			/* The console cannot be made non-blocking */
81
			if (val & O_NONBLOCK) {
82
				errno = EPERM;
83
				return -1;
84
			}
85
86
			return 0;
87
		} else if (isafifo(fd)) {
88
			int i;
89
			HANDLE handle;
90
			DWORD state;
91
92
			handle = (HANDLE)_get_osfhandle(fd);
93
94
			/*
95
			 * You can't reconfigure a pipe that has data in it
96
			 * so we need to check the buffers. We can't do
97
			 * anything about incoming data, but outgoing data
98
			 * we can wait a while for...
99
			 */
100
			for (i = 0;i < 100;i++) {
101
				IO_STATUS_BLOCK iosb;
102
				FILE_PIPE_LOCAL_INFORMATION fpli;
103
				NTSTATUS ret;
104
105
				ret = ZwQueryInformationFile(handle, &iosb,
106
					                     &fpli, sizeof(fpli),
107
					                     FilePipeLocalInformation);
108
				if (ret != STATUS_SUCCESS) {
109
					errno = ret | WIN32_ERRNO;
110
					return -1;
111
				}
112
113
				if (fpli.WriteQuotaAvailable == fpli.OutboundQuota)
114
					break;
115
116
				Sleep(50);
117
			}
118
119
			if (!GetNamedPipeHandleState(handle, &state, NULL,
120
			                             NULL, NULL, NULL, 0)) {
121
				errno = GetLastError() | WIN32_ERRNO;
122
				return -1;
123
			}
124
125
			if (val & O_NONBLOCK)
126
				state |= PIPE_NOWAIT;
127
			else
128
				state &= ~PIPE_NOWAIT;
129
130
			if (!SetNamedPipeHandleState(handle, &state,
131
			                             NULL, NULL)) {
132
				errno = GetLastError() | WIN32_ERRNO;
133
				return -1;
134
			}
135
136
			return 0;
137
		} else {
138
			int ret;
139
140
			val = (val & O_NONBLOCK) != 0;
141
142
			ret = ioctlsocket(fd, FIONBIO, &val);
143
			if (ret == SOCKET_ERROR) {
144
				errno = WSAGetLastError() | WIN32_ERRNO;
145
				return -1;
146
			}
147
148
			return 0;
149
		}
150
	default:
151
		errno = EINVAL;
152
		return -1;
153
	}
154
}
155
156
int
157
sigaction(int sig, struct sigaction *sigact, struct sigaction *osigact)
158
{
159
	void (*old)(int);
160
161
	if (sig >= NSIG) {
162
		errno = EINVAL;
163
		return -1;
164
	}
165
166
	if (sigact)
167
		old = signal(sig, sigact->sa_handler);
168
	else
169
		old = signal(sig, SIG_IGN);
170
171
	if (old == SIG_ERR)
172
		return -1;
173
174
	if (!sigact)
175
		signal(sig, old);
176
177
	if (osigact)
178
		osigact->sa_handler = old;
179
180
	return 0;
181
}
182
183
int
184
sigemptyset(sigset_t *mask)
185
{
186
	*mask = 0;
187
188
	return 0;
189
}
190
191
int kill(pid_t pid, int sig)
192
{
193
	if (pid != getpid()) {
194
		errno = EPERM;
195
		return -1;
196
	}
197
198
	if (sig >= NSIG) {
199
		errno = EINVAL;
200
		return -1;
201
	}
202
203
	return raise(sig);
204
}
205
206
unsigned int
207
sleep(unsigned int seconds)
208
{
209
	Sleep(seconds * 1000);
210
	return 0;
211
}
212
213
char *
214
win32_strerror(int errnum)
215
{
216
	if (errnum & WIN32_ERRNO) {
217
		static char msg[256];
218
		errnum &= ~WIN32_ERRNO;
219
		if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, errnum,
220
		                   0, msg, sizeof(msg), NULL)) {
221
			snprintf(msg, sizeof(msg), "Unknown error %d", errnum);
222
		} else {
223
			// Windows likes line ending on their error messages
224
			if (strlen(msg) >= 2)
225
				msg[strlen(msg)-2] = '\0';
226
		}
227
		return msg;
228
	}	
229
230
	return strerror(errnum);
231
}
232
233
#endif /* WIN32 */
(-)openbsd-compat/win32-misc.h (+94 lines)
Added Link Here
1
/*
2
 * Copyright 2013 Pierre Ossman for Cendio AB
3
 *
4
 * Permission to use, copy, modify, and distribute this software for any
5
 * purpose with or without fee is hereby granted, provided that the above
6
 * copyright notice and this permission notice appear in all copies.
7
 *
8
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
 */
16
17
#ifndef _WIN32_MISC_H
18
#define _WIN32_MISC_H
19
20
#include "includes.h"
21
22
#include <signal.h>
23
24
#ifdef WIN32
25
26
#undef _PATH_DEVNULL
27
#define _PATH_DEVNULL "nul"
28
29
#define bzero(s, n) memset(s, 0, n)
30
31
/* These are outside the normal range */
32
#define	S_IXGRP	0x00010000
33
#define	S_IWGRP	0x00020000
34
#define	S_IRGRP 0x00040000
35
#define	S_IXOTH	0x00100000
36
#define	S_IWOTH	0x00200000
37
#define	S_IROTH 0x00400000
38
#define	S_ISUID	0x01000000
39
#define	S_ISGID	0x02000000
40
#define	S_ISVTX 0x04000000
41
42
#define lstat(path, st) stat(path, st)
43
44
#define mkdir(path, mode) mkdir(path)
45
46
#define F_SETFD		0
47
#define F_GETFL		1
48
#define F_SETFL		2
49
50
#define FD_CLOEXEC	0x1
51
52
int isafifo(int fd);
53
54
int fcntl(int fd, int cmd, ... /* arg */ );
55
56
struct iovec {
57
	void  *iov_base;    /* Starting address */
58
	size_t iov_len;     /* Number of bytes to transfer */
59
};
60
61
#define	SIGHUP		(NSIG+1)
62
#define	SIGQUIT		(NSIG+2)
63
#define	SIGPIPE		(NSIG+3)
64
#define	SIGALRM		(NSIG+4)
65
#define	SIGCHLD		(NSIG+5)
66
#define	SIGTSTP		(NSIG+6)
67
#define	SIGTTIN		(NSIG+7)
68
#define	SIGTTOU		(NSIG+8)
69
#define	SIGWINCH	(NSIG+9)
70
71
typedef int sigset_t;
72
73
struct sigaction {
74
	void     (*sa_handler)(int);
75
	sigset_t   sa_mask;
76
	int        sa_flags;
77
};
78
79
int sigaction(int sig, struct sigaction *sigact, struct sigaction *osigact);
80
int sigemptyset(sigset_t *mask);
81
82
int kill(pid_t pid, int sig);
83
84
unsigned int sleep(unsigned int seconds);
85
86
#define WIN32_ERRNO 0x80000000
87
88
#define strerror win32_strerror
89
90
char *win32_strerror(int errnum);
91
92
#endif /* WIN32 */
93
94
#endif /* _WIN32_MISC_H */
(-)openbsd-compat/win32-pwd.c (+167 lines)
Added Link Here
1
/*
2
 * Copyright 2013 Pierre Ossman for Cendio AB
3
 *
4
 * Permission to use, copy, modify, and distribute this software for any
5
 * purpose with or without fee is hereby granted, provided that the above
6
 * copyright notice and this permission notice appear in all copies.
7
 *
8
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
 */
16
17
#include "includes.h"
18
19
#ifdef WIN32
20
21
#include <shlobj.h>
22
23
#define MAGIC_UID 666
24
#define MAGIC_GID 777
25
26
uid_t
27
getuid(void)
28
{
29
	return MAGIC_UID;
30
}
31
32
uid_t
33
geteuid(void)
34
{
35
	return getuid();
36
}
37
38
int
39
setuid(uid_t uid)
40
{
41
	if (uid != MAGIC_UID) {
42
		errno = EPERM;
43
		return -1;
44
	}
45
46
	return 0;
47
}
48
49
int
50
seteuid(uid_t euid)
51
{
52
	return setuid(euid);
53
}
54
55
struct passwd*
56
getpwnam(const char *name)
57
{
58
	struct passwd *pw;
59
60
	pw = getpwuid(MAGIC_UID);
61
	if (pw == NULL)
62
		return NULL;
63
64
	if (strcmp(pw->pw_name, name) != 0) {
65
		errno = ENOENT;
66
		return NULL;
67
	}
68
69
	return pw;
70
}
71
72
struct passwd*
73
getpwuid(uid_t uid)
74
{
75
	HRESULT result;
76
77
	static struct passwd pw;
78
79
	static char name[256];
80
	static char password[] = "";
81
	static char gecos[] = "";
82
	static char dir[MAX_PATH];
83
	static char shell[] = "/bin/false";
84
85
	DWORD len;
86
87
	if (uid != MAGIC_UID) {
88
		errno = ENOENT;
89
		return NULL;
90
	}
91
92
	memset(&pw, 0, sizeof(struct passwd));
93
94
	pw.pw_name = name;
95
	pw.pw_passwd = password;
96
	pw.pw_uid = MAGIC_UID;
97
	pw.pw_gid = MAGIC_GID;
98
	pw.pw_gecos = gecos;
99
	pw.pw_dir = dir;
100
	pw.pw_shell = shell;
101
102
	len = sizeof(name);
103
	if (!GetUserName(name, &len))
104
		return NULL;
105
106
	/*
107
	 * The Windows home directory is meant for user data, not
108
	 * configuration. So point things at the Application Data
109
	 * path instead.
110
	 */
111
	result = SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, dir);
112
	if (result != S_OK)
113
		return NULL;
114
115
	return &pw;
116
}
117
118
gid_t
119
getgid(void)
120
{
121
	return MAGIC_GID;
122
}
123
124
gid_t
125
getegid(void)
126
{
127
	return getgid();
128
}
129
130
int
131
setgid(gid_t gid)
132
{
133
	if (gid != MAGIC_GID) {
134
		errno = EPERM;
135
		return -1;
136
	}
137
138
	return 0;
139
}
140
141
int
142
setegid(gid_t egid)
143
{
144
	return setgid(egid);
145
}
146
147
int
148
initgroups(const char *user, gid_t group)
149
{
150
	errno = EPERM;
151
	return -1;
152
}
153
154
int
155
getgroups(int size, gid_t list[])
156
{
157
	return 0;
158
}
159
160
int
161
setgroups(size_t size, const gid_t *list)
162
{
163
	errno = EPERM;
164
	return -1;
165
}
166
167
#endif
(-)openbsd-compat/win32-pwd.h (+65 lines)
Added Link Here
1
/*
2
 * Copyright 2013 Pierre Ossman for Cendio AB
3
 *
4
 * Permission to use, copy, modify, and distribute this software for any
5
 * purpose with or without fee is hereby granted, provided that the above
6
 * copyright notice and this permission notice appear in all copies.
7
 *
8
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
 */
16
17
#ifndef _WIN32_PWD_H
18
#define _WIN32_PWD_H
19
20
#include "includes.h"
21
22
#ifdef WIN32
23
24
typedef unsigned long uid_t;
25
typedef unsigned long gid_t;
26
27
struct passwd {
28
	char   *pw_name;       /* username */
29
	char   *pw_passwd;     /* user password */
30
	uid_t   pw_uid;        /* user ID */
31
	gid_t   pw_gid;        /* group ID */
32
	char   *pw_gecos;      /* user information */
33
	char   *pw_dir;        /* home directory */
34
	char   *pw_shell;      /* shell program */
35
};
36
37
struct group {
38
	char   *gr_name;       /* group name */
39
	char   *gr_passwd;     /* group password */
40
	gid_t   gr_gid;        /* group ID */
41
	char  **gr_mem;        /* group members */
42
};
43
44
uid_t getuid(void);
45
uid_t geteuid(void);
46
47
int setuid(uid_t uid);
48
int seteuid(uid_t euid);
49
50
struct passwd *getpwnam(const char *name);
51
struct passwd *getpwuid(uid_t uid);
52
53
gid_t getgid(void);
54
gid_t getegid(void);
55
56
int setgid(gid_t gid);
57
int setegid(gid_t egid);
58
59
int initgroups(const char *user, gid_t group);
60
int getgroups(int size, gid_t list[]);
61
int setgroups(size_t size, const gid_t *list);
62
63
#endif /* WIN32 */
64
65
#endif /* _WIN32_PWD_H */
(-)openbsd-compat/win32-socket.c (+696 lines)
Added Link Here
1
/*
2
 * Copyright 2013 Pierre Ossman for Cendio AB
3
 *
4
 * Permission to use, copy, modify, and distribute this software for any
5
 * purpose with or without fee is hereby granted, provided that the above
6
 * copyright notice and this permission notice appear in all copies.
7
 *
8
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
 */
16
17
#include "includes.h"
18
19
#include "log.h"
20
21
#undef read
22
#undef write
23
24
#undef close
25
26
#undef accept
27
#undef bind
28
#undef connect
29
#undef gethostbyaddr
30
#undef gethostbyname
31
#undef gethostname
32
#undef getpeername
33
#undef getprotobyname
34
#undef getservbyname
35
#undef getsockopt
36
#undef getsockname
37
#undef listen
38
#undef setsockopt
39
#undef socket
40
41
#undef select
42
43
#ifdef WIN32
44
45
extern ssize_t win32_read_console(int fildes, void *buf, size_t nbyte);
46
extern int win32_filter_console_events(HANDLE console);
47
48
ssize_t
49
win32_read(int fildes, void *buf, size_t nbyte)
50
{
51
	int ret;
52
53
	if (isatty(fildes))
54
		return win32_read_console(fildes, buf, nbyte);
55
56
	ret = recv(fildes, buf, nbyte, 0);
57
	if (ret != SOCKET_ERROR)
58
		return ret;
59
60
	errno = WSAGetLastError();
61
62
	if ((errno != WSAENOTSOCK) && (errno != WSAEBADF)) {
63
		errno |= WIN32_ERRNO;
64
		return -1;
65
	}
66
67
	return read(fildes, buf, nbyte);
68
}
69
70
ssize_t
71
win32_write(int fildes, const void *buf, size_t nbyte)
72
{
73
	int ret;
74
75
	ret = send(fildes, buf, nbyte, 0);
76
	if (ret != SOCKET_ERROR)
77
		return ret;
78
79
	errno = WSAGetLastError();
80
81
	if ((errno != WSAENOTSOCK) && (errno != WSAEBADF)) {
82
		errno |= WIN32_ERRNO;
83
		return -1;
84
	}
85
86
	return write(fildes, buf, nbyte);
87
}
88
89
int
90
win32_close(int fd)
91
{
92
	int ret;
93
94
	if (win32_is_afunix(fd))
95
		return win32_afunix_close(fd);
96
97
	ret = closesocket(fd);
98
	if (ret != SOCKET_ERROR)
99
		return ret;
100
101
	errno = WSAGetLastError();
102
103
	if ((errno != WSAENOTSOCK) && (errno != WSAEBADF)) {
104
		errno |= WIN32_ERRNO;
105
		return -1;
106
	}
107
108
	return close(fd);
109
}
110
111
int
112
win32_accept(int socket, struct sockaddr *address, socklen_t *address_len)
113
{
114
	SOCKET ret;
115
116
	if (win32_is_afunix(socket))
117
		return win32_afunix_accept(socket, address, address_len);
118
119
	ret = accept(socket, address, address_len);
120
	if (ret == INVALID_SOCKET) {
121
		errno = WSAGetLastError() | WIN32_ERRNO;
122
		return -1;
123
	}
124
125
	return ret;
126
}
127
128
int
129
win32_bind(int socket, const struct sockaddr *address,
130
           socklen_t address_len)
131
{
132
	int ret;
133
134
	if (win32_is_afunix(socket))
135
		return win32_afunix_bind(socket, address, address_len);
136
137
	ret = bind(socket, address, address_len);
138
	if (ret == SOCKET_ERROR) {
139
		errno = WSAGetLastError() | WIN32_ERRNO;
140
		return -1;
141
	}
142
143
	return 0;
144
}
145
146
int
147
win32_connect(int socket, const struct sockaddr *address,
148
              socklen_t address_len)
149
{
150
	int ret;
151
152
	if (win32_is_afunix(socket))
153
		return win32_afunix_connect(socket, address, address_len);
154
155
	ret = connect(socket, address, address_len);
156
	if (ret == SOCKET_ERROR) {
157
		/*
158
		 * POSIX says that the proper errno for a connect()
159
		 * that cannot complete immediately is EINPROGRESS.
160
		 * Windows decides to send the standard EWOULDBLOCK.
161
		 */
162
		if (WSAGetLastError() == WSAEWOULDBLOCK)
163
			errno = WSAEINPROGRESS | WIN32_ERRNO;
164
		else
165
			errno = WSAGetLastError() | WIN32_ERRNO;
166
167
		return -1;
168
	}
169
170
	return 0;
171
}
172
173
struct hostent*
174
win32_gethostbyaddr(const void *addr, socklen_t len, int type)
175
{
176
	struct hostent *ret;
177
178
	ret = gethostbyaddr(addr, len, type);
179
	if (ret == NULL) {
180
		errno = WSAGetLastError() | WIN32_ERRNO;
181
		return NULL;
182
	}
183
184
	return ret;
185
}
186
187
struct hostent*
188
win32_gethostbyname(const char *name)
189
{
190
	struct hostent *ret;
191
192
	ret = gethostbyname(name);
193
	if (ret == NULL) {
194
		errno = WSAGetLastError() | WIN32_ERRNO;
195
		return NULL;
196
	}
197
198
	return ret;
199
}
200
201
int
202
win32_gethostname(char *name, size_t len)
203
{
204
	int ret;
205
206
	ret = gethostname(name, len);
207
	if (ret == SOCKET_ERROR) {
208
		errno = WSAGetLastError() | WIN32_ERRNO;
209
		return -1;
210
	}
211
212
	return 0;
213
}
214
215
int
216
win32_getpeername(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
217
{
218
	int ret;
219
220
	ret = getpeername(sockfd, addr, addrlen);
221
	if (ret == SOCKET_ERROR) {
222
		errno = WSAGetLastError() | WIN32_ERRNO;
223
		return -1;
224
	}
225
226
	return 0;
227
}
228
229
struct protoent*
230
win32_getprotobyname(const char *name)
231
{
232
	struct protoent *ret;
233
234
	ret = getprotobyname(name);
235
	if (ret == NULL) {
236
		errno = WSAGetLastError() | WIN32_ERRNO;
237
		return NULL;
238
	}
239
240
	return ret;
241
}
242
243
struct servent*
244
win32_getservbyname(const char *name, const char *proto)
245
{
246
	struct servent *ret;
247
248
	ret = getservbyname(name, proto);
249
	if (ret == NULL) {
250
		errno = WSAGetLastError() | WIN32_ERRNO;
251
		return NULL;
252
	}
253
254
	return ret;
255
}
256
257
int
258
win32_getsockopt(int sockfd, int level, int optname,
259
                 void *optval, socklen_t *optlen)
260
{
261
	int ret;
262
263
	ret = getsockopt(sockfd, level, optname, optval, optlen);
264
	if (ret == SOCKET_ERROR) {
265
		errno = WSAGetLastError() | WIN32_ERRNO;
266
		return -1;
267
	}
268
269
	return 0;
270
}
271
272
int
273
win32_getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
274
{
275
	int ret;
276
277
	ret = getsockname(sockfd, addr, addrlen);
278
	if (ret == SOCKET_ERROR) {
279
		errno = WSAGetLastError() | WIN32_ERRNO;
280
		return -1;
281
	}
282
283
	return 0;
284
}
285
286
int
287
win32_listen(int sockfd, int backlog)
288
{
289
	int ret;
290
291
	if (win32_is_afunix(sockfd))
292
		return win32_afunix_listen(sockfd, backlog);
293
294
	ret = listen(sockfd, backlog);
295
	if (ret == SOCKET_ERROR) {
296
		errno = WSAGetLastError() | WIN32_ERRNO;
297
		return -1;
298
	}
299
300
	return 0;
301
}
302
303
int
304
win32_setsockopt(int sockfd, int level, int optname,
305
                 const void *optval, socklen_t optlen)
306
{
307
	int ret;
308
309
	ret = setsockopt(sockfd, level, optname, optval, optlen);
310
	if (ret == SOCKET_ERROR) {
311
		errno = WSAGetLastError() | WIN32_ERRNO;
312
		return -1;
313
	}
314
315
	return 0;
316
}
317
318
int
319
win32_socket(int domain, int type, int protocol)
320
{
321
	SOCKET ret;
322
323
	if (domain == AF_UNIX)
324
		return win32_afunix_socket(domain, type, protocol);
325
326
	ret = socket(domain, type, protocol);
327
	if (ret == INVALID_SOCKET) {
328
		errno = WSAGetLastError() | WIN32_ERRNO;
329
		return -1;
330
	}
331
332
	return ret;
333
}
334
335
typedef struct fd_events {
336
	SOCKET fd;
337
	long events;
338
} fd_events;
339
340
typedef struct fd_event_set {
341
	u_int fd_count;
342
	fd_events fd_array[128];
343
} fd_event_set;
344
345
static void
346
build_fd_event(fd_event_set *events, fd_set *readfds, fd_set *writefds,
347
               fd_set *exceptfds)
348
{
349
	u_int i, j;
350
	fd_events *ev;
351
352
	events->fd_count = 0;
353
354
	if (readfds != NULL) {
355
		for (i = 0;i < readfds->fd_count;i++) {
356
			ev = &events->fd_array[events->fd_count++];
357
			ev->fd = readfds->fd_array[i];
358
			ev->events = FD_READ | FD_ACCEPT | FD_CLOSE;
359
		}
360
	}
361
362
	if (writefds != NULL) {
363
		for (i = 0;i < writefds->fd_count;i++) {
364
			for (j = 0;j < events->fd_count;j++) {
365
				ev = &events->fd_array[j];
366
				if (ev->fd == writefds->fd_array[i])
367
					break;
368
			}
369
370
			if (j == events->fd_count) {
371
				ev = &events->fd_array[events->fd_count++];
372
				ev->fd = writefds->fd_array[i];
373
				ev->events = 0;
374
			}
375
376
			ev->events |= FD_WRITE | FD_CONNECT;
377
		}
378
	}
379
}
380
381
static int
382
win32_wait(fd_set *readfds, fd_set *writefds,
383
           fd_set *exceptfds, struct timeval *timeout)
384
{
385
	int ret;
386
	u_int i;
387
388
	struct timeval no_timeout = {0, 0};
389
390
	fd_event_set events;
391
	WSAEVENT socket_event;
392
393
	int has_console, has_fifo;
394
395
	HANDLE handles[2];
396
	DWORD dwtimeout, pipe_timeout;
397
398
	has_console = 0;
399
	has_fifo = 0;
400
401
	/* Start by assembling the three lists into one */
402
	build_fd_event(&events, readfds, writefds, exceptfds);
403
404
	/*
405
	 * Now we need to check for pre-existing states, which only
406
	 * the good ol' select() can do.
407
	 */
408
	if (readfds != NULL) {
409
		for (i = 0;i < readfds->fd_count;i++) {
410
			if (isatty(readfds->fd_array[i]))
411
				has_console = 1;
412
			else if (isafifo(readfds->fd_array[i]))
413
				has_fifo = 1;
414
			else
415
				continue;
416
			FD_CLR(readfds->fd_array[i], readfds);
417
			i--;
418
		}
419
	}
420
	if (writefds != NULL) {
421
		for (i = 0;i < writefds->fd_count;i++) {
422
			if (isatty(writefds->fd_array[i]) ||
423
			    isafifo(writefds->fd_array[i])) {
424
				FD_CLR(writefds->fd_array[i], writefds);
425
				i--;
426
			}
427
		}
428
	}
429
	if (exceptfds != NULL) {
430
		for (i = 0;i < exceptfds->fd_count;i++) {
431
			if (isatty(exceptfds->fd_array[i]) ||
432
			    isafifo(exceptfds->fd_array[i])) {
433
				FD_CLR(exceptfds->fd_array[i], exceptfds);
434
				i--;
435
			}
436
		}
437
	}
438
439
	ret = select(0, readfds, writefds, exceptfds, &no_timeout);
440
	if (ret > 0)
441
		return ret;
442
	if (ret == SOCKET_ERROR) {
443
		errno = WSAGetLastError() | WIN32_ERRNO;
444
		return -1;
445
	}
446
447
	/* Don't need these anymore */
448
	if (readfds != NULL)
449
		FD_ZERO(readfds);
450
	if (writefds != NULL)
451
		FD_ZERO(writefds);
452
	if (exceptfds != NULL)
453
		FD_ZERO(exceptfds);
454
455
	/* Connect an event to all sockets */
456
	socket_event = WSACreateEvent();
457
458
	for (i = 0;i < events.fd_count;i++) {
459
		if (isatty(events.fd_array[i].fd) ||
460
		    isafifo(events.fd_array[i].fd))
461
			continue;
462
463
		ret = WSAEventSelect(events.fd_array[i].fd, socket_event,
464
		                     events.fd_array[i].events);
465
		if (ret == SOCKET_ERROR) {
466
			errno = WSAGetLastError() | WIN32_ERRNO;
467
			ret = -1;
468
			goto end;
469
		}
470
	}
471
472
	handles[0] = socket_event;
473
	handles[1] = GetStdHandle(STD_INPUT_HANDLE);
474
475
	if (timeout == NULL)
476
		dwtimeout = INFINITE;
477
	else
478
		dwtimeout = timeout->tv_sec * 1000 + timeout->tv_usec / 1000;
479
480
	pipe_timeout = 100;
481
482
	/*
483
	 * It is impossible to get events for pipes, so we have to resort
484
	 * to polling if we have one in the list. We start by polling
485
	 * rapidly and gradually back off to at least a 1 second delay.
486
	 * This is done to quickly respond to interactive periods, yet
487
	 * still sleep properly during idle times.
488
	 */
489
	do {
490
		DWORD iter_timeout;
491
492
		iter_timeout = dwtimeout;
493
494
		if (has_fifo) {
495
			for (i = 0;i < events.fd_count;i++) {
496
				HANDLE handle;
497
				DWORD avail;
498
499
				if (!isafifo(events.fd_array[i].fd))
500
					continue;
501
502
				if (!(events.fd_array[i].events & FD_READ))
503
					continue;
504
505
				handle = (HANDLE)_get_osfhandle(events.fd_array[i].fd);
506
				if (!PeekNamedPipe(handle, NULL, 0, NULL, &avail, NULL)) {
507
					errno = GetLastError() | WIN32_ERRNO;
508
					ret = -1;
509
					goto end;
510
				}
511
512
				if (avail == 0)
513
					continue;
514
515
				FD_SET(events.fd_array[i].fd, readfds);
516
			}
517
518
			if (readfds->fd_count > 0) {
519
				ret = readfds->fd_count;
520
				goto end;
521
			}
522
523
			if (iter_timeout > pipe_timeout)
524
				iter_timeout = pipe_timeout;
525
			if (dwtimeout != INFINITE)
526
				dwtimeout -= iter_timeout;
527
			if (pipe_timeout < 1000)
528
				pipe_timeout *= 2;
529
		}
530
531
		/* Now do the actual wait...*/
532
		ret = WaitForMultipleObjects(has_console ? 2 : 1, handles,
533
		                             FALSE, iter_timeout);
534
	} while (has_fifo && (ret == WAIT_TIMEOUT) && (dwtimeout > 0));
535
536
	if (ret == WAIT_FAILED) {
537
		errno = GetLastError() | WIN32_ERRNO;
538
		ret = -1;
539
		goto end;
540
	}
541
542
	if (ret == WAIT_TIMEOUT) {
543
		ret = 0;
544
		goto end;
545
	}
546
547
	/* We got something on stdin... */
548
	if (ret == (WAIT_OBJECT_0 + 1)) {
549
		/*
550
		 * stdin will signal on a lot of non-data events, so
551
		 * we need to filter out that crud.
552
		 */
553
		ret = win32_filter_console_events(GetStdHandle(STD_INPUT_HANDLE));
554
		if (ret <= 0)
555
			goto end;
556
557
		for (i = 0;i < events.fd_count;i++) {
558
			if (!isatty(events.fd_array[i].fd))
559
				continue;
560
561
			if (!(events.fd_array[i].events & FD_READ))
562
				continue;
563
564
			FD_SET(events.fd_array[i].fd, readfds);
565
		}
566
567
		ret = readfds->fd_count;
568
		goto end;
569
	}
570
571
	/* We got something on a socket. Figure out what... */
572
	for (i = 0;i < events.fd_count;i++) {
573
		WSANETWORKEVENTS net_events;
574
575
		if (isatty(events.fd_array[i].fd) ||
576
		    isafifo(events.fd_array[i].fd))
577
			continue;
578
579
		ret = WSAEnumNetworkEvents(events.fd_array[i].fd,
580
		                           socket_event, &net_events);
581
		if (ret == SOCKET_ERROR) {
582
			errno = WSAGetLastError() | WIN32_ERRNO;
583
			ret = -1;
584
			goto end;
585
		}
586
587
		if (readfds != NULL) {
588
			if (net_events.lNetworkEvents & events.fd_array[i].events &
589
			    (FD_READ | FD_ACCEPT | FD_CLOSE))
590
				FD_SET(events.fd_array[i].fd, readfds);
591
		}
592
593
		if (writefds != NULL) {
594
			if (net_events.lNetworkEvents & events.fd_array[i].events &
595
			    (FD_WRITE | FD_CONNECT))
596
				FD_SET(events.fd_array[i].fd, writefds);
597
		}
598
	}
599
600
	/* Sum up the number of signalled sockets */
601
	ret = 0;
602
	if (readfds != NULL)
603
		ret += readfds->fd_count;
604
	if (writefds != NULL)
605
		ret += writefds->fd_count;
606
	if (exceptfds != NULL)
607
		ret += exceptfds->fd_count;
608
609
end:
610
	/*
611
	 * Undocumented misfeature of the week: having an event
612
	 * connected to a socket makes accept() return WSEANOTSOCK.
613
	 * Make sure we clear the event from all sockets before
614
	 * returning.
615
	 */
616
	for (i = 0;i < events.fd_count;i++) {
617
		int local_ret;
618
619
		if (isatty(events.fd_array[i].fd) ||
620
		    isafifo(events.fd_array[i].fd))
621
			continue;
622
623
		local_ret = WSAEventSelect(events.fd_array[i].fd, NULL, 0);
624
		if (local_ret == SOCKET_ERROR) {
625
			error("WSAEventSelect(%d, NULL, 0): %s",
626
			      events.fd_array[i].fd,
627
			      win32_strerror(WSAGetLastError() | WIN32_ERRNO));
628
		}
629
	}
630
631
	CloseHandle(socket_event);
632
633
	return ret;
634
}
635
636
637
int
638
win32_select(int nfds, fd_set *readfds, fd_set *writefds,
639
             fd_set *exceptfds, struct timeval *timeout)
640
{
641
	int ret;
642
	u_int i;
643
644
	/*
645
	 * There is no select() equivalent for writing non-sockets so we need
646
	 * to check for that first and assume they are always writable.
647
	 */
648
	if (writefds != NULL) {
649
		for (i = 0;i < writefds->fd_count;i++) {
650
			if (isatty(writefds->fd_array[i]) ||
651
			    isafifo(writefds->fd_array[i]))
652
				break;
653
		}
654
655
		if (i != writefds->fd_count) {
656
			fd_set newwr;
657
658
			FD_ZERO(&newwr);
659
660
			for (;i < writefds->fd_count;i++) {
661
				if (isatty(writefds->fd_array[i]) ||
662
				    isafifo(writefds->fd_array[i]))
663
					FD_SET(writefds->fd_array[i], &newwr);
664
			}
665
666
			if (readfds != NULL)
667
				FD_ZERO(readfds);
668
			if (writefds != NULL)
669
				FD_ZERO(writefds);
670
			if (exceptfds != NULL)
671
				FD_ZERO(exceptfds);
672
673
			memcpy(writefds, &newwr, sizeof(fd_set));
674
675
			return writefds->fd_count;
676
		}
677
	}
678
679
	/* Need to use more Windows specific APIs when dealing with non-sockets */
680
	if (readfds != NULL) {
681
		for (i = 0;i < readfds->fd_count;i++) {
682
			if (isatty(readfds->fd_array[i]) ||
683
			    isafifo(readfds->fd_array[i]))
684
				return win32_wait(readfds, writefds, exceptfds, timeout);
685
		}
686
	}
687
688
	ret = select(nfds, readfds, writefds, exceptfds, timeout);
689
690
	if (ret == SOCKET_ERROR)
691
		errno = WSAGetLastError() | WIN32_ERRNO;
692
693
	return ret;
694
}
695
696
#endif /* WIN32 */
(-)openbsd-compat/win32-socket.h (+86 lines)
Added Link Here
1
/*
2
 * Copyright 2013 Pierre Ossman for Cendio AB
3
 *
4
 * Permission to use, copy, modify, and distribute this software for any
5
 * purpose with or without fee is hereby granted, provided that the above
6
 * copyright notice and this permission notice appear in all copies.
7
 *
8
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
 */
16
17
#ifndef _WIN32_SOCKET_H
18
#define _WIN32_SOCKET_H
19
20
#include "includes.h"
21
22
#ifdef WIN32
23
24
#define EPFNOSUPPORT	(WSAEPFNOSUPPORT | WIN32_ERRNO)
25
#define EAFNOSUPPORT	(WSAEAFNOSUPPORT | WIN32_ERRNO)
26
#define EADDRINUSE	(WSAEADDRINUSE | WIN32_ERRNO)
27
#define ECONNABORTED	(WSAECONNABORTED | WIN32_ERRNO)
28
#define ECONNRESET	(WSAECONNRESET | WIN32_ERRNO)
29
#define ENOTCONN	(WSAENOTCONN | WIN32_ERRNO)
30
#define ETIMEDOUT	(WSAETIMEDOUT | WIN32_ERRNO)
31
#define ECONNREFUSED	(WSAECONNREFUSED | WIN32_ERRNO)
32
#define EHOSTUNREACH	(WSAEHOSTUNREACH | WIN32_ERRNO)
33
#define EINPROGRESS	(WSAEINPROGRESS | WIN32_ERRNO)
34
35
#define read		win32_read
36
#define write		win32_write
37
38
ssize_t win32_read(int fildes, void *buf, size_t nbyte);
39
ssize_t win32_write(int fildes, const void *buf, size_t nbyte);
40
41
#define close		win32_close
42
43
int win32_close(int fd);
44
45
#define accept		win32_accept
46
#define bind		win32_bind
47
#define connect		win32_connect
48
#define gethostbyaddr	win32_gethostbyaddr
49
#define gethostbyname	win32_gethostbyname
50
#define gethostname	win32_gethostname
51
#define getpeername	win32_getpeername
52
#define getprotobyname	win32_getprotobyname
53
#define getservbyname	win32_getservbyname
54
#define getsockopt	win32_getsockopt
55
#define getsockname	win32_getsockname
56
#define listen		win32_listen
57
#define setsockopt	win32_setsockopt
58
#define socket		win32_socket
59
60
int win32_accept(int socket, struct sockaddr *address, socklen_t *address_len);
61
int win32_bind(int socket, const struct sockaddr *address,
62
               socklen_t address_len);
63
int win32_connect(int socket, const struct sockaddr *address,
64
                  socklen_t address_len);
65
struct hostent *win32_gethostbyaddr(const void *addr, socklen_t len, int type);
66
struct hostent *win32_gethostbyname(const char *name);
67
int win32_gethostname(char *name, size_t len);
68
int win32_getpeername(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
69
struct protoent *win32_getprotobyname(const char *name);
70
struct servent *win32_getservbyname(const char *name, const char *proto);
71
int win32_getsockopt(int sockfd, int level, int optname,
72
                     void *optval, socklen_t *optlen);
73
int win32_getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
74
int win32_listen(int sockfd, int backlog);
75
int win32_setsockopt(int sockfd, int level, int optname,
76
                     const void *optval, socklen_t optlen);
77
int win32_socket(int domain, int type, int protocol);
78
79
#define select		win32_select
80
81
int win32_select(int nfds, fd_set *readfds, fd_set *writefds,
82
                 fd_set *exceptfds, struct timeval *timeout);
83
84
#endif /* WIN32 */
85
86
#endif /* _WIN32_SOCKET_H */
(-)openbsd-compat/win32-sspi.c (+558 lines)
Added Link Here
1
/*
2
 * Copyright 2013 Aaron Sowry for Cendio AB
3
 *
4
 * Permission to use, copy, modify, and distribute this software for any
5
 * purpose with or without fee is hereby granted, provided that the above
6
 * copyright notice and this permission notice appear in all copies.
7
 *
8
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
 */
16
17
#include "includes.h"
18
19
#if defined(WIN32)
20
#include <string.h>
21
#include <security.h>
22
#include <xmalloc.h>
23
24
#include "win32-sspi.h"
25
26
static gss_OID_desc _GSS_C_NT_HOSTBASED_SERVICE = {10, (void *)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x04"};
27
gss_OID GSS_C_NT_HOSTBASED_SERVICE = &_GSS_C_NT_HOSTBASED_SERVICE;
28
29
static gss_OID_desc _GSS_MECH_KRB5 = {9, (void *)"\x2A\x86\x48\x86\xF7\x12\x01\x02\x02"};
30
static gss_OID GSS_MECH_KRB5 = &_GSS_MECH_KRB5;
31
32
struct gss_ctx_id_struct {
33
	CtxtHandle *ctxt_handle;
34
	CredHandle *cred_handle;
35
};
36
37
OM_uint32 gss_display_status (
38
        OM_uint32      *minor_status,
39
        OM_uint32      status_value,
40
        int            status_type,
41
        const gss_OID  mech_type,
42
        OM_uint32      *message_context,
43
        gss_buffer_t   status_string)
44
{
45
	OM_uint32 tmp;
46
	char *msg;
47
48
	if (status_string == NULL || message_context == NULL)
49
		return GSS_S_FAILURE;
50
51
	status_string->length = 0;
52
	status_string->value = NULL;
53
54
	if (minor_status != NULL)
55
		*minor_status = 0;
56
57
	// XXX: Since this is Windows-specific, we are assuming
58
	//      a mech_type of GSS_MECH_KRB5.
59
60
	if (status_type == GSS_C_GSS_CODE) {
61
		// Major status
62
		if (status_value == 0) {
63
			*message_context = 0;
64
			return GSS_S_BAD_STATUS;
65
		}
66
67
		// Routine error
68
		if (*message_context == 0) {
69
			if ((tmp = GSS_ROUTINE_ERROR(status_value))) {
70
				status_value -= tmp;
71
				switch (tmp) {
72
					case GSS_S_FAILURE:
73
						msg = "Unspecified GSS failure. Minor code may provide more information";
74
						break;
75
					case GSS_S_BAD_MECH:
76
						msg = "An unsupported mechanism was requested";
77
						break;
78
					case GSS_S_BAD_NAME:
79
						msg = "An invalid name was supplied";
80
						break;
81
					case GSS_S_BAD_NAMETYPE:
82
						msg = "A supplied name was of an unsupported type";
83
						break;
84
					case GSS_S_BAD_BINDINGS:
85
						msg = "Incorrect channel bindings were supplied";
86
						break;
87
					case GSS_S_BAD_SIG:
88
						msg = "A token had an invalid Message Integrity Check (MIC)";
89
						break;
90
					case GSS_S_NO_CRED:
91
						msg = "No credentials were supplied, or the credentials were unavailable or inaccessible";
92
						break;
93
					case GSS_S_NO_CONTEXT:
94
						msg = "No context has been established";
95
						break;
96
					case GSS_S_DEFECTIVE_TOKEN:
97
						msg = "Invalid token was supplied";
98
						break;
99
					case GSS_S_DEFECTIVE_CREDENTIAL:
100
						msg = "Invalid credential was supplied";
101
						break;
102
					case GSS_S_CREDENTIALS_EXPIRED:
103
						msg = "The referenced credential has expired";
104
						break;
105
					case GSS_S_CONTEXT_EXPIRED:
106
						msg = "The referenced context has expired";
107
						break;
108
					case GSS_S_BAD_QOP:
109
						msg = "The quality-of-protection (QOP) requested could not be provided";
110
						break;
111
					case GSS_S_UNAUTHORIZED:
112
						msg = "The operation is forbidden by local security policy";
113
						break;
114
					case GSS_S_UNAVAILABLE:
115
						msg = "The operation or option is not available or unsupported";
116
						break;
117
					case GSS_S_DUPLICATE_ELEMENT:
118
						msg = "The requested credential element already exists";
119
						break;
120
					case GSS_S_NAME_NOT_MN:
121
						msg = "The provided name was not mechanism specific (MN)";
122
						break;
123
					case GSS_S_BAD_STATUS:
124
					default:
125
						msg = "An invalid status code was supplied";
126
				}
127
				status_string->length = strlen(msg);
128
				status_string->value = xstrdup(msg);
129
				if (status_value) {
130
					(*message_context)++;
131
					return GSS_S_COMPLETE;
132
				}
133
				else {
134
					*message_context = 0;
135
					return GSS_S_COMPLETE;
136
				}
137
			}
138
			else
139
				(*message_context)++;
140
		}
141
		else
142
			status_value -= GSS_ROUTINE_ERROR(status_value);
143
		
144
		// Calling error
145
		if (*message_context == 1) {
146
			if ((tmp = GSS_CALLING_ERROR(status_value))) {
147
				status_value -= tmp;
148
				switch (tmp) {
149
					case GSS_S_CALL_INACCESSIBLE_READ:
150
						msg = "A required input parameter could not be read";
151
						break;
152
					case GSS_S_CALL_INACCESSIBLE_WRITE:
153
						msg = "A required input parameter could not be written";
154
						break;
155
					case GSS_S_CALL_BAD_STRUCTURE:
156
						msg = "A parameter was malformed";
157
						break;
158
					default:
159
						msg = "An invalid status code was supplied";
160
				}
161
				status_string->length = strlen(msg);
162
				status_string->value = xstrdup(msg);
163
				if (status_value) {
164
					(*message_context)++;
165
					return GSS_S_COMPLETE;
166
				}
167
				else {
168
					*message_context = 0;
169
					return GSS_S_COMPLETE;
170
				}
171
			}
172
			else
173
				(*message_context)++;
174
		}
175
		else
176
			status_value -= GSS_CALLING_ERROR(status_value);
177
178
		// FIXME: Check supplimentary info bits as well
179
180
	}
181
	else if (status_type == GSS_C_MECH_CODE) {
182
		// Minor status
183
		if (*message_context)
184
			return GSS_S_FAILURE;
185
186
		switch (status_value) {
187
			// FIXME: We don't set a minor code on Windows
188
			default:
189
				msg = "No minor code available";
190
		}
191
		status_string->length = strlen(msg);
192
		status_string->value = msg;
193
194
		return GSS_S_COMPLETE;
195
	}
196
	else
197
		return GSS_S_BAD_STATUS;
198
199
	return GSS_S_COMPLETE;
200
201
};
202
203
OM_uint32 gss_release_buffer (
204
        OM_uint32    *minor_status,
205
        gss_buffer_t buffer)
206
{
207
	if (minor_status != NULL)
208
		*minor_status = 0;
209
210
	if (buffer == GSS_C_NO_BUFFER)
211
		return GSS_S_COMPLETE;
212
213
	if (buffer->value) {
214
		xfree(buffer->value);
215
		buffer->value = NULL;
216
		buffer->length = 0;
217
	}
218
219
	return GSS_S_COMPLETE;
220
221
};
222
223
OM_uint32 gss_delete_sec_context (
224
        OM_uint32    *minor_status,
225
        gss_ctx_id_t *context_handle,
226
        gss_buffer_t output_token)
227
{
228
	if (minor_status != NULL)
229
		*minor_status = 0;
230
231
	if (context_handle == NULL || *context_handle == GSS_C_NO_CONTEXT)
232
		return GSS_S_NO_CONTEXT;
233
234
	int ret;
235
	ret = DeleteSecurityContext((*context_handle)->ctxt_handle);
236
237
	if (ret == SEC_E_OK) {
238
		if ((*context_handle)->cred_handle)
239
			xfree((*context_handle)->cred_handle);
240
		xfree(*context_handle);
241
		*context_handle = GSS_C_NO_CONTEXT;
242
		return GSS_S_COMPLETE;
243
	}
244
245
	return GSS_S_FAILURE;
246
247
};
248
249
OM_uint32 gss_release_name (
250
        OM_uint32  *minor_status,
251
        gss_name_t *name)
252
{
253
	if (minor_status != NULL)
254
		*minor_status = 0;
255
256
	if (name == NULL)
257
		return GSS_S_BAD_NAME;
258
259
	if (*name == GSS_C_NO_NAME)
260
		return GSS_S_COMPLETE;
261
262
	xfree(*name);
263
	*name = GSS_C_NO_NAME;
264
265
	return GSS_S_COMPLETE;
266
267
};
268
269
OM_uint32 gss_release_cred (
270
        OM_uint32     *minor_status,
271
        gss_cred_id_t *cred_handle)
272
{
273
	if (minor_status != NULL)
274
		*minor_status = 0;
275
276
	if (cred_handle == NULL)
277
		return GSS_S_NO_CRED;
278
279
	if (*cred_handle == GSS_C_NO_CREDENTIAL)
280
		return GSS_S_COMPLETE;
281
282
	if (*cred_handle)
283
		xfree(*cred_handle);
284
	*cred_handle = GSS_C_NO_CREDENTIAL;
285
286
	return GSS_S_COMPLETE;
287
288
};
289
290
OM_uint32 gss_init_sec_context (
291
        OM_uint32              *minor_status,
292
        gss_cred_id_t          initiator_cred_handle,
293
        gss_ctx_id_t           *context_handle,
294
        gss_name_t             target_name,
295
        gss_OID                mech_type,
296
        OM_uint32              req_flags,
297
        OM_uint32              time_req,
298
        gss_channel_bindings_t input_chan_bindings,
299
        gss_buffer_t           input_token,
300
        gss_OID                *actual_mech_type,
301
        gss_buffer_t           output_token,
302
        OM_uint32              *ret_flags,
303
        OM_uint32              *time_rec)
304
{
305
	int ret;
306
307
	if (minor_status == NULL)
308
		return GSS_S_FAILURE | GSS_S_CALL_INACCESSIBLE_WRITE;
309
310
	*minor_status = 0;
311
312
	// Set up context handles
313
	PCtxtHandle phContext = NULL;
314
315
	if (*context_handle == GSS_C_NO_CONTEXT) {
316
		// This is the first call to gss_init_sec_context
317
		*context_handle = (gss_ctx_id_t) xcalloc(1, sizeof(gss_ctx_id_t));
318
		(*context_handle)->cred_handle = (CredHandle*) xmalloc(sizeof(CredHandle));
319
320
		TimeStamp ptsExpiry;
321
		ret = AcquireCredentialsHandle(NULL,
322
		                               "Kerberos",
323
		                               SECPKG_CRED_OUTBOUND,
324
		                               NULL,
325
		                               NULL,
326
		                               NULL,
327
		                               NULL,
328
		                               (*context_handle)->cred_handle,
329
		                               &ptsExpiry);
330
331
	   if (ret != SEC_E_OK) {
332
		   xfree((*context_handle)->cred_handle);
333
		   xfree(*context_handle);
334
		   *context_handle = GSS_C_NO_CONTEXT;
335
336
		   if (ret == SEC_E_NO_CREDENTIALS ||
337
			   ret == SEC_E_UNKNOWN_CREDENTIALS)
338
			   return GSS_S_NO_CRED;
339
340
		   return GSS_S_FAILURE;
341
	   }
342
	}
343
	else
344
		phContext = (*context_handle)->ctxt_handle;
345
346
	// Set up input buffer
347
	SecBufferDesc pInput;
348
	SecBuffer input_buffer;
349
350
	if (input_token == GSS_C_NO_BUFFER) {
351
		input_buffer.cbBuffer = 0;
352
		input_buffer.pvBuffer = NULL;
353
		input_buffer.BufferType = SECBUFFER_TOKEN;
354
	}
355
	else {
356
		input_buffer.cbBuffer = input_token->length;
357
		input_buffer.pvBuffer = input_token->value;
358
		input_buffer.BufferType = SECBUFFER_TOKEN;
359
	}
360
361
	pInput.cBuffers = 1;
362
	pInput.pBuffers = &input_buffer;
363
	pInput.ulVersion = SECBUFFER_VERSION;
364
365
	// Set up output buffer
366
	SecBufferDesc pOutput;
367
	SecBuffer output_buffer;
368
369
	// Allocate our own token buffer
370
	PSecPkgInfo PackageInfo;
371
	QuerySecurityPackageInfo("Kerberos", &PackageInfo);
372
373
	output_buffer.cbBuffer = PackageInfo->cbMaxToken;
374
	output_buffer.pvBuffer = xmalloc(PackageInfo->cbMaxToken);
375
	output_buffer.BufferType = SECBUFFER_TOKEN;
376
377
	pOutput.cBuffers = 1;
378
	pOutput.pBuffers = &output_buffer;
379
	pOutput.ulVersion = SECBUFFER_VERSION;
380
381
	// Set up context attributes handle
382
	unsigned long pfContextAttr;
383
384
	// Set up flags
385
	unsigned long flags = ISC_REQ_MUTUAL_AUTH|ISC_REQ_REPLAY_DETECT|
386
	                      ISC_REQ_CONFIDENTIALITY;
387
388
	if (req_flags & GSS_C_DELEG_FLAG)
389
		flags |= ISC_REQ_DELEGATE;
390
391
	if ((*context_handle)->ctxt_handle == NULL)
392
		(*context_handle)->ctxt_handle = (CtxtHandle*) xmalloc(sizeof(CtxtHandle));
393
394
	ret = InitializeSecurityContext((*context_handle)->cred_handle,
395
	                                phContext,
396
	                                (char *) target_name,
397
	                                flags,
398
	                                0, // Reserved
399
	                                SECURITY_NATIVE_DREP,
400
	                                &pInput,
401
	                                0, // Reserved
402
	                                (*context_handle)->ctxt_handle,
403
	                                &pOutput,
404
	                                &pfContextAttr,
405
	                                NULL);
406
407
	if (ret_flags != NULL)
408
		if (pfContextAttr & ISC_RET_INTEGRITY)
409
			*ret_flags |= GSS_C_INTEG_FLAG;
410
411
	// FIXME: Check that the correct token type was received
412
	output_token->length = output_buffer.cbBuffer;
413
	output_token->value = output_buffer.pvBuffer;
414
415
	if (ret == SEC_I_CONTINUE_NEEDED)
416
		return GSS_S_CONTINUE_NEEDED;
417
	else if (ret == SEC_E_OK)
418
		return GSS_S_COMPLETE;
419
420
	return GSS_S_FAILURE;
421
422
};
423
424
OM_uint32 gss_import_name (
425
        OM_uint32          *minor_status,
426
        const gss_buffer_t input_name_buffer,
427
        const gss_OID      input_name_type,
428
        gss_name_t         *output_name)
429
{
430
	if (minor_status == NULL)
431
		return GSS_S_FAILURE | GSS_S_CALL_INACCESSIBLE_WRITE;
432
433
	*minor_status = 0;
434
435
	if (output_name == NULL)
436
		return GSS_S_FAILURE | GSS_S_CALL_INACCESSIBLE_WRITE;
437
438
	char *sspi_name;
439
440
	if (input_name_type == GSS_C_NT_HOSTBASED_SERVICE) {
441
		char buf[1024];
442
		char host[1024];
443
		char *ch;
444
445
		if (input_name_buffer->length + 1 > sizeof(buf))
446
			return GSS_S_BAD_NAME;
447
448
		memcpy(buf, input_name_buffer->value, input_name_buffer->length);
449
		buf[input_name_buffer->length] = '\0';
450
		ch = strchr(buf, '@');
451
452
		if (ch == NULL)
453
			return GSS_S_BAD_NAME;
454
455
		strcpy(host, ch+1);
456
457
		xasprintf(&sspi_name, "host/%s", host);
458
	}
459
	else
460
		// Unsupported name type
461
		return GSS_S_BAD_NAMETYPE;
462
463
	*output_name = (gss_name_t) sspi_name;
464
465
	return GSS_S_COMPLETE;
466
467
};
468
469
OM_uint32 gss_get_mic (
470
        OM_uint32          *minor_status,
471
        const gss_ctx_id_t context_handle,
472
        gss_qop_t          qop_req,
473
        const gss_buffer_t message_buffer,
474
        gss_buffer_t       msg_token)
475
{
476
	if (minor_status == NULL)
477
		return GSS_S_FAILURE | GSS_S_CALL_INACCESSIBLE_WRITE;
478
	   
479
	*minor_status = 0;
480
481
	if (msg_token == NULL)
482
		return GSS_S_FAILURE | GSS_S_CALL_INACCESSIBLE_WRITE;
483
484
	if (message_buffer == NULL)
485
		return GSS_S_FAILURE | GSS_S_CALL_INACCESSIBLE_READ;
486
487
	if (context_handle == GSS_C_NO_CONTEXT)
488
		return GSS_S_NO_CONTEXT;
489
490
	SecPkgContext_Sizes ContextSizes;
491
	memset(&ContextSizes, 0, sizeof(ContextSizes));
492
493
	SecBufferDesc InputBufferDescriptor;
494
	SecBuffer InputSecurityToken[2];
495
496
	int ret;
497
	ret = QueryContextAttributes(context_handle->ctxt_handle,
498
	                             SECPKG_ATTR_SIZES,
499
	                             &ContextSizes);
500
501
	if (ret != SEC_E_OK || ContextSizes.cbMaxSignature == 0)
502
		return GSS_S_FAILURE;
503
504
	InputBufferDescriptor.cBuffers = 2;
505
	InputBufferDescriptor.pBuffers = InputSecurityToken;
506
	InputBufferDescriptor.ulVersion = SECBUFFER_VERSION;
507
	InputSecurityToken[0].BufferType = SECBUFFER_DATA;
508
	InputSecurityToken[0].cbBuffer = message_buffer->length;
509
	InputSecurityToken[0].pvBuffer = message_buffer->value;
510
	InputSecurityToken[1].BufferType = SECBUFFER_TOKEN;
511
	InputSecurityToken[1].cbBuffer = ContextSizes.cbMaxSignature;
512
	InputSecurityToken[1].pvBuffer = xmalloc(ContextSizes.cbMaxSignature * sizeof(char));
513
514
	ret = MakeSignature(context_handle->ctxt_handle,
515
	                    0,
516
	                    &InputBufferDescriptor,
517
	                    0);
518
519
	if (ret == SEC_E_OK) {
520
		msg_token->length = InputSecurityToken[1].cbBuffer;
521
		msg_token->value = InputSecurityToken[1].pvBuffer;
522
		return GSS_S_COMPLETE;
523
	}
524
525
	return GSS_S_FAILURE;
526
527
};
528
529
OM_uint32 gss_indicate_mechs (
530
        OM_uint32   *minor_status,
531
        gss_OID_set *mech_set)
532
{
533
	gss_OID_set set;
534
535
	if (minor_status != NULL)
536
		*minor_status = 0;
537
538
	if (mech_set == NULL)
539
		return GSS_S_CALL_INACCESSIBLE_WRITE;
540
541
	set = (gss_OID_set_desc *) xcalloc(1, sizeof(*set));
542
543
	/* We're only providing a single mech */
544
	set->count = 1;
545
546
	set->elements = (gss_OID_desc *) xcalloc(set->count, sizeof(*set->elements));
547
548
	set->elements[0].length = GSS_MECH_KRB5->length;
549
	set->elements[0].elements = xmalloc(GSS_MECH_KRB5->length);
550
551
	memcpy(set->elements[0].elements, GSS_MECH_KRB5->elements, GSS_MECH_KRB5->length);
552
553
	*mech_set = set;
554
555
	return GSS_S_COMPLETE;
556
};
557
558
#endif /* WIN32 */
(-)openbsd-compat/win32-sspi.h (+352 lines)
Added Link Here
1
/*
2
 * Copyright 2013 Aaron Sowry for Cendio AB
3
 *
4
 * Permission to use, copy, modify, and distribute this software for any
5
 * purpose with or without fee is hereby granted, provided that the above
6
 * copyright notice and this permission notice appear in all copies.
7
 *
8
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
 */
16
17
#ifndef _WIN32_SSPI_H
18
#define _WIN32_SSPI_H
19
20
#include "includes.h"
21
22
#ifdef WIN32
23
#include <stdint.h>
24
#include <inttypes.h>
25
26
/*
27
 * First, include stddef.h to get size_t defined.
28
 */
29
#include <stddef.h>
30
31
/*
32
 * POSIX says that sys/types.h is where size_t is defined.
33
 */
34
#include <sys/types.h>
35
36
/*
37
 * First, define the three platform-dependent pointer types.
38
 */
39
struct gss_name_struct;
40
typedef struct gss_name_struct * gss_name_t;
41
42
struct gss_cred_id_struct;
43
typedef struct gss_cred_id_struct * gss_cred_id_t;
44
45
struct gss_ctx_id_struct;
46
typedef struct gss_ctx_id_struct * gss_ctx_id_t;
47
48
/*
49
 * The following type must be defined as the smallest natural unsigned integer
50
 * supported by the platform that has at least 32 bits of precision.
51
 */
52
typedef uint32_t gss_uint32;
53
typedef int32_t gss_int32;
54
55
#ifdef OM_STRING
56
/*
57
 * We have included the xom.h header file.  Use the definition for
58
 * OM_object identifier.
59
 */
60
typedef OM_object_identifier gss_OID_desc, *gss_OID;
61
#else /* OM_STRING */
62
63
/*
64
 * We can't use X/Open definitions, so roll our own.
65
 */
66
typedef gss_uint32 OM_uint32;
67
68
typedef struct gss_OID_desc_struct {
69
	OM_uint32 length;
70
	void *elements;
71
} gss_OID_desc, *gss_OID;
72
#endif /* OM_STRING */
73
74
typedef struct gss_buffer_desc_struct {
75
	size_t length;
76
	void *value;
77
} gss_buffer_desc, *gss_buffer_t;
78
79
typedef struct gss_OID_set_desc_struct {
80
	size_t count;
81
	gss_OID elements;
82
} gss_OID_set_desc, *gss_OID_set;
83
84
typedef struct gss_channel_bindings_struct {
85
	OM_uint32 initiator_addrtype;
86
	gss_buffer_desc initiator_address;
87
	OM_uint32 acceptor_addrtype;
88
	gss_buffer_desc acceptor_address;
89
	gss_buffer_desc application_data;
90
} *gss_channel_bindings_t;
91
92
/*
93
 * For now, define a QOP-type as an OM_uint32 (pending resolution of ongoing
94
 * discussions).
95
 */
96
typedef OM_uint32 gss_qop_t;
97
typedef int	gss_cred_usage_t;
98
99
/*
100
 * Flag bits for context-level services.
101
 */
102
#define GSS_C_DELEG_FLAG        1
103
#define GSS_C_MUTUAL_FLAG       2
104
#define GSS_C_REPLAY_FLAG       4
105
#define GSS_C_SEQUENCE_FLAG     8
106
#define GSS_C_CONF_FLAG         16
107
#define GSS_C_INTEG_FLAG        32
108
#define GSS_C_ANON_FLAG         64
109
#define GSS_C_PROT_READY_FLAG   128
110
#define GSS_C_TRANS_FLAG        256
111
#define GSS_C_DELEG_POLICY_FLAG 32768
112
113
/*
114
 * Define WIN32 flags missing from MinGW's headers
115
 */
116
#ifndef ISC_RET_INTEGRITY
117
#define ISC_RET_INTEGRITY ISC_REQ_INTEGRITY
118
#endif
119
120
/*
121
 * Credential usage options
122
 */
123
#define GSS_C_BOTH      0
124
#define GSS_C_INITIATE  1
125
#define GSS_C_ACCEPT    2
126
127
/*
128
 * Status code types for gss_display_status
129
 */
130
#define GSS_C_GSS_CODE  1
131
#define GSS_C_MECH_CODE 2
132
133
/*
134
 * The constant definitions for channel-bindings address families
135
 */
136
#define GSS_C_AF_UNSPEC     0
137
#define GSS_C_AF_LOCAL      1
138
#define GSS_C_AF_INET       2
139
#define GSS_C_AF_IMPLINK    3
140
#define GSS_C_AF_PUP        4
141
#define GSS_C_AF_CHAOS      5
142
#define GSS_C_AF_NS         6
143
#define GSS_C_AF_NBS        7
144
#define GSS_C_AF_ECMA       8
145
#define GSS_C_AF_DATAKIT    9
146
#define GSS_C_AF_CCITT      10
147
#define GSS_C_AF_SNA        11
148
#define GSS_C_AF_DECnet     12
149
#define GSS_C_AF_DLI        13
150
#define GSS_C_AF_LAT        14
151
#define GSS_C_AF_HYLINK     15
152
#define GSS_C_AF_APPLETALK  16
153
#define GSS_C_AF_BSC        17
154
#define GSS_C_AF_DSS        18
155
#define GSS_C_AF_OSI        19
156
#define GSS_C_AF_NETBIOS    20
157
#define GSS_C_AF_X25        21
158
159
#define GSS_C_AF_NULLADDR   255
160
161
/*
162
 * Various Null values.
163
 */
164
#define GSS_C_NO_NAME ((gss_name_t) 0)
165
#define GSS_C_NO_BUFFER ((gss_buffer_t) 0)
166
#define GSS_C_NO_OID ((gss_OID) 0)
167
#define GSS_C_NO_OID_SET ((gss_OID_set) 0)
168
#define GSS_C_NO_CONTEXT ((gss_ctx_id_t) 0)
169
#define GSS_C_NO_CREDENTIAL ((gss_cred_id_t) 0)
170
#define GSS_C_NO_CHANNEL_BINDINGS ((gss_channel_bindings_t) 0)
171
#define GSS_C_EMPTY_BUFFER {0, NULL}
172
173
/*
174
 * Some alternate names for a couple of the above values.  These are defined
175
 * for V1 compatibility.
176
 */
177
#define GSS_C_NULL_OID GSS_C_NO_OID
178
#define GSS_C_NULL_OID_SET GSS_C_NO_OID_SET
179
180
/*
181
 * Define the default Quality of Protection for per-message services.  Note
182
 * that an implementation that offers multiple levels of QOP may either reserve
183
 * a value (for example zero, as assumed here) to mean "default protection", or
184
 * alternatively may simply equate GSS_C_QOP_DEFAULT to a specific explicit
185
 * QOP value.  However a value of 0 should always be interpreted by a GSSAPI
186
 * implementation as a request for the default protection level.
187
 */
188
#define GSS_C_QOP_DEFAULT 0
189
190
/*
191
 * Expiration time of 2^32-1 seconds means infinite lifetime for a
192
 * credential or security context
193
 */
194
#define GSS_C_INDEFINITE ((OM_uint32) 0xfffffffful)
195
196
197
/* Major status codes */
198
199
#define GSS_S_COMPLETE 0
200
201
/*
202
 * Some "helper" definitions to make the status code macros obvious.
203
 */
204
#define GSS_C_CALLING_ERROR_OFFSET 24
205
#define GSS_C_ROUTINE_ERROR_OFFSET 16
206
#define GSS_C_SUPPLEMENTARY_OFFSET 0
207
#define GSS_C_CALLING_ERROR_MASK ((OM_uint32) 0377ul)
208
#define GSS_C_ROUTINE_ERROR_MASK ((OM_uint32) 0377ul)
209
#define GSS_C_SUPPLEMENTARY_MASK ((OM_uint32) 0177777ul)
210
211
/*
212
 * The macros that test status codes for error conditions.	Note that the
213
 * GSS_ERROR() macro has changed slightly from the V1 GSSAPI so that it now
214
 * evaluates its argument only once.
215
 */
216
#define GSS_CALLING_ERROR(x) \
217
  ((x) & (GSS_C_CALLING_ERROR_MASK << GSS_C_CALLING_ERROR_OFFSET))
218
#define GSS_ROUTINE_ERROR(x) \
219
  ((x) & (GSS_C_ROUTINE_ERROR_MASK << GSS_C_ROUTINE_ERROR_OFFSET))
220
#define GSS_SUPPLEMENTARY_INFO(x) \
221
  ((x) & (GSS_C_SUPPLEMENTARY_MASK << GSS_C_SUPPLEMENTARY_OFFSET))
222
#define GSS_ERROR(x) \
223
  ((x) & ((GSS_C_CALLING_ERROR_MASK << GSS_C_CALLING_ERROR_OFFSET) | \
224
          (GSS_C_ROUTINE_ERROR_MASK << GSS_C_ROUTINE_ERROR_OFFSET)))
225
226
/*
227
 * Now the actual status code definitions
228
 */
229
230
/*
231
 * Calling errors:
232
 */
233
#define GSS_S_CALL_INACCESSIBLE_READ \
234
                             (((OM_uint32) 1ul) << GSS_C_CALLING_ERROR_OFFSET)
235
#define GSS_S_CALL_INACCESSIBLE_WRITE \
236
                             (((OM_uint32) 2ul) << GSS_C_CALLING_ERROR_OFFSET)
237
#define GSS_S_CALL_BAD_STRUCTURE \
238
                             (((OM_uint32) 3ul) << GSS_C_CALLING_ERROR_OFFSET)
239
240
/*
241
 * Routine errors:
242
 */
243
#define GSS_S_BAD_MECH (((OM_uint32) 1ul) << GSS_C_ROUTINE_ERROR_OFFSET)
244
#define GSS_S_BAD_NAME (((OM_uint32) 2ul) << GSS_C_ROUTINE_ERROR_OFFSET)
245
#define GSS_S_BAD_NAMETYPE (((OM_uint32) 3ul) << GSS_C_ROUTINE_ERROR_OFFSET)
246
#define GSS_S_BAD_BINDINGS (((OM_uint32) 4ul) << GSS_C_ROUTINE_ERROR_OFFSET)
247
#define GSS_S_BAD_STATUS (((OM_uint32) 5ul) << GSS_C_ROUTINE_ERROR_OFFSET)
248
#define GSS_S_BAD_SIG (((OM_uint32) 6ul) << GSS_C_ROUTINE_ERROR_OFFSET)
249
#define GSS_S_NO_CRED (((OM_uint32) 7ul) << GSS_C_ROUTINE_ERROR_OFFSET)
250
#define GSS_S_NO_CONTEXT (((OM_uint32) 8ul) << GSS_C_ROUTINE_ERROR_OFFSET)
251
#define GSS_S_DEFECTIVE_TOKEN (((OM_uint32) 9ul) << GSS_C_ROUTINE_ERROR_OFFSET)
252
#define GSS_S_DEFECTIVE_CREDENTIAL \
253
     (((OM_uint32) 10ul) << GSS_C_ROUTINE_ERROR_OFFSET)
254
#define GSS_S_CREDENTIALS_EXPIRED \
255
     (((OM_uint32) 11ul) << GSS_C_ROUTINE_ERROR_OFFSET)
256
#define GSS_S_CONTEXT_EXPIRED \
257
     (((OM_uint32) 12ul) << GSS_C_ROUTINE_ERROR_OFFSET)
258
#define GSS_S_FAILURE (((OM_uint32) 13ul) << GSS_C_ROUTINE_ERROR_OFFSET)
259
#define GSS_S_BAD_QOP (((OM_uint32) 14ul) << GSS_C_ROUTINE_ERROR_OFFSET)
260
#define GSS_S_UNAUTHORIZED (((OM_uint32) 15ul) << GSS_C_ROUTINE_ERROR_OFFSET)
261
#define GSS_S_UNAVAILABLE (((OM_uint32) 16ul) << GSS_C_ROUTINE_ERROR_OFFSET)
262
#define GSS_S_DUPLICATE_ELEMENT \
263
     (((OM_uint32) 17ul) << GSS_C_ROUTINE_ERROR_OFFSET)
264
#define GSS_S_NAME_NOT_MN \
265
     (((OM_uint32) 18ul) << GSS_C_ROUTINE_ERROR_OFFSET)
266
#define GSS_S_BAD_MECH_ATTR \
267
     (((OM_uint32) 19ul) << GSS_C_ROUTINE_ERROR_OFFSET)
268
269
/*
270
 * Supplementary info bits:
271
 */
272
#define GSS_S_CONTINUE_NEEDED (1 << (GSS_C_SUPPLEMENTARY_OFFSET + 0))
273
#define GSS_S_DUPLICATE_TOKEN (1 << (GSS_C_SUPPLEMENTARY_OFFSET + 1))
274
#define GSS_S_OLD_TOKEN (1 << (GSS_C_SUPPLEMENTARY_OFFSET + 2))
275
#define GSS_S_UNSEQ_TOKEN (1 << (GSS_C_SUPPLEMENTARY_OFFSET + 3))
276
#define GSS_S_GAP_TOKEN (1 << (GSS_C_SUPPLEMENTARY_OFFSET + 4))
277
278
279
/*
280
 * Finally, function prototypes for the GSSAPI routines.
281
 */
282
extern gss_OID GSS_C_NT_HOSTBASED_SERVICE;
283
284
OM_uint32
285
gss_display_status(
286
    OM_uint32 *,        /* minor_status */
287
    OM_uint32,          /* status_value */
288
    int,                /* status_type */
289
    gss_OID,            /* mech_type (used to be const) */
290
    OM_uint32 *,        /* message_context */
291
    gss_buffer_t);      /* status_string */
292
293
OM_uint32
294
gss_release_buffer(
295
    OM_uint32 *,        /* minor_status */
296
    gss_buffer_t);      /* buffer */
297
298
OM_uint32
299
gss_delete_sec_context(
300
    OM_uint32 *,        /* minor_status */
301
    gss_ctx_id_t *,     /* context_handle */
302
    gss_buffer_t);      /* output_token */
303
304
OM_uint32
305
gss_release_name(
306
    OM_uint32 *,        /* minor_status */
307
    gss_name_t *);      /* input_name */
308
309
OM_uint32
310
gss_release_cred(
311
    OM_uint32 *,        /* minor_status */
312
    gss_cred_id_t *);   /* cred_handle */
313
314
OM_uint32
315
gss_init_sec_context(
316
    OM_uint32 *,            /* minor_status */
317
    gss_cred_id_t,          /* claimant_cred_handle */
318
    gss_ctx_id_t *,         /* context_handle */
319
    gss_name_t,             /* target_name */
320
    gss_OID,                /* mech_type (used to be const) */
321
    OM_uint32,              /* req_flags */
322
    OM_uint32,              /* time_req */
323
    gss_channel_bindings_t,	/* input_chan_bindings */
324
    gss_buffer_t,           /* input_token */
325
    gss_OID *,              /* actual_mech_type */
326
    gss_buffer_t,           /* output_token */
327
    OM_uint32 *,            /* ret_flags */
328
    OM_uint32 *);           /* time_rec */
329
330
OM_uint32
331
gss_import_name(
332
    OM_uint32 *,        /* minor_status */
333
    gss_buffer_t,       /* input_name_buffer */
334
    gss_OID,            /* input_name_type(used to be const) */
335
    gss_name_t *);      /* output_name */
336
337
OM_uint32
338
gss_get_mic(
339
    OM_uint32 *,        /* minor_status */
340
    gss_ctx_id_t,       /* context_handle */
341
    gss_qop_t,          /* qop_req */
342
    gss_buffer_t,       /* message_buffer */
343
    gss_buffer_t);      /* message_token */
344
345
OM_uint32
346
gss_indicate_mechs(
347
    OM_uint32 *,        /* minor_status */
348
    gss_OID_set *);     /* mech_set */
349
350
#endif /* WIN32 */
351
352
#endif /* _WIN32_SSPI_H */
(-)openbsd-compat/win32-stubs.c (+87 lines)
Added Link Here
1
/*
2
 * Copyright 2013 Pierre Ossman for Cendio AB
3
 *
4
 * Permission to use, copy, modify, and distribute this software for any
5
 * purpose with or without fee is hereby granted, provided that the above
6
 * copyright notice and this permission notice appear in all copies.
7
 *
8
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
 */
16
17
#include "includes.h"
18
19
#ifdef WIN32
20
21
ssize_t
22
readv(int fd, const struct iovec *iov, int iovcnt)
23
{
24
	errno = EINVAL;
25
	return -1;
26
}
27
28
void
29
openlog(const char *ident, int option, int facility)
30
{
31
	errno = EINVAL;
32
	return -1;
33
}
34
35
void
36
syslog(int priority, const char *format, ...)
37
{
38
}
39
40
void
41
closelog(void)
42
{
43
}
44
45
pid_t
46
fork(void)
47
{
48
	errno = EINVAL;
49
	return -1;
50
}
51
52
int
53
setpgrp(pid_t pid, pid_t pgid)
54
{
55
	errno = EINVAL;
56
	return -1;
57
}
58
59
int
60
link(const char *path1, const char *path2)
61
{
62
	errno = EINVAL;
63
	return -1;
64
}
65
66
int
67
pipe(int pipefd[2])
68
{
69
	errno = EINVAL;
70
	return -1;
71
}
72
73
int
74
getdtablesize(void)
75
{
76
	errno = EINVAL;
77
	return -1;
78
}
79
80
pid_t
81
wait4(pid_t pid, int *status, int options, struct rusage *rusage)
82
{
83
	errno = EINVAL;
84
	return -1;
85
}
86
87
#endif /* WIN32 */
(-)openbsd-compat/win32-stubs.h (+72 lines)
Added Link Here
1
/*
2
 * Copyright 2013 Pierre Ossman for Cendio AB
3
 *
4
 * Permission to use, copy, modify, and distribute this software for any
5
 * purpose with or without fee is hereby granted, provided that the above
6
 * copyright notice and this permission notice appear in all copies.
7
 *
8
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
 */
16
17
#ifndef _WIN32_STUBS_H
18
#define _WIN32_STUBS_H
19
20
#include "includes.h"
21
22
#ifdef WIN32
23
24
ssize_t readv(int fd, const struct iovec *iov, int iovcnt);
25
26
#define	LOG_CRIT	0
27
#define	LOG_ERR		1
28
#define	LOG_INFO	2
29
#define	LOG_DEBUG	3
30
31
#define	LOG_USER	0
32
#define	LOG_DAEMON	1
33
#define	LOG_AUTH	2
34
35
#define	LOG_LOCAL0	10
36
#define	LOG_LOCAL1	11
37
#define	LOG_LOCAL2	12
38
#define	LOG_LOCAL3	13
39
#define	LOG_LOCAL4	14
40
#define	LOG_LOCAL5	15
41
#define	LOG_LOCAL6	16
42
#define	LOG_LOCAL7	17
43
44
#define	LOG_PID		0x01
45
46
void openlog(const char *ident, int option, int facility);
47
void syslog(int priority, const char *format, ...);
48
void closelog(void);
49
50
pid_t fork(void);
51
52
int setpgrp(pid_t pid, pid_t pgid);
53
54
int link(const char *path1, const char *path2);
55
56
int pipe(int pipefd[2]);
57
58
int getdtablesize(void);
59
60
#define WNOHANG	1
61
62
union wait {
63
	int w_status;
64
};
65
66
struct rusage;
67
68
pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage);
69
70
#endif /* WIN32 */
71
72
#endif /* _WIN32_STUBS_H */
(-)openbsd-compat/win32-tty.c (+160 lines)
Added Link Here
1
/*
2
 * Copyright 2013 Pierre Ossman for Cendio AB
3
 *
4
 * Permission to use, copy, modify, and distribute this software for any
5
 * purpose with or without fee is hereby granted, provided that the above
6
 * copyright notice and this permission notice appear in all copies.
7
 *
8
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
 */
16
17
#include "includes.h"
18
19
#ifdef WIN32
20
21
int
22
ioctl(int d, int request, ...)
23
{
24
	if (request != TIOCGWINSZ) {
25
		errno = EINVAL;
26
		return -1;
27
	}
28
29
	errno = EINVAL;
30
	return -1;
31
}
32
33
speed_t
34
cfgetispeed(const struct termios *termios_p)
35
{
36
	return B9600;
37
}
38
39
speed_t
40
cfgetospeed(const struct termios *termios_p)
41
{
42
	return B9600;
43
}
44
45
int
46
cfsetispeed(struct termios *termios_p, speed_t speed)
47
{
48
	if (speed != B9600) {
49
		errno = EINVAL;
50
		return -1;
51
	}
52
53
	return 0;
54
}
55
56
int
57
cfsetospeed(struct termios *termios_p, speed_t speed)
58
{
59
	if (speed != B9600) {
60
		errno = EINVAL;
61
		return -1;
62
	}
63
64
	return 0;
65
}
66
67
int
68
tcgetattr(int fd, struct termios *termios_p)
69
{
70
	errno = EINVAL;
71
	return -1;
72
}
73
74
int
75
tcsetattr(int fd, int optional_actions, const struct termios *termios_p)
76
{
77
	errno = EINVAL;
78
	return -1;
79
}
80
81
pid_t
82
tcgetpgrp(int fd)
83
{
84
	return getpid();
85
}
86
87
ssize_t
88
win32_read_console(int fildes, void *buf, size_t nbyte)
89
{
90
	int ret;
91
	HANDLE handle;
92
	INPUT_RECORD input[1024];
93
	DWORD i, out;
94
95
	/*
96
	 * The only way to properly read raw input from stdin is via
97
	 * ReadConsoleInput(). Both read() and ReadFile() have magic
98
	 * filtering that you cannot fully turn off.
99
	 *
100
	 * FIXME: Handle raw mode on/off
101
	 */
102
103
	handle = (HANDLE)_get_osfhandle(fildes);
104
	if (handle == INVALID_HANDLE_VALUE)
105
		return -1;
106
107
	ret = 0;
108
109
	while (ret == 0) {
110
		if (!ReadConsoleInput(handle, input, min(nbyte, 1024), &out)) {
111
			errno = GetLastError() | WIN32_ERRNO;
112
			return -1;
113
		}
114
115
		for (i = 0;i < out;i++) {
116
			if (input[i].EventType != KEY_EVENT)
117
				continue;
118
			if (!input[i].Event.KeyEvent.bKeyDown)
119
				continue;
120
			if (input[i].Event.KeyEvent.uChar.AsciiChar == 0)
121
				continue;
122
123
			((char*)buf)[ret++] = input[i].Event.KeyEvent.uChar.AsciiChar;
124
		}
125
	}
126
127
	return ret;
128
}
129
130
int
131
win32_filter_console_events(HANDLE console)
132
{
133
	/* Filter out anything that doesn't generate an input character */
134
	while (TRUE) {
135
		INPUT_RECORD input;
136
		DWORD read;
137
138
		if (!PeekConsoleInput(console, &input, 1, &read)) {
139
			errno = GetLastError() | WIN32_ERRNO;
140
			return -1;
141
		}
142
143
		if (read == 0)
144
			return 0;
145
146
		if ((input.EventType == KEY_EVENT) &&
147
		    input.Event.KeyEvent.bKeyDown &&
148
		    (input.Event.KeyEvent.uChar.UnicodeChar != 0))
149
			break;
150
151
		if (!ReadConsoleInput(console, &input, 1, &read)) {
152
			errno = GetLastError() | WIN32_ERRNO;
153
			return -1;
154
		}
155
	}
156
157
	return 1;
158
}
159
160
#endif /* WIN32 */
(-)openbsd-compat/win32-tty.h (+117 lines)
Added Link Here
1
/*
2
 * Copyright 2013 Pierre Ossman for Cendio AB
3
 *
4
 * Permission to use, copy, modify, and distribute this software for any
5
 * purpose with or without fee is hereby granted, provided that the above
6
 * copyright notice and this permission notice appear in all copies.
7
 *
8
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
 */
16
17
#ifndef _WIN32_TTY_H
18
#define _WIN32_TTY_H
19
20
#include "includes.h"
21
22
#ifdef WIN32
23
24
struct winsize {
25
	unsigned short ws_row;		/* rows, in characters */
26
	unsigned short ws_col;		/* columns, in character */
27
	unsigned short ws_xpixel;	/* horizontal size, pixels */
28
	unsigned short ws_ypixel;	/* vertical size, pixels */
29
};
30
31
#define TIOCGWINSZ	0x5413
32
33
int ioctl(int d, int request, ...);
34
35
typedef unsigned char	cc_t;
36
typedef unsigned int	speed_t;
37
typedef unsigned int	tcflag_t;
38
39
#define NCCS 2
40
struct termios {
41
	tcflag_t c_iflag;	/* input modes */
42
	tcflag_t c_oflag;	/* output modes */
43
	tcflag_t c_cflag;	/* control modes */
44
	tcflag_t c_lflag;	/* local modes */
45
	cc_t     c_cc[NCCS];	/* special characters */
46
};
47
48
/* c_cc characters */
49
#define VTIME	0
50
#define VMIN	1
51
52
/* c_iflag bits */
53
#define IGNPAR	0000004
54
#define PARMRK	0000010
55
#define INPCK	0000020
56
#define ISTRIP	0000040
57
#define INLCR	0000100
58
#define IGNCR	0000200
59
#define ICRNL	0000400
60
#define IXON	0002000
61
#define IXANY	0004000
62
#define IXOFF	0010000
63
64
/* c_oflag bits */
65
#define OPOST	0000001
66
#define ONLCR	0000004
67
68
/* c_cflag bit meaning */
69
#define  B0	0000000
70
#define  B50	0000001
71
#define  B75	0000002
72
#define  B110	0000003
73
#define  B134	0000004
74
#define  B150	0000005
75
#define  B200	0000006
76
#define  B300	0000007
77
#define  B600	0000010
78
#define  B1200	0000011
79
#define  B1800	0000012
80
#define  B2400	0000013
81
#define  B4800	0000014
82
#define  B9600	0000015
83
#define   CS7	0000040
84
#define   CS8	0000060
85
#define PARENB	0000400
86
#define PARODD	0001000
87
88
/* c_lflag bits */
89
#define ISIG	0000001
90
#define ICANON	0000002
91
#define ECHO	0000010
92
#define ECHOE	0000020
93
#define ECHOK	0000040
94
#define ECHONL	0000100
95
#define NOFLSH	0000200
96
#define TOSTOP	0000400
97
98
speed_t cfgetispeed(const struct termios *termios_p);
99
speed_t cfgetospeed(const struct termios *termios_p);
100
101
int cfsetispeed(struct termios *termios_p, speed_t speed);
102
int cfsetospeed(struct termios *termios_p, speed_t speed);
103
104
/* tcsetattr uses these */
105
#define	TCSANOW		0
106
#define	TCSADRAIN	1
107
#define	TCSAFLUSH	2
108
109
int tcgetattr(int fd, struct termios *termios_p);
110
int tcsetattr(int fd, int optional_actions, const struct termios *termios_p);
111
112
#define HAVE_TCGETPGRP
113
pid_t tcgetpgrp(int fd);
114
115
#endif /* WIN32 */
116
117
#endif /* _WIN32_TTY_H */
(-)openbsd-compat/xcrypt.c (-1 / +3 lines)
Lines 26-32 Link Here
26
26
27
#include <sys/types.h>
27
#include <sys/types.h>
28
#include <unistd.h>
28
#include <unistd.h>
29
#include <pwd.h>
29
#ifdef HAVE_PWD_H
30
# include <pwd.h>
31
#endif
30
32
31
# if defined(HAVE_CRYPT_H) && !defined(HAVE_SECUREWARE)
33
# if defined(HAVE_CRYPT_H) && !defined(HAVE_SECUREWARE)
32
#  include <crypt.h>
34
#  include <crypt.h>

Return to bug 2104