Translate WinSock errors to Posix counterparts

MSVC 2010 defines both Posix and WinSock error values so we can no longer
simply #define the Posix error values to be their WinSock counterpart.
This patch explicitly #includes <errno.h> in port-sockets.h and still
conditionally defines the Posix error values for compatibility with older
MSVC but also translates WinSock errors to Posix for MSVC 2010
compatibility.

The downside to this approach is that there are some Posix errors we
do not currently detect (e.g. EADDRINUSE) that are neither #defined nor
translated.  If we use one of those in the future but fail to update
TranslateWSAGetLastError() we'll once again be in the situation that the
windows build will compile but fail to work, possibly only when some rare
error condition occurs.

Signed-off-by: Kevin Wasserman <kevin.wasserman@painless-security.com>

(cherry picked from commit fc08c21ab33fcc0c8851a2a0fb0e55721ff975ea)

ticket: 7197
version_fixed: 1.10.3
status: resolved
Implement switch_to for ccapiv3

krb5_stdccv3_switch_to() calls cc_ccache_set_default().
krb5_stdccv3_resolve() checks for NULL or empty residual and calls
cc_context_get_default_ccache_name() in those cases.

Signed-off-by: Kevin Wasserman <kevin.wasserman@painless-security.com>

(cherry picked from commit 2648a94ea1cf3dec91186dfec59b75de9dac793d)

ticket: 7198
version_fixed: 1.10.3
status: resolved
Add krb5int_cc_user_set_default_name

Set the default credential cache name for all processes for the current
user.  Currently implemented, for windows only, by setting
HKEY_CURRENT_USER\Software\MIT\Kerberos5:ccname to the specified
ccache name.  This will not override the environment variable 'KRB5CCNAME'.
It will override HKEY_LOCAL_MACHINE and 'indirect' registry values.

Signed-off-by: Kevin Wasserman <kevin.wasserman@painless-security.com>

(cherry picked from commit 80097093062822dde3f1140d250023576e52f59c)

ticket: 7199
version_fixed: 1.10.3
status: resolved
Always recreate acl files during dejagnu tests

The dejagnu tests create some persistent acl files containing
hostname-derived principal names.  These can get out of date if the
host has changed names since the last time the dejagnu tests were run,
causing failures (notably in iprop.exp).  To avoid this problem,
change the dejagnu tests to always create new acl files for each test
run.

(cherry picked from commit 244bb3fde58dd6bab0969e0501b537c5871088f0)

ticket: 7200
version_fixed: 1.10.3
status: resolved
Handle huge /bin directories in libdb2 test

The test suite for libdb2 uses /bin as a source of filenames and
contents for insertion into databases.  Fedora 17 (and possibly other
OSes) have /bin symlinked to /usr/bin, which can vastly increase the
number of files found, exceeding some limits of the test databases.
Truncate this list of files at 100 to prevent this problem.

(cherry picked from commit 18a378eb43a7a5a5e14a7e6c3b6504fe32804781)

ticket: 7201
version_fixed: 1.10.3
status: resolved
kfw add preauth_sam2 to OBJS for windows build

Signed-off-by: Kevin Wasserman <kevin.wasserman@painless-security.com>

(cherry picked from commit d319617ba9dd1256784fe325ae5a3858cf4603e7)

ticket: 7203
version_fixed: 1.10.3
status: resolved
KFW win-mac.h fixes

kfw: add int16_t, uint16_t typedefs to win-mac.h
uint16_t is used in chpw.c

include stdlib.h, crtdbg.h in win-mac.h

Allows leak-tracking using built-in msvc tools on windows.
crtdbg.h needs to come _after_ stdlib.h, but _before_ checking for
strdup.  Define DEBUG and CRTDBG_MAP_ALLOC for full tracking.

Signed-off-by: Kevin Wasserman <kevin.wasserman@painless-security.com>

(cherry picked from commit 0a27c56e300990909317630e626ccdd8ae8e7f41)

ticket: 7204
version_fixed: 1.10.3
status: resolved
Use %i, not %s to Tprintf GetLastError()

Signed-off-by: Kevin Wasserman <kevin.wasserman@painless-security.com>

(cherry picked from commit 692c1ccea5af4549437937a424b64ab40178fcc2)

ticket: 7206
version_fixed: 1.10.3
status: resolved
Define USE_CCAPI_V3 in krb5/ccache on windows

USE_CCAPI_V3 provides cccol iteration support for ccapi.

Signed-off-by: Kevin Wasserman <kevin.wasserman@painless-security.com>

(cherry picked from commit 227a1b093cb22eb7c6d7fee0759f28816572db70)

Build lib/krb5/ccache/ccapi on Windows only

Signed-off-by: Kevin Wasserman <kevin.wasserman@painless-security.com>

(cherry picked from commit 8c3d2bfab7017a587d0c9a7de262cdcf18ce21c8)

ticket: 7209
version_fixed: 1.10.3
status: resolved
Remove the UNICODE defines from wshelper

wshelper is clearly not intended to use unicode:
wprintf is used extensively and exclusively to write to char[] buffers and
fields in dns structs are used as explicitly ASCII text.

Signed-off-by: Alexey Melnikov <aamelnikov@gmail.com>

(cherry picked from commit 7d156d88ce5cdc40b1df02f051d65b3ad93c60e1)

ticket: 7210
version_fixed: 1.10.3
status: resolved
MSLSA Don't use lstrcpy on ANSI strings

Also change parameter types to eliminate casts.

Signed-off-by: Kevin Wasserman <kevin.wasserman@painless-security.com>

(cherry picked from commit 7acb524f5aa00274771dbbfac19d2dd779aad409)

ticket: 7212
version_fixed: 1.10.3
status: resolved
Implement cccol iterators for mslsa

Also implement  switch_to stub

Signed-off-by: Kevin Wasserman <kevin.wasserman@painless-security.com>

(cherry picked from commit 218193bb93d8cf9fd82087533c45602b6a8c5151)

Fix macro redefinition warnings in cc_mslsa.c

Include ntstatus.h and define WIN32_NO_STATUS before including winnt.h

Signed-off-by: Kevin Wasserman <kevin.wasserman@painless-security.com>

(cherry picked from commit ee6fbe222b34b28c617d4e6df994700af471b1b6)

fix leak in cc_mslsa.c

cc_name needs to be freed in krb5_lcc_close().

Signed-off-by: Kevin Wasserman <kevin.wasserman@painless-security.com>

(cherry picked from commit dcd9202f058830eacbbdfd0dd26bd82d8101e8fd)

ticket: 7213
version_fixed: 1.10.3
status: resolved
krb5_stdccv3_get_principal error handling fixup

Don't treat an error returned by krb5_parse_name as a cc-internal error.

Signed-off-by: Kevin Wasserman <kevin.wasserman@painless-security.com>

(cherry picked from commit fbe77b2c7d4340097690cbed7b48fd9888feacd4)

ticket: 7214
version_fixed: 1.10.3
status: resolved
Remove DISABLE_TRACING from windows build

Signed-off-by: Kevin Wasserman <kevin.wasserman@painless-security.com>

(cherry picked from commit 6931507c87d6139b1dcea2ea97a6e3b145287438)

ticket: 7215
version_fixed: 1.10.3
status: resolved
Fix -DDEBUG compilation errors

(cherry picked from commit 7c3ecf5c77e33f6d04d6226b041071c6ce23b062)

ticket: 7150
version_fixed: 1.10.3
status: resolved
Don't use syslog / LOG_DEBUG when they don't exist

Signed-off-by: Kevin Wasserman <kevin.wasserman@painless-security.com>

(cherry picked from commit 5ae666d1591f5ab8bc1182d053cdda7ce9a855d2)

ticket: 7207
version_fixed: 1.10.3
status: resolved
__func__ -> __FUNCTION__ in disp_status.c

For MSVC compatibility

Signed-off-by: Kevin Wasserman <kevin.wasserman@painless-security.com>

(cherry picked from commit 0552f29887201227788d1ca3df9d2b2c4f2447d2)

ticket: 7208
version_fixed: 1.10.3
status: resolved