1 /* $NetBSD: svc_auth.c,v 1.12 2000/07/06 03:10:35 christos Exp $ */ 2 3 /* 4 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 5 * unrestricted use provided that this legend is included on all tape 6 * media and as a part of the software program in whole or part. Users 7 * may copy or modify Sun RPC without charge, but are not authorized 8 * to license or distribute it to anyone else except as part of a product or 9 * program developed by the user. 10 * 11 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 12 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 13 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 14 * 15 * Sun RPC is provided with no support and without any obligation on the 16 * part of Sun Microsystems, Inc. to assist in its use, correction, 17 * modification or enhancement. 18 * 19 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 20 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 21 * OR ANY PART THEREOF. 22 * 23 * In no event will Sun Microsystems, Inc. be liable for any lost revenue 24 * or profits or other special, indirect and consequential damages, even if 25 * Sun has been advised of the possibility of such damages. 26 * 27 * Sun Microsystems, Inc. 28 * 2550 Garcia Avenue 29 * Mountain View, California 94043 30 */ 31 /* 32 * Copyright (c) 1986-1991 by Sun Microsystems Inc. 33 */ 34 35 #if defined(LIBC_SCCS) && !defined(lint) 36 #ident "@(#)svc_auth.c 1.16 94/04/24 SMI" 37 static char sccsid[] = "@(#)svc_auth.c 1.26 89/02/07 Copyr 1984 Sun Micro"; 38 #endif 39 #include <sys/cdefs.h> 40 __FBSDID("$FreeBSD$"); 41 42 /* 43 * svc_auth.c, Server-side rpc authenticator interface. 44 * 45 */ 46 47 #include <sys/param.h> 48 #include <sys/lock.h> 49 #include <sys/mutex.h> 50 #include <sys/systm.h> 51 #include <sys/ucred.h> 52 53 #include <rpc/rpc.h> 54 55 /* 56 * The call rpc message, msg has been obtained from the wire. The msg contains 57 * the raw form of credentials and verifiers. authenticate returns AUTH_OK 58 * if the msg is successfully authenticated. If AUTH_OK then the routine also 59 * does the following things: 60 * set rqst->rq_xprt->verf to the appropriate response verifier; 61 * sets rqst->rq_client_cred to the "cooked" form of the credentials. 62 * 63 * NB: rqst->rq_cxprt->verf must be pre-alloctaed; 64 * its length is set appropriately. 65 * 66 * The caller still owns and is responsible for msg->u.cmb.cred and 67 * msg->u.cmb.verf. The authentication system retains ownership of 68 * rqst->rq_client_cred, the cooked credentials. 69 * 70 * There is an assumption that any flavour less than AUTH_NULL is 71 * invalid. 72 */ 73 enum auth_stat 74 _authenticate(struct svc_req *rqst, struct rpc_msg *msg) 75 { 76 int cred_flavor; 77 enum auth_stat dummy; 78 79 rqst->rq_cred = msg->rm_call.cb_cred; 80 rqst->rq_xprt->xp_verf.oa_flavor = _null_auth.oa_flavor; 81 rqst->rq_xprt->xp_verf.oa_length = 0; 82 cred_flavor = rqst->rq_cred.oa_flavor; 83 switch (cred_flavor) { 84 case AUTH_NULL: 85 dummy = _svcauth_null(rqst, msg); 86 return (dummy); 87 case AUTH_SYS: 88 dummy = _svcauth_unix(rqst, msg); 89 return (dummy); 90 case AUTH_SHORT: 91 dummy = _svcauth_short(rqst, msg); 92 return (dummy); 93 default: 94 break; 95 } 96 97 return (AUTH_REJECTEDCRED); 98 } 99 100 /*ARGSUSED*/ 101 enum auth_stat 102 _svcauth_null(struct svc_req *rqst, struct rpc_msg *msg) 103 { 104 return (AUTH_OK); 105 } 106 107 int 108 svc_getcred(struct svc_req *rqst, struct ucred *cr, int *flavorp) 109 { 110 int flavor, i; 111 struct xucred *xcr; 112 113 KASSERT(!crshared(cr), ("svc_getcred with shared cred")); 114 115 flavor = rqst->rq_cred.oa_flavor; 116 if (flavorp) 117 *flavorp = flavor; 118 119 switch (flavor) { 120 case AUTH_UNIX: 121 xcr = (struct xucred *) rqst->rq_clntcred; 122 cr->cr_uid = cr->cr_ruid = cr->cr_svuid = xcr->cr_uid; 123 cr->cr_ngroups = xcr->cr_ngroups; 124 for (i = 0; i < xcr->cr_ngroups; i++) 125 cr->cr_groups[i] = xcr->cr_groups[i]; 126 cr->cr_rgid = cr->cr_groups[0]; 127 return (TRUE); 128 129 default: 130 return (FALSE); 131 } 132 } 133 134