@PACKAGE@_get_tunnel_user_name(3)

NAME
@PACKAGE@_get_tunnel_user_name - get the username of the current user

SYNOPSIS
#include <@PACKAGE@/get_tunnel_user_name.h> int @PACKAGE@_get_tunnel_user_name(char* buf,
size_t bufsize);

DESCRIPTION
Fetches the username that should be passed to svnserve(8) via the --tunnel-user argument. This function uses the getlogin_r(3) function to fetch the username of the user that invoked this process. If getlogin_r is unavailable or returns an error, getpwuid_r(3) is used instead. Note that if multiple users share the same user ID, this function may return the wrong username. This function is thread-safe if the user's C POSIX library is thread-safe.

ARGUMENTS

buf Pointer to a buffer of length bufsize where the null-terminated username will be written. This may be the null pointer if bufsize is 0. This function will not write beyond the end of the buffer (buf + bufsize - 1).

bufsize
    Size of the buffer at buf. If 0, buf will not be written to and may be the null pointer. If the buffer size is less than the length of the null-terminated login name, then buf will be filled with a truncated, null-terminated version of the login name.

RETURN VALUE
On success, returns the length of the username (not including the null terminator) to use with the --tunnel-user argument to svnserve. Thus, if the return value is less than bufsize, the buffer at buf contains the full username. If the return value is greater than or equal to bufsize, the username was truncated to fit in buf. On error, a negative value is returned and errno (see errno(3)) is set.

ERRORS
Error conditions and errno (see errno(3)) values are described in the specifications for getpwuid_r(3) and snprintf(3), with the addition that EINVAL may indicate that no username is associated with the UID of the invoking user.

SECURITY CONSIDERATIONS
This function uses getlogin_r(3) to determine the login name. Since users might be able to trick getlogin_r into returning an arbitrary username on some systems, the results are verified using getpwnam_r(3). This verification does not prevent a user from imitating another user if the two users share the same user ID. If verification fails, or if getlogin_r fails for any reason, getpwuid_r(3) is used instead. This function may return the incorrect username if multiple users share the same user ID.

SEE ALSO
lib@PACKAGE@(3), @PACKAGE@_exec_svnserve(3), @PACKAGE@(8), svnserve(8), getlogin_r(3), getpwuid_r(3)

AUTHOR
Richard Hansen <svnstsw@ir.bbn.com>

COPYING
Copyright (c) 2008 BBN Technologies Corp. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

    1.  Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

    2.  Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

    3.  Neither the name of BBN Technologies nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY BBN TECHNOLOGIES AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BBN TECHNOLOGIES OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.