17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51cc55349Srmesta * Common Development and Distribution License (the "License"). 61cc55349Srmesta * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21a237e38eSth199096 227c478bd9Sstevel@tonic-gate /* 23*a9685eaaSMarcel Telka * Copyright 2015 Nexenta Systems, Inc. All rights reserved. 2489621fe1SMarcel Telka */ 2589621fe1SMarcel Telka 2689621fe1SMarcel Telka /* 278c3630f0SGerald Thornbrugh * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 281cc55349Srmesta * Use is subject to license terms. 297c478bd9Sstevel@tonic-gate */ 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #include <stdio.h> 327c478bd9Sstevel@tonic-gate #include <stdlib.h> 337c478bd9Sstevel@tonic-gate #include <sys/types.h> 347c478bd9Sstevel@tonic-gate #include <string.h> 357c478bd9Sstevel@tonic-gate #include <sys/param.h> 367c478bd9Sstevel@tonic-gate #include <sys/stat.h> 377c478bd9Sstevel@tonic-gate #include <sys/file.h> 387c478bd9Sstevel@tonic-gate #include <sys/time.h> 397c478bd9Sstevel@tonic-gate #include <sys/errno.h> 407c478bd9Sstevel@tonic-gate #include <rpcsvc/mount.h> 417c478bd9Sstevel@tonic-gate #include <sys/pathconf.h> 427c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h> 437c478bd9Sstevel@tonic-gate #include <sys/utsname.h> 447c478bd9Sstevel@tonic-gate #include <arpa/inet.h> 457c478bd9Sstevel@tonic-gate #include <signal.h> 467c478bd9Sstevel@tonic-gate #include <syslog.h> 477c478bd9Sstevel@tonic-gate #include <locale.h> 487c478bd9Sstevel@tonic-gate #include <unistd.h> 497c478bd9Sstevel@tonic-gate #include <thread.h> 507c478bd9Sstevel@tonic-gate #include <netdir.h> 511cc55349Srmesta #include <nfs/auth.h> 52a237e38eSth199096 #include <sharefs/share.h> 5389621fe1SMarcel Telka #include <alloca.h> 547c478bd9Sstevel@tonic-gate #include "../lib/sharetab.h" 557c478bd9Sstevel@tonic-gate #include "mountd.h" 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate static void 581cc55349Srmesta nfsauth_access(auth_req *argp, auth_res *result) 597c478bd9Sstevel@tonic-gate { 607c478bd9Sstevel@tonic-gate struct netbuf nbuf; 617c478bd9Sstevel@tonic-gate struct share *sh; 62*a9685eaaSMarcel Telka 63*a9685eaaSMarcel Telka struct cln cln; 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate result->auth_perm = NFSAUTH_DENIED; 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate nbuf.len = argp->req_client.n_len; 687c478bd9Sstevel@tonic-gate nbuf.buf = argp->req_client.n_bytes; 697c478bd9Sstevel@tonic-gate 700a701b1eSRobert Gordon if (nbuf.len == 0 || nbuf.buf == NULL) 71*a9685eaaSMarcel Telka return; 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate /* 74*a9685eaaSMarcel Telka * Find the export 757c478bd9Sstevel@tonic-gate */ 767c478bd9Sstevel@tonic-gate sh = findentry(argp->req_path); 777c478bd9Sstevel@tonic-gate if (sh == NULL) { 787c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "%s not exported", argp->req_path); 79*a9685eaaSMarcel Telka return; 807c478bd9Sstevel@tonic-gate } 817c478bd9Sstevel@tonic-gate 82*a9685eaaSMarcel Telka cln_init_lazy(&cln, argp->req_netid, &nbuf); 83*a9685eaaSMarcel Telka 84*a9685eaaSMarcel Telka result->auth_perm = check_client(sh, &cln, argp->req_flavor, 8589621fe1SMarcel Telka argp->req_clnt_uid, argp->req_clnt_gid, argp->req_clnt_gids.len, 8689621fe1SMarcel Telka argp->req_clnt_gids.val, &result->auth_srv_uid, 8789621fe1SMarcel Telka &result->auth_srv_gid, &result->auth_srv_gids.len, 8889621fe1SMarcel Telka &result->auth_srv_gids.val); 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate sharefree(sh); 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate if (result->auth_perm == NFSAUTH_DENIED) { 93*a9685eaaSMarcel Telka char *host = cln_gethost(&cln); 94*a9685eaaSMarcel Telka if (host != NULL) 95*a9685eaaSMarcel Telka syslog(LOG_ERR, "%s denied access to %s", host, 96*a9685eaaSMarcel Telka argp->req_path); 977c478bd9Sstevel@tonic-gate } 987c478bd9Sstevel@tonic-gate 99*a9685eaaSMarcel Telka cln_fini(&cln); 1007c478bd9Sstevel@tonic-gate } 1011cc55349Srmesta 1021cc55349Srmesta void 1031cc55349Srmesta nfsauth_func(void *cookie, char *dataptr, size_t arg_size, 1041cc55349Srmesta door_desc_t *dp, uint_t n_desc) 1051cc55349Srmesta 1061cc55349Srmesta { 1071cc55349Srmesta nfsauth_arg_t *ap; 1081cc55349Srmesta nfsauth_res_t res = {0}; 1091cc55349Srmesta XDR xdrs_a; 1101cc55349Srmesta XDR xdrs_r; 11189621fe1SMarcel Telka size_t rbsz; 11289621fe1SMarcel Telka caddr_t rbuf; 1131cc55349Srmesta varg_t varg = {0}; 1141cc55349Srmesta 1151cc55349Srmesta /* 1161cc55349Srmesta * Decode the inbound door data, so we can look at the cmd. 1171cc55349Srmesta */ 11889621fe1SMarcel Telka xdrmem_create(&xdrs_a, dataptr, arg_size, XDR_DECODE); 1191cc55349Srmesta if (!xdr_varg(&xdrs_a, &varg)) { 1201cc55349Srmesta /* 1211cc55349Srmesta * If the arguments can't be decoded, bail. 1221cc55349Srmesta */ 1231cc55349Srmesta if (varg.vers == V_ERROR) 1241cc55349Srmesta syslog(LOG_ERR, gettext("Arg version mismatch")); 1251cc55349Srmesta res.stat = NFSAUTH_DR_DECERR; 1261cc55349Srmesta goto encres; 1271cc55349Srmesta } 1281cc55349Srmesta 1291cc55349Srmesta /* 1301cc55349Srmesta * Now set the args pointer to the proper version of the args 1311cc55349Srmesta */ 1321cc55349Srmesta switch (varg.vers) { 1331cc55349Srmesta case V_PROTO: 1341cc55349Srmesta ap = &varg.arg_u.arg; 1351cc55349Srmesta break; 1361cc55349Srmesta 1371cc55349Srmesta /* Additional arguments versions go here */ 1381cc55349Srmesta 1391cc55349Srmesta default: 1401cc55349Srmesta syslog(LOG_ERR, gettext("Invalid args version")); 14189621fe1SMarcel Telka res.stat = NFSAUTH_DR_DECERR; 1421cc55349Srmesta goto encres; 1431cc55349Srmesta } 1441cc55349Srmesta 1451cc55349Srmesta /* 1461cc55349Srmesta * Call the specified cmd 1471cc55349Srmesta */ 1481cc55349Srmesta switch (ap->cmd) { 1491cc55349Srmesta case NFSAUTH_ACCESS: 15089621fe1SMarcel Telka nfsauth_access(&ap->areq, &res.ares); 15189621fe1SMarcel Telka res.stat = NFSAUTH_DR_OKAY; 1521cc55349Srmesta break; 1531cc55349Srmesta default: 15489621fe1SMarcel Telka res.stat = NFSAUTH_DR_BADCMD; 1551cc55349Srmesta break; 1561cc55349Srmesta } 1571cc55349Srmesta 1581cc55349Srmesta encres: 1591cc55349Srmesta /* 1601cc55349Srmesta * Free space used to decode the args 1611cc55349Srmesta */ 16289621fe1SMarcel Telka xdr_free(xdr_varg, (char *)&varg); 1631cc55349Srmesta xdr_destroy(&xdrs_a); 1641cc55349Srmesta 1651cc55349Srmesta /* 1661cc55349Srmesta * Encode the results before passing thru door. 1671cc55349Srmesta */ 16889621fe1SMarcel Telka rbsz = xdr_sizeof(xdr_nfsauth_res, &res); 16989621fe1SMarcel Telka if (rbsz == 0) 17089621fe1SMarcel Telka goto failed; 17189621fe1SMarcel Telka rbuf = alloca(rbsz); 17289621fe1SMarcel Telka 1731cc55349Srmesta xdrmem_create(&xdrs_r, rbuf, rbsz, XDR_ENCODE); 17489621fe1SMarcel Telka if (!xdr_nfsauth_res(&xdrs_r, &res)) { 17589621fe1SMarcel Telka xdr_destroy(&xdrs_r); 17689621fe1SMarcel Telka failed: 17789621fe1SMarcel Telka xdr_free(xdr_nfsauth_res, (char *)&res); 1781cc55349Srmesta /* 1791cc55349Srmesta * return only the status code 1801cc55349Srmesta */ 18189621fe1SMarcel Telka res.stat = NFSAUTH_DR_EFAIL; 1821cc55349Srmesta rbsz = sizeof (uint_t); 18389621fe1SMarcel Telka rbuf = (caddr_t)&res.stat; 18489621fe1SMarcel Telka 18589621fe1SMarcel Telka goto out; 1861cc55349Srmesta } 1871cc55349Srmesta xdr_destroy(&xdrs_r); 18889621fe1SMarcel Telka xdr_free(xdr_nfsauth_res, (char *)&res); 1891cc55349Srmesta 19089621fe1SMarcel Telka out: 1911cc55349Srmesta (void) door_return((char *)rbuf, rbsz, NULL, 0); 1921cc55349Srmesta (void) door_return(NULL, 0, NULL, 0); 1931cc55349Srmesta /* NOTREACHED */ 1941cc55349Srmesta } 195