10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 52140Srmesta * Common Development and Distribution License (the "License"). 62140Srmesta * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 213957Sth199096 220Sstevel@tonic-gate /* 23*7387SRobert.Gordon@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 242140Srmesta * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #include <stdio.h> 280Sstevel@tonic-gate #include <stdlib.h> 290Sstevel@tonic-gate #include <sys/types.h> 300Sstevel@tonic-gate #include <string.h> 310Sstevel@tonic-gate #include <sys/param.h> 320Sstevel@tonic-gate #include <sys/stat.h> 330Sstevel@tonic-gate #include <sys/file.h> 340Sstevel@tonic-gate #include <sys/time.h> 350Sstevel@tonic-gate #include <sys/errno.h> 360Sstevel@tonic-gate #include <rpcsvc/mount.h> 370Sstevel@tonic-gate #include <sys/pathconf.h> 380Sstevel@tonic-gate #include <sys/systeminfo.h> 390Sstevel@tonic-gate #include <sys/utsname.h> 400Sstevel@tonic-gate #include <arpa/inet.h> 410Sstevel@tonic-gate #include <signal.h> 420Sstevel@tonic-gate #include <syslog.h> 430Sstevel@tonic-gate #include <locale.h> 440Sstevel@tonic-gate #include <unistd.h> 450Sstevel@tonic-gate #include <thread.h> 460Sstevel@tonic-gate #include <netdir.h> 472140Srmesta #include <nfs/auth.h> 483957Sth199096 #include <sharefs/share.h> 490Sstevel@tonic-gate #include "../lib/sharetab.h" 500Sstevel@tonic-gate #include "mountd.h" 510Sstevel@tonic-gate 520Sstevel@tonic-gate static void 532140Srmesta nfsauth_access(auth_req *argp, auth_res *result) 540Sstevel@tonic-gate { 550Sstevel@tonic-gate struct netconfig *nconf; 560Sstevel@tonic-gate struct nd_hostservlist *clnames = NULL; 570Sstevel@tonic-gate struct netbuf nbuf; 580Sstevel@tonic-gate struct share *sh; 590Sstevel@tonic-gate char tmp[MAXIPADDRLEN]; 600Sstevel@tonic-gate char *host = NULL; 610Sstevel@tonic-gate 620Sstevel@tonic-gate result->auth_perm = NFSAUTH_DENIED; 630Sstevel@tonic-gate 640Sstevel@tonic-gate /* 650Sstevel@tonic-gate * Convert the client's address to a hostname 660Sstevel@tonic-gate */ 670Sstevel@tonic-gate nconf = getnetconfigent(argp->req_netid); 680Sstevel@tonic-gate if (nconf == NULL) { 690Sstevel@tonic-gate syslog(LOG_ERR, "No netconfig entry for %s", argp->req_netid); 700Sstevel@tonic-gate return; 710Sstevel@tonic-gate } 720Sstevel@tonic-gate 730Sstevel@tonic-gate nbuf.len = argp->req_client.n_len; 740Sstevel@tonic-gate nbuf.buf = argp->req_client.n_bytes; 750Sstevel@tonic-gate 76*7387SRobert.Gordon@Sun.COM if (nbuf.len == 0 || nbuf.buf == NULL) 77*7387SRobert.Gordon@Sun.COM return; 78*7387SRobert.Gordon@Sun.COM 790Sstevel@tonic-gate if (netdir_getbyaddr(nconf, &clnames, &nbuf)) { 800Sstevel@tonic-gate host = &tmp[0]; 810Sstevel@tonic-gate if (strcmp(nconf->nc_protofmly, NC_INET) == 0) { 820Sstevel@tonic-gate struct sockaddr_in *sa; 830Sstevel@tonic-gate 840Sstevel@tonic-gate /* LINTED pointer alignment */ 850Sstevel@tonic-gate sa = (struct sockaddr_in *)nbuf.buf; 860Sstevel@tonic-gate (void) inet_ntoa_r(sa->sin_addr, tmp); 870Sstevel@tonic-gate } else if (strcmp(nconf->nc_protofmly, NC_INET6) == 0) { 880Sstevel@tonic-gate struct sockaddr_in6 *sa; 890Sstevel@tonic-gate /* LINTED pointer */ 900Sstevel@tonic-gate sa = (struct sockaddr_in6 *)nbuf.buf; 910Sstevel@tonic-gate (void) inet_ntop(AF_INET6, sa->sin6_addr.s6_addr, 92*7387SRobert.Gordon@Sun.COM tmp, INET6_ADDRSTRLEN); 930Sstevel@tonic-gate } 940Sstevel@tonic-gate clnames = anon_client(host); 950Sstevel@tonic-gate } 960Sstevel@tonic-gate 970Sstevel@tonic-gate /* 980Sstevel@tonic-gate * Now find the export 990Sstevel@tonic-gate */ 1000Sstevel@tonic-gate sh = findentry(argp->req_path); 1010Sstevel@tonic-gate if (sh == NULL) { 1020Sstevel@tonic-gate syslog(LOG_ERR, "%s not exported", argp->req_path); 1030Sstevel@tonic-gate goto done; 1040Sstevel@tonic-gate } 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate result->auth_perm = check_client(sh, &nbuf, clnames, argp->req_flavor); 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate sharefree(sh); 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate if (result->auth_perm == NFSAUTH_DENIED) { 1110Sstevel@tonic-gate syslog(LOG_ERR, "%s denied access to %s", 112*7387SRobert.Gordon@Sun.COM clnames->h_hostservs[0].h_host, argp->req_path); 1130Sstevel@tonic-gate } 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate done: 1160Sstevel@tonic-gate freenetconfigent(nconf); 1170Sstevel@tonic-gate if (clnames) 1180Sstevel@tonic-gate netdir_free(clnames, ND_HOSTSERVLIST); 1190Sstevel@tonic-gate } 1202140Srmesta 1212140Srmesta void 1222140Srmesta nfsauth_func(void *cookie, char *dataptr, size_t arg_size, 1232140Srmesta door_desc_t *dp, uint_t n_desc) 1242140Srmesta 1252140Srmesta { 1262140Srmesta nfsauth_arg_t *ap; 1272140Srmesta nfsauth_res_t res = {0}; 1282140Srmesta nfsauth_res_t *rp = &res; 1292140Srmesta XDR xdrs_a; 1302140Srmesta XDR xdrs_r; 1312140Srmesta caddr_t abuf = dataptr; 1322140Srmesta size_t absz = arg_size; 1332140Srmesta size_t rbsz = (size_t)(BYTES_PER_XDR_UNIT * 2); 1342140Srmesta char result[BYTES_PER_XDR_UNIT * 2]; 1352140Srmesta caddr_t rbuf = (caddr_t)&result; 1362140Srmesta varg_t varg = {0}; 1372140Srmesta 1382140Srmesta /* 1392140Srmesta * Decode the inbound door data, so we can look at the cmd. 1402140Srmesta */ 1412140Srmesta xdrmem_create(&xdrs_a, abuf, absz, XDR_DECODE); 1422140Srmesta if (!xdr_varg(&xdrs_a, &varg)) { 1432140Srmesta /* 1442140Srmesta * If the arguments can't be decoded, bail. 1452140Srmesta */ 1462140Srmesta if (varg.vers == V_ERROR) 1472140Srmesta syslog(LOG_ERR, gettext("Arg version mismatch")); 1482140Srmesta res.stat = NFSAUTH_DR_DECERR; 1492140Srmesta goto encres; 1502140Srmesta } 1512140Srmesta 1522140Srmesta /* 1532140Srmesta * Now set the args pointer to the proper version of the args 1542140Srmesta */ 1552140Srmesta switch (varg.vers) { 1562140Srmesta case V_PROTO: 1572140Srmesta ap = &varg.arg_u.arg; 1582140Srmesta break; 1592140Srmesta 1602140Srmesta /* Additional arguments versions go here */ 1612140Srmesta 1622140Srmesta default: 1632140Srmesta syslog(LOG_ERR, gettext("Invalid args version")); 1642140Srmesta goto encres; 1652140Srmesta } 1662140Srmesta 1672140Srmesta /* 1682140Srmesta * Call the specified cmd 1692140Srmesta */ 1702140Srmesta switch (ap->cmd) { 1712140Srmesta case NFSAUTH_ACCESS: 1722140Srmesta nfsauth_access(&ap->areq, &rp->ares); 1732140Srmesta rp->stat = NFSAUTH_DR_OKAY; 1742140Srmesta break; 1752140Srmesta default: 1762140Srmesta rp->stat = NFSAUTH_DR_BADCMD; 1772140Srmesta break; 1782140Srmesta } 1792140Srmesta 1802140Srmesta encres: 1812140Srmesta /* 1822140Srmesta * Free space used to decode the args 1832140Srmesta */ 1842140Srmesta xdrs_a.x_op = XDR_FREE; 1852140Srmesta (void) xdr_varg(&xdrs_a, &varg); 1862140Srmesta xdr_destroy(&xdrs_a); 1872140Srmesta 1882140Srmesta /* 1892140Srmesta * Encode the results before passing thru door. 1902140Srmesta * 1912140Srmesta * The result (nfsauth_res_t) is always two int's, so we don't 1922140Srmesta * have to dynamically size (or allocate) the results buffer. 1932140Srmesta */ 1942140Srmesta xdrmem_create(&xdrs_r, rbuf, rbsz, XDR_ENCODE); 1952140Srmesta if (!xdr_nfsauth_res(&xdrs_r, rp)) { 1962140Srmesta /* 1972140Srmesta * return only the status code 1982140Srmesta */ 1992140Srmesta rp->stat = NFSAUTH_DR_EFAIL; 2002140Srmesta rbsz = sizeof (uint_t); 2012140Srmesta *rbuf = (uint_t)rp->stat; 2022140Srmesta } 2032140Srmesta xdr_destroy(&xdrs_r); 2042140Srmesta 2052140Srmesta (void) door_return((char *)rbuf, rbsz, NULL, 0); 2062140Srmesta (void) door_return(NULL, 0, NULL, 0); 2072140Srmesta /* NOTREACHED */ 2082140Srmesta } 209