glibc/sunrpc/auth_unix.c
Ulrich Drepper b2bffca2e3 Update.
2002-05-11  Jakub Jelinek  <jakub@redhat.com>

	* include/netinet/in.h (bindresvport_internal): Add prototype.
	* include/rpc/auth.h  (authunix_create_internal,
	authunix_create_default_internal, authnone_create_internal,
	authdes_pk_create_internal): Add prototypes.
	* include/rpc/clnt.h (clnt_create_internal, clnttcp_create_internal,
	clntudp_create_internal, clntudp_bufcreate_internal,
	clntunix_create_internal): Add prototypes.
	* include/rpc/svc.h (svc_sendreply_internal, svcerr_decode_internal,
	svc_getreq_internal, svc_getreq_common_internal,
	svc_getreqset_internal, svc_getreq_poll_internal,
	svc_register_internal, svc_unregister_internal,
	svcudp_create_internal, svcudp_bufcreate_internal): Add prototypes.
	* include/rpc/svc_auth.h (_authenticate_internal): Add prototype.
	* include/sys/socket.h (__sendto, __recvfrom, __sendmsg, __recvmsg,
	__setsockopt, __getsockname, __bind, __listen): Add prototypes.
	* inet/rexec.c (rexec_af): Use __listen and __getsockname.
	* inet/rcmd.c (rcmd_af): Use __listen.
	(rresvport_af): Use __bind.
	* sunrpc/clnt_udp.c: Use INTUSE calls to bindresvport,
	authunix_create, authunix_create_default, authnone_create,
	authdes_pk_create, clnt_create, clnttcp_create, clntudp_create,
	clntudp_bufcreate, clntunix_create svc_sendreply, svcerr_decode,
	svc_getreq, svc_getreq_common, svc_getreqset, svc_getreq_poll,
	svc_register, svc_unregister, svcudp_create, svcudp_bufcreate,
	_authenticate, add INTDEF after such function definitions.
	Use __listen, __bind, __sendto, __recvfrom, __sendmsg, __recvmsg,
	__setsockopt, __getsockname instead of non-__ variants.
	* sunrpc/pmap_rmt.c: Likewise.
	* sunrpc/rtime.c: Likewise.
	* sunrpc/svc_udp.c: Likewise.
	* sunrpc/clnt_unix.c: Likewise.
	* sunrpc/svc_unix.c: Likewise.
	* sunrpc/bindrsvprt.c: Likewise.
	* sunrpc/svc_tcp.c: Likewise.
	* sunrpc/auth_none.c: Likewise.
	* sunrpc/clnt_raw.c: Likewise.
	* sunrpc/clnt_tcp.c: Likewise.
	* sunrpc/auth_unix.c: Likewise.
	* sunrpc/key_call.c: Likewise.
	* sunrpc/clnt_gen.c: Likewise.
	* sunrpc/pm_getmaps.c: Likewise.
	* sunrpc/clnt_simp.c: Likewise.
	* sunrpc/pmap_clnt.c: Likewise.
	* sunrpc/svc_run.c: Likewise.
	* sunrpc/svc.c: Likewise.
	* sunrpc/svc_simple.c: Likewise.
	* sunrpc/pm_getport.c: Likewise.
	* sunrpc/auth_des.c: Likewise.
	* sunrpc/svc_auth.c: Likewise.
	* sysdeps/generic/unwind-dw2-fde.c (__register_frame_info_bases,
	__register_frame_info_table_bases, __deregister_frame_info_bases):
	Add INTDEF.
	(__register_frame_info_bases_internal,
	__register_frame_info_table_bases_internal,
	__deregister_frame_info_bases_internal): Add prototypes.
	(__register_frame_info, __register_frame): Use INTUSE in call to
	__register_frame_info_bases.
	(__register_frame_info_table): Similarly.
	(__deregister_frame_info, __deregister_frame): Similarly.
	* sysdeps/generic/sendto.c (__sendto): Renamed from sendto, add
	sendto as weak alias.
	* sysdeps/mach/hurd/sendto.c: Likewise.
	* sysdeps/generic/recvfrom.c (__recvfrom): Renamed from recvfrom, add
	recvfrom as weak alias.
	* sysdeps/mach/hurd/recvfrom.c: Likewise.
	* sysdeps/unix/sysv/aix/recvfrom.c: Likewise.
	* sysdeps/generic/recvmsg.c (__recvmsg): Renamed from recvmsg, add
	recvmsg as weak alias.
	* sysdeps/unix/sysv/aix/recvmsg.c: Likewise.
	* sysdeps/generic/sendmsg.c (__sendmsg): Renamed from sendmsg, add
	sendmsg as weak alias.
	* sysdeps/unix/sysv/aix/sendmsg.c: Likewise.
	* sysdeps/generic/setsockopt.c (__setsockopt): Renamed from
	setsockopt, add setsockopt as weak alias.
	* sysdeps/mach/hurd/setsockopt.c: Likewise.
	* sysdeps/generic/bind.c (__bind): Renamed from bind, add bind as
	weak alias.
	* sysdeps/mach/hurd/bind.c: Likewise.
	* sysdeps/generic/listen.c (__listen): Renamed from listen, add listen
	as weak alias.
	* sysdeps/mach/hurd/listen.c: Likewise.
	* sysdeps/generic/getsockname.c (__getsockname): Renamed from
	getsockname, add getsockname as weak alias.
	* sysdeps/mach/hurd/getsockname.c: Likewise.
	* sysdeps/unix/sysv/aix/getsockname.c: Likewise.
	* sysdeps/mach/hurd/recvmsg.c (__recvmsg): Add weak alias.
	* sysdeps/mach/hurd/sendmsg.c (__sendmsg): Add weak alias.
	* sysdeps/unix/inet/syscalls.list (__bind, __listen, __recvmsg,
	__recvfrom, __sendmsg, __sendto, __setsockopt): Add aliases.
	* sysdeps/unix/sysv/linux/alpha/syscalls.list (__recvmsg, __sendmsg):
	Add aliases.
	* sysdeps/unix/sysv/linux/ia64/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/hppa/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/recvfrom.S (__recvfrom): Add weak alias.
	* sysdeps/unix/sysv/linux/recvmsg.S (__recvmsg): Likewise.
	* sysdeps/unix/sysv/linux/sendmsg.S (__sendmsg): Likewise.
	* sysdeps/unix/sysv/linux/sendto.S (__sendto): Likewise.
	* sysdeps/unix/sysv/linux/setsockopt.S (__setsockopt): Likewise.
	* sysdeps/unix/sysv/linux/bind.S (__bind): Likewise.
	* sysdeps/unix/sysv/linux/listen.S (__listen): Likewise.
	* sysdeps/unix/sysv/linux/getsockname.S (__getsockname): Likewise.

2002-05-10  Jakub Jelinek  <jakub@redhat.com>

	* locale/programs/localedef.h (show_archive_content): Add verbose
	argument.
	* locale/programs/localedef.c (main): Adjust caller.
	* locale/programs/locarchive.c (struct nameent, struct dataent): New.
	(nameentcmp, dataentcmp): New functions.
	(xstrcmp): Remove.
	(show_archive_content): Print verbose listing with --list-archive -v.

	* locale/programs/locarchive.c (open_archive): Take extra argument
	readonly.  If true open file with O_RDONLY and don't create the
	archive if it doesn't exist.
	Adapt all callers.
	(close_archive): Don't do anything if fd element is -1.
	* locale/programs/localedef.h (open_archive): Adjust prototype.
	* locale/programs/locfile.c (write_all_categories): Adjust open_archive
	call.

	* malloc/malloc.c (__posix_memalign): Correct check for size of
	alignment value [PR libc/3444].
2002-05-15 00:22:23 +00:00

326 lines
8.4 KiB
C

/*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape
* media and as a part of the software program in whole or part. Users
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user.
*
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* OR ANY PART THEREOF.
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
*/
/*
* Copyright (C) 1984, Sun Microsystems, Inc.
*/
/*
* auth_unix.c, Implements UNIX style authentication parameters.
*
* The system is very weak. The client uses no encryption for it's
* credentials and only sends null verifiers. The server sends backs
* null verifiers or optionally a verifier that suggests a new short hand
* for the credentials.
*/
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <libintl.h>
#include <sys/param.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
#include <rpc/auth.h>
#include <rpc/auth_unix.h>
#ifdef USE_IN_LIBIO
# include <wchar.h>
#endif
/*
* Unix authenticator operations vector
*/
static void authunix_nextverf (AUTH *);
static bool_t authunix_marshal (AUTH *, XDR *);
static bool_t authunix_validate (AUTH *, struct opaque_auth *);
static bool_t authunix_refresh (AUTH *);
static void authunix_destroy (AUTH *);
static struct auth_ops auth_unix_ops = {
authunix_nextverf,
authunix_marshal,
authunix_validate,
authunix_refresh,
authunix_destroy
};
/*
* This struct is pointed to by the ah_private field of an auth_handle.
*/
struct audata {
struct opaque_auth au_origcred; /* original credentials */
struct opaque_auth au_shcred; /* short hand cred */
u_long au_shfaults; /* short hand cache faults */
char au_marshed[MAX_AUTH_BYTES];
u_int au_mpos; /* xdr pos at end of marshed */
};
#define AUTH_PRIVATE(auth) ((struct audata *)auth->ah_private)
static bool_t marshal_new_auth (AUTH *) internal_function;
/*
* Create a unix style authenticator.
* Returns an auth handle with the given stuff in it.
*/
AUTH *
authunix_create (char *machname, uid_t uid, gid_t gid, int len,
gid_t *aup_gids)
{
struct authunix_parms aup;
char mymem[MAX_AUTH_BYTES];
struct timeval now;
XDR xdrs;
AUTH *auth;
struct audata *au;
/*
* Allocate and set up auth handle
*/
auth = (AUTH *) mem_alloc (sizeof (*auth));
au = (struct audata *) mem_alloc (sizeof (*au));
if (auth == NULL || au == NULL)
{
no_memory:
#ifdef USE_IN_LIBIO
if (_IO_fwide (stderr, 0) > 0)
(void) __fwprintf (stderr, L"%s",
_("authunix_create: out of memory\n"));
else
#endif
(void) fputs (_("authunix_create: out of memory\n"), stderr);
mem_free (auth, sizeof (*auth));
mem_free (au, sizeof (*au));
return NULL;
}
auth->ah_ops = &auth_unix_ops;
auth->ah_private = (caddr_t) au;
auth->ah_verf = au->au_shcred = _null_auth;
au->au_shfaults = 0;
/*
* fill in param struct from the given params
*/
(void) __gettimeofday (&now, (struct timezone *) 0);
aup.aup_time = now.tv_sec;
aup.aup_machname = machname;
aup.aup_uid = uid;
aup.aup_gid = gid;
aup.aup_len = (u_int) len;
aup.aup_gids = aup_gids;
/*
* Serialize the parameters into origcred
*/
INTUSE(xdrmem_create) (&xdrs, mymem, MAX_AUTH_BYTES, XDR_ENCODE);
if (!INTUSE(xdr_authunix_parms) (&xdrs, &aup))
abort ();
au->au_origcred.oa_length = len = XDR_GETPOS (&xdrs);
au->au_origcred.oa_flavor = AUTH_UNIX;
au->au_origcred.oa_base = mem_alloc ((u_int) len);
if (au->au_origcred.oa_base == NULL)
goto no_memory;
memcpy(au->au_origcred.oa_base, mymem, (u_int) len);
/*
* set auth handle to reflect new cred.
*/
auth->ah_cred = au->au_origcred;
marshal_new_auth (auth);
return auth;
}
INTDEF (authunix_create)
/*
* Returns an auth handle with parameters determined by doing lots of
* syscalls.
*/
AUTH *
authunix_create_default (void)
{
int len;
char machname[MAX_MACHINE_NAME + 1];
uid_t uid;
gid_t gid;
int max_nr_groups = __sysconf (_SC_NGROUPS_MAX);
gid_t gids[max_nr_groups];
if (__gethostname (machname, MAX_MACHINE_NAME) == -1)
abort ();
machname[MAX_MACHINE_NAME] = 0;
uid = __geteuid ();
gid = __getegid ();
if ((len = __getgroups (max_nr_groups, gids)) < 0)
abort ();
/* This braindamaged Sun code forces us here to truncate the
list of groups to NGRPS members since the code in
authuxprot.c transforms a fixed array. Grrr. */
return INTUSE(authunix_create) (machname, uid, gid, MIN (NGRPS, len), gids);
}
INTDEF (authunix_create_default)
/*
* authunix operations
*/
static void
authunix_nextverf (AUTH *auth)
{
/* no action necessary */
}
static bool_t
authunix_marshal (AUTH *auth, XDR *xdrs)
{
struct audata *au = AUTH_PRIVATE (auth);
return XDR_PUTBYTES (xdrs, au->au_marshed, au->au_mpos);
}
static bool_t
authunix_validate (AUTH *auth, struct opaque_auth *verf)
{
struct audata *au;
XDR xdrs;
if (verf->oa_flavor == AUTH_SHORT)
{
au = AUTH_PRIVATE (auth);
INTUSE(xdrmem_create) (&xdrs, verf->oa_base, verf->oa_length,
XDR_DECODE);
if (au->au_shcred.oa_base != NULL)
{
mem_free (au->au_shcred.oa_base,
au->au_shcred.oa_length);
au->au_shcred.oa_base = NULL;
}
if (INTUSE(xdr_opaque_auth) (&xdrs, &au->au_shcred))
{
auth->ah_cred = au->au_shcred;
}
else
{
xdrs.x_op = XDR_FREE;
(void) INTUSE(xdr_opaque_auth) (&xdrs, &au->au_shcred);
au->au_shcred.oa_base = NULL;
auth->ah_cred = au->au_origcred;
}
marshal_new_auth (auth);
}
return TRUE;
}
static bool_t
authunix_refresh (AUTH *auth)
{
struct audata *au = AUTH_PRIVATE (auth);
struct authunix_parms aup;
struct timeval now;
XDR xdrs;
int stat;
if (auth->ah_cred.oa_base == au->au_origcred.oa_base)
{
/* there is no hope. Punt */
return FALSE;
}
au->au_shfaults++;
/* first deserialize the creds back into a struct authunix_parms */
aup.aup_machname = NULL;
aup.aup_gids = (gid_t *) NULL;
INTUSE(xdrmem_create) (&xdrs, au->au_origcred.oa_base,
au->au_origcred.oa_length, XDR_DECODE);
stat = INTUSE(xdr_authunix_parms) (&xdrs, &aup);
if (!stat)
goto done;
/* update the time and serialize in place */
(void) __gettimeofday (&now, (struct timezone *) 0);
aup.aup_time = now.tv_sec;
xdrs.x_op = XDR_ENCODE;
XDR_SETPOS (&xdrs, 0);
stat = INTUSE(xdr_authunix_parms) (&xdrs, &aup);
if (!stat)
goto done;
auth->ah_cred = au->au_origcred;
marshal_new_auth (auth);
done:
/* free the struct authunix_parms created by deserializing */
xdrs.x_op = XDR_FREE;
(void) INTUSE(xdr_authunix_parms) (&xdrs, &aup);
XDR_DESTROY (&xdrs);
return stat;
}
static void
authunix_destroy (AUTH *auth)
{
struct audata *au = AUTH_PRIVATE (auth);
mem_free (au->au_origcred.oa_base, au->au_origcred.oa_length);
if (au->au_shcred.oa_base != NULL)
mem_free (au->au_shcred.oa_base, au->au_shcred.oa_length);
mem_free (auth->ah_private, sizeof (struct audata));
if (auth->ah_verf.oa_base != NULL)
mem_free (auth->ah_verf.oa_base, auth->ah_verf.oa_length);
mem_free ((caddr_t) auth, sizeof (*auth));
}
/*
* Marshals (pre-serializes) an auth struct.
* sets private data, au_marshed and au_mpos
*/
static bool_t
internal_function
marshal_new_auth (AUTH *auth)
{
XDR xdr_stream;
XDR *xdrs = &xdr_stream;
struct audata *au = AUTH_PRIVATE (auth);
INTUSE(xdrmem_create) (xdrs, au->au_marshed, MAX_AUTH_BYTES, XDR_ENCODE);
if ((!INTUSE(xdr_opaque_auth) (xdrs, &(auth->ah_cred))) ||
(!INTUSE(xdr_opaque_auth) (xdrs, &(auth->ah_verf))))
perror (_("auth_none.c - Fatal marshalling problem"));
else
au->au_mpos = XDR_GETPOS (xdrs);
XDR_DESTROY (xdrs);
return TRUE;
}