Only include <sys/timeb.h> for Windows

This file is deprecated on FreeBSD, and appears to only be used
by OpenAFS on windows.

Change-Id: If10816f26da91855d10826d53501e5b9974cd292
Satisfy clang's aggressive strlcpy warnings

Passing something related to the length of the source as the
length argument to strlcpy triggers a warning, which is converted
to an error with --enable-checking (on FreeBSD 10.0).  The current
code is safe, since it is using the same expression that was used
to allocate the destination buffer, but switch to using a separate
variable to hold the length and use that variable for both allocation
and copying, to appease the compiler.

Change-Id: I580083d142fd19a4e7828c915b4846868fa8f917
pioctl.c: removed unused variable

The 'rval' variable is only actually used in the LINUX20 case;
in all other places where it is assigned a value, that value
ends up in 'errcode' (if non-zero).  This also has the
side effect of eliminating the use of the uninitialized variable
'errcode' when rval was zero.

Found by clang on FreeBSD 10.0.

Change-Id: I60c56af355fdb68752d9596ff2cd7a4259b43fe9
pointers are not castable to unsigned int

When printing a pointer's value for debugging purposes, use the
dedicated printf format specifier for pointers instead of assuming
that unsigned int ('x') is good enough.

Found by clang on FreeBSD 10.0.

Change-Id: I18c42df0bf03c2d0e9e7c757445b8ff0f616c671
FBSD: Switch the dummy 'data' for mount(2)

The mount(2) API takes a void*, but 'rn' is const char*, which
is const-incorrect.  Our vfs_cmount implementation ignores the 'data'
parameter, but upstream's kernel mount(2) implementation did
have a NULL check until r158611 (in the 6.1 or 7.0 timeframe),
so leave that comment for now.

Arguably we should be using nmount(2) instead of mount(2) anyway,
but leave that for a separate patch.

Change-Id: I22fd85c2f1a32aa849e182d263de119a953690d2
fstrace: only declare 'rval' when it is used

... to avoid compiler warnings about unused variables.

Found by clang on FreeBSD 10.0.

Change-Id: I30c9fbc0e2fb0f9af273f0f17861009b6d0577df
aklog: those pesky assignments in conditionals

This one should actually be an assignment, and the compiler warning
for having two sets of parentheses is helpful.

Found by clang on FreeBSD 10.0.

Change-Id: Ic906cbdc50a20bcd0b91555581b60c518da2bc81
libacl: use initialized memory

Replace malloc with calloc to use zeroed memory when converting access
lists.

Change-Id: I17558d1737fee020772919e423c9fba37180beca
Reviewed-on: http://gerrit.openafs.org/10815
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Perry Ruiter <pruiter@sinenomine.net>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
bos: Remove last of MRAFS references

A few MRAFS tidbits were left behind during the cleanup in commit
a9301cd2dc1a875337f04751e38bba6f1da7ed32.

Change-Id: I7dcd30797ff87c61d57781c66cb9f7369638fa36
Reviewed-on: http://gerrit.openafs.org/10808
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
Windows: cm_AddCellProc always call cm_NewServer

The current implementation of cm_NewServer handles races and
collisions.  There is no need to perform a cm_FindServer() check
first.  Just call cm_NewServer() for all server entries.

Move the logging of server creation and cell assignment to
cm_NewServer().

Change-Id: If0cdb2eda9bcb6234eeaef7c2a35edf751a9c0ca
Reviewed-on: http://gerrit.openafs.org/10775
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
Windows: Support arbitrary callback ports

Reconfigure the advanced firewall to support callback ports
other than port 7001.

This changes the semantics of the afsicf api.  AFS_PORTSET_SERVER is now
zero.  Any other value is treated as a callback port.

Change-Id: I4df421cc0ceb4dca94a6b5e81990115a4ce0334e
Reviewed-on: http://gerrit.openafs.org/10776
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
Windows: cm_GetCell_gen Fixup cm_server cellp on race

If a race occurs during the instantiation of a new cm_cell_t object,
the created servers will point at the wrong cm_cell_t object after
the race is detected.  Before cm_GetCell_gen completes the cm_server_t
objects must be fixed to point to the correct cm_cell_t.

Change-Id: I8341c2cfd2a8ac7be31699d11f78b4b9ced257af
Reviewed-on: http://gerrit.openafs.org/10777
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
afs_fetchstore: re-avoid uninitialized variable

As noted in the gerrit comments for change 10742, commit
baf6af8a8f2207ce39b746d59ca4bc661c002883 does not handle the case
where the second rx_Read() call fails, and the 'length' variable
can still be used uninitialized.

Instead of using an err label and jumping to it on the case of
errors, initialize length to zero and take care to neither
set nor access *alength if an error has occurred.  This is
more consistent with the style of the surrounding code while still
avoiding the use of an uninitialized variable.

Change-Id: I6abfa4a5f051368ca12ada1494fc7687f378d319
Reviewed-on: http://gerrit.openafs.org/10806
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
Export heimdal's rand-fortuna PRNG to the kernel

Some systems (e.g., AIX, SGI, DFBSD, HPUX) do not supply a useful
implementation of osi_readRandom(), in some cases because the kernel
does not expose a random-number interface to kernel modules.  We want
real random numbers on all systems, because we want to use the for
setting the RX epoch and connection ID in the kernel.

Build hcrypto's rand-fortuna PRNG into the rand-kernel interface we expose,
and implement RAND_bytes using rand-fortuna when osi_ReadRandom()
is not useful.

Add stub routines to config.h as needed, and add a heim_threads.h
with the necessary locking for rand-fortuna.  The rand-fortuna algorithm
requires some measure of time's passage, so provide a stub gettimeofday()
with single-second resolution.  We use a single (global) mutex for the
hcrypto kernel code, so that we can statically declare an initializer to
be the address of that mutex.  Otherwise the locking is taken essentially
wholesale from rx_kmutex.

Since the rand-fortuna code does not have any actual sources of entropy
available to it during its initialization routines, we must explicitly
seed the in-kernel rand-fortuna using entropy passed in from userland.
(Userland will always have at least /dev/random available, so the
userland hcrypto should always have usable entropy.)  Be sure to do so
early in the afsd startup sequence, before any daemons are started, so
that entropy is available to the core rx code for generating the epoch
and cid -- the rand-fortuna code will (erroneously) always claim that
it has startup entropy even though in this case it may not actually
have any entropy.  The rand-fortuna code does not consider itself
fully seeded until it has 128 bytes of entropy, so be sure to pass
more than that in from userspace.

It is preferrable to always build this code into the kernel, even on
systems when it is not going to be used, to help prevent bitrot.  This
also avoids the possibility of a new system being supported that would
attempt to use the rand-fortuna code but fail to supply any seed entropy,
which would not necessarily be readily apparent.

Change-Id: I614d2bd9ac52803ec3b9572cc694cd836c8427dd
Move epoch and cid generation into the rx core

Now that we have hcrypto available everywhere, we can get real randomness
in the rx core (both uerspace and kernel), and thus can initialize the
RX epoch to a real random value when first initializing a host; there is
no need to rely on rxkad to produce randomness for this purpose.
Initialize a connection ID counter at the same time, and use that in
rx_NewConnection, also supplanting rxkad-specific logic.

The rxkad-specific logic is removed, and in particular there is no longer
a need to export rxkad_EpochWasSet to the rest of the world.
The code in afs_Daemon() to check whether the rxepoch was set can be
removed, as if the epoch is not set, rx initialization fails.

Add libafshcrypto to LIBS in the handful of places it hadn't crept already.

Change-Id: I1dd1015b29a600aaf72b6b4b36f8a17032453c97
Garbage-collect afs_GCUserData's argument

We no longer need the ability to force all rxnull connections to be
reaped, as the epoch is set globally.  Change the prototype and
callers accordingly.

Change-Id: I0815fdd035c3dd9d56f72e43603f9c53f5cec79d
Remove rx_SetEpoch, rx_SetConnectionEpoch, rx_SetConnectionId

The core RX code now manages the Epoch and CID; external callers
should not be modifying them.

Change-Id: Ia517205aa280b2a0bbd2568274be7fb010fba0bc
hack it a bit further

Change-Id: Ic965ac7611b1504984a3c104bc85d3cf70fc73d0