⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 auth_kern.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
字号:
#ifndef lintstatic	char	*sccsid = "@(#)auth_kern.c	4.1	7/2/90";#endif lint/************************************************************************ *									* *			Copyright (c) 1986 by				* *		Digital Equipment Corporation, Maynard, MA		* *			All rights reserved.				* *									* *   This software is furnished under a license and may be used and	* *   copied  only  in accordance with the terms of such license and	* *   with the  inclusion  of  the  above  copyright  notice.   This	* *   software  or  any  other copies thereof may not be provided or	* *   otherwise made available to any other person.  No title to and	* *   ownership of the software is hereby transferred.			* *									* *   This software is  derived  from  software  received  from  the	* *   University    of   California,   Berkeley,   and   from   Bell	* *   Laboratories.  Use, duplication, or disclosure is  subject  to	* *   restrictions  under  license  agreements  with  University  of	* *   California and with AT&T.						* *									* *   The information in this software is subject to change  without	* *   notice  and should not be construed as a commitment by Digital	* *   Equipment Corporation.						* *									* *   Digital assumes no responsibility for the use  or  reliability	* *   of its software on equipment which is not supplied by Digital.	* *									* ************************************************************************//* *	Portions of this software have been licensed to  *	Digital Equipment Company, Maynard, MA. *	Copyright (c) 1986 Sun Microsystems, Inc.  ALL RIGHTS RESERVED. *//* * auth_kern.c, Implements UNIX style authentication parameters in the kernel.  * * Interfaces with svc_auth_unix on the server.  See auth_unix.c for the user * level implementation of unix auth. * *//* * *   Modification history: * * 12-11-87	Robin L. and Larry C. and Ricky P. *	Added new kmalloc memory allocation to system. * * 02-Mar-87 -- logcher *	Merged in diskless changes */#include "../h/param.h"#include "../h/systm.h"#include "../h/user.h"#include "../h/kernel.h"#include "../h/proc.h"#include "../rpc/types.h"#include "../rpc/xdr.h"#include "../rpc/auth.h"#include "../rpc/clnt.h"#include "../rpc/auth_unix.h"#include "../netinet/in.h"/* * Unix authenticator operations vector */void	authkern_nextverf();bool_t	authkern_marshal();bool_t	authkern_validate();bool_t	authkern_refresh();void	authkern_destroy();static struct auth_ops auth_kern_ops = {	authkern_nextverf,	authkern_marshal,	authkern_validate,	authkern_refresh,	authkern_destroy};/* * Create a kernel unix style authenticator. * Returns an auth handle. */AUTH *authkern_create(){	register AUTH *auth;	/*	 * Allocate and set up auth handle	 */	kmem_alloc(auth, AUTH *, (u_int)sizeof(*auth), KM_RPC);	auth->ah_ops = &auth_kern_ops;	auth->ah_cred.oa_flavor = AUTH_UNIX;	auth->ah_verf = _null_auth;	return (auth);}/* * authkern operations *//*ARGSUSED*/voidauthkern_nextverf(auth)	AUTH *auth;{	/* no action necessary */}bool_tauthkern_marshal(auth, xdrs)	AUTH *auth;	XDR *xdrs;{	char	*sercred;	XDR	xdrm;	struct	opaque_auth *cred;	bool_t	ret = FALSE;	register int *gp, *gpend;	register int gidlen, credsize;	register long *ptr;	/*	 * First we try a fast path to get through	 * this very common operation.	 */	gp = u.u_groups;	gpend = &u.u_groups[NGRPS];	while (gpend > u.u_groups && gpend[-1] < 0)		gpend--;	gidlen = gpend - gp;	credsize = 4 + 4 + roundup(hostnamelen, 4) + 4 + 4 + 4 + gidlen * 4;	ptr = XDR_INLINE(xdrs, 4 + 4 + credsize + 4 + 4);	if (ptr) {		/*		 * We can do the fast path.		 */		IXDR_PUT_LONG(ptr, AUTH_UNIX);	/* cred flavor */		IXDR_PUT_LONG(ptr, credsize);	/* cred len */		IXDR_PUT_LONG(ptr, time.tv_sec);		IXDR_PUT_LONG(ptr, hostnamelen);		bcopy(hostname, (caddr_t)ptr, (u_int)hostnamelen);		ptr += roundup(hostnamelen, 4) / 4;		IXDR_PUT_LONG(ptr, u.u_uid);		IXDR_PUT_LONG(ptr, u.u_gid);		IXDR_PUT_LONG(ptr, gidlen);		while (gp < gpend) {			IXDR_PUT_LONG(ptr, *gp++);		}		IXDR_PUT_LONG(ptr, AUTH_NULL);	/* verf flavor */		IXDR_PUT_LONG(ptr, 0);	/* verf len */		return (TRUE);	}	kmem_alloc(sercred, char *, (u_int)MAX_AUTH_BYTES, KM_RPC);	/*	 * serialize u struct stuff into sercred	 */	xdrmem_create(&xdrm, sercred, MAX_AUTH_BYTES, XDR_ENCODE);	if (! xdr_authkern(&xdrm)) {		printf("authkern_marshal: xdr_authkern failed\n");		ret = FALSE;		goto done;	}	/*	 * Make opaque auth credentials that point at serialized u struct	 */	cred = &(auth->ah_cred);	cred->oa_length = XDR_GETPOS(&xdrm);	cred->oa_flavor = AUTH_UNIX;	cred->oa_base = sercred;	/*	 * serialize credentials and verifiers (null)	 */	if ((xdr_opaque_auth(xdrs, &(auth->ah_cred)))	    && (xdr_opaque_auth(xdrs, &(auth->ah_verf)))) {		ret = TRUE;	} else {		ret = FALSE;	}done:	kmem_free((caddr_t)sercred, KM_RPC);	return (ret);}/*ARGSUSED*/bool_tauthkern_validate(auth, verf)	AUTH *auth;	struct opaque_auth verf;{	return (TRUE);}/*ARGSUSED*/bool_tauthkern_refresh(auth)	AUTH *auth;{	return (FALSE);}voidauthkern_destroy(auth)	register AUTH *auth;{	kmem_free((caddr_t)auth, KM_RPC);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -