Path: blob/main/crypto/krb5/src/lib/rpc/svc_auth_unix.c
39536 views
/* @(#)svc_auth_unix.c 2.3 88/08/01 4.0 RPCSRC; from 1.28 88/02/08 SMI */1/*2* Copyright (c) 2010, Oracle America, Inc.3*4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions are met:8*9* * Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11*12* * Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in14* the documentation and/or other materials provided with the15* distribution.16*17* * Neither the name of the "Oracle America, Inc." nor the names of18* its contributors may be used to endorse or promote products19* derived from this software without specific prior written permission.20*21* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS22* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED23* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A24* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT25* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,26* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED27* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR28* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF29* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING30* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS31* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.32*/33#if !defined(lint) && defined(SCCSIDS)34static char sccsid[] = "@(#)svc_auth_unix.c 1.28 88/02/08 Copyr 1984 Sun Micro";35#endif3637/*38* svc_auth_unix.c39* Handles UNIX flavor authentication parameters on the service side of rpc.40* There are two svc auth implementations here: AUTH_UNIX and AUTH_SHORT.41* _svcauth_unix does full blown unix style uid,gid+gids auth,42* _svcauth_short uses a shorthand auth to index into a cache of longhand auths.43* Note: the shorthand has been gutted for efficiency.44*/4546#include <stdio.h>47#include <string.h>48#include <gssrpc/rpc.h>4950/*51* Unix longhand authenticator52*/53enum auth_stat54gssrpc__svcauth_unix(55struct svc_req *rqst,56struct rpc_msg *msg,57bool_t *dispatch)58{59enum auth_stat stat;60XDR xdrs;61struct authunix_parms *aup;62rpc_inline_t *buf;63struct area {64struct authunix_parms area_aup;65char area_machname[MAX_MACHINE_NAME+1];66int area_gids[NGRPS];67} *area;68u_int auth_len, str_len, gid_len, i;6970rqst->rq_xprt->xp_auth = &svc_auth_none;7172area = (struct area *) rqst->rq_clntcred;73aup = &area->area_aup;74aup->aup_machname = area->area_machname;75aup->aup_gids = area->area_gids;76auth_len = msg->rm_call.cb_cred.oa_length;77if (auth_len > INT_MAX)78return AUTH_BADCRED;79xdrmem_create(&xdrs, msg->rm_call.cb_cred.oa_base, auth_len,XDR_DECODE);80buf = XDR_INLINE(&xdrs, (int)auth_len);81if (buf != NULL) {82aup->aup_time = IXDR_GET_LONG(buf);83str_len = IXDR_GET_U_LONG(buf);84if (str_len > MAX_MACHINE_NAME) {85stat = AUTH_BADCRED;86goto done;87}88memmove(aup->aup_machname, buf, str_len);89aup->aup_machname[str_len] = 0;90str_len = RNDUP(str_len);91buf += str_len / BYTES_PER_XDR_UNIT;92aup->aup_uid = IXDR_GET_LONG(buf);93aup->aup_gid = IXDR_GET_LONG(buf);94gid_len = IXDR_GET_U_LONG(buf);95if (gid_len > NGRPS) {96stat = AUTH_BADCRED;97goto done;98}99aup->aup_len = gid_len;100for (i = 0; i < gid_len; i++) {101aup->aup_gids[i] = IXDR_GET_LONG(buf);102}103/*104* five is the smallest unix credentials structure -105* timestamp, hostname len (0), uid, gid, and gids len (0).106*/107if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len) {108(void) printf("bad auth_len gid %u str %u auth %u\n",109gid_len, str_len, auth_len);110stat = AUTH_BADCRED;111goto done;112}113} else if (! xdr_authunix_parms(&xdrs, aup)) {114xdrs.x_op = XDR_FREE;115(void)xdr_authunix_parms(&xdrs, aup);116stat = AUTH_BADCRED;117goto done;118}119rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL;120rqst->rq_xprt->xp_verf.oa_length = 0;121stat = AUTH_OK;122done:123XDR_DESTROY(&xdrs);124return (stat);125}126127128/*129* Shorthand unix authenticator130* Looks up longhand in a cache.131*/132/*ARGSUSED*/133enum auth_stat134gssrpc__svcauth_short(135struct svc_req *rqst,136struct rpc_msg *msg,137bool_t *dispatch)138{139rqst->rq_xprt->xp_auth = &svc_auth_none;140return (AUTH_REJECTEDCRED);141}142143144